blob: a5a90d2c54bddbb4ba199d078572f501ffea3032 [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;
Joe Onorato13724ea2009-12-02 21:16:35 -08002003 int[] pos = new int[2];
2004 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002005 intent.setSourceBounds(new Rect(pos[0], pos[1],
2006 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002007
2008 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002009
2010 if (success && v instanceof BubbleTextView) {
2011 mWaitingForResume = (BubbleTextView) v;
2012 mWaitingForResume.setStayPressed(true);
2013 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002014 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002015 if (v instanceof FolderIcon) {
2016 FolderIcon fi = (FolderIcon) v;
2017 handleFolderClick(fi);
2018 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002019 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002020 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002021 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002022 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002023 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002024 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002025 }
2026 }
2027
Michael Jurka0e260592010-06-30 17:07:39 -07002028 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07002029 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002030 // clicking anywhere on the workspace causes the customization drawer to slide down
2031 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07002032 return false;
2033 }
2034
Michael Jurkaaf442092010-06-10 17:01:57 -07002035 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002036 * Event handler for the search button
2037 *
2038 * @param v The view that was clicked.
2039 */
2040 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002041 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2042
Amith Yamasania135ba82011-08-09 17:42:01 -07002043 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002044 }
2045
2046 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002047 * Event handler for the voice button
2048 *
2049 * @param v The view that was clicked.
2050 */
2051 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002052 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002053
Michael Jurkaae65ee32012-04-30 11:45:54 -07002054 try {
2055 final SearchManager searchManager =
2056 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2057 ComponentName activityName = searchManager.getGlobalSearchActivity();
2058 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002059 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002060 if (activityName != null) {
2061 intent.setPackage(activityName.getPackageName());
2062 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002063 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002064 } catch (ActivityNotFoundException e) {
2065 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002066 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002067 startActivitySafely(null, intent, "onClickVoiceButton");
2068 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002069 }
2070
2071 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002072 * Event handler for the "grid" button that appears on the home screen, which
2073 * enters all apps mode.
2074 *
2075 * @param v The view that was clicked.
2076 */
2077 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07002078 showAllApps(true);
2079 }
2080
2081 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002082 // Provide the same haptic feedback that the system offers for virtual keys.
2083 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002084 }
2085
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002086 public void onClickAppMarketButton(View v) {
2087 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002088 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002089 } else {
2090 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002091 }
2092 }
2093
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002094 void startApplicationDetailsActivity(ComponentName componentName) {
2095 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002096 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2097 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002098 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002099 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002100 }
2101
Patrick Dubroy5539af72010-09-07 15:22:01 -07002102 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
2103 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
2104 // System applications cannot be installed. For now, show a toast explaining that.
2105 // We may give them the option of disabling apps this way.
2106 int messageId = R.string.uninstall_system_app_text;
2107 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
2108 } else {
2109 String packageName = appInfo.componentName.getPackageName();
2110 String className = appInfo.componentName.getClassName();
2111 Intent intent = new Intent(
2112 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002113 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2114 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002115 startActivity(intent);
2116 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002117 }
2118
Michael Jurka86a720e2012-05-09 11:23:23 -07002119 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002120 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002121
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002122 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002123 // Only launch using the new animation if the shortcut has not opted out (this is a
2124 // private contract between launcher and may be ignored in the future).
2125 boolean useLaunchAnimation = (v != null) &&
2126 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2127 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002128 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2129 v.getMeasuredWidth(), v.getMeasuredHeight());
2130
2131 startActivity(intent, opts.toBundle());
2132 } else {
2133 startActivity(intent);
2134 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002135 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002136 } catch (SecurityException e) {
2137 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002138 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002139 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002140 "or use the exported attribute for this activity. "
2141 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002142 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002143 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002144 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002145
Michael Jurka86a720e2012-05-09 11:23:23 -07002146 boolean startActivitySafely(View v, Intent intent, Object tag) {
2147 boolean success = false;
2148 try {
2149 success = startActivity(v, intent, tag);
2150 } catch (ActivityNotFoundException e) {
2151 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2152 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2153 }
2154 return success;
2155 }
2156
Romain Guy8e633c52010-03-04 12:51:36 -08002157 void startActivityForResultSafely(Intent intent, int requestCode) {
2158 try {
2159 startActivityForResult(intent, requestCode);
2160 } catch (ActivityNotFoundException e) {
2161 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2162 } catch (SecurityException e) {
2163 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2164 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2165 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2166 "or use the exported attribute for this activity.", e);
2167 }
2168 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002169
Adam Cohena9cf38f2011-05-02 15:36:58 -07002170 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002171 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002172 Folder openFolder = mWorkspace.getFolderForTag(info);
2173
2174 // If the folder info reports that the associated folder is open, then verify that
2175 // it is actually opened. There have been a few instances where this gets out of sync.
2176 if (info.opened && openFolder == null) {
2177 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2178 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
2179 info.opened = false;
2180 }
2181
Adam Cohenfb91f302012-06-11 15:45:18 -07002182 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002183 // Close any open folder
2184 closeFolder();
2185 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002186 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002187 } else {
2188 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002189 int folderScreen;
2190 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002191 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002192 // .. and close it
2193 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002194 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002195 // Close any folder open on the current screen
2196 closeFolder();
2197 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002198 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002199 }
2200 }
2201 }
2202 }
2203
Adam Cohen268c4752012-06-06 17:47:33 -07002204 /**
2205 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2206 * in the DragLayer in the exact absolute location of the original FolderIcon.
2207 */
2208 private void copyFolderIconToImage(FolderIcon fi) {
2209 final int width = fi.getMeasuredWidth();
2210 final int height = fi.getMeasuredHeight();
2211
2212 // Lazy load ImageView, Bitmap and Canvas
2213 if (mFolderIconImageView == null) {
2214 mFolderIconImageView = new ImageView(this);
2215 }
2216 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2217 mFolderIconBitmap.getHeight() != height) {
2218 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2219 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2220 }
2221
2222 DragLayer.LayoutParams lp;
2223 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2224 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2225 } else {
2226 lp = new DragLayer.LayoutParams(width, height);
2227 }
2228
Adam Cohen307fe232012-08-16 17:55:58 -07002229 // The layout from which the folder is being opened may be scaled, adjust the starting
2230 // view size by this scale factor.
2231 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002232 lp.customPosition = true;
2233 lp.x = mRectForFolderAnimation.left;
2234 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002235 lp.width = (int) (scale * width);
2236 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002237
2238 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2239 fi.draw(mFolderIconCanvas);
2240 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002241 if (fi.getFolder() != null) {
2242 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2243 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002244 }
Adam Cohen268c4752012-06-06 17:47:33 -07002245 // Just in case this image view is still in the drag layer from a previous animation,
2246 // we remove it and re-add it.
2247 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2248 mDragLayer.removeView(mFolderIconImageView);
2249 }
2250 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002251 if (fi.getFolder() != null) {
2252 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002253 }
Adam Cohen268c4752012-06-06 17:47:33 -07002254 }
2255
Adam Cohen2801caf2011-05-13 20:57:39 -07002256 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002257 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002258 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2259 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2260 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2261
Adam Cohenc51934b2011-07-26 21:07:43 -07002262 FolderInfo info = (FolderInfo) fi.getTag();
2263 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2264 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002265 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2266 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002267 }
2268
Adam Cohen268c4752012-06-06 17:47:33 -07002269 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2270 copyFolderIconToImage(fi);
2271 fi.setVisibility(View.INVISIBLE);
2272
Michael Jurka2ecf9952012-06-18 12:52:28 -07002273 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002274 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002275 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2276 oa.start();
2277 }
2278
Adam Cohen268c4752012-06-06 17:47:33 -07002279 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002280 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002281 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2282 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2283 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2284
Adam Cohen268c4752012-06-06 17:47:33 -07002285 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002286
Adam Cohen268c4752012-06-06 17:47:33 -07002287 // We remove and re-draw the FolderIcon in-case it has changed
2288 mDragLayer.removeView(mFolderIconImageView);
2289 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002290 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002291 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002292 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002293 oa.addListener(new AnimatorListenerAdapter() {
2294 @Override
2295 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002296 if (cl != null) {
2297 cl.clearFolderLeaveBehind();
2298 // Remove the ImageView copy of the FolderIcon and make the original visible.
2299 mDragLayer.removeView(mFolderIconImageView);
2300 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002301 }
2302 }
2303 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002304 oa.start();
2305 }
2306
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002307 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002308 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002309 * is animated relative to the specified View. If the View is null, no animation
2310 * is played.
2311 *
2312 * @param folderInfo The FolderInfo describing the folder to open.
2313 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002314 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002315 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002316 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002317
Adam Cohena9cf38f2011-05-02 15:36:58 -07002318 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002319
Adam Cohen4554ee12011-08-03 16:13:21 -07002320 // Just verify that the folder hasn't already been added to the DragLayer.
2321 // There was a one-off crash where the folder had a parent already.
2322 if (folder.getParent() == null) {
2323 mDragLayer.addView(folder);
2324 mDragController.addDropTarget((DropTarget) folder);
2325 } else {
2326 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2327 folder.getParent() + ").");
2328 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002329 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002330 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002331
2332 // Notify the accessibility manager that this folder "window" has appeared and occluded
2333 // the workspace items
2334 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2335 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002336 }
2337
2338 public void closeFolder() {
2339 Folder folder = mWorkspace.getOpenFolder();
2340 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002341 if (folder.isEditingName()) {
2342 folder.dismissEditingName();
2343 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002344 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002345
2346 // Dismiss the folder cling
2347 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002348 }
2349 }
2350
2351 void closeFolder(Folder folder) {
2352 folder.getInfo().opened = false;
2353
2354 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2355 if (parent != null) {
2356 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2357 shrinkAndFadeInFolderIcon(fi);
2358 }
2359 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002360
2361 // Notify the accessibility manager that this folder "window" has disappeard and no
2362 // longer occludeds the workspace items
2363 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002364 }
2365
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002366 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002367 if (!isDraggingEnabled()) return false;
2368 if (isWorkspaceLocked()) return false;
2369 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002370
2371 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002372 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002373 }
2374
Michael Jurka0280c3b2010-09-17 15:00:07 -07002375 resetAddInfo();
2376 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002377 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002378 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002379 return true;
2380 }
2381
Winson Chung3d503fb2011-07-13 17:25:49 -07002382 // The hotseat touch handling does not go through Workspace, and we always allow long press
2383 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002384 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002385 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2386 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002387 if (itemUnderLongClick == null) {
2388 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002389 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2390 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002391 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002392 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002393 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002394 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002395 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002396 }
2397 }
2398 }
2399 return true;
2400 }
2401
Winson Chung3d503fb2011-07-13 17:25:49 -07002402 boolean isHotseatLayout(View layout) {
2403 return mHotseat != null && layout != null &&
2404 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2405 }
2406 Hotseat getHotseat() {
2407 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002408 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002409 SearchDropTargetBar getSearchBar() {
2410 return mSearchDropTargetBar;
2411 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002412
Winson Chung3d503fb2011-07-13 17:25:49 -07002413 /**
2414 * Returns the CellLayout of the specified container at the specified screen.
2415 */
2416 CellLayout getCellLayout(long container, int screen) {
2417 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2418 if (mHotseat != null) {
2419 return mHotseat.getLayout();
2420 } else {
2421 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002422 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002423 } else {
2424 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002425 }
2426 }
2427
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002428 Workspace getWorkspace() {
2429 return mWorkspace;
2430 }
2431
Daniel Sandler843e8602010-06-07 14:59:01 -04002432 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
Craig Mautner360310b2012-10-26 15:13:08 -07002433 @Override
Daniel Sandler843e8602010-06-07 14:59:01 -04002434 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002435 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002436 }
2437
Craig Mautner360310b2012-10-26 15:13:08 -07002438 @Override
Andrew Flynn0dca1ec2012-02-29 13:33:22 -08002439 public boolean isAllAppsButtonRank(int rank) {
2440 return mHotseat.isAllAppsButtonRank(rank);
2441 }
2442
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002443 /**
2444 * Helper method for the cameraZoomIn/cameraZoomOut animations
2445 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002446 * @param scaleFactor The scale factor used for the zoom
2447 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002448 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002449 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002450 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002451 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002452
Winson Chung18f41f82012-05-09 13:28:10 -07002453 void disableWallpaperIfInAllApps() {
2454 // Only disable it if we are in all apps
Winson Chungc93e5ae2012-07-23 20:48:26 -07002455 if (isAllAppsVisible()) {
Winson Chung18f41f82012-05-09 13:28:10 -07002456 if (mAppsCustomizeTabHost != null &&
2457 !mAppsCustomizeTabHost.isTransitioning()) {
2458 updateWallpaperVisibility(false);
2459 }
2460 }
2461 }
2462
Craig Mautner360310b2012-10-26 15:13:08 -07002463 private void setWorkspaceBackground(boolean workspace) {
2464 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002465 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002466 }
2467
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002468 void updateWallpaperVisibility(boolean visible) {
2469 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2470 int curflags = getWindow().getAttributes().flags
2471 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2472 if (wpflags != curflags) {
2473 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2474 }
Craig Mautner360310b2012-10-26 15:13:08 -07002475 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002476 }
2477
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002478 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2479 if (v instanceof LauncherTransitionable) {
2480 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2481 }
2482 }
2483
Michael Jurkabed61d22012-02-14 22:51:29 -08002484 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2485 if (v instanceof LauncherTransitionable) {
2486 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2487 }
Winson Chung70442722012-02-10 15:43:22 -08002488
2489 // Update the workspace transition step as well
2490 dispatchOnLauncherTransitionStep(v, 0f);
2491 }
2492
2493 private void dispatchOnLauncherTransitionStep(View v, float t) {
2494 if (v instanceof LauncherTransitionable) {
2495 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2496 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002497 }
2498
2499 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2500 if (v instanceof LauncherTransitionable) {
2501 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2502 }
Winson Chung70442722012-02-10 15:43:22 -08002503
2504 // Update the workspace transition step as well
2505 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002506 }
2507
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002508 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002509 * Things to test when changing the following seven functions.
2510 * - Home from workspace
2511 * - from center screen
2512 * - from other screens
2513 * - Home from all apps
2514 * - from center screen
2515 * - from other screens
2516 * - Back from all apps
2517 * - from center screen
2518 * - from other screens
2519 * - Launch app from workspace and quit
2520 * - with back
2521 * - with home
2522 * - Launch app from all apps and quit
2523 * - with back
2524 * - with home
2525 * - Go to a screen that's not the default, then all
2526 * apps, and launch and app, and go back
2527 * - with back
2528 * -with home
2529 * - On workspace, long press power and go back
2530 * - with back
2531 * - with home
2532 * - On all apps, long press power and go back
2533 * - with back
2534 * - with home
2535 * - On workspace, power off
2536 * - On all apps, power off
2537 * - Launch an app and turn off the screen while in that app
2538 * - Go back with home key
2539 * - Go back with back key TODO: make this not go to workspace
2540 * - From all apps
2541 * - From workspace
2542 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2543 * - From all apps
2544 * - From the center workspace
2545 * - From another workspace
2546 */
2547
2548 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002549 * Zoom the camera out from the workspace to reveal 'toView'.
2550 * Assumes that the view to show is anchored at either the very top or very bottom
2551 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002552 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002553 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002554 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002555 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002556 mStateAnimation.cancel();
2557 mStateAnimation = null;
2558 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002559 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002560
Winson Chungf0ea4d32011-06-06 14:27:16 -07002561 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2562 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2563 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002564 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002565 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002566 final int startDelay =
2567 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002568
Michael Jurkab3e22d92011-10-31 15:58:33 -07002569 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002570
Michael Jurkad74c9842011-07-10 12:44:21 -07002571 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002572 Animator workspaceAnim =
2573 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002574
2575 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002576 toView.setScaleX(scale);
2577 toView.setScaleY(scale);
2578 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2579 scaleAnim.
2580 scaleX(1f).scaleY(1f).
2581 setDuration(duration).
2582 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002583
Winson Chungf0ea4d32011-06-06 14:27:16 -07002584 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002585 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002586 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002587 .ofFloat(toView, "alpha", 0f, 1f)
2588 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002589 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002590 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2591 @Override
2592 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002593 if (animation == null) {
2594 throw new RuntimeException("animation is null");
2595 }
Winson Chung70442722012-02-10 15:43:22 -08002596 float t = (Float) animation.getAnimatedValue();
2597 dispatchOnLauncherTransitionStep(fromView, t);
2598 dispatchOnLauncherTransitionStep(toView, t);
2599 }
2600 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002601
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002602 // toView should appear right at the end of the workspace shrink
2603 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002604 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002605 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002606 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002607
2608 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002609 boolean animationCancelled = false;
2610
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002611 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002612 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002613 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002614 // Prepare the position
2615 toView.setTranslationX(0.0f);
2616 toView.setTranslationY(0.0f);
2617 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002618 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002619 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002620 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002621 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002622 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2623 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002624
Michael Jurkafa7969f2012-09-21 16:39:14 -07002625 if (mWorkspace != null && !springLoaded && !LauncherApplication.isScreenLarge()) {
Winson Chung32174c82011-07-19 15:47:55 -07002626 // Hide the workspace scrollbar
2627 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002628 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002629 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002630 if (!animationCancelled) {
2631 updateWallpaperVisibility(false);
2632 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002633
2634 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002635 if (mSearchDropTargetBar != null) {
2636 mSearchDropTargetBar.hideSearchBar(false);
2637 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002638 }
2639
Adam Cohencff6af82011-09-13 14:51:53 -07002640 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002641 public void onAnimationCancel(Animator animation) {
2642 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002643 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002644 });
2645
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002646 if (workspaceAnim != null) {
2647 mStateAnimation.play(workspaceAnim);
2648 }
Michael Jurka1899a362011-11-03 13:50:45 -07002649
2650 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002651
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002652 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2653 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002654
2655 // If any of the objects being animated haven't been measured/laid out
2656 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002657 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002658 (mWorkspace.getMeasuredWidth() == 0) ||
2659 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002660 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002661 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002662
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002663 final AnimatorSet stateAnimation = mStateAnimation;
2664 final Runnable startAnimRunnable = new Runnable() {
2665 public void run() {
2666 // Check that mStateAnimation hasn't changed while
2667 // we waited for a layout/draw pass
2668 if (mStateAnimation != stateAnimation)
2669 return;
2670 setPivotsForZoom(toView, scale);
2671 dispatchOnLauncherTransitionStart(fromView, animated, false);
2672 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002673 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002674 }
2675 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002676 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002677 final ViewTreeObserver observer = toView.getViewTreeObserver();
2678 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2679 public void onGlobalLayout() {
2680 startAnimRunnable.run();
2681 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2682 }
2683 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002684 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002685 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002686 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002687 } else {
2688 toView.setTranslationX(0.0f);
2689 toView.setTranslationY(0.0f);
2690 toView.setScaleX(1.0f);
2691 toView.setScaleY(1.0f);
2692 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002693 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002694
Michael Jurkabed61d22012-02-14 22:51:29 -08002695 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2696 // Hide the workspace scrollbar
2697 mWorkspace.hideScrollingIndicator(true);
2698 hideDockDivider();
Winson Chungc7d2b602012-05-16 17:02:20 -07002699
2700 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002701 if (mSearchDropTargetBar != null) {
2702 mSearchDropTargetBar.hideSearchBar(false);
2703 }
Michael Jurkaabded662011-03-04 12:06:57 -08002704 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002705 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002706 dispatchOnLauncherTransitionStart(fromView, animated, false);
2707 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002708 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002709 dispatchOnLauncherTransitionStart(toView, animated, false);
2710 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002711 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002712 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002713 }
2714
2715 /**
2716 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002717 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002718 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002719 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002720 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2721 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002722
Michael Jurkab3e22d92011-10-31 15:58:33 -07002723 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002724 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002725 mStateAnimation.cancel();
2726 mStateAnimation = null;
2727 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002728 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002729
Winson Chungf0ea4d32011-06-06 14:27:16 -07002730 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002731 final int fadeOutDuration =
2732 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002733 final float scaleFactor = (float)
2734 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2735 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002736 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002737 Animator workspaceAnim = null;
2738
2739 if (toState == State.WORKSPACE) {
2740 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2741 workspaceAnim = mWorkspace.getChangeStateAnimation(
2742 Workspace.State.NORMAL, animated, stagger);
2743 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2744 workspaceAnim = mWorkspace.getChangeStateAnimation(
2745 Workspace.State.SPRING_LOADED, animated);
2746 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002747
Michael Jurkab3e22d92011-10-31 15:58:33 -07002748 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002749 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002750 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002751 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002752 final LauncherViewPropertyAnimator scaleAnim =
2753 new LauncherViewPropertyAnimator(fromView);
2754 scaleAnim.
2755 scaleX(scaleFactor).scaleY(scaleFactor).
2756 setDuration(duration).
2757 setInterpolator(new Workspace.ZoomInInterpolator());
2758
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002759 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002760 .ofFloat(fromView, "alpha", 1f, 0f)
2761 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002762 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002763 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2764 @Override
2765 public void onAnimationUpdate(ValueAnimator animation) {
2766 float t = 1f - (Float) animation.getAnimatedValue();
2767 dispatchOnLauncherTransitionStep(fromView, t);
2768 dispatchOnLauncherTransitionStep(toView, t);
2769 }
2770 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002771
Michael Jurka2ecf9952012-06-18 12:52:28 -07002772 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002773
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002774 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2775 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002776 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002777
2778 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002779 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002780 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002781 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002782 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002783 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2784 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkabafdaaf2012-04-26 13:43:25 -07002785 if (mWorkspace != null) {
2786 mWorkspace.hideScrollingIndicator(false);
2787 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002788 if (onCompleteRunnable != null) {
2789 onCompleteRunnable.run();
2790 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002791 mAppsCustomizeContent.updateCurrentPageScroll();
2792 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002793 }
2794 });
2795
Winson Chungf0ea4d32011-06-06 14:27:16 -07002796 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002797 if (workspaceAnim != null) {
2798 mStateAnimation.play(workspaceAnim);
2799 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002800 dispatchOnLauncherTransitionStart(fromView, animated, true);
2801 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002802 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002803 } else {
2804 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002805 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002806 dispatchOnLauncherTransitionStart(fromView, animated, true);
2807 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002808 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002809 dispatchOnLauncherTransitionStart(toView, animated, true);
2810 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002811 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002812 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002813 }
2814
Michael Jurkae326f182011-11-21 14:05:46 -08002815 @Override
2816 public void onTrimMemory(int level) {
2817 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002818 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002819 mAppsCustomizeTabHost.onTrimMemory();
2820 }
2821 }
2822
Winson Chung18f41f82012-05-09 13:28:10 -07002823 @Override
2824 public void onWindowFocusChanged(boolean hasFocus) {
2825 if (!hasFocus) {
2826 // When another window occludes launcher (like the notification shade, or recents),
2827 // ensure that we enable the wallpaper flag so that transitions are done correctly.
2828 updateWallpaperVisibility(true);
2829 } else {
2830 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07002831 mWorkspace.postDelayed(new Runnable() {
2832 @Override
2833 public void run() {
2834 disableWallpaperIfInAllApps();
2835 }
2836 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07002837 }
2838 }
2839
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002840 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002841 showWorkspace(animated, null);
2842 }
2843
2844 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002845 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002846 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002847 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002848 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002849
Winson Chungc7d2b602012-05-16 17:02:20 -07002850 // Show the search bar (only animate if we were showing the drop target bar in spring
2851 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07002852 if (mSearchDropTargetBar != null) {
2853 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
2854 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002855
Michael Jurkab737ee62011-11-15 15:57:22 -08002856 // We only need to animate in the dock divider if we're going from spring loaded mode
Winson Chungc7d2b602012-05-16 17:02:20 -07002857 showDockDivider(animated && wasInSpringLoadedMode);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002858
2859 // Set focus to the AppsCustomize button
2860 if (mAllAppsButton != null) {
2861 mAllAppsButton.requestFocus();
2862 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002863 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002864
Michael Jurkab737ee62011-11-15 15:57:22 -08002865 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002866
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002867 // Change the state *after* we've called all the transition code
2868 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002869
Winson Chung5fb63472011-02-02 17:03:37 -08002870 // Resume the auto-advance of widgets
2871 mUserPresent = true;
2872 updateRunning();
2873
alanv1d4fde62012-10-17 13:15:47 -07002874 // Send an accessibility event to announce the context change
2875 getWindow().getDecorView()
2876 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Joe Onorato00acb122009-08-04 16:04:30 -04002877 }
2878
Michael Jurkab3e22d92011-10-31 15:58:33 -07002879 void showAllApps(boolean animated) {
2880 if (mState != State.WORKSPACE) return;
2881
2882 showAppsCustomizeHelper(animated, false);
2883 mAppsCustomizeTabHost.requestFocus();
2884
Michael Jurkab3e22d92011-10-31 15:58:33 -07002885 // Change the state *after* we've called all the transition code
2886 mState = State.APPS_CUSTOMIZE;
2887
2888 // Pause the auto-advance of widgets until we are out of AllApps
2889 mUserPresent = false;
2890 updateRunning();
2891 closeFolder();
2892
2893 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07002894 getWindow().getDecorView()
2895 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002896 }
2897
Adam Cohen7777d962011-08-18 18:58:38 -07002898 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002899 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002900 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002901 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002902 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002903 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002904 }
Adam Cohen7777d962011-08-18 18:58:38 -07002905
Adam Cohened66b2b2012-01-23 17:28:51 -08002906 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2907 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002908 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2909
Winson Chunge7a03942011-08-05 15:05:12 -07002910 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002911 @Override
2912 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002913 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002914 // Before we show workspace, hide all apps again because
2915 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2916 // clean up our state transition functions
2917 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002918 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002919 } else {
2920 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002921 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002922 }
2923 }, (extendedDelay ?
2924 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2925 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2926 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002927
Michael Jurkad3ef3062010-11-23 16:23:58 -08002928 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002929 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002930 final boolean animated = true;
2931 final boolean springLoaded = true;
2932 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002933 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002934 }
2935 // Otherwise, we are not in spring loaded mode, so don't do anything.
2936 }
2937
Michael Jurkab737ee62011-11-15 15:57:22 -08002938 void hideDockDivider() {
2939 if (mQsbDivider != null && mDockDivider != null) {
2940 mQsbDivider.setVisibility(View.INVISIBLE);
2941 mDockDivider.setVisibility(View.INVISIBLE);
2942 }
2943 }
2944
2945 void showDockDivider(boolean animated) {
2946 if (mQsbDivider != null && mDockDivider != null) {
2947 mQsbDivider.setVisibility(View.VISIBLE);
2948 mDockDivider.setVisibility(View.VISIBLE);
2949 if (mDividerAnimator != null) {
2950 mDividerAnimator.cancel();
2951 mQsbDivider.setAlpha(1f);
2952 mDockDivider.setAlpha(1f);
2953 mDividerAnimator = null;
2954 }
2955 if (animated) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07002956 mDividerAnimator = LauncherAnimUtils.createAnimatorSet();
2957 mDividerAnimator.playTogether(LauncherAnimUtils.ofFloat(mQsbDivider, "alpha", 1f),
2958 LauncherAnimUtils.ofFloat(mDockDivider, "alpha", 1f));
Winson Chungadf0c182012-08-23 14:59:07 -07002959 int duration = 0;
2960 if (mSearchDropTargetBar != null) {
2961 duration = mSearchDropTargetBar.getTransitionInDuration();
2962 }
2963 mDividerAnimator.setDuration(duration);
Michael Jurkab737ee62011-11-15 15:57:22 -08002964 mDividerAnimator.start();
2965 }
2966 }
2967 }
2968
Michael Jurkab3e22d92011-10-31 15:58:33 -07002969 void lockAllApps() {
2970 // TODO
2971 }
2972
2973 void unlockAllApps() {
2974 // TODO
2975 }
2976
Winson Chungf0ea4d32011-06-06 14:27:16 -07002977 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002978 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002979 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002980 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002981 if (!LauncherApplication.isScreenLarge()) {
2982 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002983 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07002984 int duration = 0;
2985 if (mSearchDropTargetBar != null) {
2986 duration = mSearchDropTargetBar.getTransitionInDuration();
2987 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08002988 mHotseat.animate().alpha(1f).setDuration(duration);
2989 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002990 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002991 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002992 }
2993 }
2994 }
2995
2996 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002997 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002998 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002999 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003000 if (!LauncherApplication.isScreenLarge()) {
3001 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003002 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003003 int duration = 0;
3004 if (mSearchDropTargetBar != null) {
3005 duration = mSearchDropTargetBar.getTransitionOutDuration();
3006 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003007 mHotseat.animate().alpha(0f).setDuration(duration);
3008 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003009 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003010 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003011 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003012 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003013 }
3014
Patrick Dubroy5f445422011-02-18 14:35:21 -08003015 /**
3016 * Add an item from all apps or customize onto the given workspace screen.
3017 * If layout is null, add to the current screen.
3018 */
3019 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003020 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003021 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003022 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003023 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003024
Winson Chungdff8ebb2011-09-08 17:25:31 -07003025 /** Maps the current orientation to an index for referencing orientation correct global icons */
3026 private int getCurrentOrientationIndexForGlobalIcons() {
3027 // default - 0, landscape - 1
3028 switch (getResources().getConfiguration().orientation) {
3029 case Configuration.ORIENTATION_LANDSCAPE:
3030 return 1;
3031 default:
3032 return 0;
3033 }
3034 }
3035
Michael Jurkaae65ee32012-04-30 11:45:54 -07003036 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003037 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003038 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003039 // Look for the toolbar icon specified in the activity meta-data
3040 Bundle metaData = packageManager.getActivityInfo(
3041 activityName, PackageManager.GET_META_DATA).metaData;
3042 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003043 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003044 if (iconResId != 0) {
3045 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003046 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003047 }
3048 }
3049 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003050 // This can happen if the activity defines an invalid drawable
3051 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3052 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003053 } catch (Resources.NotFoundException nfe) {
3054 // This can happen if the activity defines an invalid drawable
3055 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3056 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003057 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003058 return null;
3059 }
3060
3061 // if successful in getting icon, return it; otherwise, set button to use default drawable
3062 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003063 int buttonId, ComponentName activityName, int fallbackDrawableId,
3064 String toolbarResourceName) {
3065 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003066 Resources r = getResources();
3067 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3068 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003069
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003070 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003071 // If we were unable to find the icon via the meta-data, use a generic one
3072 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003073 toolbarIcon = r.getDrawable(fallbackDrawableId);
3074 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003075 if (button != null) {
3076 button.setCompoundDrawables(toolbarIcon, null, null, null);
3077 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003078 return null;
3079 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003080 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 toolbarIcon.getConstantState();
3085 }
3086 }
3087
3088 // if successful in getting icon, return it; otherwise, set button to use default drawable
3089 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003090 int buttonId, ComponentName activityName, int fallbackDrawableId,
3091 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003092 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003093 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003094
Michael Jurka19e0fc52011-07-22 18:00:21 -07003095 if (button != null) {
3096 // If we were unable to find the icon via the meta-data, use a
3097 // generic one
3098 if (toolbarIcon == null) {
3099 button.setImageResource(fallbackDrawableId);
3100 } else {
3101 button.setImageDrawable(toolbarIcon);
3102 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003103 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003104
3105 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3106
Michael Jurka0423dcf2010-10-05 14:56:18 -07003107 }
3108
Winson Chung1b884092012-06-08 17:13:02 -07003109 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003110 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003111 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003112 }
3113
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003114 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003115 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003116 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003117 }
3118
Winson Chungbb185bd2011-11-21 12:31:42 -08003119 private void invalidatePressedFocusedStates(View container, View button) {
3120 if (container instanceof HolographicLinearLayout) {
3121 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3122 layout.invalidatePressedFocusedStates();
3123 } else if (button instanceof HolographicImageView) {
3124 HolographicImageView view = (HolographicImageView) button;
3125 view.invalidatePressedFocusedStates();
3126 }
3127 }
3128
Winson Chungc51db6a2011-10-05 11:44:49 -07003129 private boolean updateGlobalSearchIcon() {
3130 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003131 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003132 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003133 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07003134 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07003135
Winson Chung1cad91e2011-05-25 17:41:01 -07003136 final SearchManager searchManager =
3137 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3138 ComponentName activityName = searchManager.getGlobalSearchActivity();
3139 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003140 int coi = getCurrentOrientationIndexForGlobalIcons();
3141 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003142 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3143 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3144 if (sGlobalSearchIcon[coi] == null) {
3145 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3146 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3147 TOOLBAR_ICON_METADATA_NAME);
3148 }
3149
Winson Chungc51db6a2011-10-05 11:44:49 -07003150 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3151 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003152 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003153 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003154 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003155 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003156 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3157 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
3158 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003159 voiceButton.setVisibility(View.GONE);
Michael Jurkac60498a2012-05-07 15:29:42 -07003160 if (voiceButtonProxy != null) {
3161 voiceButtonProxy.setVisibility(View.GONE);
3162 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003163 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003164 }
3165 }
3166
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003167 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003168 final View searchButtonContainer = findViewById(R.id.search_button_container);
3169 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003170 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003171 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003172 }
3173
Winson Chungc51db6a2011-10-05 11:44:49 -07003174 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003175 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003176 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07003177 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07003178
Winson Chungc51db6a2011-10-05 11:44:49 -07003179 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003180 final SearchManager searchManager =
3181 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3182 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3183
3184 ComponentName activityName = null;
3185 if (globalSearchActivity != null) {
3186 // Check if the global search activity handles voice search
3187 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3188 intent.setPackage(globalSearchActivity.getPackageName());
3189 activityName = intent.resolveActivity(getPackageManager());
3190 }
3191
3192 if (activityName == null) {
3193 // Fallback: check if an activity other than the global search activity
3194 // resolves this
3195 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3196 activityName = intent.resolveActivity(getPackageManager());
3197 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003198 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003199 int coi = getCurrentOrientationIndexForGlobalIcons();
3200 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003201 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3202 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3203 if (sVoiceSearchIcon[coi] == null) {
3204 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3205 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3206 TOOLBAR_ICON_METADATA_NAME);
3207 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003208 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003209 voiceButton.setVisibility(View.VISIBLE);
Jim Miller14091b12012-04-24 19:27:54 -07003210 if (voiceButtonProxy != null) {
3211 voiceButtonProxy.setVisibility(View.VISIBLE);
3212 }
Winson Chungbb185bd2011-11-21 12:31:42 -08003213 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003214 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003215 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003216 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003217 voiceButton.setVisibility(View.GONE);
Jim Miller14091b12012-04-24 19:27:54 -07003218 if (voiceButtonProxy != null) {
3219 voiceButtonProxy.setVisibility(View.GONE);
3220 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003221 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003222 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003223 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003224
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003225 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003226 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3227 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003228 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003229 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003230 }
3231
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003232 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003233 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003234 */
3235 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003236 final View marketButton = findViewById(R.id.market_button);
3237 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3238 // Find the app market activity by resolving an intent.
3239 // (If multiple app markets are installed, it will return the ResolverActivity.)
3240 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003241 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003242 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003243 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003244 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003245 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3246 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003247 marketButton.setVisibility(View.VISIBLE);
3248 } else {
3249 // We should hide and disable the view so that we don't try and restore the visibility
3250 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3251 marketButton.setVisibility(View.GONE);
3252 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003253 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003254 }
3255
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003256 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003257 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3258 Resources r = getResources();
3259 Drawable marketIconDrawable = d.newDrawable(r);
3260 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3261 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3262 marketIconDrawable.setBounds(0, 0, w, h);
3263
3264 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003265 }
3266
Michael Jurkad7c28052012-04-27 15:43:36 -07003267 @Override
3268 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003269 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003270 final List<CharSequence> text = event.getText();
3271 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003272 // Populate event with a fake title based on the current state.
3273 if (mState == State.APPS_CUSTOMIZE) {
3274 text.add(getString(R.string.all_apps_button_label));
3275 } else {
3276 text.add(getString(R.string.all_apps_home_button_label));
3277 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003278 return result;
3279 }
3280
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003281 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003282 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003283 */
3284 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3285 @Override
3286 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003287 closeSystemDialogs();
3288 }
3289 }
3290
3291 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003292 * Receives notifications whenever the appwidgets are reset.
3293 */
3294 private class AppWidgetResetObserver extends ContentObserver {
3295 public AppWidgetResetObserver() {
3296 super(new Handler());
3297 }
3298
3299 @Override
3300 public void onChange(boolean selfChange) {
3301 onAppWidgetReset();
3302 }
3303 }
3304
3305 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003306 * If the activity is currently paused, signal that we need to run the passed Runnable
3307 * in onResume.
3308 *
3309 * This needs to be called from incoming places where resources might have been loaded
3310 * while we are paused. That is becaues the Configuration might be wrong
3311 * when we're not running, and if it comes back to what it was when we
3312 * were paused, we are not restarted.
3313 *
3314 * Implementation of the method from LauncherModel.Callbacks.
3315 *
3316 * @return true if we are currently paused. The caller might be able to
3317 * skip some work in that case since we will come back again.
3318 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003319 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003320 if (mPaused) {
3321 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003322 if (deletePreviousRunnables) {
3323 while (mOnResumeCallbacks.remove(run)) {
3324 }
3325 }
Michael Jurka7607c2f2013-04-03 14:33:19 -07003326 mOnResumeCallbacks.add(run);
3327 return true;
3328 } else {
3329 return false;
3330 }
3331 }
3332
Michael Jurkac402cd92013-05-20 15:49:32 +02003333 private boolean waitUntilResume(Runnable run) {
3334 return waitUntilResume(run, false);
3335 }
3336
Michael Jurka7607c2f2013-04-03 14:33:19 -07003337 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003338 * If the activity is currently paused, signal that we need to re-run the loader
3339 * in onResume.
3340 *
3341 * This needs to be called from incoming places where resources might have been loaded
3342 * while we are paused. That is becaues the Configuration might be wrong
3343 * when we're not running, and if it comes back to what it was when we
3344 * were paused, we are not restarted.
3345 *
3346 * Implementation of the method from LauncherModel.Callbacks.
3347 *
3348 * @return true if we are currently paused. The caller might be able to
3349 * skip some work in that case since we will come back again.
3350 */
3351 public boolean setLoadOnResume() {
3352 if (mPaused) {
3353 Log.i(TAG, "setLoadOnResume");
3354 mOnResumeNeedsLoad = true;
3355 return true;
3356 } else {
3357 return false;
3358 }
3359 }
3360
3361 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003362 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003363 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003364 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003365 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003366 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003367 } else {
3368 return SCREEN_COUNT / 2;
3369 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003370 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003371
Joe Onorato9c1289c2009-08-17 11:03:03 -04003372 /**
3373 * Refreshes the shortcuts shown on the workspace.
3374 *
3375 * Implementation of the method from LauncherModel.Callbacks.
3376 */
3377 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003378 // If we're starting binding all over again, clear any bind calls we'd postponed in
3379 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3380 // from scratch again
3381 mOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003382
Michael Jurka7607c2f2013-04-03 14:33:19 -07003383 final Workspace workspace = mWorkspace;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003384 mNewShortcutAnimatePage = -1;
3385 mNewShortcutAnimateViews.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003386 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003387 int count = workspace.getChildCount();
3388 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003389 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003390 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3391 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003392 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08003393 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003394 if (mHotseat != null) {
3395 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003396 }
3397 }
3398
3399 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003400 * Bind the items start-end from the list.
3401 *
3402 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003403 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003404 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end) {
3405 if (waitUntilResume(new Runnable() {
3406 public void run() {
3407 bindItems(shortcuts, start, end);
3408 }
3409 })) {
3410 return;
3411 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003412
Winson Chungf0c6ae02012-03-21 16:10:31 -07003413 // Get the list of added shortcuts and intersect them with the set of shortcuts here
3414 Set<String> newApps = new HashSet<String>();
3415 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);
3416
3417 Workspace workspace = mWorkspace;
3418 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003419 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003420
3421 // Short circuit if we are loading dock items for a configuration which has no dock
3422 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3423 mHotseat == null) {
3424 continue;
3425 }
3426
Joe Onorato9c1289c2009-08-17 11:03:03 -04003427 switch (item.itemType) {
3428 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3429 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003430 ShortcutInfo info = (ShortcutInfo) item;
3431 String uri = info.intent.toUri(0).toString();
3432 View shortcut = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -07003433 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3434 item.cellY, 1, 1, false);
Winson Chungbfeac062012-06-06 15:56:08 -07003435 boolean animateIconUp = false;
3436 synchronized (newApps) {
3437 if (newApps.contains(uri)) {
3438 animateIconUp = newApps.remove(uri);
3439 }
3440 }
3441 if (animateIconUp) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003442 // Prepare the view to be animated up
3443 shortcut.setAlpha(0f);
3444 shortcut.setScaleX(0f);
3445 shortcut.setScaleY(0f);
3446 mNewShortcutAnimatePage = item.screen;
3447 if (!mNewShortcutAnimateViews.contains(shortcut)) {
3448 mNewShortcutAnimateViews.add(shortcut);
3449 }
3450 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003451 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003452 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003453 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003454 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003455 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003456 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3457 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003458 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003459 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003460 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003461
Joe Onorato9c1289c2009-08-17 11:03:03 -04003462 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003463 }
3464
Joe Onorato9c1289c2009-08-17 11:03:03 -04003465 /**
3466 * Implementation of the method from LauncherModel.Callbacks.
3467 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003468 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
3469 if (waitUntilResume(new Runnable() {
3470 public void run() {
3471 bindFolders(folders);
3472 }
3473 })) {
3474 return;
3475 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003476 sFolders.clear();
3477 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003478 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003479
3480 /**
3481 * Add the views for a widget to the workspace.
3482 *
3483 * Implementation of the method from LauncherModel.Callbacks.
3484 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003485 public void bindAppWidget(final LauncherAppWidgetInfo item) {
3486 if (waitUntilResume(new Runnable() {
3487 public void run() {
3488 bindAppWidget(item);
3489 }
3490 })) {
3491 return;
3492 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003493
Daniel Sandler843e8602010-06-07 14:59:01 -04003494 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3495 if (DEBUG_WIDGETS) {
3496 Log.d(TAG, "bindAppWidget: " + item);
3497 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003498 final Workspace workspace = mWorkspace;
3499
3500 final int appWidgetId = item.appWidgetId;
3501 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003502 if (DEBUG_WIDGETS) {
3503 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3504 }
3505
Joe Onorato9c1289c2009-08-17 11:03:03 -04003506 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3507
Joe Onorato9c1289c2009-08-17 11:03:03 -04003508 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003509 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003510
Winson Chung3d503fb2011-07-13 17:25:49 -07003511 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003512 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003513 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3514
Joe Onorato9c1289c2009-08-17 11:03:03 -04003515 workspace.requestLayout();
3516
Daniel Sandler843e8602010-06-07 14:59:01 -04003517 if (DEBUG_WIDGETS) {
3518 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3519 + (SystemClock.uptimeMillis()-start) + "ms");
3520 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003521 }
3522
Adam Cohen1462de32012-07-24 22:34:36 -07003523 public void onPageBoundSynchronously(int page) {
3524 mSynchronouslyBoundPages.add(page);
3525 }
3526
Joe Onorato9c1289c2009-08-17 11:03:03 -04003527 /**
3528 * Callback saying that there aren't any more items to bind.
3529 *
3530 * Implementation of the method from LauncherModel.Callbacks.
3531 */
3532 public void finishBindingItems() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003533 if (waitUntilResume(new Runnable() {
3534 public void run() {
3535 finishBindingItems();
3536 }
3537 })) {
3538 return;
3539 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003540 if (mSavedState != null) {
3541 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003542 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003543 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003544 mSavedState = null;
3545 }
3546
Adam Cohen1462de32012-07-24 22:34:36 -07003547 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003548
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003549 // If we received the result of any pending adds while the loader was running (e.g. the
3550 // widget configuration forced an orientation change), process them now.
3551 for (int i = 0; i < sPendingAddList.size(); i++) {
3552 completeAdd(sPendingAddList.get(i));
3553 }
3554 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003555
Winson Chungc51db6a2011-10-05 11:44:49 -07003556 // Update the market app icon as necessary (the other icons will be managed in response to
3557 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003558 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003559
Winson Chungf0c6ae02012-03-21 16:10:31 -07003560 // Animate up any icons as necessary
3561 if (mVisible || mWorkspaceLoading) {
3562 Runnable newAppsRunnable = new Runnable() {
3563 @Override
3564 public void run() {
Winson Chunga2413752012-04-03 14:22:34 -07003565 runNewAppsAnimation(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003566 }
3567 };
Winson Chunga2413752012-04-03 14:22:34 -07003568
3569 boolean willSnapPage = mNewShortcutAnimatePage > -1 &&
3570 mNewShortcutAnimatePage != mWorkspace.getCurrentPage();
3571 if (canRunNewAppsAnimation()) {
3572 // If the user has not interacted recently, then either snap to the new page to show
3573 // the new-apps animation or just run them if they are to appear on the current page
3574 if (willSnapPage) {
3575 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable);
3576 } else {
3577 runNewAppsAnimation(false);
3578 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003579 } else {
Winson Chung318eee02012-04-12 10:59:27 -07003580 // If the user has interacted recently, then just add the items in place if they
Winson Chunga2413752012-04-03 14:22:34 -07003581 // are on another page (or just normally if they are added to the current page)
3582 runNewAppsAnimation(willSnapPage);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003583 }
3584 }
3585
3586 mWorkspaceLoading = false;
3587 }
3588
Winson Chunga2413752012-04-03 14:22:34 -07003589 private boolean canRunNewAppsAnimation() {
3590 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3591 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3592 }
3593
Winson Chungf0c6ae02012-03-21 16:10:31 -07003594 /**
3595 * Runs a new animation that scales up icons that were added while Launcher was in the
3596 * background.
Winson Chunga2413752012-04-03 14:22:34 -07003597 *
3598 * @param immediate whether to run the animation or show the results immediately
Winson Chungf0c6ae02012-03-21 16:10:31 -07003599 */
Winson Chunga2413752012-04-03 14:22:34 -07003600 private void runNewAppsAnimation(boolean immediate) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07003601 AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003602 Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chunga2413752012-04-03 14:22:34 -07003603
3604 // Order these new views spatially so that they animate in order
Winson Chungf0c6ae02012-03-21 16:10:31 -07003605 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
3606 @Override
3607 public int compare(View a, View b) {
3608 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
3609 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
3610 int cellCountX = LauncherModel.getCellCountX();
3611 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
3612 }
3613 });
Winson Chunga2413752012-04-03 14:22:34 -07003614
3615 // Animate each of the views in place (or show them immediately if requested)
3616 if (immediate) {
3617 for (View v : mNewShortcutAnimateViews) {
3618 v.setAlpha(1f);
3619 v.setScaleX(1f);
3620 v.setScaleY(1f);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003621 }
Winson Chunga2413752012-04-03 14:22:34 -07003622 } else {
3623 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
3624 View v = mNewShortcutAnimateViews.get(i);
Michael Jurka2ecf9952012-06-18 12:52:28 -07003625 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
Winson Chunga2413752012-04-03 14:22:34 -07003626 PropertyValuesHolder.ofFloat("alpha", 1f),
3627 PropertyValuesHolder.ofFloat("scaleX", 1f),
3628 PropertyValuesHolder.ofFloat("scaleY", 1f));
3629 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3630 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3631 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3632 bounceAnims.add(bounceAnim);
3633 }
3634 anim.playTogether(bounceAnims);
3635 anim.addListener(new AnimatorListenerAdapter() {
3636 @Override
3637 public void onAnimationEnd(Animator animation) {
Michael Jurkad6dd7c82012-10-19 17:15:16 +02003638 if (mWorkspace != null) {
3639 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
3640 }
Winson Chunga2413752012-04-03 14:22:34 -07003641 }
3642 });
3643 anim.start();
3644 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003645
3646 // Clean up
3647 mNewShortcutAnimatePage = -1;
3648 mNewShortcutAnimateViews.clear();
3649 new Thread("clearNewAppsThread") {
3650 public void run() {
3651 mSharedPrefs.edit()
3652 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
3653 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null)
3654 .commit();
3655 }
3656 }.start();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003657 }
3658
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003659 @Override
3660 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003661 boolean searchVisible = updateGlobalSearchIcon();
3662 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003663 if (mSearchDropTargetBar != null) {
3664 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3665 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003666 }
3667
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003668 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003669 * Add the icons for all apps.
3670 *
3671 * Implementation of the method from LauncherModel.Callbacks.
3672 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003673 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003674 Runnable setAllAppsRunnable = new Runnable() {
3675 public void run() {
3676 if (mAppsCustomizeContent != null) {
3677 mAppsCustomizeContent.setApps(apps);
3678 }
3679 }
3680 };
3681
Michael Jurkac57b7a82011-08-09 22:02:20 -07003682 // Remove the progress bar entirely; we could also make it GONE
3683 // but better to remove it since we know it's not going to be used
3684 View progressBar = mAppsCustomizeTabHost.
3685 findViewById(R.id.apps_customize_progress_bar);
3686 if (progressBar != null) {
3687 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chungc93e5ae2012-07-23 20:48:26 -07003688
3689 // We just post the call to setApps so the user sees the progress bar
3690 // disappear-- otherwise, it just looks like the progress bar froze
3691 // which doesn't look great
3692 mAppsCustomizeTabHost.post(setAllAppsRunnable);
3693 } else {
3694 // If we did not initialize the spinner in onCreate, then we can directly set the
3695 // list of applications without waiting for any progress bars views to be hidden.
3696 setAllAppsRunnable.run();
Winson Chung785d2eb2011-04-14 16:08:02 -07003697 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003698 }
3699
3700 /**
3701 * A package was installed.
3702 *
3703 * Implementation of the method from LauncherModel.Callbacks.
3704 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003705 public void bindAppsAdded(final ArrayList<ApplicationInfo> apps) {
3706 if (waitUntilResume(new Runnable() {
3707 public void run() {
3708 bindAppsAdded(apps);
3709 }
3710 })) {
3711 return;
3712 }
3713
Winson Chungf0ea4d32011-06-06 14:27:16 -07003714
Winson Chung785d2eb2011-04-14 16:08:02 -07003715 if (mAppsCustomizeContent != null) {
3716 mAppsCustomizeContent.addApps(apps);
3717 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003718 }
3719
3720 /**
3721 * A package was updated.
3722 *
3723 * Implementation of the method from LauncherModel.Callbacks.
3724 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003725 public void bindAppsUpdated(final ArrayList<ApplicationInfo> apps) {
3726 if (waitUntilResume(new Runnable() {
3727 public void run() {
3728 bindAppsUpdated(apps);
3729 }
3730 })) {
3731 return;
3732 }
3733
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003734 if (mWorkspace != null) {
3735 mWorkspace.updateShortcuts(apps);
3736 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003737
Winson Chung785d2eb2011-04-14 16:08:02 -07003738 if (mAppsCustomizeContent != null) {
3739 mAppsCustomizeContent.updateApps(apps);
3740 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003741 }
3742
3743 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003744 * A package was uninstalled. We take both the super set of packageNames
3745 * in addition to specific applications to remove, the reason being that
3746 * this can be called when a package is updated as well. In that scenario,
3747 * we only remove specific components from the workspace, where as
3748 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003749 *
3750 * Implementation of the method from LauncherModel.Callbacks.
3751 */
Winson Chung83892cc2013-05-01 16:53:33 -07003752 public void bindComponentsRemoved(final ArrayList<String> packageNames,
3753 final ArrayList<ApplicationInfo> appInfos,
3754 final boolean matchPackageNamesOnly) {
3755 if (waitUntilResume(new Runnable() {
3756 public void run() {
3757 bindComponentsRemoved(packageNames, appInfos, matchPackageNamesOnly);
3758 }
3759 })) {
3760 return;
3761 }
3762
3763 if (matchPackageNamesOnly) {
3764 mWorkspace.removeItemsByPackageName(packageNames);
3765 } else {
3766 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003767 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003768
Winson Chung785d2eb2011-04-14 16:08:02 -07003769 if (mAppsCustomizeContent != null) {
Winson Chung83892cc2013-05-01 16:53:33 -07003770 mAppsCustomizeContent.removeApps(appInfos);
Winson Chung785d2eb2011-04-14 16:08:02 -07003771 }
Winson Chunga1820962011-10-03 16:31:06 -07003772
3773 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003774 mDragController.onAppsRemoved(appInfos, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003775 }
Joe Onoratobe386092009-11-17 17:32:16 -08003776
3777 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003778 * A number of packages were updated.
3779 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003780
3781 private ArrayList<Object> mWidgetsAndShortcuts;
3782 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003783 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003784 bindPackagesUpdated(mWidgetsAndShortcuts);
3785 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003786 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003787 };
3788
3789 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3790 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3791 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003792 return;
3793 }
3794
Winson Chung785d2eb2011-04-14 16:08:02 -07003795 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003796 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003797 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003798 }
3799
Winson Chung400438b2011-01-16 17:53:48 -08003800 private int mapConfigurationOriActivityInfoOri(int configOri) {
3801 final Display d = getWindowManager().getDefaultDisplay();
3802 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3803 switch (d.getRotation()) {
3804 case Surface.ROTATION_0:
3805 case Surface.ROTATION_180:
3806 // We are currently in the same basic orientation as the natural orientation
3807 naturalOri = configOri;
3808 break;
3809 case Surface.ROTATION_90:
3810 case Surface.ROTATION_270:
3811 // We are currently in the other basic orientation to the natural orientation
3812 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3813 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3814 break;
3815 }
3816
3817 int[] oriMap = {
3818 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3819 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3820 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3821 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3822 };
3823 // Since the map starts at portrait, we need to offset if this device's natural orientation
3824 // is landscape.
3825 int indexOffset = 0;
3826 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3827 indexOffset = 1;
3828 }
3829 return oriMap[(d.getRotation() + indexOffset) % 4];
3830 }
Adam Cohen446e9402011-09-15 18:21:21 -07003831
Winson Chung4b919f82012-05-01 10:44:08 -07003832 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08003833 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07003834 getResources().getBoolean(R.bool.allow_rotation);
3835 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08003836 }
Winson Chung4b919f82012-05-01 10:44:08 -07003837 public void lockScreenOrientation() {
3838 if (isRotationEnabled()) {
3839 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3840 .getConfiguration().orientation));
3841 }
3842 }
3843 public void unlockScreenOrientation(boolean immediate) {
3844 if (isRotationEnabled()) {
3845 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07003846 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07003847 } else {
3848 mHandler.postDelayed(new Runnable() {
3849 public void run() {
3850 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3851 }
3852 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07003853 }
Winson Chung4b919f82012-05-01 10:44:08 -07003854 }
Winson Chung400438b2011-01-16 17:53:48 -08003855 }
3856
Winson Chung82f55532011-08-09 14:14:23 -07003857 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003858 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003859 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003860 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003861
Michael Jurkae233a8b2013-03-19 13:49:20 +01003862 // Restricted secondary users (child mode) will potentially have very few apps
3863 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04003864// boolean supportsLimitedUsers =
3865// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
3866// Account[] accounts = AccountManager.get(this).getAccounts();
3867// if (supportsLimitedUsers && accounts.length == 0) {
3868// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
3869// Bundle restrictions = um.getUserRestrictions();
3870// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
3871// return false;
3872// }
3873// }
Winson Chung7d7541e2011-09-16 20:14:36 -07003874 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003875 }
Michael Jurka22143132012-10-04 17:42:38 +02003876
Winson Chung7d7541e2011-09-16 20:14:36 -07003877 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
Michael Jurka22143132012-10-04 17:42:38 +02003878 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07003879 if (cling != null) {
3880 cling.init(this, positionData);
3881 cling.setVisibility(View.VISIBLE);
3882 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3883 if (animate) {
3884 cling.buildLayer();
3885 cling.setAlpha(0f);
3886 cling.animate()
3887 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003888 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003889 .setDuration(SHOW_CLING_DURATION)
3890 .setStartDelay(delay)
3891 .start();
3892 } else {
3893 cling.setAlpha(1f);
3894 }
Michael Jurka22143132012-10-04 17:42:38 +02003895 cling.setFocusableInTouchMode(true);
3896 cling.post(new Runnable() {
3897 public void run() {
3898 cling.setFocusable(true);
3899 cling.requestFocus();
3900 }
3901 });
3902 mHideFromAccessibilityHelper.setImportantForAccessibilityToNo(
3903 mDragLayer, clingId == R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003904 }
3905 return cling;
3906 }
Michael Jurka22143132012-10-04 17:42:38 +02003907
Winson Chung7d7541e2011-09-16 20:14:36 -07003908 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung7819abd2012-11-29 14:29:38 -08003909 // To catch cases where siblings of top-level views are made invisible, just check whether
3910 // the cling is directly set to GONE before dismissing it.
3911 if (cling != null && cling.getVisibility() != View.GONE) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07003912 ObjectAnimator anim = LauncherAnimUtils.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003913 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003914 anim.addListener(new AnimatorListenerAdapter() {
3915 public void onAnimationEnd(Animator animation) {
3916 cling.setVisibility(View.GONE);
3917 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003918 // We should update the shared preferences on a background thread
3919 new Thread("dismissClingThread") {
3920 public void run() {
3921 SharedPreferences.Editor editor = mSharedPrefs.edit();
3922 editor.putBoolean(flag, true);
3923 editor.commit();
3924 }
3925 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003926 };
3927 });
3928 anim.start();
Michael Jurka22143132012-10-04 17:42:38 +02003929 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung82f55532011-08-09 14:14:23 -07003930 }
3931 }
Michael Jurka22143132012-10-04 17:42:38 +02003932
Winson Chung9d9d74f2011-09-19 11:49:12 -07003933 private void removeCling(int id) {
3934 final View cling = findViewById(id);
3935 if (cling != null) {
3936 final ViewGroup parent = (ViewGroup) cling.getParent();
3937 parent.post(new Runnable() {
3938 @Override
3939 public void run() {
3940 parent.removeView(cling);
3941 }
3942 });
Michael Jurka22143132012-10-04 17:42:38 +02003943 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003944 }
3945 }
Michael Jurka974c3862012-05-22 22:00:31 -07003946
3947 private boolean skipCustomClingIfNoAccounts() {
3948 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3949 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
3950 if (customCling) {
3951 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04003952 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07003953 Account[] accounts = am.getAccountsByType("com.google");
3954 return accounts.length == 0;
3955 }
3956 return false;
3957 }
3958
Winson Chung7d7541e2011-09-16 20:14:36 -07003959 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003960 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003961 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07003962 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
3963 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02003964 // If we're not using the default workspace layout, replace workspace cling
3965 // with a custom workspace cling (usually specified in an overlay)
3966 // For now, only do this on tablets
3967 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
Michael Jurkaa1131212012-10-09 14:46:26 +02003968 getResources().getBoolean(R.bool.config_useCustomClings)) {
Michael Jurka45355c42012-10-08 13:21:35 +02003969 // Use a custom cling
3970 View cling = findViewById(R.id.workspace_cling);
3971 ViewGroup clingParent = (ViewGroup) cling.getParent();
3972 int clingIndex = clingParent.indexOfChild(cling);
3973 clingParent.removeViewAt(clingIndex);
3974 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
3975 clingParent.addView(customCling, clingIndex);
3976 customCling.setId(R.id.workspace_cling);
3977 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003978 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003979 } else {
3980 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003981 }
3982 }
3983 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003984 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003985 if (isClingsEnabled() &&
3986 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003987 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003988 } else {
3989 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003990 }
3991 }
3992 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003993 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003994 if (isClingsEnabled() &&
3995 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
3996 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003997 } else {
3998 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08003999 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004000 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004001 }
4002 public boolean isFolderClingVisible() {
4003 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004004 if (cling != null) {
4005 return cling.getVisibility() == View.VISIBLE;
4006 }
4007 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004008 }
Winson Chung82f55532011-08-09 14:14:23 -07004009 public void dismissWorkspaceCling(View v) {
4010 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004011 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004012 }
4013 public void dismissAllAppsCling(View v) {
4014 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004015 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
4016 }
4017 public void dismissFolderCling(View v) {
4018 Cling cling = (Cling) findViewById(R.id.folder_cling);
4019 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004020 }
4021
Winson Chung80baf5a2010-08-09 16:03:15 -07004022 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004023 * Prints out out state for debugging.
4024 */
4025 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004026 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004027 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004028 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4029 Log.d(TAG, "mRestoring=" + mRestoring);
4030 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4031 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004032 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004033 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004034
Winson Chung785d2eb2011-04-14 16:08:02 -07004035 if (mAppsCustomizeContent != null) {
4036 mAppsCustomizeContent.dumpState();
4037 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004038 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004039 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004040
4041 @Override
4042 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4043 super.dump(prefix, fd, writer, args);
4044 writer.println(" ");
4045 writer.println("Debug logs: ");
4046 for (int i = 0; i < sDumpLogs.size(); i++) {
4047 writer.println(" " + sDumpLogs.get(i));
4048 }
4049 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004050
4051 public static void dumpDebugLogsToConsole() {
4052 Log.d(TAG, "");
4053 Log.d(TAG, "*********************");
4054 Log.d(TAG, "Launcher debug logs: ");
4055 for (int i = 0; i < sDumpLogs.size(); i++) {
4056 Log.d(TAG, " " + sDumpLogs.get(i));
4057 }
4058 Log.d(TAG, "*********************");
4059 Log.d(TAG, "");
4060 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004061}
Michael Jurka2763be32011-02-24 11:19:57 -08004062
Michael Jurkaabded662011-03-04 12:06:57 -08004063interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004064 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004065 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004066 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004067 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004068 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004069}