blob: 5ef73179bce4922be0ed3434d2889b993fe82779 [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
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800341 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200342 android.os.Debug.startMethodTracing(
343 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800344 }
345
346 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800347 setContentView(R.layout.launcher);
348 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700349 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800350
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800351 registerContentObservers();
352
Joe Onorato7c312c12009-08-13 21:36:53 -0700353 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700354
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800355 mSavedState = savedInstanceState;
356 restoreState(mSavedState);
357
Winson Chunga12a2502010-12-20 14:41:35 -0800358 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700359 if (mAppsCustomizeContent != null) {
Winson Chung7c7a22d2012-06-01 13:46:48 -0700360 Log.d(TAG, "6549598 Launcher.onCreate()");
Winson Chung785d2eb2011-04-14 16:08:02 -0700361 mAppsCustomizeContent.onPackagesUpdated();
362 }
Winson Chunga12a2502010-12-20 14:41:35 -0800363
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800364 if (PROFILE_STARTUP) {
365 android.os.Debug.stopMethodTracing();
366 }
367
368 if (!mRestoring) {
Winson Chungf0c6ae02012-03-21 16:10:31 -0700369 mModel.startLoader(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800370 }
371
Michael Jurkac57b7a82011-08-09 22:02:20 -0700372 if (!mModel.isAllAppsLoaded()) {
373 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
374 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
375 }
376
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800377 // For handling default keys
378 mDefaultKeySsb = new SpannableStringBuilder();
379 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800380
381 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
382 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800383
Adam Cohenf9426d52012-06-04 17:26:21 -0700384 updateGlobalIcons();
385
386 // On large interfaces, we want the screen to auto-rotate based on the current orientation
387 unlockScreenOrientation(true);
388 }
389
390 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700391 boolean searchVisible = false;
392 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800393 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700394 int coi = getCurrentOrientationIndexForGlobalIcons();
395 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
396 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700397 updateAppMarketIcon();
398 searchVisible = updateGlobalSearchIcon();
399 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700400 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700401 if (sGlobalSearchIcon[coi] != null) {
402 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700403 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700404 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700405 if (sVoiceSearchIcon[coi] != null) {
406 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700407 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700408 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700409 if (sAppMarketIcon[coi] != null) {
410 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800411 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700412 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800413 }
Romain Guycbb89e42009-06-08 15:52:54 -0700414
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800415 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700416 if (sLocaleConfiguration == null) {
417 new AsyncTask<Void, Void, LocaleConfiguration>() {
418 @Override
419 protected LocaleConfiguration doInBackground(Void... unused) {
420 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
421 readConfiguration(Launcher.this, localeConfiguration);
422 return localeConfiguration;
423 }
424
425 @Override
426 protected void onPostExecute(LocaleConfiguration result) {
427 sLocaleConfiguration = result;
428 checkForLocaleChange(); // recursive, but now with a locale configuration
429 }
430 }.execute();
431 return;
432 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700433
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800434 final Configuration configuration = getResources().getConfiguration();
435
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700436 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800437 final String locale = configuration.locale.toString();
438
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700439 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800440 final int mcc = configuration.mcc;
441
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700442 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800443 final int mnc = configuration.mnc;
444
Romain Guy84f296c2009-11-04 15:00:44 -0800445 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800446
Romain Guy84f296c2009-11-04 15:00:44 -0800447 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700448 sLocaleConfiguration.locale = locale;
449 sLocaleConfiguration.mcc = mcc;
450 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700451
Joe Onorato0589f0f2010-02-08 13:44:00 -0800452 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700453
454 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
455 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700456 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700457 public void run() {
458 writeConfiguration(Launcher.this, localeConfiguration);
459 }
460 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700461 }
462 }
463
464 private static class LocaleConfiguration {
465 public String locale;
466 public int mcc = -1;
467 public int mnc = -1;
468 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700469
Romain Guy98d01652009-06-30 16:21:04 -0700470 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
471 DataInputStream in = null;
472 try {
473 in = new DataInputStream(context.openFileInput(PREFERENCES));
474 configuration.locale = in.readUTF();
475 configuration.mcc = in.readInt();
476 configuration.mnc = in.readInt();
477 } catch (FileNotFoundException e) {
478 // Ignore
479 } catch (IOException e) {
480 // Ignore
481 } finally {
482 if (in != null) {
483 try {
484 in.close();
485 } catch (IOException e) {
486 // Ignore
487 }
488 }
489 }
490 }
491
492 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
493 DataOutputStream out = null;
494 try {
495 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
496 out.writeUTF(configuration.locale);
497 out.writeInt(configuration.mcc);
498 out.writeInt(configuration.mnc);
499 out.flush();
500 } catch (FileNotFoundException e) {
501 // Ignore
502 } catch (IOException e) {
503 //noinspection ResultOfMethodCallIgnored
504 context.getFileStreamPath(PREFERENCES).delete();
505 } finally {
506 if (out != null) {
507 try {
508 out.close();
509 } catch (IOException e) {
510 // Ignore
511 }
512 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800513 }
514 }
515
Adam Cohen716b51e2011-06-30 12:09:54 -0700516 public DragLayer getDragLayer() {
517 return mDragLayer;
518 }
519
Winson Chung36a62fe2012-05-06 18:04:42 -0700520 boolean isDraggingEnabled() {
521 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
522 // that is subsequently removed from the workspace in startBinding().
523 return !mModel.isLoadingWorkspace();
524 }
525
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800526 static int getScreen() {
527 synchronized (sLock) {
528 return sScreen;
529 }
530 }
531
532 static void setScreen(int screen) {
533 synchronized (sLock) {
534 sScreen = screen;
535 }
536 }
537
Winson Chung557d6ed2011-07-08 15:34:52 -0700538 /**
539 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
540 * a configuration step, this allows the proper animations to run after other transitions.
541 */
542 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700543 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800544 switch (args.requestCode) {
545 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700546 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
547 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800548 break;
549 case REQUEST_PICK_SHORTCUT:
550 processShortcut(args.intent);
551 break;
552 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700553 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
554 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700555 result = true;
556 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800557 case REQUEST_CREATE_APPWIDGET:
558 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800559 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700560 result = true;
561 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800562 case REQUEST_PICK_WALLPAPER:
563 // We just wanted the activity result here so we can clear mWaitingForResult
564 break;
565 }
Michael Jurka27614d22012-04-02 06:40:22 -0700566 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
567 // if you turned the screen off and then back while in All Apps, Launcher would not
568 // return to the workspace. Clearing mAddInfo.container here fixes this issue
569 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700570 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800571 }
572
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800573 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700574 protected void onActivityResult(
575 final int requestCode, final int resultCode, final Intent data) {
576 if (requestCode == REQUEST_BIND_APPWIDGET) {
577 int appWidgetId = data != null ?
578 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
579 if (resultCode == RESULT_CANCELED) {
580 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
581 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700582 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700583 }
584 return;
585 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700586 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800587 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
588 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700589 mWaitingForResult = false;
590
Adam Cohened66b2b2012-01-23 17:28:51 -0800591 // We have special handling for widgets
592 if (isWidgetDrop) {
593 int appWidgetId = data != null ?
594 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700595 if (appWidgetId < 0) {
596 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
597 "widget configuration activity.");
598 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
599 } else {
600 completeTwoStageWidgetDrop(resultCode, appWidgetId);
601 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800602 return;
603 }
604
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800605 // The pattern used here is that a user PICKs a specific application,
606 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700607
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800608 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
609 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700610 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800611 final PendingAddArguments args = new PendingAddArguments();
612 args.requestCode = requestCode;
613 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700614 args.container = mPendingAddInfo.container;
615 args.screen = mPendingAddInfo.screen;
616 args.cellX = mPendingAddInfo.cellX;
617 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800618 if (isWorkspaceLocked()) {
619 sPendingAddList.add(args);
620 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700621 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800622 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800623 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800624 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700625 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800626 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
627 null);
628 }
629
630 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700631 CellLayout cellLayout =
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700632 (CellLayout) mWorkspace.getChildAt(mPendingAddInfo.screen);
Adam Cohened66b2b2012-01-23 17:28:51 -0800633 Runnable onCompleteRunnable = null;
634 int animationType = 0;
635
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700636 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800637 if (resultCode == RESULT_OK) {
638 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
639 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700640 mPendingAddWidgetInfo);
641 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800642 onCompleteRunnable = new Runnable() {
643 @Override
644 public void run() {
645 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
646 mPendingAddInfo.screen, layout, null);
647 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
648 null);
649 }
650 };
651 } else if (resultCode == RESULT_CANCELED) {
652 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
653 onCompleteRunnable = new Runnable() {
654 @Override
655 public void run() {
656 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
657 null);
658 }
659 };
660 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700661 if (mDragLayer.getAnimatedView() != null) {
662 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
663 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
664 animationType, boundWidget, true);
665 } else {
666 // The animated view may be null in the case of a rotation during widget configuration
667 onCompleteRunnable.run();
668 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800669 }
670
671 @Override
672 protected void onResume() {
673 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700674
Winson Chungde0fb8f2012-05-08 14:37:08 -0700675 // Process any items that were added while Launcher was away
676 InstallShortcutReceiver.flushInstallQueue(this);
677
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800678 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700679 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400680 mWorkspaceLoading = true;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700681 mModel.startLoader(true);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400682 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700683 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800684 }
Winson Chunge4e50662012-01-23 14:45:13 -0800685
686 // Reset the pressed state of icons that were locked in the press state while activities
687 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800688 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800689 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800690 mWaitingForResume.setStayPressed(false);
691 }
Winson Chunge4e50662012-01-23 14:45:13 -0800692 if (mAppsCustomizeContent != null) {
693 // Resets the previous all apps icon press state
694 mAppsCustomizeContent.resetDrawableState();
695 }
Adam Cohen06dff352012-06-01 17:17:08 -0700696 // It is possible that widgets can receive updates while launcher is not in the foreground.
697 // Consequently, the widgets will be inflated in the orientation of the foreground activity
698 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
699 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700700 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700701
702 // Again, as with the above scenario, it's possible that one or more of the global icons
703 // were updated in the wrong orientation.
704 updateGlobalIcons();
Adam Cohen06dff352012-06-01 17:17:08 -0700705 }
706
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800707 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700708 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700709 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
710 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
711 // when Launcher resumes and we are still in AllApps.
712 updateWallpaperVisibility(true);
713
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700714 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700715 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800716 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700717 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700718 }
Romain Guycbb89e42009-06-08 15:52:54 -0700719
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700720 @Override
721 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400722 // Flag the loader to stop early before switching
723 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700724 if (mAppsCustomizeContent != null) {
725 mAppsCustomizeContent.surrender();
726 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800727 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700728 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700729
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800730 // We can't hide the IME if it was forced open. So don't bother
731 /*
732 @Override
733 public void onWindowFocusChanged(boolean hasFocus) {
734 super.onWindowFocusChanged(hasFocus);
735
736 if (hasFocus) {
737 final InputMethodManager inputManager = (InputMethodManager)
738 getSystemService(Context.INPUT_METHOD_SERVICE);
739 WindowManager.LayoutParams lp = getWindow().getAttributes();
740 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
741 android.os.Handler()) {
742 protected void onReceiveResult(int resultCode, Bundle resultData) {
743 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
744 }
745 });
746 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
747 }
748 }
749 */
750
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800751 private boolean acceptFilter() {
752 final InputMethodManager inputManager = (InputMethodManager)
753 getSystemService(Context.INPUT_METHOD_SERVICE);
754 return !inputManager.isFullscreenMode();
755 }
756
757 @Override
758 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700759 final int uniChar = event.getUnicodeChar();
760 final boolean handled = super.onKeyDown(keyCode, event);
761 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
762 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800763 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
764 keyCode, event);
765 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700766 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700767 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700768 // showSearchDialog()
769 // If there are multiple keystrokes before the search dialog takes focus,
770 // onSearchRequested() will be called for every keystroke,
771 // but it is idempotent, so it's fine.
772 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800773 }
774 }
775
Joe Onorato8a9625e2010-01-28 15:55:35 -0800776 // Eat the long press event so the keyboard doesn't come up.
777 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
778 return true;
779 }
780
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800781 return handled;
782 }
783
Karl Rosaen138a0412009-04-23 19:00:21 -0700784 private String getTypedText() {
785 return mDefaultKeySsb.toString();
786 }
787
788 private void clearTypedText() {
789 mDefaultKeySsb.clear();
790 mDefaultKeySsb.clearSpans();
791 Selection.setSelection(mDefaultKeySsb, 0);
792 }
793
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800794 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700795 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
796 * State
797 */
798 private static State intToState(int stateOrdinal) {
799 State state = State.WORKSPACE;
800 final State[] stateValues = State.values();
801 for (int i = 0; i < stateValues.length; i++) {
802 if (stateValues[i].ordinal() == stateOrdinal) {
803 state = stateValues[i];
804 break;
805 }
806 }
807 return state;
808 }
809
810 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800811 * Restores the previous state, if it exists.
812 *
813 * @param savedState The previous state.
814 */
815 private void restoreState(Bundle savedState) {
816 if (savedState == null) {
817 return;
818 }
819
Michael Jurka883f55b2010-10-21 15:47:14 -0700820 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700821 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800822 showAllApps(false);
823 }
824
Winson Chungf0c6ae02012-03-21 16:10:31 -0700825 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800826 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700827 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800828 }
829
Winson Chung3d503fb2011-07-13 17:25:49 -0700830 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
831 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700832
Winson Chung3d503fb2011-07-13 17:25:49 -0700833 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
834 mPendingAddInfo.container = pendingAddContainer;
835 mPendingAddInfo.screen = pendingAddScreen;
836 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
837 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700838 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
839 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
840 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -0700841 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800842 mRestoring = true;
843 }
844
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700845
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800846 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
847 if (renameFolder) {
848 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700849 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800850 mRestoring = true;
851 }
Winson Chunga12a2502010-12-20 14:41:35 -0800852
Winson Chung785d2eb2011-04-14 16:08:02 -0700853
854 // Restore the AppsCustomize tab
855 if (mAppsCustomizeTabHost != null) {
856 String curTab = savedState.getString("apps_customize_currentTab");
857 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700858 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700859 mAppsCustomizeContent.setContentType(
860 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
861 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700862 mAppsCustomizeContent.loadAssociatedPages(
863 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700864 }
865
Winson Chung5afbf7b2011-07-25 11:53:08 -0700866 int currentIndex = savedState.getInt("apps_customize_currentIndex");
867 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700868 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800869 }
870
871 /**
872 * Finds all the views we need and configure them properly.
873 */
874 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700875 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400876
Winson Chung4c98d922011-05-31 16:50:48 -0700877 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
878 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800879 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
880 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800881
Winson Chung4c98d922011-05-31 16:50:48 -0700882 // Setup the drag layer
883 mDragLayer.setup(this, dragController);
884
Winson Chung3d503fb2011-07-13 17:25:49 -0700885 // Setup the hotseat
886 mHotseat = (Hotseat) findViewById(R.id.hotseat);
887 if (mHotseat != null) {
888 mHotseat.setup(this);
889 }
890
Winson Chung4c98d922011-05-31 16:50:48 -0700891 // Setup the workspace
892 mWorkspace.setHapticFeedbackEnabled(false);
893 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700894 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700895 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700896
Winson Chungf0ea4d32011-06-06 14:27:16 -0700897 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700898 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700899
Winson Chungf0ea4d32011-06-06 14:27:16 -0700900 // Setup AppsCustomize
901 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
902 findViewById(R.id.apps_customize_pane);
903 mAppsCustomizeContent = (AppsCustomizePagedView)
904 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
Winson Chungc7450e32012-04-17 17:34:08 -0700905 mAppsCustomizeTabHost.setup(this);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700906 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400907
Michael Jurka5130e402011-10-13 04:55:35 -0700908 // Get the all apps button
909 mAllAppsButton = findViewById(R.id.all_apps_button);
910 if (mAllAppsButton != null) {
911 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
912 @Override
913 public boolean onTouch(View v, MotionEvent event) {
914 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
915 onTouchDownAllAppsButton(v);
916 }
917 return false;
918 }
919 });
920 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700921 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700922 dragController.setDragScoller(mWorkspace);
923 dragController.setScrollView(mDragLayer);
924 dragController.setMoveTarget(mWorkspace);
925 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700926 if (mSearchDropTargetBar != null) {
927 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800928 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800929 }
930
931 /**
932 * Creates a view representing a shortcut.
933 *
934 * @param info The data structure describing the shortcut.
935 *
936 * @return A View inflated from R.layout.application.
937 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800938 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800939 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700940 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800941 }
942
943 /**
944 * Creates a view representing a shortcut inflated from the specified resource.
945 *
946 * @param layoutResId The id of the XML layout used to create the shortcut.
947 * @param parent The group the shortcut belongs to.
948 * @param info The data structure describing the shortcut.
949 *
950 * @return A View inflated from layoutResId.
951 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800952 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800953 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
954 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800955 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800956 return favorite;
957 }
958
959 /**
960 * Add an application shortcut to the workspace.
961 *
962 * @param data The intent describing the application.
963 * @param cellInfo The position on screen where to create the shortcut.
964 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700965 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700966 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700967 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700968
Adam Cohenfbba09b2011-07-18 21:43:05 -0700969 // First we check if we already know the exact location where we want to add this item.
970 if (cellX >= 0 && cellY >= 0) {
971 cellXY[0] = cellX;
972 cellXY[1] = cellY;
973 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -0700974 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -0700975 return;
976 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800977
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800978 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800979
Romain Guy73b979d2009-06-09 12:57:21 -0700980 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800981 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800982 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800983 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700984 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700985 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800986 } else {
987 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800988 }
989 }
Romain Guycbb89e42009-06-08 15:52:54 -0700990
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800991 /**
992 * Add a shortcut to the workspace.
993 *
994 * @param data The intent describing the shortcut.
995 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800996 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700997 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
998 int cellY) {
999 int[] cellXY = mTmpAddItemCellCoordinates;
1000 int[] touchXY = mPendingAddInfo.dropPos;
1001 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001002
Michael Jurkad3ef3062010-11-23 16:23:58 -08001003 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001004
Adam Cohen558baaf2011-08-15 15:22:57 -07001005 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001006 if (info == null) {
1007 return;
1008 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001009 final View view = createShortcut(info);
1010
Adam Cohenfbba09b2011-07-18 21:43:05 -07001011 // First we check if we already know the exact location where we want to add this item.
1012 if (cellX >= 0 && cellY >= 0) {
1013 cellXY[0] = cellX;
1014 cellXY[1] = cellY;
1015 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001016
1017 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001018 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001019 true, null,null)) {
1020 return;
1021 }
1022 DragObject dragObject = new DragObject();
1023 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001024 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1025 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001026 return;
1027 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001028 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001029 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001030 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001031 foundCellSpan = (result != null);
1032 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001033 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001034 }
1035
1036 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001037 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001038 return;
1039 }
1040
Adam Cohen558baaf2011-08-15 15:22:57 -07001041 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001042
1043 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001044 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
1045 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001046 }
1047 }
1048
Adam Cohen2f093b62012-04-30 18:59:53 -07001049 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1050 int minHeight) {
1051 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001052 // We want to account for the extra amount of padding that we are adding to the widget
1053 // to ensure that it gets the full amount of space that it has requested
1054 int requiredWidth = minWidth + padding.left + padding.right;
1055 int requiredHeight = minHeight + padding.top + padding.bottom;
Adam Cohen2f093b62012-04-30 18:59:53 -07001056 return CellLayout.rectToCell(context.getResources(), requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001057 }
1058
Adam Cohen2f093b62012-04-30 18:59:53 -07001059 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1060 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001061 }
1062
Adam Cohen2f093b62012-04-30 18:59:53 -07001063 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1064 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001065 }
1066
Adam Cohen2f093b62012-04-30 18:59:53 -07001067 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1068 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001069 }
1070
Adam Cohen2f093b62012-04-30 18:59:53 -07001071 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1072 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001073 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001074 }
1075
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001076 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001077 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001078 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001079 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001080 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001081 */
Adam Cohened66b2b2012-01-23 17:28:51 -08001082 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
1083 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1084 if (appWidgetInfo == null) {
1085 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1086 }
Romain Guycbb89e42009-06-08 15:52:54 -07001087
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001088 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -07001089 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -07001090
Adam Cohen2f093b62012-04-30 18:59:53 -07001091 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1092 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001093
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001094 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001095 // We have saved the position to which the widget was dragged-- this really only matters
1096 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001097 int[] cellXY = mTmpAddItemCellCoordinates;
1098 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001099 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001100 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001101 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1102 cellXY[0] = mPendingAddInfo.cellX;
1103 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001104 spanXY[0] = mPendingAddInfo.spanX;
1105 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001106 foundCellSpan = true;
1107 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001108 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001109 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001110 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1111 spanXY[1], cellXY, finalSpan);
1112 spanXY[0] = finalSpan[0];
1113 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001114 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001115 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001116 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001117 }
1118
Michael Jurka0280c3b2010-09-17 15:00:07 -07001119 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001120 if (appWidgetId != -1) {
1121 // Deleting an app widget ID is a void call but writes to disk before returning
1122 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001123 new Thread("deleteAppWidgetId") {
1124 public void run() {
1125 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1126 }
1127 }.start();
1128 }
Winson Chung93eef082012-03-23 15:59:27 -07001129 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001130 return;
1131 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001132
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001133 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001134 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1135 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001136 launcherInfo.spanX = spanXY[0];
1137 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001138 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1139 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001140
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001141 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001142 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001143
1144 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001145 if (hostView == null) {
1146 // Perform actual inflation because we're live
1147 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1148 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1149 } else {
1150 // The AppWidgetHostView has already been inflated and instantiated
1151 launcherInfo.hostView = hostView;
1152 }
Romain Guycbb89e42009-06-08 15:52:54 -07001153
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001154 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001155 launcherInfo.hostView.setVisibility(View.VISIBLE);
Winson Chung211bac32012-05-15 13:43:57 -07001156 launcherInfo.notifyWidgetSizeChanged(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001157 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001158 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001159
1160 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001161 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001162 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001163 }
Romain Guycbb89e42009-06-08 15:52:54 -07001164
Adam Cohended9f8d2010-11-03 13:25:16 -07001165 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1166 @Override
1167 public void onReceive(Context context, Intent intent) {
1168 final String action = intent.getAction();
1169 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1170 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001171 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001172 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001173
Winson Chungc100e8e2011-08-09 16:02:43 -07001174 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001175 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001176 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1177 mAppsCustomizeTabHost.reset();
1178 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001179 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001180 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1181 mUserPresent = true;
1182 updateRunning();
1183 }
1184 }
1185 };
1186
1187 @Override
1188 public void onAttachedToWindow() {
1189 super.onAttachedToWindow();
1190
1191 // Listen for broadcasts related to user-presence
1192 final IntentFilter filter = new IntentFilter();
1193 filter.addAction(Intent.ACTION_SCREEN_OFF);
1194 filter.addAction(Intent.ACTION_USER_PRESENT);
1195 registerReceiver(mReceiver, filter);
1196
Adam Cohend113e0c2010-11-11 10:48:05 -08001197 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001198 mVisible = true;
1199 }
1200
1201 @Override
1202 public void onDetachedFromWindow() {
1203 super.onDetachedFromWindow();
1204 mVisible = false;
1205
Adam Cohend113e0c2010-11-11 10:48:05 -08001206 if (mAttached) {
1207 unregisterReceiver(mReceiver);
1208 mAttached = false;
1209 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001210 updateRunning();
1211 }
1212
1213 public void onWindowVisibilityChanged(int visibility) {
1214 mVisible = visibility == View.VISIBLE;
1215 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001216 // The following code used to be in onResume, but it turns out onResume is called when
1217 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1218 // is a more appropriate event to handle
1219 if (mVisible) {
1220 mAppsCustomizeTabHost.onWindowVisible();
1221 if (!mWorkspaceLoading) {
1222 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001223 // We want to let Launcher draw itself at least once before we force it to build
1224 // layers on all the workspace pages, so that transitioning to Launcher from other
1225 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
1226 // a true draw so we wait until the second preDraw call to be safe
1227 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001228 public boolean onPreDraw() {
Michael Jurka6ee21d22012-02-21 18:20:27 -08001229 // We delay the layer building a bit in order to give
1230 // other message processing a time to run. In particular
1231 // this avoids a delay in hiding the IME if it was
1232 // currently shown, because doing that may involve
1233 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001234 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Winson Chung31ce0732012-05-06 13:36:43 -07001235
Michael Jurka6ee21d22012-02-21 18:20:27 -08001236 observer.removeOnPreDrawListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001237 return true;
1238 }
1239 });
1240 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001241 // When Launcher comes back to foreground, a different Activity might be responsible for
1242 // the app market intent, so refresh the icon
1243 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001244 clearTypedText();
1245 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001246 }
1247
1248 private void sendAdvanceMessage(long delay) {
1249 mHandler.removeMessages(ADVANCE_MSG);
1250 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1251 mHandler.sendMessageDelayed(msg, delay);
1252 mAutoAdvanceSentTime = System.currentTimeMillis();
1253 }
1254
1255 private void updateRunning() {
1256 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1257 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1258 mAutoAdvanceRunning = autoAdvanceRunning;
1259 if (autoAdvanceRunning) {
1260 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1261 sendAdvanceMessage(delay);
1262 } else {
1263 if (!mWidgetsToAdvance.isEmpty()) {
1264 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1265 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1266 }
1267 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001268 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001269 }
1270 }
1271 }
1272
1273 private final Handler mHandler = new Handler() {
1274 @Override
1275 public void handleMessage(Message msg) {
1276 if (msg.what == ADVANCE_MSG) {
1277 int i = 0;
1278 for (View key: mWidgetsToAdvance.keySet()) {
1279 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1280 final int delay = mAdvanceStagger * i;
1281 if (v instanceof Advanceable) {
1282 postDelayed(new Runnable() {
1283 public void run() {
1284 ((Advanceable) v).advance();
1285 }
1286 }, delay);
1287 }
1288 i++;
1289 }
1290 sendAdvanceMessage(mAdvanceInterval);
1291 }
1292 }
1293 };
1294
1295 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001296 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001297 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1298 if (v instanceof Advanceable) {
1299 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001300 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001301 updateRunning();
1302 }
1303 }
1304
1305 void removeWidgetToAutoAdvance(View hostView) {
1306 if (mWidgetsToAdvance.containsKey(hostView)) {
1307 mWidgetsToAdvance.remove(hostView);
1308 updateRunning();
1309 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001310 }
1311
Joe Onorato9c1289c2009-08-17 11:03:03 -04001312 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001313 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001314 launcherInfo.hostView = null;
1315 }
1316
Winson Chung93eef082012-03-23 15:59:27 -07001317 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1318 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1319 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001320 }
1321
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001322 public LauncherAppWidgetHost getAppWidgetHost() {
1323 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001324 }
Romain Guycbb89e42009-06-08 15:52:54 -07001325
Winson Chunga9abd0e2010-10-27 17:18:37 -07001326 public LauncherModel getModel() {
1327 return mModel;
1328 }
1329
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001330 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001331 getWindow().closeAllPanels();
1332
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001333 // Whatever we were doing is hereby canceled.
1334 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001335 }
1336
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001337 @Override
1338 protected void onNewIntent(Intent intent) {
1339 super.onNewIntent(intent);
1340
1341 // Close the menu
1342 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001343 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001344 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001345
Joe Onorato14f122b2009-11-19 14:06:36 -08001346 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1347 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001348
Adam Cohenac56cff2011-09-28 20:45:37 -07001349 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001350 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001351 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001352 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1353 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001354 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001355 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001356
1357 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001358 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001359 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001360
Joe Onorato3a8820b2009-11-10 15:06:42 -08001361 final View v = getWindow().peekDecorView();
1362 if (v != null && v.getWindowToken() != null) {
1363 InputMethodManager imm = (InputMethodManager)getSystemService(
1364 INPUT_METHOD_SERVICE);
1365 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001366 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001367
Michael Jurka35aa14d2011-07-07 17:01:08 -07001368 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001369 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001370 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001371 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001372 }
1373 }
1374
1375 @Override
1376 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1377 // Do not call super here
1378 mSavedInstanceState = savedInstanceState;
1379 }
1380
1381 @Override
1382 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001383 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001384 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001385
Michael Jurka883f55b2010-10-21 15:47:14 -07001386 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001387 // We close any open folder since it will not be re-opened, and we need to make sure
1388 // this state is reflected.
1389 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001390
Winson Chung3d503fb2011-07-13 17:25:49 -07001391 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1392 mWaitingForResult) {
1393 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1394 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1395 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1396 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001397 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1398 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1399 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001400 }
1401
1402 if (mFolderInfo != null && mWaitingForResult) {
1403 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1404 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1405 }
Michael Jurka946ad472010-07-09 18:05:18 -07001406
Winson Chung785d2eb2011-04-14 16:08:02 -07001407 // Save the current AppsCustomize tab
1408 if (mAppsCustomizeTabHost != null) {
1409 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1410 if (currentTabTag != null) {
1411 outState.putString("apps_customize_currentTab", currentTabTag);
1412 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001413 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1414 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001415 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001416 }
1417
1418 @Override
1419 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001420 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001421
Winson Chunge7a03942011-08-05 15:05:12 -07001422 // Remove all pending runnables
1423 mHandler.removeMessages(ADVANCE_MSG);
1424 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001425 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001426
Winson Chungcd2b0142011-06-08 16:02:26 -07001427 // Stop callbacks from LauncherModel
1428 LauncherApplication app = ((LauncherApplication) getApplication());
1429 mModel.stopLoader();
1430 app.setLauncher(null);
1431
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001432 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001433 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001434 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001435 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001436 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001437 mAppWidgetHost = null;
1438
1439 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001440
1441 TextKeyListener.getInstance().release();
1442
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001443
Winson Chung3d503fb2011-07-13 17:25:49 -07001444 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001445
1446 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001447 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001448
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001449 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001450 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1451 mWorkspace.removeAllViews();
1452 mWorkspace = null;
1453 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001454
1455 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001456 }
1457
Adam Cohena9cf38f2011-05-02 15:36:58 -07001458 public DragController getDragController() {
1459 return mDragController;
1460 }
1461
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001462 @Override
1463 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001464 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001465 super.startActivityForResult(intent, requestCode);
1466 }
1467
Winson Chung70d72102011-08-12 11:24:35 -07001468 /**
1469 * Indicates that we want global search for this activity by setting the globalSearch
1470 * argument for {@link #startSearch} to true.
1471 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001472 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001473 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001474 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001475
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001476 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001477
Karl Rosaen138a0412009-04-23 19:00:21 -07001478 if (initialQuery == null) {
1479 // Use any text typed in the launcher as the initial query
1480 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001481 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001482 if (appSearchData == null) {
1483 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001484 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001485 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001486 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001487
Karl Rosaen138a0412009-04-23 19:00:21 -07001488 final SearchManager searchManager =
1489 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001490 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001491 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001492 }
1493
Winson Chung70d72102011-08-12 11:24:35 -07001494 @Override
1495 public boolean onCreateOptionsMenu(Menu menu) {
1496 if (isWorkspaceLocked()) {
1497 return false;
1498 }
1499
1500 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001501
1502 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1503 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1504 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001505 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1506 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1507 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001508 String helpUrl = getString(R.string.help_url);
1509 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001510 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1511 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1512
Winson Chung70d72102011-08-12 11:24:35 -07001513 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1514 .setIcon(android.R.drawable.ic_menu_gallery)
1515 .setAlphabeticShortcut('W');
1516 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1517 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001518 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001519 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001520 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1521 .setIcon(android.R.drawable.ic_menu_preferences)
1522 .setIntent(settings)
1523 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001524 if (!helpUrl.isEmpty()) {
1525 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1526 .setIcon(android.R.drawable.ic_menu_help)
1527 .setIntent(help)
1528 .setAlphabeticShortcut('H');
1529 }
Winson Chung70d72102011-08-12 11:24:35 -07001530 return true;
1531 }
1532
1533 @Override
1534 public boolean onPrepareOptionsMenu(Menu menu) {
1535 super.onPrepareOptionsMenu(menu);
1536
1537 if (mAppsCustomizeTabHost.isTransitioning()) {
1538 return false;
1539 }
1540 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1541 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1542
1543 return true;
1544 }
1545
1546 @Override
1547 public boolean onOptionsItemSelected(MenuItem item) {
1548 switch (item.getItemId()) {
1549 case MENU_WALLPAPER_SETTINGS:
1550 startWallpaper();
1551 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001552 }
1553
1554 return super.onOptionsItemSelected(item);
1555 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001556
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001557 @Override
1558 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001559 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001560 // Use a custom animation for launching search
1561 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001562 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001563 }
1564
Joe Onorato9c1289c2009-08-17 11:03:03 -04001565 public boolean isWorkspaceLocked() {
1566 return mWorkspaceLoading || mWaitingForResult;
1567 }
1568
Michael Jurka0280c3b2010-09-17 15:00:07 -07001569 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001570 mPendingAddInfo.container = ItemInfo.NO_ID;
1571 mPendingAddInfo.screen = -1;
1572 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1573 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001574 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001575 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001576 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001577
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001578 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1579 AppWidgetProviderInfo appWidgetInfo) {
1580 if (appWidgetInfo.configure != null) {
1581 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001582
Bjorn Bringert7984c942009-12-09 15:38:25 +00001583 // Launch over to configure widget, if needed
1584 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001585 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001586 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Romain Guy8e633c52010-03-04 12:51:36 -08001587 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001588 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001589 // Otherwise just add it
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001590 completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget,
1591 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001592 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001593 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001594 }
1595 }
Romain Guycbb89e42009-06-08 15:52:54 -07001596
Adam Cohenfbba09b2011-07-18 21:43:05 -07001597 /**
1598 * Process a shortcut drop.
1599 *
1600 * @param componentName The name of the component
1601 * @param screen The screen where it should be added
1602 * @param cell The cell it should be added to, optional
1603 * @param position The location on the screen where it was dropped, optional
1604 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001605 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1606 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001607 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001608 mPendingAddInfo.container = container;
1609 mPendingAddInfo.screen = screen;
1610 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001611
1612 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001613 mPendingAddInfo.cellX = cell[0];
1614 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001615 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001616
1617 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1618 createShortcutIntent.setComponent(componentName);
1619 processShortcut(createShortcutIntent);
1620 }
1621
Adam Cohenfbba09b2011-07-18 21:43:05 -07001622 /**
1623 * Process a widget drop.
1624 *
1625 * @param info The PendingAppWidgetInfo of the widget being added.
1626 * @param screen The screen where it should be added
1627 * @param cell The cell it should be added to, optional
1628 * @param position The location on the screen where it was dropped, optional
1629 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001630 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
Adam Cohend41fbf52012-02-16 23:53:59 -08001631 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001632 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001633 mPendingAddInfo.container = info.container = container;
1634 mPendingAddInfo.screen = info.screen = screen;
1635 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001636 mPendingAddInfo.minSpanX = info.minSpanX;
1637 mPendingAddInfo.minSpanY = info.minSpanY;
1638
Adam Cohenfbba09b2011-07-18 21:43:05 -07001639 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001640 mPendingAddInfo.cellX = cell[0];
1641 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001642 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001643 if (span != null) {
1644 mPendingAddInfo.spanX = span[0];
1645 mPendingAddInfo.spanY = span[1];
1646 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001647
Adam Cohened66b2b2012-01-23 17:28:51 -08001648 AppWidgetHostView hostView = info.boundWidget;
1649 int appWidgetId;
1650 if (hostView != null) {
1651 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001652 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001653 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001654 // In this case, we either need to start an activity to get permission to bind
1655 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001656 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Michael Jurka8b805b12012-04-18 14:23:14 -07001657 if (mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName)) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001658 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001659 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001660 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001661 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1662 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1663 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
1664 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1665 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001666 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001667 }
1668
Joe Onoratodeb98af2010-02-19 14:59:39 -08001669 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001670 // Handle case where user selected "Applications"
1671 String applicationName = getResources().getString(R.string.group_applications);
1672 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001673
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001674 if (applicationName != null && applicationName.equals(shortcutName)) {
1675 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1676 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001677
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001678 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1679 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001680 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001681 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001682 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001683 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001684 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001685 }
1686
Winson Chung24ab2f12010-09-16 14:10:47 -07001687 void processWallpaper(Intent intent) {
1688 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1689 }
1690
Winson Chung3d503fb2011-07-13 17:25:49 -07001691 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1692 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001693 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001694 folderInfo.title = getText(R.string.folder_name);
1695
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001696 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001697 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1698 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001699 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001700
1701 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001702 FolderIcon newFolder =
1703 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1704 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1705 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001706 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001707 }
Romain Guycbb89e42009-06-08 15:52:54 -07001708
Joe Onorato9c1289c2009-08-17 11:03:03 -04001709 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001710 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001711 }
1712
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001713 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001714 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001715 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001716 Intent chooser = Intent.createChooser(pickWallpaper,
1717 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001718 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1719 // Removed in Eclair MR1
1720// WallpaperManager wm = (WallpaperManager)
1721// getSystemService(Context.WALLPAPER_SERVICE);
1722// WallpaperInfo wi = wm.getWallpaperInfo();
1723// if (wi != null && wi.getSettingsActivity() != null) {
1724// LabeledIntent li = new LabeledIntent(getPackageName(),
1725// R.string.configure_wallpaper, 0);
1726// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1727// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1728// }
Mike Clerona0618e42009-10-22 13:55:21 -07001729 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001730 }
1731
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001732 /**
1733 * Registers various content observers. The current implementation registers
1734 * only a favorites observer to keep track of the favorites applications.
1735 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001736 private void registerContentObservers() {
1737 ContentResolver resolver = getContentResolver();
1738 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1739 true, mWidgetObserver);
1740 }
1741
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001742 @Override
1743 public boolean dispatchKeyEvent(KeyEvent event) {
1744 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1745 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001746 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001747 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001748 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001749 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001750 dumpState();
1751 return true;
1752 }
1753 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001754 }
1755 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1756 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001757 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001758 return true;
1759 }
1760 }
1761
1762 return super.dispatchKeyEvent(event);
1763 }
1764
Joe Onorato88ec0992009-11-19 13:16:06 -08001765 @Override
1766 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001767 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001768 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001769 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001770 Folder openFolder = mWorkspace.getOpenFolder();
1771 if (openFolder.isEditingName()) {
1772 openFolder.dismissEditingName();
1773 } else {
1774 closeFolder();
1775 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001776 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001777 mWorkspace.exitWidgetResizeMode();
1778
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001779 // Back button is a no-op here, but give at least some feedback for the button press
1780 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001781 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001782 }
1783
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001784 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001785 * Re-listen when widgets are reset.
1786 */
1787 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001788 if (mAppWidgetHost != null) {
1789 mAppWidgetHost.startListening();
1790 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001791 }
1792
1793 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001794 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1795 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001796 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001797 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001798 if (mModel != null) {
1799 mModel.unbindWorkspaceItems();
1800 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001801 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001802
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001803 /**
1804 * Launches the intent referred by the clicked shortcut.
1805 *
1806 * @param v The view representing the clicked shortcut.
1807 */
1808 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001809 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1810 // view has detached (it's possible for this to happen if the view is removed mid touch).
1811 if (v.getWindowToken() == null) {
1812 return;
1813 }
1814
Winson Chung9b0b2fe2012-02-24 13:03:34 -08001815 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001816 return;
1817 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001818
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001819 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001820 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001821 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001822 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001823 int[] pos = new int[2];
1824 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001825 intent.setSourceBounds(new Rect(pos[0], pos[1],
1826 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07001827
1828 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001829
1830 if (success && v instanceof BubbleTextView) {
1831 mWaitingForResume = (BubbleTextView) v;
1832 mWaitingForResume.setStayPressed(true);
1833 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001834 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001835 if (v instanceof FolderIcon) {
1836 FolderIcon fi = (FolderIcon) v;
1837 handleFolderClick(fi);
1838 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001839 } else if (v == mAllAppsButton) {
1840 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001841 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001842 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001843 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001844 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001845 }
1846 }
1847
Michael Jurka0e260592010-06-30 17:07:39 -07001848 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001849 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001850 // clicking anywhere on the workspace causes the customization drawer to slide down
1851 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001852 return false;
1853 }
1854
Michael Jurkaaf442092010-06-10 17:01:57 -07001855 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001856 * Event handler for the search button
1857 *
1858 * @param v The view that was clicked.
1859 */
1860 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001861 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1862
Amith Yamasania135ba82011-08-09 17:42:01 -07001863 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001864 }
1865
1866 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001867 * Event handler for the voice button
1868 *
1869 * @param v The view that was clicked.
1870 */
1871 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001872 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001873
Michael Jurkaae65ee32012-04-30 11:45:54 -07001874 try {
1875 final SearchManager searchManager =
1876 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1877 ComponentName activityName = searchManager.getGlobalSearchActivity();
1878 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07001879 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001880 if (activityName != null) {
1881 intent.setPackage(activityName.getPackageName());
1882 }
Michael Jurka86a720e2012-05-09 11:23:23 -07001883 startActivity(null, intent, "onClickVoiceButton");
Winson Chung01b0b632012-05-22 10:18:14 -07001884 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001885 } catch (ActivityNotFoundException e) {
1886 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07001887 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001888 startActivitySafely(null, intent, "onClickVoiceButton");
1889 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001890 }
1891
1892 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001893 * Event handler for the "grid" button that appears on the home screen, which
1894 * enters all apps mode.
1895 *
1896 * @param v The view that was clicked.
1897 */
1898 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001899 showAllApps(true);
1900 }
1901
1902 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001903 // Provide the same haptic feedback that the system offers for virtual keys.
1904 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001905 }
1906
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001907 public void onClickAppMarketButton(View v) {
1908 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07001909 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07001910 } else {
1911 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001912 }
1913 }
1914
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001915 void startApplicationDetailsActivity(ComponentName componentName) {
1916 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001917 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1918 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001919 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07001920 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001921 }
1922
Patrick Dubroy5539af72010-09-07 15:22:01 -07001923 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1924 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1925 // System applications cannot be installed. For now, show a toast explaining that.
1926 // We may give them the option of disabling apps this way.
1927 int messageId = R.string.uninstall_system_app_text;
1928 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1929 } else {
1930 String packageName = appInfo.componentName.getPackageName();
1931 String className = appInfo.componentName.getClassName();
1932 Intent intent = new Intent(
1933 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001934 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1935 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001936 startActivity(intent);
1937 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001938 }
1939
Michael Jurka86a720e2012-05-09 11:23:23 -07001940 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001941 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07001942
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001943 try {
Winson Chung2672ff92012-05-04 16:22:30 -07001944 // Only launch using the new animation if the shortcut has not opted out (this is a
1945 // private contract between launcher and may be ignored in the future).
1946 boolean useLaunchAnimation = (v != null) &&
1947 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
1948 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07001949 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
1950 v.getMeasuredWidth(), v.getMeasuredHeight());
1951
1952 startActivity(intent, opts.toBundle());
1953 } else {
1954 startActivity(intent);
1955 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001956 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001957 } catch (SecurityException e) {
1958 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001959 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001960 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001961 "or use the exported attribute for this activity. "
1962 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001963 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001964 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001965 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001966
Michael Jurka86a720e2012-05-09 11:23:23 -07001967 boolean startActivitySafely(View v, Intent intent, Object tag) {
1968 boolean success = false;
1969 try {
1970 success = startActivity(v, intent, tag);
1971 } catch (ActivityNotFoundException e) {
1972 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1973 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
1974 }
1975 return success;
1976 }
1977
Romain Guy8e633c52010-03-04 12:51:36 -08001978 void startActivityForResultSafely(Intent intent, int requestCode) {
1979 try {
1980 startActivityForResult(intent, requestCode);
1981 } catch (ActivityNotFoundException e) {
1982 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1983 } catch (SecurityException e) {
1984 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1985 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1986 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1987 "or use the exported attribute for this activity.", e);
1988 }
1989 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001990
Adam Cohena9cf38f2011-05-02 15:36:58 -07001991 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07001992 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07001993 Folder openFolder = mWorkspace.getFolderForTag(info);
1994
1995 // If the folder info reports that the associated folder is open, then verify that
1996 // it is actually opened. There have been a few instances where this gets out of sync.
1997 if (info.opened && openFolder == null) {
1998 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
1999 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
2000 info.opened = false;
2001 }
2002
Adam Cohenfb91f302012-06-11 15:45:18 -07002003 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002004 // Close any open folder
2005 closeFolder();
2006 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002007 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002008 } else {
2009 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002010 int folderScreen;
2011 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002012 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002013 // .. and close it
2014 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002015 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002016 // Close any folder open on the current screen
2017 closeFolder();
2018 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002019 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002020 }
2021 }
2022 }
2023 }
2024
Adam Cohen268c4752012-06-06 17:47:33 -07002025 /**
2026 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2027 * in the DragLayer in the exact absolute location of the original FolderIcon.
2028 */
2029 private void copyFolderIconToImage(FolderIcon fi) {
2030 final int width = fi.getMeasuredWidth();
2031 final int height = fi.getMeasuredHeight();
2032
2033 // Lazy load ImageView, Bitmap and Canvas
2034 if (mFolderIconImageView == null) {
2035 mFolderIconImageView = new ImageView(this);
2036 }
2037 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2038 mFolderIconBitmap.getHeight() != height) {
2039 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2040 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2041 }
2042
2043 DragLayer.LayoutParams lp;
2044 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2045 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2046 } else {
2047 lp = new DragLayer.LayoutParams(width, height);
2048 }
2049
2050 mDragLayer.getViewRectRelativeToSelf(fi, mRectForFolderAnimation);
2051 lp.customPosition = true;
2052 lp.x = mRectForFolderAnimation.left;
2053 lp.y = mRectForFolderAnimation.top;
Adam Cohen8ec23032012-06-08 14:46:22 -07002054 lp.width = width;
2055 lp.height = height;
Adam Cohen268c4752012-06-06 17:47:33 -07002056
2057 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2058 fi.draw(mFolderIconCanvas);
2059 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002060 if (fi.getFolder() != null) {
2061 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2062 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002063 }
Adam Cohen268c4752012-06-06 17:47:33 -07002064 // Just in case this image view is still in the drag layer from a previous animation,
2065 // we remove it and re-add it.
2066 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2067 mDragLayer.removeView(mFolderIconImageView);
2068 }
2069 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002070 if (fi.getFolder() != null) {
2071 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002072 }
Adam Cohen268c4752012-06-06 17:47:33 -07002073 }
2074
Adam Cohen2801caf2011-05-13 20:57:39 -07002075 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002076 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002077 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2078 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2079 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2080
Adam Cohenc51934b2011-07-26 21:07:43 -07002081 FolderInfo info = (FolderInfo) fi.getTag();
2082 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2083 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002084 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2085 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002086 }
2087
Adam Cohen268c4752012-06-06 17:47:33 -07002088 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2089 copyFolderIconToImage(fi);
2090 fi.setVisibility(View.INVISIBLE);
2091
2092 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(mFolderIconImageView, alpha,
2093 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002094 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2095 oa.start();
2096 }
2097
Adam Cohen268c4752012-06-06 17:47:33 -07002098 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002099 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002100 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2101 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2102 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2103
Adam Cohen268c4752012-06-06 17:47:33 -07002104 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002105
Adam Cohen268c4752012-06-06 17:47:33 -07002106 // We remove and re-draw the FolderIcon in-case it has changed
2107 mDragLayer.removeView(mFolderIconImageView);
2108 copyFolderIconToImage(fi);
Adam Cohen268c4752012-06-06 17:47:33 -07002109 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(mFolderIconImageView, alpha,
2110 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002111 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002112 oa.addListener(new AnimatorListenerAdapter() {
2113 @Override
2114 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002115 if (cl != null) {
2116 cl.clearFolderLeaveBehind();
2117 // Remove the ImageView copy of the FolderIcon and make the original visible.
2118 mDragLayer.removeView(mFolderIconImageView);
2119 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002120 }
2121 }
2122 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002123 oa.start();
2124 }
2125
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002126 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002127 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002128 * is animated relative to the specified View. If the View is null, no animation
2129 * is played.
2130 *
2131 * @param folderInfo The FolderInfo describing the folder to open.
2132 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002133 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002134 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002135 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002136
Adam Cohena9cf38f2011-05-02 15:36:58 -07002137 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002138
Adam Cohen4554ee12011-08-03 16:13:21 -07002139 // Just verify that the folder hasn't already been added to the DragLayer.
2140 // There was a one-off crash where the folder had a parent already.
2141 if (folder.getParent() == null) {
2142 mDragLayer.addView(folder);
2143 mDragController.addDropTarget((DropTarget) folder);
2144 } else {
2145 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2146 folder.getParent() + ").");
2147 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002148 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002149 growAndFadeOutFolderIcon(folderIcon);
Adam Cohen4554ee12011-08-03 16:13:21 -07002150 }
2151
2152 public void closeFolder() {
2153 Folder folder = mWorkspace.getOpenFolder();
2154 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002155 if (folder.isEditingName()) {
2156 folder.dismissEditingName();
2157 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002158 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002159
2160 // Dismiss the folder cling
2161 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002162 }
2163 }
2164
2165 void closeFolder(Folder folder) {
2166 folder.getInfo().opened = false;
2167
2168 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2169 if (parent != null) {
2170 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2171 shrinkAndFadeInFolderIcon(fi);
2172 }
2173 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002174 }
2175
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002176 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002177 if (!isDraggingEnabled()) return false;
2178 if (isWorkspaceLocked()) return false;
2179 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002180
2181 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002182 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002183 }
2184
Michael Jurka0280c3b2010-09-17 15:00:07 -07002185 resetAddInfo();
2186 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002187 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002188 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002189 return true;
2190 }
2191
Winson Chung3d503fb2011-07-13 17:25:49 -07002192 // The hotseat touch handling does not go through Workspace, and we always allow long press
2193 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002194 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002195 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2196 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002197 if (itemUnderLongClick == null) {
2198 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002199 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2200 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002201 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002202 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002203 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002204 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002205 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002206 }
2207 }
2208 }
2209 return true;
2210 }
2211
Winson Chung3d503fb2011-07-13 17:25:49 -07002212 boolean isHotseatLayout(View layout) {
2213 return mHotseat != null && layout != null &&
2214 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2215 }
2216 Hotseat getHotseat() {
2217 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002218 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002219 SearchDropTargetBar getSearchBar() {
2220 return mSearchDropTargetBar;
2221 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002222
Winson Chung3d503fb2011-07-13 17:25:49 -07002223 /**
2224 * Returns the CellLayout of the specified container at the specified screen.
2225 */
2226 CellLayout getCellLayout(long container, int screen) {
2227 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2228 if (mHotseat != null) {
2229 return mHotseat.getLayout();
2230 } else {
2231 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002232 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002233 } else {
2234 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002235 }
2236 }
2237
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002238 Workspace getWorkspace() {
2239 return mWorkspace;
2240 }
2241
Daniel Sandler843e8602010-06-07 14:59:01 -04002242 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2243 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002244 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002245 }
2246
Andrew Flynn0dca1ec2012-02-29 13:33:22 -08002247 public boolean isAllAppsButtonRank(int rank) {
2248 return mHotseat.isAllAppsButtonRank(rank);
2249 }
2250
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002251 // AllAppsView.Watcher
2252 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002253 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002254 mWorkspace.setVisibility(View.GONE);
2255 }
2256 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002257
2258 /**
2259 * Helper method for the cameraZoomIn/cameraZoomOut animations
2260 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002261 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002262 * @param scaleFactor The scale factor used for the zoom
2263 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002264 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002265 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002266 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002267 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002268
Winson Chung18f41f82012-05-09 13:28:10 -07002269 void disableWallpaperIfInAllApps() {
2270 // Only disable it if we are in all apps
2271 if (mState == State.APPS_CUSTOMIZE) {
2272 if (mAppsCustomizeTabHost != null &&
2273 !mAppsCustomizeTabHost.isTransitioning()) {
2274 updateWallpaperVisibility(false);
2275 }
2276 }
2277 }
2278
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002279 void updateWallpaperVisibility(boolean visible) {
2280 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2281 int curflags = getWindow().getAttributes().flags
2282 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2283 if (wpflags != curflags) {
2284 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2285 }
2286 }
2287
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002288 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2289 if (v instanceof LauncherTransitionable) {
2290 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2291 }
2292 }
2293
Michael Jurkabed61d22012-02-14 22:51:29 -08002294 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
Winson Chung7c7a22d2012-06-01 13:46:48 -07002295 if (toWorkspace) {
2296 Log.d(TAG, "6549598 Start animation to workspace");
2297 } else {
2298 Log.d(TAG, "6549598 Start animation to all apps");
2299 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002300 if (v instanceof LauncherTransitionable) {
2301 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2302 }
Winson Chung70442722012-02-10 15:43:22 -08002303
2304 // Update the workspace transition step as well
2305 dispatchOnLauncherTransitionStep(v, 0f);
2306 }
2307
2308 private void dispatchOnLauncherTransitionStep(View v, float t) {
2309 if (v instanceof LauncherTransitionable) {
2310 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2311 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002312 }
2313
2314 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
Winson Chung7c7a22d2012-06-01 13:46:48 -07002315 if (toWorkspace) {
2316 Log.d(TAG, "6549598 End animation to workspace");
2317 } else {
2318 Log.d(TAG, "6549598 End animation to all apps");
2319 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002320 if (v instanceof LauncherTransitionable) {
2321 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2322 }
Winson Chung70442722012-02-10 15:43:22 -08002323
2324 // Update the workspace transition step as well
2325 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002326 }
2327
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002328 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002329 * Things to test when changing the following seven functions.
2330 * - Home from workspace
2331 * - from center screen
2332 * - from other screens
2333 * - Home from all apps
2334 * - from center screen
2335 * - from other screens
2336 * - Back from all apps
2337 * - from center screen
2338 * - from other screens
2339 * - Launch app from workspace and quit
2340 * - with back
2341 * - with home
2342 * - Launch app from all apps and quit
2343 * - with back
2344 * - with home
2345 * - Go to a screen that's not the default, then all
2346 * apps, and launch and app, and go back
2347 * - with back
2348 * -with home
2349 * - On workspace, long press power and go back
2350 * - with back
2351 * - with home
2352 * - On all apps, long press power and go back
2353 * - with back
2354 * - with home
2355 * - On workspace, power off
2356 * - On all apps, power off
2357 * - Launch an app and turn off the screen while in that app
2358 * - Go back with home key
2359 * - Go back with back key TODO: make this not go to workspace
2360 * - From all apps
2361 * - From workspace
2362 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2363 * - From all apps
2364 * - From the center workspace
2365 * - From another workspace
2366 */
2367
2368 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002369 * Zoom the camera out from the workspace to reveal 'toView'.
2370 * Assumes that the view to show is anchored at either the very top or very bottom
2371 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002372 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002373 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002374 if (mStateAnimation != null) {
2375 mStateAnimation.cancel();
2376 mStateAnimation = null;
2377 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002378 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002379
Winson Chungf0ea4d32011-06-06 14:27:16 -07002380 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2381 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2382 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002383 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002384 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002385 final int startDelay =
2386 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002387
Michael Jurkab3e22d92011-10-31 15:58:33 -07002388 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002389
Michael Jurkad74c9842011-07-10 12:44:21 -07002390 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002391 Animator workspaceAnim =
2392 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002393
2394 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002395 toView.setScaleX(scale);
2396 toView.setScaleY(scale);
2397 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2398 scaleAnim.
2399 scaleX(1f).scaleY(1f).
2400 setDuration(duration).
2401 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002402
Winson Chungf0ea4d32011-06-06 14:27:16 -07002403 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002404 toView.setAlpha(0f);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002405 final ObjectAnimator alphaAnim = ObjectAnimator
2406 .ofFloat(toView, "alpha", 0f, 1f)
2407 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002408 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002409 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2410 @Override
2411 public void onAnimationUpdate(ValueAnimator animation) {
2412 float t = (Float) animation.getAnimatedValue();
2413 dispatchOnLauncherTransitionStep(fromView, t);
2414 dispatchOnLauncherTransitionStep(toView, t);
2415 }
2416 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002417
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002418 // toView should appear right at the end of the workspace shrink
2419 // animation
2420 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002421 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002422 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002423
2424 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002425 boolean animationCancelled = false;
2426
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002427 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002428 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002429 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002430 // Prepare the position
2431 toView.setTranslationX(0.0f);
2432 toView.setTranslationY(0.0f);
2433 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002434 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002435 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002436 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002437 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002438 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2439 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002440
2441 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2442 // Hide the workspace scrollbar
2443 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002444 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002445 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002446 if (!animationCancelled) {
2447 updateWallpaperVisibility(false);
2448 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002449
2450 // Hide the search bar
2451 mSearchDropTargetBar.hideSearchBar(false);
Adam Cohenf4ddea32011-09-12 13:46:42 -07002452 }
2453
Adam Cohencff6af82011-09-13 14:51:53 -07002454 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002455 public void onAnimationCancel(Animator animation) {
2456 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002457 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002458 });
2459
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002460 if (workspaceAnim != null) {
2461 mStateAnimation.play(workspaceAnim);
2462 }
Michael Jurka1899a362011-11-03 13:50:45 -07002463
2464 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002465 final ViewTreeObserver observer;
2466
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002467 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2468 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002469
2470 // If any of the objects being animated haven't been measured/laid out
2471 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002472 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002473 (mWorkspace.getMeasuredWidth() == 0) ||
2474 (toView.getMeasuredWidth() == 0)) {
2475 observer = mWorkspace.getViewTreeObserver();
2476 delayAnim = true;
2477 } else {
2478 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002479 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002480
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002481 final AnimatorSet stateAnimation = mStateAnimation;
2482 final Runnable startAnimRunnable = new Runnable() {
2483 public void run() {
2484 // Check that mStateAnimation hasn't changed while
2485 // we waited for a layout/draw pass
2486 if (mStateAnimation != stateAnimation)
2487 return;
2488 setPivotsForZoom(toView, scale);
2489 dispatchOnLauncherTransitionStart(fromView, animated, false);
2490 dispatchOnLauncherTransitionStart(toView, animated, false);
2491 mWorkspace.post(new Runnable() {
2492 public void run() {
2493 // Check that mStateAnimation hasn't changed while
2494 // we waited for a layout/draw pass
2495 if (mStateAnimation != stateAnimation)
2496 return;
2497 mStateAnimation.start();
2498 }
2499 });
2500 }
2501 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002502 if (delayAnim) {
2503 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2504 public void onGlobalLayout() {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002505 mWorkspace.post(startAnimRunnable);
Michael Jurka3a9fced2012-04-13 14:44:29 -07002506 observer.removeOnGlobalLayoutListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002507 }
2508 };
2509 observer.addOnGlobalLayoutListener(delayedStart);
2510 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002511 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002512 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002513 } else {
2514 toView.setTranslationX(0.0f);
2515 toView.setTranslationY(0.0f);
2516 toView.setScaleX(1.0f);
2517 toView.setScaleY(1.0f);
2518 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002519 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002520
Michael Jurkabed61d22012-02-14 22:51:29 -08002521 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2522 // Hide the workspace scrollbar
2523 mWorkspace.hideScrollingIndicator(true);
2524 hideDockDivider();
Winson Chungc7d2b602012-05-16 17:02:20 -07002525
2526 // Hide the search bar
2527 mSearchDropTargetBar.hideSearchBar(false);
Michael Jurkaabded662011-03-04 12:06:57 -08002528 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002529 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002530 dispatchOnLauncherTransitionStart(fromView, animated, false);
2531 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002532 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002533 dispatchOnLauncherTransitionStart(toView, animated, false);
2534 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002535 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002536 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002537 }
2538
2539 /**
2540 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002541 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002542 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002543 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002544 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2545 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002546
Michael Jurkab3e22d92011-10-31 15:58:33 -07002547 if (mStateAnimation != null) {
2548 mStateAnimation.cancel();
2549 mStateAnimation = null;
2550 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002551 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002552
Winson Chungf0ea4d32011-06-06 14:27:16 -07002553 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002554 final int fadeOutDuration =
2555 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002556 final float scaleFactor = (float)
2557 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2558 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002559 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002560 Animator workspaceAnim = null;
2561
2562 if (toState == State.WORKSPACE) {
2563 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2564 workspaceAnim = mWorkspace.getChangeStateAnimation(
2565 Workspace.State.NORMAL, animated, stagger);
2566 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2567 workspaceAnim = mWorkspace.getChangeStateAnimation(
2568 Workspace.State.SPRING_LOADED, animated);
2569 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002570
Michael Jurkab3e22d92011-10-31 15:58:33 -07002571 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002572 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002573 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002574 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002575 final LauncherViewPropertyAnimator scaleAnim =
2576 new LauncherViewPropertyAnimator(fromView);
2577 scaleAnim.
2578 scaleX(scaleFactor).scaleY(scaleFactor).
2579 setDuration(duration).
2580 setInterpolator(new Workspace.ZoomInInterpolator());
2581
2582 final ObjectAnimator alphaAnim = ObjectAnimator
2583 .ofFloat(fromView, "alpha", 1f, 0f)
2584 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002585 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002586 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2587 @Override
2588 public void onAnimationUpdate(ValueAnimator animation) {
2589 float t = 1f - (Float) animation.getAnimatedValue();
2590 dispatchOnLauncherTransitionStep(fromView, t);
2591 dispatchOnLauncherTransitionStep(toView, t);
2592 }
2593 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002594
Michael Jurkabed61d22012-02-14 22:51:29 -08002595 mStateAnimation = new AnimatorSet();
2596
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002597 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2598 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002599
2600 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002601 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002602 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002603 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002604 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002605 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2606 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkabafdaaf2012-04-26 13:43:25 -07002607 if (mWorkspace != null) {
2608 mWorkspace.hideScrollingIndicator(false);
2609 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002610 if (onCompleteRunnable != null) {
2611 onCompleteRunnable.run();
2612 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002613 }
2614 });
2615
Winson Chungf0ea4d32011-06-06 14:27:16 -07002616 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002617 if (workspaceAnim != null) {
2618 mStateAnimation.play(workspaceAnim);
2619 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002620 dispatchOnLauncherTransitionStart(fromView, animated, true);
2621 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002622 final Animator stateAnimation = mStateAnimation;
2623 mWorkspace.post(new Runnable() {
2624 public void run() {
2625 if (stateAnimation != mStateAnimation)
2626 return;
2627 mStateAnimation.start();
2628 }
2629 });
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002630 } else {
2631 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002632 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002633 dispatchOnLauncherTransitionStart(fromView, animated, true);
2634 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002635 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002636 dispatchOnLauncherTransitionStart(toView, animated, true);
2637 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002638 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002639 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002640 }
2641
Michael Jurkae326f182011-11-21 14:05:46 -08002642 @Override
2643 public void onTrimMemory(int level) {
2644 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002645 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002646 mAppsCustomizeTabHost.onTrimMemory();
2647 }
2648 }
2649
Winson Chung18f41f82012-05-09 13:28:10 -07002650 @Override
2651 public void onWindowFocusChanged(boolean hasFocus) {
2652 if (!hasFocus) {
2653 // When another window occludes launcher (like the notification shade, or recents),
2654 // ensure that we enable the wallpaper flag so that transitions are done correctly.
2655 updateWallpaperVisibility(true);
2656 } else {
2657 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07002658 mWorkspace.postDelayed(new Runnable() {
2659 @Override
2660 public void run() {
2661 disableWallpaperIfInAllApps();
2662 }
2663 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07002664 }
2665 }
2666
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002667 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002668 showWorkspace(animated, null);
2669 }
2670
2671 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002672 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002673 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002674 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002675 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002676
Winson Chungc7d2b602012-05-16 17:02:20 -07002677 // Show the search bar (only animate if we were showing the drop target bar in spring
2678 // loaded mode)
2679 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
2680
Michael Jurkab737ee62011-11-15 15:57:22 -08002681 // We only need to animate in the dock divider if we're going from spring loaded mode
Winson Chungc7d2b602012-05-16 17:02:20 -07002682 showDockDivider(animated && wasInSpringLoadedMode);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002683
2684 // Set focus to the AppsCustomize button
2685 if (mAllAppsButton != null) {
2686 mAllAppsButton.requestFocus();
2687 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002688 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002689
Michael Jurkab737ee62011-11-15 15:57:22 -08002690 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002691
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002692 // Change the state *after* we've called all the transition code
2693 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002694
Winson Chung5fb63472011-02-02 17:03:37 -08002695 // Resume the auto-advance of widgets
2696 mUserPresent = true;
2697 updateRunning();
2698
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002699 // send an accessibility event to announce the context change
2700 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002701 }
2702
Michael Jurkab3e22d92011-10-31 15:58:33 -07002703 void showAllApps(boolean animated) {
2704 if (mState != State.WORKSPACE) return;
2705
2706 showAppsCustomizeHelper(animated, false);
2707 mAppsCustomizeTabHost.requestFocus();
2708
Michael Jurkab3e22d92011-10-31 15:58:33 -07002709 // Change the state *after* we've called all the transition code
2710 mState = State.APPS_CUSTOMIZE;
2711
2712 // Pause the auto-advance of widgets until we are out of AllApps
2713 mUserPresent = false;
2714 updateRunning();
2715 closeFolder();
2716
2717 // Send an accessibility event to announce the context change
2718 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2719 }
2720
Adam Cohen7777d962011-08-18 18:58:38 -07002721 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002722 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002723 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002724 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002725 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002726 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002727 }
Adam Cohen7777d962011-08-18 18:58:38 -07002728
Adam Cohened66b2b2012-01-23 17:28:51 -08002729 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2730 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002731 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2732
Winson Chunge7a03942011-08-05 15:05:12 -07002733 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002734 @Override
2735 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002736 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002737 // Before we show workspace, hide all apps again because
2738 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2739 // clean up our state transition functions
2740 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002741 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002742 } else {
2743 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002744 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002745 }
2746 }, (extendedDelay ?
2747 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2748 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2749 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002750
Michael Jurkad3ef3062010-11-23 16:23:58 -08002751 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002752 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002753 final boolean animated = true;
2754 final boolean springLoaded = true;
2755 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002756 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002757 }
2758 // Otherwise, we are not in spring loaded mode, so don't do anything.
2759 }
2760
Michael Jurkab737ee62011-11-15 15:57:22 -08002761 void hideDockDivider() {
2762 if (mQsbDivider != null && mDockDivider != null) {
2763 mQsbDivider.setVisibility(View.INVISIBLE);
2764 mDockDivider.setVisibility(View.INVISIBLE);
2765 }
2766 }
2767
2768 void showDockDivider(boolean animated) {
2769 if (mQsbDivider != null && mDockDivider != null) {
2770 mQsbDivider.setVisibility(View.VISIBLE);
2771 mDockDivider.setVisibility(View.VISIBLE);
2772 if (mDividerAnimator != null) {
2773 mDividerAnimator.cancel();
2774 mQsbDivider.setAlpha(1f);
2775 mDockDivider.setAlpha(1f);
2776 mDividerAnimator = null;
2777 }
2778 if (animated) {
2779 mDividerAnimator = new AnimatorSet();
2780 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2781 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2782 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2783 mDividerAnimator.start();
2784 }
2785 }
2786 }
2787
Michael Jurkab3e22d92011-10-31 15:58:33 -07002788 void lockAllApps() {
2789 // TODO
2790 }
2791
2792 void unlockAllApps() {
2793 // TODO
2794 }
2795
Adam Cohenfc53cd22011-07-20 15:45:11 -07002796 public boolean isAllAppsCustomizeOpen() {
2797 return mState == State.APPS_CUSTOMIZE;
2798 }
2799
Winson Chungf0ea4d32011-06-06 14:27:16 -07002800 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002801 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002802 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002803 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002804 if (!LauncherApplication.isScreenLarge()) {
2805 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002806 if (mHotseat.getAlpha() != 1f) {
2807 int duration = mSearchDropTargetBar.getTransitionInDuration();
2808 mHotseat.animate().alpha(1f).setDuration(duration);
2809 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002810 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002811 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002812 }
2813 }
2814 }
2815
2816 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002817 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002818 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002819 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002820 if (!LauncherApplication.isScreenLarge()) {
2821 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002822 if (mHotseat.getAlpha() != 0f) {
2823 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2824 mHotseat.animate().alpha(0f).setDuration(duration);
2825 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002826 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002827 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002828 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002829 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002830 }
2831
Patrick Dubroy5f445422011-02-18 14:35:21 -08002832 /**
2833 * Add an item from all apps or customize onto the given workspace screen.
2834 * If layout is null, add to the current screen.
2835 */
2836 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002837 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07002838 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07002839 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002840 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002841
Winson Chungdff8ebb2011-09-08 17:25:31 -07002842 /** Maps the current orientation to an index for referencing orientation correct global icons */
2843 private int getCurrentOrientationIndexForGlobalIcons() {
2844 // default - 0, landscape - 1
2845 switch (getResources().getConfiguration().orientation) {
2846 case Configuration.ORIENTATION_LANDSCAPE:
2847 return 1;
2848 default:
2849 return 0;
2850 }
2851 }
2852
Michael Jurkaae65ee32012-04-30 11:45:54 -07002853 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002854 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002855 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002856 // Look for the toolbar icon specified in the activity meta-data
2857 Bundle metaData = packageManager.getActivityInfo(
2858 activityName, PackageManager.GET_META_DATA).metaData;
2859 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002860 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002861 if (iconResId != 0) {
2862 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002863 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002864 }
2865 }
2866 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002867 // This can happen if the activity defines an invalid drawable
2868 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2869 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002870 } catch (Resources.NotFoundException nfe) {
2871 // This can happen if the activity defines an invalid drawable
2872 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2873 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002874 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002875 return null;
2876 }
2877
2878 // if successful in getting icon, return it; otherwise, set button to use default drawable
2879 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002880 int buttonId, ComponentName activityName, int fallbackDrawableId,
2881 String toolbarResourceName) {
2882 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002883 Resources r = getResources();
2884 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2885 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002886
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002887 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002888 // If we were unable to find the icon via the meta-data, use a generic one
2889 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002890 toolbarIcon = r.getDrawable(fallbackDrawableId);
2891 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 null;
2896 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002897 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002898 if (button != null) {
2899 button.setCompoundDrawables(toolbarIcon, null, null, null);
2900 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002901 return toolbarIcon.getConstantState();
2902 }
2903 }
2904
2905 // if successful in getting icon, return it; otherwise, set button to use default drawable
2906 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002907 int buttonId, ComponentName activityName, int fallbackDrawableId,
2908 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002909 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002910 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002911
Michael Jurka19e0fc52011-07-22 18:00:21 -07002912 if (button != null) {
2913 // If we were unable to find the icon via the meta-data, use a
2914 // generic one
2915 if (toolbarIcon == null) {
2916 button.setImageResource(fallbackDrawableId);
2917 } else {
2918 button.setImageDrawable(toolbarIcon);
2919 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002920 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002921
2922 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2923
Michael Jurka0423dcf2010-10-05 14:56:18 -07002924 }
2925
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002926 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2927 TextView button = (TextView) findViewById(buttonId);
2928 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2929 }
2930
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002931 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002932 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002933 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002934 }
2935
Winson Chungbb185bd2011-11-21 12:31:42 -08002936 private void invalidatePressedFocusedStates(View container, View button) {
2937 if (container instanceof HolographicLinearLayout) {
2938 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2939 layout.invalidatePressedFocusedStates();
2940 } else if (button instanceof HolographicImageView) {
2941 HolographicImageView view = (HolographicImageView) button;
2942 view.invalidatePressedFocusedStates();
2943 }
2944 }
2945
Winson Chungc51db6a2011-10-05 11:44:49 -07002946 private boolean updateGlobalSearchIcon() {
2947 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002948 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2949 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002950 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002951 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07002952 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07002953
Winson Chung1cad91e2011-05-25 17:41:01 -07002954 final SearchManager searchManager =
2955 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2956 ComponentName activityName = searchManager.getGlobalSearchActivity();
2957 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002958 int coi = getCurrentOrientationIndexForGlobalIcons();
2959 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002960 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2961 TOOLBAR_SEARCH_ICON_METADATA_NAME);
2962 if (sGlobalSearchIcon[coi] == null) {
2963 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
2964 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2965 TOOLBAR_ICON_METADATA_NAME);
2966 }
2967
Winson Chung649723c2011-07-06 20:41:23 -07002968 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002969 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2970 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002971 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002972 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002973 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002974 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002975 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002976 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2977 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2978 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002979 voiceButton.setVisibility(View.GONE);
Michael Jurkac60498a2012-05-07 15:29:42 -07002980 if (voiceButtonProxy != null) {
2981 voiceButtonProxy.setVisibility(View.GONE);
2982 }
Winson Chungc51db6a2011-10-05 11:44:49 -07002983 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002984 }
2985 }
2986
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002987 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002988 final View searchButtonContainer = findViewById(R.id.search_button_container);
2989 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002990 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002991 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002992 }
2993
Winson Chungc51db6a2011-10-05 11:44:49 -07002994 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002995 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002996 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002997 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07002998 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07002999
Winson Chungc51db6a2011-10-05 11:44:49 -07003000 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003001 final SearchManager searchManager =
3002 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3003 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3004
3005 ComponentName activityName = null;
3006 if (globalSearchActivity != null) {
3007 // Check if the global search activity handles voice search
3008 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3009 intent.setPackage(globalSearchActivity.getPackageName());
3010 activityName = intent.resolveActivity(getPackageManager());
3011 }
3012
3013 if (activityName == null) {
3014 // Fallback: check if an activity other than the global search activity
3015 // resolves this
3016 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3017 activityName = intent.resolveActivity(getPackageManager());
3018 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003019 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003020 int coi = getCurrentOrientationIndexForGlobalIcons();
3021 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003022 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3023 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3024 if (sVoiceSearchIcon[coi] == null) {
3025 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3026 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3027 TOOLBAR_ICON_METADATA_NAME);
3028 }
Winson Chung649723c2011-07-06 20:41:23 -07003029 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07003030 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003031 voiceButton.setVisibility(View.VISIBLE);
Jim Miller14091b12012-04-24 19:27:54 -07003032 if (voiceButtonProxy != null) {
3033 voiceButtonProxy.setVisibility(View.VISIBLE);
3034 }
Winson Chungbb185bd2011-11-21 12:31:42 -08003035 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003036 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003037 } else {
Winson Chung649723c2011-07-06 20:41:23 -07003038 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07003039 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003040 voiceButton.setVisibility(View.GONE);
Jim Miller14091b12012-04-24 19:27:54 -07003041 if (voiceButtonProxy != null) {
3042 voiceButtonProxy.setVisibility(View.GONE);
3043 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003044 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003045 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003046 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003047
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003048 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003049 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3050 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003051 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003052 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003053 }
3054
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003055 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003056 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003057 */
3058 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003059 final View marketButton = findViewById(R.id.market_button);
3060 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3061 // Find the app market activity by resolving an intent.
3062 // (If multiple app markets are installed, it will return the ResolverActivity.)
3063 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003064 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003065 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003066 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003067 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003068 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3069 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003070 marketButton.setVisibility(View.VISIBLE);
3071 } else {
3072 // We should hide and disable the view so that we don't try and restore the visibility
3073 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3074 marketButton.setVisibility(View.GONE);
3075 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003076 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003077 }
3078
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003079 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003080 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003081 }
3082
Michael Jurkad7c28052012-04-27 15:43:36 -07003083 @Override
3084 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
3085 boolean result = super.dispatchPopulateAccessibilityEvent(event);
3086 final List<CharSequence> text = event.getText();
3087 text.clear();
3088 text.add(getString(R.string.home));
3089 return result;
3090 }
3091
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003092 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003093 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003094 */
3095 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3096 @Override
3097 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003098 closeSystemDialogs();
3099 }
3100 }
3101
3102 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003103 * Receives notifications whenever the appwidgets are reset.
3104 */
3105 private class AppWidgetResetObserver extends ContentObserver {
3106 public AppWidgetResetObserver() {
3107 super(new Handler());
3108 }
3109
3110 @Override
3111 public void onChange(boolean selfChange) {
3112 onAppWidgetReset();
3113 }
3114 }
3115
3116 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003117 * If the activity is currently paused, signal that we need to re-run the loader
3118 * in onResume.
3119 *
3120 * This needs to be called from incoming places where resources might have been loaded
3121 * while we are paused. That is becaues the Configuration might be wrong
3122 * when we're not running, and if it comes back to what it was when we
3123 * were paused, we are not restarted.
3124 *
3125 * Implementation of the method from LauncherModel.Callbacks.
3126 *
3127 * @return true if we are currently paused. The caller might be able to
3128 * skip some work in that case since we will come back again.
3129 */
3130 public boolean setLoadOnResume() {
3131 if (mPaused) {
3132 Log.i(TAG, "setLoadOnResume");
3133 mOnResumeNeedsLoad = true;
3134 return true;
3135 } else {
3136 return false;
3137 }
3138 }
3139
3140 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003141 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003142 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003143 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003144 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003145 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003146 } else {
3147 return SCREEN_COUNT / 2;
3148 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003149 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003150
Joe Onorato9c1289c2009-08-17 11:03:03 -04003151 /**
3152 * Refreshes the shortcuts shown on the workspace.
3153 *
3154 * Implementation of the method from LauncherModel.Callbacks.
3155 */
3156 public void startBinding() {
3157 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07003158
Winson Chungf0c6ae02012-03-21 16:10:31 -07003159 mNewShortcutAnimatePage = -1;
3160 mNewShortcutAnimateViews.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003161 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003162 int count = workspace.getChildCount();
3163 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003164 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003165 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3166 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003167 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08003168 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003169 if (mHotseat != null) {
3170 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003171 }
3172 }
3173
3174 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003175 * Bind the items start-end from the list.
3176 *
3177 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003178 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003179 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003180 setLoadOnResume();
3181
Winson Chungf0c6ae02012-03-21 16:10:31 -07003182 // Get the list of added shortcuts and intersect them with the set of shortcuts here
3183 Set<String> newApps = new HashSet<String>();
3184 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);
3185
3186 Workspace workspace = mWorkspace;
3187 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003188 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003189
3190 // Short circuit if we are loading dock items for a configuration which has no dock
3191 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3192 mHotseat == null) {
3193 continue;
3194 }
3195
Joe Onorato9c1289c2009-08-17 11:03:03 -04003196 switch (item.itemType) {
3197 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3198 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003199 ShortcutInfo info = (ShortcutInfo) item;
3200 String uri = info.intent.toUri(0).toString();
3201 View shortcut = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -07003202 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3203 item.cellY, 1, 1, false);
Winson Chungbfeac062012-06-06 15:56:08 -07003204 boolean animateIconUp = false;
3205 synchronized (newApps) {
3206 if (newApps.contains(uri)) {
3207 animateIconUp = newApps.remove(uri);
3208 }
3209 }
3210 if (animateIconUp) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003211 // Prepare the view to be animated up
3212 shortcut.setAlpha(0f);
3213 shortcut.setScaleX(0f);
3214 shortcut.setScaleY(0f);
3215 mNewShortcutAnimatePage = item.screen;
3216 if (!mNewShortcutAnimateViews.contains(shortcut)) {
3217 mNewShortcutAnimateViews.add(shortcut);
3218 }
3219 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003220 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003221 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003222 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003223 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003224 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003225 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3226 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003227 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003228 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003229 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003230
Joe Onorato9c1289c2009-08-17 11:03:03 -04003231 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003232 }
3233
Joe Onorato9c1289c2009-08-17 11:03:03 -04003234 /**
3235 * Implementation of the method from LauncherModel.Callbacks.
3236 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003237 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003238 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003239 sFolders.clear();
3240 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003241 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003242
3243 /**
3244 * Add the views for a widget to the workspace.
3245 *
3246 * Implementation of the method from LauncherModel.Callbacks.
3247 */
3248 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003249 setLoadOnResume();
3250
Daniel Sandler843e8602010-06-07 14:59:01 -04003251 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3252 if (DEBUG_WIDGETS) {
3253 Log.d(TAG, "bindAppWidget: " + item);
3254 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003255 final Workspace workspace = mWorkspace;
3256
3257 final int appWidgetId = item.appWidgetId;
3258 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003259 if (DEBUG_WIDGETS) {
3260 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3261 }
3262
Joe Onorato9c1289c2009-08-17 11:03:03 -04003263 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3264
Joe Onorato9c1289c2009-08-17 11:03:03 -04003265 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003266 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003267
Winson Chung3d503fb2011-07-13 17:25:49 -07003268 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003269 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003270 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3271
Joe Onorato9c1289c2009-08-17 11:03:03 -04003272 workspace.requestLayout();
3273
Daniel Sandler843e8602010-06-07 14:59:01 -04003274 if (DEBUG_WIDGETS) {
3275 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3276 + (SystemClock.uptimeMillis()-start) + "ms");
3277 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003278 }
3279
3280 /**
3281 * Callback saying that there aren't any more items to bind.
3282 *
3283 * Implementation of the method from LauncherModel.Callbacks.
3284 */
3285 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003286 setLoadOnResume();
3287
Joe Onorato9c1289c2009-08-17 11:03:03 -04003288 if (mSavedState != null) {
3289 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003290 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003291 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003292 mSavedState = null;
3293 }
3294
3295 if (mSavedInstanceState != null) {
3296 super.onRestoreInstanceState(mSavedInstanceState);
3297 mSavedInstanceState = null;
3298 }
3299
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003300 // If we received the result of any pending adds while the loader was running (e.g. the
3301 // widget configuration forced an orientation change), process them now.
3302 for (int i = 0; i < sPendingAddList.size(); i++) {
3303 completeAdd(sPendingAddList.get(i));
3304 }
3305 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003306
Winson Chungc51db6a2011-10-05 11:44:49 -07003307 // Update the market app icon as necessary (the other icons will be managed in response to
3308 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003309 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003310
Winson Chungf0c6ae02012-03-21 16:10:31 -07003311 // Animate up any icons as necessary
3312 if (mVisible || mWorkspaceLoading) {
3313 Runnable newAppsRunnable = new Runnable() {
3314 @Override
3315 public void run() {
Winson Chunga2413752012-04-03 14:22:34 -07003316 runNewAppsAnimation(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003317 }
3318 };
Winson Chunga2413752012-04-03 14:22:34 -07003319
3320 boolean willSnapPage = mNewShortcutAnimatePage > -1 &&
3321 mNewShortcutAnimatePage != mWorkspace.getCurrentPage();
3322 if (canRunNewAppsAnimation()) {
3323 // If the user has not interacted recently, then either snap to the new page to show
3324 // the new-apps animation or just run them if they are to appear on the current page
3325 if (willSnapPage) {
3326 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable);
3327 } else {
3328 runNewAppsAnimation(false);
3329 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003330 } else {
Winson Chung318eee02012-04-12 10:59:27 -07003331 // If the user has interacted recently, then just add the items in place if they
Winson Chunga2413752012-04-03 14:22:34 -07003332 // are on another page (or just normally if they are added to the current page)
3333 runNewAppsAnimation(willSnapPage);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003334 }
3335 }
3336
3337 mWorkspaceLoading = false;
3338 }
3339
Winson Chunga2413752012-04-03 14:22:34 -07003340 private boolean canRunNewAppsAnimation() {
3341 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3342 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3343 }
3344
Winson Chungf0c6ae02012-03-21 16:10:31 -07003345 /**
3346 * Runs a new animation that scales up icons that were added while Launcher was in the
3347 * background.
Winson Chunga2413752012-04-03 14:22:34 -07003348 *
3349 * @param immediate whether to run the animation or show the results immediately
Winson Chungf0c6ae02012-03-21 16:10:31 -07003350 */
Winson Chunga2413752012-04-03 14:22:34 -07003351 private void runNewAppsAnimation(boolean immediate) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003352 AnimatorSet anim = new AnimatorSet();
3353 Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chunga2413752012-04-03 14:22:34 -07003354
3355 // Order these new views spatially so that they animate in order
Winson Chungf0c6ae02012-03-21 16:10:31 -07003356 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
3357 @Override
3358 public int compare(View a, View b) {
3359 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
3360 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
3361 int cellCountX = LauncherModel.getCellCountX();
3362 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
3363 }
3364 });
Winson Chunga2413752012-04-03 14:22:34 -07003365
3366 // Animate each of the views in place (or show them immediately if requested)
3367 if (immediate) {
3368 for (View v : mNewShortcutAnimateViews) {
3369 v.setAlpha(1f);
3370 v.setScaleX(1f);
3371 v.setScaleY(1f);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003372 }
Winson Chunga2413752012-04-03 14:22:34 -07003373 } else {
3374 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
3375 View v = mNewShortcutAnimateViews.get(i);
3376 ValueAnimator bounceAnim = ObjectAnimator.ofPropertyValuesHolder(v,
3377 PropertyValuesHolder.ofFloat("alpha", 1f),
3378 PropertyValuesHolder.ofFloat("scaleX", 1f),
3379 PropertyValuesHolder.ofFloat("scaleY", 1f));
3380 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3381 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3382 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3383 bounceAnims.add(bounceAnim);
3384 }
3385 anim.playTogether(bounceAnims);
3386 anim.addListener(new AnimatorListenerAdapter() {
3387 @Override
3388 public void onAnimationEnd(Animator animation) {
3389 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
3390 }
3391 });
3392 anim.start();
3393 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003394
3395 // Clean up
3396 mNewShortcutAnimatePage = -1;
3397 mNewShortcutAnimateViews.clear();
3398 new Thread("clearNewAppsThread") {
3399 public void run() {
3400 mSharedPrefs.edit()
3401 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
3402 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null)
3403 .commit();
3404 }
3405 }.start();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003406 }
3407
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003408 @Override
3409 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003410 boolean searchVisible = updateGlobalSearchIcon();
3411 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3412 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003413 }
3414
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003415 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003416 * Add the icons for all apps.
3417 *
3418 * Implementation of the method from LauncherModel.Callbacks.
3419 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003420 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3421 // Remove the progress bar entirely; we could also make it GONE
3422 // but better to remove it since we know it's not going to be used
3423 View progressBar = mAppsCustomizeTabHost.
3424 findViewById(R.id.apps_customize_progress_bar);
3425 if (progressBar != null) {
3426 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003427 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003428 // We just post the call to setApps so the user sees the progress bar
3429 // disappear-- otherwise, it just looks like the progress bar froze
3430 // which doesn't look great
3431 mAppsCustomizeTabHost.post(new Runnable() {
3432 public void run() {
3433 if (mAppsCustomizeContent != null) {
3434 mAppsCustomizeContent.setApps(apps);
3435 }
3436 }
3437 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003438 }
3439
3440 /**
3441 * A package was installed.
3442 *
3443 * Implementation of the method from LauncherModel.Callbacks.
3444 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003445 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003446 setLoadOnResume();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003447
Winson Chung785d2eb2011-04-14 16:08:02 -07003448 if (mAppsCustomizeContent != null) {
3449 mAppsCustomizeContent.addApps(apps);
3450 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003451 }
3452
3453 /**
3454 * A package was updated.
3455 *
3456 * Implementation of the method from LauncherModel.Callbacks.
3457 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003458 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003459 setLoadOnResume();
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003460 if (mWorkspace != null) {
3461 mWorkspace.updateShortcuts(apps);
3462 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003463
Winson Chung785d2eb2011-04-14 16:08:02 -07003464 if (mAppsCustomizeContent != null) {
3465 mAppsCustomizeContent.updateApps(apps);
3466 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003467 }
3468
3469 /**
3470 * A package was uninstalled.
3471 *
3472 * Implementation of the method from LauncherModel.Callbacks.
3473 */
Joe Onorato36115782010-06-17 13:28:48 -04003474 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato36115782010-06-17 13:28:48 -04003475 if (permanent) {
3476 mWorkspace.removeItems(apps);
3477 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003478
Winson Chung785d2eb2011-04-14 16:08:02 -07003479 if (mAppsCustomizeContent != null) {
3480 mAppsCustomizeContent.removeApps(apps);
3481 }
Winson Chunga1820962011-10-03 16:31:06 -07003482
3483 // Notify the drag controller
3484 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003485 }
Joe Onoratobe386092009-11-17 17:32:16 -08003486
3487 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003488 * A number of packages were updated.
3489 */
3490 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003491 if (mAppsCustomizeContent != null) {
3492 mAppsCustomizeContent.onPackagesUpdated();
3493 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003494 }
3495
Winson Chung400438b2011-01-16 17:53:48 -08003496 private int mapConfigurationOriActivityInfoOri(int configOri) {
3497 final Display d = getWindowManager().getDefaultDisplay();
3498 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3499 switch (d.getRotation()) {
3500 case Surface.ROTATION_0:
3501 case Surface.ROTATION_180:
3502 // We are currently in the same basic orientation as the natural orientation
3503 naturalOri = configOri;
3504 break;
3505 case Surface.ROTATION_90:
3506 case Surface.ROTATION_270:
3507 // We are currently in the other basic orientation to the natural orientation
3508 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3509 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3510 break;
3511 }
3512
3513 int[] oriMap = {
3514 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3515 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3516 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3517 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3518 };
3519 // Since the map starts at portrait, we need to offset if this device's natural orientation
3520 // is landscape.
3521 int indexOffset = 0;
3522 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3523 indexOffset = 1;
3524 }
3525 return oriMap[(d.getRotation() + indexOffset) % 4];
3526 }
Adam Cohen446e9402011-09-15 18:21:21 -07003527
Winson Chung4b919f82012-05-01 10:44:08 -07003528 public boolean isRotationEnabled() {
3529 boolean forceEnableRotation = "true".equalsIgnoreCase(SystemProperties.get(
3530 FORCE_ENABLE_ROTATION_PROPERTY, "false"));
3531 boolean enableRotation = forceEnableRotation ||
3532 getResources().getBoolean(R.bool.allow_rotation);
3533 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08003534 }
Winson Chung4b919f82012-05-01 10:44:08 -07003535 public void lockScreenOrientation() {
3536 if (isRotationEnabled()) {
3537 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3538 .getConfiguration().orientation));
3539 }
3540 }
3541 public void unlockScreenOrientation(boolean immediate) {
3542 if (isRotationEnabled()) {
3543 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07003544 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07003545 } else {
3546 mHandler.postDelayed(new Runnable() {
3547 public void run() {
3548 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3549 }
3550 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07003551 }
Winson Chung4b919f82012-05-01 10:44:08 -07003552 }
Winson Chung400438b2011-01-16 17:53:48 -08003553 }
3554
Winson Chung82f55532011-08-09 14:14:23 -07003555 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003556 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003557 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003558 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003559
Winson Chung7d7541e2011-09-16 20:14:36 -07003560 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003561 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003562 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3563 Cling cling = (Cling) findViewById(clingId);
3564 if (cling != null) {
3565 cling.init(this, positionData);
3566 cling.setVisibility(View.VISIBLE);
3567 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Svetoslav Ganov55d225d2012-05-22 15:19:14 -07003568 cling.requestAccessibilityFocus();
Winson Chung7d7541e2011-09-16 20:14:36 -07003569 if (animate) {
3570 cling.buildLayer();
3571 cling.setAlpha(0f);
3572 cling.animate()
3573 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003574 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003575 .setDuration(SHOW_CLING_DURATION)
3576 .setStartDelay(delay)
3577 .start();
3578 } else {
3579 cling.setAlpha(1f);
3580 }
3581 }
3582 return cling;
3583 }
3584 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003585 if (cling != null) {
3586 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003587 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003588 anim.addListener(new AnimatorListenerAdapter() {
3589 public void onAnimationEnd(Animator animation) {
3590 cling.setVisibility(View.GONE);
3591 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003592 // We should update the shared preferences on a background thread
3593 new Thread("dismissClingThread") {
3594 public void run() {
3595 SharedPreferences.Editor editor = mSharedPrefs.edit();
3596 editor.putBoolean(flag, true);
3597 editor.commit();
3598 }
3599 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003600 };
3601 });
3602 anim.start();
3603 }
3604 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003605 private void removeCling(int id) {
3606 final View cling = findViewById(id);
3607 if (cling != null) {
3608 final ViewGroup parent = (ViewGroup) cling.getParent();
3609 parent.post(new Runnable() {
3610 @Override
3611 public void run() {
3612 parent.removeView(cling);
3613 }
3614 });
3615 }
3616 }
Michael Jurka974c3862012-05-22 22:00:31 -07003617
3618 private boolean skipCustomClingIfNoAccounts() {
3619 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3620 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
3621 if (customCling) {
3622 AccountManager am = AccountManager.get(this);
3623 Account[] accounts = am.getAccountsByType("com.google");
3624 return accounts.length == 0;
3625 }
3626 return false;
3627 }
3628
Winson Chung7d7541e2011-09-16 20:14:36 -07003629 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003630 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003631 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07003632 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
3633 !skipCustomClingIfNoAccounts() ) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003634 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003635 } else {
3636 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003637 }
3638 }
3639 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003640 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003641 if (isClingsEnabled() &&
3642 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003643 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003644 } else {
3645 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003646 }
3647 }
3648 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003649 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003650 if (isClingsEnabled() &&
3651 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
3652 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003653 } else {
3654 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08003655 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07003656 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003657 }
3658 public boolean isFolderClingVisible() {
3659 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003660 if (cling != null) {
3661 return cling.getVisibility() == View.VISIBLE;
3662 }
3663 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003664 }
Winson Chung82f55532011-08-09 14:14:23 -07003665 public void dismissWorkspaceCling(View v) {
3666 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003667 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003668 }
3669 public void dismissAllAppsCling(View v) {
3670 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003671 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3672 }
3673 public void dismissFolderCling(View v) {
3674 Cling cling = (Cling) findViewById(R.id.folder_cling);
3675 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003676 }
3677
Winson Chung80baf5a2010-08-09 16:03:15 -07003678 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003679 * Prints out out state for debugging.
3680 */
3681 public void dumpState() {
3682 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003683 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003684 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3685 Log.d(TAG, "mRestoring=" + mRestoring);
3686 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3687 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003688 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003689 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003690
Winson Chung785d2eb2011-04-14 16:08:02 -07003691 if (mAppsCustomizeContent != null) {
3692 mAppsCustomizeContent.dumpState();
3693 }
Joe Onoratobe386092009-11-17 17:32:16 -08003694 Log.d(TAG, "END launcher2 dump state");
3695 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003696
3697 @Override
3698 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3699 super.dump(prefix, fd, writer, args);
3700 writer.println(" ");
3701 writer.println("Debug logs: ");
3702 for (int i = 0; i < sDumpLogs.size(); i++) {
3703 writer.println(" " + sDumpLogs.get(i));
3704 }
3705 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003706}
Michael Jurka2763be32011-02-24 11:19:57 -08003707
Michael Jurkaabded662011-03-04 12:06:57 -08003708interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003709 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003710 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08003711 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08003712 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08003713 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003714}