blob: 98d4c094dd095b5b42cd1e787ea0ee8a4d7a0d87 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Joe Onoratoa5902522009-07-30 13:37:37 -070018package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Michael Jurka974c3862012-05-22 22:00:31 -070020import android.accounts.Account;
21import android.accounts.AccountManager;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080023import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070030import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070031import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070049import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080050import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070051import android.graphics.Bitmap;
52import android.graphics.Canvas;
53import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070054import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070055import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040056import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070057import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080058import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020059import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080060import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070061import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070062import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040063import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080064import android.os.SystemProperties;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070065import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080066import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067import android.text.Selection;
68import android.text.SpannableStringBuilder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070070import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080071import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080072import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073import android.view.KeyEvent;
74import android.view.LayoutInflater;
75import android.view.Menu;
76import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070077import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080078import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080079import android.view.View;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080080import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070081import android.view.ViewGroup;
Michael Jurkab737ee62011-11-15 15:57:22 -080082import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080083import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Dianne Hackbornbb003a52011-08-30 14:40:07 -070084import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080085import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070086import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070087import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080088import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070090import android.widget.Advanceable;
Michael Jurkaaf442092010-06-10 17:01:57 -070091import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070092import android.widget.TextView;
93import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070094
Adam Cohendf2cc412011-04-27 16:56:57 -070095import com.android.common.Search;
96import com.android.launcher.R;
Adam Cohen558baaf2011-08-15 15:22:57 -070097import com.android.launcher2.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080098
Adam Cohenc0dcf592011-06-01 15:30:43 -070099import java.io.DataInputStream;
100import java.io.DataOutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700101import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.FileNotFoundException;
103import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700104import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700105import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700106import java.util.Collection;
107import java.util.Collections;
108import java.util.Comparator;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.util.HashMap;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700110import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700111import java.util.List;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700112import java.util.Set;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700113
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800114/**
115 * Default launcher application.
116 */
Michael Jurka946ad472010-07-09 18:05:18 -0700117public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700118 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
119 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800120 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700121 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122
Joe Onorato9c1289c2009-08-17 11:03:03 -0400123 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400124 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700125 static final boolean DEBUG_STRICT_MODE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700126
Winson Chung70d72102011-08-12 11:24:35 -0700127 private static final int MENU_GROUP_WALLPAPER = 1;
128 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
129 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700130 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
131 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132
133 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700134 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_PICK_APPLICATION = 6;
136 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700137 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700138 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
Michael Jurka8b805b12012-04-18 14:23:14 -0700140 private static final int REQUEST_BIND_APPWIDGET = 11;
141
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
143
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800144 static final int SCREEN_COUNT = 5;
145 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146
Romain Guy98d01652009-06-30 16:21:04 -0700147 private static final String PREFERENCES = "launcher.preferences";
Adam Cohen23a4d302011-12-01 17:26:44 -0800148 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher.force_enable_rotation";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149
Winson Chung2672ff92012-05-04 16:22:30 -0700150 // The Intent extra that defines whether to ignore the launch animation
151 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
152 "com.android.launcher.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
153
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154 // Type: int
155 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700156 // Type: int
157 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700159 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
160 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800161 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
162 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700163 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700165 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166 // Type: boolean
167 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
168 // Type: long
169 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700170 // Type: int
171 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
172 // Type: int
173 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
174 // Type: parcelable
175 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700177 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700178 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
179 "com.android.launcher.toolbar_search_icon";
180 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
181 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700182
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700183 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700184 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700185 private State mState = State.WORKSPACE;
186 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800187 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700188
Joe Onorato9c1289c2009-08-17 11:03:03 -0400189 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700190 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
191 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700192 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700193 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800194
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800196 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800197
Winson Chunga2413752012-04-03 14:22:34 -0700198 // How long to wait before the new-shortcut animation automatically pans the workspace
199 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
200
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800201 private final BroadcastReceiver mCloseSystemDialogsReceiver
202 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800203 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
204
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205 private LayoutInflater mInflater;
206
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800208 private View mQsbDivider;
209 private View mDockDivider;
210 private DragLayer mDragLayer;
211 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700212
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700213 private AppWidgetManager mAppWidgetManager;
214 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700215
Michael Jurkac9d95c52011-08-29 14:03:34 -0700216 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700217 private AppWidgetProviderInfo mPendingAddWidgetInfo;
218
Michael Jurka0280c3b2010-09-17 15:00:07 -0700219 private int[] mTmpAddItemCellCoordinates = new int[2];
220
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221 private FolderInfo mFolderInfo;
222
Winson Chung3d503fb2011-07-13 17:25:49 -0700223 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800224 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700225
Winson Chungc51db6a2011-10-05 11:44:49 -0700226 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700227 private AppsCustomizeTabHost mAppsCustomizeTabHost;
228 private AppsCustomizePagedView mAppsCustomizeContent;
229 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800230
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800231 private Bundle mSavedState;
232
233 private SpannableStringBuilder mDefaultKeySsb = null;
234
Joe Onorato9c1289c2009-08-17 11:03:03 -0400235 private boolean mWorkspaceLoading = true;
236
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800237 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800238 private boolean mRestoring;
239 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700240 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800241
242 private Bundle mSavedInstanceState;
243
Joe Onorato9c1289c2009-08-17 11:03:03 -0400244 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800245 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800246 private boolean mUserPresent = true;
247 private boolean mVisible = false;
248 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400249
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700250 private static LocaleConfiguration sLocaleConfiguration = null;
251
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700252 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700253
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700254 private Intent mAppMarketIntent = null;
255
Adam Cohended9f8d2010-11-03 13:25:16 -0700256 // Related to the auto-advancing of widgets
257 private final int ADVANCE_MSG = 1;
258 private final int mAdvanceInterval = 20000;
259 private final int mAdvanceStagger = 250;
260 private long mAutoAdvanceSentTime;
261 private long mAutoAdvanceTimeLeft = -1;
262 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
263 new HashMap<View, AppWidgetProviderInfo>();
264
Winson Chung400438b2011-01-16 17:53:48 -0800265 // Determines how long to wait after a rotation before restoring the screen orientation to
266 // match the sensor state.
267 private final int mRestoreScreenOrientationDelay = 500;
268
Michael Jurka4ef207b2010-11-29 17:05:45 -0800269 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700270 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
271 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
272 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800273
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700274 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
275
Winson Chung46353de2012-02-16 14:05:10 -0800276 // We only want to get the SharedPreferences once since it does an FS stat each time we get
277 // it from the context.
278 private SharedPreferences mSharedPrefs;
279
Winson Chungf0c6ae02012-03-21 16:10:31 -0700280 // Holds the page that we need to animate to, and the icon views that we need to animate up
281 // when we scroll to that page on resume.
282 private int mNewShortcutAnimatePage = -1;
283 private ArrayList<View> mNewShortcutAnimateViews = new ArrayList<View>();
Adam Cohen268c4752012-06-06 17:47:33 -0700284 private ImageView mFolderIconImageView;
285 private Bitmap mFolderIconBitmap;
286 private Canvas mFolderIconCanvas;
287 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700288
Michael Jurkaddd62e92011-02-16 17:49:14 -0800289 private BubbleTextView mWaitingForResume;
290
Michael Jurkac1f5d262011-09-30 19:32:27 -0700291 private Runnable mBuildLayersRunnable = new Runnable() {
292 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700293 if (mWorkspace != null) {
294 mWorkspace.buildPageHardwareLayers();
295 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700296 }
297 };
298
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800299 private static ArrayList<PendingAddArguments> sPendingAddList
300 = new ArrayList<PendingAddArguments>();
301
302 private static class PendingAddArguments {
303 int requestCode;
304 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700305 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800306 int screen;
307 int cellX;
308 int cellY;
309 }
310
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800311 @Override
312 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700313 if (DEBUG_STRICT_MODE) {
314 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
315 .detectDiskReads()
316 .detectDiskWrites()
317 .detectNetwork() // or .detectAll() for all detectable problems
318 .penaltyLog()
319 .build());
320 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
321 .detectLeakedSqlLiteObjects()
322 .detectLeakedClosableObjects()
323 .penaltyLog()
324 .penaltyDeath()
325 .build());
326 }
327
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800328 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800329 LauncherApplication app = ((LauncherApplication)getApplication());
Winson Chungf0c6ae02012-03-21 16:10:31 -0700330 mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(),
331 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800332 mModel = app.setLauncher(this);
333 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400334 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800335 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700336
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700337 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700338 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
339 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700340
Adam Cohend7d37b12012-07-18 16:15:08 -0700341 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
342 // this also ensures that any synchronous binding below doesn't re-trigger another
343 // LauncherModel load.
344 mPaused = false;
345
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800346 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200347 android.os.Debug.startMethodTracing(
348 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800349 }
350
351 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800352 setContentView(R.layout.launcher);
353 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700354 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800355
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800356 registerContentObservers();
357
Joe Onorato7c312c12009-08-13 21:36:53 -0700358 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700359
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800360 mSavedState = savedInstanceState;
361 restoreState(mSavedState);
362
Winson Chunga12a2502010-12-20 14:41:35 -0800363 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700364 if (mAppsCustomizeContent != null) {
365 mAppsCustomizeContent.onPackagesUpdated();
366 }
Winson Chunga12a2502010-12-20 14:41:35 -0800367
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800368 if (PROFILE_STARTUP) {
369 android.os.Debug.stopMethodTracing();
370 }
371
372 if (!mRestoring) {
Adam Cohend7d37b12012-07-18 16:15:08 -0700373 mModel.startLoader(true, mWorkspace.getCurrentPage());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800374 }
375
Michael Jurkac57b7a82011-08-09 22:02:20 -0700376 if (!mModel.isAllAppsLoaded()) {
377 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
378 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
379 }
380
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800381 // For handling default keys
382 mDefaultKeySsb = new SpannableStringBuilder();
383 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800384
385 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
386 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800387
Adam Cohenf9426d52012-06-04 17:26:21 -0700388 updateGlobalIcons();
389
390 // On large interfaces, we want the screen to auto-rotate based on the current orientation
391 unlockScreenOrientation(true);
392 }
393
394 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700395 boolean searchVisible = false;
396 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800397 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700398 int coi = getCurrentOrientationIndexForGlobalIcons();
399 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
400 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700401 updateAppMarketIcon();
402 searchVisible = updateGlobalSearchIcon();
403 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700404 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700405 if (sGlobalSearchIcon[coi] != null) {
406 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700407 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700408 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700409 if (sVoiceSearchIcon[coi] != null) {
410 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700411 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700412 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700413 if (sAppMarketIcon[coi] != null) {
414 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800415 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700416 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800417 }
Romain Guycbb89e42009-06-08 15:52:54 -0700418
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800419 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700420 if (sLocaleConfiguration == null) {
421 new AsyncTask<Void, Void, LocaleConfiguration>() {
422 @Override
423 protected LocaleConfiguration doInBackground(Void... unused) {
424 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
425 readConfiguration(Launcher.this, localeConfiguration);
426 return localeConfiguration;
427 }
428
429 @Override
430 protected void onPostExecute(LocaleConfiguration result) {
431 sLocaleConfiguration = result;
432 checkForLocaleChange(); // recursive, but now with a locale configuration
433 }
434 }.execute();
435 return;
436 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700437
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800438 final Configuration configuration = getResources().getConfiguration();
439
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700440 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800441 final String locale = configuration.locale.toString();
442
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700443 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800444 final int mcc = configuration.mcc;
445
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700446 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800447 final int mnc = configuration.mnc;
448
Romain Guy84f296c2009-11-04 15:00:44 -0800449 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450
Romain Guy84f296c2009-11-04 15:00:44 -0800451 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700452 sLocaleConfiguration.locale = locale;
453 sLocaleConfiguration.mcc = mcc;
454 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700455
Joe Onorato0589f0f2010-02-08 13:44:00 -0800456 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700457
458 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
459 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700460 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700461 public void run() {
462 writeConfiguration(Launcher.this, localeConfiguration);
463 }
464 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700465 }
466 }
467
468 private static class LocaleConfiguration {
469 public String locale;
470 public int mcc = -1;
471 public int mnc = -1;
472 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700473
Romain Guy98d01652009-06-30 16:21:04 -0700474 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
475 DataInputStream in = null;
476 try {
477 in = new DataInputStream(context.openFileInput(PREFERENCES));
478 configuration.locale = in.readUTF();
479 configuration.mcc = in.readInt();
480 configuration.mnc = in.readInt();
481 } catch (FileNotFoundException e) {
482 // Ignore
483 } catch (IOException e) {
484 // Ignore
485 } finally {
486 if (in != null) {
487 try {
488 in.close();
489 } catch (IOException e) {
490 // Ignore
491 }
492 }
493 }
494 }
495
496 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
497 DataOutputStream out = null;
498 try {
499 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
500 out.writeUTF(configuration.locale);
501 out.writeInt(configuration.mcc);
502 out.writeInt(configuration.mnc);
503 out.flush();
504 } catch (FileNotFoundException e) {
505 // Ignore
506 } catch (IOException e) {
507 //noinspection ResultOfMethodCallIgnored
508 context.getFileStreamPath(PREFERENCES).delete();
509 } finally {
510 if (out != null) {
511 try {
512 out.close();
513 } catch (IOException e) {
514 // Ignore
515 }
516 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800517 }
518 }
519
Adam Cohen716b51e2011-06-30 12:09:54 -0700520 public DragLayer getDragLayer() {
521 return mDragLayer;
522 }
523
Winson Chung36a62fe2012-05-06 18:04:42 -0700524 boolean isDraggingEnabled() {
525 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
526 // that is subsequently removed from the workspace in startBinding().
527 return !mModel.isLoadingWorkspace();
528 }
529
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800530 static int getScreen() {
531 synchronized (sLock) {
532 return sScreen;
533 }
534 }
535
536 static void setScreen(int screen) {
537 synchronized (sLock) {
538 sScreen = screen;
539 }
540 }
541
Winson Chung557d6ed2011-07-08 15:34:52 -0700542 /**
543 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
544 * a configuration step, this allows the proper animations to run after other transitions.
545 */
546 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700547 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800548 switch (args.requestCode) {
549 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700550 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
551 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800552 break;
553 case REQUEST_PICK_SHORTCUT:
554 processShortcut(args.intent);
555 break;
556 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700557 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
558 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700559 result = true;
560 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800561 case REQUEST_CREATE_APPWIDGET:
562 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800563 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700564 result = true;
565 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800566 case REQUEST_PICK_WALLPAPER:
567 // We just wanted the activity result here so we can clear mWaitingForResult
568 break;
569 }
Michael Jurka27614d22012-04-02 06:40:22 -0700570 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
571 // if you turned the screen off and then back while in All Apps, Launcher would not
572 // return to the workspace. Clearing mAddInfo.container here fixes this issue
573 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700574 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800575 }
576
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800577 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700578 protected void onActivityResult(
579 final int requestCode, final int resultCode, final Intent data) {
580 if (requestCode == REQUEST_BIND_APPWIDGET) {
581 int appWidgetId = data != null ?
582 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
583 if (resultCode == RESULT_CANCELED) {
584 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
585 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700586 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700587 }
588 return;
589 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700590 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800591 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
592 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700593 mWaitingForResult = false;
594
Adam Cohened66b2b2012-01-23 17:28:51 -0800595 // We have special handling for widgets
596 if (isWidgetDrop) {
597 int appWidgetId = data != null ?
598 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700599 if (appWidgetId < 0) {
600 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
601 "widget configuration activity.");
602 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
603 } else {
604 completeTwoStageWidgetDrop(resultCode, appWidgetId);
605 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800606 return;
607 }
608
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800609 // The pattern used here is that a user PICKs a specific application,
610 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700611
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800612 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
613 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700614 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800615 final PendingAddArguments args = new PendingAddArguments();
616 args.requestCode = requestCode;
617 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700618 args.container = mPendingAddInfo.container;
619 args.screen = mPendingAddInfo.screen;
620 args.cellX = mPendingAddInfo.cellX;
621 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800622 if (isWorkspaceLocked()) {
623 sPendingAddList.add(args);
624 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700625 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800626 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800627 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800628 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700629 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800630 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
631 null);
632 }
633
634 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700635 CellLayout cellLayout =
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700636 (CellLayout) mWorkspace.getChildAt(mPendingAddInfo.screen);
Adam Cohened66b2b2012-01-23 17:28:51 -0800637 Runnable onCompleteRunnable = null;
638 int animationType = 0;
639
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700640 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800641 if (resultCode == RESULT_OK) {
642 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
643 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700644 mPendingAddWidgetInfo);
645 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800646 onCompleteRunnable = new Runnable() {
647 @Override
648 public void run() {
649 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
650 mPendingAddInfo.screen, layout, null);
651 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
652 null);
653 }
654 };
655 } else if (resultCode == RESULT_CANCELED) {
656 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
657 onCompleteRunnable = new Runnable() {
658 @Override
659 public void run() {
660 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
661 null);
662 }
663 };
664 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700665 if (mDragLayer.getAnimatedView() != null) {
666 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
667 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
668 animationType, boundWidget, true);
669 } else {
670 // The animated view may be null in the case of a rotation during widget configuration
671 onCompleteRunnable.run();
672 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 }
674
675 @Override
676 protected void onResume() {
677 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700678
Winson Chungde0fb8f2012-05-08 14:37:08 -0700679 // Process any items that were added while Launcher was away
680 InstallShortcutReceiver.flushInstallQueue(this);
681
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800682 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700683 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400684 mWorkspaceLoading = true;
Adam Cohend7d37b12012-07-18 16:15:08 -0700685 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400686 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700687 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800688 }
Winson Chunge4e50662012-01-23 14:45:13 -0800689
690 // Reset the pressed state of icons that were locked in the press state while activities
691 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800692 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800693 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800694 mWaitingForResume.setStayPressed(false);
695 }
Winson Chunge4e50662012-01-23 14:45:13 -0800696 if (mAppsCustomizeContent != null) {
697 // Resets the previous all apps icon press state
698 mAppsCustomizeContent.resetDrawableState();
699 }
Adam Cohen06dff352012-06-01 17:17:08 -0700700 // It is possible that widgets can receive updates while launcher is not in the foreground.
701 // Consequently, the widgets will be inflated in the orientation of the foreground activity
702 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
703 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700704 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700705
706 // Again, as with the above scenario, it's possible that one or more of the global icons
707 // were updated in the wrong orientation.
708 updateGlobalIcons();
Adam Cohen06dff352012-06-01 17:17:08 -0700709 }
710
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800711 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700712 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700713 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
714 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
715 // when Launcher resumes and we are still in AllApps.
716 updateWallpaperVisibility(true);
717
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700718 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700719 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800720 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700721 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700722 }
Romain Guycbb89e42009-06-08 15:52:54 -0700723
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700724 @Override
725 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400726 // Flag the loader to stop early before switching
727 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700728 if (mAppsCustomizeContent != null) {
729 mAppsCustomizeContent.surrender();
730 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800731 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700732 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700733
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800734 // We can't hide the IME if it was forced open. So don't bother
735 /*
736 @Override
737 public void onWindowFocusChanged(boolean hasFocus) {
738 super.onWindowFocusChanged(hasFocus);
739
740 if (hasFocus) {
741 final InputMethodManager inputManager = (InputMethodManager)
742 getSystemService(Context.INPUT_METHOD_SERVICE);
743 WindowManager.LayoutParams lp = getWindow().getAttributes();
744 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
745 android.os.Handler()) {
746 protected void onReceiveResult(int resultCode, Bundle resultData) {
747 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
748 }
749 });
750 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
751 }
752 }
753 */
754
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800755 private boolean acceptFilter() {
756 final InputMethodManager inputManager = (InputMethodManager)
757 getSystemService(Context.INPUT_METHOD_SERVICE);
758 return !inputManager.isFullscreenMode();
759 }
760
761 @Override
762 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700763 final int uniChar = event.getUnicodeChar();
764 final boolean handled = super.onKeyDown(keyCode, event);
765 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
766 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800767 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
768 keyCode, event);
769 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700770 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700771 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700772 // showSearchDialog()
773 // If there are multiple keystrokes before the search dialog takes focus,
774 // onSearchRequested() will be called for every keystroke,
775 // but it is idempotent, so it's fine.
776 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800777 }
778 }
779
Joe Onorato8a9625e2010-01-28 15:55:35 -0800780 // Eat the long press event so the keyboard doesn't come up.
781 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
782 return true;
783 }
784
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800785 return handled;
786 }
787
Karl Rosaen138a0412009-04-23 19:00:21 -0700788 private String getTypedText() {
789 return mDefaultKeySsb.toString();
790 }
791
792 private void clearTypedText() {
793 mDefaultKeySsb.clear();
794 mDefaultKeySsb.clearSpans();
795 Selection.setSelection(mDefaultKeySsb, 0);
796 }
797
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800798 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700799 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
800 * State
801 */
802 private static State intToState(int stateOrdinal) {
803 State state = State.WORKSPACE;
804 final State[] stateValues = State.values();
805 for (int i = 0; i < stateValues.length; i++) {
806 if (stateValues[i].ordinal() == stateOrdinal) {
807 state = stateValues[i];
808 break;
809 }
810 }
811 return state;
812 }
813
814 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800815 * Restores the previous state, if it exists.
816 *
817 * @param savedState The previous state.
818 */
819 private void restoreState(Bundle savedState) {
820 if (savedState == null) {
821 return;
822 }
823
Michael Jurka883f55b2010-10-21 15:47:14 -0700824 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700825 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800826 showAllApps(false);
827 }
828
Winson Chungf0c6ae02012-03-21 16:10:31 -0700829 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800830 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700831 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800832 }
833
Winson Chung3d503fb2011-07-13 17:25:49 -0700834 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
835 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700836
Winson Chung3d503fb2011-07-13 17:25:49 -0700837 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
838 mPendingAddInfo.container = pendingAddContainer;
839 mPendingAddInfo.screen = pendingAddScreen;
840 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
841 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700842 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
843 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
844 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -0700845 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800846 mRestoring = true;
847 }
848
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700849
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800850 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
851 if (renameFolder) {
852 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700853 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800854 mRestoring = true;
855 }
Winson Chunga12a2502010-12-20 14:41:35 -0800856
Winson Chung785d2eb2011-04-14 16:08:02 -0700857
858 // Restore the AppsCustomize tab
859 if (mAppsCustomizeTabHost != null) {
860 String curTab = savedState.getString("apps_customize_currentTab");
861 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700862 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700863 mAppsCustomizeContent.setContentType(
864 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
865 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700866 mAppsCustomizeContent.loadAssociatedPages(
867 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700868 }
869
Winson Chung5afbf7b2011-07-25 11:53:08 -0700870 int currentIndex = savedState.getInt("apps_customize_currentIndex");
871 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700872 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800873 }
874
875 /**
876 * Finds all the views we need and configure them properly.
877 */
878 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700879 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400880
Winson Chung4c98d922011-05-31 16:50:48 -0700881 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
882 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800883 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
884 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800885
Winson Chung4c98d922011-05-31 16:50:48 -0700886 // Setup the drag layer
887 mDragLayer.setup(this, dragController);
888
Winson Chung3d503fb2011-07-13 17:25:49 -0700889 // Setup the hotseat
890 mHotseat = (Hotseat) findViewById(R.id.hotseat);
891 if (mHotseat != null) {
892 mHotseat.setup(this);
893 }
894
Winson Chung4c98d922011-05-31 16:50:48 -0700895 // Setup the workspace
896 mWorkspace.setHapticFeedbackEnabled(false);
897 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700898 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700899 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700900
Winson Chungf0ea4d32011-06-06 14:27:16 -0700901 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700902 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700903
Winson Chungf0ea4d32011-06-06 14:27:16 -0700904 // Setup AppsCustomize
905 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
906 findViewById(R.id.apps_customize_pane);
907 mAppsCustomizeContent = (AppsCustomizePagedView)
908 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
Winson Chungc7450e32012-04-17 17:34:08 -0700909 mAppsCustomizeTabHost.setup(this);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700910 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400911
Michael Jurka5130e402011-10-13 04:55:35 -0700912 // Get the all apps button
913 mAllAppsButton = findViewById(R.id.all_apps_button);
914 if (mAllAppsButton != null) {
915 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
916 @Override
917 public boolean onTouch(View v, MotionEvent event) {
918 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
919 onTouchDownAllAppsButton(v);
920 }
921 return false;
922 }
923 });
924 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700925 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700926 dragController.setDragScoller(mWorkspace);
927 dragController.setScrollView(mDragLayer);
928 dragController.setMoveTarget(mWorkspace);
929 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700930 if (mSearchDropTargetBar != null) {
931 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800932 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800933 }
934
935 /**
936 * Creates a view representing a shortcut.
937 *
938 * @param info The data structure describing the shortcut.
939 *
940 * @return A View inflated from R.layout.application.
941 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800942 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800943 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700944 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800945 }
946
947 /**
948 * Creates a view representing a shortcut inflated from the specified resource.
949 *
950 * @param layoutResId The id of the XML layout used to create the shortcut.
951 * @param parent The group the shortcut belongs to.
952 * @param info The data structure describing the shortcut.
953 *
954 * @return A View inflated from layoutResId.
955 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800956 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800957 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
958 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800959 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800960 return favorite;
961 }
962
963 /**
964 * Add an application shortcut to the workspace.
965 *
966 * @param data The intent describing the application.
967 * @param cellInfo The position on screen where to create the shortcut.
968 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700969 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700970 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700971 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700972
Adam Cohenfbba09b2011-07-18 21:43:05 -0700973 // First we check if we already know the exact location where we want to add this item.
974 if (cellX >= 0 && cellY >= 0) {
975 cellXY[0] = cellX;
976 cellXY[1] = cellY;
977 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -0700978 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -0700979 return;
980 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800981
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800982 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800983
Romain Guy73b979d2009-06-09 12:57:21 -0700984 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800985 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800986 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800987 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700988 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700989 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800990 } else {
991 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800992 }
993 }
Romain Guycbb89e42009-06-08 15:52:54 -0700994
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800995 /**
996 * Add a shortcut to the workspace.
997 *
998 * @param data The intent describing the shortcut.
999 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001000 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001001 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
1002 int cellY) {
1003 int[] cellXY = mTmpAddItemCellCoordinates;
1004 int[] touchXY = mPendingAddInfo.dropPos;
1005 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001006
Michael Jurkad3ef3062010-11-23 16:23:58 -08001007 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001008
Adam Cohen558baaf2011-08-15 15:22:57 -07001009 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001010 if (info == null) {
1011 return;
1012 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001013 final View view = createShortcut(info);
1014
Adam Cohenfbba09b2011-07-18 21:43:05 -07001015 // First we check if we already know the exact location where we want to add this item.
1016 if (cellX >= 0 && cellY >= 0) {
1017 cellXY[0] = cellX;
1018 cellXY[1] = cellY;
1019 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001020
1021 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001022 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001023 true, null,null)) {
1024 return;
1025 }
1026 DragObject dragObject = new DragObject();
1027 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001028 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1029 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001030 return;
1031 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001032 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001033 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001034 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001035 foundCellSpan = (result != null);
1036 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001037 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001038 }
1039
1040 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001041 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001042 return;
1043 }
1044
Adam Cohen558baaf2011-08-15 15:22:57 -07001045 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001046
1047 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001048 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
1049 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001050 }
1051 }
1052
Adam Cohen2f093b62012-04-30 18:59:53 -07001053 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1054 int minHeight) {
1055 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001056 // We want to account for the extra amount of padding that we are adding to the widget
1057 // to ensure that it gets the full amount of space that it has requested
1058 int requiredWidth = minWidth + padding.left + padding.right;
1059 int requiredHeight = minHeight + padding.top + padding.bottom;
Adam Cohen2f093b62012-04-30 18:59:53 -07001060 return CellLayout.rectToCell(context.getResources(), requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001061 }
1062
Adam Cohen2f093b62012-04-30 18:59:53 -07001063 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1064 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001065 }
1066
Adam Cohen2f093b62012-04-30 18:59:53 -07001067 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1068 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001069 }
1070
Adam Cohen2f093b62012-04-30 18:59:53 -07001071 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1072 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001073 }
1074
Adam Cohen2f093b62012-04-30 18:59:53 -07001075 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1076 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001077 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001078 }
1079
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001080 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001081 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001082 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001083 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001084 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001085 */
Adam Cohened66b2b2012-01-23 17:28:51 -08001086 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
1087 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1088 if (appWidgetInfo == null) {
1089 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1090 }
Romain Guycbb89e42009-06-08 15:52:54 -07001091
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001092 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -07001093 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -07001094
Adam Cohen2f093b62012-04-30 18:59:53 -07001095 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1096 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001097
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001098 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001099 // We have saved the position to which the widget was dragged-- this really only matters
1100 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001101 int[] cellXY = mTmpAddItemCellCoordinates;
1102 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001103 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001104 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001105 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1106 cellXY[0] = mPendingAddInfo.cellX;
1107 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001108 spanXY[0] = mPendingAddInfo.spanX;
1109 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001110 foundCellSpan = true;
1111 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001112 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001113 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001114 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1115 spanXY[1], cellXY, finalSpan);
1116 spanXY[0] = finalSpan[0];
1117 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001118 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001119 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001120 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001121 }
1122
Michael Jurka0280c3b2010-09-17 15:00:07 -07001123 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001124 if (appWidgetId != -1) {
1125 // Deleting an app widget ID is a void call but writes to disk before returning
1126 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001127 new Thread("deleteAppWidgetId") {
1128 public void run() {
1129 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1130 }
1131 }.start();
1132 }
Winson Chung93eef082012-03-23 15:59:27 -07001133 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001134 return;
1135 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001136
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001137 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001138 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1139 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001140 launcherInfo.spanX = spanXY[0];
1141 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001142 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1143 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001144
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001145 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001146 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001147
1148 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001149 if (hostView == null) {
1150 // Perform actual inflation because we're live
1151 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1152 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1153 } else {
1154 // The AppWidgetHostView has already been inflated and instantiated
1155 launcherInfo.hostView = hostView;
1156 }
Romain Guycbb89e42009-06-08 15:52:54 -07001157
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001158 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001159 launcherInfo.hostView.setVisibility(View.VISIBLE);
Winson Chung211bac32012-05-15 13:43:57 -07001160 launcherInfo.notifyWidgetSizeChanged(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001161 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001162 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001163
1164 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001165 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001166 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001167 }
Romain Guycbb89e42009-06-08 15:52:54 -07001168
Adam Cohended9f8d2010-11-03 13:25:16 -07001169 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1170 @Override
1171 public void onReceive(Context context, Intent intent) {
1172 final String action = intent.getAction();
1173 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1174 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001175 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001176 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001177
Winson Chungc100e8e2011-08-09 16:02:43 -07001178 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001179 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001180 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1181 mAppsCustomizeTabHost.reset();
1182 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001183 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001184 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1185 mUserPresent = true;
1186 updateRunning();
1187 }
1188 }
1189 };
1190
1191 @Override
1192 public void onAttachedToWindow() {
1193 super.onAttachedToWindow();
1194
1195 // Listen for broadcasts related to user-presence
1196 final IntentFilter filter = new IntentFilter();
1197 filter.addAction(Intent.ACTION_SCREEN_OFF);
1198 filter.addAction(Intent.ACTION_USER_PRESENT);
1199 registerReceiver(mReceiver, filter);
1200
Adam Cohend113e0c2010-11-11 10:48:05 -08001201 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001202 mVisible = true;
1203 }
1204
1205 @Override
1206 public void onDetachedFromWindow() {
1207 super.onDetachedFromWindow();
1208 mVisible = false;
1209
Adam Cohend113e0c2010-11-11 10:48:05 -08001210 if (mAttached) {
1211 unregisterReceiver(mReceiver);
1212 mAttached = false;
1213 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001214 updateRunning();
1215 }
1216
1217 public void onWindowVisibilityChanged(int visibility) {
1218 mVisible = visibility == View.VISIBLE;
1219 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001220 // The following code used to be in onResume, but it turns out onResume is called when
1221 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1222 // is a more appropriate event to handle
1223 if (mVisible) {
1224 mAppsCustomizeTabHost.onWindowVisible();
1225 if (!mWorkspaceLoading) {
1226 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001227 // We want to let Launcher draw itself at least once before we force it to build
1228 // layers on all the workspace pages, so that transitioning to Launcher from other
1229 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
1230 // a true draw so we wait until the second preDraw call to be safe
1231 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001232 public boolean onPreDraw() {
Michael Jurka6ee21d22012-02-21 18:20:27 -08001233 // We delay the layer building a bit in order to give
1234 // other message processing a time to run. In particular
1235 // this avoids a delay in hiding the IME if it was
1236 // currently shown, because doing that may involve
1237 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001238 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Winson Chung31ce0732012-05-06 13:36:43 -07001239
Michael Jurka6ee21d22012-02-21 18:20:27 -08001240 observer.removeOnPreDrawListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001241 return true;
1242 }
1243 });
1244 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001245 // When Launcher comes back to foreground, a different Activity might be responsible for
1246 // the app market intent, so refresh the icon
1247 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001248 clearTypedText();
1249 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001250 }
1251
1252 private void sendAdvanceMessage(long delay) {
1253 mHandler.removeMessages(ADVANCE_MSG);
1254 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1255 mHandler.sendMessageDelayed(msg, delay);
1256 mAutoAdvanceSentTime = System.currentTimeMillis();
1257 }
1258
1259 private void updateRunning() {
1260 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1261 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1262 mAutoAdvanceRunning = autoAdvanceRunning;
1263 if (autoAdvanceRunning) {
1264 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1265 sendAdvanceMessage(delay);
1266 } else {
1267 if (!mWidgetsToAdvance.isEmpty()) {
1268 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1269 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1270 }
1271 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001272 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001273 }
1274 }
1275 }
1276
1277 private final Handler mHandler = new Handler() {
1278 @Override
1279 public void handleMessage(Message msg) {
1280 if (msg.what == ADVANCE_MSG) {
1281 int i = 0;
1282 for (View key: mWidgetsToAdvance.keySet()) {
1283 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1284 final int delay = mAdvanceStagger * i;
1285 if (v instanceof Advanceable) {
1286 postDelayed(new Runnable() {
1287 public void run() {
1288 ((Advanceable) v).advance();
1289 }
1290 }, delay);
1291 }
1292 i++;
1293 }
1294 sendAdvanceMessage(mAdvanceInterval);
1295 }
1296 }
1297 };
1298
1299 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001300 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001301 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1302 if (v instanceof Advanceable) {
1303 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001304 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001305 updateRunning();
1306 }
1307 }
1308
1309 void removeWidgetToAutoAdvance(View hostView) {
1310 if (mWidgetsToAdvance.containsKey(hostView)) {
1311 mWidgetsToAdvance.remove(hostView);
1312 updateRunning();
1313 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001314 }
1315
Joe Onorato9c1289c2009-08-17 11:03:03 -04001316 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001317 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001318 launcherInfo.hostView = null;
1319 }
1320
Winson Chung93eef082012-03-23 15:59:27 -07001321 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1322 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1323 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001324 }
1325
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001326 public LauncherAppWidgetHost getAppWidgetHost() {
1327 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001328 }
Romain Guycbb89e42009-06-08 15:52:54 -07001329
Winson Chunga9abd0e2010-10-27 17:18:37 -07001330 public LauncherModel getModel() {
1331 return mModel;
1332 }
1333
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001334 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001335 getWindow().closeAllPanels();
1336
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001337 // Whatever we were doing is hereby canceled.
1338 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001339 }
1340
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001341 @Override
1342 protected void onNewIntent(Intent intent) {
1343 super.onNewIntent(intent);
1344
1345 // Close the menu
1346 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001347 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001348 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001349
Joe Onorato14f122b2009-11-19 14:06:36 -08001350 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1351 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001352
Adam Cohenac56cff2011-09-28 20:45:37 -07001353 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001354 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001355 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001356 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1357 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001358 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001359 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001360
1361 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001362 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001363 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001364
Joe Onorato3a8820b2009-11-10 15:06:42 -08001365 final View v = getWindow().peekDecorView();
1366 if (v != null && v.getWindowToken() != null) {
1367 InputMethodManager imm = (InputMethodManager)getSystemService(
1368 INPUT_METHOD_SERVICE);
1369 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001370 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001371
Michael Jurka35aa14d2011-07-07 17:01:08 -07001372 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001373 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001374 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001375 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001376 }
1377 }
1378
1379 @Override
1380 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1381 // Do not call super here
1382 mSavedInstanceState = savedInstanceState;
1383 }
1384
1385 @Override
1386 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001387 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001388 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001389
Michael Jurka883f55b2010-10-21 15:47:14 -07001390 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001391 // We close any open folder since it will not be re-opened, and we need to make sure
1392 // this state is reflected.
1393 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001394
Winson Chung3d503fb2011-07-13 17:25:49 -07001395 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1396 mWaitingForResult) {
1397 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1398 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1399 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1400 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001401 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1402 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1403 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001404 }
1405
1406 if (mFolderInfo != null && mWaitingForResult) {
1407 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1408 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1409 }
Michael Jurka946ad472010-07-09 18:05:18 -07001410
Winson Chung785d2eb2011-04-14 16:08:02 -07001411 // Save the current AppsCustomize tab
1412 if (mAppsCustomizeTabHost != null) {
1413 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1414 if (currentTabTag != null) {
1415 outState.putString("apps_customize_currentTab", currentTabTag);
1416 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001417 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1418 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001419 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001420 }
1421
1422 @Override
1423 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001424 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001425
Winson Chunge7a03942011-08-05 15:05:12 -07001426 // Remove all pending runnables
1427 mHandler.removeMessages(ADVANCE_MSG);
1428 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001429 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001430
Winson Chungcd2b0142011-06-08 16:02:26 -07001431 // Stop callbacks from LauncherModel
1432 LauncherApplication app = ((LauncherApplication) getApplication());
1433 mModel.stopLoader();
1434 app.setLauncher(null);
1435
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001436 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001437 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001438 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001439 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001440 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001441 mAppWidgetHost = null;
1442
1443 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001444
1445 TextKeyListener.getInstance().release();
1446
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001447
Winson Chung3d503fb2011-07-13 17:25:49 -07001448 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001449
1450 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001451 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001452
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001453 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001454 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1455 mWorkspace.removeAllViews();
1456 mWorkspace = null;
1457 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001458
1459 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001460 }
1461
Adam Cohena9cf38f2011-05-02 15:36:58 -07001462 public DragController getDragController() {
1463 return mDragController;
1464 }
1465
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001466 @Override
1467 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001468 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001469 super.startActivityForResult(intent, requestCode);
1470 }
1471
Winson Chung70d72102011-08-12 11:24:35 -07001472 /**
1473 * Indicates that we want global search for this activity by setting the globalSearch
1474 * argument for {@link #startSearch} to true.
1475 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001476 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001477 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001478 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001479
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001480 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001481
Karl Rosaen138a0412009-04-23 19:00:21 -07001482 if (initialQuery == null) {
1483 // Use any text typed in the launcher as the initial query
1484 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001485 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001486 if (appSearchData == null) {
1487 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001488 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001489 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001490 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001491
Karl Rosaen138a0412009-04-23 19:00:21 -07001492 final SearchManager searchManager =
1493 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001494 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001495 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001496 }
1497
Winson Chung70d72102011-08-12 11:24:35 -07001498 @Override
1499 public boolean onCreateOptionsMenu(Menu menu) {
1500 if (isWorkspaceLocked()) {
1501 return false;
1502 }
1503
1504 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001505
1506 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1507 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1508 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001509 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1510 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1511 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001512 String helpUrl = getString(R.string.help_url);
1513 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001514 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1515 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1516
Winson Chung70d72102011-08-12 11:24:35 -07001517 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1518 .setIcon(android.R.drawable.ic_menu_gallery)
1519 .setAlphabeticShortcut('W');
1520 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1521 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001522 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001523 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001524 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1525 .setIcon(android.R.drawable.ic_menu_preferences)
1526 .setIntent(settings)
1527 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001528 if (!helpUrl.isEmpty()) {
1529 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1530 .setIcon(android.R.drawable.ic_menu_help)
1531 .setIntent(help)
1532 .setAlphabeticShortcut('H');
1533 }
Winson Chung70d72102011-08-12 11:24:35 -07001534 return true;
1535 }
1536
1537 @Override
1538 public boolean onPrepareOptionsMenu(Menu menu) {
1539 super.onPrepareOptionsMenu(menu);
1540
1541 if (mAppsCustomizeTabHost.isTransitioning()) {
1542 return false;
1543 }
1544 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1545 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1546
1547 return true;
1548 }
1549
1550 @Override
1551 public boolean onOptionsItemSelected(MenuItem item) {
1552 switch (item.getItemId()) {
1553 case MENU_WALLPAPER_SETTINGS:
1554 startWallpaper();
1555 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001556 }
1557
1558 return super.onOptionsItemSelected(item);
1559 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001560
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001561 @Override
1562 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001563 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001564 // Use a custom animation for launching search
1565 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001566 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001567 }
1568
Joe Onorato9c1289c2009-08-17 11:03:03 -04001569 public boolean isWorkspaceLocked() {
1570 return mWorkspaceLoading || mWaitingForResult;
1571 }
1572
Michael Jurka0280c3b2010-09-17 15:00:07 -07001573 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001574 mPendingAddInfo.container = ItemInfo.NO_ID;
1575 mPendingAddInfo.screen = -1;
1576 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1577 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001578 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001579 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001580 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001581
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001582 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1583 AppWidgetProviderInfo appWidgetInfo) {
1584 if (appWidgetInfo.configure != null) {
1585 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001586
Bjorn Bringert7984c942009-12-09 15:38:25 +00001587 // Launch over to configure widget, if needed
1588 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001589 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001590 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Romain Guy8e633c52010-03-04 12:51:36 -08001591 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001592 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001593 // Otherwise just add it
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001594 completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget,
1595 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001596 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001597 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001598 }
1599 }
Romain Guycbb89e42009-06-08 15:52:54 -07001600
Adam Cohenfbba09b2011-07-18 21:43:05 -07001601 /**
1602 * Process a shortcut drop.
1603 *
1604 * @param componentName The name of the component
1605 * @param screen The screen where it should be added
1606 * @param cell The cell it should be added to, optional
1607 * @param position The location on the screen where it was dropped, optional
1608 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001609 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1610 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001611 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001612 mPendingAddInfo.container = container;
1613 mPendingAddInfo.screen = screen;
1614 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001615
1616 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001617 mPendingAddInfo.cellX = cell[0];
1618 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001619 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001620
1621 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1622 createShortcutIntent.setComponent(componentName);
1623 processShortcut(createShortcutIntent);
1624 }
1625
Adam Cohenfbba09b2011-07-18 21:43:05 -07001626 /**
1627 * Process a widget drop.
1628 *
1629 * @param info The PendingAppWidgetInfo of the widget being added.
1630 * @param screen The screen where it should be added
1631 * @param cell The cell it should be added to, optional
1632 * @param position The location on the screen where it was dropped, optional
1633 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001634 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
Adam Cohend41fbf52012-02-16 23:53:59 -08001635 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001636 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001637 mPendingAddInfo.container = info.container = container;
1638 mPendingAddInfo.screen = info.screen = screen;
1639 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001640 mPendingAddInfo.minSpanX = info.minSpanX;
1641 mPendingAddInfo.minSpanY = info.minSpanY;
1642
Adam Cohenfbba09b2011-07-18 21:43:05 -07001643 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001644 mPendingAddInfo.cellX = cell[0];
1645 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001646 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001647 if (span != null) {
1648 mPendingAddInfo.spanX = span[0];
1649 mPendingAddInfo.spanY = span[1];
1650 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001651
Adam Cohened66b2b2012-01-23 17:28:51 -08001652 AppWidgetHostView hostView = info.boundWidget;
1653 int appWidgetId;
1654 if (hostView != null) {
1655 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001656 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001657 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001658 // In this case, we either need to start an activity to get permission to bind
1659 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001660 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Michael Jurka8b805b12012-04-18 14:23:14 -07001661 if (mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName)) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001662 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001663 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001664 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001665 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1666 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1667 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
1668 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1669 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001670 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001671 }
1672
Joe Onoratodeb98af2010-02-19 14:59:39 -08001673 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001674 // Handle case where user selected "Applications"
1675 String applicationName = getResources().getString(R.string.group_applications);
1676 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001677
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001678 if (applicationName != null && applicationName.equals(shortcutName)) {
1679 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1680 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001681
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001682 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1683 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001684 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001685 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001686 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001687 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001688 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001689 }
1690
Winson Chung24ab2f12010-09-16 14:10:47 -07001691 void processWallpaper(Intent intent) {
1692 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1693 }
1694
Winson Chung3d503fb2011-07-13 17:25:49 -07001695 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1696 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001697 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001698 folderInfo.title = getText(R.string.folder_name);
1699
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001700 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001701 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1702 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001703 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001704
1705 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001706 FolderIcon newFolder =
1707 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1708 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1709 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001710 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001711 }
Romain Guycbb89e42009-06-08 15:52:54 -07001712
Joe Onorato9c1289c2009-08-17 11:03:03 -04001713 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001714 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001715 }
1716
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001718 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001719 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001720 Intent chooser = Intent.createChooser(pickWallpaper,
1721 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001722 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1723 // Removed in Eclair MR1
1724// WallpaperManager wm = (WallpaperManager)
1725// getSystemService(Context.WALLPAPER_SERVICE);
1726// WallpaperInfo wi = wm.getWallpaperInfo();
1727// if (wi != null && wi.getSettingsActivity() != null) {
1728// LabeledIntent li = new LabeledIntent(getPackageName(),
1729// R.string.configure_wallpaper, 0);
1730// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1731// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1732// }
Mike Clerona0618e42009-10-22 13:55:21 -07001733 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001734 }
1735
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001736 /**
1737 * Registers various content observers. The current implementation registers
1738 * only a favorites observer to keep track of the favorites applications.
1739 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001740 private void registerContentObservers() {
1741 ContentResolver resolver = getContentResolver();
1742 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1743 true, mWidgetObserver);
1744 }
1745
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001746 @Override
1747 public boolean dispatchKeyEvent(KeyEvent event) {
1748 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1749 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001750 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001751 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001752 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001753 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001754 dumpState();
1755 return true;
1756 }
1757 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001758 }
1759 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1760 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001761 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001762 return true;
1763 }
1764 }
1765
1766 return super.dispatchKeyEvent(event);
1767 }
1768
Joe Onorato88ec0992009-11-19 13:16:06 -08001769 @Override
1770 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001771 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001772 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001773 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001774 Folder openFolder = mWorkspace.getOpenFolder();
1775 if (openFolder.isEditingName()) {
1776 openFolder.dismissEditingName();
1777 } else {
1778 closeFolder();
1779 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001780 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001781 mWorkspace.exitWidgetResizeMode();
1782
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001783 // Back button is a no-op here, but give at least some feedback for the button press
1784 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001785 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001786 }
1787
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001788 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001789 * Re-listen when widgets are reset.
1790 */
1791 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001792 if (mAppWidgetHost != null) {
1793 mAppWidgetHost.startListening();
1794 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001795 }
1796
1797 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001798 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1799 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001800 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001801 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001802 if (mModel != null) {
1803 mModel.unbindWorkspaceItems();
1804 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001805 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001806
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001807 /**
1808 * Launches the intent referred by the clicked shortcut.
1809 *
1810 * @param v The view representing the clicked shortcut.
1811 */
1812 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001813 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1814 // view has detached (it's possible for this to happen if the view is removed mid touch).
1815 if (v.getWindowToken() == null) {
1816 return;
1817 }
1818
Winson Chung9b0b2fe2012-02-24 13:03:34 -08001819 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001820 return;
1821 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001822
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001823 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001824 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001825 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001826 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001827 int[] pos = new int[2];
1828 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001829 intent.setSourceBounds(new Rect(pos[0], pos[1],
1830 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07001831
1832 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001833
1834 if (success && v instanceof BubbleTextView) {
1835 mWaitingForResume = (BubbleTextView) v;
1836 mWaitingForResume.setStayPressed(true);
1837 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001838 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001839 if (v instanceof FolderIcon) {
1840 FolderIcon fi = (FolderIcon) v;
1841 handleFolderClick(fi);
1842 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001843 } else if (v == mAllAppsButton) {
1844 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001845 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001846 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001847 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001848 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001849 }
1850 }
1851
Michael Jurka0e260592010-06-30 17:07:39 -07001852 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001853 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001854 // clicking anywhere on the workspace causes the customization drawer to slide down
1855 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001856 return false;
1857 }
1858
Michael Jurkaaf442092010-06-10 17:01:57 -07001859 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001860 * Event handler for the search button
1861 *
1862 * @param v The view that was clicked.
1863 */
1864 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001865 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1866
Amith Yamasania135ba82011-08-09 17:42:01 -07001867 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001868 }
1869
1870 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001871 * Event handler for the voice button
1872 *
1873 * @param v The view that was clicked.
1874 */
1875 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001876 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001877
Michael Jurkaae65ee32012-04-30 11:45:54 -07001878 try {
1879 final SearchManager searchManager =
1880 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1881 ComponentName activityName = searchManager.getGlobalSearchActivity();
1882 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07001883 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001884 if (activityName != null) {
1885 intent.setPackage(activityName.getPackageName());
1886 }
Michael Jurka86a720e2012-05-09 11:23:23 -07001887 startActivity(null, intent, "onClickVoiceButton");
Winson Chung01b0b632012-05-22 10:18:14 -07001888 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001889 } catch (ActivityNotFoundException e) {
1890 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07001891 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001892 startActivitySafely(null, intent, "onClickVoiceButton");
1893 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001894 }
1895
1896 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001897 * Event handler for the "grid" button that appears on the home screen, which
1898 * enters all apps mode.
1899 *
1900 * @param v The view that was clicked.
1901 */
1902 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001903 showAllApps(true);
1904 }
1905
1906 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001907 // Provide the same haptic feedback that the system offers for virtual keys.
1908 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001909 }
1910
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001911 public void onClickAppMarketButton(View v) {
1912 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07001913 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07001914 } else {
1915 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001916 }
1917 }
1918
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001919 void startApplicationDetailsActivity(ComponentName componentName) {
1920 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001921 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1922 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001923 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07001924 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001925 }
1926
Patrick Dubroy5539af72010-09-07 15:22:01 -07001927 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1928 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1929 // System applications cannot be installed. For now, show a toast explaining that.
1930 // We may give them the option of disabling apps this way.
1931 int messageId = R.string.uninstall_system_app_text;
1932 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1933 } else {
1934 String packageName = appInfo.componentName.getPackageName();
1935 String className = appInfo.componentName.getClassName();
1936 Intent intent = new Intent(
1937 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001938 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1939 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001940 startActivity(intent);
1941 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001942 }
1943
Michael Jurka86a720e2012-05-09 11:23:23 -07001944 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001945 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07001946
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001947 try {
Winson Chung2672ff92012-05-04 16:22:30 -07001948 // Only launch using the new animation if the shortcut has not opted out (this is a
1949 // private contract between launcher and may be ignored in the future).
1950 boolean useLaunchAnimation = (v != null) &&
1951 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
1952 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07001953 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
1954 v.getMeasuredWidth(), v.getMeasuredHeight());
1955
1956 startActivity(intent, opts.toBundle());
1957 } else {
1958 startActivity(intent);
1959 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001960 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001961 } catch (SecurityException e) {
1962 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001963 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001964 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001965 "or use the exported attribute for this activity. "
1966 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001967 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001968 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001969 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001970
Michael Jurka86a720e2012-05-09 11:23:23 -07001971 boolean startActivitySafely(View v, Intent intent, Object tag) {
1972 boolean success = false;
1973 try {
1974 success = startActivity(v, intent, tag);
1975 } catch (ActivityNotFoundException e) {
1976 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1977 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
1978 }
1979 return success;
1980 }
1981
Romain Guy8e633c52010-03-04 12:51:36 -08001982 void startActivityForResultSafely(Intent intent, int requestCode) {
1983 try {
1984 startActivityForResult(intent, requestCode);
1985 } catch (ActivityNotFoundException e) {
1986 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1987 } catch (SecurityException e) {
1988 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1989 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1990 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1991 "or use the exported attribute for this activity.", e);
1992 }
1993 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001994
Adam Cohena9cf38f2011-05-02 15:36:58 -07001995 private void handleFolderClick(FolderIcon folderIcon) {
1996 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07001997 Folder openFolder = mWorkspace.getFolderForTag(info);
1998
1999 // If the folder info reports that the associated folder is open, then verify that
2000 // it is actually opened. There have been a few instances where this gets out of sync.
2001 if (info.opened && openFolder == null) {
2002 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2003 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
2004 info.opened = false;
2005 }
2006
Adam Cohena9cf38f2011-05-02 15:36:58 -07002007 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002008 // Close any open folder
2009 closeFolder();
2010 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002011 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002012 } else {
2013 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002014 int folderScreen;
2015 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002016 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002017 // .. and close it
2018 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002019 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002020 // Close any folder open on the current screen
2021 closeFolder();
2022 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002023 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002024 }
2025 }
2026 }
2027 }
2028
Adam Cohen268c4752012-06-06 17:47:33 -07002029 /**
2030 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2031 * in the DragLayer in the exact absolute location of the original FolderIcon.
2032 */
2033 private void copyFolderIconToImage(FolderIcon fi) {
2034 final int width = fi.getMeasuredWidth();
2035 final int height = fi.getMeasuredHeight();
2036
2037 // Lazy load ImageView, Bitmap and Canvas
2038 if (mFolderIconImageView == null) {
2039 mFolderIconImageView = new ImageView(this);
2040 }
2041 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2042 mFolderIconBitmap.getHeight() != height) {
2043 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2044 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2045 }
2046
2047 DragLayer.LayoutParams lp;
2048 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2049 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2050 } else {
2051 lp = new DragLayer.LayoutParams(width, height);
2052 }
2053
2054 mDragLayer.getViewRectRelativeToSelf(fi, mRectForFolderAnimation);
2055 lp.customPosition = true;
2056 lp.x = mRectForFolderAnimation.left;
2057 lp.y = mRectForFolderAnimation.top;
Adam Cohen8ec23032012-06-08 14:46:22 -07002058 lp.width = width;
2059 lp.height = height;
Adam Cohen268c4752012-06-06 17:47:33 -07002060
2061 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2062 fi.draw(mFolderIconCanvas);
2063 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohen8ec23032012-06-08 14:46:22 -07002064 if (fi.mFolder != null) {
2065 mFolderIconImageView.setPivotX(fi.mFolder.getPivotXForIconAnimation());
2066 mFolderIconImageView.setPivotY(fi.mFolder.getPivotYForIconAnimation());
2067 }
Adam Cohen268c4752012-06-06 17:47:33 -07002068 // Just in case this image view is still in the drag layer from a previous animation,
2069 // we remove it and re-add it.
2070 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2071 mDragLayer.removeView(mFolderIconImageView);
2072 }
2073 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohen8ec23032012-06-08 14:46:22 -07002074 if (fi.mFolder != null) {
2075 fi.mFolder.bringToFront();
2076 }
Adam Cohen268c4752012-06-06 17:47:33 -07002077 }
2078
Adam Cohen2801caf2011-05-13 20:57:39 -07002079 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002080 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002081 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2082 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2083 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2084
Adam Cohenc51934b2011-07-26 21:07:43 -07002085 FolderInfo info = (FolderInfo) fi.getTag();
2086 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2087 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002088 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2089 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002090 }
2091
Adam Cohen268c4752012-06-06 17:47:33 -07002092 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2093 copyFolderIconToImage(fi);
2094 fi.setVisibility(View.INVISIBLE);
2095
2096 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(mFolderIconImageView, alpha,
2097 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002098 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2099 oa.start();
2100 }
2101
Adam Cohen268c4752012-06-06 17:47:33 -07002102 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002103 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002104 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2105 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2106 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2107
Adam Cohen268c4752012-06-06 17:47:33 -07002108 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002109
Adam Cohen268c4752012-06-06 17:47:33 -07002110 // We remove and re-draw the FolderIcon in-case it has changed
2111 mDragLayer.removeView(mFolderIconImageView);
2112 copyFolderIconToImage(fi);
Adam Cohen268c4752012-06-06 17:47:33 -07002113 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(mFolderIconImageView, alpha,
2114 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002115 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002116 oa.addListener(new AnimatorListenerAdapter() {
2117 @Override
2118 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002119 if (cl != null) {
2120 cl.clearFolderLeaveBehind();
2121 // Remove the ImageView copy of the FolderIcon and make the original visible.
2122 mDragLayer.removeView(mFolderIconImageView);
2123 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002124 }
2125 }
2126 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002127 oa.start();
2128 }
2129
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002130 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002131 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002132 * is animated relative to the specified View. If the View is null, no animation
2133 * is played.
2134 *
2135 * @param folderInfo The FolderInfo describing the folder to open.
2136 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002137 public void openFolder(FolderIcon folderIcon) {
2138 Folder folder = folderIcon.mFolder;
2139 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002140
Adam Cohena9cf38f2011-05-02 15:36:58 -07002141 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002142
Adam Cohen4554ee12011-08-03 16:13:21 -07002143 // Just verify that the folder hasn't already been added to the DragLayer.
2144 // There was a one-off crash where the folder had a parent already.
2145 if (folder.getParent() == null) {
2146 mDragLayer.addView(folder);
2147 mDragController.addDropTarget((DropTarget) folder);
2148 } else {
2149 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2150 folder.getParent() + ").");
2151 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002152 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002153 growAndFadeOutFolderIcon(folderIcon);
Adam Cohen4554ee12011-08-03 16:13:21 -07002154 }
2155
2156 public void closeFolder() {
2157 Folder folder = mWorkspace.getOpenFolder();
2158 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002159 if (folder.isEditingName()) {
2160 folder.dismissEditingName();
2161 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002162 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002163
2164 // Dismiss the folder cling
2165 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002166 }
2167 }
2168
2169 void closeFolder(Folder folder) {
2170 folder.getInfo().opened = false;
2171
2172 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2173 if (parent != null) {
2174 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2175 shrinkAndFadeInFolderIcon(fi);
2176 }
2177 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002178 }
2179
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002180 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002181 if (!isDraggingEnabled()) return false;
2182 if (isWorkspaceLocked()) return false;
2183 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002184
2185 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002186 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002187 }
2188
Michael Jurka0280c3b2010-09-17 15:00:07 -07002189 resetAddInfo();
2190 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002191 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002192 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002193 return true;
2194 }
2195
Winson Chung3d503fb2011-07-13 17:25:49 -07002196 // The hotseat touch handling does not go through Workspace, and we always allow long press
2197 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002198 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002199 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2200 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002201 if (itemUnderLongClick == null) {
2202 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002203 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2204 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002205 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002206 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002207 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002208 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002209 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002210 }
2211 }
2212 }
2213 return true;
2214 }
2215
Winson Chung3d503fb2011-07-13 17:25:49 -07002216 boolean isHotseatLayout(View layout) {
2217 return mHotseat != null && layout != null &&
2218 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2219 }
2220 Hotseat getHotseat() {
2221 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002222 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002223 SearchDropTargetBar getSearchBar() {
2224 return mSearchDropTargetBar;
2225 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002226
Winson Chung3d503fb2011-07-13 17:25:49 -07002227 /**
2228 * Returns the CellLayout of the specified container at the specified screen.
2229 */
2230 CellLayout getCellLayout(long container, int screen) {
2231 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2232 if (mHotseat != null) {
2233 return mHotseat.getLayout();
2234 } else {
2235 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002236 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002237 } else {
2238 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002239 }
2240 }
2241
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002242 Workspace getWorkspace() {
2243 return mWorkspace;
2244 }
2245
Daniel Sandler843e8602010-06-07 14:59:01 -04002246 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2247 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002248 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002249 }
2250
Andrew Flynn0dca1ec2012-02-29 13:33:22 -08002251 public boolean isAllAppsButtonRank(int rank) {
2252 return mHotseat.isAllAppsButtonRank(rank);
2253 }
2254
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002255 // AllAppsView.Watcher
2256 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002257 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002258 mWorkspace.setVisibility(View.GONE);
2259 }
2260 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002261
2262 /**
2263 * Helper method for the cameraZoomIn/cameraZoomOut animations
2264 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002265 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002266 * @param scaleFactor The scale factor used for the zoom
2267 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002268 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002269 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002270 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002271 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002272
Winson Chung18f41f82012-05-09 13:28:10 -07002273 void disableWallpaperIfInAllApps() {
2274 // Only disable it if we are in all apps
2275 if (mState == State.APPS_CUSTOMIZE) {
2276 if (mAppsCustomizeTabHost != null &&
2277 !mAppsCustomizeTabHost.isTransitioning()) {
2278 updateWallpaperVisibility(false);
2279 }
2280 }
2281 }
2282
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002283 void updateWallpaperVisibility(boolean visible) {
2284 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2285 int curflags = getWindow().getAttributes().flags
2286 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2287 if (wpflags != curflags) {
2288 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2289 }
2290 }
2291
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002292 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2293 if (v instanceof LauncherTransitionable) {
2294 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2295 }
2296 }
2297
Michael Jurkabed61d22012-02-14 22:51:29 -08002298 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2299 if (v instanceof LauncherTransitionable) {
2300 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2301 }
Winson Chung70442722012-02-10 15:43:22 -08002302
2303 // Update the workspace transition step as well
2304 dispatchOnLauncherTransitionStep(v, 0f);
2305 }
2306
2307 private void dispatchOnLauncherTransitionStep(View v, float t) {
2308 if (v instanceof LauncherTransitionable) {
2309 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2310 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002311 }
2312
2313 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2314 if (v instanceof LauncherTransitionable) {
2315 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2316 }
Winson Chung70442722012-02-10 15:43:22 -08002317
2318 // Update the workspace transition step as well
2319 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002320 }
2321
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002322 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002323 * Things to test when changing the following seven functions.
2324 * - Home from workspace
2325 * - from center screen
2326 * - from other screens
2327 * - Home from all apps
2328 * - from center screen
2329 * - from other screens
2330 * - Back from all apps
2331 * - from center screen
2332 * - from other screens
2333 * - Launch app from workspace and quit
2334 * - with back
2335 * - with home
2336 * - Launch app from all apps and quit
2337 * - with back
2338 * - with home
2339 * - Go to a screen that's not the default, then all
2340 * apps, and launch and app, and go back
2341 * - with back
2342 * -with home
2343 * - On workspace, long press power and go back
2344 * - with back
2345 * - with home
2346 * - On all apps, long press power and go back
2347 * - with back
2348 * - with home
2349 * - On workspace, power off
2350 * - On all apps, power off
2351 * - Launch an app and turn off the screen while in that app
2352 * - Go back with home key
2353 * - Go back with back key TODO: make this not go to workspace
2354 * - From all apps
2355 * - From workspace
2356 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2357 * - From all apps
2358 * - From the center workspace
2359 * - From another workspace
2360 */
2361
2362 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002363 * Zoom the camera out from the workspace to reveal 'toView'.
2364 * Assumes that the view to show is anchored at either the very top or very bottom
2365 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002366 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002367 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002368 if (mStateAnimation != null) {
2369 mStateAnimation.cancel();
2370 mStateAnimation = null;
2371 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002372 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002373
Winson Chungf0ea4d32011-06-06 14:27:16 -07002374 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2375 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2376 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002377 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002378 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002379 final int startDelay =
2380 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002381
Michael Jurkab3e22d92011-10-31 15:58:33 -07002382 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002383
Michael Jurkad74c9842011-07-10 12:44:21 -07002384 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002385 Animator workspaceAnim =
2386 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002387
2388 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002389 toView.setScaleX(scale);
2390 toView.setScaleY(scale);
2391 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2392 scaleAnim.
2393 scaleX(1f).scaleY(1f).
2394 setDuration(duration).
2395 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002396
Winson Chungf0ea4d32011-06-06 14:27:16 -07002397 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002398 toView.setAlpha(0f);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002399 final ObjectAnimator alphaAnim = ObjectAnimator
2400 .ofFloat(toView, "alpha", 0f, 1f)
2401 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002402 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002403 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2404 @Override
2405 public void onAnimationUpdate(ValueAnimator animation) {
2406 float t = (Float) animation.getAnimatedValue();
2407 dispatchOnLauncherTransitionStep(fromView, t);
2408 dispatchOnLauncherTransitionStep(toView, t);
2409 }
2410 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002411
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002412 // toView should appear right at the end of the workspace shrink
2413 // animation
2414 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002415 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002416 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002417
2418 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002419 boolean animationCancelled = false;
2420
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002421 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002422 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002423 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002424 // Prepare the position
2425 toView.setTranslationX(0.0f);
2426 toView.setTranslationY(0.0f);
2427 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002428 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002429 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002430 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002431 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002432 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2433 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002434
2435 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2436 // Hide the workspace scrollbar
2437 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002438 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002439 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002440 if (!animationCancelled) {
2441 updateWallpaperVisibility(false);
2442 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002443
2444 // Hide the search bar
2445 mSearchDropTargetBar.hideSearchBar(false);
Adam Cohenf4ddea32011-09-12 13:46:42 -07002446 }
2447
Adam Cohencff6af82011-09-13 14:51:53 -07002448 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002449 public void onAnimationCancel(Animator animation) {
2450 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002451 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002452 });
2453
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002454 if (workspaceAnim != null) {
2455 mStateAnimation.play(workspaceAnim);
2456 }
Michael Jurka1899a362011-11-03 13:50:45 -07002457
2458 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002459 final ViewTreeObserver observer;
2460
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002461 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2462 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002463
2464 // If any of the objects being animated haven't been measured/laid out
2465 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002466 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002467 (mWorkspace.getMeasuredWidth() == 0) ||
2468 (toView.getMeasuredWidth() == 0)) {
2469 observer = mWorkspace.getViewTreeObserver();
2470 delayAnim = true;
2471 } else {
2472 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002473 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002474
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002475 final AnimatorSet stateAnimation = mStateAnimation;
2476 final Runnable startAnimRunnable = new Runnable() {
2477 public void run() {
2478 // Check that mStateAnimation hasn't changed while
2479 // we waited for a layout/draw pass
2480 if (mStateAnimation != stateAnimation)
2481 return;
2482 setPivotsForZoom(toView, scale);
2483 dispatchOnLauncherTransitionStart(fromView, animated, false);
2484 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurka382aa182012-06-11 15:42:07 -07002485 toView.post(new Runnable() {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002486 public void run() {
2487 // Check that mStateAnimation hasn't changed while
2488 // we waited for a layout/draw pass
2489 if (mStateAnimation != stateAnimation)
2490 return;
2491 mStateAnimation.start();
2492 }
2493 });
2494 }
2495 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002496 if (delayAnim) {
2497 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2498 public void onGlobalLayout() {
Michael Jurka382aa182012-06-11 15:42:07 -07002499 toView.post(startAnimRunnable);
Michael Jurka3a9fced2012-04-13 14:44:29 -07002500 observer.removeOnGlobalLayoutListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002501 }
2502 };
2503 observer.addOnGlobalLayoutListener(delayedStart);
2504 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002505 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002506 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002507 } else {
2508 toView.setTranslationX(0.0f);
2509 toView.setTranslationY(0.0f);
2510 toView.setScaleX(1.0f);
2511 toView.setScaleY(1.0f);
2512 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002513 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002514
Michael Jurkabed61d22012-02-14 22:51:29 -08002515 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2516 // Hide the workspace scrollbar
2517 mWorkspace.hideScrollingIndicator(true);
2518 hideDockDivider();
Winson Chungc7d2b602012-05-16 17:02:20 -07002519
2520 // Hide the search bar
2521 mSearchDropTargetBar.hideSearchBar(false);
Michael Jurkaabded662011-03-04 12:06:57 -08002522 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002523 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002524 dispatchOnLauncherTransitionStart(fromView, animated, false);
2525 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002526 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002527 dispatchOnLauncherTransitionStart(toView, animated, false);
2528 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002529 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002530 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002531 }
2532
2533 /**
2534 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002535 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002536 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002537 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002538 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2539 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002540
Michael Jurkab3e22d92011-10-31 15:58:33 -07002541 if (mStateAnimation != null) {
2542 mStateAnimation.cancel();
2543 mStateAnimation = null;
2544 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002545 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002546
Winson Chungf0ea4d32011-06-06 14:27:16 -07002547 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002548 final int fadeOutDuration =
2549 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002550 final float scaleFactor = (float)
2551 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2552 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002553 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002554 Animator workspaceAnim = null;
2555
2556 if (toState == State.WORKSPACE) {
2557 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2558 workspaceAnim = mWorkspace.getChangeStateAnimation(
2559 Workspace.State.NORMAL, animated, stagger);
2560 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2561 workspaceAnim = mWorkspace.getChangeStateAnimation(
2562 Workspace.State.SPRING_LOADED, animated);
2563 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002564
Michael Jurkab3e22d92011-10-31 15:58:33 -07002565 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002566 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002567 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002568 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002569 final LauncherViewPropertyAnimator scaleAnim =
2570 new LauncherViewPropertyAnimator(fromView);
2571 scaleAnim.
2572 scaleX(scaleFactor).scaleY(scaleFactor).
2573 setDuration(duration).
2574 setInterpolator(new Workspace.ZoomInInterpolator());
2575
2576 final ObjectAnimator alphaAnim = ObjectAnimator
2577 .ofFloat(fromView, "alpha", 1f, 0f)
2578 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002579 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002580 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2581 @Override
2582 public void onAnimationUpdate(ValueAnimator animation) {
2583 float t = 1f - (Float) animation.getAnimatedValue();
2584 dispatchOnLauncherTransitionStep(fromView, t);
2585 dispatchOnLauncherTransitionStep(toView, t);
2586 }
2587 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002588
Michael Jurkabed61d22012-02-14 22:51:29 -08002589 mStateAnimation = new AnimatorSet();
2590
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002591 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2592 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002593
2594 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002595 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002596 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002597 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002598 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002599 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2600 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkabafdaaf2012-04-26 13:43:25 -07002601 if (mWorkspace != null) {
2602 mWorkspace.hideScrollingIndicator(false);
2603 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002604 if (onCompleteRunnable != null) {
2605 onCompleteRunnable.run();
2606 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002607 }
2608 });
2609
Winson Chungf0ea4d32011-06-06 14:27:16 -07002610 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002611 if (workspaceAnim != null) {
2612 mStateAnimation.play(workspaceAnim);
2613 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002614 dispatchOnLauncherTransitionStart(fromView, animated, true);
2615 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002616 final Animator stateAnimation = mStateAnimation;
2617 mWorkspace.post(new Runnable() {
2618 public void run() {
2619 if (stateAnimation != mStateAnimation)
2620 return;
2621 mStateAnimation.start();
2622 }
2623 });
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002624 } else {
2625 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002626 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002627 dispatchOnLauncherTransitionStart(fromView, animated, true);
2628 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002629 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002630 dispatchOnLauncherTransitionStart(toView, animated, true);
2631 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002632 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002633 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002634 }
2635
Michael Jurkae326f182011-11-21 14:05:46 -08002636 @Override
2637 public void onTrimMemory(int level) {
2638 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002639 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002640 mAppsCustomizeTabHost.onTrimMemory();
2641 }
2642 }
2643
Winson Chung18f41f82012-05-09 13:28:10 -07002644 @Override
2645 public void onWindowFocusChanged(boolean hasFocus) {
2646 if (!hasFocus) {
2647 // When another window occludes launcher (like the notification shade, or recents),
2648 // ensure that we enable the wallpaper flag so that transitions are done correctly.
2649 updateWallpaperVisibility(true);
2650 } else {
2651 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07002652 mWorkspace.postDelayed(new Runnable() {
2653 @Override
2654 public void run() {
2655 disableWallpaperIfInAllApps();
2656 }
2657 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07002658 }
2659 }
2660
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002661 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002662 showWorkspace(animated, null);
2663 }
2664
2665 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002666 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002667 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002668 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002669 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002670
Winson Chungc7d2b602012-05-16 17:02:20 -07002671 // Show the search bar (only animate if we were showing the drop target bar in spring
2672 // loaded mode)
2673 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
2674
Michael Jurkab737ee62011-11-15 15:57:22 -08002675 // We only need to animate in the dock divider if we're going from spring loaded mode
Winson Chungc7d2b602012-05-16 17:02:20 -07002676 showDockDivider(animated && wasInSpringLoadedMode);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002677
2678 // Set focus to the AppsCustomize button
2679 if (mAllAppsButton != null) {
2680 mAllAppsButton.requestFocus();
2681 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002682 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002683
Michael Jurkab737ee62011-11-15 15:57:22 -08002684 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002685
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002686 // Change the state *after* we've called all the transition code
2687 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002688
Winson Chung5fb63472011-02-02 17:03:37 -08002689 // Resume the auto-advance of widgets
2690 mUserPresent = true;
2691 updateRunning();
2692
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002693 // send an accessibility event to announce the context change
2694 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002695 }
2696
Michael Jurkab3e22d92011-10-31 15:58:33 -07002697 void showAllApps(boolean animated) {
2698 if (mState != State.WORKSPACE) return;
2699
2700 showAppsCustomizeHelper(animated, false);
2701 mAppsCustomizeTabHost.requestFocus();
2702
Michael Jurkab3e22d92011-10-31 15:58:33 -07002703 // Change the state *after* we've called all the transition code
2704 mState = State.APPS_CUSTOMIZE;
2705
2706 // Pause the auto-advance of widgets until we are out of AllApps
2707 mUserPresent = false;
2708 updateRunning();
2709 closeFolder();
2710
2711 // Send an accessibility event to announce the context change
2712 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2713 }
2714
Adam Cohen7777d962011-08-18 18:58:38 -07002715 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002716 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002717 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002718 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002719 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002720 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002721 }
Adam Cohen7777d962011-08-18 18:58:38 -07002722
Adam Cohened66b2b2012-01-23 17:28:51 -08002723 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2724 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002725 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2726
Winson Chunge7a03942011-08-05 15:05:12 -07002727 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002728 @Override
2729 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002730 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002731 // Before we show workspace, hide all apps again because
2732 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2733 // clean up our state transition functions
2734 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002735 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002736 } else {
2737 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002738 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002739 }
2740 }, (extendedDelay ?
2741 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2742 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2743 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002744
Michael Jurkad3ef3062010-11-23 16:23:58 -08002745 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002746 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002747 final boolean animated = true;
2748 final boolean springLoaded = true;
2749 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002750 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002751 }
2752 // Otherwise, we are not in spring loaded mode, so don't do anything.
2753 }
2754
Michael Jurkab737ee62011-11-15 15:57:22 -08002755 void hideDockDivider() {
2756 if (mQsbDivider != null && mDockDivider != null) {
2757 mQsbDivider.setVisibility(View.INVISIBLE);
2758 mDockDivider.setVisibility(View.INVISIBLE);
2759 }
2760 }
2761
2762 void showDockDivider(boolean animated) {
2763 if (mQsbDivider != null && mDockDivider != null) {
2764 mQsbDivider.setVisibility(View.VISIBLE);
2765 mDockDivider.setVisibility(View.VISIBLE);
2766 if (mDividerAnimator != null) {
2767 mDividerAnimator.cancel();
2768 mQsbDivider.setAlpha(1f);
2769 mDockDivider.setAlpha(1f);
2770 mDividerAnimator = null;
2771 }
2772 if (animated) {
2773 mDividerAnimator = new AnimatorSet();
2774 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2775 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2776 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2777 mDividerAnimator.start();
2778 }
2779 }
2780 }
2781
Michael Jurkab3e22d92011-10-31 15:58:33 -07002782 void lockAllApps() {
2783 // TODO
2784 }
2785
2786 void unlockAllApps() {
2787 // TODO
2788 }
2789
Adam Cohenfc53cd22011-07-20 15:45:11 -07002790 public boolean isAllAppsCustomizeOpen() {
2791 return mState == State.APPS_CUSTOMIZE;
2792 }
2793
Winson Chungf0ea4d32011-06-06 14:27:16 -07002794 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002795 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002796 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002797 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002798 if (!LauncherApplication.isScreenLarge()) {
2799 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002800 if (mHotseat.getAlpha() != 1f) {
2801 int duration = mSearchDropTargetBar.getTransitionInDuration();
2802 mHotseat.animate().alpha(1f).setDuration(duration);
2803 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002804 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002805 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002806 }
2807 }
2808 }
2809
2810 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002811 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002812 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002813 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002814 if (!LauncherApplication.isScreenLarge()) {
2815 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002816 if (mHotseat.getAlpha() != 0f) {
2817 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2818 mHotseat.animate().alpha(0f).setDuration(duration);
2819 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002820 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002821 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002822 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002823 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002824 }
2825
Patrick Dubroy5f445422011-02-18 14:35:21 -08002826 /**
2827 * Add an item from all apps or customize onto the given workspace screen.
2828 * If layout is null, add to the current screen.
2829 */
2830 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002831 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07002832 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07002833 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002834 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002835
Winson Chungdff8ebb2011-09-08 17:25:31 -07002836 /** Maps the current orientation to an index for referencing orientation correct global icons */
2837 private int getCurrentOrientationIndexForGlobalIcons() {
2838 // default - 0, landscape - 1
2839 switch (getResources().getConfiguration().orientation) {
2840 case Configuration.ORIENTATION_LANDSCAPE:
2841 return 1;
2842 default:
2843 return 0;
2844 }
2845 }
2846
Michael Jurkaae65ee32012-04-30 11:45:54 -07002847 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002848 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002849 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002850 // Look for the toolbar icon specified in the activity meta-data
2851 Bundle metaData = packageManager.getActivityInfo(
2852 activityName, PackageManager.GET_META_DATA).metaData;
2853 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002854 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002855 if (iconResId != 0) {
2856 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002857 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002858 }
2859 }
2860 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002861 // This can happen if the activity defines an invalid drawable
2862 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2863 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002864 } catch (Resources.NotFoundException nfe) {
2865 // This can happen if the activity defines an invalid drawable
2866 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2867 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002868 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002869 return null;
2870 }
2871
2872 // if successful in getting icon, return it; otherwise, set button to use default drawable
2873 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002874 int buttonId, ComponentName activityName, int fallbackDrawableId,
2875 String toolbarResourceName) {
2876 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002877 Resources r = getResources();
2878 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2879 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002880
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002881 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002882 // If we were unable to find the icon via the meta-data, use a generic one
2883 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002884 toolbarIcon = r.getDrawable(fallbackDrawableId);
2885 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002886 if (button != null) {
2887 button.setCompoundDrawables(toolbarIcon, null, null, null);
2888 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002889 return null;
2890 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002891 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002892 if (button != null) {
2893 button.setCompoundDrawables(toolbarIcon, null, null, null);
2894 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002895 return toolbarIcon.getConstantState();
2896 }
2897 }
2898
2899 // if successful in getting icon, return it; otherwise, set button to use default drawable
2900 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002901 int buttonId, ComponentName activityName, int fallbackDrawableId,
2902 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002903 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002904 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002905
Michael Jurka19e0fc52011-07-22 18:00:21 -07002906 if (button != null) {
2907 // If we were unable to find the icon via the meta-data, use a
2908 // generic one
2909 if (toolbarIcon == null) {
2910 button.setImageResource(fallbackDrawableId);
2911 } else {
2912 button.setImageDrawable(toolbarIcon);
2913 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002914 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002915
2916 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2917
Michael Jurka0423dcf2010-10-05 14:56:18 -07002918 }
2919
Winson Chung1b884092012-06-08 17:13:02 -07002920 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002921 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07002922 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002923 }
2924
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002925 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002926 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002927 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002928 }
2929
Winson Chungbb185bd2011-11-21 12:31:42 -08002930 private void invalidatePressedFocusedStates(View container, View button) {
2931 if (container instanceof HolographicLinearLayout) {
2932 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2933 layout.invalidatePressedFocusedStates();
2934 } else if (button instanceof HolographicImageView) {
2935 HolographicImageView view = (HolographicImageView) button;
2936 view.invalidatePressedFocusedStates();
2937 }
2938 }
2939
Winson Chungc51db6a2011-10-05 11:44:49 -07002940 private boolean updateGlobalSearchIcon() {
2941 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002942 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2943 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002944 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002945 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07002946 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07002947
Winson Chung1cad91e2011-05-25 17:41:01 -07002948 final SearchManager searchManager =
2949 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2950 ComponentName activityName = searchManager.getGlobalSearchActivity();
2951 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002952 int coi = getCurrentOrientationIndexForGlobalIcons();
2953 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002954 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2955 TOOLBAR_SEARCH_ICON_METADATA_NAME);
2956 if (sGlobalSearchIcon[coi] == null) {
2957 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
2958 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2959 TOOLBAR_ICON_METADATA_NAME);
2960 }
2961
Winson Chung649723c2011-07-06 20:41:23 -07002962 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002963 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2964 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002965 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002966 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002967 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002968 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002969 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002970 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2971 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2972 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002973 voiceButton.setVisibility(View.GONE);
Michael Jurkac60498a2012-05-07 15:29:42 -07002974 if (voiceButtonProxy != null) {
2975 voiceButtonProxy.setVisibility(View.GONE);
2976 }
Winson Chungc51db6a2011-10-05 11:44:49 -07002977 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002978 }
2979 }
2980
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002981 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002982 final View searchButtonContainer = findViewById(R.id.search_button_container);
2983 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002984 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002985 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002986 }
2987
Winson Chungc51db6a2011-10-05 11:44:49 -07002988 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002989 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002990 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002991 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07002992 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07002993
Winson Chungc51db6a2011-10-05 11:44:49 -07002994 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07002995 final SearchManager searchManager =
2996 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2997 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2998
2999 ComponentName activityName = null;
3000 if (globalSearchActivity != null) {
3001 // Check if the global search activity handles voice search
3002 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3003 intent.setPackage(globalSearchActivity.getPackageName());
3004 activityName = intent.resolveActivity(getPackageManager());
3005 }
3006
3007 if (activityName == null) {
3008 // Fallback: check if an activity other than the global search activity
3009 // resolves this
3010 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3011 activityName = intent.resolveActivity(getPackageManager());
3012 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003013 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003014 int coi = getCurrentOrientationIndexForGlobalIcons();
3015 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003016 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3017 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3018 if (sVoiceSearchIcon[coi] == null) {
3019 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3020 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3021 TOOLBAR_ICON_METADATA_NAME);
3022 }
Winson Chung649723c2011-07-06 20:41:23 -07003023 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07003024 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003025 voiceButton.setVisibility(View.VISIBLE);
Jim Miller14091b12012-04-24 19:27:54 -07003026 if (voiceButtonProxy != null) {
3027 voiceButtonProxy.setVisibility(View.VISIBLE);
3028 }
Winson Chungbb185bd2011-11-21 12:31:42 -08003029 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003030 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003031 } else {
Winson Chung649723c2011-07-06 20:41:23 -07003032 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07003033 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003034 voiceButton.setVisibility(View.GONE);
Jim Miller14091b12012-04-24 19:27:54 -07003035 if (voiceButtonProxy != null) {
3036 voiceButtonProxy.setVisibility(View.GONE);
3037 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003038 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003039 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003040 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003041
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003042 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003043 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3044 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003045 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003046 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003047 }
3048
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003049 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003050 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003051 */
3052 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003053 final View marketButton = findViewById(R.id.market_button);
3054 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3055 // Find the app market activity by resolving an intent.
3056 // (If multiple app markets are installed, it will return the ResolverActivity.)
3057 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003058 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003059 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003060 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003061 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003062 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3063 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003064 marketButton.setVisibility(View.VISIBLE);
3065 } else {
3066 // We should hide and disable the view so that we don't try and restore the visibility
3067 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3068 marketButton.setVisibility(View.GONE);
3069 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003070 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003071 }
3072
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003073 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003074 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3075 Resources r = getResources();
3076 Drawable marketIconDrawable = d.newDrawable(r);
3077 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3078 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3079 marketIconDrawable.setBounds(0, 0, w, h);
3080
3081 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003082 }
3083
Michael Jurkad7c28052012-04-27 15:43:36 -07003084 @Override
3085 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
3086 boolean result = super.dispatchPopulateAccessibilityEvent(event);
3087 final List<CharSequence> text = event.getText();
3088 text.clear();
3089 text.add(getString(R.string.home));
3090 return result;
3091 }
3092
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003093 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003094 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003095 */
3096 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3097 @Override
3098 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003099 closeSystemDialogs();
3100 }
3101 }
3102
3103 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003104 * Receives notifications whenever the appwidgets are reset.
3105 */
3106 private class AppWidgetResetObserver extends ContentObserver {
3107 public AppWidgetResetObserver() {
3108 super(new Handler());
3109 }
3110
3111 @Override
3112 public void onChange(boolean selfChange) {
3113 onAppWidgetReset();
3114 }
3115 }
3116
3117 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003118 * If the activity is currently paused, signal that we need to re-run the loader
3119 * in onResume.
3120 *
3121 * This needs to be called from incoming places where resources might have been loaded
3122 * while we are paused. That is becaues the Configuration might be wrong
3123 * when we're not running, and if it comes back to what it was when we
3124 * were paused, we are not restarted.
3125 *
3126 * Implementation of the method from LauncherModel.Callbacks.
3127 *
3128 * @return true if we are currently paused. The caller might be able to
3129 * skip some work in that case since we will come back again.
3130 */
3131 public boolean setLoadOnResume() {
3132 if (mPaused) {
3133 Log.i(TAG, "setLoadOnResume");
3134 mOnResumeNeedsLoad = true;
3135 return true;
3136 } else {
3137 return false;
3138 }
3139 }
3140
3141 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003142 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003143 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003144 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003145 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003146 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003147 } else {
3148 return SCREEN_COUNT / 2;
3149 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003150 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003151
Joe Onorato9c1289c2009-08-17 11:03:03 -04003152 /**
3153 * Refreshes the shortcuts shown on the workspace.
3154 *
3155 * Implementation of the method from LauncherModel.Callbacks.
3156 */
3157 public void startBinding() {
3158 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07003159
Winson Chungf0c6ae02012-03-21 16:10:31 -07003160 mNewShortcutAnimatePage = -1;
3161 mNewShortcutAnimateViews.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003162 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003163 int count = workspace.getChildCount();
3164 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003165 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003166 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3167 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003168 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08003169 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003170 if (mHotseat != null) {
3171 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003172 }
3173 }
3174
3175 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003176 * Bind the items start-end from the list.
3177 *
3178 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003179 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003180 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003181 setLoadOnResume();
3182
Winson Chungf0c6ae02012-03-21 16:10:31 -07003183 // Get the list of added shortcuts and intersect them with the set of shortcuts here
3184 Set<String> newApps = new HashSet<String>();
3185 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);
3186
3187 Workspace workspace = mWorkspace;
3188 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003189 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003190
3191 // Short circuit if we are loading dock items for a configuration which has no dock
3192 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3193 mHotseat == null) {
3194 continue;
3195 }
3196
Joe Onorato9c1289c2009-08-17 11:03:03 -04003197 switch (item.itemType) {
3198 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3199 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003200 ShortcutInfo info = (ShortcutInfo) item;
3201 String uri = info.intent.toUri(0).toString();
3202 View shortcut = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -07003203 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3204 item.cellY, 1, 1, false);
Winson Chungbfeac062012-06-06 15:56:08 -07003205 boolean animateIconUp = false;
3206 synchronized (newApps) {
3207 if (newApps.contains(uri)) {
3208 animateIconUp = newApps.remove(uri);
3209 }
3210 }
3211 if (animateIconUp) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003212 // Prepare the view to be animated up
3213 shortcut.setAlpha(0f);
3214 shortcut.setScaleX(0f);
3215 shortcut.setScaleY(0f);
3216 mNewShortcutAnimatePage = item.screen;
3217 if (!mNewShortcutAnimateViews.contains(shortcut)) {
3218 mNewShortcutAnimateViews.add(shortcut);
3219 }
3220 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003221 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003222 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003223 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003224 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003225 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003226 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3227 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003228 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003229 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003230 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003231
Joe Onorato9c1289c2009-08-17 11:03:03 -04003232 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003233 }
3234
Joe Onorato9c1289c2009-08-17 11:03:03 -04003235 /**
3236 * Implementation of the method from LauncherModel.Callbacks.
3237 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003238 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003239 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003240 sFolders.clear();
3241 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003242 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003243
3244 /**
3245 * Add the views for a widget to the workspace.
3246 *
3247 * Implementation of the method from LauncherModel.Callbacks.
3248 */
3249 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003250 setLoadOnResume();
3251
Daniel Sandler843e8602010-06-07 14:59:01 -04003252 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3253 if (DEBUG_WIDGETS) {
3254 Log.d(TAG, "bindAppWidget: " + item);
3255 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003256 final Workspace workspace = mWorkspace;
3257
3258 final int appWidgetId = item.appWidgetId;
3259 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003260 if (DEBUG_WIDGETS) {
3261 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3262 }
3263
Joe Onorato9c1289c2009-08-17 11:03:03 -04003264 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3265
Joe Onorato9c1289c2009-08-17 11:03:03 -04003266 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003267 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003268
Winson Chung3d503fb2011-07-13 17:25:49 -07003269 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003270 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003271 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3272
Joe Onorato9c1289c2009-08-17 11:03:03 -04003273 workspace.requestLayout();
3274
Daniel Sandler843e8602010-06-07 14:59:01 -04003275 if (DEBUG_WIDGETS) {
3276 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3277 + (SystemClock.uptimeMillis()-start) + "ms");
3278 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003279 }
3280
3281 /**
3282 * Callback saying that there aren't any more items to bind.
3283 *
3284 * Implementation of the method from LauncherModel.Callbacks.
3285 */
3286 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003287 setLoadOnResume();
3288
Joe Onorato9c1289c2009-08-17 11:03:03 -04003289 if (mSavedState != null) {
3290 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003291 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003292 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003293 mSavedState = null;
3294 }
3295
3296 if (mSavedInstanceState != null) {
3297 super.onRestoreInstanceState(mSavedInstanceState);
3298 mSavedInstanceState = null;
3299 }
3300
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003301 // If we received the result of any pending adds while the loader was running (e.g. the
3302 // widget configuration forced an orientation change), process them now.
3303 for (int i = 0; i < sPendingAddList.size(); i++) {
3304 completeAdd(sPendingAddList.get(i));
3305 }
3306 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003307
Winson Chungc51db6a2011-10-05 11:44:49 -07003308 // Update the market app icon as necessary (the other icons will be managed in response to
3309 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003310 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003311
Winson Chungf0c6ae02012-03-21 16:10:31 -07003312 // Animate up any icons as necessary
3313 if (mVisible || mWorkspaceLoading) {
3314 Runnable newAppsRunnable = new Runnable() {
3315 @Override
3316 public void run() {
Winson Chunga2413752012-04-03 14:22:34 -07003317 runNewAppsAnimation(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003318 }
3319 };
Winson Chunga2413752012-04-03 14:22:34 -07003320
3321 boolean willSnapPage = mNewShortcutAnimatePage > -1 &&
3322 mNewShortcutAnimatePage != mWorkspace.getCurrentPage();
3323 if (canRunNewAppsAnimation()) {
3324 // If the user has not interacted recently, then either snap to the new page to show
3325 // the new-apps animation or just run them if they are to appear on the current page
3326 if (willSnapPage) {
3327 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable);
3328 } else {
3329 runNewAppsAnimation(false);
3330 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003331 } else {
Winson Chung318eee02012-04-12 10:59:27 -07003332 // If the user has interacted recently, then just add the items in place if they
Winson Chunga2413752012-04-03 14:22:34 -07003333 // are on another page (or just normally if they are added to the current page)
3334 runNewAppsAnimation(willSnapPage);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003335 }
3336 }
3337
3338 mWorkspaceLoading = false;
3339 }
3340
Winson Chunga2413752012-04-03 14:22:34 -07003341 private boolean canRunNewAppsAnimation() {
3342 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3343 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3344 }
3345
Winson Chungf0c6ae02012-03-21 16:10:31 -07003346 /**
3347 * Runs a new animation that scales up icons that were added while Launcher was in the
3348 * background.
Winson Chunga2413752012-04-03 14:22:34 -07003349 *
3350 * @param immediate whether to run the animation or show the results immediately
Winson Chungf0c6ae02012-03-21 16:10:31 -07003351 */
Winson Chunga2413752012-04-03 14:22:34 -07003352 private void runNewAppsAnimation(boolean immediate) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003353 AnimatorSet anim = new AnimatorSet();
3354 Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chunga2413752012-04-03 14:22:34 -07003355
3356 // Order these new views spatially so that they animate in order
Winson Chungf0c6ae02012-03-21 16:10:31 -07003357 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
3358 @Override
3359 public int compare(View a, View b) {
3360 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
3361 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
3362 int cellCountX = LauncherModel.getCellCountX();
3363 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
3364 }
3365 });
Winson Chunga2413752012-04-03 14:22:34 -07003366
3367 // Animate each of the views in place (or show them immediately if requested)
3368 if (immediate) {
3369 for (View v : mNewShortcutAnimateViews) {
3370 v.setAlpha(1f);
3371 v.setScaleX(1f);
3372 v.setScaleY(1f);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003373 }
Winson Chunga2413752012-04-03 14:22:34 -07003374 } else {
3375 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
3376 View v = mNewShortcutAnimateViews.get(i);
3377 ValueAnimator bounceAnim = ObjectAnimator.ofPropertyValuesHolder(v,
3378 PropertyValuesHolder.ofFloat("alpha", 1f),
3379 PropertyValuesHolder.ofFloat("scaleX", 1f),
3380 PropertyValuesHolder.ofFloat("scaleY", 1f));
3381 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3382 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3383 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3384 bounceAnims.add(bounceAnim);
3385 }
3386 anim.playTogether(bounceAnims);
3387 anim.addListener(new AnimatorListenerAdapter() {
3388 @Override
3389 public void onAnimationEnd(Animator animation) {
3390 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
3391 }
3392 });
3393 anim.start();
3394 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003395
3396 // Clean up
3397 mNewShortcutAnimatePage = -1;
3398 mNewShortcutAnimateViews.clear();
3399 new Thread("clearNewAppsThread") {
3400 public void run() {
3401 mSharedPrefs.edit()
3402 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
3403 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null)
3404 .commit();
3405 }
3406 }.start();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003407 }
3408
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003409 @Override
3410 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003411 boolean searchVisible = updateGlobalSearchIcon();
3412 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3413 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003414 }
3415
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003416 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003417 * Add the icons for all apps.
3418 *
3419 * Implementation of the method from LauncherModel.Callbacks.
3420 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003421 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3422 // Remove the progress bar entirely; we could also make it GONE
3423 // but better to remove it since we know it's not going to be used
3424 View progressBar = mAppsCustomizeTabHost.
3425 findViewById(R.id.apps_customize_progress_bar);
3426 if (progressBar != null) {
3427 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003428 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003429 // We just post the call to setApps so the user sees the progress bar
3430 // disappear-- otherwise, it just looks like the progress bar froze
3431 // which doesn't look great
3432 mAppsCustomizeTabHost.post(new Runnable() {
3433 public void run() {
3434 if (mAppsCustomizeContent != null) {
3435 mAppsCustomizeContent.setApps(apps);
3436 }
3437 }
3438 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003439 }
3440
3441 /**
3442 * A package was installed.
3443 *
3444 * Implementation of the method from LauncherModel.Callbacks.
3445 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003446 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003447 setLoadOnResume();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003448
Winson Chung785d2eb2011-04-14 16:08:02 -07003449 if (mAppsCustomizeContent != null) {
3450 mAppsCustomizeContent.addApps(apps);
3451 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003452 }
3453
3454 /**
3455 * A package was updated.
3456 *
3457 * Implementation of the method from LauncherModel.Callbacks.
3458 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003459 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003460 setLoadOnResume();
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003461 if (mWorkspace != null) {
3462 mWorkspace.updateShortcuts(apps);
3463 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003464
Winson Chung785d2eb2011-04-14 16:08:02 -07003465 if (mAppsCustomizeContent != null) {
3466 mAppsCustomizeContent.updateApps(apps);
3467 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003468 }
3469
3470 /**
3471 * A package was uninstalled.
3472 *
3473 * Implementation of the method from LauncherModel.Callbacks.
3474 */
Joe Onorato36115782010-06-17 13:28:48 -04003475 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato36115782010-06-17 13:28:48 -04003476 if (permanent) {
3477 mWorkspace.removeItems(apps);
3478 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003479
Winson Chung785d2eb2011-04-14 16:08:02 -07003480 if (mAppsCustomizeContent != null) {
3481 mAppsCustomizeContent.removeApps(apps);
3482 }
Winson Chunga1820962011-10-03 16:31:06 -07003483
3484 // Notify the drag controller
3485 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003486 }
Joe Onoratobe386092009-11-17 17:32:16 -08003487
3488 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003489 * A number of packages were updated.
3490 */
3491 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003492 if (mAppsCustomizeContent != null) {
3493 mAppsCustomizeContent.onPackagesUpdated();
3494 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003495 }
3496
Winson Chung400438b2011-01-16 17:53:48 -08003497 private int mapConfigurationOriActivityInfoOri(int configOri) {
3498 final Display d = getWindowManager().getDefaultDisplay();
3499 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3500 switch (d.getRotation()) {
3501 case Surface.ROTATION_0:
3502 case Surface.ROTATION_180:
3503 // We are currently in the same basic orientation as the natural orientation
3504 naturalOri = configOri;
3505 break;
3506 case Surface.ROTATION_90:
3507 case Surface.ROTATION_270:
3508 // We are currently in the other basic orientation to the natural orientation
3509 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3510 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3511 break;
3512 }
3513
3514 int[] oriMap = {
3515 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3516 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3517 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3518 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3519 };
3520 // Since the map starts at portrait, we need to offset if this device's natural orientation
3521 // is landscape.
3522 int indexOffset = 0;
3523 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3524 indexOffset = 1;
3525 }
3526 return oriMap[(d.getRotation() + indexOffset) % 4];
3527 }
Adam Cohen446e9402011-09-15 18:21:21 -07003528
Winson Chung4b919f82012-05-01 10:44:08 -07003529 public boolean isRotationEnabled() {
3530 boolean forceEnableRotation = "true".equalsIgnoreCase(SystemProperties.get(
3531 FORCE_ENABLE_ROTATION_PROPERTY, "false"));
3532 boolean enableRotation = forceEnableRotation ||
3533 getResources().getBoolean(R.bool.allow_rotation);
3534 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08003535 }
Winson Chung4b919f82012-05-01 10:44:08 -07003536 public void lockScreenOrientation() {
3537 if (isRotationEnabled()) {
3538 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3539 .getConfiguration().orientation));
3540 }
3541 }
3542 public void unlockScreenOrientation(boolean immediate) {
3543 if (isRotationEnabled()) {
3544 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07003545 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07003546 } else {
3547 mHandler.postDelayed(new Runnable() {
3548 public void run() {
3549 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3550 }
3551 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07003552 }
Winson Chung4b919f82012-05-01 10:44:08 -07003553 }
Winson Chung400438b2011-01-16 17:53:48 -08003554 }
3555
Winson Chung82f55532011-08-09 14:14:23 -07003556 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003557 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003558 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003559 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003560
Winson Chung7d7541e2011-09-16 20:14:36 -07003561 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003562 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003563 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3564 Cling cling = (Cling) findViewById(clingId);
3565 if (cling != null) {
3566 cling.init(this, positionData);
3567 cling.setVisibility(View.VISIBLE);
3568 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Svetoslav Ganov55d225d2012-05-22 15:19:14 -07003569 cling.requestAccessibilityFocus();
Winson Chung7d7541e2011-09-16 20:14:36 -07003570 if (animate) {
3571 cling.buildLayer();
3572 cling.setAlpha(0f);
3573 cling.animate()
3574 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003575 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003576 .setDuration(SHOW_CLING_DURATION)
3577 .setStartDelay(delay)
3578 .start();
3579 } else {
3580 cling.setAlpha(1f);
3581 }
3582 }
3583 return cling;
3584 }
3585 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003586 if (cling != null) {
3587 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003588 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003589 anim.addListener(new AnimatorListenerAdapter() {
3590 public void onAnimationEnd(Animator animation) {
3591 cling.setVisibility(View.GONE);
3592 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003593 // We should update the shared preferences on a background thread
3594 new Thread("dismissClingThread") {
3595 public void run() {
3596 SharedPreferences.Editor editor = mSharedPrefs.edit();
3597 editor.putBoolean(flag, true);
3598 editor.commit();
3599 }
3600 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003601 };
3602 });
3603 anim.start();
3604 }
3605 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003606 private void removeCling(int id) {
3607 final View cling = findViewById(id);
3608 if (cling != null) {
3609 final ViewGroup parent = (ViewGroup) cling.getParent();
3610 parent.post(new Runnable() {
3611 @Override
3612 public void run() {
3613 parent.removeView(cling);
3614 }
3615 });
3616 }
3617 }
Michael Jurka974c3862012-05-22 22:00:31 -07003618
3619 private boolean skipCustomClingIfNoAccounts() {
3620 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3621 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
3622 if (customCling) {
3623 AccountManager am = AccountManager.get(this);
3624 Account[] accounts = am.getAccountsByType("com.google");
3625 return accounts.length == 0;
3626 }
3627 return false;
3628 }
3629
Winson Chung7d7541e2011-09-16 20:14:36 -07003630 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003631 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003632 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07003633 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
3634 !skipCustomClingIfNoAccounts() ) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003635 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003636 } else {
3637 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003638 }
3639 }
3640 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003641 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003642 if (isClingsEnabled() &&
3643 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003644 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003645 } else {
3646 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003647 }
3648 }
3649 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003650 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003651 if (isClingsEnabled() &&
3652 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
3653 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003654 } else {
3655 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08003656 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07003657 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003658 }
3659 public boolean isFolderClingVisible() {
3660 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003661 if (cling != null) {
3662 return cling.getVisibility() == View.VISIBLE;
3663 }
3664 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003665 }
Winson Chung82f55532011-08-09 14:14:23 -07003666 public void dismissWorkspaceCling(View v) {
3667 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003668 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003669 }
3670 public void dismissAllAppsCling(View v) {
3671 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003672 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3673 }
3674 public void dismissFolderCling(View v) {
3675 Cling cling = (Cling) findViewById(R.id.folder_cling);
3676 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003677 }
3678
Winson Chung80baf5a2010-08-09 16:03:15 -07003679 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003680 * Prints out out state for debugging.
3681 */
3682 public void dumpState() {
3683 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003684 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003685 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3686 Log.d(TAG, "mRestoring=" + mRestoring);
3687 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3688 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003689 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003690 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003691
Winson Chung785d2eb2011-04-14 16:08:02 -07003692 if (mAppsCustomizeContent != null) {
3693 mAppsCustomizeContent.dumpState();
3694 }
Joe Onoratobe386092009-11-17 17:32:16 -08003695 Log.d(TAG, "END launcher2 dump state");
3696 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003697
3698 @Override
3699 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3700 super.dump(prefix, fd, writer, args);
3701 writer.println(" ");
3702 writer.println("Debug logs: ");
3703 for (int i = 0; i < sDumpLogs.size(); i++) {
3704 writer.println(" " + sDumpLogs.get(i));
3705 }
3706 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003707}
Michael Jurka2763be32011-02-24 11:19:57 -08003708
Michael Jurkaabded662011-03-04 12:06:57 -08003709interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003710 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003711 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08003712 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08003713 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08003714 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003715}