blob: 664b7632327d49c4d0cca765e97e928a4d4b4903 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Michael Jurka974c3862012-05-22 22:00:31 -070020import android.accounts.Account;
21import android.accounts.AccountManager;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080023import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070030import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070031import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070049import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080050import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070051import android.graphics.Bitmap;
52import android.graphics.Canvas;
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;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070066import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080067import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070072import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080073import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080074import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080075import android.view.KeyEvent;
76import android.view.LayoutInflater;
77import android.view.Menu;
78import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070079import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080080import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080081import android.view.View;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080082import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070083import android.view.ViewGroup;
Michael Jurkab737ee62011-11-15 15:57:22 -080084import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080085import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Dianne Hackbornbb003a52011-08-30 14:40:07 -070086import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080087import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070088import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070089import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080090import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070092import android.widget.Advanceable;
Michael Jurkaaf442092010-06-10 17:01:57 -070093import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070094import android.widget.TextView;
95import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070096
Daniel Sandler325dc232013-06-05 22:57:57 -040097import com.android.launcher3.R;
98import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080099
Adam Cohenc0dcf592011-06-01 15:30:43 -0700100import java.io.DataInputStream;
101import java.io.DataOutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700102import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700103import java.io.FileNotFoundException;
104import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700105import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700106import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700107import java.util.Collection;
108import java.util.Collections;
109import java.util.Comparator;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700110import java.util.HashMap;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700111import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700112import java.util.List;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700113import java.util.Set;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115/**
116 * Default launcher application.
117 */
Michael Jurka946ad472010-07-09 18:05:18 -0700118public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700119 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700120 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800121 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700122 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800123
Joe Onorato9c1289c2009-08-17 11:03:03 -0400124 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400125 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700126 static final boolean DEBUG_STRICT_MODE = false;
Michael Jurkac402cd92013-05-20 15:49:32 +0200127 static final boolean DEBUG_RESUME_TIME = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700128
Winson Chung70d72102011-08-12 11:24:35 -0700129 private static final int MENU_GROUP_WALLPAPER = 1;
130 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
131 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700132 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
133 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800134
135 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700139 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700140 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Michael Jurka8b805b12012-04-18 14:23:14 -0700142 private static final int REQUEST_BIND_APPWIDGET = 11;
143
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800144 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
145
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800146 static final int SCREEN_COUNT = 5;
147 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148
Romain Guy98d01652009-06-30 16:21:04 -0700149 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800150 // To turn on these properties, type
151 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
152 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
153 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Winson Chung2672ff92012-05-04 16:22:30 -0700155 // The Intent extra that defines whether to ignore the launch animation
156 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400157 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700158
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800159 // Type: int
160 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700161 // Type: int
162 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700164 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
165 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
167 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700168 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 // Type: boolean
172 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
173 // Type: long
174 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700175 // Type: int
176 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
177 // Type: int
178 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
179 // Type: parcelable
180 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100182 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700183 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100184 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700185 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100186 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700187
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700188 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700189 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700190 private State mState = State.WORKSPACE;
191 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800192 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700193
Joe Onorato9c1289c2009-08-17 11:03:03 -0400194 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700195 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
196 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700197 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700198 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800199
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800200 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800201 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202
Winson Chunga2413752012-04-03 14:22:34 -0700203 // How long to wait before the new-shortcut animation automatically pans the workspace
204 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
205
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800206 private final BroadcastReceiver mCloseSystemDialogsReceiver
207 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800208 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
209
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210 private LayoutInflater mInflater;
211
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800213 private View mQsbDivider;
214 private View mDockDivider;
Craig Mautner360310b2012-10-26 15:13:08 -0700215 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800216 private DragLayer mDragLayer;
217 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700218
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700219 private AppWidgetManager mAppWidgetManager;
220 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700221
Michael Jurkac9d95c52011-08-29 14:03:34 -0700222 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700223 private AppWidgetProviderInfo mPendingAddWidgetInfo;
224
Michael Jurka0280c3b2010-09-17 15:00:07 -0700225 private int[] mTmpAddItemCellCoordinates = new int[2];
226
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800227 private FolderInfo mFolderInfo;
228
Winson Chung3d503fb2011-07-13 17:25:49 -0700229 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800230 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700231
Winson Chungc51db6a2011-10-05 11:44:49 -0700232 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700233 private AppsCustomizeTabHost mAppsCustomizeTabHost;
234 private AppsCustomizePagedView mAppsCustomizeContent;
235 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800237 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700238 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
239 // scroll issues (because the workspace may not have been measured yet) and extra work.
240 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
241 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800242
243 private SpannableStringBuilder mDefaultKeySsb = null;
244
Joe Onorato9c1289c2009-08-17 11:03:03 -0400245 private boolean mWorkspaceLoading = true;
246
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800247 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800248 private boolean mRestoring;
249 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700250 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800251
Michael Jurka7607c2f2013-04-03 14:33:19 -0700252 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
253
Winson Chung4a2afa32012-07-19 14:53:05 -0700254 // Keep track of whether the user has left launcher
255 private static boolean sPausedFromUserAction = false;
256
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800257 private Bundle mSavedInstanceState;
258
Joe Onorato9c1289c2009-08-17 11:03:03 -0400259 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800260 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800261 private boolean mUserPresent = true;
262 private boolean mVisible = false;
263 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400264
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700265 private static LocaleConfiguration sLocaleConfiguration = null;
266
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700267 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700268
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700269 private Intent mAppMarketIntent = null;
270
Adam Cohended9f8d2010-11-03 13:25:16 -0700271 // Related to the auto-advancing of widgets
272 private final int ADVANCE_MSG = 1;
273 private final int mAdvanceInterval = 20000;
274 private final int mAdvanceStagger = 250;
275 private long mAutoAdvanceSentTime;
276 private long mAutoAdvanceTimeLeft = -1;
277 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
278 new HashMap<View, AppWidgetProviderInfo>();
279
Winson Chung400438b2011-01-16 17:53:48 -0800280 // Determines how long to wait after a rotation before restoring the screen orientation to
281 // match the sensor state.
282 private final int mRestoreScreenOrientationDelay = 500;
283
Michael Jurka4ef207b2010-11-29 17:05:45 -0800284 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700285 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
286 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
287 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800288
Craig Mautner360310b2012-10-26 15:13:08 -0700289 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700290
Adam Cohen1462de32012-07-24 22:34:36 -0700291 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
292
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700293 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
294
Winson Chung46353de2012-02-16 14:05:10 -0800295 // We only want to get the SharedPreferences once since it does an FS stat each time we get
296 // it from the context.
297 private SharedPreferences mSharedPrefs;
298
Winson Chungf0c6ae02012-03-21 16:10:31 -0700299 // Holds the page that we need to animate to, and the icon views that we need to animate up
300 // when we scroll to that page on resume.
301 private int mNewShortcutAnimatePage = -1;
302 private ArrayList<View> mNewShortcutAnimateViews = new ArrayList<View>();
Adam Cohen268c4752012-06-06 17:47:33 -0700303 private ImageView mFolderIconImageView;
304 private Bitmap mFolderIconBitmap;
305 private Canvas mFolderIconCanvas;
306 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700307
Michael Jurkaddd62e92011-02-16 17:49:14 -0800308 private BubbleTextView mWaitingForResume;
309
Michael Jurka22143132012-10-04 17:42:38 +0200310 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
311 = new HideFromAccessibilityHelper();
312
Michael Jurkac1f5d262011-09-30 19:32:27 -0700313 private Runnable mBuildLayersRunnable = new Runnable() {
314 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700315 if (mWorkspace != null) {
316 mWorkspace.buildPageHardwareLayers();
317 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700318 }
319 };
320
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800321 private static ArrayList<PendingAddArguments> sPendingAddList
322 = new ArrayList<PendingAddArguments>();
323
Michael Jurka0a457bf2012-11-19 14:05:05 -0800324 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
325
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800326 private static class PendingAddArguments {
327 int requestCode;
328 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700329 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800330 int screen;
331 int cellX;
332 int cellY;
333 }
334
Michael Jurka0a457bf2012-11-19 14:05:05 -0800335 private static boolean isPropertyEnabled(String propertyName) {
336 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700337 }
338
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800339 @Override
340 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700341 if (DEBUG_STRICT_MODE) {
342 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
343 .detectDiskReads()
344 .detectDiskWrites()
345 .detectNetwork() // or .detectAll() for all detectable problems
346 .penaltyLog()
347 .build());
348 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
349 .detectLeakedSqlLiteObjects()
350 .detectLeakedClosableObjects()
351 .penaltyLog()
352 .penaltyDeath()
353 .build());
354 }
355
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800356 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800357 LauncherApplication app = ((LauncherApplication)getApplication());
Winson Chungf0c6ae02012-03-21 16:10:31 -0700358 mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(),
359 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800360 mModel = app.setLauncher(this);
361 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400362 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800363 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700364
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700365 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700366 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
367 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700368
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700369 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
370 // this also ensures that any synchronous binding below doesn't re-trigger another
371 // LauncherModel load.
372 mPaused = false;
373
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800374 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200375 android.os.Debug.startMethodTracing(
376 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800377 }
378
379 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800380 setContentView(R.layout.launcher);
381 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700382 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800383
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800384 registerContentObservers();
385
Joe Onorato7c312c12009-08-13 21:36:53 -0700386 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700387
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800388 mSavedState = savedInstanceState;
389 restoreState(mSavedState);
390
Winson Chunga12a2502010-12-20 14:41:35 -0800391 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700392 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200393 mAppsCustomizeContent.onPackagesUpdated(
394 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700395 }
Winson Chunga12a2502010-12-20 14:41:35 -0800396
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800397 if (PROFILE_STARTUP) {
398 android.os.Debug.stopMethodTracing();
399 }
400
401 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700402 if (sPausedFromUserAction) {
403 // If the user leaves launcher, then we should just load items asynchronously when
404 // they return.
405 mModel.startLoader(true, -1);
406 } else {
407 // We only load the page synchronously if the user rotates (or triggers a
408 // configuration change) while launcher is in the foreground
409 mModel.startLoader(true, mWorkspace.getCurrentPage());
410 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800411 }
412
Michael Jurkac57b7a82011-08-09 22:02:20 -0700413 if (!mModel.isAllAppsLoaded()) {
414 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
415 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
416 }
417
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800418 // For handling default keys
419 mDefaultKeySsb = new SpannableStringBuilder();
420 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800421
422 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
423 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800424
Adam Cohenf9426d52012-06-04 17:26:21 -0700425 updateGlobalIcons();
426
427 // On large interfaces, we want the screen to auto-rotate based on the current orientation
428 unlockScreenOrientation(true);
429 }
430
Winson Chung4a2afa32012-07-19 14:53:05 -0700431 protected void onUserLeaveHint() {
432 super.onUserLeaveHint();
433 sPausedFromUserAction = true;
434 }
435
Adam Cohenf9426d52012-06-04 17:26:21 -0700436 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700437 boolean searchVisible = false;
438 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800439 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700440 int coi = getCurrentOrientationIndexForGlobalIcons();
441 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
442 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700443 updateAppMarketIcon();
444 searchVisible = updateGlobalSearchIcon();
445 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700446 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700447 if (sGlobalSearchIcon[coi] != null) {
448 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700449 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700450 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700451 if (sVoiceSearchIcon[coi] != null) {
452 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700453 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700454 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700455 if (sAppMarketIcon[coi] != null) {
456 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800457 }
Winson Chungadf0c182012-08-23 14:59:07 -0700458 if (mSearchDropTargetBar != null) {
459 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
460 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800461 }
Romain Guycbb89e42009-06-08 15:52:54 -0700462
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800463 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700464 if (sLocaleConfiguration == null) {
465 new AsyncTask<Void, Void, LocaleConfiguration>() {
466 @Override
467 protected LocaleConfiguration doInBackground(Void... unused) {
468 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
469 readConfiguration(Launcher.this, localeConfiguration);
470 return localeConfiguration;
471 }
472
473 @Override
474 protected void onPostExecute(LocaleConfiguration result) {
475 sLocaleConfiguration = result;
476 checkForLocaleChange(); // recursive, but now with a locale configuration
477 }
478 }.execute();
479 return;
480 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700481
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800482 final Configuration configuration = getResources().getConfiguration();
483
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700484 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800485 final String locale = configuration.locale.toString();
486
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700487 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800488 final int mcc = configuration.mcc;
489
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700490 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800491 final int mnc = configuration.mnc;
492
Romain Guy84f296c2009-11-04 15:00:44 -0800493 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800494
Romain Guy84f296c2009-11-04 15:00:44 -0800495 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700496 sLocaleConfiguration.locale = locale;
497 sLocaleConfiguration.mcc = mcc;
498 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700499
Joe Onorato0589f0f2010-02-08 13:44:00 -0800500 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700501
502 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
503 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700504 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700505 public void run() {
506 writeConfiguration(Launcher.this, localeConfiguration);
507 }
508 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700509 }
510 }
511
512 private static class LocaleConfiguration {
513 public String locale;
514 public int mcc = -1;
515 public int mnc = -1;
516 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700517
Romain Guy98d01652009-06-30 16:21:04 -0700518 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
519 DataInputStream in = null;
520 try {
521 in = new DataInputStream(context.openFileInput(PREFERENCES));
522 configuration.locale = in.readUTF();
523 configuration.mcc = in.readInt();
524 configuration.mnc = in.readInt();
525 } catch (FileNotFoundException e) {
526 // Ignore
527 } catch (IOException e) {
528 // Ignore
529 } finally {
530 if (in != null) {
531 try {
532 in.close();
533 } catch (IOException e) {
534 // Ignore
535 }
536 }
537 }
538 }
539
540 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
541 DataOutputStream out = null;
542 try {
543 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
544 out.writeUTF(configuration.locale);
545 out.writeInt(configuration.mcc);
546 out.writeInt(configuration.mnc);
547 out.flush();
548 } catch (FileNotFoundException e) {
549 // Ignore
550 } catch (IOException e) {
551 //noinspection ResultOfMethodCallIgnored
552 context.getFileStreamPath(PREFERENCES).delete();
553 } finally {
554 if (out != null) {
555 try {
556 out.close();
557 } catch (IOException e) {
558 // Ignore
559 }
560 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800561 }
562 }
563
Adam Cohen716b51e2011-06-30 12:09:54 -0700564 public DragLayer getDragLayer() {
565 return mDragLayer;
566 }
567
Winson Chung36a62fe2012-05-06 18:04:42 -0700568 boolean isDraggingEnabled() {
569 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
570 // that is subsequently removed from the workspace in startBinding().
571 return !mModel.isLoadingWorkspace();
572 }
573
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800574 static int getScreen() {
575 synchronized (sLock) {
576 return sScreen;
577 }
578 }
579
580 static void setScreen(int screen) {
581 synchronized (sLock) {
582 sScreen = screen;
583 }
584 }
585
Winson Chung557d6ed2011-07-08 15:34:52 -0700586 /**
587 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
588 * a configuration step, this allows the proper animations to run after other transitions.
589 */
590 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700591 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800592 switch (args.requestCode) {
593 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700594 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
595 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800596 break;
597 case REQUEST_PICK_SHORTCUT:
598 processShortcut(args.intent);
599 break;
600 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700601 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
602 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700603 result = true;
604 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800605 case REQUEST_CREATE_APPWIDGET:
606 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800607 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700608 result = true;
609 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800610 case REQUEST_PICK_WALLPAPER:
611 // We just wanted the activity result here so we can clear mWaitingForResult
612 break;
613 }
Michael Jurka27614d22012-04-02 06:40:22 -0700614 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
615 // if you turned the screen off and then back while in All Apps, Launcher would not
616 // return to the workspace. Clearing mAddInfo.container here fixes this issue
617 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700618 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800619 }
620
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800621 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700622 protected void onActivityResult(
623 final int requestCode, final int resultCode, final Intent data) {
624 if (requestCode == REQUEST_BIND_APPWIDGET) {
625 int appWidgetId = data != null ?
626 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
627 if (resultCode == RESULT_CANCELED) {
628 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
629 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700630 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700631 }
632 return;
633 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700634 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800635 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
636 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700637 mWaitingForResult = false;
638
Adam Cohened66b2b2012-01-23 17:28:51 -0800639 // We have special handling for widgets
640 if (isWidgetDrop) {
641 int appWidgetId = data != null ?
642 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700643 if (appWidgetId < 0) {
644 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
645 "widget configuration activity.");
646 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
647 } else {
648 completeTwoStageWidgetDrop(resultCode, appWidgetId);
649 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800650 return;
651 }
652
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800653 // The pattern used here is that a user PICKs a specific application,
654 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700655
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800656 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
657 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700658 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800659 final PendingAddArguments args = new PendingAddArguments();
660 args.requestCode = requestCode;
661 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700662 args.container = mPendingAddInfo.container;
663 args.screen = mPendingAddInfo.screen;
664 args.cellX = mPendingAddInfo.cellX;
665 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800666 if (isWorkspaceLocked()) {
667 sPendingAddList.add(args);
668 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700669 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800670 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800671 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800672 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700673 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800674 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
675 null);
676 }
677
678 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700679 CellLayout cellLayout =
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700680 (CellLayout) mWorkspace.getChildAt(mPendingAddInfo.screen);
Adam Cohened66b2b2012-01-23 17:28:51 -0800681 Runnable onCompleteRunnable = null;
682 int animationType = 0;
683
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700684 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800685 if (resultCode == RESULT_OK) {
686 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
687 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700688 mPendingAddWidgetInfo);
689 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800690 onCompleteRunnable = new Runnable() {
691 @Override
692 public void run() {
693 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
694 mPendingAddInfo.screen, layout, null);
695 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
696 null);
697 }
698 };
699 } else if (resultCode == RESULT_CANCELED) {
700 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
701 onCompleteRunnable = new Runnable() {
702 @Override
703 public void run() {
704 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
705 null);
706 }
707 };
708 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700709 if (mDragLayer.getAnimatedView() != null) {
710 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
711 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
712 animationType, boundWidget, true);
713 } else {
714 // The animated view may be null in the case of a rotation during widget configuration
715 onCompleteRunnable.run();
716 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800717 }
718
719 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700720 protected void onStop() {
721 super.onStop();
722 FirstFrameAnimatorHelper.setIsVisible(false);
723 }
724
725 @Override
726 protected void onStart() {
727 super.onStart();
728 FirstFrameAnimatorHelper.setIsVisible(true);
729 }
730
731 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800732 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200733 long startTime = 0;
734 if (DEBUG_RESUME_TIME) {
735 startTime = System.currentTimeMillis();
736 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800737 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700738
Winson Chung4a2afa32012-07-19 14:53:05 -0700739 // Restore the previous launcher state
740 if (mOnResumeState == State.WORKSPACE) {
741 showWorkspace(false);
742 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
743 showAllApps(false);
744 }
745 mOnResumeState = State.NONE;
746
Craig Mautner360310b2012-10-26 15:13:08 -0700747 // Background was set to gradient in onPause(), restore to black if in all apps.
748 setWorkspaceBackground(mState == State.WORKSPACE);
749
Winson Chungde0fb8f2012-05-08 14:37:08 -0700750 // Process any items that were added while Launcher was away
751 InstallShortcutReceiver.flushInstallQueue(this);
752
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800753 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700754 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700755 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400756 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700757 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400758 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700759 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800760 }
Michael Jurkac402cd92013-05-20 15:49:32 +0200761 if (mOnResumeCallbacks.size() > 0) {
762 // We might have postponed some bind calls until onResume (see waitUntilResume) --
763 // execute them here
764 long startTimeCallbacks = 0;
765 if (DEBUG_RESUME_TIME) {
766 startTimeCallbacks = System.currentTimeMillis();
767 }
768
769 if (mAppsCustomizeContent != null) {
770 mAppsCustomizeContent.setBulkBind(true);
771 }
772 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
773 mOnResumeCallbacks.get(i).run();
774 }
775 if (mAppsCustomizeContent != null) {
776 mAppsCustomizeContent.setBulkBind(false);
777 }
778 mOnResumeCallbacks.clear();
779 if (DEBUG_RESUME_TIME) {
780 Log.d(TAG, "Time spent processing callbacks in onResume: " +
781 (System.currentTimeMillis() - startTimeCallbacks));
782 }
Michael Jurka447bf842013-05-15 14:52:15 +0200783 }
Winson Chunge4e50662012-01-23 14:45:13 -0800784
785 // Reset the pressed state of icons that were locked in the press state while activities
786 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800787 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800788 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800789 mWaitingForResume.setStayPressed(false);
790 }
Winson Chunge4e50662012-01-23 14:45:13 -0800791 if (mAppsCustomizeContent != null) {
792 // Resets the previous all apps icon press state
793 mAppsCustomizeContent.resetDrawableState();
794 }
Adam Cohen06dff352012-06-01 17:17:08 -0700795 // It is possible that widgets can receive updates while launcher is not in the foreground.
796 // Consequently, the widgets will be inflated in the orientation of the foreground activity
797 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
798 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700799 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700800
801 // Again, as with the above scenario, it's possible that one or more of the global icons
802 // were updated in the wrong orientation.
803 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200804 if (DEBUG_RESUME_TIME) {
805 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
806 }
Adam Cohen06dff352012-06-01 17:17:08 -0700807 }
808
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800809 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700810 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700811 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
812 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
813 // when Launcher resumes and we are still in AllApps.
814 updateWallpaperVisibility(true);
815
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700816 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700817 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800818 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700819 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700820 }
Romain Guycbb89e42009-06-08 15:52:54 -0700821
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700822 @Override
823 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400824 // Flag the loader to stop early before switching
825 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700826 if (mAppsCustomizeContent != null) {
827 mAppsCustomizeContent.surrender();
828 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800829 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700830 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700831
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800832 // We can't hide the IME if it was forced open. So don't bother
833 /*
834 @Override
835 public void onWindowFocusChanged(boolean hasFocus) {
836 super.onWindowFocusChanged(hasFocus);
837
838 if (hasFocus) {
839 final InputMethodManager inputManager = (InputMethodManager)
840 getSystemService(Context.INPUT_METHOD_SERVICE);
841 WindowManager.LayoutParams lp = getWindow().getAttributes();
842 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
843 android.os.Handler()) {
844 protected void onReceiveResult(int resultCode, Bundle resultData) {
845 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
846 }
847 });
848 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
849 }
850 }
851 */
852
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800853 private boolean acceptFilter() {
854 final InputMethodManager inputManager = (InputMethodManager)
855 getSystemService(Context.INPUT_METHOD_SERVICE);
856 return !inputManager.isFullscreenMode();
857 }
858
859 @Override
860 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700861 final int uniChar = event.getUnicodeChar();
862 final boolean handled = super.onKeyDown(keyCode, event);
863 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
864 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800865 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
866 keyCode, event);
867 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700868 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700869 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700870 // showSearchDialog()
871 // If there are multiple keystrokes before the search dialog takes focus,
872 // onSearchRequested() will be called for every keystroke,
873 // but it is idempotent, so it's fine.
874 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800875 }
876 }
877
Joe Onorato8a9625e2010-01-28 15:55:35 -0800878 // Eat the long press event so the keyboard doesn't come up.
879 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
880 return true;
881 }
882
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800883 return handled;
884 }
885
Karl Rosaen138a0412009-04-23 19:00:21 -0700886 private String getTypedText() {
887 return mDefaultKeySsb.toString();
888 }
889
890 private void clearTypedText() {
891 mDefaultKeySsb.clear();
892 mDefaultKeySsb.clearSpans();
893 Selection.setSelection(mDefaultKeySsb, 0);
894 }
895
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800896 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700897 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
898 * State
899 */
900 private static State intToState(int stateOrdinal) {
901 State state = State.WORKSPACE;
902 final State[] stateValues = State.values();
903 for (int i = 0; i < stateValues.length; i++) {
904 if (stateValues[i].ordinal() == stateOrdinal) {
905 state = stateValues[i];
906 break;
907 }
908 }
909 return state;
910 }
911
912 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800913 * Restores the previous state, if it exists.
914 *
915 * @param savedState The previous state.
916 */
917 private void restoreState(Bundle savedState) {
918 if (savedState == null) {
919 return;
920 }
921
Michael Jurka883f55b2010-10-21 15:47:14 -0700922 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700923 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700924 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -0800925 }
926
Winson Chungf0c6ae02012-03-21 16:10:31 -0700927 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800928 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700929 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800930 }
931
Winson Chung3d503fb2011-07-13 17:25:49 -0700932 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
933 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700934
Winson Chung3d503fb2011-07-13 17:25:49 -0700935 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
936 mPendingAddInfo.container = pendingAddContainer;
937 mPendingAddInfo.screen = pendingAddScreen;
938 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
939 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700940 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
941 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
942 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -0700943 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800944 mRestoring = true;
945 }
946
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700947
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800948 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
949 if (renameFolder) {
950 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700951 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800952 mRestoring = true;
953 }
Winson Chunga12a2502010-12-20 14:41:35 -0800954
Winson Chung785d2eb2011-04-14 16:08:02 -0700955
956 // Restore the AppsCustomize tab
957 if (mAppsCustomizeTabHost != null) {
958 String curTab = savedState.getString("apps_customize_currentTab");
959 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -0700960 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -0700961 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -0700962 mAppsCustomizeContent.loadAssociatedPages(
963 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700964 }
965
Winson Chung5afbf7b2011-07-25 11:53:08 -0700966 int currentIndex = savedState.getInt("apps_customize_currentIndex");
967 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700968 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800969 }
970
971 /**
972 * Finds all the views we need and configure them properly.
973 */
974 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700975 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400976
Craig Mautner360310b2012-10-26 15:13:08 -0700977 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -0700978 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
979 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -0700980 mQsbDivider = findViewById(R.id.qsb_divider);
981 mDockDivider = findViewById(R.id.dock_divider);
982
983 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
984 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800985
Winson Chung4c98d922011-05-31 16:50:48 -0700986 // Setup the drag layer
987 mDragLayer.setup(this, dragController);
988
Winson Chung3d503fb2011-07-13 17:25:49 -0700989 // Setup the hotseat
990 mHotseat = (Hotseat) findViewById(R.id.hotseat);
991 if (mHotseat != null) {
992 mHotseat.setup(this);
993 }
994
Winson Chung4c98d922011-05-31 16:50:48 -0700995 // Setup the workspace
996 mWorkspace.setHapticFeedbackEnabled(false);
997 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700998 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700999 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001000
Winson Chungf0ea4d32011-06-06 14:27:16 -07001001 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001002 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001003
Winson Chungf0ea4d32011-06-06 14:27:16 -07001004 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001005 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001006 mAppsCustomizeContent = (AppsCustomizePagedView)
1007 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1008 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001009
Winson Chung3d503fb2011-07-13 17:25:49 -07001010 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001011 dragController.setDragScoller(mWorkspace);
1012 dragController.setScrollView(mDragLayer);
1013 dragController.setMoveTarget(mWorkspace);
1014 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001015 if (mSearchDropTargetBar != null) {
1016 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001017 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001018 }
1019
1020 /**
1021 * Creates a view representing a shortcut.
1022 *
1023 * @param info The data structure describing the shortcut.
1024 *
1025 * @return A View inflated from R.layout.application.
1026 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001027 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001028 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001029 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001030 }
1031
1032 /**
1033 * Creates a view representing a shortcut inflated from the specified resource.
1034 *
1035 * @param layoutResId The id of the XML layout used to create the shortcut.
1036 * @param parent The group the shortcut belongs to.
1037 * @param info The data structure describing the shortcut.
1038 *
1039 * @return A View inflated from layoutResId.
1040 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001041 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001042 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1043 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001044 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001045 return favorite;
1046 }
1047
1048 /**
1049 * Add an application shortcut to the workspace.
1050 *
1051 * @param data The intent describing the application.
1052 * @param cellInfo The position on screen where to create the shortcut.
1053 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001054 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001055 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -07001056 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001057
Adam Cohenfbba09b2011-07-18 21:43:05 -07001058 // First we check if we already know the exact location where we want to add this item.
1059 if (cellX >= 0 && cellY >= 0) {
1060 cellXY[0] = cellX;
1061 cellXY[1] = cellY;
1062 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001063 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001064 return;
1065 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001066
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001067 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001068
Romain Guy73b979d2009-06-09 12:57:21 -07001069 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001070 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001071 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001072 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -07001073 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001074 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001075 } else {
1076 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001077 }
1078 }
Romain Guycbb89e42009-06-08 15:52:54 -07001079
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001080 /**
1081 * Add a shortcut to the workspace.
1082 *
1083 * @param data The intent describing the shortcut.
1084 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001085 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001086 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
1087 int cellY) {
1088 int[] cellXY = mTmpAddItemCellCoordinates;
1089 int[] touchXY = mPendingAddInfo.dropPos;
1090 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001091
Michael Jurkad3ef3062010-11-23 16:23:58 -08001092 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001093
Adam Cohen558baaf2011-08-15 15:22:57 -07001094 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001095 if (info == null) {
1096 return;
1097 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001098 final View view = createShortcut(info);
1099
Adam Cohenfbba09b2011-07-18 21:43:05 -07001100 // First we check if we already know the exact location where we want to add this item.
1101 if (cellX >= 0 && cellY >= 0) {
1102 cellXY[0] = cellX;
1103 cellXY[1] = cellY;
1104 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001105
1106 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001107 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001108 true, null,null)) {
1109 return;
1110 }
1111 DragObject dragObject = new DragObject();
1112 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001113 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1114 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001115 return;
1116 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001117 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001118 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001119 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001120 foundCellSpan = (result != null);
1121 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001122 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001123 }
1124
1125 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001126 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001127 return;
1128 }
1129
Adam Cohen558baaf2011-08-15 15:22:57 -07001130 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001131
1132 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001133 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
1134 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001135 }
1136 }
1137
Adam Cohen2f093b62012-04-30 18:59:53 -07001138 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1139 int minHeight) {
1140 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001141 // We want to account for the extra amount of padding that we are adding to the widget
1142 // to ensure that it gets the full amount of space that it has requested
1143 int requiredWidth = minWidth + padding.left + padding.right;
1144 int requiredHeight = minHeight + padding.top + padding.bottom;
Adam Cohen2f093b62012-04-30 18:59:53 -07001145 return CellLayout.rectToCell(context.getResources(), requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001146 }
1147
Adam Cohen2f093b62012-04-30 18:59:53 -07001148 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1149 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001150 }
1151
Adam Cohen2f093b62012-04-30 18:59:53 -07001152 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1153 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001154 }
1155
Adam Cohen2f093b62012-04-30 18:59:53 -07001156 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1157 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001158 }
1159
Adam Cohen2f093b62012-04-30 18:59:53 -07001160 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1161 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001162 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001163 }
1164
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001165 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001166 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001167 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001168 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001169 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001170 */
Adam Cohened66b2b2012-01-23 17:28:51 -08001171 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
1172 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1173 if (appWidgetInfo == null) {
1174 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1175 }
Romain Guycbb89e42009-06-08 15:52:54 -07001176
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001177 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -07001178 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -07001179
Adam Cohen2f093b62012-04-30 18:59:53 -07001180 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1181 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001182
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001183 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001184 // We have saved the position to which the widget was dragged-- this really only matters
1185 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001186 int[] cellXY = mTmpAddItemCellCoordinates;
1187 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001188 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001189 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001190 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1191 cellXY[0] = mPendingAddInfo.cellX;
1192 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001193 spanXY[0] = mPendingAddInfo.spanX;
1194 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001195 foundCellSpan = true;
1196 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001197 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001198 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001199 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1200 spanXY[1], cellXY, finalSpan);
1201 spanXY[0] = finalSpan[0];
1202 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001203 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001204 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001205 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001206 }
1207
Michael Jurka0280c3b2010-09-17 15:00:07 -07001208 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001209 if (appWidgetId != -1) {
1210 // Deleting an app widget ID is a void call but writes to disk before returning
1211 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001212 new Thread("deleteAppWidgetId") {
1213 public void run() {
1214 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1215 }
1216 }.start();
1217 }
Winson Chung93eef082012-03-23 15:59:27 -07001218 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001219 return;
1220 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001221
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001222 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001223 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1224 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001225 launcherInfo.spanX = spanXY[0];
1226 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001227 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1228 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001229
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001230 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001231 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232
1233 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001234 if (hostView == null) {
1235 // Perform actual inflation because we're live
1236 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1237 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1238 } else {
1239 // The AppWidgetHostView has already been inflated and instantiated
1240 launcherInfo.hostView = hostView;
1241 }
Romain Guycbb89e42009-06-08 15:52:54 -07001242
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001243 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001244 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001245 launcherInfo.notifyWidgetSizeChanged(this);
1246
Winson Chung3d503fb2011-07-13 17:25:49 -07001247 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001248 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001249
1250 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001251 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001252 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001253 }
Romain Guycbb89e42009-06-08 15:52:54 -07001254
Adam Cohended9f8d2010-11-03 13:25:16 -07001255 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1256 @Override
1257 public void onReceive(Context context, Intent intent) {
1258 final String action = intent.getAction();
1259 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1260 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001261 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001262 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001263
Winson Chungc100e8e2011-08-09 16:02:43 -07001264 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001265 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001266 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1267 mAppsCustomizeTabHost.reset();
1268 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001269 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001270 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1271 mUserPresent = true;
1272 updateRunning();
1273 }
1274 }
1275 };
1276
1277 @Override
1278 public void onAttachedToWindow() {
1279 super.onAttachedToWindow();
1280
1281 // Listen for broadcasts related to user-presence
1282 final IntentFilter filter = new IntentFilter();
1283 filter.addAction(Intent.ACTION_SCREEN_OFF);
1284 filter.addAction(Intent.ACTION_USER_PRESENT);
1285 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001286 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001287 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001288 mVisible = true;
1289 }
1290
1291 @Override
1292 public void onDetachedFromWindow() {
1293 super.onDetachedFromWindow();
1294 mVisible = false;
1295
Adam Cohend113e0c2010-11-11 10:48:05 -08001296 if (mAttached) {
1297 unregisterReceiver(mReceiver);
1298 mAttached = false;
1299 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001300 updateRunning();
1301 }
1302
1303 public void onWindowVisibilityChanged(int visibility) {
1304 mVisible = visibility == View.VISIBLE;
1305 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001306 // The following code used to be in onResume, but it turns out onResume is called when
1307 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1308 // is a more appropriate event to handle
1309 if (mVisible) {
1310 mAppsCustomizeTabHost.onWindowVisible();
1311 if (!mWorkspaceLoading) {
1312 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001313 // We want to let Launcher draw itself at least once before we force it to build
1314 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001315 // apps is nice and speedy.
1316 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001317 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001318 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001319 if (mStarted) return;
1320 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001321 // We delay the layer building a bit in order to give
1322 // other message processing a time to run. In particular
1323 // this avoids a delay in hiding the IME if it was
1324 // currently shown, because doing that may involve
1325 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001326 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001327 final ViewTreeObserver.OnDrawListener listener = this;
1328 mWorkspace.post(new Runnable() {
1329 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001330 if (mWorkspace != null &&
1331 mWorkspace.getViewTreeObserver() != null) {
1332 mWorkspace.getViewTreeObserver().
1333 removeOnDrawListener(listener);
1334 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001335 }
1336 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001337 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001338 }
1339 });
1340 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001341 // When Launcher comes back to foreground, a different Activity might be responsible for
1342 // the app market intent, so refresh the icon
1343 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001344 clearTypedText();
1345 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001346 }
1347
1348 private void sendAdvanceMessage(long delay) {
1349 mHandler.removeMessages(ADVANCE_MSG);
1350 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1351 mHandler.sendMessageDelayed(msg, delay);
1352 mAutoAdvanceSentTime = System.currentTimeMillis();
1353 }
1354
1355 private void updateRunning() {
1356 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1357 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1358 mAutoAdvanceRunning = autoAdvanceRunning;
1359 if (autoAdvanceRunning) {
1360 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1361 sendAdvanceMessage(delay);
1362 } else {
1363 if (!mWidgetsToAdvance.isEmpty()) {
1364 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1365 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1366 }
1367 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001368 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001369 }
1370 }
1371 }
1372
1373 private final Handler mHandler = new Handler() {
1374 @Override
1375 public void handleMessage(Message msg) {
1376 if (msg.what == ADVANCE_MSG) {
1377 int i = 0;
1378 for (View key: mWidgetsToAdvance.keySet()) {
1379 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1380 final int delay = mAdvanceStagger * i;
1381 if (v instanceof Advanceable) {
1382 postDelayed(new Runnable() {
1383 public void run() {
1384 ((Advanceable) v).advance();
1385 }
1386 }, delay);
1387 }
1388 i++;
1389 }
1390 sendAdvanceMessage(mAdvanceInterval);
1391 }
1392 }
1393 };
1394
1395 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001396 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001397 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1398 if (v instanceof Advanceable) {
1399 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001400 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001401 updateRunning();
1402 }
1403 }
1404
1405 void removeWidgetToAutoAdvance(View hostView) {
1406 if (mWidgetsToAdvance.containsKey(hostView)) {
1407 mWidgetsToAdvance.remove(hostView);
1408 updateRunning();
1409 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001410 }
1411
Joe Onorato9c1289c2009-08-17 11:03:03 -04001412 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001413 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001414 launcherInfo.hostView = null;
1415 }
1416
Winson Chung93eef082012-03-23 15:59:27 -07001417 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1418 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1419 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001420 }
1421
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001422 public LauncherAppWidgetHost getAppWidgetHost() {
1423 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001424 }
Romain Guycbb89e42009-06-08 15:52:54 -07001425
Winson Chunga9abd0e2010-10-27 17:18:37 -07001426 public LauncherModel getModel() {
1427 return mModel;
1428 }
1429
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001430 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001431 getWindow().closeAllPanels();
1432
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001433 // Whatever we were doing is hereby canceled.
1434 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001435 }
1436
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001437 @Override
1438 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001439 long startTime = 0;
1440 if (DEBUG_RESUME_TIME) {
1441 startTime = System.currentTimeMillis();
1442 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001443 super.onNewIntent(intent);
1444
1445 // Close the menu
1446 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001447 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001448 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001449
Jamie Genniscb222e82012-10-23 15:44:26 -07001450 final boolean alreadyOnHome =
1451 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001452 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001453
Jamie Genniscb222e82012-10-23 15:44:26 -07001454 Runnable processIntent = new Runnable() {
1455 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001456 if (mWorkspace == null) {
1457 // Can be cases where mWorkspace is null, this prevents a NPE
1458 return;
1459 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001460 Folder openFolder = mWorkspace.getOpenFolder();
1461 // In all these cases, only animate if we're already on home
1462 mWorkspace.exitWidgetResizeMode();
1463 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1464 openFolder == null) {
1465 mWorkspace.moveToDefaultScreen(true);
1466 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001467
Jamie Genniscb222e82012-10-23 15:44:26 -07001468 closeFolder();
1469 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001470
Jamie Genniscb222e82012-10-23 15:44:26 -07001471 // If we are already on home, then just animate back to the workspace,
1472 // otherwise, just wait until onResume to set the state back to Workspace
1473 if (alreadyOnHome) {
1474 showWorkspace(true);
1475 } else {
1476 mOnResumeState = State.WORKSPACE;
1477 }
1478
1479 final View v = getWindow().peekDecorView();
1480 if (v != null && v.getWindowToken() != null) {
1481 InputMethodManager imm = (InputMethodManager)getSystemService(
1482 INPUT_METHOD_SERVICE);
1483 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1484 }
1485
1486 // Reset AllApps to its initial state
1487 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
1488 mAppsCustomizeTabHost.reset();
1489 }
1490 }
1491 };
1492
1493 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1494 // Delay processing of the intent to allow the status bar animation to finish
1495 // first in order to avoid janky animations.
1496 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001497 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001498 // Process the intent immediately.
1499 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001500 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001501
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001502 }
Michael Jurka447bf842013-05-15 14:52:15 +02001503 if (DEBUG_RESUME_TIME) {
1504 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1505 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001506 }
1507
1508 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001509 public void onRestoreInstanceState(Bundle state) {
1510 super.onRestoreInstanceState(state);
1511 for (int page: mSynchronouslyBoundPages) {
1512 mWorkspace.restoreInstanceStateForChild(page);
1513 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001514 }
1515
1516 @Override
1517 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001518 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001519 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001520
Michael Jurka883f55b2010-10-21 15:47:14 -07001521 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001522 // We close any open folder since it will not be re-opened, and we need to make sure
1523 // this state is reflected.
1524 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001525
Winson Chung3d503fb2011-07-13 17:25:49 -07001526 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1527 mWaitingForResult) {
1528 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1529 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1530 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1531 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001532 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1533 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1534 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001535 }
1536
1537 if (mFolderInfo != null && mWaitingForResult) {
1538 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1539 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1540 }
Michael Jurka946ad472010-07-09 18:05:18 -07001541
Winson Chung785d2eb2011-04-14 16:08:02 -07001542 // Save the current AppsCustomize tab
1543 if (mAppsCustomizeTabHost != null) {
1544 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1545 if (currentTabTag != null) {
1546 outState.putString("apps_customize_currentTab", currentTabTag);
1547 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001548 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1549 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001550 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001551 }
1552
1553 @Override
1554 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001555 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001556
Winson Chunge7a03942011-08-05 15:05:12 -07001557 // Remove all pending runnables
1558 mHandler.removeMessages(ADVANCE_MSG);
1559 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001560 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001561
Winson Chungcd2b0142011-06-08 16:02:26 -07001562 // Stop callbacks from LauncherModel
1563 LauncherApplication app = ((LauncherApplication) getApplication());
1564 mModel.stopLoader();
1565 app.setLauncher(null);
1566
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001567 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001568 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001569 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001570 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001571 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001572 mAppWidgetHost = null;
1573
1574 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001575
1576 TextKeyListener.getInstance().release();
1577
Winson Chung81b52252012-08-27 15:34:29 -07001578 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1579 // to prevent leaking Launcher activities on orientation change.
1580 if (mModel != null) {
1581 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1582 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001583
1584 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001585 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001586
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001587 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001588 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1589 mWorkspace.removeAllViews();
1590 mWorkspace = null;
1591 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001592
Michael Jurka2ecf9952012-06-18 12:52:28 -07001593 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001594 }
1595
Adam Cohena9cf38f2011-05-02 15:36:58 -07001596 public DragController getDragController() {
1597 return mDragController;
1598 }
1599
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001600 @Override
1601 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001602 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001603 super.startActivityForResult(intent, requestCode);
1604 }
1605
Winson Chung70d72102011-08-12 11:24:35 -07001606 /**
1607 * Indicates that we want global search for this activity by setting the globalSearch
1608 * argument for {@link #startSearch} to true.
1609 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001610 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001611 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001612 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001613
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001614 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001615
Karl Rosaen138a0412009-04-23 19:00:21 -07001616 if (initialQuery == null) {
1617 // Use any text typed in the launcher as the initial query
1618 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001619 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001620 if (appSearchData == null) {
1621 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001622 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001623 }
Winson Chungadf0c182012-08-23 14:59:07 -07001624 Rect sourceBounds = new Rect();
1625 if (mSearchDropTargetBar != null) {
1626 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1627 }
Romain Guycbb89e42009-06-08 15:52:54 -07001628
Michael Jurkaa33411c2012-06-14 16:18:21 -07001629 startGlobalSearch(initialQuery, selectInitialQuery,
1630 appSearchData, sourceBounds);
1631 }
1632
1633 /**
1634 * Starts the global search activity. This code is a copied from SearchManager
1635 */
1636 public void startGlobalSearch(String initialQuery,
1637 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001638 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001639 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1640 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1641 if (globalSearchActivity == null) {
1642 Log.w(TAG, "No global search activity found.");
1643 return;
1644 }
1645 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1646 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1647 intent.setComponent(globalSearchActivity);
1648 // Make sure that we have a Bundle to put source in
1649 if (appSearchData == null) {
1650 appSearchData = new Bundle();
1651 } else {
1652 appSearchData = new Bundle(appSearchData);
1653 }
1654 // Set source to package name of app that starts global search, if not set already.
1655 if (!appSearchData.containsKey("source")) {
1656 appSearchData.putString("source", getPackageName());
1657 }
1658 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1659 if (!TextUtils.isEmpty(initialQuery)) {
1660 intent.putExtra(SearchManager.QUERY, initialQuery);
1661 }
1662 if (selectInitialQuery) {
1663 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1664 }
1665 intent.setSourceBounds(sourceBounds);
1666 try {
1667 startActivity(intent);
1668 } catch (ActivityNotFoundException ex) {
1669 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1670 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001671 }
1672
Winson Chung70d72102011-08-12 11:24:35 -07001673 @Override
1674 public boolean onCreateOptionsMenu(Menu menu) {
1675 if (isWorkspaceLocked()) {
1676 return false;
1677 }
1678
1679 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001680
1681 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1682 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1683 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001684 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1685 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1686 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001687 String helpUrl = getString(R.string.help_url);
1688 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001689 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1690 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1691
Winson Chung70d72102011-08-12 11:24:35 -07001692 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1693 .setIcon(android.R.drawable.ic_menu_gallery)
1694 .setAlphabeticShortcut('W');
1695 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1696 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001697 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001698 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001699 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1700 .setIcon(android.R.drawable.ic_menu_preferences)
1701 .setIntent(settings)
1702 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001703 if (!helpUrl.isEmpty()) {
1704 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1705 .setIcon(android.R.drawable.ic_menu_help)
1706 .setIntent(help)
1707 .setAlphabeticShortcut('H');
1708 }
Winson Chung70d72102011-08-12 11:24:35 -07001709 return true;
1710 }
1711
1712 @Override
1713 public boolean onPrepareOptionsMenu(Menu menu) {
1714 super.onPrepareOptionsMenu(menu);
1715
1716 if (mAppsCustomizeTabHost.isTransitioning()) {
1717 return false;
1718 }
1719 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1720 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1721
1722 return true;
1723 }
1724
1725 @Override
1726 public boolean onOptionsItemSelected(MenuItem item) {
1727 switch (item.getItemId()) {
1728 case MENU_WALLPAPER_SETTINGS:
1729 startWallpaper();
1730 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001731 }
1732
1733 return super.onOptionsItemSelected(item);
1734 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001735
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001736 @Override
1737 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001738 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001739 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001740 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001741 }
1742
Joe Onorato9c1289c2009-08-17 11:03:03 -04001743 public boolean isWorkspaceLocked() {
1744 return mWorkspaceLoading || mWaitingForResult;
1745 }
1746
Michael Jurka0280c3b2010-09-17 15:00:07 -07001747 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001748 mPendingAddInfo.container = ItemInfo.NO_ID;
1749 mPendingAddInfo.screen = -1;
1750 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1751 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001752 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001753 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001754 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001755
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001756 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1757 AppWidgetProviderInfo appWidgetInfo) {
1758 if (appWidgetInfo.configure != null) {
1759 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001760
Bjorn Bringert7984c942009-12-09 15:38:25 +00001761 // Launch over to configure widget, if needed
1762 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001763 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001764 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Romain Guy8e633c52010-03-04 12:51:36 -08001765 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001766 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001767 // Otherwise just add it
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001768 completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget,
1769 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001770 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001771 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001772 }
1773 }
Romain Guycbb89e42009-06-08 15:52:54 -07001774
Adam Cohenfbba09b2011-07-18 21:43:05 -07001775 /**
1776 * Process a shortcut drop.
1777 *
1778 * @param componentName The name of the component
1779 * @param screen The screen where it should be added
1780 * @param cell The cell it should be added to, optional
1781 * @param position The location on the screen where it was dropped, optional
1782 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001783 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1784 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001785 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001786 mPendingAddInfo.container = container;
1787 mPendingAddInfo.screen = screen;
1788 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001789
1790 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001791 mPendingAddInfo.cellX = cell[0];
1792 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001793 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001794
1795 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1796 createShortcutIntent.setComponent(componentName);
1797 processShortcut(createShortcutIntent);
1798 }
1799
Adam Cohenfbba09b2011-07-18 21:43:05 -07001800 /**
1801 * Process a widget drop.
1802 *
1803 * @param info The PendingAppWidgetInfo of the widget being added.
1804 * @param screen The screen where it should be added
1805 * @param cell The cell it should be added to, optional
1806 * @param position The location on the screen where it was dropped, optional
1807 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001808 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
Adam Cohend41fbf52012-02-16 23:53:59 -08001809 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001810 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001811 mPendingAddInfo.container = info.container = container;
1812 mPendingAddInfo.screen = info.screen = screen;
1813 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001814 mPendingAddInfo.minSpanX = info.minSpanX;
1815 mPendingAddInfo.minSpanY = info.minSpanY;
1816
Adam Cohenfbba09b2011-07-18 21:43:05 -07001817 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001818 mPendingAddInfo.cellX = cell[0];
1819 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001820 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001821 if (span != null) {
1822 mPendingAddInfo.spanX = span[0];
1823 mPendingAddInfo.spanY = span[1];
1824 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001825
Adam Cohened66b2b2012-01-23 17:28:51 -08001826 AppWidgetHostView hostView = info.boundWidget;
1827 int appWidgetId;
1828 if (hostView != null) {
1829 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001830 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001831 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001832 // In this case, we either need to start an activity to get permission to bind
1833 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001834 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001835 Bundle options = info.bindOptions;
1836
1837 boolean success = false;
1838 if (options != null) {
1839 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1840 info.componentName, options);
1841 } else {
1842 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1843 info.componentName);
1844 }
1845 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001846 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001847 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001848 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001849 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1850 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1851 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07001852 // TODO: we need to make sure that this accounts for the options bundle.
1853 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07001854 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1855 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001856 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001857 }
1858
Joe Onoratodeb98af2010-02-19 14:59:39 -08001859 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001860 // Handle case where user selected "Applications"
1861 String applicationName = getResources().getString(R.string.group_applications);
1862 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001863
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001864 if (applicationName != null && applicationName.equals(shortcutName)) {
1865 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1866 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001867
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001868 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1869 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001870 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001871 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001872 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001873 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001874 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001875 }
1876
Winson Chung24ab2f12010-09-16 14:10:47 -07001877 void processWallpaper(Intent intent) {
1878 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1879 }
1880
Winson Chung3d503fb2011-07-13 17:25:49 -07001881 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1882 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001883 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001884 folderInfo.title = getText(R.string.folder_name);
1885
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001886 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001887 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1888 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001889 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001890
1891 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001892 FolderIcon newFolder =
1893 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1894 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1895 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001896 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001897 }
Romain Guycbb89e42009-06-08 15:52:54 -07001898
Joe Onorato9c1289c2009-08-17 11:03:03 -04001899 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001900 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001901 }
1902
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001903 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001904 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001905 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001906 Intent chooser = Intent.createChooser(pickWallpaper,
1907 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001908 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1909 // Removed in Eclair MR1
1910// WallpaperManager wm = (WallpaperManager)
1911// getSystemService(Context.WALLPAPER_SERVICE);
1912// WallpaperInfo wi = wm.getWallpaperInfo();
1913// if (wi != null && wi.getSettingsActivity() != null) {
1914// LabeledIntent li = new LabeledIntent(getPackageName(),
1915// R.string.configure_wallpaper, 0);
1916// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1917// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1918// }
Mike Clerona0618e42009-10-22 13:55:21 -07001919 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001920 }
1921
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001922 /**
1923 * Registers various content observers. The current implementation registers
1924 * only a favorites observer to keep track of the favorites applications.
1925 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001926 private void registerContentObservers() {
1927 ContentResolver resolver = getContentResolver();
1928 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1929 true, mWidgetObserver);
1930 }
1931
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001932 @Override
1933 public boolean dispatchKeyEvent(KeyEvent event) {
1934 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1935 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001936 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001937 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001938 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08001939 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08001940 dumpState();
1941 return true;
1942 }
1943 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001944 }
1945 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1946 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001947 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001948 return true;
1949 }
1950 }
1951
1952 return super.dispatchKeyEvent(event);
1953 }
1954
Joe Onorato88ec0992009-11-19 13:16:06 -08001955 @Override
1956 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001957 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001958 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001959 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001960 Folder openFolder = mWorkspace.getOpenFolder();
1961 if (openFolder.isEditingName()) {
1962 openFolder.dismissEditingName();
1963 } else {
1964 closeFolder();
1965 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001966 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001967 mWorkspace.exitWidgetResizeMode();
1968
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001969 // Back button is a no-op here, but give at least some feedback for the button press
1970 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001971 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001972 }
1973
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001974 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001975 * Re-listen when widgets are reset.
1976 */
1977 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001978 if (mAppWidgetHost != null) {
1979 mAppWidgetHost.startListening();
1980 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001981 }
1982
1983 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001984 * Launches the intent referred by the clicked shortcut.
1985 *
1986 * @param v The view representing the clicked shortcut.
1987 */
1988 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001989 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1990 // view has detached (it's possible for this to happen if the view is removed mid touch).
1991 if (v.getWindowToken() == null) {
1992 return;
1993 }
1994
Winson Chung9b0b2fe2012-02-24 13:03:34 -08001995 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001996 return;
1997 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001998
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001999 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002000 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002001 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08002002 final Intent intent = ((ShortcutInfo) tag).intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002003
2004 ComponentName widgetComp = new ComponentName(this, WidgetAdder.class);
2005 if (intent.getComponent().getClassName().equals(widgetComp.getClassName())) {
2006 showAllApps(true);
2007 return;
2008 }
Joe Onorato13724ea2009-12-02 21:16:35 -08002009 int[] pos = new int[2];
2010 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002011 intent.setSourceBounds(new Rect(pos[0], pos[1],
2012 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002013
2014 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002015
2016 if (success && v instanceof BubbleTextView) {
2017 mWaitingForResume = (BubbleTextView) v;
2018 mWaitingForResume.setStayPressed(true);
2019 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002020 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002021 if (v instanceof FolderIcon) {
2022 FolderIcon fi = (FolderIcon) v;
2023 handleFolderClick(fi);
2024 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002025 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002026 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002027 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002028 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002029 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002030 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031 }
2032 }
2033
Michael Jurka0e260592010-06-30 17:07:39 -07002034 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07002035 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002036 // clicking anywhere on the workspace causes the customization drawer to slide down
2037 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07002038 return false;
2039 }
2040
Michael Jurkaaf442092010-06-10 17:01:57 -07002041 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002042 * Event handler for the search button
2043 *
2044 * @param v The view that was clicked.
2045 */
2046 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002047 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2048
Amith Yamasania135ba82011-08-09 17:42:01 -07002049 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002050 }
2051
2052 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002053 * Event handler for the voice button
2054 *
2055 * @param v The view that was clicked.
2056 */
2057 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002058 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002059
Michael Jurkaae65ee32012-04-30 11:45:54 -07002060 try {
2061 final SearchManager searchManager =
2062 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2063 ComponentName activityName = searchManager.getGlobalSearchActivity();
2064 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002065 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002066 if (activityName != null) {
2067 intent.setPackage(activityName.getPackageName());
2068 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002069 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002070 } catch (ActivityNotFoundException e) {
2071 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002072 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002073 startActivitySafely(null, intent, "onClickVoiceButton");
2074 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002075 }
2076
2077 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002078 * Event handler for the "grid" button that appears on the home screen, which
2079 * enters all apps mode.
2080 *
2081 * @param v The view that was clicked.
2082 */
2083 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07002084 showAllApps(true);
2085 }
2086
2087 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002088 // Provide the same haptic feedback that the system offers for virtual keys.
2089 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002090 }
2091
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002092 public void onClickAppMarketButton(View v) {
2093 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002094 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002095 } else {
2096 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002097 }
2098 }
2099
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002100 void startApplicationDetailsActivity(ComponentName componentName) {
2101 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002102 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2103 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002104 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002105 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002106 }
2107
Patrick Dubroy5539af72010-09-07 15:22:01 -07002108 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
2109 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
2110 // System applications cannot be installed. For now, show a toast explaining that.
2111 // We may give them the option of disabling apps this way.
2112 int messageId = R.string.uninstall_system_app_text;
2113 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
2114 } else {
2115 String packageName = appInfo.componentName.getPackageName();
2116 String className = appInfo.componentName.getClassName();
2117 Intent intent = new Intent(
2118 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002119 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2120 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002121 startActivity(intent);
2122 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002123 }
2124
Michael Jurka86a720e2012-05-09 11:23:23 -07002125 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002126 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002127
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002128 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002129 // Only launch using the new animation if the shortcut has not opted out (this is a
2130 // private contract between launcher and may be ignored in the future).
2131 boolean useLaunchAnimation = (v != null) &&
2132 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2133 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002134 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2135 v.getMeasuredWidth(), v.getMeasuredHeight());
2136
2137 startActivity(intent, opts.toBundle());
2138 } else {
2139 startActivity(intent);
2140 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002141 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002142 } catch (SecurityException e) {
2143 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002144 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002145 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002146 "or use the exported attribute for this activity. "
2147 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002148 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002149 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002150 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002151
Michael Jurka86a720e2012-05-09 11:23:23 -07002152 boolean startActivitySafely(View v, Intent intent, Object tag) {
2153 boolean success = false;
2154 try {
2155 success = startActivity(v, intent, tag);
2156 } catch (ActivityNotFoundException e) {
2157 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2158 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2159 }
2160 return success;
2161 }
2162
Romain Guy8e633c52010-03-04 12:51:36 -08002163 void startActivityForResultSafely(Intent intent, int requestCode) {
2164 try {
2165 startActivityForResult(intent, requestCode);
2166 } catch (ActivityNotFoundException e) {
2167 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2168 } catch (SecurityException e) {
2169 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2170 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2171 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2172 "or use the exported attribute for this activity.", e);
2173 }
2174 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002175
Adam Cohena9cf38f2011-05-02 15:36:58 -07002176 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002177 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002178 Folder openFolder = mWorkspace.getFolderForTag(info);
2179
2180 // If the folder info reports that the associated folder is open, then verify that
2181 // it is actually opened. There have been a few instances where this gets out of sync.
2182 if (info.opened && openFolder == null) {
2183 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2184 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
2185 info.opened = false;
2186 }
2187
Adam Cohenfb91f302012-06-11 15:45:18 -07002188 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002189 // Close any open folder
2190 closeFolder();
2191 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002192 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002193 } else {
2194 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002195 int folderScreen;
2196 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002197 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002198 // .. and close it
2199 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002200 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002201 // Close any folder open on the current screen
2202 closeFolder();
2203 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002204 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002205 }
2206 }
2207 }
2208 }
2209
Adam Cohen268c4752012-06-06 17:47:33 -07002210 /**
2211 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2212 * in the DragLayer in the exact absolute location of the original FolderIcon.
2213 */
2214 private void copyFolderIconToImage(FolderIcon fi) {
2215 final int width = fi.getMeasuredWidth();
2216 final int height = fi.getMeasuredHeight();
2217
2218 // Lazy load ImageView, Bitmap and Canvas
2219 if (mFolderIconImageView == null) {
2220 mFolderIconImageView = new ImageView(this);
2221 }
2222 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2223 mFolderIconBitmap.getHeight() != height) {
2224 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2225 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2226 }
2227
2228 DragLayer.LayoutParams lp;
2229 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2230 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2231 } else {
2232 lp = new DragLayer.LayoutParams(width, height);
2233 }
2234
Adam Cohen307fe232012-08-16 17:55:58 -07002235 // The layout from which the folder is being opened may be scaled, adjust the starting
2236 // view size by this scale factor.
2237 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002238 lp.customPosition = true;
2239 lp.x = mRectForFolderAnimation.left;
2240 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002241 lp.width = (int) (scale * width);
2242 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002243
2244 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2245 fi.draw(mFolderIconCanvas);
2246 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002247 if (fi.getFolder() != null) {
2248 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2249 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002250 }
Adam Cohen268c4752012-06-06 17:47:33 -07002251 // Just in case this image view is still in the drag layer from a previous animation,
2252 // we remove it and re-add it.
2253 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2254 mDragLayer.removeView(mFolderIconImageView);
2255 }
2256 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002257 if (fi.getFolder() != null) {
2258 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002259 }
Adam Cohen268c4752012-06-06 17:47:33 -07002260 }
2261
Adam Cohen2801caf2011-05-13 20:57:39 -07002262 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002263 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002264 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2265 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2266 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2267
Adam Cohenc51934b2011-07-26 21:07:43 -07002268 FolderInfo info = (FolderInfo) fi.getTag();
2269 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2270 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002271 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2272 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002273 }
2274
Adam Cohen268c4752012-06-06 17:47:33 -07002275 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2276 copyFolderIconToImage(fi);
2277 fi.setVisibility(View.INVISIBLE);
2278
Michael Jurka2ecf9952012-06-18 12:52:28 -07002279 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002280 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002281 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2282 oa.start();
2283 }
2284
Adam Cohen268c4752012-06-06 17:47:33 -07002285 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002286 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002287 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2288 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2289 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2290
Adam Cohen268c4752012-06-06 17:47:33 -07002291 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002292
Adam Cohen268c4752012-06-06 17:47:33 -07002293 // We remove and re-draw the FolderIcon in-case it has changed
2294 mDragLayer.removeView(mFolderIconImageView);
2295 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002296 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002297 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002298 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002299 oa.addListener(new AnimatorListenerAdapter() {
2300 @Override
2301 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002302 if (cl != null) {
2303 cl.clearFolderLeaveBehind();
2304 // Remove the ImageView copy of the FolderIcon and make the original visible.
2305 mDragLayer.removeView(mFolderIconImageView);
2306 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002307 }
2308 }
2309 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002310 oa.start();
2311 }
2312
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002313 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002314 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002315 * is animated relative to the specified View. If the View is null, no animation
2316 * is played.
2317 *
2318 * @param folderInfo The FolderInfo describing the folder to open.
2319 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002320 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002321 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002322 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002323
Adam Cohena9cf38f2011-05-02 15:36:58 -07002324 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002325
Adam Cohen4554ee12011-08-03 16:13:21 -07002326 // Just verify that the folder hasn't already been added to the DragLayer.
2327 // There was a one-off crash where the folder had a parent already.
2328 if (folder.getParent() == null) {
2329 mDragLayer.addView(folder);
2330 mDragController.addDropTarget((DropTarget) folder);
2331 } else {
2332 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2333 folder.getParent() + ").");
2334 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002335 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002336 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002337
2338 // Notify the accessibility manager that this folder "window" has appeared and occluded
2339 // the workspace items
2340 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2341 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002342 }
2343
2344 public void closeFolder() {
2345 Folder folder = mWorkspace.getOpenFolder();
2346 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002347 if (folder.isEditingName()) {
2348 folder.dismissEditingName();
2349 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002350 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002351
2352 // Dismiss the folder cling
2353 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002354 }
2355 }
2356
2357 void closeFolder(Folder folder) {
2358 folder.getInfo().opened = false;
2359
2360 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2361 if (parent != null) {
2362 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2363 shrinkAndFadeInFolderIcon(fi);
2364 }
2365 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002366
2367 // Notify the accessibility manager that this folder "window" has disappeard and no
2368 // longer occludeds the workspace items
2369 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002370 }
2371
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002372 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002373 if (!isDraggingEnabled()) return false;
2374 if (isWorkspaceLocked()) return false;
2375 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002376
2377 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002378 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002379 }
2380
Michael Jurka0280c3b2010-09-17 15:00:07 -07002381 resetAddInfo();
2382 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002383 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002384 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002385 return true;
2386 }
2387
Winson Chung3d503fb2011-07-13 17:25:49 -07002388 // The hotseat touch handling does not go through Workspace, and we always allow long press
2389 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002390 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002391 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2392 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002393 if (itemUnderLongClick == null) {
2394 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002395 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2396 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002397 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002398 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002399 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002400 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002401 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002402 }
2403 }
2404 }
2405 return true;
2406 }
2407
Winson Chung3d503fb2011-07-13 17:25:49 -07002408 boolean isHotseatLayout(View layout) {
2409 return mHotseat != null && layout != null &&
2410 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2411 }
2412 Hotseat getHotseat() {
2413 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002414 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002415 SearchDropTargetBar getSearchBar() {
2416 return mSearchDropTargetBar;
2417 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002418
Winson Chung3d503fb2011-07-13 17:25:49 -07002419 /**
2420 * Returns the CellLayout of the specified container at the specified screen.
2421 */
2422 CellLayout getCellLayout(long container, int screen) {
2423 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2424 if (mHotseat != null) {
2425 return mHotseat.getLayout();
2426 } else {
2427 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002428 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002429 } else {
2430 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002431 }
2432 }
2433
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002434 Workspace getWorkspace() {
2435 return mWorkspace;
2436 }
2437
Daniel Sandler843e8602010-06-07 14:59:01 -04002438 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
Craig Mautner360310b2012-10-26 15:13:08 -07002439 @Override
Daniel Sandler843e8602010-06-07 14:59:01 -04002440 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002441 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002442 }
2443
Craig Mautner360310b2012-10-26 15:13:08 -07002444 @Override
Andrew Flynn0dca1ec2012-02-29 13:33:22 -08002445 public boolean isAllAppsButtonRank(int rank) {
2446 return mHotseat.isAllAppsButtonRank(rank);
2447 }
2448
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002449 /**
2450 * Helper method for the cameraZoomIn/cameraZoomOut animations
2451 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002452 * @param scaleFactor The scale factor used for the zoom
2453 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002454 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002455 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002456 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002457 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002458
Winson Chung18f41f82012-05-09 13:28:10 -07002459 void disableWallpaperIfInAllApps() {
2460 // Only disable it if we are in all apps
Winson Chungc93e5ae2012-07-23 20:48:26 -07002461 if (isAllAppsVisible()) {
Winson Chung18f41f82012-05-09 13:28:10 -07002462 if (mAppsCustomizeTabHost != null &&
2463 !mAppsCustomizeTabHost.isTransitioning()) {
2464 updateWallpaperVisibility(false);
2465 }
2466 }
2467 }
2468
Craig Mautner360310b2012-10-26 15:13:08 -07002469 private void setWorkspaceBackground(boolean workspace) {
2470 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002471 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002472 }
2473
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002474 void updateWallpaperVisibility(boolean visible) {
2475 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2476 int curflags = getWindow().getAttributes().flags
2477 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2478 if (wpflags != curflags) {
2479 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2480 }
Craig Mautner360310b2012-10-26 15:13:08 -07002481 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002482 }
2483
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002484 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2485 if (v instanceof LauncherTransitionable) {
2486 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2487 }
2488 }
2489
Michael Jurkabed61d22012-02-14 22:51:29 -08002490 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2491 if (v instanceof LauncherTransitionable) {
2492 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2493 }
Winson Chung70442722012-02-10 15:43:22 -08002494
2495 // Update the workspace transition step as well
2496 dispatchOnLauncherTransitionStep(v, 0f);
2497 }
2498
2499 private void dispatchOnLauncherTransitionStep(View v, float t) {
2500 if (v instanceof LauncherTransitionable) {
2501 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2502 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002503 }
2504
2505 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2506 if (v instanceof LauncherTransitionable) {
2507 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2508 }
Winson Chung70442722012-02-10 15:43:22 -08002509
2510 // Update the workspace transition step as well
2511 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002512 }
2513
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002514 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002515 * Things to test when changing the following seven functions.
2516 * - Home from workspace
2517 * - from center screen
2518 * - from other screens
2519 * - Home from all apps
2520 * - from center screen
2521 * - from other screens
2522 * - Back from all apps
2523 * - from center screen
2524 * - from other screens
2525 * - Launch app from workspace and quit
2526 * - with back
2527 * - with home
2528 * - Launch app from all apps and quit
2529 * - with back
2530 * - with home
2531 * - Go to a screen that's not the default, then all
2532 * apps, and launch and app, and go back
2533 * - with back
2534 * -with home
2535 * - On workspace, long press power and go back
2536 * - with back
2537 * - with home
2538 * - On all apps, long press power and go back
2539 * - with back
2540 * - with home
2541 * - On workspace, power off
2542 * - On all apps, power off
2543 * - Launch an app and turn off the screen while in that app
2544 * - Go back with home key
2545 * - Go back with back key TODO: make this not go to workspace
2546 * - From all apps
2547 * - From workspace
2548 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2549 * - From all apps
2550 * - From the center workspace
2551 * - From another workspace
2552 */
2553
2554 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002555 * Zoom the camera out from the workspace to reveal 'toView'.
2556 * Assumes that the view to show is anchored at either the very top or very bottom
2557 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002558 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002559 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002560 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002561 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002562 mStateAnimation.cancel();
2563 mStateAnimation = null;
2564 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002565 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002566
Winson Chungf0ea4d32011-06-06 14:27:16 -07002567 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2568 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2569 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002570 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002571 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002572 final int startDelay =
2573 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002574
Michael Jurkab3e22d92011-10-31 15:58:33 -07002575 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002576
Michael Jurkad74c9842011-07-10 12:44:21 -07002577 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002578 Animator workspaceAnim =
2579 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002580
2581 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002582 toView.setScaleX(scale);
2583 toView.setScaleY(scale);
2584 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2585 scaleAnim.
2586 scaleX(1f).scaleY(1f).
2587 setDuration(duration).
2588 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002589
Winson Chungf0ea4d32011-06-06 14:27:16 -07002590 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002591 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002592 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002593 .ofFloat(toView, "alpha", 0f, 1f)
2594 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002595 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002596 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2597 @Override
2598 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002599 if (animation == null) {
2600 throw new RuntimeException("animation is null");
2601 }
Winson Chung70442722012-02-10 15:43:22 -08002602 float t = (Float) animation.getAnimatedValue();
2603 dispatchOnLauncherTransitionStep(fromView, t);
2604 dispatchOnLauncherTransitionStep(toView, t);
2605 }
2606 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002607
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002608 // toView should appear right at the end of the workspace shrink
2609 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002610 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002611 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002612 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002613
2614 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002615 boolean animationCancelled = false;
2616
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002617 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002618 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002619 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002620 // Prepare the position
2621 toView.setTranslationX(0.0f);
2622 toView.setTranslationY(0.0f);
2623 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002624 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002625 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002626 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002627 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002628 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2629 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002630
Michael Jurkafa7969f2012-09-21 16:39:14 -07002631 if (mWorkspace != null && !springLoaded && !LauncherApplication.isScreenLarge()) {
Winson Chung32174c82011-07-19 15:47:55 -07002632 // Hide the workspace scrollbar
2633 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002634 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002635 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002636 if (!animationCancelled) {
2637 updateWallpaperVisibility(false);
2638 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002639
2640 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002641 if (mSearchDropTargetBar != null) {
2642 mSearchDropTargetBar.hideSearchBar(false);
2643 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002644 }
2645
Adam Cohencff6af82011-09-13 14:51:53 -07002646 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002647 public void onAnimationCancel(Animator animation) {
2648 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002649 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002650 });
2651
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002652 if (workspaceAnim != null) {
2653 mStateAnimation.play(workspaceAnim);
2654 }
Michael Jurka1899a362011-11-03 13:50:45 -07002655
2656 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002657
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002658 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2659 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002660
2661 // If any of the objects being animated haven't been measured/laid out
2662 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002663 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002664 (mWorkspace.getMeasuredWidth() == 0) ||
2665 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002666 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002667 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002668
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002669 final AnimatorSet stateAnimation = mStateAnimation;
2670 final Runnable startAnimRunnable = new Runnable() {
2671 public void run() {
2672 // Check that mStateAnimation hasn't changed while
2673 // we waited for a layout/draw pass
2674 if (mStateAnimation != stateAnimation)
2675 return;
2676 setPivotsForZoom(toView, scale);
2677 dispatchOnLauncherTransitionStart(fromView, animated, false);
2678 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002679 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002680 }
2681 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002682 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002683 final ViewTreeObserver observer = toView.getViewTreeObserver();
2684 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2685 public void onGlobalLayout() {
2686 startAnimRunnable.run();
2687 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2688 }
2689 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002690 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002691 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002692 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002693 } else {
2694 toView.setTranslationX(0.0f);
2695 toView.setTranslationY(0.0f);
2696 toView.setScaleX(1.0f);
2697 toView.setScaleY(1.0f);
2698 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002699 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002700
Michael Jurkabed61d22012-02-14 22:51:29 -08002701 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2702 // Hide the workspace scrollbar
2703 mWorkspace.hideScrollingIndicator(true);
2704 hideDockDivider();
Winson Chungc7d2b602012-05-16 17:02:20 -07002705
2706 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002707 if (mSearchDropTargetBar != null) {
2708 mSearchDropTargetBar.hideSearchBar(false);
2709 }
Michael Jurkaabded662011-03-04 12:06:57 -08002710 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002711 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002712 dispatchOnLauncherTransitionStart(fromView, animated, false);
2713 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002714 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002715 dispatchOnLauncherTransitionStart(toView, animated, false);
2716 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002717 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002718 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002719 }
2720
2721 /**
2722 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002723 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002724 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002725 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002726 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2727 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002728
Michael Jurkab3e22d92011-10-31 15:58:33 -07002729 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002730 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002731 mStateAnimation.cancel();
2732 mStateAnimation = null;
2733 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002734 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002735
Winson Chungf0ea4d32011-06-06 14:27:16 -07002736 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002737 final int fadeOutDuration =
2738 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002739 final float scaleFactor = (float)
2740 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2741 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002742 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002743 Animator workspaceAnim = null;
2744
2745 if (toState == State.WORKSPACE) {
2746 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2747 workspaceAnim = mWorkspace.getChangeStateAnimation(
2748 Workspace.State.NORMAL, animated, stagger);
2749 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2750 workspaceAnim = mWorkspace.getChangeStateAnimation(
2751 Workspace.State.SPRING_LOADED, animated);
2752 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002753
Michael Jurkab3e22d92011-10-31 15:58:33 -07002754 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002755 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002756 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002757 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002758 final LauncherViewPropertyAnimator scaleAnim =
2759 new LauncherViewPropertyAnimator(fromView);
2760 scaleAnim.
2761 scaleX(scaleFactor).scaleY(scaleFactor).
2762 setDuration(duration).
2763 setInterpolator(new Workspace.ZoomInInterpolator());
2764
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002765 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002766 .ofFloat(fromView, "alpha", 1f, 0f)
2767 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002768 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002769 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2770 @Override
2771 public void onAnimationUpdate(ValueAnimator animation) {
2772 float t = 1f - (Float) animation.getAnimatedValue();
2773 dispatchOnLauncherTransitionStep(fromView, t);
2774 dispatchOnLauncherTransitionStep(toView, t);
2775 }
2776 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002777
Michael Jurka2ecf9952012-06-18 12:52:28 -07002778 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002779
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002780 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2781 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002782 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002783
2784 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002785 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002786 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002787 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002788 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002789 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2790 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkabafdaaf2012-04-26 13:43:25 -07002791 if (mWorkspace != null) {
2792 mWorkspace.hideScrollingIndicator(false);
2793 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002794 if (onCompleteRunnable != null) {
2795 onCompleteRunnable.run();
2796 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002797 mAppsCustomizeContent.updateCurrentPageScroll();
2798 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002799 }
2800 });
2801
Winson Chungf0ea4d32011-06-06 14:27:16 -07002802 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002803 if (workspaceAnim != null) {
2804 mStateAnimation.play(workspaceAnim);
2805 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002806 dispatchOnLauncherTransitionStart(fromView, animated, true);
2807 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002808 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002809 } else {
2810 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002811 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002812 dispatchOnLauncherTransitionStart(fromView, animated, true);
2813 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002814 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002815 dispatchOnLauncherTransitionStart(toView, animated, true);
2816 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002817 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002818 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002819 }
2820
Michael Jurkae326f182011-11-21 14:05:46 -08002821 @Override
2822 public void onTrimMemory(int level) {
2823 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002824 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002825 mAppsCustomizeTabHost.onTrimMemory();
2826 }
2827 }
2828
Winson Chung18f41f82012-05-09 13:28:10 -07002829 @Override
2830 public void onWindowFocusChanged(boolean hasFocus) {
2831 if (!hasFocus) {
2832 // When another window occludes launcher (like the notification shade, or recents),
2833 // ensure that we enable the wallpaper flag so that transitions are done correctly.
2834 updateWallpaperVisibility(true);
2835 } else {
2836 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07002837 mWorkspace.postDelayed(new Runnable() {
2838 @Override
2839 public void run() {
2840 disableWallpaperIfInAllApps();
2841 }
2842 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07002843 }
2844 }
2845
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002846 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002847 showWorkspace(animated, null);
2848 }
2849
2850 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002851 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002852 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002853 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002854 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002855
Winson Chungc7d2b602012-05-16 17:02:20 -07002856 // Show the search bar (only animate if we were showing the drop target bar in spring
2857 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07002858 if (mSearchDropTargetBar != null) {
2859 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
2860 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002861
Michael Jurkab737ee62011-11-15 15:57:22 -08002862 // We only need to animate in the dock divider if we're going from spring loaded mode
Winson Chungc7d2b602012-05-16 17:02:20 -07002863 showDockDivider(animated && wasInSpringLoadedMode);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002864
2865 // Set focus to the AppsCustomize button
2866 if (mAllAppsButton != null) {
2867 mAllAppsButton.requestFocus();
2868 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002869 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002870
Michael Jurkab737ee62011-11-15 15:57:22 -08002871 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002872
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002873 // Change the state *after* we've called all the transition code
2874 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002875
Winson Chung5fb63472011-02-02 17:03:37 -08002876 // Resume the auto-advance of widgets
2877 mUserPresent = true;
2878 updateRunning();
2879
alanv1d4fde62012-10-17 13:15:47 -07002880 // Send an accessibility event to announce the context change
2881 getWindow().getDecorView()
2882 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Joe Onorato00acb122009-08-04 16:04:30 -04002883 }
2884
Michael Jurkab3e22d92011-10-31 15:58:33 -07002885 void showAllApps(boolean animated) {
2886 if (mState != State.WORKSPACE) return;
2887
2888 showAppsCustomizeHelper(animated, false);
2889 mAppsCustomizeTabHost.requestFocus();
2890
Michael Jurkab3e22d92011-10-31 15:58:33 -07002891 // Change the state *after* we've called all the transition code
2892 mState = State.APPS_CUSTOMIZE;
2893
2894 // Pause the auto-advance of widgets until we are out of AllApps
2895 mUserPresent = false;
2896 updateRunning();
2897 closeFolder();
2898
2899 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07002900 getWindow().getDecorView()
2901 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002902 }
2903
Adam Cohen7777d962011-08-18 18:58:38 -07002904 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002905 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002906 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002907 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002908 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002909 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002910 }
Adam Cohen7777d962011-08-18 18:58:38 -07002911
Adam Cohened66b2b2012-01-23 17:28:51 -08002912 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2913 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002914 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2915
Winson Chunge7a03942011-08-05 15:05:12 -07002916 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002917 @Override
2918 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002919 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002920 // Before we show workspace, hide all apps again because
2921 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2922 // clean up our state transition functions
2923 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002924 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002925 } else {
2926 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002927 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002928 }
2929 }, (extendedDelay ?
2930 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2931 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2932 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002933
Michael Jurkad3ef3062010-11-23 16:23:58 -08002934 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002935 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002936 final boolean animated = true;
2937 final boolean springLoaded = true;
2938 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002939 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002940 }
2941 // Otherwise, we are not in spring loaded mode, so don't do anything.
2942 }
2943
Michael Jurkab737ee62011-11-15 15:57:22 -08002944 void hideDockDivider() {
2945 if (mQsbDivider != null && mDockDivider != null) {
2946 mQsbDivider.setVisibility(View.INVISIBLE);
2947 mDockDivider.setVisibility(View.INVISIBLE);
2948 }
2949 }
2950
2951 void showDockDivider(boolean animated) {
2952 if (mQsbDivider != null && mDockDivider != null) {
2953 mQsbDivider.setVisibility(View.VISIBLE);
2954 mDockDivider.setVisibility(View.VISIBLE);
2955 if (mDividerAnimator != null) {
2956 mDividerAnimator.cancel();
2957 mQsbDivider.setAlpha(1f);
2958 mDockDivider.setAlpha(1f);
2959 mDividerAnimator = null;
2960 }
2961 if (animated) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07002962 mDividerAnimator = LauncherAnimUtils.createAnimatorSet();
2963 mDividerAnimator.playTogether(LauncherAnimUtils.ofFloat(mQsbDivider, "alpha", 1f),
2964 LauncherAnimUtils.ofFloat(mDockDivider, "alpha", 1f));
Winson Chungadf0c182012-08-23 14:59:07 -07002965 int duration = 0;
2966 if (mSearchDropTargetBar != null) {
2967 duration = mSearchDropTargetBar.getTransitionInDuration();
2968 }
2969 mDividerAnimator.setDuration(duration);
Michael Jurkab737ee62011-11-15 15:57:22 -08002970 mDividerAnimator.start();
2971 }
2972 }
2973 }
2974
Michael Jurkab3e22d92011-10-31 15:58:33 -07002975 void lockAllApps() {
2976 // TODO
2977 }
2978
2979 void unlockAllApps() {
2980 // TODO
2981 }
2982
Winson Chungf0ea4d32011-06-06 14:27:16 -07002983 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002984 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002985 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002986 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002987 if (!LauncherApplication.isScreenLarge()) {
2988 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002989 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07002990 int duration = 0;
2991 if (mSearchDropTargetBar != null) {
2992 duration = mSearchDropTargetBar.getTransitionInDuration();
2993 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08002994 mHotseat.animate().alpha(1f).setDuration(duration);
2995 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002996 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002997 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002998 }
2999 }
3000 }
3001
3002 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003003 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003004 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003005 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003006 if (!LauncherApplication.isScreenLarge()) {
3007 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003008 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003009 int duration = 0;
3010 if (mSearchDropTargetBar != null) {
3011 duration = mSearchDropTargetBar.getTransitionOutDuration();
3012 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003013 mHotseat.animate().alpha(0f).setDuration(duration);
3014 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003015 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003016 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003017 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003018 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003019 }
3020
Patrick Dubroy5f445422011-02-18 14:35:21 -08003021 /**
3022 * Add an item from all apps or customize onto the given workspace screen.
3023 * If layout is null, add to the current screen.
3024 */
3025 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003026 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003027 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003028 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003029 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003030
Winson Chungdff8ebb2011-09-08 17:25:31 -07003031 /** Maps the current orientation to an index for referencing orientation correct global icons */
3032 private int getCurrentOrientationIndexForGlobalIcons() {
3033 // default - 0, landscape - 1
3034 switch (getResources().getConfiguration().orientation) {
3035 case Configuration.ORIENTATION_LANDSCAPE:
3036 return 1;
3037 default:
3038 return 0;
3039 }
3040 }
3041
Michael Jurkaae65ee32012-04-30 11:45:54 -07003042 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003043 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003044 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003045 // Look for the toolbar icon specified in the activity meta-data
3046 Bundle metaData = packageManager.getActivityInfo(
3047 activityName, PackageManager.GET_META_DATA).metaData;
3048 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003049 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003050 if (iconResId != 0) {
3051 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003052 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003053 }
3054 }
3055 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003056 // This can happen if the activity defines an invalid drawable
3057 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3058 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003059 } catch (Resources.NotFoundException nfe) {
3060 // This can happen if the activity defines an invalid drawable
3061 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3062 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003063 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003064 return null;
3065 }
3066
3067 // if successful in getting icon, return it; otherwise, set button to use default drawable
3068 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003069 int buttonId, ComponentName activityName, int fallbackDrawableId,
3070 String toolbarResourceName) {
3071 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003072 Resources r = getResources();
3073 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3074 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003075
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003076 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003077 // If we were unable to find the icon via the meta-data, use a generic one
3078 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003079 toolbarIcon = r.getDrawable(fallbackDrawableId);
3080 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003081 if (button != null) {
3082 button.setCompoundDrawables(toolbarIcon, null, null, null);
3083 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003084 return null;
3085 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003086 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003087 if (button != null) {
3088 button.setCompoundDrawables(toolbarIcon, null, null, null);
3089 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003090 return toolbarIcon.getConstantState();
3091 }
3092 }
3093
3094 // if successful in getting icon, return it; otherwise, set button to use default drawable
3095 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003096 int buttonId, ComponentName activityName, int fallbackDrawableId,
3097 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003098 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003099 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003100
Michael Jurka19e0fc52011-07-22 18:00:21 -07003101 if (button != null) {
3102 // If we were unable to find the icon via the meta-data, use a
3103 // generic one
3104 if (toolbarIcon == null) {
3105 button.setImageResource(fallbackDrawableId);
3106 } else {
3107 button.setImageDrawable(toolbarIcon);
3108 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003109 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003110
3111 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3112
Michael Jurka0423dcf2010-10-05 14:56:18 -07003113 }
3114
Winson Chung1b884092012-06-08 17:13:02 -07003115 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003116 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003117 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003118 }
3119
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003120 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003121 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003122 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003123 }
3124
Winson Chungbb185bd2011-11-21 12:31:42 -08003125 private void invalidatePressedFocusedStates(View container, View button) {
3126 if (container instanceof HolographicLinearLayout) {
3127 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3128 layout.invalidatePressedFocusedStates();
3129 } else if (button instanceof HolographicImageView) {
3130 HolographicImageView view = (HolographicImageView) button;
3131 view.invalidatePressedFocusedStates();
3132 }
3133 }
3134
Winson Chungc51db6a2011-10-05 11:44:49 -07003135 private boolean updateGlobalSearchIcon() {
3136 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003137 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003138 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003139 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07003140 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07003141
Winson Chung1cad91e2011-05-25 17:41:01 -07003142 final SearchManager searchManager =
3143 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3144 ComponentName activityName = searchManager.getGlobalSearchActivity();
3145 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003146 int coi = getCurrentOrientationIndexForGlobalIcons();
3147 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003148 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3149 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3150 if (sGlobalSearchIcon[coi] == null) {
3151 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3152 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3153 TOOLBAR_ICON_METADATA_NAME);
3154 }
3155
Winson Chungc51db6a2011-10-05 11:44:49 -07003156 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3157 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003158 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003159 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003160 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003161 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003162 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3163 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
3164 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003165 voiceButton.setVisibility(View.GONE);
Michael Jurkac60498a2012-05-07 15:29:42 -07003166 if (voiceButtonProxy != null) {
3167 voiceButtonProxy.setVisibility(View.GONE);
3168 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003169 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003170 }
3171 }
3172
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003173 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003174 final View searchButtonContainer = findViewById(R.id.search_button_container);
3175 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003176 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003177 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003178 }
3179
Winson Chungc51db6a2011-10-05 11:44:49 -07003180 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003181 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003182 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07003183 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07003184
Winson Chungc51db6a2011-10-05 11:44:49 -07003185 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003186 final SearchManager searchManager =
3187 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3188 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3189
3190 ComponentName activityName = null;
3191 if (globalSearchActivity != null) {
3192 // Check if the global search activity handles voice search
3193 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3194 intent.setPackage(globalSearchActivity.getPackageName());
3195 activityName = intent.resolveActivity(getPackageManager());
3196 }
3197
3198 if (activityName == null) {
3199 // Fallback: check if an activity other than the global search activity
3200 // resolves this
3201 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3202 activityName = intent.resolveActivity(getPackageManager());
3203 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003204 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003205 int coi = getCurrentOrientationIndexForGlobalIcons();
3206 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003207 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3208 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3209 if (sVoiceSearchIcon[coi] == null) {
3210 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3211 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3212 TOOLBAR_ICON_METADATA_NAME);
3213 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003214 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003215 voiceButton.setVisibility(View.VISIBLE);
Jim Miller14091b12012-04-24 19:27:54 -07003216 if (voiceButtonProxy != null) {
3217 voiceButtonProxy.setVisibility(View.VISIBLE);
3218 }
Winson Chungbb185bd2011-11-21 12:31:42 -08003219 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003220 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003221 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003222 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003223 voiceButton.setVisibility(View.GONE);
Jim Miller14091b12012-04-24 19:27:54 -07003224 if (voiceButtonProxy != null) {
3225 voiceButtonProxy.setVisibility(View.GONE);
3226 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003227 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003228 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003229 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003230
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003231 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003232 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3233 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003234 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003235 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003236 }
3237
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003238 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003239 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003240 */
3241 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003242 final View marketButton = findViewById(R.id.market_button);
3243 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3244 // Find the app market activity by resolving an intent.
3245 // (If multiple app markets are installed, it will return the ResolverActivity.)
3246 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003247 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003248 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003249 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003250 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003251 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3252 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003253 marketButton.setVisibility(View.VISIBLE);
3254 } else {
3255 // We should hide and disable the view so that we don't try and restore the visibility
3256 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3257 marketButton.setVisibility(View.GONE);
3258 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003259 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003260 }
3261
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003262 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003263 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3264 Resources r = getResources();
3265 Drawable marketIconDrawable = d.newDrawable(r);
3266 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3267 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3268 marketIconDrawable.setBounds(0, 0, w, h);
3269
3270 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003271 }
3272
Michael Jurkad7c28052012-04-27 15:43:36 -07003273 @Override
3274 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003275 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003276 final List<CharSequence> text = event.getText();
3277 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003278 // Populate event with a fake title based on the current state.
3279 if (mState == State.APPS_CUSTOMIZE) {
3280 text.add(getString(R.string.all_apps_button_label));
3281 } else {
3282 text.add(getString(R.string.all_apps_home_button_label));
3283 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003284 return result;
3285 }
3286
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003287 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003288 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003289 */
3290 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3291 @Override
3292 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003293 closeSystemDialogs();
3294 }
3295 }
3296
3297 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003298 * Receives notifications whenever the appwidgets are reset.
3299 */
3300 private class AppWidgetResetObserver extends ContentObserver {
3301 public AppWidgetResetObserver() {
3302 super(new Handler());
3303 }
3304
3305 @Override
3306 public void onChange(boolean selfChange) {
3307 onAppWidgetReset();
3308 }
3309 }
3310
3311 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003312 * If the activity is currently paused, signal that we need to run the passed Runnable
3313 * in onResume.
3314 *
3315 * This needs to be called from incoming places where resources might have been loaded
3316 * while we are paused. That is becaues the Configuration might be wrong
3317 * when we're not running, and if it comes back to what it was when we
3318 * were paused, we are not restarted.
3319 *
3320 * Implementation of the method from LauncherModel.Callbacks.
3321 *
3322 * @return true if we are currently paused. The caller might be able to
3323 * skip some work in that case since we will come back again.
3324 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003325 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003326 if (mPaused) {
3327 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003328 if (deletePreviousRunnables) {
3329 while (mOnResumeCallbacks.remove(run)) {
3330 }
3331 }
Michael Jurka7607c2f2013-04-03 14:33:19 -07003332 mOnResumeCallbacks.add(run);
3333 return true;
3334 } else {
3335 return false;
3336 }
3337 }
3338
Michael Jurkac402cd92013-05-20 15:49:32 +02003339 private boolean waitUntilResume(Runnable run) {
3340 return waitUntilResume(run, false);
3341 }
3342
Michael Jurka7607c2f2013-04-03 14:33:19 -07003343 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003344 * If the activity is currently paused, signal that we need to re-run the loader
3345 * in onResume.
3346 *
3347 * This needs to be called from incoming places where resources might have been loaded
3348 * while we are paused. That is becaues the Configuration might be wrong
3349 * when we're not running, and if it comes back to what it was when we
3350 * were paused, we are not restarted.
3351 *
3352 * Implementation of the method from LauncherModel.Callbacks.
3353 *
3354 * @return true if we are currently paused. The caller might be able to
3355 * skip some work in that case since we will come back again.
3356 */
3357 public boolean setLoadOnResume() {
3358 if (mPaused) {
3359 Log.i(TAG, "setLoadOnResume");
3360 mOnResumeNeedsLoad = true;
3361 return true;
3362 } else {
3363 return false;
3364 }
3365 }
3366
3367 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003368 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003369 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003370 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003371 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003372 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003373 } else {
3374 return SCREEN_COUNT / 2;
3375 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003376 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003377
Joe Onorato9c1289c2009-08-17 11:03:03 -04003378 /**
3379 * Refreshes the shortcuts shown on the workspace.
3380 *
3381 * Implementation of the method from LauncherModel.Callbacks.
3382 */
3383 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003384 // If we're starting binding all over again, clear any bind calls we'd postponed in
3385 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3386 // from scratch again
3387 mOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003388
Michael Jurka7607c2f2013-04-03 14:33:19 -07003389 final Workspace workspace = mWorkspace;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003390 mNewShortcutAnimatePage = -1;
3391 mNewShortcutAnimateViews.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003392 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003393 int count = workspace.getChildCount();
3394 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003395 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003396 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3397 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003398 }
Michael Jurka05bf6442011-11-30 20:28:53 -08003399 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003400 if (mHotseat != null) {
3401 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003402 }
3403 }
3404
3405 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003406 * Bind the items start-end from the list.
3407 *
3408 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003409 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003410 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end) {
3411 if (waitUntilResume(new Runnable() {
3412 public void run() {
3413 bindItems(shortcuts, start, end);
3414 }
3415 })) {
3416 return;
3417 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003418
Winson Chungf0c6ae02012-03-21 16:10:31 -07003419 // Get the list of added shortcuts and intersect them with the set of shortcuts here
3420 Set<String> newApps = new HashSet<String>();
3421 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);
3422
3423 Workspace workspace = mWorkspace;
3424 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003425 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003426
3427 // Short circuit if we are loading dock items for a configuration which has no dock
3428 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3429 mHotseat == null) {
3430 continue;
3431 }
3432
Joe Onorato9c1289c2009-08-17 11:03:03 -04003433 switch (item.itemType) {
3434 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3435 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003436 ShortcutInfo info = (ShortcutInfo) item;
3437 String uri = info.intent.toUri(0).toString();
3438 View shortcut = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -07003439 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3440 item.cellY, 1, 1, false);
Winson Chungbfeac062012-06-06 15:56:08 -07003441 boolean animateIconUp = false;
3442 synchronized (newApps) {
3443 if (newApps.contains(uri)) {
3444 animateIconUp = newApps.remove(uri);
3445 }
3446 }
3447 if (animateIconUp) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003448 // Prepare the view to be animated up
3449 shortcut.setAlpha(0f);
3450 shortcut.setScaleX(0f);
3451 shortcut.setScaleY(0f);
3452 mNewShortcutAnimatePage = item.screen;
3453 if (!mNewShortcutAnimateViews.contains(shortcut)) {
3454 mNewShortcutAnimateViews.add(shortcut);
3455 }
3456 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003457 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003458 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003459 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003460 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003461 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003462 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3463 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003464 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003465 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003466 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003467
Joe Onorato9c1289c2009-08-17 11:03:03 -04003468 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003469 }
3470
Joe Onorato9c1289c2009-08-17 11:03:03 -04003471 /**
3472 * Implementation of the method from LauncherModel.Callbacks.
3473 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003474 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
3475 if (waitUntilResume(new Runnable() {
3476 public void run() {
3477 bindFolders(folders);
3478 }
3479 })) {
3480 return;
3481 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003482 sFolders.clear();
3483 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003484 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003485
3486 /**
3487 * Add the views for a widget to the workspace.
3488 *
3489 * Implementation of the method from LauncherModel.Callbacks.
3490 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003491 public void bindAppWidget(final LauncherAppWidgetInfo item) {
3492 if (waitUntilResume(new Runnable() {
3493 public void run() {
3494 bindAppWidget(item);
3495 }
3496 })) {
3497 return;
3498 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003499
Daniel Sandler843e8602010-06-07 14:59:01 -04003500 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3501 if (DEBUG_WIDGETS) {
3502 Log.d(TAG, "bindAppWidget: " + item);
3503 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003504 final Workspace workspace = mWorkspace;
3505
3506 final int appWidgetId = item.appWidgetId;
3507 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003508 if (DEBUG_WIDGETS) {
3509 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3510 }
3511
Joe Onorato9c1289c2009-08-17 11:03:03 -04003512 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3513
Joe Onorato9c1289c2009-08-17 11:03:03 -04003514 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003515 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003516
Winson Chung3d503fb2011-07-13 17:25:49 -07003517 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003518 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003519 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3520
Joe Onorato9c1289c2009-08-17 11:03:03 -04003521 workspace.requestLayout();
3522
Daniel Sandler843e8602010-06-07 14:59:01 -04003523 if (DEBUG_WIDGETS) {
3524 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3525 + (SystemClock.uptimeMillis()-start) + "ms");
3526 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003527 }
3528
Adam Cohen1462de32012-07-24 22:34:36 -07003529 public void onPageBoundSynchronously(int page) {
3530 mSynchronouslyBoundPages.add(page);
3531 }
3532
Joe Onorato9c1289c2009-08-17 11:03:03 -04003533 /**
3534 * Callback saying that there aren't any more items to bind.
3535 *
3536 * Implementation of the method from LauncherModel.Callbacks.
3537 */
3538 public void finishBindingItems() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003539 if (waitUntilResume(new Runnable() {
3540 public void run() {
3541 finishBindingItems();
3542 }
3543 })) {
3544 return;
3545 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003546 if (mSavedState != null) {
3547 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003548 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003549 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003550 mSavedState = null;
3551 }
3552
Adam Cohen1462de32012-07-24 22:34:36 -07003553 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003554
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003555 // If we received the result of any pending adds while the loader was running (e.g. the
3556 // widget configuration forced an orientation change), process them now.
3557 for (int i = 0; i < sPendingAddList.size(); i++) {
3558 completeAdd(sPendingAddList.get(i));
3559 }
3560 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003561
Winson Chungc51db6a2011-10-05 11:44:49 -07003562 // Update the market app icon as necessary (the other icons will be managed in response to
3563 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003564 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003565
Winson Chungf0c6ae02012-03-21 16:10:31 -07003566 // Animate up any icons as necessary
3567 if (mVisible || mWorkspaceLoading) {
3568 Runnable newAppsRunnable = new Runnable() {
3569 @Override
3570 public void run() {
Winson Chunga2413752012-04-03 14:22:34 -07003571 runNewAppsAnimation(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003572 }
3573 };
Winson Chunga2413752012-04-03 14:22:34 -07003574
3575 boolean willSnapPage = mNewShortcutAnimatePage > -1 &&
3576 mNewShortcutAnimatePage != mWorkspace.getCurrentPage();
3577 if (canRunNewAppsAnimation()) {
3578 // If the user has not interacted recently, then either snap to the new page to show
3579 // the new-apps animation or just run them if they are to appear on the current page
3580 if (willSnapPage) {
3581 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable);
3582 } else {
3583 runNewAppsAnimation(false);
3584 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003585 } else {
Winson Chung318eee02012-04-12 10:59:27 -07003586 // If the user has interacted recently, then just add the items in place if they
Winson Chunga2413752012-04-03 14:22:34 -07003587 // are on another page (or just normally if they are added to the current page)
3588 runNewAppsAnimation(willSnapPage);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003589 }
3590 }
3591
3592 mWorkspaceLoading = false;
3593 }
3594
Winson Chunga2413752012-04-03 14:22:34 -07003595 private boolean canRunNewAppsAnimation() {
3596 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3597 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3598 }
3599
Winson Chungf0c6ae02012-03-21 16:10:31 -07003600 /**
3601 * Runs a new animation that scales up icons that were added while Launcher was in the
3602 * background.
Winson Chunga2413752012-04-03 14:22:34 -07003603 *
3604 * @param immediate whether to run the animation or show the results immediately
Winson Chungf0c6ae02012-03-21 16:10:31 -07003605 */
Winson Chunga2413752012-04-03 14:22:34 -07003606 private void runNewAppsAnimation(boolean immediate) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07003607 AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003608 Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chunga2413752012-04-03 14:22:34 -07003609
3610 // Order these new views spatially so that they animate in order
Winson Chungf0c6ae02012-03-21 16:10:31 -07003611 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
3612 @Override
3613 public int compare(View a, View b) {
3614 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
3615 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
3616 int cellCountX = LauncherModel.getCellCountX();
3617 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
3618 }
3619 });
Winson Chunga2413752012-04-03 14:22:34 -07003620
3621 // Animate each of the views in place (or show them immediately if requested)
3622 if (immediate) {
3623 for (View v : mNewShortcutAnimateViews) {
3624 v.setAlpha(1f);
3625 v.setScaleX(1f);
3626 v.setScaleY(1f);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003627 }
Winson Chunga2413752012-04-03 14:22:34 -07003628 } else {
3629 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
3630 View v = mNewShortcutAnimateViews.get(i);
Michael Jurka2ecf9952012-06-18 12:52:28 -07003631 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
Winson Chunga2413752012-04-03 14:22:34 -07003632 PropertyValuesHolder.ofFloat("alpha", 1f),
3633 PropertyValuesHolder.ofFloat("scaleX", 1f),
3634 PropertyValuesHolder.ofFloat("scaleY", 1f));
3635 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3636 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3637 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3638 bounceAnims.add(bounceAnim);
3639 }
3640 anim.playTogether(bounceAnims);
3641 anim.addListener(new AnimatorListenerAdapter() {
3642 @Override
3643 public void onAnimationEnd(Animator animation) {
Michael Jurkad6dd7c82012-10-19 17:15:16 +02003644 if (mWorkspace != null) {
3645 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
3646 }
Winson Chunga2413752012-04-03 14:22:34 -07003647 }
3648 });
3649 anim.start();
3650 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003651
3652 // Clean up
3653 mNewShortcutAnimatePage = -1;
3654 mNewShortcutAnimateViews.clear();
3655 new Thread("clearNewAppsThread") {
3656 public void run() {
3657 mSharedPrefs.edit()
3658 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
3659 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null)
3660 .commit();
3661 }
3662 }.start();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003663 }
3664
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003665 @Override
3666 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003667 boolean searchVisible = updateGlobalSearchIcon();
3668 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003669 if (mSearchDropTargetBar != null) {
3670 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3671 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003672 }
3673
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003674 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003675 * Add the icons for all apps.
3676 *
3677 * Implementation of the method from LauncherModel.Callbacks.
3678 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003679 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003680 Runnable setAllAppsRunnable = new Runnable() {
3681 public void run() {
3682 if (mAppsCustomizeContent != null) {
3683 mAppsCustomizeContent.setApps(apps);
3684 }
3685 }
3686 };
3687
Michael Jurkac57b7a82011-08-09 22:02:20 -07003688 // Remove the progress bar entirely; we could also make it GONE
3689 // but better to remove it since we know it's not going to be used
3690 View progressBar = mAppsCustomizeTabHost.
3691 findViewById(R.id.apps_customize_progress_bar);
3692 if (progressBar != null) {
3693 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chungc93e5ae2012-07-23 20:48:26 -07003694
3695 // We just post the call to setApps so the user sees the progress bar
3696 // disappear-- otherwise, it just looks like the progress bar froze
3697 // which doesn't look great
3698 mAppsCustomizeTabHost.post(setAllAppsRunnable);
3699 } else {
3700 // If we did not initialize the spinner in onCreate, then we can directly set the
3701 // list of applications without waiting for any progress bars views to be hidden.
3702 setAllAppsRunnable.run();
Winson Chung785d2eb2011-04-14 16:08:02 -07003703 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003704 }
3705
3706 /**
3707 * A package was installed.
3708 *
3709 * Implementation of the method from LauncherModel.Callbacks.
3710 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003711 public void bindAppsAdded(final ArrayList<ApplicationInfo> apps) {
3712 if (waitUntilResume(new Runnable() {
3713 public void run() {
3714 bindAppsAdded(apps);
3715 }
3716 })) {
3717 return;
3718 }
3719
Winson Chungf0ea4d32011-06-06 14:27:16 -07003720
Winson Chung785d2eb2011-04-14 16:08:02 -07003721 if (mAppsCustomizeContent != null) {
3722 mAppsCustomizeContent.addApps(apps);
3723 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003724 }
3725
3726 /**
3727 * A package was updated.
3728 *
3729 * Implementation of the method from LauncherModel.Callbacks.
3730 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003731 public void bindAppsUpdated(final ArrayList<ApplicationInfo> apps) {
3732 if (waitUntilResume(new Runnable() {
3733 public void run() {
3734 bindAppsUpdated(apps);
3735 }
3736 })) {
3737 return;
3738 }
3739
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003740 if (mWorkspace != null) {
3741 mWorkspace.updateShortcuts(apps);
3742 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003743
Winson Chung785d2eb2011-04-14 16:08:02 -07003744 if (mAppsCustomizeContent != null) {
3745 mAppsCustomizeContent.updateApps(apps);
3746 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003747 }
3748
3749 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003750 * A package was uninstalled. We take both the super set of packageNames
3751 * in addition to specific applications to remove, the reason being that
3752 * this can be called when a package is updated as well. In that scenario,
3753 * we only remove specific components from the workspace, where as
3754 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003755 *
3756 * Implementation of the method from LauncherModel.Callbacks.
3757 */
Winson Chung83892cc2013-05-01 16:53:33 -07003758 public void bindComponentsRemoved(final ArrayList<String> packageNames,
3759 final ArrayList<ApplicationInfo> appInfos,
3760 final boolean matchPackageNamesOnly) {
3761 if (waitUntilResume(new Runnable() {
3762 public void run() {
3763 bindComponentsRemoved(packageNames, appInfos, matchPackageNamesOnly);
3764 }
3765 })) {
3766 return;
3767 }
3768
3769 if (matchPackageNamesOnly) {
3770 mWorkspace.removeItemsByPackageName(packageNames);
3771 } else {
3772 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003773 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003774
Winson Chung785d2eb2011-04-14 16:08:02 -07003775 if (mAppsCustomizeContent != null) {
Winson Chung83892cc2013-05-01 16:53:33 -07003776 mAppsCustomizeContent.removeApps(appInfos);
Winson Chung785d2eb2011-04-14 16:08:02 -07003777 }
Winson Chunga1820962011-10-03 16:31:06 -07003778
3779 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003780 mDragController.onAppsRemoved(appInfos, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003781 }
Joe Onoratobe386092009-11-17 17:32:16 -08003782
3783 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003784 * A number of packages were updated.
3785 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003786
3787 private ArrayList<Object> mWidgetsAndShortcuts;
3788 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003789 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003790 bindPackagesUpdated(mWidgetsAndShortcuts);
3791 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003792 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003793 };
3794
3795 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3796 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3797 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003798 return;
3799 }
3800
Winson Chung785d2eb2011-04-14 16:08:02 -07003801 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003802 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003803 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003804 }
3805
Winson Chung400438b2011-01-16 17:53:48 -08003806 private int mapConfigurationOriActivityInfoOri(int configOri) {
3807 final Display d = getWindowManager().getDefaultDisplay();
3808 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3809 switch (d.getRotation()) {
3810 case Surface.ROTATION_0:
3811 case Surface.ROTATION_180:
3812 // We are currently in the same basic orientation as the natural orientation
3813 naturalOri = configOri;
3814 break;
3815 case Surface.ROTATION_90:
3816 case Surface.ROTATION_270:
3817 // We are currently in the other basic orientation to the natural orientation
3818 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3819 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3820 break;
3821 }
3822
3823 int[] oriMap = {
3824 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3825 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3826 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3827 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3828 };
3829 // Since the map starts at portrait, we need to offset if this device's natural orientation
3830 // is landscape.
3831 int indexOffset = 0;
3832 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3833 indexOffset = 1;
3834 }
3835 return oriMap[(d.getRotation() + indexOffset) % 4];
3836 }
Adam Cohen446e9402011-09-15 18:21:21 -07003837
Winson Chung4b919f82012-05-01 10:44:08 -07003838 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08003839 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07003840 getResources().getBoolean(R.bool.allow_rotation);
3841 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08003842 }
Winson Chung4b919f82012-05-01 10:44:08 -07003843 public void lockScreenOrientation() {
3844 if (isRotationEnabled()) {
3845 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3846 .getConfiguration().orientation));
3847 }
3848 }
3849 public void unlockScreenOrientation(boolean immediate) {
3850 if (isRotationEnabled()) {
3851 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07003852 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07003853 } else {
3854 mHandler.postDelayed(new Runnable() {
3855 public void run() {
3856 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3857 }
3858 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07003859 }
Winson Chung4b919f82012-05-01 10:44:08 -07003860 }
Winson Chung400438b2011-01-16 17:53:48 -08003861 }
3862
Winson Chung82f55532011-08-09 14:14:23 -07003863 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003864 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003865 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003866 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003867
Michael Jurkae233a8b2013-03-19 13:49:20 +01003868 // Restricted secondary users (child mode) will potentially have very few apps
3869 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04003870// boolean supportsLimitedUsers =
3871// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
3872// Account[] accounts = AccountManager.get(this).getAccounts();
3873// if (supportsLimitedUsers && accounts.length == 0) {
3874// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
3875// Bundle restrictions = um.getUserRestrictions();
3876// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
3877// return false;
3878// }
3879// }
Winson Chung7d7541e2011-09-16 20:14:36 -07003880 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003881 }
Michael Jurka22143132012-10-04 17:42:38 +02003882
Winson Chung7d7541e2011-09-16 20:14:36 -07003883 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
Michael Jurka22143132012-10-04 17:42:38 +02003884 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07003885 if (cling != null) {
3886 cling.init(this, positionData);
3887 cling.setVisibility(View.VISIBLE);
3888 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3889 if (animate) {
3890 cling.buildLayer();
3891 cling.setAlpha(0f);
3892 cling.animate()
3893 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003894 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003895 .setDuration(SHOW_CLING_DURATION)
3896 .setStartDelay(delay)
3897 .start();
3898 } else {
3899 cling.setAlpha(1f);
3900 }
Michael Jurka22143132012-10-04 17:42:38 +02003901 cling.setFocusableInTouchMode(true);
3902 cling.post(new Runnable() {
3903 public void run() {
3904 cling.setFocusable(true);
3905 cling.requestFocus();
3906 }
3907 });
3908 mHideFromAccessibilityHelper.setImportantForAccessibilityToNo(
3909 mDragLayer, clingId == R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003910 }
3911 return cling;
3912 }
Michael Jurka22143132012-10-04 17:42:38 +02003913
Winson Chung7d7541e2011-09-16 20:14:36 -07003914 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung7819abd2012-11-29 14:29:38 -08003915 // To catch cases where siblings of top-level views are made invisible, just check whether
3916 // the cling is directly set to GONE before dismissing it.
3917 if (cling != null && cling.getVisibility() != View.GONE) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07003918 ObjectAnimator anim = LauncherAnimUtils.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003919 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003920 anim.addListener(new AnimatorListenerAdapter() {
3921 public void onAnimationEnd(Animator animation) {
3922 cling.setVisibility(View.GONE);
3923 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003924 // We should update the shared preferences on a background thread
3925 new Thread("dismissClingThread") {
3926 public void run() {
3927 SharedPreferences.Editor editor = mSharedPrefs.edit();
3928 editor.putBoolean(flag, true);
3929 editor.commit();
3930 }
3931 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003932 };
3933 });
3934 anim.start();
Michael Jurka22143132012-10-04 17:42:38 +02003935 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung82f55532011-08-09 14:14:23 -07003936 }
3937 }
Michael Jurka22143132012-10-04 17:42:38 +02003938
Winson Chung9d9d74f2011-09-19 11:49:12 -07003939 private void removeCling(int id) {
3940 final View cling = findViewById(id);
3941 if (cling != null) {
3942 final ViewGroup parent = (ViewGroup) cling.getParent();
3943 parent.post(new Runnable() {
3944 @Override
3945 public void run() {
3946 parent.removeView(cling);
3947 }
3948 });
Michael Jurka22143132012-10-04 17:42:38 +02003949 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003950 }
3951 }
Michael Jurka974c3862012-05-22 22:00:31 -07003952
3953 private boolean skipCustomClingIfNoAccounts() {
3954 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3955 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
3956 if (customCling) {
3957 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04003958 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07003959 Account[] accounts = am.getAccountsByType("com.google");
3960 return accounts.length == 0;
3961 }
3962 return false;
3963 }
3964
Winson Chung7d7541e2011-09-16 20:14:36 -07003965 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003966 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003967 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07003968 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
3969 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02003970 // If we're not using the default workspace layout, replace workspace cling
3971 // with a custom workspace cling (usually specified in an overlay)
3972 // For now, only do this on tablets
3973 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
Michael Jurkaa1131212012-10-09 14:46:26 +02003974 getResources().getBoolean(R.bool.config_useCustomClings)) {
Michael Jurka45355c42012-10-08 13:21:35 +02003975 // Use a custom cling
3976 View cling = findViewById(R.id.workspace_cling);
3977 ViewGroup clingParent = (ViewGroup) cling.getParent();
3978 int clingIndex = clingParent.indexOfChild(cling);
3979 clingParent.removeViewAt(clingIndex);
3980 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
3981 clingParent.addView(customCling, clingIndex);
3982 customCling.setId(R.id.workspace_cling);
3983 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003984 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003985 } else {
3986 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003987 }
3988 }
3989 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003990 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003991 if (isClingsEnabled() &&
3992 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003993 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003994 } else {
3995 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003996 }
3997 }
3998 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003999 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004000 if (isClingsEnabled() &&
4001 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
4002 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004003 } else {
4004 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004005 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004006 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004007 }
4008 public boolean isFolderClingVisible() {
4009 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004010 if (cling != null) {
4011 return cling.getVisibility() == View.VISIBLE;
4012 }
4013 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004014 }
Winson Chung82f55532011-08-09 14:14:23 -07004015 public void dismissWorkspaceCling(View v) {
4016 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004017 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004018 }
4019 public void dismissAllAppsCling(View v) {
4020 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004021 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
4022 }
4023 public void dismissFolderCling(View v) {
4024 Cling cling = (Cling) findViewById(R.id.folder_cling);
4025 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004026 }
4027
Winson Chung80baf5a2010-08-09 16:03:15 -07004028 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004029 * Prints out out state for debugging.
4030 */
4031 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004032 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004033 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004034 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4035 Log.d(TAG, "mRestoring=" + mRestoring);
4036 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4037 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004038 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004039 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004040
Winson Chung785d2eb2011-04-14 16:08:02 -07004041 if (mAppsCustomizeContent != null) {
4042 mAppsCustomizeContent.dumpState();
4043 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004044 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004045 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004046
4047 @Override
4048 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4049 super.dump(prefix, fd, writer, args);
4050 writer.println(" ");
4051 writer.println("Debug logs: ");
4052 for (int i = 0; i < sDumpLogs.size(); i++) {
4053 writer.println(" " + sDumpLogs.get(i));
4054 }
4055 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004056
4057 public static void dumpDebugLogsToConsole() {
4058 Log.d(TAG, "");
4059 Log.d(TAG, "*********************");
4060 Log.d(TAG, "Launcher debug logs: ");
4061 for (int i = 0; i < sDumpLogs.size(); i++) {
4062 Log.d(TAG, " " + sDumpLogs.get(i));
4063 }
4064 Log.d(TAG, "*********************");
4065 Log.d(TAG, "");
4066 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004067}
Michael Jurka2763be32011-02-24 11:19:57 -08004068
Michael Jurkaabded662011-03-04 12:06:57 -08004069interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004070 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004071 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004072 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004073 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004074 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004075}