blob: 8526905c59c6a265a16db97d85ff5f72b502f659 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Michael Jurka974c3862012-05-22 22:00:31 -070020import android.accounts.Account;
21import android.accounts.AccountManager;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080023import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070030import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070031import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070049import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080050import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070051import android.graphics.Bitmap;
52import android.graphics.Canvas;
Craig Mautner360310b2012-10-26 15:13:08 -070053import android.graphics.Color;
Adam Cohen268c4752012-06-06 17:47:33 -070054import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070055import android.graphics.Rect;
Craig Mautner360310b2012-10-26 15:13:08 -070056import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040058import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070059import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020061import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080062import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070063import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070064import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070066import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080067import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070072import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080073import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080074import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080075import android.view.KeyEvent;
76import android.view.LayoutInflater;
77import android.view.Menu;
78import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070079import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080080import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080081import android.view.View;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080082import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070083import android.view.ViewGroup;
Michael Jurkab737ee62011-11-15 15:57:22 -080084import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080085import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Dianne Hackbornbb003a52011-08-30 14:40:07 -070086import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080087import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070088import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070089import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080090import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070092import android.widget.Advanceable;
Michael Jurkaaf442092010-06-10 17:01:57 -070093import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070094import android.widget.TextView;
95import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070096
Daniel Sandler325dc232013-06-05 22:57:57 -040097import com.android.launcher3.R;
98import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080099
Adam Cohenc0dcf592011-06-01 15:30:43 -0700100import java.io.DataInputStream;
101import java.io.DataOutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700102import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700103import java.io.FileNotFoundException;
104import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700105import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700106import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700107import java.util.Collection;
108import java.util.Collections;
109import java.util.Comparator;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700110import java.util.HashMap;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700111import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700112import java.util.List;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700113import java.util.Set;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115/**
116 * Default launcher application.
117 */
Michael Jurka946ad472010-07-09 18:05:18 -0700118public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700119 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700120 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800121 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700122 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800123
Joe Onorato9c1289c2009-08-17 11:03:03 -0400124 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400125 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700126 static final boolean DEBUG_STRICT_MODE = false;
Michael Jurkac402cd92013-05-20 15:49:32 +0200127 static final boolean DEBUG_RESUME_TIME = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700128
Winson Chung70d72102011-08-12 11:24:35 -0700129 private static final int MENU_GROUP_WALLPAPER = 1;
130 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
131 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700132 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
133 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800134
135 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700139 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700140 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Michael Jurka8b805b12012-04-18 14:23:14 -0700142 private static final int REQUEST_BIND_APPWIDGET = 11;
143
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800144 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
145
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800146 static final int SCREEN_COUNT = 5;
147 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148
Romain Guy98d01652009-06-30 16:21:04 -0700149 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800150 // To turn on these properties, type
151 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
152 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
153 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Winson Chung2672ff92012-05-04 16:22:30 -0700155 // The Intent extra that defines whether to ignore the launch animation
156 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400157 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700158
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800159 // Type: int
160 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700161 // Type: int
162 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700164 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
165 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
167 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700168 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 // Type: boolean
172 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
173 // Type: long
174 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700175 // Type: int
176 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
177 // Type: int
178 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
179 // Type: parcelable
180 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100182 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700183 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100184 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700185 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100186 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700187
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700188 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700189 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700190 private State mState = State.WORKSPACE;
191 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800192 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700193
Joe Onorato9c1289c2009-08-17 11:03:03 -0400194 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700195 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
196 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700197 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700198 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800199
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800200 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800201 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202
Winson Chunga2413752012-04-03 14:22:34 -0700203 // How long to wait before the new-shortcut animation automatically pans the workspace
204 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
205
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800206 private final BroadcastReceiver mCloseSystemDialogsReceiver
207 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800208 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
209
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210 private LayoutInflater mInflater;
211
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800213 private View mQsbDivider;
214 private View mDockDivider;
Craig Mautner360310b2012-10-26 15:13:08 -0700215 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800216 private DragLayer mDragLayer;
217 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700218
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700219 private AppWidgetManager mAppWidgetManager;
220 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700221
Michael Jurkac9d95c52011-08-29 14:03:34 -0700222 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700223 private AppWidgetProviderInfo mPendingAddWidgetInfo;
224
Michael Jurka0280c3b2010-09-17 15:00:07 -0700225 private int[] mTmpAddItemCellCoordinates = new int[2];
226
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800227 private FolderInfo mFolderInfo;
228
Winson Chung3d503fb2011-07-13 17:25:49 -0700229 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800230 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700231
Winson Chungc51db6a2011-10-05 11:44:49 -0700232 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700233 private AppsCustomizeTabHost mAppsCustomizeTabHost;
234 private AppsCustomizePagedView mAppsCustomizeContent;
235 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800237 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700238 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
239 // scroll issues (because the workspace may not have been measured yet) and extra work.
240 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
241 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800242
243 private SpannableStringBuilder mDefaultKeySsb = null;
244
Joe Onorato9c1289c2009-08-17 11:03:03 -0400245 private boolean mWorkspaceLoading = true;
246
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800247 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800248 private boolean mRestoring;
249 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700250 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800251
Michael Jurka7607c2f2013-04-03 14:33:19 -0700252 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
253
Winson Chung4a2afa32012-07-19 14:53:05 -0700254 // Keep track of whether the user has left launcher
255 private static boolean sPausedFromUserAction = false;
256
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800257 private Bundle mSavedInstanceState;
258
Joe Onorato9c1289c2009-08-17 11:03:03 -0400259 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800260 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800261 private boolean mUserPresent = true;
262 private boolean mVisible = false;
263 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400264
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700265 private static LocaleConfiguration sLocaleConfiguration = null;
266
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700267 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700268
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700269 private Intent mAppMarketIntent = null;
270
Adam Cohended9f8d2010-11-03 13:25:16 -0700271 // Related to the auto-advancing of widgets
272 private final int ADVANCE_MSG = 1;
273 private final int mAdvanceInterval = 20000;
274 private final int mAdvanceStagger = 250;
275 private long mAutoAdvanceSentTime;
276 private long mAutoAdvanceTimeLeft = -1;
277 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
278 new HashMap<View, AppWidgetProviderInfo>();
279
Winson Chung400438b2011-01-16 17:53:48 -0800280 // Determines how long to wait after a rotation before restoring the screen orientation to
281 // match the sensor state.
282 private final int mRestoreScreenOrientationDelay = 500;
283
Michael Jurka4ef207b2010-11-29 17:05:45 -0800284 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700285 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
286 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
287 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800288
Craig Mautner360310b2012-10-26 15:13:08 -0700289 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700290
Adam Cohen1462de32012-07-24 22:34:36 -0700291 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
292
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700293 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
294
Winson Chung46353de2012-02-16 14:05:10 -0800295 // We only want to get the SharedPreferences once since it does an FS stat each time we get
296 // it from the context.
297 private SharedPreferences mSharedPrefs;
298
Adam Cohene25af792013-06-06 23:08:25 -0700299 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
300
Winson Chungf0c6ae02012-03-21 16:10:31 -0700301 // Holds the page that we need to animate to, and the icon views that we need to animate up
302 // when we scroll to that page on resume.
303 private int mNewShortcutAnimatePage = -1;
304 private ArrayList<View> mNewShortcutAnimateViews = new ArrayList<View>();
Adam Cohen268c4752012-06-06 17:47:33 -0700305 private ImageView mFolderIconImageView;
306 private Bitmap mFolderIconBitmap;
307 private Canvas mFolderIconCanvas;
308 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700309
Michael Jurkaddd62e92011-02-16 17:49:14 -0800310 private BubbleTextView mWaitingForResume;
311
Michael Jurka22143132012-10-04 17:42:38 +0200312 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
313 = new HideFromAccessibilityHelper();
314
Michael Jurkac1f5d262011-09-30 19:32:27 -0700315 private Runnable mBuildLayersRunnable = new Runnable() {
316 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700317 if (mWorkspace != null) {
318 mWorkspace.buildPageHardwareLayers();
319 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700320 }
321 };
322
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800323 private static ArrayList<PendingAddArguments> sPendingAddList
324 = new ArrayList<PendingAddArguments>();
325
Michael Jurka0a457bf2012-11-19 14:05:05 -0800326 private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
327
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800328 private static class PendingAddArguments {
329 int requestCode;
330 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700331 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800332 int screen;
333 int cellX;
334 int cellY;
335 }
336
Michael Jurka0a457bf2012-11-19 14:05:05 -0800337 private static boolean isPropertyEnabled(String propertyName) {
338 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700339 }
340
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800341 @Override
342 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700343 if (DEBUG_STRICT_MODE) {
344 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
345 .detectDiskReads()
346 .detectDiskWrites()
347 .detectNetwork() // or .detectAll() for all detectable problems
348 .penaltyLog()
349 .build());
350 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
351 .detectLeakedSqlLiteObjects()
352 .detectLeakedClosableObjects()
353 .penaltyLog()
354 .penaltyDeath()
355 .build());
356 }
357
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800358 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800359 LauncherApplication app = ((LauncherApplication)getApplication());
Winson Chungf0c6ae02012-03-21 16:10:31 -0700360 mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(),
361 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800362 mModel = app.setLauncher(this);
363 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400364 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800365 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700366
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700367 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700368 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
369 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700370
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700371 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
372 // this also ensures that any synchronous binding below doesn't re-trigger another
373 // LauncherModel load.
374 mPaused = false;
375
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200377 android.os.Debug.startMethodTracing(
378 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800379 }
380
381 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800382 setContentView(R.layout.launcher);
383 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700384 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800386 registerContentObservers();
387
Joe Onorato7c312c12009-08-13 21:36:53 -0700388 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700389
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800390 mSavedState = savedInstanceState;
391 restoreState(mSavedState);
392
Winson Chunga12a2502010-12-20 14:41:35 -0800393 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700394 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200395 mAppsCustomizeContent.onPackagesUpdated(
396 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700397 }
Winson Chunga12a2502010-12-20 14:41:35 -0800398
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800399 if (PROFILE_STARTUP) {
400 android.os.Debug.stopMethodTracing();
401 }
402
403 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700404 if (sPausedFromUserAction) {
405 // If the user leaves launcher, then we should just load items asynchronously when
406 // they return.
407 mModel.startLoader(true, -1);
408 } else {
409 // We only load the page synchronously if the user rotates (or triggers a
410 // configuration change) while launcher is in the foreground
411 mModel.startLoader(true, mWorkspace.getCurrentPage());
412 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800413 }
414
Michael Jurkac57b7a82011-08-09 22:02:20 -0700415 if (!mModel.isAllAppsLoaded()) {
416 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
417 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
418 }
419
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800420 // For handling default keys
421 mDefaultKeySsb = new SpannableStringBuilder();
422 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800423
424 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
425 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800426
Adam Cohenf9426d52012-06-04 17:26:21 -0700427 updateGlobalIcons();
428
429 // On large interfaces, we want the screen to auto-rotate based on the current orientation
430 unlockScreenOrientation(true);
431 }
432
Winson Chung4a2afa32012-07-19 14:53:05 -0700433 protected void onUserLeaveHint() {
434 super.onUserLeaveHint();
435 sPausedFromUserAction = true;
436 }
437
Adam Cohenf9426d52012-06-04 17:26:21 -0700438 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700439 boolean searchVisible = false;
440 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800441 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700442 int coi = getCurrentOrientationIndexForGlobalIcons();
443 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
444 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700445 updateAppMarketIcon();
446 searchVisible = updateGlobalSearchIcon();
447 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700448 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700449 if (sGlobalSearchIcon[coi] != null) {
450 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700451 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700452 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700453 if (sVoiceSearchIcon[coi] != null) {
454 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700455 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700456 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700457 if (sAppMarketIcon[coi] != null) {
458 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800459 }
Winson Chungadf0c182012-08-23 14:59:07 -0700460 if (mSearchDropTargetBar != null) {
461 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
462 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800463 }
Romain Guycbb89e42009-06-08 15:52:54 -0700464
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800465 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700466 if (sLocaleConfiguration == null) {
467 new AsyncTask<Void, Void, LocaleConfiguration>() {
468 @Override
469 protected LocaleConfiguration doInBackground(Void... unused) {
470 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
471 readConfiguration(Launcher.this, localeConfiguration);
472 return localeConfiguration;
473 }
474
475 @Override
476 protected void onPostExecute(LocaleConfiguration result) {
477 sLocaleConfiguration = result;
478 checkForLocaleChange(); // recursive, but now with a locale configuration
479 }
480 }.execute();
481 return;
482 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700483
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800484 final Configuration configuration = getResources().getConfiguration();
485
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700486 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800487 final String locale = configuration.locale.toString();
488
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700489 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800490 final int mcc = configuration.mcc;
491
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700492 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800493 final int mnc = configuration.mnc;
494
Romain Guy84f296c2009-11-04 15:00:44 -0800495 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800496
Romain Guy84f296c2009-11-04 15:00:44 -0800497 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700498 sLocaleConfiguration.locale = locale;
499 sLocaleConfiguration.mcc = mcc;
500 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700501
Joe Onorato0589f0f2010-02-08 13:44:00 -0800502 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700503
504 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
505 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700506 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700507 public void run() {
508 writeConfiguration(Launcher.this, localeConfiguration);
509 }
510 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700511 }
512 }
513
514 private static class LocaleConfiguration {
515 public String locale;
516 public int mcc = -1;
517 public int mnc = -1;
518 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700519
Romain Guy98d01652009-06-30 16:21:04 -0700520 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
521 DataInputStream in = null;
522 try {
523 in = new DataInputStream(context.openFileInput(PREFERENCES));
524 configuration.locale = in.readUTF();
525 configuration.mcc = in.readInt();
526 configuration.mnc = in.readInt();
527 } catch (FileNotFoundException e) {
528 // Ignore
529 } catch (IOException e) {
530 // Ignore
531 } finally {
532 if (in != null) {
533 try {
534 in.close();
535 } catch (IOException e) {
536 // Ignore
537 }
538 }
539 }
540 }
541
542 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
543 DataOutputStream out = null;
544 try {
545 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
546 out.writeUTF(configuration.locale);
547 out.writeInt(configuration.mcc);
548 out.writeInt(configuration.mnc);
549 out.flush();
550 } catch (FileNotFoundException e) {
551 // Ignore
552 } catch (IOException e) {
553 //noinspection ResultOfMethodCallIgnored
554 context.getFileStreamPath(PREFERENCES).delete();
555 } finally {
556 if (out != null) {
557 try {
558 out.close();
559 } catch (IOException e) {
560 // Ignore
561 }
562 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800563 }
564 }
565
Adam Cohen716b51e2011-06-30 12:09:54 -0700566 public DragLayer getDragLayer() {
567 return mDragLayer;
568 }
569
Winson Chung36a62fe2012-05-06 18:04:42 -0700570 boolean isDraggingEnabled() {
571 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
572 // that is subsequently removed from the workspace in startBinding().
573 return !mModel.isLoadingWorkspace();
574 }
575
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800576 static int getScreen() {
577 synchronized (sLock) {
578 return sScreen;
579 }
580 }
581
582 static void setScreen(int screen) {
583 synchronized (sLock) {
584 sScreen = screen;
585 }
586 }
587
Winson Chung557d6ed2011-07-08 15:34:52 -0700588 /**
589 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
590 * a configuration step, this allows the proper animations to run after other transitions.
591 */
592 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700593 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800594 switch (args.requestCode) {
595 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700596 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
597 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800598 break;
599 case REQUEST_PICK_SHORTCUT:
600 processShortcut(args.intent);
601 break;
602 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700603 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
604 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700605 result = true;
606 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800607 case REQUEST_CREATE_APPWIDGET:
608 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800609 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700610 result = true;
611 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800612 case REQUEST_PICK_WALLPAPER:
613 // We just wanted the activity result here so we can clear mWaitingForResult
614 break;
615 }
Michael Jurka27614d22012-04-02 06:40:22 -0700616 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
617 // if you turned the screen off and then back while in All Apps, Launcher would not
618 // return to the workspace. Clearing mAddInfo.container here fixes this issue
619 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700620 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800621 }
622
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800623 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700624 protected void onActivityResult(
625 final int requestCode, final int resultCode, final Intent data) {
626 if (requestCode == REQUEST_BIND_APPWIDGET) {
627 int appWidgetId = data != null ?
628 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
629 if (resultCode == RESULT_CANCELED) {
630 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
631 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700632 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700633 }
634 return;
635 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700636 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800637 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
638 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700639 mWaitingForResult = false;
640
Adam Cohened66b2b2012-01-23 17:28:51 -0800641 // We have special handling for widgets
642 if (isWidgetDrop) {
643 int appWidgetId = data != null ?
644 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700645 if (appWidgetId < 0) {
646 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
647 "widget configuration activity.");
648 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
649 } else {
650 completeTwoStageWidgetDrop(resultCode, appWidgetId);
651 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800652 return;
653 }
654
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800655 // The pattern used here is that a user PICKs a specific application,
656 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700657
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800658 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
659 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700660 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800661 final PendingAddArguments args = new PendingAddArguments();
662 args.requestCode = requestCode;
663 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700664 args.container = mPendingAddInfo.container;
665 args.screen = mPendingAddInfo.screen;
666 args.cellX = mPendingAddInfo.cellX;
667 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800668 if (isWorkspaceLocked()) {
669 sPendingAddList.add(args);
670 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700671 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800672 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800674 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700675 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800676 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
677 null);
678 }
679
680 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700681 CellLayout cellLayout =
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700682 (CellLayout) mWorkspace.getChildAt(mPendingAddInfo.screen);
Adam Cohened66b2b2012-01-23 17:28:51 -0800683 Runnable onCompleteRunnable = null;
684 int animationType = 0;
685
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700686 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800687 if (resultCode == RESULT_OK) {
688 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
689 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700690 mPendingAddWidgetInfo);
691 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800692 onCompleteRunnable = new Runnable() {
693 @Override
694 public void run() {
695 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
696 mPendingAddInfo.screen, layout, null);
697 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
698 null);
699 }
700 };
701 } else if (resultCode == RESULT_CANCELED) {
702 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
703 onCompleteRunnable = new Runnable() {
704 @Override
705 public void run() {
706 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
707 null);
708 }
709 };
710 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700711 if (mDragLayer.getAnimatedView() != null) {
712 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
713 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
714 animationType, boundWidget, true);
715 } else {
716 // The animated view may be null in the case of a rotation during widget configuration
717 onCompleteRunnable.run();
718 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800719 }
720
721 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700722 protected void onStop() {
723 super.onStop();
724 FirstFrameAnimatorHelper.setIsVisible(false);
725 }
726
727 @Override
728 protected void onStart() {
729 super.onStart();
730 FirstFrameAnimatorHelper.setIsVisible(true);
731 }
732
733 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800734 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200735 long startTime = 0;
736 if (DEBUG_RESUME_TIME) {
737 startTime = System.currentTimeMillis();
738 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800739 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700740
Winson Chung4a2afa32012-07-19 14:53:05 -0700741 // Restore the previous launcher state
742 if (mOnResumeState == State.WORKSPACE) {
743 showWorkspace(false);
744 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
745 showAllApps(false);
746 }
747 mOnResumeState = State.NONE;
748
Craig Mautner360310b2012-10-26 15:13:08 -0700749 // Background was set to gradient in onPause(), restore to black if in all apps.
750 setWorkspaceBackground(mState == State.WORKSPACE);
751
Winson Chungde0fb8f2012-05-08 14:37:08 -0700752 // Process any items that were added while Launcher was away
753 InstallShortcutReceiver.flushInstallQueue(this);
754
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800755 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700756 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700757 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400758 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700759 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400760 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700761 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800762 }
Michael Jurkac402cd92013-05-20 15:49:32 +0200763 if (mOnResumeCallbacks.size() > 0) {
764 // We might have postponed some bind calls until onResume (see waitUntilResume) --
765 // execute them here
766 long startTimeCallbacks = 0;
767 if (DEBUG_RESUME_TIME) {
768 startTimeCallbacks = System.currentTimeMillis();
769 }
770
771 if (mAppsCustomizeContent != null) {
772 mAppsCustomizeContent.setBulkBind(true);
773 }
774 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
775 mOnResumeCallbacks.get(i).run();
776 }
777 if (mAppsCustomizeContent != null) {
778 mAppsCustomizeContent.setBulkBind(false);
779 }
780 mOnResumeCallbacks.clear();
781 if (DEBUG_RESUME_TIME) {
782 Log.d(TAG, "Time spent processing callbacks in onResume: " +
783 (System.currentTimeMillis() - startTimeCallbacks));
784 }
Michael Jurka447bf842013-05-15 14:52:15 +0200785 }
Winson Chunge4e50662012-01-23 14:45:13 -0800786
787 // Reset the pressed state of icons that were locked in the press state while activities
788 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800789 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800790 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800791 mWaitingForResume.setStayPressed(false);
792 }
Winson Chunge4e50662012-01-23 14:45:13 -0800793 if (mAppsCustomizeContent != null) {
794 // Resets the previous all apps icon press state
795 mAppsCustomizeContent.resetDrawableState();
796 }
Adam Cohen06dff352012-06-01 17:17:08 -0700797 // It is possible that widgets can receive updates while launcher is not in the foreground.
798 // Consequently, the widgets will be inflated in the orientation of the foreground activity
799 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
800 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700801 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700802
803 // Again, as with the above scenario, it's possible that one or more of the global icons
804 // were updated in the wrong orientation.
805 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200806 if (DEBUG_RESUME_TIME) {
807 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
808 }
Adam Cohen06dff352012-06-01 17:17:08 -0700809 }
810
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800811 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700812 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700813 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
814 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
815 // when Launcher resumes and we are still in AllApps.
816 updateWallpaperVisibility(true);
817
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700818 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700819 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800820 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700821 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700822 }
Romain Guycbb89e42009-06-08 15:52:54 -0700823
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700824 @Override
825 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400826 // Flag the loader to stop early before switching
827 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700828 if (mAppsCustomizeContent != null) {
829 mAppsCustomizeContent.surrender();
830 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800831 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700832 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700833
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800834 // We can't hide the IME if it was forced open. So don't bother
835 /*
836 @Override
837 public void onWindowFocusChanged(boolean hasFocus) {
838 super.onWindowFocusChanged(hasFocus);
839
840 if (hasFocus) {
841 final InputMethodManager inputManager = (InputMethodManager)
842 getSystemService(Context.INPUT_METHOD_SERVICE);
843 WindowManager.LayoutParams lp = getWindow().getAttributes();
844 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
845 android.os.Handler()) {
846 protected void onReceiveResult(int resultCode, Bundle resultData) {
847 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
848 }
849 });
850 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
851 }
852 }
853 */
854
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800855 private boolean acceptFilter() {
856 final InputMethodManager inputManager = (InputMethodManager)
857 getSystemService(Context.INPUT_METHOD_SERVICE);
858 return !inputManager.isFullscreenMode();
859 }
860
861 @Override
862 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700863 final int uniChar = event.getUnicodeChar();
864 final boolean handled = super.onKeyDown(keyCode, event);
865 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
866 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800867 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
868 keyCode, event);
869 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700870 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700871 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700872 // showSearchDialog()
873 // If there are multiple keystrokes before the search dialog takes focus,
874 // onSearchRequested() will be called for every keystroke,
875 // but it is idempotent, so it's fine.
876 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800877 }
878 }
879
Joe Onorato8a9625e2010-01-28 15:55:35 -0800880 // Eat the long press event so the keyboard doesn't come up.
881 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
882 return true;
883 }
884
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800885 return handled;
886 }
887
Karl Rosaen138a0412009-04-23 19:00:21 -0700888 private String getTypedText() {
889 return mDefaultKeySsb.toString();
890 }
891
892 private void clearTypedText() {
893 mDefaultKeySsb.clear();
894 mDefaultKeySsb.clearSpans();
895 Selection.setSelection(mDefaultKeySsb, 0);
896 }
897
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700899 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
900 * State
901 */
902 private static State intToState(int stateOrdinal) {
903 State state = State.WORKSPACE;
904 final State[] stateValues = State.values();
905 for (int i = 0; i < stateValues.length; i++) {
906 if (stateValues[i].ordinal() == stateOrdinal) {
907 state = stateValues[i];
908 break;
909 }
910 }
911 return state;
912 }
913
914 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800915 * Restores the previous state, if it exists.
916 *
917 * @param savedState The previous state.
918 */
919 private void restoreState(Bundle savedState) {
920 if (savedState == null) {
921 return;
922 }
923
Michael Jurka883f55b2010-10-21 15:47:14 -0700924 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700925 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700926 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -0800927 }
928
Winson Chungf0c6ae02012-03-21 16:10:31 -0700929 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800930 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700931 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800932 }
933
Winson Chung3d503fb2011-07-13 17:25:49 -0700934 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
935 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700936
Winson Chung3d503fb2011-07-13 17:25:49 -0700937 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
938 mPendingAddInfo.container = pendingAddContainer;
939 mPendingAddInfo.screen = pendingAddScreen;
940 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
941 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700942 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
943 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
944 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -0700945 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800946 mRestoring = true;
947 }
948
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700949
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800950 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
951 if (renameFolder) {
952 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700953 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800954 mRestoring = true;
955 }
Winson Chunga12a2502010-12-20 14:41:35 -0800956
Winson Chung785d2eb2011-04-14 16:08:02 -0700957
958 // Restore the AppsCustomize tab
959 if (mAppsCustomizeTabHost != null) {
960 String curTab = savedState.getString("apps_customize_currentTab");
961 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -0700962 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -0700963 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -0700964 mAppsCustomizeContent.loadAssociatedPages(
965 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700966 }
967
Winson Chung5afbf7b2011-07-25 11:53:08 -0700968 int currentIndex = savedState.getInt("apps_customize_currentIndex");
969 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700970 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800971 }
972
973 /**
974 * Finds all the views we need and configure them properly.
975 */
976 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700977 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400978
Craig Mautner360310b2012-10-26 15:13:08 -0700979 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -0700980 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
981 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -0700982 mQsbDivider = findViewById(R.id.qsb_divider);
983 mDockDivider = findViewById(R.id.dock_divider);
984
985 mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
986 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800987
Winson Chung4c98d922011-05-31 16:50:48 -0700988 // Setup the drag layer
989 mDragLayer.setup(this, dragController);
990
Winson Chung3d503fb2011-07-13 17:25:49 -0700991 // Setup the hotseat
992 mHotseat = (Hotseat) findViewById(R.id.hotseat);
993 if (mHotseat != null) {
994 mHotseat.setup(this);
995 }
996
Winson Chung4c98d922011-05-31 16:50:48 -0700997 // Setup the workspace
998 mWorkspace.setHapticFeedbackEnabled(false);
999 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001000 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001001 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001002
Winson Chungf0ea4d32011-06-06 14:27:16 -07001003 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001004 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001005
Winson Chungf0ea4d32011-06-06 14:27:16 -07001006 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001007 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001008 mAppsCustomizeContent = (AppsCustomizePagedView)
1009 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1010 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001011
Winson Chung3d503fb2011-07-13 17:25:49 -07001012 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001013 dragController.setDragScoller(mWorkspace);
1014 dragController.setScrollView(mDragLayer);
1015 dragController.setMoveTarget(mWorkspace);
1016 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001017 if (mSearchDropTargetBar != null) {
1018 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001019 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001020 }
1021
1022 /**
1023 * Creates a view representing a shortcut.
1024 *
1025 * @param info The data structure describing the shortcut.
1026 *
1027 * @return A View inflated from R.layout.application.
1028 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001029 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001030 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001031 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001032 }
1033
1034 /**
1035 * Creates a view representing a shortcut inflated from the specified resource.
1036 *
1037 * @param layoutResId The id of the XML layout used to create the shortcut.
1038 * @param parent The group the shortcut belongs to.
1039 * @param info The data structure describing the shortcut.
1040 *
1041 * @return A View inflated from layoutResId.
1042 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001043 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001044 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1045 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001046 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001047 return favorite;
1048 }
1049
1050 /**
1051 * Add an application shortcut to the workspace.
1052 *
1053 * @param data The intent describing the application.
1054 * @param cellInfo The position on screen where to create the shortcut.
1055 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001056 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001057 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -07001058 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001059
Adam Cohenfbba09b2011-07-18 21:43:05 -07001060 // First we check if we already know the exact location where we want to add this item.
1061 if (cellX >= 0 && cellY >= 0) {
1062 cellXY[0] = cellX;
1063 cellXY[1] = cellY;
1064 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001065 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001066 return;
1067 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001068
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001069 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001070
Romain Guy73b979d2009-06-09 12:57:21 -07001071 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001072 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001073 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001074 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -07001075 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001076 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001077 } else {
1078 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001079 }
1080 }
Romain Guycbb89e42009-06-08 15:52:54 -07001081
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001082 /**
1083 * Add a shortcut to the workspace.
1084 *
1085 * @param data The intent describing the shortcut.
1086 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001087 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001088 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
1089 int cellY) {
1090 int[] cellXY = mTmpAddItemCellCoordinates;
1091 int[] touchXY = mPendingAddInfo.dropPos;
1092 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001093
Michael Jurkad3ef3062010-11-23 16:23:58 -08001094 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001095
Adam Cohen558baaf2011-08-15 15:22:57 -07001096 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001097 if (info == null) {
1098 return;
1099 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001100 final View view = createShortcut(info);
1101
Adam Cohenfbba09b2011-07-18 21:43:05 -07001102 // First we check if we already know the exact location where we want to add this item.
1103 if (cellX >= 0 && cellY >= 0) {
1104 cellXY[0] = cellX;
1105 cellXY[1] = cellY;
1106 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001107
1108 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001109 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001110 true, null,null)) {
1111 return;
1112 }
1113 DragObject dragObject = new DragObject();
1114 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001115 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1116 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001117 return;
1118 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001119 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001120 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001121 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001122 foundCellSpan = (result != null);
1123 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001124 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001125 }
1126
1127 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001128 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001129 return;
1130 }
1131
Adam Cohen558baaf2011-08-15 15:22:57 -07001132 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001133
1134 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001135 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
1136 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001137 }
1138 }
1139
Adam Cohen2f093b62012-04-30 18:59:53 -07001140 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1141 int minHeight) {
1142 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001143 // We want to account for the extra amount of padding that we are adding to the widget
1144 // to ensure that it gets the full amount of space that it has requested
1145 int requiredWidth = minWidth + padding.left + padding.right;
1146 int requiredHeight = minHeight + padding.top + padding.bottom;
Adam Cohen2f093b62012-04-30 18:59:53 -07001147 return CellLayout.rectToCell(context.getResources(), requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001148 }
1149
Adam Cohen2f093b62012-04-30 18:59:53 -07001150 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1151 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001152 }
1153
Adam Cohen2f093b62012-04-30 18:59:53 -07001154 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1155 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001156 }
1157
Adam Cohen2f093b62012-04-30 18:59:53 -07001158 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1159 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001160 }
1161
Adam Cohen2f093b62012-04-30 18:59:53 -07001162 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1163 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001164 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001165 }
1166
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001167 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001168 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001169 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001170 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001171 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001172 */
Adam Cohened66b2b2012-01-23 17:28:51 -08001173 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
1174 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1175 if (appWidgetInfo == null) {
1176 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1177 }
Romain Guycbb89e42009-06-08 15:52:54 -07001178
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001179 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -07001180 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -07001181
Adam Cohen2f093b62012-04-30 18:59:53 -07001182 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1183 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001184
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001185 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001186 // We have saved the position to which the widget was dragged-- this really only matters
1187 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001188 int[] cellXY = mTmpAddItemCellCoordinates;
1189 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001190 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001191 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001192 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1193 cellXY[0] = mPendingAddInfo.cellX;
1194 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001195 spanXY[0] = mPendingAddInfo.spanX;
1196 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001197 foundCellSpan = true;
1198 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001199 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001200 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001201 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1202 spanXY[1], cellXY, finalSpan);
1203 spanXY[0] = finalSpan[0];
1204 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001205 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001206 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001207 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001208 }
1209
Michael Jurka0280c3b2010-09-17 15:00:07 -07001210 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001211 if (appWidgetId != -1) {
1212 // Deleting an app widget ID is a void call but writes to disk before returning
1213 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001214 new Thread("deleteAppWidgetId") {
1215 public void run() {
1216 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1217 }
1218 }.start();
1219 }
Winson Chung93eef082012-03-23 15:59:27 -07001220 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001221 return;
1222 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001223
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001224 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001225 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1226 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001227 launcherInfo.spanX = spanXY[0];
1228 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001229 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1230 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001231
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001233 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001234
1235 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001236 if (hostView == null) {
1237 // Perform actual inflation because we're live
1238 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1239 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1240 } else {
1241 // The AppWidgetHostView has already been inflated and instantiated
1242 launcherInfo.hostView = hostView;
1243 }
Romain Guycbb89e42009-06-08 15:52:54 -07001244
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001245 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001246 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001247 launcherInfo.notifyWidgetSizeChanged(this);
1248
Winson Chung3d503fb2011-07-13 17:25:49 -07001249 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001250 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001251
1252 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001253 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001254 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001255 }
Romain Guycbb89e42009-06-08 15:52:54 -07001256
Adam Cohended9f8d2010-11-03 13:25:16 -07001257 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1258 @Override
1259 public void onReceive(Context context, Intent intent) {
1260 final String action = intent.getAction();
1261 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1262 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001263 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001264 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001265
Winson Chungc100e8e2011-08-09 16:02:43 -07001266 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001267 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001268 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1269 mAppsCustomizeTabHost.reset();
1270 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001271 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001272 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1273 mUserPresent = true;
1274 updateRunning();
1275 }
1276 }
1277 };
1278
1279 @Override
1280 public void onAttachedToWindow() {
1281 super.onAttachedToWindow();
1282
1283 // Listen for broadcasts related to user-presence
1284 final IntentFilter filter = new IntentFilter();
1285 filter.addAction(Intent.ACTION_SCREEN_OFF);
1286 filter.addAction(Intent.ACTION_USER_PRESENT);
1287 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001288 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001289 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001290 mVisible = true;
1291 }
1292
1293 @Override
1294 public void onDetachedFromWindow() {
1295 super.onDetachedFromWindow();
1296 mVisible = false;
1297
Adam Cohend113e0c2010-11-11 10:48:05 -08001298 if (mAttached) {
1299 unregisterReceiver(mReceiver);
1300 mAttached = false;
1301 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001302 updateRunning();
1303 }
1304
1305 public void onWindowVisibilityChanged(int visibility) {
1306 mVisible = visibility == View.VISIBLE;
1307 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001308 // The following code used to be in onResume, but it turns out onResume is called when
1309 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1310 // is a more appropriate event to handle
1311 if (mVisible) {
1312 mAppsCustomizeTabHost.onWindowVisible();
1313 if (!mWorkspaceLoading) {
1314 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001315 // We want to let Launcher draw itself at least once before we force it to build
1316 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001317 // apps is nice and speedy.
1318 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001319 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001320 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001321 if (mStarted) return;
1322 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001323 // We delay the layer building a bit in order to give
1324 // other message processing a time to run. In particular
1325 // this avoids a delay in hiding the IME if it was
1326 // currently shown, because doing that may involve
1327 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001328 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001329 final ViewTreeObserver.OnDrawListener listener = this;
1330 mWorkspace.post(new Runnable() {
1331 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001332 if (mWorkspace != null &&
1333 mWorkspace.getViewTreeObserver() != null) {
1334 mWorkspace.getViewTreeObserver().
1335 removeOnDrawListener(listener);
1336 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001337 }
1338 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001339 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001340 }
1341 });
1342 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001343 // When Launcher comes back to foreground, a different Activity might be responsible for
1344 // the app market intent, so refresh the icon
1345 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001346 clearTypedText();
1347 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001348 }
1349
1350 private void sendAdvanceMessage(long delay) {
1351 mHandler.removeMessages(ADVANCE_MSG);
1352 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1353 mHandler.sendMessageDelayed(msg, delay);
1354 mAutoAdvanceSentTime = System.currentTimeMillis();
1355 }
1356
1357 private void updateRunning() {
1358 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1359 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1360 mAutoAdvanceRunning = autoAdvanceRunning;
1361 if (autoAdvanceRunning) {
1362 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1363 sendAdvanceMessage(delay);
1364 } else {
1365 if (!mWidgetsToAdvance.isEmpty()) {
1366 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1367 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1368 }
1369 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001370 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001371 }
1372 }
1373 }
1374
1375 private final Handler mHandler = new Handler() {
1376 @Override
1377 public void handleMessage(Message msg) {
1378 if (msg.what == ADVANCE_MSG) {
1379 int i = 0;
1380 for (View key: mWidgetsToAdvance.keySet()) {
1381 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1382 final int delay = mAdvanceStagger * i;
1383 if (v instanceof Advanceable) {
1384 postDelayed(new Runnable() {
1385 public void run() {
1386 ((Advanceable) v).advance();
1387 }
1388 }, delay);
1389 }
1390 i++;
1391 }
1392 sendAdvanceMessage(mAdvanceInterval);
1393 }
1394 }
1395 };
1396
1397 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001398 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001399 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1400 if (v instanceof Advanceable) {
1401 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001402 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001403 updateRunning();
1404 }
1405 }
1406
1407 void removeWidgetToAutoAdvance(View hostView) {
1408 if (mWidgetsToAdvance.containsKey(hostView)) {
1409 mWidgetsToAdvance.remove(hostView);
1410 updateRunning();
1411 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001412 }
1413
Joe Onorato9c1289c2009-08-17 11:03:03 -04001414 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001415 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001416 launcherInfo.hostView = null;
1417 }
1418
Winson Chung93eef082012-03-23 15:59:27 -07001419 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1420 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1421 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001422 }
1423
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001424 public LauncherAppWidgetHost getAppWidgetHost() {
1425 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001426 }
Romain Guycbb89e42009-06-08 15:52:54 -07001427
Winson Chunga9abd0e2010-10-27 17:18:37 -07001428 public LauncherModel getModel() {
1429 return mModel;
1430 }
1431
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001432 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001433 getWindow().closeAllPanels();
1434
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001435 // Whatever we were doing is hereby canceled.
1436 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001437 }
1438
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001439 @Override
1440 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001441 long startTime = 0;
1442 if (DEBUG_RESUME_TIME) {
1443 startTime = System.currentTimeMillis();
1444 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001445 super.onNewIntent(intent);
1446
1447 // Close the menu
1448 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001449 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001450 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001451
Jamie Genniscb222e82012-10-23 15:44:26 -07001452 final boolean alreadyOnHome =
1453 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001454 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001455
Jamie Genniscb222e82012-10-23 15:44:26 -07001456 Runnable processIntent = new Runnable() {
1457 public void run() {
Michael Jurkaffc26822012-11-16 18:21:22 -08001458 if (mWorkspace == null) {
1459 // Can be cases where mWorkspace is null, this prevents a NPE
1460 return;
1461 }
Jamie Genniscb222e82012-10-23 15:44:26 -07001462 Folder openFolder = mWorkspace.getOpenFolder();
1463 // In all these cases, only animate if we're already on home
1464 mWorkspace.exitWidgetResizeMode();
1465 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1466 openFolder == null) {
1467 mWorkspace.moveToDefaultScreen(true);
1468 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001469
Jamie Genniscb222e82012-10-23 15:44:26 -07001470 closeFolder();
1471 exitSpringLoadedDragMode();
Winson Chung4a2afa32012-07-19 14:53:05 -07001472
Jamie Genniscb222e82012-10-23 15:44:26 -07001473 // If we are already on home, then just animate back to the workspace,
1474 // otherwise, just wait until onResume to set the state back to Workspace
1475 if (alreadyOnHome) {
1476 showWorkspace(true);
1477 } else {
1478 mOnResumeState = State.WORKSPACE;
1479 }
1480
1481 final View v = getWindow().peekDecorView();
1482 if (v != null && v.getWindowToken() != null) {
1483 InputMethodManager imm = (InputMethodManager)getSystemService(
1484 INPUT_METHOD_SERVICE);
1485 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1486 }
1487
1488 // Reset AllApps to its initial state
1489 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
1490 mAppsCustomizeTabHost.reset();
1491 }
1492 }
1493 };
1494
1495 if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
1496 // Delay processing of the intent to allow the status bar animation to finish
1497 // first in order to avoid janky animations.
1498 mWorkspace.postDelayed(processIntent, 350);
Winson Chung4a2afa32012-07-19 14:53:05 -07001499 } else {
Jamie Genniscb222e82012-10-23 15:44:26 -07001500 // Process the intent immediately.
1501 processIntent.run();
Winson Chung4a2afa32012-07-19 14:53:05 -07001502 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001503
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001504 }
Michael Jurka447bf842013-05-15 14:52:15 +02001505 if (DEBUG_RESUME_TIME) {
1506 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1507 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001508 }
1509
1510 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001511 public void onRestoreInstanceState(Bundle state) {
1512 super.onRestoreInstanceState(state);
1513 for (int page: mSynchronouslyBoundPages) {
1514 mWorkspace.restoreInstanceStateForChild(page);
1515 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001516 }
1517
1518 @Override
1519 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001520 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001521 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001522
Michael Jurka883f55b2010-10-21 15:47:14 -07001523 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001524 // We close any open folder since it will not be re-opened, and we need to make sure
1525 // this state is reflected.
1526 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001527
Winson Chung3d503fb2011-07-13 17:25:49 -07001528 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1529 mWaitingForResult) {
1530 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1531 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1532 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1533 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001534 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1535 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1536 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001537 }
1538
1539 if (mFolderInfo != null && mWaitingForResult) {
1540 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1541 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1542 }
Michael Jurka946ad472010-07-09 18:05:18 -07001543
Winson Chung785d2eb2011-04-14 16:08:02 -07001544 // Save the current AppsCustomize tab
1545 if (mAppsCustomizeTabHost != null) {
1546 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1547 if (currentTabTag != null) {
1548 outState.putString("apps_customize_currentTab", currentTabTag);
1549 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001550 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1551 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001552 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001553 }
1554
1555 @Override
1556 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001557 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001558
Winson Chunge7a03942011-08-05 15:05:12 -07001559 // Remove all pending runnables
1560 mHandler.removeMessages(ADVANCE_MSG);
1561 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001562 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001563
Winson Chungcd2b0142011-06-08 16:02:26 -07001564 // Stop callbacks from LauncherModel
1565 LauncherApplication app = ((LauncherApplication) getApplication());
1566 mModel.stopLoader();
1567 app.setLauncher(null);
1568
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001569 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001570 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001571 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001572 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001573 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001574 mAppWidgetHost = null;
1575
1576 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001577
1578 TextKeyListener.getInstance().release();
1579
Winson Chung81b52252012-08-27 15:34:29 -07001580 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1581 // to prevent leaking Launcher activities on orientation change.
1582 if (mModel != null) {
1583 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1584 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001585
1586 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001587 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001588
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001589 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001590 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1591 mWorkspace.removeAllViews();
1592 mWorkspace = null;
1593 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001594
Michael Jurka2ecf9952012-06-18 12:52:28 -07001595 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001596 }
1597
Adam Cohena9cf38f2011-05-02 15:36:58 -07001598 public DragController getDragController() {
1599 return mDragController;
1600 }
1601
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001602 @Override
1603 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001604 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001605 super.startActivityForResult(intent, requestCode);
1606 }
1607
Winson Chung70d72102011-08-12 11:24:35 -07001608 /**
1609 * Indicates that we want global search for this activity by setting the globalSearch
1610 * argument for {@link #startSearch} to true.
1611 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001612 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001613 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001614 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001615
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001616 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001617
Karl Rosaen138a0412009-04-23 19:00:21 -07001618 if (initialQuery == null) {
1619 // Use any text typed in the launcher as the initial query
1620 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001621 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001622 if (appSearchData == null) {
1623 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001624 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001625 }
Winson Chungadf0c182012-08-23 14:59:07 -07001626 Rect sourceBounds = new Rect();
1627 if (mSearchDropTargetBar != null) {
1628 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1629 }
Romain Guycbb89e42009-06-08 15:52:54 -07001630
Michael Jurkaa33411c2012-06-14 16:18:21 -07001631 startGlobalSearch(initialQuery, selectInitialQuery,
1632 appSearchData, sourceBounds);
1633 }
1634
1635 /**
1636 * Starts the global search activity. This code is a copied from SearchManager
1637 */
1638 public void startGlobalSearch(String initialQuery,
1639 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001640 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001641 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1642 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1643 if (globalSearchActivity == null) {
1644 Log.w(TAG, "No global search activity found.");
1645 return;
1646 }
1647 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1648 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1649 intent.setComponent(globalSearchActivity);
1650 // Make sure that we have a Bundle to put source in
1651 if (appSearchData == null) {
1652 appSearchData = new Bundle();
1653 } else {
1654 appSearchData = new Bundle(appSearchData);
1655 }
1656 // Set source to package name of app that starts global search, if not set already.
1657 if (!appSearchData.containsKey("source")) {
1658 appSearchData.putString("source", getPackageName());
1659 }
1660 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1661 if (!TextUtils.isEmpty(initialQuery)) {
1662 intent.putExtra(SearchManager.QUERY, initialQuery);
1663 }
1664 if (selectInitialQuery) {
1665 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1666 }
1667 intent.setSourceBounds(sourceBounds);
1668 try {
1669 startActivity(intent);
1670 } catch (ActivityNotFoundException ex) {
1671 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1672 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001673 }
1674
Winson Chung70d72102011-08-12 11:24:35 -07001675 @Override
1676 public boolean onCreateOptionsMenu(Menu menu) {
1677 if (isWorkspaceLocked()) {
1678 return false;
1679 }
1680
1681 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001682
1683 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1684 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1685 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001686 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1687 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1688 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001689 String helpUrl = getString(R.string.help_url);
1690 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001691 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1692 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1693
Winson Chung70d72102011-08-12 11:24:35 -07001694 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1695 .setIcon(android.R.drawable.ic_menu_gallery)
1696 .setAlphabeticShortcut('W');
1697 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1698 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001699 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001700 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001701 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1702 .setIcon(android.R.drawable.ic_menu_preferences)
1703 .setIntent(settings)
1704 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001705 if (!helpUrl.isEmpty()) {
1706 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1707 .setIcon(android.R.drawable.ic_menu_help)
1708 .setIntent(help)
1709 .setAlphabeticShortcut('H');
1710 }
Winson Chung70d72102011-08-12 11:24:35 -07001711 return true;
1712 }
1713
1714 @Override
1715 public boolean onPrepareOptionsMenu(Menu menu) {
1716 super.onPrepareOptionsMenu(menu);
1717
1718 if (mAppsCustomizeTabHost.isTransitioning()) {
1719 return false;
1720 }
1721 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1722 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1723
1724 return true;
1725 }
1726
1727 @Override
1728 public boolean onOptionsItemSelected(MenuItem item) {
1729 switch (item.getItemId()) {
1730 case MENU_WALLPAPER_SETTINGS:
1731 startWallpaper();
1732 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001733 }
1734
1735 return super.onOptionsItemSelected(item);
1736 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001737
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001738 @Override
1739 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001740 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001741 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001742 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001743 }
1744
Joe Onorato9c1289c2009-08-17 11:03:03 -04001745 public boolean isWorkspaceLocked() {
1746 return mWorkspaceLoading || mWaitingForResult;
1747 }
1748
Michael Jurka0280c3b2010-09-17 15:00:07 -07001749 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001750 mPendingAddInfo.container = ItemInfo.NO_ID;
1751 mPendingAddInfo.screen = -1;
1752 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1753 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001754 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001755 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001756 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001757
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001758 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1759 AppWidgetProviderInfo appWidgetInfo) {
1760 if (appWidgetInfo.configure != null) {
1761 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001762
Bjorn Bringert7984c942009-12-09 15:38:25 +00001763 // Launch over to configure widget, if needed
1764 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001765 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001766 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Romain Guy8e633c52010-03-04 12:51:36 -08001767 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001768 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001769 // Otherwise just add it
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001770 completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget,
1771 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001772 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001773 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001774 }
1775 }
Romain Guycbb89e42009-06-08 15:52:54 -07001776
Adam Cohenfbba09b2011-07-18 21:43:05 -07001777 /**
1778 * Process a shortcut drop.
1779 *
1780 * @param componentName The name of the component
1781 * @param screen The screen where it should be added
1782 * @param cell The cell it should be added to, optional
1783 * @param position The location on the screen where it was dropped, optional
1784 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001785 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1786 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001787 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001788 mPendingAddInfo.container = container;
1789 mPendingAddInfo.screen = screen;
1790 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001791
1792 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001793 mPendingAddInfo.cellX = cell[0];
1794 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001795 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001796
1797 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1798 createShortcutIntent.setComponent(componentName);
1799 processShortcut(createShortcutIntent);
1800 }
1801
Adam Cohenfbba09b2011-07-18 21:43:05 -07001802 /**
1803 * Process a widget drop.
1804 *
1805 * @param info The PendingAppWidgetInfo of the widget being added.
1806 * @param screen The screen where it should be added
1807 * @param cell The cell it should be added to, optional
1808 * @param position The location on the screen where it was dropped, optional
1809 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001810 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
Adam Cohend41fbf52012-02-16 23:53:59 -08001811 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001812 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001813 mPendingAddInfo.container = info.container = container;
1814 mPendingAddInfo.screen = info.screen = screen;
1815 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001816 mPendingAddInfo.minSpanX = info.minSpanX;
1817 mPendingAddInfo.minSpanY = info.minSpanY;
1818
Adam Cohenfbba09b2011-07-18 21:43:05 -07001819 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001820 mPendingAddInfo.cellX = cell[0];
1821 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001822 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001823 if (span != null) {
1824 mPendingAddInfo.spanX = span[0];
1825 mPendingAddInfo.spanY = span[1];
1826 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001827
Adam Cohened66b2b2012-01-23 17:28:51 -08001828 AppWidgetHostView hostView = info.boundWidget;
1829 int appWidgetId;
1830 if (hostView != null) {
1831 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001832 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001833 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001834 // In this case, we either need to start an activity to get permission to bind
1835 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001836 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07001837 Bundle options = info.bindOptions;
1838
1839 boolean success = false;
1840 if (options != null) {
1841 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1842 info.componentName, options);
1843 } else {
1844 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
1845 info.componentName);
1846 }
1847 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001848 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001849 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001850 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001851 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1852 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1853 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07001854 // TODO: we need to make sure that this accounts for the options bundle.
1855 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07001856 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1857 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001858 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001859 }
1860
Joe Onoratodeb98af2010-02-19 14:59:39 -08001861 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001862 // Handle case where user selected "Applications"
1863 String applicationName = getResources().getString(R.string.group_applications);
1864 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001865
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001866 if (applicationName != null && applicationName.equals(shortcutName)) {
1867 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1868 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001869
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001870 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1871 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001872 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001873 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001874 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001875 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001876 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001877 }
1878
Winson Chung24ab2f12010-09-16 14:10:47 -07001879 void processWallpaper(Intent intent) {
1880 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1881 }
1882
Winson Chung3d503fb2011-07-13 17:25:49 -07001883 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1884 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001885 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001886 folderInfo.title = getText(R.string.folder_name);
1887
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001888 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001889 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1890 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001891 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001892
1893 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001894 FolderIcon newFolder =
1895 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1896 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1897 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001898 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001899 }
Romain Guycbb89e42009-06-08 15:52:54 -07001900
Joe Onorato9c1289c2009-08-17 11:03:03 -04001901 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001902 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001903 }
1904
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001905 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001906 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001907 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001908 Intent chooser = Intent.createChooser(pickWallpaper,
1909 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001910 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1911 // Removed in Eclair MR1
1912// WallpaperManager wm = (WallpaperManager)
1913// getSystemService(Context.WALLPAPER_SERVICE);
1914// WallpaperInfo wi = wm.getWallpaperInfo();
1915// if (wi != null && wi.getSettingsActivity() != null) {
1916// LabeledIntent li = new LabeledIntent(getPackageName(),
1917// R.string.configure_wallpaper, 0);
1918// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1919// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1920// }
Mike Clerona0618e42009-10-22 13:55:21 -07001921 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001922 }
1923
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001924 /**
1925 * Registers various content observers. The current implementation registers
1926 * only a favorites observer to keep track of the favorites applications.
1927 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001928 private void registerContentObservers() {
1929 ContentResolver resolver = getContentResolver();
1930 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1931 true, mWidgetObserver);
1932 }
1933
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001934 @Override
1935 public boolean dispatchKeyEvent(KeyEvent event) {
1936 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1937 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001938 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001939 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001940 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08001941 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08001942 dumpState();
1943 return true;
1944 }
1945 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001946 }
1947 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1948 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001949 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001950 return true;
1951 }
1952 }
1953
1954 return super.dispatchKeyEvent(event);
1955 }
1956
Joe Onorato88ec0992009-11-19 13:16:06 -08001957 @Override
1958 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001959 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001960 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001961 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001962 Folder openFolder = mWorkspace.getOpenFolder();
1963 if (openFolder.isEditingName()) {
1964 openFolder.dismissEditingName();
1965 } else {
1966 closeFolder();
1967 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001968 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001969 mWorkspace.exitWidgetResizeMode();
1970
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001971 // Back button is a no-op here, but give at least some feedback for the button press
1972 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001973 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001974 }
1975
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001976 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001977 * Re-listen when widgets are reset.
1978 */
1979 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001980 if (mAppWidgetHost != null) {
1981 mAppWidgetHost.startListening();
1982 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001983 }
1984
1985 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001986 * Launches the intent referred by the clicked shortcut.
1987 *
1988 * @param v The view representing the clicked shortcut.
1989 */
1990 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001991 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1992 // view has detached (it's possible for this to happen if the view is removed mid touch).
1993 if (v.getWindowToken() == null) {
1994 return;
1995 }
1996
Winson Chung9b0b2fe2012-02-24 13:03:34 -08001997 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001998 return;
1999 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002000
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002001 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002002 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08002004 final Intent intent = ((ShortcutInfo) tag).intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002005
2006 ComponentName widgetComp = new ComponentName(this, WidgetAdder.class);
2007 if (intent.getComponent().getClassName().equals(widgetComp.getClassName())) {
2008 showAllApps(true);
2009 return;
2010 }
Joe Onorato13724ea2009-12-02 21:16:35 -08002011 int[] pos = new int[2];
2012 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002013 intent.setSourceBounds(new Rect(pos[0], pos[1],
2014 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002015
2016 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002017
2018 if (success && v instanceof BubbleTextView) {
2019 mWaitingForResume = (BubbleTextView) v;
2020 mWaitingForResume.setStayPressed(true);
2021 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002022 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002023 if (v instanceof FolderIcon) {
2024 FolderIcon fi = (FolderIcon) v;
2025 handleFolderClick(fi);
2026 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002027 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002028 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002029 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002030 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002031 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002032 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002033 }
2034 }
2035
Michael Jurka0e260592010-06-30 17:07:39 -07002036 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07002037 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002038 // clicking anywhere on the workspace causes the customization drawer to slide down
2039 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07002040 return false;
2041 }
2042
Michael Jurkaaf442092010-06-10 17:01:57 -07002043 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002044 * Event handler for the search button
2045 *
2046 * @param v The view that was clicked.
2047 */
2048 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002049 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2050
Amith Yamasania135ba82011-08-09 17:42:01 -07002051 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002052 }
2053
2054 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002055 * Event handler for the voice button
2056 *
2057 * @param v The view that was clicked.
2058 */
2059 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002060 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002061
Michael Jurkaae65ee32012-04-30 11:45:54 -07002062 try {
2063 final SearchManager searchManager =
2064 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2065 ComponentName activityName = searchManager.getGlobalSearchActivity();
2066 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002067 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002068 if (activityName != null) {
2069 intent.setPackage(activityName.getPackageName());
2070 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002071 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002072 } catch (ActivityNotFoundException e) {
2073 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002074 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002075 startActivitySafely(null, intent, "onClickVoiceButton");
2076 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002077 }
2078
2079 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002080 * Event handler for the "grid" button that appears on the home screen, which
2081 * enters all apps mode.
2082 *
2083 * @param v The view that was clicked.
2084 */
2085 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07002086 showAllApps(true);
2087 }
2088
2089 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002090 // Provide the same haptic feedback that the system offers for virtual keys.
2091 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002092 }
2093
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002094 public void onClickAppMarketButton(View v) {
2095 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07002096 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07002097 } else {
2098 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002099 }
2100 }
2101
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002102 void startApplicationDetailsActivity(ComponentName componentName) {
2103 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002104 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2105 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002106 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002107 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002108 }
2109
Patrick Dubroy5539af72010-09-07 15:22:01 -07002110 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
2111 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
2112 // System applications cannot be installed. For now, show a toast explaining that.
2113 // We may give them the option of disabling apps this way.
2114 int messageId = R.string.uninstall_system_app_text;
2115 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
2116 } else {
2117 String packageName = appInfo.componentName.getPackageName();
2118 String className = appInfo.componentName.getClassName();
2119 Intent intent = new Intent(
2120 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002121 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2122 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002123 startActivity(intent);
2124 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002125 }
2126
Michael Jurka86a720e2012-05-09 11:23:23 -07002127 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002128 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002129
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002130 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002131 // Only launch using the new animation if the shortcut has not opted out (this is a
2132 // private contract between launcher and may be ignored in the future).
2133 boolean useLaunchAnimation = (v != null) &&
2134 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2135 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002136 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2137 v.getMeasuredWidth(), v.getMeasuredHeight());
2138
2139 startActivity(intent, opts.toBundle());
2140 } else {
2141 startActivity(intent);
2142 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002143 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002144 } catch (SecurityException e) {
2145 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002146 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002147 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002148 "or use the exported attribute for this activity. "
2149 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002150 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002151 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002152 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002153
Michael Jurka86a720e2012-05-09 11:23:23 -07002154 boolean startActivitySafely(View v, Intent intent, Object tag) {
2155 boolean success = false;
2156 try {
2157 success = startActivity(v, intent, tag);
2158 } catch (ActivityNotFoundException e) {
2159 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2160 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2161 }
2162 return success;
2163 }
2164
Romain Guy8e633c52010-03-04 12:51:36 -08002165 void startActivityForResultSafely(Intent intent, int requestCode) {
2166 try {
2167 startActivityForResult(intent, requestCode);
2168 } catch (ActivityNotFoundException e) {
2169 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2170 } catch (SecurityException e) {
2171 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2172 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2173 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2174 "or use the exported attribute for this activity.", e);
2175 }
2176 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002177
Adam Cohena9cf38f2011-05-02 15:36:58 -07002178 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002179 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002180 Folder openFolder = mWorkspace.getFolderForTag(info);
2181
2182 // If the folder info reports that the associated folder is open, then verify that
2183 // it is actually opened. There have been a few instances where this gets out of sync.
2184 if (info.opened && openFolder == null) {
2185 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2186 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
2187 info.opened = false;
2188 }
2189
Adam Cohenfb91f302012-06-11 15:45:18 -07002190 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002191 // Close any open folder
2192 closeFolder();
2193 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002194 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002195 } else {
2196 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002197 int folderScreen;
2198 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002199 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002200 // .. and close it
2201 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002202 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002203 // Close any folder open on the current screen
2204 closeFolder();
2205 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002206 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002207 }
2208 }
2209 }
2210 }
2211
Adam Cohen268c4752012-06-06 17:47:33 -07002212 /**
2213 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2214 * in the DragLayer in the exact absolute location of the original FolderIcon.
2215 */
2216 private void copyFolderIconToImage(FolderIcon fi) {
2217 final int width = fi.getMeasuredWidth();
2218 final int height = fi.getMeasuredHeight();
2219
2220 // Lazy load ImageView, Bitmap and Canvas
2221 if (mFolderIconImageView == null) {
2222 mFolderIconImageView = new ImageView(this);
2223 }
2224 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2225 mFolderIconBitmap.getHeight() != height) {
2226 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2227 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2228 }
2229
2230 DragLayer.LayoutParams lp;
2231 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2232 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2233 } else {
2234 lp = new DragLayer.LayoutParams(width, height);
2235 }
2236
Adam Cohen307fe232012-08-16 17:55:58 -07002237 // The layout from which the folder is being opened may be scaled, adjust the starting
2238 // view size by this scale factor.
2239 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002240 lp.customPosition = true;
2241 lp.x = mRectForFolderAnimation.left;
2242 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002243 lp.width = (int) (scale * width);
2244 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002245
2246 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2247 fi.draw(mFolderIconCanvas);
2248 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002249 if (fi.getFolder() != null) {
2250 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2251 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002252 }
Adam Cohen268c4752012-06-06 17:47:33 -07002253 // Just in case this image view is still in the drag layer from a previous animation,
2254 // we remove it and re-add it.
2255 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2256 mDragLayer.removeView(mFolderIconImageView);
2257 }
2258 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002259 if (fi.getFolder() != null) {
2260 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002261 }
Adam Cohen268c4752012-06-06 17:47:33 -07002262 }
2263
Adam Cohen2801caf2011-05-13 20:57:39 -07002264 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002265 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002266 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2267 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2268 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2269
Adam Cohenc51934b2011-07-26 21:07:43 -07002270 FolderInfo info = (FolderInfo) fi.getTag();
2271 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2272 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002273 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2274 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002275 }
2276
Adam Cohen268c4752012-06-06 17:47:33 -07002277 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2278 copyFolderIconToImage(fi);
2279 fi.setVisibility(View.INVISIBLE);
2280
Michael Jurka2ecf9952012-06-18 12:52:28 -07002281 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002282 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002283 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2284 oa.start();
2285 }
2286
Adam Cohen268c4752012-06-06 17:47:33 -07002287 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002288 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002289 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2290 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2291 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2292
Adam Cohen268c4752012-06-06 17:47:33 -07002293 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002294
Adam Cohen268c4752012-06-06 17:47:33 -07002295 // We remove and re-draw the FolderIcon in-case it has changed
2296 mDragLayer.removeView(mFolderIconImageView);
2297 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002298 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002299 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002300 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002301 oa.addListener(new AnimatorListenerAdapter() {
2302 @Override
2303 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002304 if (cl != null) {
2305 cl.clearFolderLeaveBehind();
2306 // Remove the ImageView copy of the FolderIcon and make the original visible.
2307 mDragLayer.removeView(mFolderIconImageView);
2308 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002309 }
2310 }
2311 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002312 oa.start();
2313 }
2314
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002315 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002316 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002317 * is animated relative to the specified View. If the View is null, no animation
2318 * is played.
2319 *
2320 * @param folderInfo The FolderInfo describing the folder to open.
2321 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002322 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002323 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002324 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002325
Adam Cohena9cf38f2011-05-02 15:36:58 -07002326 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002327
Adam Cohen4554ee12011-08-03 16:13:21 -07002328 // Just verify that the folder hasn't already been added to the DragLayer.
2329 // There was a one-off crash where the folder had a parent already.
2330 if (folder.getParent() == null) {
2331 mDragLayer.addView(folder);
2332 mDragController.addDropTarget((DropTarget) folder);
2333 } else {
2334 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2335 folder.getParent() + ").");
2336 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002337 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002338 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002339
2340 // Notify the accessibility manager that this folder "window" has appeared and occluded
2341 // the workspace items
2342 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2343 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002344 }
2345
2346 public void closeFolder() {
2347 Folder folder = mWorkspace.getOpenFolder();
2348 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002349 if (folder.isEditingName()) {
2350 folder.dismissEditingName();
2351 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002352 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002353
2354 // Dismiss the folder cling
2355 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002356 }
2357 }
2358
2359 void closeFolder(Folder folder) {
2360 folder.getInfo().opened = false;
2361
2362 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2363 if (parent != null) {
2364 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2365 shrinkAndFadeInFolderIcon(fi);
2366 }
2367 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002368
2369 // Notify the accessibility manager that this folder "window" has disappeard and no
2370 // longer occludeds the workspace items
2371 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002372 }
2373
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002374 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002375 if (!isDraggingEnabled()) return false;
2376 if (isWorkspaceLocked()) return false;
2377 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002378
2379 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002380 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002381 }
2382
Michael Jurka0280c3b2010-09-17 15:00:07 -07002383 resetAddInfo();
2384 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002385 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002386 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002387 return true;
2388 }
2389
Winson Chung3d503fb2011-07-13 17:25:49 -07002390 // The hotseat touch handling does not go through Workspace, and we always allow long press
2391 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002392 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002393 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2394 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002395 if (itemUnderLongClick == null) {
2396 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002397 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2398 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002399 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002400 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002401 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002402 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002403 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002404 }
2405 }
2406 }
2407 return true;
2408 }
2409
Winson Chung3d503fb2011-07-13 17:25:49 -07002410 boolean isHotseatLayout(View layout) {
2411 return mHotseat != null && layout != null &&
2412 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2413 }
2414 Hotseat getHotseat() {
2415 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002416 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002417 SearchDropTargetBar getSearchBar() {
2418 return mSearchDropTargetBar;
2419 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002420
Winson Chung3d503fb2011-07-13 17:25:49 -07002421 /**
2422 * Returns the CellLayout of the specified container at the specified screen.
2423 */
2424 CellLayout getCellLayout(long container, int screen) {
2425 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2426 if (mHotseat != null) {
2427 return mHotseat.getLayout();
2428 } else {
2429 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002430 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002431 } else {
2432 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002433 }
2434 }
2435
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002436 Workspace getWorkspace() {
2437 return mWorkspace;
2438 }
2439
Daniel Sandler843e8602010-06-07 14:59:01 -04002440 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
Craig Mautner360310b2012-10-26 15:13:08 -07002441 @Override
Daniel Sandler843e8602010-06-07 14:59:01 -04002442 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002443 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002444 }
2445
Craig Mautner360310b2012-10-26 15:13:08 -07002446 @Override
Andrew Flynn0dca1ec2012-02-29 13:33:22 -08002447 public boolean isAllAppsButtonRank(int rank) {
2448 return mHotseat.isAllAppsButtonRank(rank);
2449 }
2450
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002451 /**
2452 * Helper method for the cameraZoomIn/cameraZoomOut animations
2453 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002454 * @param scaleFactor The scale factor used for the zoom
2455 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002456 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002457 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002458 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002459 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002460
Winson Chung18f41f82012-05-09 13:28:10 -07002461 void disableWallpaperIfInAllApps() {
2462 // Only disable it if we are in all apps
Winson Chungc93e5ae2012-07-23 20:48:26 -07002463 if (isAllAppsVisible()) {
Winson Chung18f41f82012-05-09 13:28:10 -07002464 if (mAppsCustomizeTabHost != null &&
2465 !mAppsCustomizeTabHost.isTransitioning()) {
2466 updateWallpaperVisibility(false);
2467 }
2468 }
2469 }
2470
Craig Mautner360310b2012-10-26 15:13:08 -07002471 private void setWorkspaceBackground(boolean workspace) {
2472 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002473 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002474 }
2475
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002476 void updateWallpaperVisibility(boolean visible) {
2477 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2478 int curflags = getWindow().getAttributes().flags
2479 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2480 if (wpflags != curflags) {
2481 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2482 }
Craig Mautner360310b2012-10-26 15:13:08 -07002483 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002484 }
2485
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002486 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2487 if (v instanceof LauncherTransitionable) {
2488 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2489 }
2490 }
2491
Michael Jurkabed61d22012-02-14 22:51:29 -08002492 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2493 if (v instanceof LauncherTransitionable) {
2494 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2495 }
Winson Chung70442722012-02-10 15:43:22 -08002496
2497 // Update the workspace transition step as well
2498 dispatchOnLauncherTransitionStep(v, 0f);
2499 }
2500
2501 private void dispatchOnLauncherTransitionStep(View v, float t) {
2502 if (v instanceof LauncherTransitionable) {
2503 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2504 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002505 }
2506
2507 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2508 if (v instanceof LauncherTransitionable) {
2509 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2510 }
Winson Chung70442722012-02-10 15:43:22 -08002511
2512 // Update the workspace transition step as well
2513 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002514 }
2515
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002516 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002517 * Things to test when changing the following seven functions.
2518 * - Home from workspace
2519 * - from center screen
2520 * - from other screens
2521 * - Home from all apps
2522 * - from center screen
2523 * - from other screens
2524 * - Back from all apps
2525 * - from center screen
2526 * - from other screens
2527 * - Launch app from workspace and quit
2528 * - with back
2529 * - with home
2530 * - Launch app from all apps and quit
2531 * - with back
2532 * - with home
2533 * - Go to a screen that's not the default, then all
2534 * apps, and launch and app, and go back
2535 * - with back
2536 * -with home
2537 * - On workspace, long press power and go back
2538 * - with back
2539 * - with home
2540 * - On all apps, long press power and go back
2541 * - with back
2542 * - with home
2543 * - On workspace, power off
2544 * - On all apps, power off
2545 * - Launch an app and turn off the screen while in that app
2546 * - Go back with home key
2547 * - Go back with back key TODO: make this not go to workspace
2548 * - From all apps
2549 * - From workspace
2550 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2551 * - From all apps
2552 * - From the center workspace
2553 * - From another workspace
2554 */
2555
2556 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002557 * Zoom the camera out from the workspace to reveal 'toView'.
2558 * Assumes that the view to show is anchored at either the very top or very bottom
2559 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002560 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002561 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002562 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002563 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002564 mStateAnimation.cancel();
2565 mStateAnimation = null;
2566 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002567 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002568
Winson Chungf0ea4d32011-06-06 14:27:16 -07002569 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2570 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2571 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002572 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002573 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002574 final int startDelay =
2575 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002576
Michael Jurkab3e22d92011-10-31 15:58:33 -07002577 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002578
Michael Jurkad74c9842011-07-10 12:44:21 -07002579 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002580 Animator workspaceAnim =
2581 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002582
2583 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002584 toView.setScaleX(scale);
2585 toView.setScaleY(scale);
2586 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2587 scaleAnim.
2588 scaleX(1f).scaleY(1f).
2589 setDuration(duration).
2590 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002591
Winson Chungf0ea4d32011-06-06 14:27:16 -07002592 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002593 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002594 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002595 .ofFloat(toView, "alpha", 0f, 1f)
2596 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002597 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002598 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2599 @Override
2600 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002601 if (animation == null) {
2602 throw new RuntimeException("animation is null");
2603 }
Winson Chung70442722012-02-10 15:43:22 -08002604 float t = (Float) animation.getAnimatedValue();
2605 dispatchOnLauncherTransitionStep(fromView, t);
2606 dispatchOnLauncherTransitionStep(toView, t);
2607 }
2608 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002609
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002610 // toView should appear right at the end of the workspace shrink
2611 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002612 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002613 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002614 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002615
2616 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002617 boolean animationCancelled = false;
2618
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002619 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002620 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002621 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002622 // Prepare the position
2623 toView.setTranslationX(0.0f);
2624 toView.setTranslationY(0.0f);
2625 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002626 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002627 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002628 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002629 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002630 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2631 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002632
Michael Jurkafa7969f2012-09-21 16:39:14 -07002633 if (mWorkspace != null && !springLoaded && !LauncherApplication.isScreenLarge()) {
Winson Chung32174c82011-07-19 15:47:55 -07002634 // Hide the workspace scrollbar
2635 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002636 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002637 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002638 if (!animationCancelled) {
2639 updateWallpaperVisibility(false);
2640 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002641
2642 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002643 if (mSearchDropTargetBar != null) {
2644 mSearchDropTargetBar.hideSearchBar(false);
2645 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002646 }
2647
Adam Cohencff6af82011-09-13 14:51:53 -07002648 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002649 public void onAnimationCancel(Animator animation) {
2650 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002651 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002652 });
2653
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002654 if (workspaceAnim != null) {
2655 mStateAnimation.play(workspaceAnim);
2656 }
Michael Jurka1899a362011-11-03 13:50:45 -07002657
2658 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002659
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002660 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2661 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002662
2663 // If any of the objects being animated haven't been measured/laid out
2664 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002665 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002666 (mWorkspace.getMeasuredWidth() == 0) ||
2667 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002668 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002669 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002670
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002671 final AnimatorSet stateAnimation = mStateAnimation;
2672 final Runnable startAnimRunnable = new Runnable() {
2673 public void run() {
2674 // Check that mStateAnimation hasn't changed while
2675 // we waited for a layout/draw pass
2676 if (mStateAnimation != stateAnimation)
2677 return;
2678 setPivotsForZoom(toView, scale);
2679 dispatchOnLauncherTransitionStart(fromView, animated, false);
2680 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002681 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002682 }
2683 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002684 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002685 final ViewTreeObserver observer = toView.getViewTreeObserver();
2686 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2687 public void onGlobalLayout() {
2688 startAnimRunnable.run();
2689 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2690 }
2691 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002692 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002693 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002694 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002695 } else {
2696 toView.setTranslationX(0.0f);
2697 toView.setTranslationY(0.0f);
2698 toView.setScaleX(1.0f);
2699 toView.setScaleY(1.0f);
2700 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002701 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002702
Michael Jurkabed61d22012-02-14 22:51:29 -08002703 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2704 // Hide the workspace scrollbar
2705 mWorkspace.hideScrollingIndicator(true);
2706 hideDockDivider();
Winson Chungc7d2b602012-05-16 17:02:20 -07002707
2708 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002709 if (mSearchDropTargetBar != null) {
2710 mSearchDropTargetBar.hideSearchBar(false);
2711 }
Michael Jurkaabded662011-03-04 12:06:57 -08002712 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002713 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002714 dispatchOnLauncherTransitionStart(fromView, animated, false);
2715 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002716 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002717 dispatchOnLauncherTransitionStart(toView, animated, false);
2718 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002719 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002720 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002721 }
2722
2723 /**
2724 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002725 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002726 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002727 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002728 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2729 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002730
Michael Jurkab3e22d92011-10-31 15:58:33 -07002731 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002732 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002733 mStateAnimation.cancel();
2734 mStateAnimation = null;
2735 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002736 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002737
Winson Chungf0ea4d32011-06-06 14:27:16 -07002738 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002739 final int fadeOutDuration =
2740 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002741 final float scaleFactor = (float)
2742 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2743 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002744 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002745 Animator workspaceAnim = null;
2746
2747 if (toState == State.WORKSPACE) {
2748 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2749 workspaceAnim = mWorkspace.getChangeStateAnimation(
2750 Workspace.State.NORMAL, animated, stagger);
2751 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2752 workspaceAnim = mWorkspace.getChangeStateAnimation(
2753 Workspace.State.SPRING_LOADED, animated);
2754 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002755
Michael Jurkab3e22d92011-10-31 15:58:33 -07002756 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002757 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002758 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002759 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002760 final LauncherViewPropertyAnimator scaleAnim =
2761 new LauncherViewPropertyAnimator(fromView);
2762 scaleAnim.
2763 scaleX(scaleFactor).scaleY(scaleFactor).
2764 setDuration(duration).
2765 setInterpolator(new Workspace.ZoomInInterpolator());
2766
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002767 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002768 .ofFloat(fromView, "alpha", 1f, 0f)
2769 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002770 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002771 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2772 @Override
2773 public void onAnimationUpdate(ValueAnimator animation) {
2774 float t = 1f - (Float) animation.getAnimatedValue();
2775 dispatchOnLauncherTransitionStep(fromView, t);
2776 dispatchOnLauncherTransitionStep(toView, t);
2777 }
2778 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002779
Michael Jurka2ecf9952012-06-18 12:52:28 -07002780 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002781
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002782 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2783 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002784 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08002785
2786 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002787 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002788 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002789 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002790 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002791 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2792 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkabafdaaf2012-04-26 13:43:25 -07002793 if (mWorkspace != null) {
2794 mWorkspace.hideScrollingIndicator(false);
2795 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002796 if (onCompleteRunnable != null) {
2797 onCompleteRunnable.run();
2798 }
Chet Haasebc2f0822012-10-26 17:59:53 -07002799 mAppsCustomizeContent.updateCurrentPageScroll();
2800 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002801 }
2802 });
2803
Winson Chungf0ea4d32011-06-06 14:27:16 -07002804 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002805 if (workspaceAnim != null) {
2806 mStateAnimation.play(workspaceAnim);
2807 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002808 dispatchOnLauncherTransitionStart(fromView, animated, true);
2809 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002810 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002811 } else {
2812 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002813 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002814 dispatchOnLauncherTransitionStart(fromView, animated, true);
2815 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002816 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002817 dispatchOnLauncherTransitionStart(toView, animated, true);
2818 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002819 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002820 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002821 }
2822
Michael Jurkae326f182011-11-21 14:05:46 -08002823 @Override
2824 public void onTrimMemory(int level) {
2825 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002826 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002827 mAppsCustomizeTabHost.onTrimMemory();
2828 }
2829 }
2830
Winson Chung18f41f82012-05-09 13:28:10 -07002831 @Override
2832 public void onWindowFocusChanged(boolean hasFocus) {
2833 if (!hasFocus) {
2834 // When another window occludes launcher (like the notification shade, or recents),
2835 // ensure that we enable the wallpaper flag so that transitions are done correctly.
2836 updateWallpaperVisibility(true);
2837 } else {
2838 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07002839 mWorkspace.postDelayed(new Runnable() {
2840 @Override
2841 public void run() {
2842 disableWallpaperIfInAllApps();
2843 }
2844 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07002845 }
2846 }
2847
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002848 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002849 showWorkspace(animated, null);
2850 }
2851
2852 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002853 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002854 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002855 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002856 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002857
Winson Chungc7d2b602012-05-16 17:02:20 -07002858 // Show the search bar (only animate if we were showing the drop target bar in spring
2859 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07002860 if (mSearchDropTargetBar != null) {
2861 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
2862 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002863
Michael Jurkab737ee62011-11-15 15:57:22 -08002864 // We only need to animate in the dock divider if we're going from spring loaded mode
Winson Chungc7d2b602012-05-16 17:02:20 -07002865 showDockDivider(animated && wasInSpringLoadedMode);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002866
2867 // Set focus to the AppsCustomize button
2868 if (mAllAppsButton != null) {
2869 mAllAppsButton.requestFocus();
2870 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002871 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002872
Michael Jurkab737ee62011-11-15 15:57:22 -08002873 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002874
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002875 // Change the state *after* we've called all the transition code
2876 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002877
Winson Chung5fb63472011-02-02 17:03:37 -08002878 // Resume the auto-advance of widgets
2879 mUserPresent = true;
2880 updateRunning();
2881
alanv1d4fde62012-10-17 13:15:47 -07002882 // Send an accessibility event to announce the context change
2883 getWindow().getDecorView()
2884 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Joe Onorato00acb122009-08-04 16:04:30 -04002885 }
2886
Michael Jurkab3e22d92011-10-31 15:58:33 -07002887 void showAllApps(boolean animated) {
2888 if (mState != State.WORKSPACE) return;
2889
2890 showAppsCustomizeHelper(animated, false);
2891 mAppsCustomizeTabHost.requestFocus();
2892
Michael Jurkab3e22d92011-10-31 15:58:33 -07002893 // Change the state *after* we've called all the transition code
2894 mState = State.APPS_CUSTOMIZE;
2895
2896 // Pause the auto-advance of widgets until we are out of AllApps
2897 mUserPresent = false;
2898 updateRunning();
2899 closeFolder();
2900
2901 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07002902 getWindow().getDecorView()
2903 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002904 }
2905
Adam Cohen7777d962011-08-18 18:58:38 -07002906 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002907 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002908 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002909 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002910 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002911 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002912 }
Adam Cohen7777d962011-08-18 18:58:38 -07002913
Adam Cohened66b2b2012-01-23 17:28:51 -08002914 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2915 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002916 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2917
Winson Chunge7a03942011-08-05 15:05:12 -07002918 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002919 @Override
2920 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002921 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002922 // Before we show workspace, hide all apps again because
2923 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2924 // clean up our state transition functions
2925 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002926 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002927 } else {
2928 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002929 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002930 }
2931 }, (extendedDelay ?
2932 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2933 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2934 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002935
Michael Jurkad3ef3062010-11-23 16:23:58 -08002936 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002937 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002938 final boolean animated = true;
2939 final boolean springLoaded = true;
2940 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002941 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002942 }
2943 // Otherwise, we are not in spring loaded mode, so don't do anything.
2944 }
2945
Michael Jurkab737ee62011-11-15 15:57:22 -08002946 void hideDockDivider() {
2947 if (mQsbDivider != null && mDockDivider != null) {
2948 mQsbDivider.setVisibility(View.INVISIBLE);
2949 mDockDivider.setVisibility(View.INVISIBLE);
2950 }
2951 }
2952
2953 void showDockDivider(boolean animated) {
2954 if (mQsbDivider != null && mDockDivider != null) {
2955 mQsbDivider.setVisibility(View.VISIBLE);
2956 mDockDivider.setVisibility(View.VISIBLE);
2957 if (mDividerAnimator != null) {
2958 mDividerAnimator.cancel();
2959 mQsbDivider.setAlpha(1f);
2960 mDockDivider.setAlpha(1f);
2961 mDividerAnimator = null;
2962 }
2963 if (animated) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07002964 mDividerAnimator = LauncherAnimUtils.createAnimatorSet();
2965 mDividerAnimator.playTogether(LauncherAnimUtils.ofFloat(mQsbDivider, "alpha", 1f),
2966 LauncherAnimUtils.ofFloat(mDockDivider, "alpha", 1f));
Winson Chungadf0c182012-08-23 14:59:07 -07002967 int duration = 0;
2968 if (mSearchDropTargetBar != null) {
2969 duration = mSearchDropTargetBar.getTransitionInDuration();
2970 }
2971 mDividerAnimator.setDuration(duration);
Michael Jurkab737ee62011-11-15 15:57:22 -08002972 mDividerAnimator.start();
2973 }
2974 }
2975 }
2976
Michael Jurkab3e22d92011-10-31 15:58:33 -07002977 void lockAllApps() {
2978 // TODO
2979 }
2980
2981 void unlockAllApps() {
2982 // TODO
2983 }
2984
Winson Chungf0ea4d32011-06-06 14:27:16 -07002985 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002986 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002987 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002988 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002989 if (!LauncherApplication.isScreenLarge()) {
2990 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002991 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07002992 int duration = 0;
2993 if (mSearchDropTargetBar != null) {
2994 duration = mSearchDropTargetBar.getTransitionInDuration();
2995 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08002996 mHotseat.animate().alpha(1f).setDuration(duration);
2997 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002998 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002999 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003000 }
3001 }
3002 }
3003
3004 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003005 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003006 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003007 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003008 if (!LauncherApplication.isScreenLarge()) {
3009 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003010 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003011 int duration = 0;
3012 if (mSearchDropTargetBar != null) {
3013 duration = mSearchDropTargetBar.getTransitionOutDuration();
3014 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003015 mHotseat.animate().alpha(0f).setDuration(duration);
3016 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003017 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003018 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003019 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003020 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003021 }
3022
Patrick Dubroy5f445422011-02-18 14:35:21 -08003023 /**
3024 * Add an item from all apps or customize onto the given workspace screen.
3025 * If layout is null, add to the current screen.
3026 */
3027 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003028 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003029 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003030 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003031 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003032
Winson Chungdff8ebb2011-09-08 17:25:31 -07003033 /** Maps the current orientation to an index for referencing orientation correct global icons */
3034 private int getCurrentOrientationIndexForGlobalIcons() {
3035 // default - 0, landscape - 1
3036 switch (getResources().getConfiguration().orientation) {
3037 case Configuration.ORIENTATION_LANDSCAPE:
3038 return 1;
3039 default:
3040 return 0;
3041 }
3042 }
3043
Michael Jurkaae65ee32012-04-30 11:45:54 -07003044 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003045 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003046 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003047 // Look for the toolbar icon specified in the activity meta-data
3048 Bundle metaData = packageManager.getActivityInfo(
3049 activityName, PackageManager.GET_META_DATA).metaData;
3050 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003051 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003052 if (iconResId != 0) {
3053 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003054 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003055 }
3056 }
3057 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003058 // This can happen if the activity defines an invalid drawable
3059 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3060 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003061 } catch (Resources.NotFoundException nfe) {
3062 // This can happen if the activity defines an invalid drawable
3063 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3064 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003065 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003066 return null;
3067 }
3068
3069 // if successful in getting icon, return it; otherwise, set button to use default drawable
3070 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003071 int buttonId, ComponentName activityName, int fallbackDrawableId,
3072 String toolbarResourceName) {
3073 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003074 Resources r = getResources();
3075 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3076 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003077
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003078 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003079 // If we were unable to find the icon via the meta-data, use a generic one
3080 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003081 toolbarIcon = r.getDrawable(fallbackDrawableId);
3082 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003083 if (button != null) {
3084 button.setCompoundDrawables(toolbarIcon, null, null, null);
3085 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003086 return null;
3087 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003088 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003089 if (button != null) {
3090 button.setCompoundDrawables(toolbarIcon, null, null, null);
3091 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003092 return toolbarIcon.getConstantState();
3093 }
3094 }
3095
3096 // if successful in getting icon, return it; otherwise, set button to use default drawable
3097 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003098 int buttonId, ComponentName activityName, int fallbackDrawableId,
3099 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003100 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003101 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003102
Michael Jurka19e0fc52011-07-22 18:00:21 -07003103 if (button != null) {
3104 // If we were unable to find the icon via the meta-data, use a
3105 // generic one
3106 if (toolbarIcon == null) {
3107 button.setImageResource(fallbackDrawableId);
3108 } else {
3109 button.setImageDrawable(toolbarIcon);
3110 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003111 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003112
3113 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3114
Michael Jurka0423dcf2010-10-05 14:56:18 -07003115 }
3116
Winson Chung1b884092012-06-08 17:13:02 -07003117 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003118 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003119 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003120 }
3121
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003122 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003123 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003124 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003125 }
3126
Winson Chungbb185bd2011-11-21 12:31:42 -08003127 private void invalidatePressedFocusedStates(View container, View button) {
3128 if (container instanceof HolographicLinearLayout) {
3129 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3130 layout.invalidatePressedFocusedStates();
3131 } else if (button instanceof HolographicImageView) {
3132 HolographicImageView view = (HolographicImageView) button;
3133 view.invalidatePressedFocusedStates();
3134 }
3135 }
3136
Winson Chungc51db6a2011-10-05 11:44:49 -07003137 private boolean updateGlobalSearchIcon() {
3138 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003139 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003140 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003141 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07003142 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07003143
Winson Chung1cad91e2011-05-25 17:41:01 -07003144 final SearchManager searchManager =
3145 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3146 ComponentName activityName = searchManager.getGlobalSearchActivity();
3147 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003148 int coi = getCurrentOrientationIndexForGlobalIcons();
3149 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003150 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3151 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3152 if (sGlobalSearchIcon[coi] == null) {
3153 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3154 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3155 TOOLBAR_ICON_METADATA_NAME);
3156 }
3157
Winson Chungc51db6a2011-10-05 11:44:49 -07003158 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3159 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003160 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003161 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003162 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003163 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003164 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3165 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
3166 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003167 voiceButton.setVisibility(View.GONE);
Michael Jurkac60498a2012-05-07 15:29:42 -07003168 if (voiceButtonProxy != null) {
3169 voiceButtonProxy.setVisibility(View.GONE);
3170 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003171 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003172 }
3173 }
3174
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003175 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003176 final View searchButtonContainer = findViewById(R.id.search_button_container);
3177 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003178 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003179 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003180 }
3181
Winson Chungc51db6a2011-10-05 11:44:49 -07003182 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003183 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003184 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07003185 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07003186
Winson Chungc51db6a2011-10-05 11:44:49 -07003187 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003188 final SearchManager searchManager =
3189 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3190 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3191
3192 ComponentName activityName = null;
3193 if (globalSearchActivity != null) {
3194 // Check if the global search activity handles voice search
3195 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3196 intent.setPackage(globalSearchActivity.getPackageName());
3197 activityName = intent.resolveActivity(getPackageManager());
3198 }
3199
3200 if (activityName == null) {
3201 // Fallback: check if an activity other than the global search activity
3202 // resolves this
3203 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3204 activityName = intent.resolveActivity(getPackageManager());
3205 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003206 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003207 int coi = getCurrentOrientationIndexForGlobalIcons();
3208 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003209 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3210 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3211 if (sVoiceSearchIcon[coi] == null) {
3212 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3213 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3214 TOOLBAR_ICON_METADATA_NAME);
3215 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003216 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003217 voiceButton.setVisibility(View.VISIBLE);
Jim Miller14091b12012-04-24 19:27:54 -07003218 if (voiceButtonProxy != null) {
3219 voiceButtonProxy.setVisibility(View.VISIBLE);
3220 }
Winson Chungbb185bd2011-11-21 12:31:42 -08003221 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003222 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003223 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003224 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003225 voiceButton.setVisibility(View.GONE);
Jim Miller14091b12012-04-24 19:27:54 -07003226 if (voiceButtonProxy != null) {
3227 voiceButtonProxy.setVisibility(View.GONE);
3228 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003229 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003230 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003231 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003232
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003233 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003234 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3235 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003236 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003237 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003238 }
3239
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003240 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003241 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003242 */
3243 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003244 final View marketButton = findViewById(R.id.market_button);
3245 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3246 // Find the app market activity by resolving an intent.
3247 // (If multiple app markets are installed, it will return the ResolverActivity.)
3248 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003249 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003250 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003251 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003252 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003253 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3254 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003255 marketButton.setVisibility(View.VISIBLE);
3256 } else {
3257 // We should hide and disable the view so that we don't try and restore the visibility
3258 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3259 marketButton.setVisibility(View.GONE);
3260 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003261 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003262 }
3263
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003264 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003265 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3266 Resources r = getResources();
3267 Drawable marketIconDrawable = d.newDrawable(r);
3268 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3269 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3270 marketIconDrawable.setBounds(0, 0, w, h);
3271
3272 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003273 }
3274
Michael Jurkad7c28052012-04-27 15:43:36 -07003275 @Override
3276 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003277 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003278 final List<CharSequence> text = event.getText();
3279 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003280 // Populate event with a fake title based on the current state.
3281 if (mState == State.APPS_CUSTOMIZE) {
3282 text.add(getString(R.string.all_apps_button_label));
3283 } else {
3284 text.add(getString(R.string.all_apps_home_button_label));
3285 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003286 return result;
3287 }
3288
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003289 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003290 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003291 */
3292 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3293 @Override
3294 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003295 closeSystemDialogs();
3296 }
3297 }
3298
3299 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003300 * Receives notifications whenever the appwidgets are reset.
3301 */
3302 private class AppWidgetResetObserver extends ContentObserver {
3303 public AppWidgetResetObserver() {
3304 super(new Handler());
3305 }
3306
3307 @Override
3308 public void onChange(boolean selfChange) {
3309 onAppWidgetReset();
3310 }
3311 }
3312
3313 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003314 * If the activity is currently paused, signal that we need to run the passed Runnable
3315 * in onResume.
3316 *
3317 * This needs to be called from incoming places where resources might have been loaded
3318 * while we are paused. That is becaues the Configuration might be wrong
3319 * when we're not running, and if it comes back to what it was when we
3320 * were paused, we are not restarted.
3321 *
3322 * Implementation of the method from LauncherModel.Callbacks.
3323 *
3324 * @return true if we are currently paused. The caller might be able to
3325 * skip some work in that case since we will come back again.
3326 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003327 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003328 if (mPaused) {
3329 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003330 if (deletePreviousRunnables) {
3331 while (mOnResumeCallbacks.remove(run)) {
3332 }
3333 }
Michael Jurka7607c2f2013-04-03 14:33:19 -07003334 mOnResumeCallbacks.add(run);
3335 return true;
3336 } else {
3337 return false;
3338 }
3339 }
3340
Michael Jurkac402cd92013-05-20 15:49:32 +02003341 private boolean waitUntilResume(Runnable run) {
3342 return waitUntilResume(run, false);
3343 }
3344
Michael Jurka7607c2f2013-04-03 14:33:19 -07003345 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003346 * If the activity is currently paused, signal that we need to re-run the loader
3347 * in onResume.
3348 *
3349 * This needs to be called from incoming places where resources might have been loaded
3350 * while we are paused. That is becaues the Configuration might be wrong
3351 * when we're not running, and if it comes back to what it was when we
3352 * were paused, we are not restarted.
3353 *
3354 * Implementation of the method from LauncherModel.Callbacks.
3355 *
3356 * @return true if we are currently paused. The caller might be able to
3357 * skip some work in that case since we will come back again.
3358 */
3359 public boolean setLoadOnResume() {
3360 if (mPaused) {
3361 Log.i(TAG, "setLoadOnResume");
3362 mOnResumeNeedsLoad = true;
3363 return true;
3364 } else {
3365 return false;
3366 }
3367 }
3368
3369 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003370 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003371 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003372 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003373 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003374 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003375 } else {
3376 return SCREEN_COUNT / 2;
3377 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003378 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003379
Joe Onorato9c1289c2009-08-17 11:03:03 -04003380 /**
3381 * Refreshes the shortcuts shown on the workspace.
3382 *
3383 * Implementation of the method from LauncherModel.Callbacks.
3384 */
3385 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003386 // If we're starting binding all over again, clear any bind calls we'd postponed in
3387 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3388 // from scratch again
3389 mOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003390
Michael Jurka7607c2f2013-04-03 14:33:19 -07003391 final Workspace workspace = mWorkspace;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003392 mNewShortcutAnimatePage = -1;
3393 mNewShortcutAnimateViews.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003394 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003395 int count = workspace.getChildCount();
3396 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003397 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003398 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3399 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003400 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08003401 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003402 if (mHotseat != null) {
3403 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003404 }
3405 }
3406
3407 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003408 * Bind the items start-end from the list.
3409 *
3410 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003411 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003412 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end) {
3413 if (waitUntilResume(new Runnable() {
3414 public void run() {
3415 bindItems(shortcuts, start, end);
3416 }
3417 })) {
3418 return;
3419 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003420
Winson Chungf0c6ae02012-03-21 16:10:31 -07003421 // Get the list of added shortcuts and intersect them with the set of shortcuts here
3422 Set<String> newApps = new HashSet<String>();
3423 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);
3424
3425 Workspace workspace = mWorkspace;
3426 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003427 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003428
3429 // Short circuit if we are loading dock items for a configuration which has no dock
3430 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3431 mHotseat == null) {
3432 continue;
3433 }
3434
Joe Onorato9c1289c2009-08-17 11:03:03 -04003435 switch (item.itemType) {
3436 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3437 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003438 ShortcutInfo info = (ShortcutInfo) item;
3439 String uri = info.intent.toUri(0).toString();
3440 View shortcut = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -07003441 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3442 item.cellY, 1, 1, false);
Winson Chungbfeac062012-06-06 15:56:08 -07003443 boolean animateIconUp = false;
3444 synchronized (newApps) {
3445 if (newApps.contains(uri)) {
3446 animateIconUp = newApps.remove(uri);
3447 }
3448 }
3449 if (animateIconUp) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003450 // Prepare the view to be animated up
3451 shortcut.setAlpha(0f);
3452 shortcut.setScaleX(0f);
3453 shortcut.setScaleY(0f);
3454 mNewShortcutAnimatePage = item.screen;
3455 if (!mNewShortcutAnimateViews.contains(shortcut)) {
3456 mNewShortcutAnimateViews.add(shortcut);
3457 }
3458 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003459 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003460 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003461 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003462 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003463 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003464 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3465 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003466 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003467 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003468 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003469
Joe Onorato9c1289c2009-08-17 11:03:03 -04003470 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003471 }
3472
Joe Onorato9c1289c2009-08-17 11:03:03 -04003473 /**
3474 * Implementation of the method from LauncherModel.Callbacks.
3475 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003476 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
3477 if (waitUntilResume(new Runnable() {
3478 public void run() {
3479 bindFolders(folders);
3480 }
3481 })) {
3482 return;
3483 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003484 sFolders.clear();
3485 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003486 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003487
3488 /**
3489 * Add the views for a widget to the workspace.
3490 *
3491 * Implementation of the method from LauncherModel.Callbacks.
3492 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003493 public void bindAppWidget(final LauncherAppWidgetInfo item) {
3494 if (waitUntilResume(new Runnable() {
3495 public void run() {
3496 bindAppWidget(item);
3497 }
3498 })) {
3499 return;
3500 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003501
Daniel Sandler843e8602010-06-07 14:59:01 -04003502 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3503 if (DEBUG_WIDGETS) {
3504 Log.d(TAG, "bindAppWidget: " + item);
3505 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003506 final Workspace workspace = mWorkspace;
3507
3508 final int appWidgetId = item.appWidgetId;
3509 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003510 if (DEBUG_WIDGETS) {
3511 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3512 }
3513
Joe Onorato9c1289c2009-08-17 11:03:03 -04003514 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3515
Joe Onorato9c1289c2009-08-17 11:03:03 -04003516 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003517 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003518
Winson Chung3d503fb2011-07-13 17:25:49 -07003519 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003520 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003521 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3522
Joe Onorato9c1289c2009-08-17 11:03:03 -04003523 workspace.requestLayout();
3524
Daniel Sandler843e8602010-06-07 14:59:01 -04003525 if (DEBUG_WIDGETS) {
3526 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3527 + (SystemClock.uptimeMillis()-start) + "ms");
3528 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003529 }
3530
Adam Cohen1462de32012-07-24 22:34:36 -07003531 public void onPageBoundSynchronously(int page) {
3532 mSynchronouslyBoundPages.add(page);
3533 }
3534
Joe Onorato9c1289c2009-08-17 11:03:03 -04003535 /**
3536 * Callback saying that there aren't any more items to bind.
3537 *
3538 * Implementation of the method from LauncherModel.Callbacks.
3539 */
Adam Cohene25af792013-06-06 23:08:25 -07003540 public void finishBindingItems(final boolean upgradePath) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003541 if (waitUntilResume(new Runnable() {
3542 public void run() {
Adam Cohene25af792013-06-06 23:08:25 -07003543 finishBindingItems(upgradePath);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003544 }
3545 })) {
3546 return;
3547 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003548 if (mSavedState != null) {
3549 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003550 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003551 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003552 mSavedState = null;
3553 }
3554
Adam Cohen1462de32012-07-24 22:34:36 -07003555 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003556
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003557 // If we received the result of any pending adds while the loader was running (e.g. the
3558 // widget configuration forced an orientation change), process them now.
3559 for (int i = 0; i < sPendingAddList.size(); i++) {
3560 completeAdd(sPendingAddList.get(i));
3561 }
3562 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003563
Winson Chungc51db6a2011-10-05 11:44:49 -07003564 // Update the market app icon as necessary (the other icons will be managed in response to
3565 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003566 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003567
Winson Chungf0c6ae02012-03-21 16:10:31 -07003568 // Animate up any icons as necessary
3569 if (mVisible || mWorkspaceLoading) {
3570 Runnable newAppsRunnable = new Runnable() {
3571 @Override
3572 public void run() {
Winson Chunga2413752012-04-03 14:22:34 -07003573 runNewAppsAnimation(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003574 }
3575 };
Winson Chunga2413752012-04-03 14:22:34 -07003576
3577 boolean willSnapPage = mNewShortcutAnimatePage > -1 &&
3578 mNewShortcutAnimatePage != mWorkspace.getCurrentPage();
3579 if (canRunNewAppsAnimation()) {
3580 // If the user has not interacted recently, then either snap to the new page to show
3581 // the new-apps animation or just run them if they are to appear on the current page
3582 if (willSnapPage) {
3583 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable);
3584 } else {
3585 runNewAppsAnimation(false);
3586 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003587 } else {
Winson Chung318eee02012-04-12 10:59:27 -07003588 // If the user has interacted recently, then just add the items in place if they
Winson Chunga2413752012-04-03 14:22:34 -07003589 // are on another page (or just normally if they are added to the current page)
3590 runNewAppsAnimation(willSnapPage);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003591 }
3592 }
3593
3594 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003595 if (upgradePath) {
3596 mWorkspace.saveWorkspaceToDb();
3597
3598 // Run through this twice... a little hackleberry, but the right solution is complex.
3599 mWorkspace.stripDuplicateApps();
3600 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.stripDuplicateApps();
3601 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003602 }
3603
Winson Chunga2413752012-04-03 14:22:34 -07003604 private boolean canRunNewAppsAnimation() {
3605 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3606 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3607 }
3608
Winson Chungf0c6ae02012-03-21 16:10:31 -07003609 /**
3610 * Runs a new animation that scales up icons that were added while Launcher was in the
3611 * background.
Winson Chunga2413752012-04-03 14:22:34 -07003612 *
3613 * @param immediate whether to run the animation or show the results immediately
Winson Chungf0c6ae02012-03-21 16:10:31 -07003614 */
Winson Chunga2413752012-04-03 14:22:34 -07003615 private void runNewAppsAnimation(boolean immediate) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07003616 AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003617 Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chunga2413752012-04-03 14:22:34 -07003618
3619 // Order these new views spatially so that they animate in order
Winson Chungf0c6ae02012-03-21 16:10:31 -07003620 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
3621 @Override
3622 public int compare(View a, View b) {
3623 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
3624 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
3625 int cellCountX = LauncherModel.getCellCountX();
3626 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
3627 }
3628 });
Winson Chunga2413752012-04-03 14:22:34 -07003629
3630 // Animate each of the views in place (or show them immediately if requested)
3631 if (immediate) {
3632 for (View v : mNewShortcutAnimateViews) {
3633 v.setAlpha(1f);
3634 v.setScaleX(1f);
3635 v.setScaleY(1f);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003636 }
Winson Chunga2413752012-04-03 14:22:34 -07003637 } else {
3638 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
3639 View v = mNewShortcutAnimateViews.get(i);
Michael Jurka2ecf9952012-06-18 12:52:28 -07003640 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
Winson Chunga2413752012-04-03 14:22:34 -07003641 PropertyValuesHolder.ofFloat("alpha", 1f),
3642 PropertyValuesHolder.ofFloat("scaleX", 1f),
3643 PropertyValuesHolder.ofFloat("scaleY", 1f));
3644 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3645 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3646 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3647 bounceAnims.add(bounceAnim);
3648 }
3649 anim.playTogether(bounceAnims);
3650 anim.addListener(new AnimatorListenerAdapter() {
3651 @Override
3652 public void onAnimationEnd(Animator animation) {
Michael Jurkad6dd7c82012-10-19 17:15:16 +02003653 if (mWorkspace != null) {
3654 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
3655 }
Winson Chunga2413752012-04-03 14:22:34 -07003656 }
3657 });
3658 anim.start();
3659 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003660
3661 // Clean up
3662 mNewShortcutAnimatePage = -1;
3663 mNewShortcutAnimateViews.clear();
3664 new Thread("clearNewAppsThread") {
3665 public void run() {
3666 mSharedPrefs.edit()
3667 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
3668 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null)
3669 .commit();
3670 }
3671 }.start();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003672 }
3673
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003674 @Override
3675 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003676 boolean searchVisible = updateGlobalSearchIcon();
3677 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003678 if (mSearchDropTargetBar != null) {
3679 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3680 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003681 }
3682
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003683 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003684 * Add the icons for all apps.
3685 *
3686 * Implementation of the method from LauncherModel.Callbacks.
3687 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003688 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003689 Runnable setAllAppsRunnable = new Runnable() {
3690 public void run() {
3691 if (mAppsCustomizeContent != null) {
3692 mAppsCustomizeContent.setApps(apps);
Adam Cohene25af792013-06-06 23:08:25 -07003693
3694 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3695 getHotseat().addAllAppsFolder(mIconCache, apps,
3696 mIntentsOnWorkspaceFromUpgradePath, Launcher.this);
3697 mIntentsOnWorkspaceFromUpgradePath = null;
3698 }
Winson Chungc93e5ae2012-07-23 20:48:26 -07003699 }
3700 }
3701 };
3702
Michael Jurkac57b7a82011-08-09 22:02:20 -07003703 // Remove the progress bar entirely; we could also make it GONE
3704 // but better to remove it since we know it's not going to be used
3705 View progressBar = mAppsCustomizeTabHost.
3706 findViewById(R.id.apps_customize_progress_bar);
3707 if (progressBar != null) {
3708 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chungc93e5ae2012-07-23 20:48:26 -07003709
3710 // We just post the call to setApps so the user sees the progress bar
3711 // disappear-- otherwise, it just looks like the progress bar froze
3712 // which doesn't look great
3713 mAppsCustomizeTabHost.post(setAllAppsRunnable);
3714 } else {
3715 // If we did not initialize the spinner in onCreate, then we can directly set the
3716 // list of applications without waiting for any progress bars views to be hidden.
3717 setAllAppsRunnable.run();
Winson Chung785d2eb2011-04-14 16:08:02 -07003718 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003719 }
3720
3721 /**
3722 * A package was installed.
3723 *
3724 * Implementation of the method from LauncherModel.Callbacks.
3725 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003726 public void bindAppsAdded(final ArrayList<ApplicationInfo> apps) {
3727 if (waitUntilResume(new Runnable() {
3728 public void run() {
3729 bindAppsAdded(apps);
3730 }
3731 })) {
3732 return;
3733 }
3734
Winson Chungf0ea4d32011-06-06 14:27:16 -07003735
Winson Chung785d2eb2011-04-14 16:08:02 -07003736 if (mAppsCustomizeContent != null) {
3737 mAppsCustomizeContent.addApps(apps);
3738 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003739 }
3740
3741 /**
3742 * A package was updated.
3743 *
3744 * Implementation of the method from LauncherModel.Callbacks.
3745 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003746 public void bindAppsUpdated(final ArrayList<ApplicationInfo> apps) {
3747 if (waitUntilResume(new Runnable() {
3748 public void run() {
3749 bindAppsUpdated(apps);
3750 }
3751 })) {
3752 return;
3753 }
3754
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003755 if (mWorkspace != null) {
3756 mWorkspace.updateShortcuts(apps);
3757 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003758
Winson Chung785d2eb2011-04-14 16:08:02 -07003759 if (mAppsCustomizeContent != null) {
3760 mAppsCustomizeContent.updateApps(apps);
3761 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003762 }
3763
3764 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003765 * A package was uninstalled. We take both the super set of packageNames
3766 * in addition to specific applications to remove, the reason being that
3767 * this can be called when a package is updated as well. In that scenario,
3768 * we only remove specific components from the workspace, where as
3769 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003770 *
3771 * Implementation of the method from LauncherModel.Callbacks.
3772 */
Winson Chung83892cc2013-05-01 16:53:33 -07003773 public void bindComponentsRemoved(final ArrayList<String> packageNames,
3774 final ArrayList<ApplicationInfo> appInfos,
3775 final boolean matchPackageNamesOnly) {
3776 if (waitUntilResume(new Runnable() {
3777 public void run() {
3778 bindComponentsRemoved(packageNames, appInfos, matchPackageNamesOnly);
3779 }
3780 })) {
3781 return;
3782 }
3783
3784 if (matchPackageNamesOnly) {
3785 mWorkspace.removeItemsByPackageName(packageNames);
3786 } else {
3787 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003788 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003789
Winson Chung785d2eb2011-04-14 16:08:02 -07003790 if (mAppsCustomizeContent != null) {
Winson Chung83892cc2013-05-01 16:53:33 -07003791 mAppsCustomizeContent.removeApps(appInfos);
Winson Chung785d2eb2011-04-14 16:08:02 -07003792 }
Winson Chunga1820962011-10-03 16:31:06 -07003793
3794 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003795 mDragController.onAppsRemoved(appInfos, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003796 }
Joe Onoratobe386092009-11-17 17:32:16 -08003797
3798 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003799 * A number of packages were updated.
3800 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003801
3802 private ArrayList<Object> mWidgetsAndShortcuts;
3803 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003804 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02003805 bindPackagesUpdated(mWidgetsAndShortcuts);
3806 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07003807 }
Michael Jurkac402cd92013-05-20 15:49:32 +02003808 };
3809
3810 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
3811 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
3812 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07003813 return;
3814 }
3815
Winson Chung785d2eb2011-04-14 16:08:02 -07003816 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003817 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07003818 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003819 }
3820
Winson Chung400438b2011-01-16 17:53:48 -08003821 private int mapConfigurationOriActivityInfoOri(int configOri) {
3822 final Display d = getWindowManager().getDefaultDisplay();
3823 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3824 switch (d.getRotation()) {
3825 case Surface.ROTATION_0:
3826 case Surface.ROTATION_180:
3827 // We are currently in the same basic orientation as the natural orientation
3828 naturalOri = configOri;
3829 break;
3830 case Surface.ROTATION_90:
3831 case Surface.ROTATION_270:
3832 // We are currently in the other basic orientation to the natural orientation
3833 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3834 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3835 break;
3836 }
3837
3838 int[] oriMap = {
3839 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3840 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3841 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3842 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3843 };
3844 // Since the map starts at portrait, we need to offset if this device's natural orientation
3845 // is landscape.
3846 int indexOffset = 0;
3847 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3848 indexOffset = 1;
3849 }
3850 return oriMap[(d.getRotation() + indexOffset) % 4];
3851 }
Adam Cohen446e9402011-09-15 18:21:21 -07003852
Winson Chung4b919f82012-05-01 10:44:08 -07003853 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08003854 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07003855 getResources().getBoolean(R.bool.allow_rotation);
3856 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08003857 }
Winson Chung4b919f82012-05-01 10:44:08 -07003858 public void lockScreenOrientation() {
3859 if (isRotationEnabled()) {
3860 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3861 .getConfiguration().orientation));
3862 }
3863 }
3864 public void unlockScreenOrientation(boolean immediate) {
3865 if (isRotationEnabled()) {
3866 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07003867 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07003868 } else {
3869 mHandler.postDelayed(new Runnable() {
3870 public void run() {
3871 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3872 }
3873 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07003874 }
Winson Chung4b919f82012-05-01 10:44:08 -07003875 }
Winson Chung400438b2011-01-16 17:53:48 -08003876 }
3877
Winson Chung82f55532011-08-09 14:14:23 -07003878 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003879 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003880 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003881 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003882
Michael Jurkae233a8b2013-03-19 13:49:20 +01003883 // Restricted secondary users (child mode) will potentially have very few apps
3884 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04003885// boolean supportsLimitedUsers =
3886// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
3887// Account[] accounts = AccountManager.get(this).getAccounts();
3888// if (supportsLimitedUsers && accounts.length == 0) {
3889// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
3890// Bundle restrictions = um.getUserRestrictions();
3891// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
3892// return false;
3893// }
3894// }
Winson Chung7d7541e2011-09-16 20:14:36 -07003895 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003896 }
Michael Jurka22143132012-10-04 17:42:38 +02003897
Winson Chung7d7541e2011-09-16 20:14:36 -07003898 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
Michael Jurka22143132012-10-04 17:42:38 +02003899 final Cling cling = (Cling) findViewById(clingId);
Winson Chung7d7541e2011-09-16 20:14:36 -07003900 if (cling != null) {
3901 cling.init(this, positionData);
3902 cling.setVisibility(View.VISIBLE);
3903 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3904 if (animate) {
3905 cling.buildLayer();
3906 cling.setAlpha(0f);
3907 cling.animate()
3908 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003909 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003910 .setDuration(SHOW_CLING_DURATION)
3911 .setStartDelay(delay)
3912 .start();
3913 } else {
3914 cling.setAlpha(1f);
3915 }
Michael Jurka22143132012-10-04 17:42:38 +02003916 cling.setFocusableInTouchMode(true);
3917 cling.post(new Runnable() {
3918 public void run() {
3919 cling.setFocusable(true);
3920 cling.requestFocus();
3921 }
3922 });
3923 mHideFromAccessibilityHelper.setImportantForAccessibilityToNo(
3924 mDragLayer, clingId == R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003925 }
3926 return cling;
3927 }
Michael Jurka22143132012-10-04 17:42:38 +02003928
Winson Chung7d7541e2011-09-16 20:14:36 -07003929 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung7819abd2012-11-29 14:29:38 -08003930 // To catch cases where siblings of top-level views are made invisible, just check whether
3931 // the cling is directly set to GONE before dismissing it.
3932 if (cling != null && cling.getVisibility() != View.GONE) {
Michael Jurka2ecf9952012-06-18 12:52:28 -07003933 ObjectAnimator anim = LauncherAnimUtils.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003934 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003935 anim.addListener(new AnimatorListenerAdapter() {
3936 public void onAnimationEnd(Animator animation) {
3937 cling.setVisibility(View.GONE);
3938 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003939 // We should update the shared preferences on a background thread
3940 new Thread("dismissClingThread") {
3941 public void run() {
3942 SharedPreferences.Editor editor = mSharedPrefs.edit();
3943 editor.putBoolean(flag, true);
3944 editor.commit();
3945 }
3946 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003947 };
3948 });
3949 anim.start();
Michael Jurka22143132012-10-04 17:42:38 +02003950 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung82f55532011-08-09 14:14:23 -07003951 }
3952 }
Michael Jurka22143132012-10-04 17:42:38 +02003953
Winson Chung9d9d74f2011-09-19 11:49:12 -07003954 private void removeCling(int id) {
3955 final View cling = findViewById(id);
3956 if (cling != null) {
3957 final ViewGroup parent = (ViewGroup) cling.getParent();
3958 parent.post(new Runnable() {
3959 @Override
3960 public void run() {
3961 parent.removeView(cling);
3962 }
3963 });
Michael Jurka22143132012-10-04 17:42:38 +02003964 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003965 }
3966 }
Michael Jurka974c3862012-05-22 22:00:31 -07003967
3968 private boolean skipCustomClingIfNoAccounts() {
3969 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3970 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
3971 if (customCling) {
3972 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04003973 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07003974 Account[] accounts = am.getAccountsByType("com.google");
3975 return accounts.length == 0;
3976 }
3977 return false;
3978 }
3979
Winson Chung7d7541e2011-09-16 20:14:36 -07003980 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003981 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003982 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07003983 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
3984 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02003985 // If we're not using the default workspace layout, replace workspace cling
3986 // with a custom workspace cling (usually specified in an overlay)
3987 // For now, only do this on tablets
3988 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
Michael Jurkaa1131212012-10-09 14:46:26 +02003989 getResources().getBoolean(R.bool.config_useCustomClings)) {
Michael Jurka45355c42012-10-08 13:21:35 +02003990 // Use a custom cling
3991 View cling = findViewById(R.id.workspace_cling);
3992 ViewGroup clingParent = (ViewGroup) cling.getParent();
3993 int clingIndex = clingParent.indexOfChild(cling);
3994 clingParent.removeViewAt(clingIndex);
3995 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
3996 clingParent.addView(customCling, clingIndex);
3997 customCling.setId(R.id.workspace_cling);
3998 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003999 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004000 } else {
4001 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004002 }
4003 }
4004 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07004005 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004006 if (isClingsEnabled() &&
4007 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07004008 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004009 } else {
4010 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004011 }
4012 }
4013 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004014 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004015 if (isClingsEnabled() &&
4016 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
4017 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004018 } else {
4019 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004020 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004021 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004022 }
4023 public boolean isFolderClingVisible() {
4024 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004025 if (cling != null) {
4026 return cling.getVisibility() == View.VISIBLE;
4027 }
4028 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004029 }
Winson Chung82f55532011-08-09 14:14:23 -07004030 public void dismissWorkspaceCling(View v) {
4031 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004032 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004033 }
4034 public void dismissAllAppsCling(View v) {
4035 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004036 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
4037 }
4038 public void dismissFolderCling(View v) {
4039 Cling cling = (Cling) findViewById(R.id.folder_cling);
4040 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07004041 }
4042
Winson Chung80baf5a2010-08-09 16:03:15 -07004043 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004044 * Prints out out state for debugging.
4045 */
4046 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004047 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004048 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004049 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4050 Log.d(TAG, "mRestoring=" + mRestoring);
4051 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4052 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004053 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004054 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004055
Winson Chung785d2eb2011-04-14 16:08:02 -07004056 if (mAppsCustomizeContent != null) {
4057 mAppsCustomizeContent.dumpState();
4058 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004059 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004060 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004061
4062 @Override
4063 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4064 super.dump(prefix, fd, writer, args);
4065 writer.println(" ");
4066 writer.println("Debug logs: ");
4067 for (int i = 0; i < sDumpLogs.size(); i++) {
4068 writer.println(" " + sDumpLogs.get(i));
4069 }
4070 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004071
4072 public static void dumpDebugLogsToConsole() {
4073 Log.d(TAG, "");
4074 Log.d(TAG, "*********************");
4075 Log.d(TAG, "Launcher debug logs: ");
4076 for (int i = 0; i < sDumpLogs.size(); i++) {
4077 Log.d(TAG, " " + sDumpLogs.get(i));
4078 }
4079 Log.d(TAG, "*********************");
4080 Log.d(TAG, "");
4081 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004082}
Michael Jurka2763be32011-02-24 11:19:57 -08004083
Michael Jurkaabded662011-03-04 12:06:57 -08004084interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004085 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004086 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004087 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004088 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004089 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004090}