blob: be83ee012e08771a774e639921dd85dc98d7d6cd [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;
Adam Cohen7564d982013-06-06 23:11:58 -0700264 private static final boolean DISABLE_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400265
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700266 private static LocaleConfiguration sLocaleConfiguration = null;
267
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700268 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700269
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700270 private Intent mAppMarketIntent = null;
271
Adam Cohended9f8d2010-11-03 13:25:16 -0700272 // Related to the auto-advancing of widgets
273 private final int ADVANCE_MSG = 1;
274 private final int mAdvanceInterval = 20000;
275 private final int mAdvanceStagger = 250;
276 private long mAutoAdvanceSentTime;
277 private long mAutoAdvanceTimeLeft = -1;
278 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
279 new HashMap<View, AppWidgetProviderInfo>();
280
Winson Chung400438b2011-01-16 17:53:48 -0800281 // Determines how long to wait after a rotation before restoring the screen orientation to
282 // match the sensor state.
283 private final int mRestoreScreenOrientationDelay = 500;
284
Michael Jurka4ef207b2010-11-29 17:05:45 -0800285 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700286 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
287 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
288 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800289
Craig Mautner360310b2012-10-26 15:13:08 -0700290 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700291
Adam Cohen1462de32012-07-24 22:34:36 -0700292 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
293
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700294 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
295
Winson Chung46353de2012-02-16 14:05:10 -0800296 // We only want to get the SharedPreferences once since it does an FS stat each time we get
297 // it from the context.
298 private SharedPreferences mSharedPrefs;
299
Adam Cohene25af792013-06-06 23:08:25 -0700300 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
301
Winson Chungf0c6ae02012-03-21 16:10:31 -0700302 // Holds the page that we need to animate to, and the icon views that we need to animate up
303 // when we scroll to that page on resume.
304 private int mNewShortcutAnimatePage = -1;
305 private ArrayList<View> mNewShortcutAnimateViews = new ArrayList<View>();
Adam Cohen268c4752012-06-06 17:47:33 -0700306 private ImageView mFolderIconImageView;
307 private Bitmap mFolderIconBitmap;
308 private Canvas mFolderIconCanvas;
309 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700310
Michael Jurkaddd62e92011-02-16 17:49:14 -0800311 private BubbleTextView mWaitingForResume;
312
Michael Jurka22143132012-10-04 17:42:38 +0200313 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
314 = new HideFromAccessibilityHelper();
315
Michael Jurkac1f5d262011-09-30 19:32:27 -0700316 private Runnable mBuildLayersRunnable = new Runnable() {
317 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700318 if (mWorkspace != null) {
319 mWorkspace.buildPageHardwareLayers();
320 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700321 }
322 };
323
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800324 private static ArrayList<PendingAddArguments> sPendingAddList
325 = new ArrayList<PendingAddArguments>();
326
Michael Jurka0a457bf2012-11-19 14:05:05 -0800327 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
328
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800329 private static class PendingAddArguments {
330 int requestCode;
331 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700332 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800333 int screen;
334 int cellX;
335 int cellY;
336 }
337
Michael Jurka0a457bf2012-11-19 14:05:05 -0800338 private static boolean isPropertyEnabled(String propertyName) {
339 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700340 }
341
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800342 @Override
343 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700344 if (DEBUG_STRICT_MODE) {
345 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
346 .detectDiskReads()
347 .detectDiskWrites()
348 .detectNetwork() // or .detectAll() for all detectable problems
349 .penaltyLog()
350 .build());
351 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
352 .detectLeakedSqlLiteObjects()
353 .detectLeakedClosableObjects()
354 .penaltyLog()
355 .penaltyDeath()
356 .build());
357 }
358
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800359 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800360 LauncherApplication app = ((LauncherApplication)getApplication());
Winson Chungf0c6ae02012-03-21 16:10:31 -0700361 mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(),
362 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800363 mModel = app.setLauncher(this);
364 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400365 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800366 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700367
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700368 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700369 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
370 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700371
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700372 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
373 // this also ensures that any synchronous binding below doesn't re-trigger another
374 // LauncherModel load.
375 mPaused = false;
376
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800377 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200378 android.os.Debug.startMethodTracing(
379 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800380 }
381
382 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800383 setContentView(R.layout.launcher);
384 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700385 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800386
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800387 registerContentObservers();
388
Joe Onorato7c312c12009-08-13 21:36:53 -0700389 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700390
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800391 mSavedState = savedInstanceState;
392 restoreState(mSavedState);
393
Winson Chunga12a2502010-12-20 14:41:35 -0800394 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700395 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200396 mAppsCustomizeContent.onPackagesUpdated(
397 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700398 }
Winson Chunga12a2502010-12-20 14:41:35 -0800399
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800400 if (PROFILE_STARTUP) {
401 android.os.Debug.stopMethodTracing();
402 }
403
404 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700405 if (sPausedFromUserAction) {
406 // If the user leaves launcher, then we should just load items asynchronously when
407 // they return.
408 mModel.startLoader(true, -1);
409 } else {
410 // We only load the page synchronously if the user rotates (or triggers a
411 // configuration change) while launcher is in the foreground
412 mModel.startLoader(true, mWorkspace.getCurrentPage());
413 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800414 }
415
Michael Jurkac57b7a82011-08-09 22:02:20 -0700416 if (!mModel.isAllAppsLoaded()) {
417 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
418 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
419 }
420
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800421 // For handling default keys
422 mDefaultKeySsb = new SpannableStringBuilder();
423 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800424
425 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
426 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800427
Adam Cohenf9426d52012-06-04 17:26:21 -0700428 updateGlobalIcons();
429
430 // On large interfaces, we want the screen to auto-rotate based on the current orientation
431 unlockScreenOrientation(true);
432 }
433
Winson Chung4a2afa32012-07-19 14:53:05 -0700434 protected void onUserLeaveHint() {
435 super.onUserLeaveHint();
436 sPausedFromUserAction = true;
437 }
438
Adam Cohenf9426d52012-06-04 17:26:21 -0700439 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700440 boolean searchVisible = false;
441 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800442 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700443 int coi = getCurrentOrientationIndexForGlobalIcons();
444 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
445 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700446 updateAppMarketIcon();
447 searchVisible = updateGlobalSearchIcon();
448 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700449 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700450 if (sGlobalSearchIcon[coi] != null) {
451 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700452 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700453 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700454 if (sVoiceSearchIcon[coi] != null) {
455 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700456 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700457 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700458 if (sAppMarketIcon[coi] != null) {
459 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800460 }
Winson Chungadf0c182012-08-23 14:59:07 -0700461 if (mSearchDropTargetBar != null) {
462 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
463 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800464 }
Romain Guycbb89e42009-06-08 15:52:54 -0700465
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800466 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700467 if (sLocaleConfiguration == null) {
468 new AsyncTask<Void, Void, LocaleConfiguration>() {
469 @Override
470 protected LocaleConfiguration doInBackground(Void... unused) {
471 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
472 readConfiguration(Launcher.this, localeConfiguration);
473 return localeConfiguration;
474 }
475
476 @Override
477 protected void onPostExecute(LocaleConfiguration result) {
478 sLocaleConfiguration = result;
479 checkForLocaleChange(); // recursive, but now with a locale configuration
480 }
481 }.execute();
482 return;
483 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700484
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800485 final Configuration configuration = getResources().getConfiguration();
486
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700487 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800488 final String locale = configuration.locale.toString();
489
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700490 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800491 final int mcc = configuration.mcc;
492
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700493 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800494 final int mnc = configuration.mnc;
495
Romain Guy84f296c2009-11-04 15:00:44 -0800496 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800497
Romain Guy84f296c2009-11-04 15:00:44 -0800498 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700499 sLocaleConfiguration.locale = locale;
500 sLocaleConfiguration.mcc = mcc;
501 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700502
Joe Onorato0589f0f2010-02-08 13:44:00 -0800503 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700504
505 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
506 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700507 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700508 public void run() {
509 writeConfiguration(Launcher.this, localeConfiguration);
510 }
511 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700512 }
513 }
514
515 private static class LocaleConfiguration {
516 public String locale;
517 public int mcc = -1;
518 public int mnc = -1;
519 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700520
Romain Guy98d01652009-06-30 16:21:04 -0700521 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
522 DataInputStream in = null;
523 try {
524 in = new DataInputStream(context.openFileInput(PREFERENCES));
525 configuration.locale = in.readUTF();
526 configuration.mcc = in.readInt();
527 configuration.mnc = in.readInt();
528 } catch (FileNotFoundException e) {
529 // Ignore
530 } catch (IOException e) {
531 // Ignore
532 } finally {
533 if (in != null) {
534 try {
535 in.close();
536 } catch (IOException e) {
537 // Ignore
538 }
539 }
540 }
541 }
542
543 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
544 DataOutputStream out = null;
545 try {
546 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
547 out.writeUTF(configuration.locale);
548 out.writeInt(configuration.mcc);
549 out.writeInt(configuration.mnc);
550 out.flush();
551 } catch (FileNotFoundException e) {
552 // Ignore
553 } catch (IOException e) {
554 //noinspection ResultOfMethodCallIgnored
555 context.getFileStreamPath(PREFERENCES).delete();
556 } finally {
557 if (out != null) {
558 try {
559 out.close();
560 } catch (IOException e) {
561 // Ignore
562 }
563 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564 }
565 }
566
Adam Cohen716b51e2011-06-30 12:09:54 -0700567 public DragLayer getDragLayer() {
568 return mDragLayer;
569 }
570
Winson Chung36a62fe2012-05-06 18:04:42 -0700571 boolean isDraggingEnabled() {
572 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
573 // that is subsequently removed from the workspace in startBinding().
574 return !mModel.isLoadingWorkspace();
575 }
576
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800577 static int getScreen() {
578 synchronized (sLock) {
579 return sScreen;
580 }
581 }
582
583 static void setScreen(int screen) {
584 synchronized (sLock) {
585 sScreen = screen;
586 }
587 }
588
Winson Chung557d6ed2011-07-08 15:34:52 -0700589 /**
590 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
591 * a configuration step, this allows the proper animations to run after other transitions.
592 */
593 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700594 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800595 switch (args.requestCode) {
596 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700597 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
598 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800599 break;
600 case REQUEST_PICK_SHORTCUT:
601 processShortcut(args.intent);
602 break;
603 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700604 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
605 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700606 result = true;
607 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800608 case REQUEST_CREATE_APPWIDGET:
609 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800610 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700611 result = true;
612 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800613 case REQUEST_PICK_WALLPAPER:
614 // We just wanted the activity result here so we can clear mWaitingForResult
615 break;
616 }
Michael Jurka27614d22012-04-02 06:40:22 -0700617 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
618 // if you turned the screen off and then back while in All Apps, Launcher would not
619 // return to the workspace. Clearing mAddInfo.container here fixes this issue
620 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700621 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800622 }
623
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800624 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700625 protected void onActivityResult(
626 final int requestCode, final int resultCode, final Intent data) {
627 if (requestCode == REQUEST_BIND_APPWIDGET) {
628 int appWidgetId = data != null ?
629 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
630 if (resultCode == RESULT_CANCELED) {
631 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
632 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700633 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700634 }
635 return;
636 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700637 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800638 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
639 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700640 mWaitingForResult = false;
641
Adam Cohened66b2b2012-01-23 17:28:51 -0800642 // We have special handling for widgets
643 if (isWidgetDrop) {
644 int appWidgetId = data != null ?
645 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700646 if (appWidgetId < 0) {
647 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
648 "widget configuration activity.");
649 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
650 } else {
651 completeTwoStageWidgetDrop(resultCode, appWidgetId);
652 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800653 return;
654 }
655
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800656 // The pattern used here is that a user PICKs a specific application,
657 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700658
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800659 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
660 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700661 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800662 final PendingAddArguments args = new PendingAddArguments();
663 args.requestCode = requestCode;
664 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700665 args.container = mPendingAddInfo.container;
666 args.screen = mPendingAddInfo.screen;
667 args.cellX = mPendingAddInfo.cellX;
668 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800669 if (isWorkspaceLocked()) {
670 sPendingAddList.add(args);
671 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700672 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800674 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800675 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700676 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800677 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
678 null);
679 }
680
681 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700682 CellLayout cellLayout =
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700683 (CellLayout) mWorkspace.getChildAt(mPendingAddInfo.screen);
Adam Cohened66b2b2012-01-23 17:28:51 -0800684 Runnable onCompleteRunnable = null;
685 int animationType = 0;
686
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700687 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800688 if (resultCode == RESULT_OK) {
689 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
690 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700691 mPendingAddWidgetInfo);
692 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800693 onCompleteRunnable = new Runnable() {
694 @Override
695 public void run() {
696 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
697 mPendingAddInfo.screen, layout, null);
698 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
699 null);
700 }
701 };
702 } else if (resultCode == RESULT_CANCELED) {
703 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
704 onCompleteRunnable = new Runnable() {
705 @Override
706 public void run() {
707 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
708 null);
709 }
710 };
711 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700712 if (mDragLayer.getAnimatedView() != null) {
713 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
714 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
715 animationType, boundWidget, true);
716 } else {
717 // The animated view may be null in the case of a rotation during widget configuration
718 onCompleteRunnable.run();
719 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800720 }
721
722 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700723 protected void onStop() {
724 super.onStop();
725 FirstFrameAnimatorHelper.setIsVisible(false);
726 }
727
728 @Override
729 protected void onStart() {
730 super.onStart();
731 FirstFrameAnimatorHelper.setIsVisible(true);
732 }
733
734 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800735 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200736 long startTime = 0;
737 if (DEBUG_RESUME_TIME) {
738 startTime = System.currentTimeMillis();
739 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800740 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700741
Winson Chung4a2afa32012-07-19 14:53:05 -0700742 // Restore the previous launcher state
743 if (mOnResumeState == State.WORKSPACE) {
744 showWorkspace(false);
745 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
746 showAllApps(false);
747 }
748 mOnResumeState = State.NONE;
749
Craig Mautner360310b2012-10-26 15:13:08 -0700750 // Background was set to gradient in onPause(), restore to black if in all apps.
751 setWorkspaceBackground(mState == State.WORKSPACE);
752
Winson Chungde0fb8f2012-05-08 14:37:08 -0700753 // Process any items that were added while Launcher was away
754 InstallShortcutReceiver.flushInstallQueue(this);
755
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800756 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700757 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700758 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400759 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700760 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400761 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700762 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800763 }
Michael Jurkac402cd92013-05-20 15:49:32 +0200764 if (mOnResumeCallbacks.size() > 0) {
765 // We might have postponed some bind calls until onResume (see waitUntilResume) --
766 // execute them here
767 long startTimeCallbacks = 0;
768 if (DEBUG_RESUME_TIME) {
769 startTimeCallbacks = System.currentTimeMillis();
770 }
771
772 if (mAppsCustomizeContent != null) {
773 mAppsCustomizeContent.setBulkBind(true);
774 }
775 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
776 mOnResumeCallbacks.get(i).run();
777 }
778 if (mAppsCustomizeContent != null) {
779 mAppsCustomizeContent.setBulkBind(false);
780 }
781 mOnResumeCallbacks.clear();
782 if (DEBUG_RESUME_TIME) {
783 Log.d(TAG, "Time spent processing callbacks in onResume: " +
784 (System.currentTimeMillis() - startTimeCallbacks));
785 }
Michael Jurka447bf842013-05-15 14:52:15 +0200786 }
Winson Chunge4e50662012-01-23 14:45:13 -0800787
788 // Reset the pressed state of icons that were locked in the press state while activities
789 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800790 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800791 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800792 mWaitingForResume.setStayPressed(false);
793 }
Winson Chunge4e50662012-01-23 14:45:13 -0800794 if (mAppsCustomizeContent != null) {
795 // Resets the previous all apps icon press state
796 mAppsCustomizeContent.resetDrawableState();
797 }
Adam Cohen06dff352012-06-01 17:17:08 -0700798 // It is possible that widgets can receive updates while launcher is not in the foreground.
799 // Consequently, the widgets will be inflated in the orientation of the foreground activity
800 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
801 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700802 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700803
804 // Again, as with the above scenario, it's possible that one or more of the global icons
805 // were updated in the wrong orientation.
806 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200807 if (DEBUG_RESUME_TIME) {
808 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
809 }
Adam Cohen06dff352012-06-01 17:17:08 -0700810 }
811
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800812 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700813 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700814 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
815 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
816 // when Launcher resumes and we are still in AllApps.
817 updateWallpaperVisibility(true);
818
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700819 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700820 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800821 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700822 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700823 }
Romain Guycbb89e42009-06-08 15:52:54 -0700824
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700825 @Override
826 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400827 // Flag the loader to stop early before switching
828 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700829 if (mAppsCustomizeContent != null) {
830 mAppsCustomizeContent.surrender();
831 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800832 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700833 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700834
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800835 // We can't hide the IME if it was forced open. So don't bother
836 /*
837 @Override
838 public void onWindowFocusChanged(boolean hasFocus) {
839 super.onWindowFocusChanged(hasFocus);
840
841 if (hasFocus) {
842 final InputMethodManager inputManager = (InputMethodManager)
843 getSystemService(Context.INPUT_METHOD_SERVICE);
844 WindowManager.LayoutParams lp = getWindow().getAttributes();
845 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
846 android.os.Handler()) {
847 protected void onReceiveResult(int resultCode, Bundle resultData) {
848 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
849 }
850 });
851 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
852 }
853 }
854 */
855
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800856 private boolean acceptFilter() {
857 final InputMethodManager inputManager = (InputMethodManager)
858 getSystemService(Context.INPUT_METHOD_SERVICE);
859 return !inputManager.isFullscreenMode();
860 }
861
862 @Override
863 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700864 final int uniChar = event.getUnicodeChar();
865 final boolean handled = super.onKeyDown(keyCode, event);
866 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
867 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800868 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
869 keyCode, event);
870 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700871 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700872 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700873 // showSearchDialog()
874 // If there are multiple keystrokes before the search dialog takes focus,
875 // onSearchRequested() will be called for every keystroke,
876 // but it is idempotent, so it's fine.
877 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800878 }
879 }
880
Joe Onorato8a9625e2010-01-28 15:55:35 -0800881 // Eat the long press event so the keyboard doesn't come up.
882 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
883 return true;
884 }
885
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800886 return handled;
887 }
888
Karl Rosaen138a0412009-04-23 19:00:21 -0700889 private String getTypedText() {
890 return mDefaultKeySsb.toString();
891 }
892
893 private void clearTypedText() {
894 mDefaultKeySsb.clear();
895 mDefaultKeySsb.clearSpans();
896 Selection.setSelection(mDefaultKeySsb, 0);
897 }
898
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800899 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700900 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
901 * State
902 */
903 private static State intToState(int stateOrdinal) {
904 State state = State.WORKSPACE;
905 final State[] stateValues = State.values();
906 for (int i = 0; i < stateValues.length; i++) {
907 if (stateValues[i].ordinal() == stateOrdinal) {
908 state = stateValues[i];
909 break;
910 }
911 }
912 return state;
913 }
914
915 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800916 * Restores the previous state, if it exists.
917 *
918 * @param savedState The previous state.
919 */
920 private void restoreState(Bundle savedState) {
921 if (savedState == null) {
922 return;
923 }
924
Michael Jurka883f55b2010-10-21 15:47:14 -0700925 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700926 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700927 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -0800928 }
929
Winson Chungf0c6ae02012-03-21 16:10:31 -0700930 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800931 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700932 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800933 }
934
Winson Chung3d503fb2011-07-13 17:25:49 -0700935 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
936 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700937
Winson Chung3d503fb2011-07-13 17:25:49 -0700938 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
939 mPendingAddInfo.container = pendingAddContainer;
940 mPendingAddInfo.screen = pendingAddScreen;
941 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
942 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700943 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
944 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
945 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -0700946 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800947 mRestoring = true;
948 }
949
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700950
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800951 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
952 if (renameFolder) {
953 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700954 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800955 mRestoring = true;
956 }
Winson Chunga12a2502010-12-20 14:41:35 -0800957
Winson Chung785d2eb2011-04-14 16:08:02 -0700958
959 // Restore the AppsCustomize tab
960 if (mAppsCustomizeTabHost != null) {
961 String curTab = savedState.getString("apps_customize_currentTab");
962 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -0700963 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -0700964 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -0700965 mAppsCustomizeContent.loadAssociatedPages(
966 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700967 }
968
Winson Chung5afbf7b2011-07-25 11:53:08 -0700969 int currentIndex = savedState.getInt("apps_customize_currentIndex");
970 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700971 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800972 }
973
974 /**
975 * Finds all the views we need and configure them properly.
976 */
977 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700978 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400979
Craig Mautner360310b2012-10-26 15:13:08 -0700980 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -0700981 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
982 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -0700983 mQsbDivider = findViewById(R.id.qsb_divider);
984 mDockDivider = findViewById(R.id.dock_divider);
985
986 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
987 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800988
Winson Chung4c98d922011-05-31 16:50:48 -0700989 // Setup the drag layer
990 mDragLayer.setup(this, dragController);
991
Winson Chung3d503fb2011-07-13 17:25:49 -0700992 // Setup the hotseat
993 mHotseat = (Hotseat) findViewById(R.id.hotseat);
994 if (mHotseat != null) {
995 mHotseat.setup(this);
996 }
997
Winson Chung4c98d922011-05-31 16:50:48 -0700998 // Setup the workspace
999 mWorkspace.setHapticFeedbackEnabled(false);
1000 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001001 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001002 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001003
Winson Chungf0ea4d32011-06-06 14:27:16 -07001004 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001005 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001006
Winson Chungf0ea4d32011-06-06 14:27:16 -07001007 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001008 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001009 mAppsCustomizeContent = (AppsCustomizePagedView)
1010 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1011 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001012
Winson Chung3d503fb2011-07-13 17:25:49 -07001013 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001014 dragController.setDragScoller(mWorkspace);
1015 dragController.setScrollView(mDragLayer);
1016 dragController.setMoveTarget(mWorkspace);
1017 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001018 if (mSearchDropTargetBar != null) {
1019 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001020 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001021 }
1022
1023 /**
1024 * Creates a view representing a shortcut.
1025 *
1026 * @param info The data structure describing the shortcut.
1027 *
1028 * @return A View inflated from R.layout.application.
1029 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001030 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001031 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001032 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001033 }
1034
1035 /**
1036 * Creates a view representing a shortcut inflated from the specified resource.
1037 *
1038 * @param layoutResId The id of the XML layout used to create the shortcut.
1039 * @param parent The group the shortcut belongs to.
1040 * @param info The data structure describing the shortcut.
1041 *
1042 * @return A View inflated from layoutResId.
1043 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001044 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001045 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1046 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001047 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001048 return favorite;
1049 }
1050
1051 /**
1052 * Add an application shortcut to the workspace.
1053 *
1054 * @param data The intent describing the application.
1055 * @param cellInfo The position on screen where to create the shortcut.
1056 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001057 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001058 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -07001059 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001060
Adam Cohenfbba09b2011-07-18 21:43:05 -07001061 // First we check if we already know the exact location where we want to add this item.
1062 if (cellX >= 0 && cellY >= 0) {
1063 cellXY[0] = cellX;
1064 cellXY[1] = cellY;
1065 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001066 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001067 return;
1068 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001069
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001070 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001071
Romain Guy73b979d2009-06-09 12:57:21 -07001072 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001073 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001074 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001075 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -07001076 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001077 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001078 } else {
1079 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001080 }
1081 }
Romain Guycbb89e42009-06-08 15:52:54 -07001082
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001083 /**
1084 * Add a shortcut to the workspace.
1085 *
1086 * @param data The intent describing the shortcut.
1087 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001088 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001089 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
1090 int cellY) {
1091 int[] cellXY = mTmpAddItemCellCoordinates;
1092 int[] touchXY = mPendingAddInfo.dropPos;
1093 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001094
Michael Jurkad3ef3062010-11-23 16:23:58 -08001095 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001096
Adam Cohen558baaf2011-08-15 15:22:57 -07001097 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001098 if (info == null) {
1099 return;
1100 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001101 final View view = createShortcut(info);
1102
Adam Cohenfbba09b2011-07-18 21:43:05 -07001103 // First we check if we already know the exact location where we want to add this item.
1104 if (cellX >= 0 && cellY >= 0) {
1105 cellXY[0] = cellX;
1106 cellXY[1] = cellY;
1107 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001108
1109 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001110 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001111 true, null,null)) {
1112 return;
1113 }
1114 DragObject dragObject = new DragObject();
1115 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001116 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1117 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001118 return;
1119 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001120 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001121 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001122 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001123 foundCellSpan = (result != null);
1124 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001125 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001126 }
1127
1128 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001129 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001130 return;
1131 }
1132
Adam Cohen558baaf2011-08-15 15:22:57 -07001133 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001134
1135 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001136 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
1137 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001138 }
1139 }
1140
Adam Cohen2f093b62012-04-30 18:59:53 -07001141 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1142 int minHeight) {
1143 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001144 // We want to account for the extra amount of padding that we are adding to the widget
1145 // to ensure that it gets the full amount of space that it has requested
1146 int requiredWidth = minWidth + padding.left + padding.right;
1147 int requiredHeight = minHeight + padding.top + padding.bottom;
Adam Cohen2f093b62012-04-30 18:59:53 -07001148 return CellLayout.rectToCell(context.getResources(), requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001149 }
1150
Adam Cohen2f093b62012-04-30 18:59:53 -07001151 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1152 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001153 }
1154
Adam Cohen2f093b62012-04-30 18:59:53 -07001155 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1156 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001157 }
1158
Adam Cohen2f093b62012-04-30 18:59:53 -07001159 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1160 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001161 }
1162
Adam Cohen2f093b62012-04-30 18:59:53 -07001163 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1164 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001165 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001166 }
1167
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001168 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001169 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001170 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001171 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001172 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001173 */
Adam Cohened66b2b2012-01-23 17:28:51 -08001174 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
1175 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1176 if (appWidgetInfo == null) {
1177 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1178 }
Romain Guycbb89e42009-06-08 15:52:54 -07001179
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001180 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -07001181 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -07001182
Adam Cohen2f093b62012-04-30 18:59:53 -07001183 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1184 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001185
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001186 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001187 // We have saved the position to which the widget was dragged-- this really only matters
1188 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001189 int[] cellXY = mTmpAddItemCellCoordinates;
1190 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001191 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001192 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001193 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1194 cellXY[0] = mPendingAddInfo.cellX;
1195 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001196 spanXY[0] = mPendingAddInfo.spanX;
1197 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001198 foundCellSpan = true;
1199 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001200 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001201 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001202 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1203 spanXY[1], cellXY, finalSpan);
1204 spanXY[0] = finalSpan[0];
1205 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001206 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001207 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001208 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001209 }
1210
Michael Jurka0280c3b2010-09-17 15:00:07 -07001211 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001212 if (appWidgetId != -1) {
1213 // Deleting an app widget ID is a void call but writes to disk before returning
1214 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001215 new Thread("deleteAppWidgetId") {
1216 public void run() {
1217 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1218 }
1219 }.start();
1220 }
Winson Chung93eef082012-03-23 15:59:27 -07001221 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001222 return;
1223 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001224
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001225 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001226 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1227 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001228 launcherInfo.spanX = spanXY[0];
1229 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001230 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1231 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001232
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001233 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001234 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001235
1236 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001237 if (hostView == null) {
1238 // Perform actual inflation because we're live
1239 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1240 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1241 } else {
1242 // The AppWidgetHostView has already been inflated and instantiated
1243 launcherInfo.hostView = hostView;
1244 }
Romain Guycbb89e42009-06-08 15:52:54 -07001245
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001246 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001247 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001248 launcherInfo.notifyWidgetSizeChanged(this);
1249
Winson Chung3d503fb2011-07-13 17:25:49 -07001250 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001251 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001252
1253 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001254 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001255 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001256 }
Romain Guycbb89e42009-06-08 15:52:54 -07001257
Adam Cohended9f8d2010-11-03 13:25:16 -07001258 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1259 @Override
1260 public void onReceive(Context context, Intent intent) {
1261 final String action = intent.getAction();
1262 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1263 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001264 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001265 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001266
Winson Chungc100e8e2011-08-09 16:02:43 -07001267 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001268 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001269 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1270 mAppsCustomizeTabHost.reset();
1271 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001272 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001273 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1274 mUserPresent = true;
1275 updateRunning();
1276 }
1277 }
1278 };
1279
1280 @Override
1281 public void onAttachedToWindow() {
1282 super.onAttachedToWindow();
1283
1284 // Listen for broadcasts related to user-presence
1285 final IntentFilter filter = new IntentFilter();
1286 filter.addAction(Intent.ACTION_SCREEN_OFF);
1287 filter.addAction(Intent.ACTION_USER_PRESENT);
1288 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001289 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001290 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001291 mVisible = true;
1292 }
1293
1294 @Override
1295 public void onDetachedFromWindow() {
1296 super.onDetachedFromWindow();
1297 mVisible = false;
1298
Adam Cohend113e0c2010-11-11 10:48:05 -08001299 if (mAttached) {
1300 unregisterReceiver(mReceiver);
1301 mAttached = false;
1302 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001303 updateRunning();
1304 }
1305
1306 public void onWindowVisibilityChanged(int visibility) {
1307 mVisible = visibility == View.VISIBLE;
1308 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001309 // The following code used to be in onResume, but it turns out onResume is called when
1310 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1311 // is a more appropriate event to handle
1312 if (mVisible) {
1313 mAppsCustomizeTabHost.onWindowVisible();
1314 if (!mWorkspaceLoading) {
1315 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001316 // We want to let Launcher draw itself at least once before we force it to build
1317 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001318 // apps is nice and speedy.
1319 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001320 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001321 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001322 if (mStarted) return;
1323 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001324 // We delay the layer building a bit in order to give
1325 // other message processing a time to run. In particular
1326 // this avoids a delay in hiding the IME if it was
1327 // currently shown, because doing that may involve
1328 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001329 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001330 final ViewTreeObserver.OnDrawListener listener = this;
1331 mWorkspace.post(new Runnable() {
1332 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001333 if (mWorkspace != null &&
1334 mWorkspace.getViewTreeObserver() != null) {
1335 mWorkspace.getViewTreeObserver().
1336 removeOnDrawListener(listener);
1337 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001338 }
1339 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001340 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001341 }
1342 });
1343 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001344 // When Launcher comes back to foreground, a different Activity might be responsible for
1345 // the app market intent, so refresh the icon
1346 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001347 clearTypedText();
1348 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001349 }
1350
1351 private void sendAdvanceMessage(long delay) {
1352 mHandler.removeMessages(ADVANCE_MSG);
1353 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1354 mHandler.sendMessageDelayed(msg, delay);
1355 mAutoAdvanceSentTime = System.currentTimeMillis();
1356 }
1357
1358 private void updateRunning() {
1359 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1360 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1361 mAutoAdvanceRunning = autoAdvanceRunning;
1362 if (autoAdvanceRunning) {
1363 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1364 sendAdvanceMessage(delay);
1365 } else {
1366 if (!mWidgetsToAdvance.isEmpty()) {
1367 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1368 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1369 }
1370 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001371 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001372 }
1373 }
1374 }
1375
1376 private final Handler mHandler = new Handler() {
1377 @Override
1378 public void handleMessage(Message msg) {
1379 if (msg.what == ADVANCE_MSG) {
1380 int i = 0;
1381 for (View key: mWidgetsToAdvance.keySet()) {
1382 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1383 final int delay = mAdvanceStagger * i;
1384 if (v instanceof Advanceable) {
1385 postDelayed(new Runnable() {
1386 public void run() {
1387 ((Advanceable) v).advance();
1388 }
1389 }, delay);
1390 }
1391 i++;
1392 }
1393 sendAdvanceMessage(mAdvanceInterval);
1394 }
1395 }
1396 };
1397
1398 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001399 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001400 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1401 if (v instanceof Advanceable) {
1402 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001403 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001404 updateRunning();
1405 }
1406 }
1407
1408 void removeWidgetToAutoAdvance(View hostView) {
1409 if (mWidgetsToAdvance.containsKey(hostView)) {
1410 mWidgetsToAdvance.remove(hostView);
1411 updateRunning();
1412 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001413 }
1414
Joe Onorato9c1289c2009-08-17 11:03:03 -04001415 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001416 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001417 launcherInfo.hostView = null;
1418 }
1419
Winson Chung93eef082012-03-23 15:59:27 -07001420 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1421 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1422 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001423 }
1424
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001425 public LauncherAppWidgetHost getAppWidgetHost() {
1426 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001427 }
Romain Guycbb89e42009-06-08 15:52:54 -07001428
Winson Chunga9abd0e2010-10-27 17:18:37 -07001429 public LauncherModel getModel() {
1430 return mModel;
1431 }
1432
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001433 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001434 getWindow().closeAllPanels();
1435
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001436 // Whatever we were doing is hereby canceled.
1437 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001438 }
1439
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001440 @Override
1441 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001442 long startTime = 0;
1443 if (DEBUG_RESUME_TIME) {
1444 startTime = System.currentTimeMillis();
1445 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001446 super.onNewIntent(intent);
1447
1448 // Close the menu
1449 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001450 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001451 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001452
Jamie Genniscb222e82012-10-23 15:44:26 -07001453 final boolean alreadyOnHome =
1454 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001455 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001456
Jamie Genniscb222e82012-10-23 15:44:26 -07001457 Runnable processIntent = new Runnable() {
1458 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001459 if (mWorkspace == null) {
1460 // Can be cases where mWorkspace is null, this prevents a NPE
1461 return;
1462 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001463 Folder openFolder = mWorkspace.getOpenFolder();
1464 // In all these cases, only animate if we're already on home
1465 mWorkspace.exitWidgetResizeMode();
1466 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1467 openFolder == null) {
1468 mWorkspace.moveToDefaultScreen(true);
1469 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001470
Jamie Genniscb222e82012-10-23 15:44:26 -07001471 closeFolder();
1472 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001473
Jamie Genniscb222e82012-10-23 15:44:26 -07001474 // If we are already on home, then just animate back to the workspace,
1475 // otherwise, just wait until onResume to set the state back to Workspace
1476 if (alreadyOnHome) {
1477 showWorkspace(true);
1478 } else {
1479 mOnResumeState = State.WORKSPACE;
1480 }
1481
1482 final View v = getWindow().peekDecorView();
1483 if (v != null && v.getWindowToken() != null) {
1484 InputMethodManager imm = (InputMethodManager)getSystemService(
1485 INPUT_METHOD_SERVICE);
1486 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1487 }
1488
1489 // Reset AllApps to its initial state
1490 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
1491 mAppsCustomizeTabHost.reset();
1492 }
1493 }
1494 };
1495
1496 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1497 // Delay processing of the intent to allow the status bar animation to finish
1498 // first in order to avoid janky animations.
1499 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001500 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001501 // Process the intent immediately.
1502 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001503 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001504
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001505 }
Michael Jurka447bf842013-05-15 14:52:15 +02001506 if (DEBUG_RESUME_TIME) {
1507 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1508 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001509 }
1510
1511 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001512 public void onRestoreInstanceState(Bundle state) {
1513 super.onRestoreInstanceState(state);
1514 for (int page: mSynchronouslyBoundPages) {
1515 mWorkspace.restoreInstanceStateForChild(page);
1516 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001517 }
1518
1519 @Override
1520 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001521 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001522 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001523
Michael Jurka883f55b2010-10-21 15:47:14 -07001524 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001525 // We close any open folder since it will not be re-opened, and we need to make sure
1526 // this state is reflected.
1527 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001528
Winson Chung3d503fb2011-07-13 17:25:49 -07001529 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1530 mWaitingForResult) {
1531 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1532 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1533 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1534 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001535 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1536 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1537 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001538 }
1539
1540 if (mFolderInfo != null && mWaitingForResult) {
1541 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1542 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1543 }
Michael Jurka946ad472010-07-09 18:05:18 -07001544
Winson Chung785d2eb2011-04-14 16:08:02 -07001545 // Save the current AppsCustomize tab
1546 if (mAppsCustomizeTabHost != null) {
1547 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1548 if (currentTabTag != null) {
1549 outState.putString("apps_customize_currentTab", currentTabTag);
1550 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001551 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1552 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001553 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001554 }
1555
1556 @Override
1557 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001558 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001559
Winson Chunge7a03942011-08-05 15:05:12 -07001560 // Remove all pending runnables
1561 mHandler.removeMessages(ADVANCE_MSG);
1562 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001563 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001564
Winson Chungcd2b0142011-06-08 16:02:26 -07001565 // Stop callbacks from LauncherModel
1566 LauncherApplication app = ((LauncherApplication) getApplication());
1567 mModel.stopLoader();
1568 app.setLauncher(null);
1569
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001570 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001571 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001572 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001573 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001574 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001575 mAppWidgetHost = null;
1576
1577 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001578
1579 TextKeyListener.getInstance().release();
1580
Winson Chung81b52252012-08-27 15:34:29 -07001581 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1582 // to prevent leaking Launcher activities on orientation change.
1583 if (mModel != null) {
1584 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1585 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001586
1587 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001588 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001589
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001590 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001591 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1592 mWorkspace.removeAllViews();
1593 mWorkspace = null;
1594 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001595
Michael Jurka2ecf9952012-06-18 12:52:28 -07001596 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001597 }
1598
Adam Cohena9cf38f2011-05-02 15:36:58 -07001599 public DragController getDragController() {
1600 return mDragController;
1601 }
1602
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001603 @Override
1604 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001605 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001606 super.startActivityForResult(intent, requestCode);
1607 }
1608
Winson Chung70d72102011-08-12 11:24:35 -07001609 /**
1610 * Indicates that we want global search for this activity by setting the globalSearch
1611 * argument for {@link #startSearch} to true.
1612 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001613 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001614 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001615 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001616
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001617 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001618
Karl Rosaen138a0412009-04-23 19:00:21 -07001619 if (initialQuery == null) {
1620 // Use any text typed in the launcher as the initial query
1621 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001622 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001623 if (appSearchData == null) {
1624 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001625 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001626 }
Winson Chungadf0c182012-08-23 14:59:07 -07001627 Rect sourceBounds = new Rect();
1628 if (mSearchDropTargetBar != null) {
1629 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1630 }
Romain Guycbb89e42009-06-08 15:52:54 -07001631
Michael Jurkaa33411c2012-06-14 16:18:21 -07001632 startGlobalSearch(initialQuery, selectInitialQuery,
1633 appSearchData, sourceBounds);
1634 }
1635
1636 /**
1637 * Starts the global search activity. This code is a copied from SearchManager
1638 */
1639 public void startGlobalSearch(String initialQuery,
1640 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001641 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001642 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1643 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1644 if (globalSearchActivity == null) {
1645 Log.w(TAG, "No global search activity found.");
1646 return;
1647 }
1648 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1649 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1650 intent.setComponent(globalSearchActivity);
1651 // Make sure that we have a Bundle to put source in
1652 if (appSearchData == null) {
1653 appSearchData = new Bundle();
1654 } else {
1655 appSearchData = new Bundle(appSearchData);
1656 }
1657 // Set source to package name of app that starts global search, if not set already.
1658 if (!appSearchData.containsKey("source")) {
1659 appSearchData.putString("source", getPackageName());
1660 }
1661 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1662 if (!TextUtils.isEmpty(initialQuery)) {
1663 intent.putExtra(SearchManager.QUERY, initialQuery);
1664 }
1665 if (selectInitialQuery) {
1666 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1667 }
1668 intent.setSourceBounds(sourceBounds);
1669 try {
1670 startActivity(intent);
1671 } catch (ActivityNotFoundException ex) {
1672 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1673 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001674 }
1675
Winson Chung70d72102011-08-12 11:24:35 -07001676 @Override
1677 public boolean onCreateOptionsMenu(Menu menu) {
1678 if (isWorkspaceLocked()) {
1679 return false;
1680 }
1681
1682 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001683
1684 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1685 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1686 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001687 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1688 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1689 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001690 String helpUrl = getString(R.string.help_url);
1691 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001692 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1693 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1694
Winson Chung70d72102011-08-12 11:24:35 -07001695 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1696 .setIcon(android.R.drawable.ic_menu_gallery)
1697 .setAlphabeticShortcut('W');
1698 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1699 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001700 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001701 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001702 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1703 .setIcon(android.R.drawable.ic_menu_preferences)
1704 .setIntent(settings)
1705 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001706 if (!helpUrl.isEmpty()) {
1707 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1708 .setIcon(android.R.drawable.ic_menu_help)
1709 .setIntent(help)
1710 .setAlphabeticShortcut('H');
1711 }
Winson Chung70d72102011-08-12 11:24:35 -07001712 return true;
1713 }
1714
1715 @Override
1716 public boolean onPrepareOptionsMenu(Menu menu) {
1717 super.onPrepareOptionsMenu(menu);
1718
1719 if (mAppsCustomizeTabHost.isTransitioning()) {
1720 return false;
1721 }
1722 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1723 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1724
1725 return true;
1726 }
1727
1728 @Override
1729 public boolean onOptionsItemSelected(MenuItem item) {
1730 switch (item.getItemId()) {
1731 case MENU_WALLPAPER_SETTINGS:
1732 startWallpaper();
1733 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001734 }
1735
1736 return super.onOptionsItemSelected(item);
1737 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001738
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001739 @Override
1740 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001741 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001742 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001743 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001744 }
1745
Joe Onorato9c1289c2009-08-17 11:03:03 -04001746 public boolean isWorkspaceLocked() {
1747 return mWorkspaceLoading || mWaitingForResult;
1748 }
1749
Michael Jurka0280c3b2010-09-17 15:00:07 -07001750 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001751 mPendingAddInfo.container = ItemInfo.NO_ID;
1752 mPendingAddInfo.screen = -1;
1753 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1754 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001755 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001756 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001757 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001758
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001759 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1760 AppWidgetProviderInfo appWidgetInfo) {
1761 if (appWidgetInfo.configure != null) {
1762 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001763
Bjorn Bringert7984c942009-12-09 15:38:25 +00001764 // Launch over to configure widget, if needed
1765 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001766 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001767 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Romain Guy8e633c52010-03-04 12:51:36 -08001768 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001769 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001770 // Otherwise just add it
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001771 completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget,
1772 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001773 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001774 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001775 }
1776 }
Romain Guycbb89e42009-06-08 15:52:54 -07001777
Adam Cohenfbba09b2011-07-18 21:43:05 -07001778 /**
1779 * Process a shortcut drop.
1780 *
1781 * @param componentName The name of the component
1782 * @param screen The screen where it should be added
1783 * @param cell The cell it should be added to, optional
1784 * @param position The location on the screen where it was dropped, optional
1785 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001786 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1787 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001788 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001789 mPendingAddInfo.container = container;
1790 mPendingAddInfo.screen = screen;
1791 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001792
1793 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001794 mPendingAddInfo.cellX = cell[0];
1795 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001796 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001797
1798 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1799 createShortcutIntent.setComponent(componentName);
1800 processShortcut(createShortcutIntent);
1801 }
1802
Adam Cohenfbba09b2011-07-18 21:43:05 -07001803 /**
1804 * Process a widget drop.
1805 *
1806 * @param info The PendingAppWidgetInfo of the widget being added.
1807 * @param screen The screen where it should be added
1808 * @param cell The cell it should be added to, optional
1809 * @param position The location on the screen where it was dropped, optional
1810 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001811 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
Adam Cohend41fbf52012-02-16 23:53:59 -08001812 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001813 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001814 mPendingAddInfo.container = info.container = container;
1815 mPendingAddInfo.screen = info.screen = screen;
1816 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001817 mPendingAddInfo.minSpanX = info.minSpanX;
1818 mPendingAddInfo.minSpanY = info.minSpanY;
1819
Adam Cohenfbba09b2011-07-18 21:43:05 -07001820 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001821 mPendingAddInfo.cellX = cell[0];
1822 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001823 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001824 if (span != null) {
1825 mPendingAddInfo.spanX = span[0];
1826 mPendingAddInfo.spanY = span[1];
1827 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001828
Adam Cohened66b2b2012-01-23 17:28:51 -08001829 AppWidgetHostView hostView = info.boundWidget;
1830 int appWidgetId;
1831 if (hostView != null) {
1832 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001833 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001834 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001835 // In this case, we either need to start an activity to get permission to bind
1836 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001837 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001838 Bundle options = info.bindOptions;
1839
1840 boolean success = false;
1841 if (options != null) {
1842 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1843 info.componentName, options);
1844 } else {
1845 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1846 info.componentName);
1847 }
1848 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001849 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001850 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001851 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001852 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1853 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1854 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07001855 // TODO: we need to make sure that this accounts for the options bundle.
1856 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07001857 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1858 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001859 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001860 }
1861
Joe Onoratodeb98af2010-02-19 14:59:39 -08001862 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001863 // Handle case where user selected "Applications"
1864 String applicationName = getResources().getString(R.string.group_applications);
1865 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001866
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001867 if (applicationName != null && applicationName.equals(shortcutName)) {
1868 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1869 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001870
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001871 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1872 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001873 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001874 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001875 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001876 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001877 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001878 }
1879
Winson Chung24ab2f12010-09-16 14:10:47 -07001880 void processWallpaper(Intent intent) {
1881 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1882 }
1883
Winson Chung3d503fb2011-07-13 17:25:49 -07001884 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1885 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001886 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001887 folderInfo.title = getText(R.string.folder_name);
1888
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001889 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001890 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1891 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001892 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001893
1894 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001895 FolderIcon newFolder =
1896 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1897 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1898 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001899 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001900 }
Romain Guycbb89e42009-06-08 15:52:54 -07001901
Joe Onorato9c1289c2009-08-17 11:03:03 -04001902 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001903 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001904 }
1905
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001906 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001907 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001908 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001909 Intent chooser = Intent.createChooser(pickWallpaper,
1910 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001911 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1912 // Removed in Eclair MR1
1913// WallpaperManager wm = (WallpaperManager)
1914// getSystemService(Context.WALLPAPER_SERVICE);
1915// WallpaperInfo wi = wm.getWallpaperInfo();
1916// if (wi != null && wi.getSettingsActivity() != null) {
1917// LabeledIntent li = new LabeledIntent(getPackageName(),
1918// R.string.configure_wallpaper, 0);
1919// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1920// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1921// }
Mike Clerona0618e42009-10-22 13:55:21 -07001922 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001923 }
1924
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001925 /**
1926 * Registers various content observers. The current implementation registers
1927 * only a favorites observer to keep track of the favorites applications.
1928 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001929 private void registerContentObservers() {
1930 ContentResolver resolver = getContentResolver();
1931 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1932 true, mWidgetObserver);
1933 }
1934
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001935 @Override
1936 public boolean dispatchKeyEvent(KeyEvent event) {
1937 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1938 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001939 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001940 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001941 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08001942 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08001943 dumpState();
1944 return true;
1945 }
1946 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001947 }
1948 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1949 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001950 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001951 return true;
1952 }
1953 }
1954
1955 return super.dispatchKeyEvent(event);
1956 }
1957
Joe Onorato88ec0992009-11-19 13:16:06 -08001958 @Override
1959 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001960 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001961 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001962 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001963 Folder openFolder = mWorkspace.getOpenFolder();
1964 if (openFolder.isEditingName()) {
1965 openFolder.dismissEditingName();
1966 } else {
1967 closeFolder();
1968 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001969 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001970 mWorkspace.exitWidgetResizeMode();
1971
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001972 // Back button is a no-op here, but give at least some feedback for the button press
1973 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001974 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001975 }
1976
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001977 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001978 * Re-listen when widgets are reset.
1979 */
1980 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001981 if (mAppWidgetHost != null) {
1982 mAppWidgetHost.startListening();
1983 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001984 }
1985
1986 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001987 * Launches the intent referred by the clicked shortcut.
1988 *
1989 * @param v The view representing the clicked shortcut.
1990 */
1991 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001992 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1993 // view has detached (it's possible for this to happen if the view is removed mid touch).
1994 if (v.getWindowToken() == null) {
1995 return;
1996 }
1997
Winson Chung9b0b2fe2012-02-24 13:03:34 -08001998 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001999 return;
2000 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002002 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002003 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002004 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08002005 final Intent intent = ((ShortcutInfo) tag).intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002006
2007 ComponentName widgetComp = new ComponentName(this, WidgetAdder.class);
2008 if (intent.getComponent().getClassName().equals(widgetComp.getClassName())) {
2009 showAllApps(true);
2010 return;
2011 }
Joe Onorato13724ea2009-12-02 21:16:35 -08002012 int[] pos = new int[2];
2013 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002014 intent.setSourceBounds(new Rect(pos[0], pos[1],
2015 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002016
2017 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002018
2019 if (success && v instanceof BubbleTextView) {
2020 mWaitingForResume = (BubbleTextView) v;
2021 mWaitingForResume.setStayPressed(true);
2022 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002023 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002024 if (v instanceof FolderIcon) {
2025 FolderIcon fi = (FolderIcon) v;
2026 handleFolderClick(fi);
2027 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002028 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002029 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002030 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002031 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002032 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002033 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002034 }
2035 }
2036
Michael Jurka0e260592010-06-30 17:07:39 -07002037 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07002038 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002039 // clicking anywhere on the workspace causes the customization drawer to slide down
2040 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07002041 return false;
2042 }
2043
Michael Jurkaaf442092010-06-10 17:01:57 -07002044 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002045 * Event handler for the search button
2046 *
2047 * @param v The view that was clicked.
2048 */
2049 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002050 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2051
Amith Yamasania135ba82011-08-09 17:42:01 -07002052 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002053 }
2054
2055 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002056 * Event handler for the voice button
2057 *
2058 * @param v The view that was clicked.
2059 */
2060 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002061 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002062
Michael Jurkaae65ee32012-04-30 11:45:54 -07002063 try {
2064 final SearchManager searchManager =
2065 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2066 ComponentName activityName = searchManager.getGlobalSearchActivity();
2067 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002068 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002069 if (activityName != null) {
2070 intent.setPackage(activityName.getPackageName());
2071 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002072 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002073 } catch (ActivityNotFoundException e) {
2074 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002075 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002076 startActivitySafely(null, intent, "onClickVoiceButton");
2077 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002078 }
2079
2080 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002081 * Event handler for the "grid" button that appears on the home screen, which
2082 * enters all apps mode.
2083 *
2084 * @param v The view that was clicked.
2085 */
2086 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07002087 showAllApps(true);
2088 }
2089
2090 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002091 // Provide the same haptic feedback that the system offers for virtual keys.
2092 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002093 }
2094
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002095 public void onClickAppMarketButton(View v) {
2096 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002097 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002098 } else {
2099 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002100 }
2101 }
2102
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002103 void startApplicationDetailsActivity(ComponentName componentName) {
2104 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002105 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2106 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002107 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002108 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002109 }
2110
Patrick Dubroy5539af72010-09-07 15:22:01 -07002111 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
2112 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
2113 // System applications cannot be installed. For now, show a toast explaining that.
2114 // We may give them the option of disabling apps this way.
2115 int messageId = R.string.uninstall_system_app_text;
2116 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
2117 } else {
2118 String packageName = appInfo.componentName.getPackageName();
2119 String className = appInfo.componentName.getClassName();
2120 Intent intent = new Intent(
2121 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002122 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2123 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002124 startActivity(intent);
2125 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002126 }
2127
Michael Jurka86a720e2012-05-09 11:23:23 -07002128 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002129 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002130
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002131 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002132 // Only launch using the new animation if the shortcut has not opted out (this is a
2133 // private contract between launcher and may be ignored in the future).
2134 boolean useLaunchAnimation = (v != null) &&
2135 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2136 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002137 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2138 v.getMeasuredWidth(), v.getMeasuredHeight());
2139
2140 startActivity(intent, opts.toBundle());
2141 } else {
2142 startActivity(intent);
2143 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002144 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002145 } catch (SecurityException e) {
2146 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002147 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002148 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002149 "or use the exported attribute for this activity. "
2150 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002151 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002152 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002153 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002154
Michael Jurka86a720e2012-05-09 11:23:23 -07002155 boolean startActivitySafely(View v, Intent intent, Object tag) {
2156 boolean success = false;
2157 try {
2158 success = startActivity(v, intent, tag);
2159 } catch (ActivityNotFoundException e) {
2160 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2161 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2162 }
2163 return success;
2164 }
2165
Romain Guy8e633c52010-03-04 12:51:36 -08002166 void startActivityForResultSafely(Intent intent, int requestCode) {
2167 try {
2168 startActivityForResult(intent, requestCode);
2169 } catch (ActivityNotFoundException e) {
2170 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2171 } catch (SecurityException e) {
2172 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2173 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2174 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2175 "or use the exported attribute for this activity.", e);
2176 }
2177 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002178
Adam Cohena9cf38f2011-05-02 15:36:58 -07002179 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002180 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002181 Folder openFolder = mWorkspace.getFolderForTag(info);
2182
2183 // If the folder info reports that the associated folder is open, then verify that
2184 // it is actually opened. There have been a few instances where this gets out of sync.
2185 if (info.opened && openFolder == null) {
2186 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2187 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
2188 info.opened = false;
2189 }
2190
Adam Cohenfb91f302012-06-11 15:45:18 -07002191 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002192 // Close any open folder
2193 closeFolder();
2194 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002195 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002196 } else {
2197 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002198 int folderScreen;
2199 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002200 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002201 // .. and close it
2202 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002203 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002204 // Close any folder open on the current screen
2205 closeFolder();
2206 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002207 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002208 }
2209 }
2210 }
2211 }
2212
Adam Cohen268c4752012-06-06 17:47:33 -07002213 /**
2214 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2215 * in the DragLayer in the exact absolute location of the original FolderIcon.
2216 */
2217 private void copyFolderIconToImage(FolderIcon fi) {
2218 final int width = fi.getMeasuredWidth();
2219 final int height = fi.getMeasuredHeight();
2220
2221 // Lazy load ImageView, Bitmap and Canvas
2222 if (mFolderIconImageView == null) {
2223 mFolderIconImageView = new ImageView(this);
2224 }
2225 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2226 mFolderIconBitmap.getHeight() != height) {
2227 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2228 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2229 }
2230
2231 DragLayer.LayoutParams lp;
2232 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2233 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2234 } else {
2235 lp = new DragLayer.LayoutParams(width, height);
2236 }
2237
Adam Cohen307fe232012-08-16 17:55:58 -07002238 // The layout from which the folder is being opened may be scaled, adjust the starting
2239 // view size by this scale factor.
2240 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002241 lp.customPosition = true;
2242 lp.x = mRectForFolderAnimation.left;
2243 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002244 lp.width = (int) (scale * width);
2245 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002246
2247 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2248 fi.draw(mFolderIconCanvas);
2249 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002250 if (fi.getFolder() != null) {
2251 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2252 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002253 }
Adam Cohen268c4752012-06-06 17:47:33 -07002254 // Just in case this image view is still in the drag layer from a previous animation,
2255 // we remove it and re-add it.
2256 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2257 mDragLayer.removeView(mFolderIconImageView);
2258 }
2259 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002260 if (fi.getFolder() != null) {
2261 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002262 }
Adam Cohen268c4752012-06-06 17:47:33 -07002263 }
2264
Adam Cohen2801caf2011-05-13 20:57:39 -07002265 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002266 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002267 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2268 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2269 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2270
Adam Cohenc51934b2011-07-26 21:07:43 -07002271 FolderInfo info = (FolderInfo) fi.getTag();
2272 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2273 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002274 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2275 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002276 }
2277
Adam Cohen268c4752012-06-06 17:47:33 -07002278 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2279 copyFolderIconToImage(fi);
2280 fi.setVisibility(View.INVISIBLE);
2281
Michael Jurka2ecf9952012-06-18 12:52:28 -07002282 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002283 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002284 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2285 oa.start();
2286 }
2287
Adam Cohen268c4752012-06-06 17:47:33 -07002288 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002289 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002290 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2291 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2292 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2293
Adam Cohen268c4752012-06-06 17:47:33 -07002294 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002295
Adam Cohen268c4752012-06-06 17:47:33 -07002296 // We remove and re-draw the FolderIcon in-case it has changed
2297 mDragLayer.removeView(mFolderIconImageView);
2298 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002299 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002300 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002301 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002302 oa.addListener(new AnimatorListenerAdapter() {
2303 @Override
2304 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002305 if (cl != null) {
2306 cl.clearFolderLeaveBehind();
2307 // Remove the ImageView copy of the FolderIcon and make the original visible.
2308 mDragLayer.removeView(mFolderIconImageView);
2309 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002310 }
2311 }
2312 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002313 oa.start();
2314 }
2315
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002316 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002317 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002318 * is animated relative to the specified View. If the View is null, no animation
2319 * is played.
2320 *
2321 * @param folderInfo The FolderInfo describing the folder to open.
2322 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002323 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002324 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002325 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002326
Adam Cohena9cf38f2011-05-02 15:36:58 -07002327 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002328
Adam Cohen4554ee12011-08-03 16:13:21 -07002329 // Just verify that the folder hasn't already been added to the DragLayer.
2330 // There was a one-off crash where the folder had a parent already.
2331 if (folder.getParent() == null) {
2332 mDragLayer.addView(folder);
2333 mDragController.addDropTarget((DropTarget) folder);
2334 } else {
2335 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2336 folder.getParent() + ").");
2337 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002338 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002339 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002340
2341 // Notify the accessibility manager that this folder "window" has appeared and occluded
2342 // the workspace items
2343 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2344 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002345 }
2346
2347 public void closeFolder() {
2348 Folder folder = mWorkspace.getOpenFolder();
2349 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002350 if (folder.isEditingName()) {
2351 folder.dismissEditingName();
2352 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002353 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002354
2355 // Dismiss the folder cling
2356 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002357 }
2358 }
2359
2360 void closeFolder(Folder folder) {
2361 folder.getInfo().opened = false;
2362
2363 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2364 if (parent != null) {
2365 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2366 shrinkAndFadeInFolderIcon(fi);
2367 }
2368 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002369
2370 // Notify the accessibility manager that this folder "window" has disappeard and no
2371 // longer occludeds the workspace items
2372 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002373 }
2374
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002375 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002376 if (!isDraggingEnabled()) return false;
2377 if (isWorkspaceLocked()) return false;
2378 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002379
2380 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002381 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002382 }
2383
Michael Jurka0280c3b2010-09-17 15:00:07 -07002384 resetAddInfo();
2385 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002386 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002387 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002388 return true;
2389 }
2390
Winson Chung3d503fb2011-07-13 17:25:49 -07002391 // The hotseat touch handling does not go through Workspace, and we always allow long press
2392 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002393 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002394 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2395 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002396 if (itemUnderLongClick == null) {
2397 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002398 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2399 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002400 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002401 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002402 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002403 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002404 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002405 }
2406 }
2407 }
2408 return true;
2409 }
2410
Winson Chung3d503fb2011-07-13 17:25:49 -07002411 boolean isHotseatLayout(View layout) {
2412 return mHotseat != null && layout != null &&
2413 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2414 }
2415 Hotseat getHotseat() {
2416 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002417 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002418 SearchDropTargetBar getSearchBar() {
2419 return mSearchDropTargetBar;
2420 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002421
Winson Chung3d503fb2011-07-13 17:25:49 -07002422 /**
2423 * Returns the CellLayout of the specified container at the specified screen.
2424 */
2425 CellLayout getCellLayout(long container, int screen) {
2426 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2427 if (mHotseat != null) {
2428 return mHotseat.getLayout();
2429 } else {
2430 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002431 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002432 } else {
2433 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002434 }
2435 }
2436
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002437 Workspace getWorkspace() {
2438 return mWorkspace;
2439 }
2440
Daniel Sandler843e8602010-06-07 14:59:01 -04002441 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
Craig Mautner360310b2012-10-26 15:13:08 -07002442 @Override
Daniel Sandler843e8602010-06-07 14:59:01 -04002443 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002444 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002445 }
2446
Craig Mautner360310b2012-10-26 15:13:08 -07002447 @Override
Andrew Flynn0dca1ec2012-02-29 13:33:22 -08002448 public boolean isAllAppsButtonRank(int rank) {
2449 return mHotseat.isAllAppsButtonRank(rank);
2450 }
2451
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002452 /**
2453 * Helper method for the cameraZoomIn/cameraZoomOut animations
2454 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002455 * @param scaleFactor The scale factor used for the zoom
2456 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002457 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002458 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002459 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002460 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002461
Winson Chung18f41f82012-05-09 13:28:10 -07002462 void disableWallpaperIfInAllApps() {
2463 // Only disable it if we are in all apps
Winson Chungc93e5ae2012-07-23 20:48:26 -07002464 if (isAllAppsVisible()) {
Winson Chung18f41f82012-05-09 13:28:10 -07002465 if (mAppsCustomizeTabHost != null &&
2466 !mAppsCustomizeTabHost.isTransitioning()) {
2467 updateWallpaperVisibility(false);
2468 }
2469 }
2470 }
2471
Craig Mautner360310b2012-10-26 15:13:08 -07002472 private void setWorkspaceBackground(boolean workspace) {
2473 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002474 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002475 }
2476
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002477 void updateWallpaperVisibility(boolean visible) {
2478 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2479 int curflags = getWindow().getAttributes().flags
2480 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2481 if (wpflags != curflags) {
2482 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2483 }
Craig Mautner360310b2012-10-26 15:13:08 -07002484 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002485 }
2486
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002487 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2488 if (v instanceof LauncherTransitionable) {
2489 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2490 }
2491 }
2492
Michael Jurkabed61d22012-02-14 22:51:29 -08002493 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2494 if (v instanceof LauncherTransitionable) {
2495 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2496 }
Winson Chung70442722012-02-10 15:43:22 -08002497
2498 // Update the workspace transition step as well
2499 dispatchOnLauncherTransitionStep(v, 0f);
2500 }
2501
2502 private void dispatchOnLauncherTransitionStep(View v, float t) {
2503 if (v instanceof LauncherTransitionable) {
2504 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2505 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002506 }
2507
2508 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2509 if (v instanceof LauncherTransitionable) {
2510 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2511 }
Winson Chung70442722012-02-10 15:43:22 -08002512
2513 // Update the workspace transition step as well
2514 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002515 }
2516
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002517 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002518 * Things to test when changing the following seven functions.
2519 * - Home from workspace
2520 * - from center screen
2521 * - from other screens
2522 * - Home from all apps
2523 * - from center screen
2524 * - from other screens
2525 * - Back from all apps
2526 * - from center screen
2527 * - from other screens
2528 * - Launch app from workspace and quit
2529 * - with back
2530 * - with home
2531 * - Launch app from all apps and quit
2532 * - with back
2533 * - with home
2534 * - Go to a screen that's not the default, then all
2535 * apps, and launch and app, and go back
2536 * - with back
2537 * -with home
2538 * - On workspace, long press power and go back
2539 * - with back
2540 * - with home
2541 * - On all apps, long press power and go back
2542 * - with back
2543 * - with home
2544 * - On workspace, power off
2545 * - On all apps, power off
2546 * - Launch an app and turn off the screen while in that app
2547 * - Go back with home key
2548 * - Go back with back key TODO: make this not go to workspace
2549 * - From all apps
2550 * - From workspace
2551 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2552 * - From all apps
2553 * - From the center workspace
2554 * - From another workspace
2555 */
2556
2557 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002558 * Zoom the camera out from the workspace to reveal 'toView'.
2559 * Assumes that the view to show is anchored at either the very top or very bottom
2560 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002561 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002562 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002563 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002564 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002565 mStateAnimation.cancel();
2566 mStateAnimation = null;
2567 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002568 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002569
Winson Chungf0ea4d32011-06-06 14:27:16 -07002570 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2571 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2572 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002573 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002574 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002575 final int startDelay =
2576 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002577
Michael Jurkab3e22d92011-10-31 15:58:33 -07002578 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002579
Michael Jurkad74c9842011-07-10 12:44:21 -07002580 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002581 Animator workspaceAnim =
2582 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002583
2584 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002585 toView.setScaleX(scale);
2586 toView.setScaleY(scale);
2587 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2588 scaleAnim.
2589 scaleX(1f).scaleY(1f).
2590 setDuration(duration).
2591 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002592
Winson Chungf0ea4d32011-06-06 14:27:16 -07002593 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002594 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002595 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002596 .ofFloat(toView, "alpha", 0f, 1f)
2597 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002598 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002599 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2600 @Override
2601 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002602 if (animation == null) {
2603 throw new RuntimeException("animation is null");
2604 }
Winson Chung70442722012-02-10 15:43:22 -08002605 float t = (Float) animation.getAnimatedValue();
2606 dispatchOnLauncherTransitionStep(fromView, t);
2607 dispatchOnLauncherTransitionStep(toView, t);
2608 }
2609 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002610
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002611 // toView should appear right at the end of the workspace shrink
2612 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002613 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002614 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002615 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002616
2617 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002618 boolean animationCancelled = false;
2619
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002620 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002621 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002622 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002623 // Prepare the position
2624 toView.setTranslationX(0.0f);
2625 toView.setTranslationY(0.0f);
2626 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002627 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002628 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002629 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002630 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002631 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2632 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002633
Michael Jurkafa7969f2012-09-21 16:39:14 -07002634 if (mWorkspace != null && !springLoaded && !LauncherApplication.isScreenLarge()) {
Winson Chung32174c82011-07-19 15:47:55 -07002635 // Hide the workspace scrollbar
2636 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002637 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002638 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002639 if (!animationCancelled) {
2640 updateWallpaperVisibility(false);
2641 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002642
2643 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002644 if (mSearchDropTargetBar != null) {
2645 mSearchDropTargetBar.hideSearchBar(false);
2646 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002647 }
2648
Adam Cohencff6af82011-09-13 14:51:53 -07002649 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002650 public void onAnimationCancel(Animator animation) {
2651 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002652 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002653 });
2654
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002655 if (workspaceAnim != null) {
2656 mStateAnimation.play(workspaceAnim);
2657 }
Michael Jurka1899a362011-11-03 13:50:45 -07002658
2659 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002660
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002661 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2662 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002663
2664 // If any of the objects being animated haven't been measured/laid out
2665 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002666 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002667 (mWorkspace.getMeasuredWidth() == 0) ||
2668 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002669 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002670 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002671
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002672 final AnimatorSet stateAnimation = mStateAnimation;
2673 final Runnable startAnimRunnable = new Runnable() {
2674 public void run() {
2675 // Check that mStateAnimation hasn't changed while
2676 // we waited for a layout/draw pass
2677 if (mStateAnimation != stateAnimation)
2678 return;
2679 setPivotsForZoom(toView, scale);
2680 dispatchOnLauncherTransitionStart(fromView, animated, false);
2681 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002682 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002683 }
2684 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002685 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002686 final ViewTreeObserver observer = toView.getViewTreeObserver();
2687 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2688 public void onGlobalLayout() {
2689 startAnimRunnable.run();
2690 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2691 }
2692 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002693 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002694 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002695 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002696 } else {
2697 toView.setTranslationX(0.0f);
2698 toView.setTranslationY(0.0f);
2699 toView.setScaleX(1.0f);
2700 toView.setScaleY(1.0f);
2701 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002702 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002703
Michael Jurkabed61d22012-02-14 22:51:29 -08002704 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2705 // Hide the workspace scrollbar
2706 mWorkspace.hideScrollingIndicator(true);
2707 hideDockDivider();
Winson Chungc7d2b602012-05-16 17:02:20 -07002708
2709 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002710 if (mSearchDropTargetBar != null) {
2711 mSearchDropTargetBar.hideSearchBar(false);
2712 }
Michael Jurkaabded662011-03-04 12:06:57 -08002713 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002714 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002715 dispatchOnLauncherTransitionStart(fromView, animated, false);
2716 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002717 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002718 dispatchOnLauncherTransitionStart(toView, animated, false);
2719 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002720 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002721 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002722 }
2723
2724 /**
2725 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002726 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002727 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002728 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002729 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2730 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002731
Michael Jurkab3e22d92011-10-31 15:58:33 -07002732 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002733 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002734 mStateAnimation.cancel();
2735 mStateAnimation = null;
2736 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002737 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002738
Winson Chungf0ea4d32011-06-06 14:27:16 -07002739 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002740 final int fadeOutDuration =
2741 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002742 final float scaleFactor = (float)
2743 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2744 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002745 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002746 Animator workspaceAnim = null;
2747
2748 if (toState == State.WORKSPACE) {
2749 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2750 workspaceAnim = mWorkspace.getChangeStateAnimation(
2751 Workspace.State.NORMAL, animated, stagger);
2752 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2753 workspaceAnim = mWorkspace.getChangeStateAnimation(
2754 Workspace.State.SPRING_LOADED, animated);
2755 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002756
Michael Jurkab3e22d92011-10-31 15:58:33 -07002757 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002758 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002759 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002760 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002761 final LauncherViewPropertyAnimator scaleAnim =
2762 new LauncherViewPropertyAnimator(fromView);
2763 scaleAnim.
2764 scaleX(scaleFactor).scaleY(scaleFactor).
2765 setDuration(duration).
2766 setInterpolator(new Workspace.ZoomInInterpolator());
2767
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002768 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002769 .ofFloat(fromView, "alpha", 1f, 0f)
2770 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002771 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002772 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2773 @Override
2774 public void onAnimationUpdate(ValueAnimator animation) {
2775 float t = 1f - (Float) animation.getAnimatedValue();
2776 dispatchOnLauncherTransitionStep(fromView, t);
2777 dispatchOnLauncherTransitionStep(toView, t);
2778 }
2779 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002780
Michael Jurka2ecf9952012-06-18 12:52:28 -07002781 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002782
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002783 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2784 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002785 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002786
2787 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002788 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002789 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002790 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002791 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002792 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2793 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkabafdaaf2012-04-26 13:43:25 -07002794 if (mWorkspace != null) {
2795 mWorkspace.hideScrollingIndicator(false);
2796 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002797 if (onCompleteRunnable != null) {
2798 onCompleteRunnable.run();
2799 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002800 mAppsCustomizeContent.updateCurrentPageScroll();
2801 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002802 }
2803 });
2804
Winson Chungf0ea4d32011-06-06 14:27:16 -07002805 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002806 if (workspaceAnim != null) {
2807 mStateAnimation.play(workspaceAnim);
2808 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002809 dispatchOnLauncherTransitionStart(fromView, animated, true);
2810 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002811 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002812 } else {
2813 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002814 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002815 dispatchOnLauncherTransitionStart(fromView, animated, true);
2816 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002817 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002818 dispatchOnLauncherTransitionStart(toView, animated, true);
2819 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002820 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002821 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002822 }
2823
Michael Jurkae326f182011-11-21 14:05:46 -08002824 @Override
2825 public void onTrimMemory(int level) {
2826 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002827 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002828 mAppsCustomizeTabHost.onTrimMemory();
2829 }
2830 }
2831
Winson Chung18f41f82012-05-09 13:28:10 -07002832 @Override
2833 public void onWindowFocusChanged(boolean hasFocus) {
2834 if (!hasFocus) {
2835 // When another window occludes launcher (like the notification shade, or recents),
2836 // ensure that we enable the wallpaper flag so that transitions are done correctly.
2837 updateWallpaperVisibility(true);
2838 } else {
2839 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07002840 mWorkspace.postDelayed(new Runnable() {
2841 @Override
2842 public void run() {
2843 disableWallpaperIfInAllApps();
2844 }
2845 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07002846 }
2847 }
2848
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002849 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002850 showWorkspace(animated, null);
2851 }
2852
2853 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002854 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002855 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002856 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002857 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002858
Winson Chungc7d2b602012-05-16 17:02:20 -07002859 // Show the search bar (only animate if we were showing the drop target bar in spring
2860 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07002861 if (mSearchDropTargetBar != null) {
2862 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
2863 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002864
Michael Jurkab737ee62011-11-15 15:57:22 -08002865 // We only need to animate in the dock divider if we're going from spring loaded mode
Winson Chungc7d2b602012-05-16 17:02:20 -07002866 showDockDivider(animated && wasInSpringLoadedMode);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002867
2868 // Set focus to the AppsCustomize button
2869 if (mAllAppsButton != null) {
2870 mAllAppsButton.requestFocus();
2871 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002872 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002873
Michael Jurkab737ee62011-11-15 15:57:22 -08002874 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002875
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002876 // Change the state *after* we've called all the transition code
2877 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002878
Winson Chung5fb63472011-02-02 17:03:37 -08002879 // Resume the auto-advance of widgets
2880 mUserPresent = true;
2881 updateRunning();
2882
alanv1d4fde62012-10-17 13:15:47 -07002883 // Send an accessibility event to announce the context change
2884 getWindow().getDecorView()
2885 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Joe Onorato00acb122009-08-04 16:04:30 -04002886 }
2887
Michael Jurkab3e22d92011-10-31 15:58:33 -07002888 void showAllApps(boolean animated) {
2889 if (mState != State.WORKSPACE) return;
2890
2891 showAppsCustomizeHelper(animated, false);
2892 mAppsCustomizeTabHost.requestFocus();
2893
Michael Jurkab3e22d92011-10-31 15:58:33 -07002894 // Change the state *after* we've called all the transition code
2895 mState = State.APPS_CUSTOMIZE;
2896
2897 // Pause the auto-advance of widgets until we are out of AllApps
2898 mUserPresent = false;
2899 updateRunning();
2900 closeFolder();
2901
2902 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07002903 getWindow().getDecorView()
2904 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002905 }
2906
Adam Cohen7777d962011-08-18 18:58:38 -07002907 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002908 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002909 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002910 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002911 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002912 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002913 }
Adam Cohen7777d962011-08-18 18:58:38 -07002914
Adam Cohened66b2b2012-01-23 17:28:51 -08002915 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2916 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002917 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2918
Winson Chunge7a03942011-08-05 15:05:12 -07002919 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002920 @Override
2921 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002922 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002923 // Before we show workspace, hide all apps again because
2924 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2925 // clean up our state transition functions
2926 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002927 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002928 } else {
2929 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002930 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002931 }
2932 }, (extendedDelay ?
2933 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2934 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2935 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002936
Michael Jurkad3ef3062010-11-23 16:23:58 -08002937 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002938 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002939 final boolean animated = true;
2940 final boolean springLoaded = true;
2941 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002942 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002943 }
2944 // Otherwise, we are not in spring loaded mode, so don't do anything.
2945 }
2946
Michael Jurkab737ee62011-11-15 15:57:22 -08002947 void hideDockDivider() {
2948 if (mQsbDivider != null && mDockDivider != null) {
2949 mQsbDivider.setVisibility(View.INVISIBLE);
2950 mDockDivider.setVisibility(View.INVISIBLE);
2951 }
2952 }
2953
2954 void showDockDivider(boolean animated) {
2955 if (mQsbDivider != null && mDockDivider != null) {
2956 mQsbDivider.setVisibility(View.VISIBLE);
2957 mDockDivider.setVisibility(View.VISIBLE);
2958 if (mDividerAnimator != null) {
2959 mDividerAnimator.cancel();
2960 mQsbDivider.setAlpha(1f);
2961 mDockDivider.setAlpha(1f);
2962 mDividerAnimator = null;
2963 }
2964 if (animated) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07002965 mDividerAnimator = LauncherAnimUtils.createAnimatorSet();
2966 mDividerAnimator.playTogether(LauncherAnimUtils.ofFloat(mQsbDivider, "alpha", 1f),
2967 LauncherAnimUtils.ofFloat(mDockDivider, "alpha", 1f));
Winson Chungadf0c182012-08-23 14:59:07 -07002968 int duration = 0;
2969 if (mSearchDropTargetBar != null) {
2970 duration = mSearchDropTargetBar.getTransitionInDuration();
2971 }
2972 mDividerAnimator.setDuration(duration);
Michael Jurkab737ee62011-11-15 15:57:22 -08002973 mDividerAnimator.start();
2974 }
2975 }
2976 }
2977
Michael Jurkab3e22d92011-10-31 15:58:33 -07002978 void lockAllApps() {
2979 // TODO
2980 }
2981
2982 void unlockAllApps() {
2983 // TODO
2984 }
2985
Winson Chungf0ea4d32011-06-06 14:27:16 -07002986 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002987 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002988 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002989 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002990 if (!LauncherApplication.isScreenLarge()) {
2991 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002992 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07002993 int duration = 0;
2994 if (mSearchDropTargetBar != null) {
2995 duration = mSearchDropTargetBar.getTransitionInDuration();
2996 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08002997 mHotseat.animate().alpha(1f).setDuration(duration);
2998 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002999 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003000 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003001 }
3002 }
3003 }
3004
3005 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003006 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003007 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003008 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003009 if (!LauncherApplication.isScreenLarge()) {
3010 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003011 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003012 int duration = 0;
3013 if (mSearchDropTargetBar != null) {
3014 duration = mSearchDropTargetBar.getTransitionOutDuration();
3015 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003016 mHotseat.animate().alpha(0f).setDuration(duration);
3017 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003018 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003019 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003020 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003021 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003022 }
3023
Patrick Dubroy5f445422011-02-18 14:35:21 -08003024 /**
3025 * Add an item from all apps or customize onto the given workspace screen.
3026 * If layout is null, add to the current screen.
3027 */
3028 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003029 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003030 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003031 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003032 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003033
Winson Chungdff8ebb2011-09-08 17:25:31 -07003034 /** Maps the current orientation to an index for referencing orientation correct global icons */
3035 private int getCurrentOrientationIndexForGlobalIcons() {
3036 // default - 0, landscape - 1
3037 switch (getResources().getConfiguration().orientation) {
3038 case Configuration.ORIENTATION_LANDSCAPE:
3039 return 1;
3040 default:
3041 return 0;
3042 }
3043 }
3044
Michael Jurkaae65ee32012-04-30 11:45:54 -07003045 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003046 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003047 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003048 // Look for the toolbar icon specified in the activity meta-data
3049 Bundle metaData = packageManager.getActivityInfo(
3050 activityName, PackageManager.GET_META_DATA).metaData;
3051 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003052 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003053 if (iconResId != 0) {
3054 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003055 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003056 }
3057 }
3058 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003059 // This can happen if the activity defines an invalid drawable
3060 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3061 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003062 } catch (Resources.NotFoundException nfe) {
3063 // This can happen if the activity defines an invalid drawable
3064 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3065 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003066 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003067 return null;
3068 }
3069
3070 // if successful in getting icon, return it; otherwise, set button to use default drawable
3071 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003072 int buttonId, ComponentName activityName, int fallbackDrawableId,
3073 String toolbarResourceName) {
3074 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003075 Resources r = getResources();
3076 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3077 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003078
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003079 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003080 // If we were unable to find the icon via the meta-data, use a generic one
3081 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003082 toolbarIcon = r.getDrawable(fallbackDrawableId);
3083 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003084 if (button != null) {
3085 button.setCompoundDrawables(toolbarIcon, null, null, null);
3086 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003087 return null;
3088 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003089 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003090 if (button != null) {
3091 button.setCompoundDrawables(toolbarIcon, null, null, null);
3092 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003093 return toolbarIcon.getConstantState();
3094 }
3095 }
3096
3097 // if successful in getting icon, return it; otherwise, set button to use default drawable
3098 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003099 int buttonId, ComponentName activityName, int fallbackDrawableId,
3100 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003101 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003102 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003103
Michael Jurka19e0fc52011-07-22 18:00:21 -07003104 if (button != null) {
3105 // If we were unable to find the icon via the meta-data, use a
3106 // generic one
3107 if (toolbarIcon == null) {
3108 button.setImageResource(fallbackDrawableId);
3109 } else {
3110 button.setImageDrawable(toolbarIcon);
3111 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003112 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003113
3114 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3115
Michael Jurka0423dcf2010-10-05 14:56:18 -07003116 }
3117
Winson Chung1b884092012-06-08 17:13:02 -07003118 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003119 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003120 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003121 }
3122
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003123 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003124 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003125 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003126 }
3127
Winson Chungbb185bd2011-11-21 12:31:42 -08003128 private void invalidatePressedFocusedStates(View container, View button) {
3129 if (container instanceof HolographicLinearLayout) {
3130 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3131 layout.invalidatePressedFocusedStates();
3132 } else if (button instanceof HolographicImageView) {
3133 HolographicImageView view = (HolographicImageView) button;
3134 view.invalidatePressedFocusedStates();
3135 }
3136 }
3137
Winson Chungc51db6a2011-10-05 11:44:49 -07003138 private boolean updateGlobalSearchIcon() {
3139 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003140 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003141 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003142 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07003143 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07003144
Winson Chung1cad91e2011-05-25 17:41:01 -07003145 final SearchManager searchManager =
3146 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3147 ComponentName activityName = searchManager.getGlobalSearchActivity();
3148 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003149 int coi = getCurrentOrientationIndexForGlobalIcons();
3150 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003151 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3152 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3153 if (sGlobalSearchIcon[coi] == null) {
3154 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3155 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3156 TOOLBAR_ICON_METADATA_NAME);
3157 }
3158
Winson Chungc51db6a2011-10-05 11:44:49 -07003159 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3160 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003161 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003162 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003163 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003164 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003165 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3166 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
3167 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003168 voiceButton.setVisibility(View.GONE);
Michael Jurkac60498a2012-05-07 15:29:42 -07003169 if (voiceButtonProxy != null) {
3170 voiceButtonProxy.setVisibility(View.GONE);
3171 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003172 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003173 }
3174 }
3175
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003176 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003177 final View searchButtonContainer = findViewById(R.id.search_button_container);
3178 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003179 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003180 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003181 }
3182
Winson Chungc51db6a2011-10-05 11:44:49 -07003183 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003184 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003185 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07003186 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07003187
Winson Chungc51db6a2011-10-05 11:44:49 -07003188 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003189 final SearchManager searchManager =
3190 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3191 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3192
3193 ComponentName activityName = null;
3194 if (globalSearchActivity != null) {
3195 // Check if the global search activity handles voice search
3196 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3197 intent.setPackage(globalSearchActivity.getPackageName());
3198 activityName = intent.resolveActivity(getPackageManager());
3199 }
3200
3201 if (activityName == null) {
3202 // Fallback: check if an activity other than the global search activity
3203 // resolves this
3204 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3205 activityName = intent.resolveActivity(getPackageManager());
3206 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003207 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003208 int coi = getCurrentOrientationIndexForGlobalIcons();
3209 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003210 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3211 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3212 if (sVoiceSearchIcon[coi] == null) {
3213 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3214 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3215 TOOLBAR_ICON_METADATA_NAME);
3216 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003217 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003218 voiceButton.setVisibility(View.VISIBLE);
Jim Miller14091b12012-04-24 19:27:54 -07003219 if (voiceButtonProxy != null) {
3220 voiceButtonProxy.setVisibility(View.VISIBLE);
3221 }
Winson Chungbb185bd2011-11-21 12:31:42 -08003222 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003223 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003224 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003225 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003226 voiceButton.setVisibility(View.GONE);
Jim Miller14091b12012-04-24 19:27:54 -07003227 if (voiceButtonProxy != null) {
3228 voiceButtonProxy.setVisibility(View.GONE);
3229 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003230 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003231 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003232 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003233
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003234 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003235 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3236 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003237 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003238 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003239 }
3240
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003241 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003242 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003243 */
3244 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003245 final View marketButton = findViewById(R.id.market_button);
3246 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3247 // Find the app market activity by resolving an intent.
3248 // (If multiple app markets are installed, it will return the ResolverActivity.)
3249 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003250 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003251 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003252 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003253 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003254 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3255 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003256 marketButton.setVisibility(View.VISIBLE);
3257 } else {
3258 // We should hide and disable the view so that we don't try and restore the visibility
3259 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3260 marketButton.setVisibility(View.GONE);
3261 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003262 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003263 }
3264
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003265 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003266 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3267 Resources r = getResources();
3268 Drawable marketIconDrawable = d.newDrawable(r);
3269 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3270 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3271 marketIconDrawable.setBounds(0, 0, w, h);
3272
3273 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003274 }
3275
Michael Jurkad7c28052012-04-27 15:43:36 -07003276 @Override
3277 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003278 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003279 final List<CharSequence> text = event.getText();
3280 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003281 // Populate event with a fake title based on the current state.
3282 if (mState == State.APPS_CUSTOMIZE) {
3283 text.add(getString(R.string.all_apps_button_label));
3284 } else {
3285 text.add(getString(R.string.all_apps_home_button_label));
3286 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003287 return result;
3288 }
3289
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003290 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003291 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003292 */
3293 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3294 @Override
3295 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003296 closeSystemDialogs();
3297 }
3298 }
3299
3300 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003301 * Receives notifications whenever the appwidgets are reset.
3302 */
3303 private class AppWidgetResetObserver extends ContentObserver {
3304 public AppWidgetResetObserver() {
3305 super(new Handler());
3306 }
3307
3308 @Override
3309 public void onChange(boolean selfChange) {
3310 onAppWidgetReset();
3311 }
3312 }
3313
3314 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003315 * If the activity is currently paused, signal that we need to run the passed Runnable
3316 * in onResume.
3317 *
3318 * This needs to be called from incoming places where resources might have been loaded
3319 * while we are paused. That is becaues the Configuration might be wrong
3320 * when we're not running, and if it comes back to what it was when we
3321 * were paused, we are not restarted.
3322 *
3323 * Implementation of the method from LauncherModel.Callbacks.
3324 *
3325 * @return true if we are currently paused. The caller might be able to
3326 * skip some work in that case since we will come back again.
3327 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003328 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003329 if (mPaused) {
3330 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003331 if (deletePreviousRunnables) {
3332 while (mOnResumeCallbacks.remove(run)) {
3333 }
3334 }
Michael Jurka7607c2f2013-04-03 14:33:19 -07003335 mOnResumeCallbacks.add(run);
3336 return true;
3337 } else {
3338 return false;
3339 }
3340 }
3341
Michael Jurkac402cd92013-05-20 15:49:32 +02003342 private boolean waitUntilResume(Runnable run) {
3343 return waitUntilResume(run, false);
3344 }
3345
Michael Jurka7607c2f2013-04-03 14:33:19 -07003346 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003347 * If the activity is currently paused, signal that we need to re-run the loader
3348 * in onResume.
3349 *
3350 * This needs to be called from incoming places where resources might have been loaded
3351 * while we are paused. That is becaues the Configuration might be wrong
3352 * when we're not running, and if it comes back to what it was when we
3353 * were paused, we are not restarted.
3354 *
3355 * Implementation of the method from LauncherModel.Callbacks.
3356 *
3357 * @return true if we are currently paused. The caller might be able to
3358 * skip some work in that case since we will come back again.
3359 */
3360 public boolean setLoadOnResume() {
3361 if (mPaused) {
3362 Log.i(TAG, "setLoadOnResume");
3363 mOnResumeNeedsLoad = true;
3364 return true;
3365 } else {
3366 return false;
3367 }
3368 }
3369
3370 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003371 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003372 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003373 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003374 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003375 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003376 } else {
3377 return SCREEN_COUNT / 2;
3378 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003379 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003380
Joe Onorato9c1289c2009-08-17 11:03:03 -04003381 /**
3382 * Refreshes the shortcuts shown on the workspace.
3383 *
3384 * Implementation of the method from LauncherModel.Callbacks.
3385 */
3386 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003387 // If we're starting binding all over again, clear any bind calls we'd postponed in
3388 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3389 // from scratch again
3390 mOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003391
Michael Jurka7607c2f2013-04-03 14:33:19 -07003392 final Workspace workspace = mWorkspace;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003393 mNewShortcutAnimatePage = -1;
3394 mNewShortcutAnimateViews.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003395 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003396 int count = workspace.getChildCount();
3397 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003398 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003399 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3400 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003401 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08003402 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003403 if (mHotseat != null) {
3404 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003405 }
3406 }
3407
3408 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003409 * Bind the items start-end from the list.
3410 *
3411 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003412 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003413 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end) {
3414 if (waitUntilResume(new Runnable() {
3415 public void run() {
3416 bindItems(shortcuts, start, end);
3417 }
3418 })) {
3419 return;
3420 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003421
Winson Chungf0c6ae02012-03-21 16:10:31 -07003422 // Get the list of added shortcuts and intersect them with the set of shortcuts here
3423 Set<String> newApps = new HashSet<String>();
3424 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);
3425
3426 Workspace workspace = mWorkspace;
3427 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003428 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003429
3430 // Short circuit if we are loading dock items for a configuration which has no dock
3431 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3432 mHotseat == null) {
3433 continue;
3434 }
3435
Joe Onorato9c1289c2009-08-17 11:03:03 -04003436 switch (item.itemType) {
3437 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3438 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003439 ShortcutInfo info = (ShortcutInfo) item;
3440 String uri = info.intent.toUri(0).toString();
3441 View shortcut = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -07003442 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3443 item.cellY, 1, 1, false);
Winson Chungbfeac062012-06-06 15:56:08 -07003444 boolean animateIconUp = false;
3445 synchronized (newApps) {
3446 if (newApps.contains(uri)) {
3447 animateIconUp = newApps.remove(uri);
3448 }
3449 }
3450 if (animateIconUp) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003451 // Prepare the view to be animated up
3452 shortcut.setAlpha(0f);
3453 shortcut.setScaleX(0f);
3454 shortcut.setScaleY(0f);
3455 mNewShortcutAnimatePage = item.screen;
3456 if (!mNewShortcutAnimateViews.contains(shortcut)) {
3457 mNewShortcutAnimateViews.add(shortcut);
3458 }
3459 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003460 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003461 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003462 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003463 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003464 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003465 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3466 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003467 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003468 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003469 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003470
Joe Onorato9c1289c2009-08-17 11:03:03 -04003471 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003472 }
3473
Joe Onorato9c1289c2009-08-17 11:03:03 -04003474 /**
3475 * Implementation of the method from LauncherModel.Callbacks.
3476 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003477 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
3478 if (waitUntilResume(new Runnable() {
3479 public void run() {
3480 bindFolders(folders);
3481 }
3482 })) {
3483 return;
3484 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003485 sFolders.clear();
3486 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003487 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003488
3489 /**
3490 * Add the views for a widget to the workspace.
3491 *
3492 * Implementation of the method from LauncherModel.Callbacks.
3493 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003494 public void bindAppWidget(final LauncherAppWidgetInfo item) {
3495 if (waitUntilResume(new Runnable() {
3496 public void run() {
3497 bindAppWidget(item);
3498 }
3499 })) {
3500 return;
3501 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003502
Daniel Sandler843e8602010-06-07 14:59:01 -04003503 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3504 if (DEBUG_WIDGETS) {
3505 Log.d(TAG, "bindAppWidget: " + item);
3506 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003507 final Workspace workspace = mWorkspace;
3508
3509 final int appWidgetId = item.appWidgetId;
3510 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003511 if (DEBUG_WIDGETS) {
3512 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3513 }
3514
Joe Onorato9c1289c2009-08-17 11:03:03 -04003515 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3516
Joe Onorato9c1289c2009-08-17 11:03:03 -04003517 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003518 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003519
Winson Chung3d503fb2011-07-13 17:25:49 -07003520 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003521 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003522 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3523
Joe Onorato9c1289c2009-08-17 11:03:03 -04003524 workspace.requestLayout();
3525
Daniel Sandler843e8602010-06-07 14:59:01 -04003526 if (DEBUG_WIDGETS) {
3527 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3528 + (SystemClock.uptimeMillis()-start) + "ms");
3529 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003530 }
3531
Adam Cohen1462de32012-07-24 22:34:36 -07003532 public void onPageBoundSynchronously(int page) {
3533 mSynchronouslyBoundPages.add(page);
3534 }
3535
Joe Onorato9c1289c2009-08-17 11:03:03 -04003536 /**
3537 * Callback saying that there aren't any more items to bind.
3538 *
3539 * Implementation of the method from LauncherModel.Callbacks.
3540 */
Adam Cohene25af792013-06-06 23:08:25 -07003541 public void finishBindingItems(final boolean upgradePath) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003542 if (waitUntilResume(new Runnable() {
3543 public void run() {
Adam Cohene25af792013-06-06 23:08:25 -07003544 finishBindingItems(upgradePath);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003545 }
3546 })) {
3547 return;
3548 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003549 if (mSavedState != null) {
3550 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003551 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003552 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003553 mSavedState = null;
3554 }
3555
Adam Cohen1462de32012-07-24 22:34:36 -07003556 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003557
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003558 // If we received the result of any pending adds while the loader was running (e.g. the
3559 // widget configuration forced an orientation change), process them now.
3560 for (int i = 0; i < sPendingAddList.size(); i++) {
3561 completeAdd(sPendingAddList.get(i));
3562 }
3563 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003564
Winson Chungc51db6a2011-10-05 11:44:49 -07003565 // Update the market app icon as necessary (the other icons will be managed in response to
3566 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003567 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003568
Winson Chungf0c6ae02012-03-21 16:10:31 -07003569 // Animate up any icons as necessary
3570 if (mVisible || mWorkspaceLoading) {
3571 Runnable newAppsRunnable = new Runnable() {
3572 @Override
3573 public void run() {
Winson Chunga2413752012-04-03 14:22:34 -07003574 runNewAppsAnimation(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003575 }
3576 };
Winson Chunga2413752012-04-03 14:22:34 -07003577
3578 boolean willSnapPage = mNewShortcutAnimatePage > -1 &&
3579 mNewShortcutAnimatePage != mWorkspace.getCurrentPage();
3580 if (canRunNewAppsAnimation()) {
3581 // If the user has not interacted recently, then either snap to the new page to show
3582 // the new-apps animation or just run them if they are to appear on the current page
3583 if (willSnapPage) {
3584 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable);
3585 } else {
3586 runNewAppsAnimation(false);
3587 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003588 } else {
Winson Chung318eee02012-04-12 10:59:27 -07003589 // If the user has interacted recently, then just add the items in place if they
Winson Chunga2413752012-04-03 14:22:34 -07003590 // are on another page (or just normally if they are added to the current page)
3591 runNewAppsAnimation(willSnapPage);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003592 }
3593 }
3594
3595 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003596 if (upgradePath) {
3597 mWorkspace.saveWorkspaceToDb();
3598
3599 // Run through this twice... a little hackleberry, but the right solution is complex.
3600 mWorkspace.stripDuplicateApps();
3601 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.stripDuplicateApps();
3602 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003603 }
3604
Winson Chunga2413752012-04-03 14:22:34 -07003605 private boolean canRunNewAppsAnimation() {
3606 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3607 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3608 }
3609
Winson Chungf0c6ae02012-03-21 16:10:31 -07003610 /**
3611 * Runs a new animation that scales up icons that were added while Launcher was in the
3612 * background.
Winson Chunga2413752012-04-03 14:22:34 -07003613 *
3614 * @param immediate whether to run the animation or show the results immediately
Winson Chungf0c6ae02012-03-21 16:10:31 -07003615 */
Winson Chunga2413752012-04-03 14:22:34 -07003616 private void runNewAppsAnimation(boolean immediate) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07003617 AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003618 Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chunga2413752012-04-03 14:22:34 -07003619
3620 // Order these new views spatially so that they animate in order
Winson Chungf0c6ae02012-03-21 16:10:31 -07003621 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
3622 @Override
3623 public int compare(View a, View b) {
3624 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
3625 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
3626 int cellCountX = LauncherModel.getCellCountX();
3627 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
3628 }
3629 });
Winson Chunga2413752012-04-03 14:22:34 -07003630
3631 // Animate each of the views in place (or show them immediately if requested)
3632 if (immediate) {
3633 for (View v : mNewShortcutAnimateViews) {
3634 v.setAlpha(1f);
3635 v.setScaleX(1f);
3636 v.setScaleY(1f);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003637 }
Winson Chunga2413752012-04-03 14:22:34 -07003638 } else {
3639 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
3640 View v = mNewShortcutAnimateViews.get(i);
Michael Jurka2ecf9952012-06-18 12:52:28 -07003641 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
Winson Chunga2413752012-04-03 14:22:34 -07003642 PropertyValuesHolder.ofFloat("alpha", 1f),
3643 PropertyValuesHolder.ofFloat("scaleX", 1f),
3644 PropertyValuesHolder.ofFloat("scaleY", 1f));
3645 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3646 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3647 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3648 bounceAnims.add(bounceAnim);
3649 }
3650 anim.playTogether(bounceAnims);
3651 anim.addListener(new AnimatorListenerAdapter() {
3652 @Override
3653 public void onAnimationEnd(Animator animation) {
Michael Jurkad6dd7c82012-10-19 17:15:16 +02003654 if (mWorkspace != null) {
3655 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
3656 }
Winson Chunga2413752012-04-03 14:22:34 -07003657 }
3658 });
3659 anim.start();
3660 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003661
3662 // Clean up
3663 mNewShortcutAnimatePage = -1;
3664 mNewShortcutAnimateViews.clear();
3665 new Thread("clearNewAppsThread") {
3666 public void run() {
3667 mSharedPrefs.edit()
3668 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
3669 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null)
3670 .commit();
3671 }
3672 }.start();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003673 }
3674
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003675 @Override
3676 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003677 boolean searchVisible = updateGlobalSearchIcon();
3678 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003679 if (mSearchDropTargetBar != null) {
3680 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3681 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003682 }
3683
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003684 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003685 * Add the icons for all apps.
3686 *
3687 * Implementation of the method from LauncherModel.Callbacks.
3688 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003689 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003690 Runnable setAllAppsRunnable = new Runnable() {
3691 public void run() {
3692 if (mAppsCustomizeContent != null) {
3693 mAppsCustomizeContent.setApps(apps);
Adam Cohene25af792013-06-06 23:08:25 -07003694
3695 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3696 getHotseat().addAllAppsFolder(mIconCache, apps,
3697 mIntentsOnWorkspaceFromUpgradePath, Launcher.this);
3698 mIntentsOnWorkspaceFromUpgradePath = null;
3699 }
Winson Chungc93e5ae2012-07-23 20:48:26 -07003700 }
3701 }
3702 };
3703
Michael Jurkac57b7a82011-08-09 22:02:20 -07003704 // Remove the progress bar entirely; we could also make it GONE
3705 // but better to remove it since we know it's not going to be used
3706 View progressBar = mAppsCustomizeTabHost.
3707 findViewById(R.id.apps_customize_progress_bar);
3708 if (progressBar != null) {
3709 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chungc93e5ae2012-07-23 20:48:26 -07003710
3711 // We just post the call to setApps so the user sees the progress bar
3712 // disappear-- otherwise, it just looks like the progress bar froze
3713 // which doesn't look great
3714 mAppsCustomizeTabHost.post(setAllAppsRunnable);
3715 } else {
3716 // If we did not initialize the spinner in onCreate, then we can directly set the
3717 // list of applications without waiting for any progress bars views to be hidden.
3718 setAllAppsRunnable.run();
Winson Chung785d2eb2011-04-14 16:08:02 -07003719 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003720 }
3721
3722 /**
3723 * A package was installed.
3724 *
3725 * Implementation of the method from LauncherModel.Callbacks.
3726 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003727 public void bindAppsAdded(final ArrayList<ApplicationInfo> apps) {
3728 if (waitUntilResume(new Runnable() {
3729 public void run() {
3730 bindAppsAdded(apps);
3731 }
3732 })) {
3733 return;
3734 }
3735
Winson Chungf0ea4d32011-06-06 14:27:16 -07003736
Winson Chung785d2eb2011-04-14 16:08:02 -07003737 if (mAppsCustomizeContent != null) {
3738 mAppsCustomizeContent.addApps(apps);
3739 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003740 }
3741
3742 /**
3743 * A package was updated.
3744 *
3745 * Implementation of the method from LauncherModel.Callbacks.
3746 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003747 public void bindAppsUpdated(final ArrayList<ApplicationInfo> apps) {
3748 if (waitUntilResume(new Runnable() {
3749 public void run() {
3750 bindAppsUpdated(apps);
3751 }
3752 })) {
3753 return;
3754 }
3755
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003756 if (mWorkspace != null) {
3757 mWorkspace.updateShortcuts(apps);
3758 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003759
Winson Chung785d2eb2011-04-14 16:08:02 -07003760 if (mAppsCustomizeContent != null) {
3761 mAppsCustomizeContent.updateApps(apps);
3762 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003763 }
3764
3765 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003766 * A package was uninstalled. We take both the super set of packageNames
3767 * in addition to specific applications to remove, the reason being that
3768 * this can be called when a package is updated as well. In that scenario,
3769 * we only remove specific components from the workspace, where as
3770 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003771 *
3772 * Implementation of the method from LauncherModel.Callbacks.
3773 */
Winson Chung83892cc2013-05-01 16:53:33 -07003774 public void bindComponentsRemoved(final ArrayList<String> packageNames,
3775 final ArrayList<ApplicationInfo> appInfos,
3776 final boolean matchPackageNamesOnly) {
3777 if (waitUntilResume(new Runnable() {
3778 public void run() {
3779 bindComponentsRemoved(packageNames, appInfos, matchPackageNamesOnly);
3780 }
3781 })) {
3782 return;
3783 }
3784
3785 if (matchPackageNamesOnly) {
3786 mWorkspace.removeItemsByPackageName(packageNames);
3787 } else {
3788 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003789 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003790
Winson Chung785d2eb2011-04-14 16:08:02 -07003791 if (mAppsCustomizeContent != null) {
Winson Chung83892cc2013-05-01 16:53:33 -07003792 mAppsCustomizeContent.removeApps(appInfos);
Winson Chung785d2eb2011-04-14 16:08:02 -07003793 }
Winson Chunga1820962011-10-03 16:31:06 -07003794
3795 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003796 mDragController.onAppsRemoved(appInfos, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003797 }
Joe Onoratobe386092009-11-17 17:32:16 -08003798
3799 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003800 * A number of packages were updated.
3801 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003802
3803 private ArrayList<Object> mWidgetsAndShortcuts;
3804 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003805 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003806 bindPackagesUpdated(mWidgetsAndShortcuts);
3807 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003808 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003809 };
3810
3811 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3812 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3813 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003814 return;
3815 }
3816
Winson Chung785d2eb2011-04-14 16:08:02 -07003817 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003818 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003819 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003820 }
3821
Winson Chung400438b2011-01-16 17:53:48 -08003822 private int mapConfigurationOriActivityInfoOri(int configOri) {
3823 final Display d = getWindowManager().getDefaultDisplay();
3824 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3825 switch (d.getRotation()) {
3826 case Surface.ROTATION_0:
3827 case Surface.ROTATION_180:
3828 // We are currently in the same basic orientation as the natural orientation
3829 naturalOri = configOri;
3830 break;
3831 case Surface.ROTATION_90:
3832 case Surface.ROTATION_270:
3833 // We are currently in the other basic orientation to the natural orientation
3834 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3835 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3836 break;
3837 }
3838
3839 int[] oriMap = {
3840 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3841 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3842 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3843 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3844 };
3845 // Since the map starts at portrait, we need to offset if this device's natural orientation
3846 // is landscape.
3847 int indexOffset = 0;
3848 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3849 indexOffset = 1;
3850 }
3851 return oriMap[(d.getRotation() + indexOffset) % 4];
3852 }
Adam Cohen446e9402011-09-15 18:21:21 -07003853
Winson Chung4b919f82012-05-01 10:44:08 -07003854 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08003855 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07003856 getResources().getBoolean(R.bool.allow_rotation);
3857 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08003858 }
Winson Chung4b919f82012-05-01 10:44:08 -07003859 public void lockScreenOrientation() {
3860 if (isRotationEnabled()) {
3861 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3862 .getConfiguration().orientation));
3863 }
3864 }
3865 public void unlockScreenOrientation(boolean immediate) {
3866 if (isRotationEnabled()) {
3867 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07003868 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07003869 } else {
3870 mHandler.postDelayed(new Runnable() {
3871 public void run() {
3872 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3873 }
3874 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07003875 }
Winson Chung4b919f82012-05-01 10:44:08 -07003876 }
Winson Chung400438b2011-01-16 17:53:48 -08003877 }
3878
Winson Chung82f55532011-08-09 14:14:23 -07003879 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003880 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07003881 if (DISABLE_CLINGS) {
3882 return false;
3883 }
3884
Brett Chabot2a9e2282011-08-23 15:03:13 -07003885 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003886 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003887
Michael Jurkae233a8b2013-03-19 13:49:20 +01003888 // Restricted secondary users (child mode) will potentially have very few apps
3889 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04003890// boolean supportsLimitedUsers =
3891// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
3892// Account[] accounts = AccountManager.get(this).getAccounts();
3893// if (supportsLimitedUsers && accounts.length == 0) {
3894// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
3895// Bundle restrictions = um.getUserRestrictions();
3896// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
3897// return false;
3898// }
3899// }
Winson Chung7d7541e2011-09-16 20:14:36 -07003900 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003901 }
Michael Jurka22143132012-10-04 17:42:38 +02003902
Winson Chung7d7541e2011-09-16 20:14:36 -07003903 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
Michael Jurka22143132012-10-04 17:42:38 +02003904 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07003905 if (cling != null) {
3906 cling.init(this, positionData);
3907 cling.setVisibility(View.VISIBLE);
3908 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3909 if (animate) {
3910 cling.buildLayer();
3911 cling.setAlpha(0f);
3912 cling.animate()
3913 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003914 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003915 .setDuration(SHOW_CLING_DURATION)
3916 .setStartDelay(delay)
3917 .start();
3918 } else {
3919 cling.setAlpha(1f);
3920 }
Michael Jurka22143132012-10-04 17:42:38 +02003921 cling.setFocusableInTouchMode(true);
3922 cling.post(new Runnable() {
3923 public void run() {
3924 cling.setFocusable(true);
3925 cling.requestFocus();
3926 }
3927 });
3928 mHideFromAccessibilityHelper.setImportantForAccessibilityToNo(
3929 mDragLayer, clingId == R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003930 }
3931 return cling;
3932 }
Michael Jurka22143132012-10-04 17:42:38 +02003933
Winson Chung7d7541e2011-09-16 20:14:36 -07003934 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung7819abd2012-11-29 14:29:38 -08003935 // To catch cases where siblings of top-level views are made invisible, just check whether
3936 // the cling is directly set to GONE before dismissing it.
3937 if (cling != null && cling.getVisibility() != View.GONE) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07003938 ObjectAnimator anim = LauncherAnimUtils.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003939 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003940 anim.addListener(new AnimatorListenerAdapter() {
3941 public void onAnimationEnd(Animator animation) {
3942 cling.setVisibility(View.GONE);
3943 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003944 // We should update the shared preferences on a background thread
3945 new Thread("dismissClingThread") {
3946 public void run() {
3947 SharedPreferences.Editor editor = mSharedPrefs.edit();
3948 editor.putBoolean(flag, true);
3949 editor.commit();
3950 }
3951 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003952 };
3953 });
3954 anim.start();
Michael Jurka22143132012-10-04 17:42:38 +02003955 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung82f55532011-08-09 14:14:23 -07003956 }
3957 }
Michael Jurka22143132012-10-04 17:42:38 +02003958
Winson Chung9d9d74f2011-09-19 11:49:12 -07003959 private void removeCling(int id) {
3960 final View cling = findViewById(id);
3961 if (cling != null) {
3962 final ViewGroup parent = (ViewGroup) cling.getParent();
3963 parent.post(new Runnable() {
3964 @Override
3965 public void run() {
3966 parent.removeView(cling);
3967 }
3968 });
Michael Jurka22143132012-10-04 17:42:38 +02003969 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003970 }
3971 }
Michael Jurka974c3862012-05-22 22:00:31 -07003972
3973 private boolean skipCustomClingIfNoAccounts() {
3974 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3975 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
3976 if (customCling) {
3977 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04003978 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07003979 Account[] accounts = am.getAccountsByType("com.google");
3980 return accounts.length == 0;
3981 }
3982 return false;
3983 }
3984
Winson Chung7d7541e2011-09-16 20:14:36 -07003985 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003986 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003987 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07003988 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
3989 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02003990 // If we're not using the default workspace layout, replace workspace cling
3991 // with a custom workspace cling (usually specified in an overlay)
3992 // For now, only do this on tablets
3993 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
Michael Jurkaa1131212012-10-09 14:46:26 +02003994 getResources().getBoolean(R.bool.config_useCustomClings)) {
Michael Jurka45355c42012-10-08 13:21:35 +02003995 // Use a custom cling
3996 View cling = findViewById(R.id.workspace_cling);
3997 ViewGroup clingParent = (ViewGroup) cling.getParent();
3998 int clingIndex = clingParent.indexOfChild(cling);
3999 clingParent.removeViewAt(clingIndex);
4000 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4001 clingParent.addView(customCling, clingIndex);
4002 customCling.setId(R.id.workspace_cling);
4003 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004004 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004005 } else {
4006 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004007 }
4008 }
4009 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07004010 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004011 if (isClingsEnabled() &&
4012 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07004013 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004014 } else {
4015 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004016 }
4017 }
4018 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004019 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004020 if (isClingsEnabled() &&
4021 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
4022 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004023 } else {
4024 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004025 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004026 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004027 }
4028 public boolean isFolderClingVisible() {
4029 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004030 if (cling != null) {
4031 return cling.getVisibility() == View.VISIBLE;
4032 }
4033 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004034 }
Winson Chung82f55532011-08-09 14:14:23 -07004035 public void dismissWorkspaceCling(View v) {
4036 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004037 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004038 }
4039 public void dismissAllAppsCling(View v) {
4040 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004041 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
4042 }
4043 public void dismissFolderCling(View v) {
4044 Cling cling = (Cling) findViewById(R.id.folder_cling);
4045 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004046 }
4047
Winson Chung80baf5a2010-08-09 16:03:15 -07004048 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004049 * Prints out out state for debugging.
4050 */
4051 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004052 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004053 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004054 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4055 Log.d(TAG, "mRestoring=" + mRestoring);
4056 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4057 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004058 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004059 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004060
Winson Chung785d2eb2011-04-14 16:08:02 -07004061 if (mAppsCustomizeContent != null) {
4062 mAppsCustomizeContent.dumpState();
4063 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004064 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004065 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004066
4067 @Override
4068 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4069 super.dump(prefix, fd, writer, args);
4070 writer.println(" ");
4071 writer.println("Debug logs: ");
4072 for (int i = 0; i < sDumpLogs.size(); i++) {
4073 writer.println(" " + sDumpLogs.get(i));
4074 }
4075 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004076
4077 public static void dumpDebugLogsToConsole() {
4078 Log.d(TAG, "");
4079 Log.d(TAG, "*********************");
4080 Log.d(TAG, "Launcher debug logs: ");
4081 for (int i = 0; i < sDumpLogs.size(); i++) {
4082 Log.d(TAG, " " + sDumpLogs.get(i));
4083 }
4084 Log.d(TAG, "*********************");
4085 Log.d(TAG, "");
4086 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004087}
Michael Jurka2763be32011-02-24 11:19:57 -08004088
Michael Jurkaabded662011-03-04 12:06:57 -08004089interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004090 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004091 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004092 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004093 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004094 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004095}