blob: 7da5b56c84adc1275a0cc078bffe14a8a5a714c5 [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
1236 // We had to enable the wallpaper visibility when launching apps from all
1237 // apps (so that the transitions would be the same as when launching from
1238 // workspace) so take this time to see if we need to re-disable the
1239 // wallpaper visibility to ensure performance.
1240 mWorkspace.post(new Runnable() {
1241 @Override
1242 public void run() {
Winson Chung18f41f82012-05-09 13:28:10 -07001243 disableWallpaperIfInAllApps();
Winson Chung31ce0732012-05-06 13:36:43 -07001244 }
1245 });
1246
Michael Jurka6ee21d22012-02-21 18:20:27 -08001247 observer.removeOnPreDrawListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001248 return true;
1249 }
1250 });
1251 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001252 // When Launcher comes back to foreground, a different Activity might be responsible for
1253 // the app market intent, so refresh the icon
1254 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001255 clearTypedText();
1256 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001257 }
1258
1259 private void sendAdvanceMessage(long delay) {
1260 mHandler.removeMessages(ADVANCE_MSG);
1261 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1262 mHandler.sendMessageDelayed(msg, delay);
1263 mAutoAdvanceSentTime = System.currentTimeMillis();
1264 }
1265
1266 private void updateRunning() {
1267 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1268 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1269 mAutoAdvanceRunning = autoAdvanceRunning;
1270 if (autoAdvanceRunning) {
1271 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1272 sendAdvanceMessage(delay);
1273 } else {
1274 if (!mWidgetsToAdvance.isEmpty()) {
1275 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1276 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1277 }
1278 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001279 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001280 }
1281 }
1282 }
1283
1284 private final Handler mHandler = new Handler() {
1285 @Override
1286 public void handleMessage(Message msg) {
1287 if (msg.what == ADVANCE_MSG) {
1288 int i = 0;
1289 for (View key: mWidgetsToAdvance.keySet()) {
1290 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1291 final int delay = mAdvanceStagger * i;
1292 if (v instanceof Advanceable) {
1293 postDelayed(new Runnable() {
1294 public void run() {
1295 ((Advanceable) v).advance();
1296 }
1297 }, delay);
1298 }
1299 i++;
1300 }
1301 sendAdvanceMessage(mAdvanceInterval);
1302 }
1303 }
1304 };
1305
1306 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001307 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001308 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1309 if (v instanceof Advanceable) {
1310 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001311 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001312 updateRunning();
1313 }
1314 }
1315
1316 void removeWidgetToAutoAdvance(View hostView) {
1317 if (mWidgetsToAdvance.containsKey(hostView)) {
1318 mWidgetsToAdvance.remove(hostView);
1319 updateRunning();
1320 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001321 }
1322
Joe Onorato9c1289c2009-08-17 11:03:03 -04001323 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001324 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001325 launcherInfo.hostView = null;
1326 }
1327
Winson Chung93eef082012-03-23 15:59:27 -07001328 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1329 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1330 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001331 }
1332
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001333 public LauncherAppWidgetHost getAppWidgetHost() {
1334 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001335 }
Romain Guycbb89e42009-06-08 15:52:54 -07001336
Winson Chunga9abd0e2010-10-27 17:18:37 -07001337 public LauncherModel getModel() {
1338 return mModel;
1339 }
1340
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001341 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001342 getWindow().closeAllPanels();
1343
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001344 // Whatever we were doing is hereby canceled.
1345 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001346 }
1347
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001348 @Override
1349 protected void onNewIntent(Intent intent) {
1350 super.onNewIntent(intent);
1351
1352 // Close the menu
1353 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001354 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001355 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001356
Joe Onorato14f122b2009-11-19 14:06:36 -08001357 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1358 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001359
Adam Cohenac56cff2011-09-28 20:45:37 -07001360 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001361 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001362 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001363 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1364 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001365 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001366 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001367
1368 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001369 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001370 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001371
Joe Onorato3a8820b2009-11-10 15:06:42 -08001372 final View v = getWindow().peekDecorView();
1373 if (v != null && v.getWindowToken() != null) {
1374 InputMethodManager imm = (InputMethodManager)getSystemService(
1375 INPUT_METHOD_SERVICE);
1376 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001377 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001378
Michael Jurka35aa14d2011-07-07 17:01:08 -07001379 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001380 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001381 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001382 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001383 }
1384 }
1385
1386 @Override
1387 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1388 // Do not call super here
1389 mSavedInstanceState = savedInstanceState;
1390 }
1391
1392 @Override
1393 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001394 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001395 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001396
Michael Jurka883f55b2010-10-21 15:47:14 -07001397 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001398 // We close any open folder since it will not be re-opened, and we need to make sure
1399 // this state is reflected.
1400 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001401
Winson Chung3d503fb2011-07-13 17:25:49 -07001402 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1403 mWaitingForResult) {
1404 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1405 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1406 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1407 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001408 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1409 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1410 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001411 }
1412
1413 if (mFolderInfo != null && mWaitingForResult) {
1414 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1415 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1416 }
Michael Jurka946ad472010-07-09 18:05:18 -07001417
Winson Chung785d2eb2011-04-14 16:08:02 -07001418 // Save the current AppsCustomize tab
1419 if (mAppsCustomizeTabHost != null) {
1420 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1421 if (currentTabTag != null) {
1422 outState.putString("apps_customize_currentTab", currentTabTag);
1423 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001424 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1425 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001426 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001427 }
1428
1429 @Override
1430 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001431 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001432
Winson Chunge7a03942011-08-05 15:05:12 -07001433 // Remove all pending runnables
1434 mHandler.removeMessages(ADVANCE_MSG);
1435 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001436 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001437
Winson Chungcd2b0142011-06-08 16:02:26 -07001438 // Stop callbacks from LauncherModel
1439 LauncherApplication app = ((LauncherApplication) getApplication());
1440 mModel.stopLoader();
1441 app.setLauncher(null);
1442
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001443 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001444 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001445 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001446 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001447 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001448 mAppWidgetHost = null;
1449
1450 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001451
1452 TextKeyListener.getInstance().release();
1453
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001454
Winson Chung3d503fb2011-07-13 17:25:49 -07001455 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001456
1457 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001458 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001459
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001460 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001461 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1462 mWorkspace.removeAllViews();
1463 mWorkspace = null;
1464 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001465
1466 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001467 }
1468
Adam Cohena9cf38f2011-05-02 15:36:58 -07001469 public DragController getDragController() {
1470 return mDragController;
1471 }
1472
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001473 @Override
1474 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001475 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001476 super.startActivityForResult(intent, requestCode);
1477 }
1478
Winson Chung70d72102011-08-12 11:24:35 -07001479 /**
1480 * Indicates that we want global search for this activity by setting the globalSearch
1481 * argument for {@link #startSearch} to true.
1482 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001483 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001484 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001485 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001486
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001487 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001488
Karl Rosaen138a0412009-04-23 19:00:21 -07001489 if (initialQuery == null) {
1490 // Use any text typed in the launcher as the initial query
1491 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001492 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001493 if (appSearchData == null) {
1494 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001495 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001496 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001497 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001498
Karl Rosaen138a0412009-04-23 19:00:21 -07001499 final SearchManager searchManager =
1500 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001501 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001502 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001503 }
1504
Winson Chung70d72102011-08-12 11:24:35 -07001505 @Override
1506 public boolean onCreateOptionsMenu(Menu menu) {
1507 if (isWorkspaceLocked()) {
1508 return false;
1509 }
1510
1511 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001512
1513 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1514 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1515 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001516 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1517 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1518 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001519 String helpUrl = getString(R.string.help_url);
1520 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001521 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1522 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1523
Winson Chung70d72102011-08-12 11:24:35 -07001524 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1525 .setIcon(android.R.drawable.ic_menu_gallery)
1526 .setAlphabeticShortcut('W');
1527 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1528 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001529 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001530 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001531 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1532 .setIcon(android.R.drawable.ic_menu_preferences)
1533 .setIntent(settings)
1534 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001535 if (!helpUrl.isEmpty()) {
1536 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1537 .setIcon(android.R.drawable.ic_menu_help)
1538 .setIntent(help)
1539 .setAlphabeticShortcut('H');
1540 }
Winson Chung70d72102011-08-12 11:24:35 -07001541 return true;
1542 }
1543
1544 @Override
1545 public boolean onPrepareOptionsMenu(Menu menu) {
1546 super.onPrepareOptionsMenu(menu);
1547
1548 if (mAppsCustomizeTabHost.isTransitioning()) {
1549 return false;
1550 }
1551 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1552 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1553
1554 return true;
1555 }
1556
1557 @Override
1558 public boolean onOptionsItemSelected(MenuItem item) {
1559 switch (item.getItemId()) {
1560 case MENU_WALLPAPER_SETTINGS:
1561 startWallpaper();
1562 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001563 }
1564
1565 return super.onOptionsItemSelected(item);
1566 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001567
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001568 @Override
1569 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001570 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001571 // Use a custom animation for launching search
1572 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001573 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001574 }
1575
Joe Onorato9c1289c2009-08-17 11:03:03 -04001576 public boolean isWorkspaceLocked() {
1577 return mWorkspaceLoading || mWaitingForResult;
1578 }
1579
Michael Jurka0280c3b2010-09-17 15:00:07 -07001580 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001581 mPendingAddInfo.container = ItemInfo.NO_ID;
1582 mPendingAddInfo.screen = -1;
1583 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1584 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001585 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001586 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001587 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001588
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001589 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1590 AppWidgetProviderInfo appWidgetInfo) {
1591 if (appWidgetInfo.configure != null) {
1592 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001593
Bjorn Bringert7984c942009-12-09 15:38:25 +00001594 // Launch over to configure widget, if needed
1595 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001596 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001597 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Romain Guy8e633c52010-03-04 12:51:36 -08001598 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001599 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001600 // Otherwise just add it
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001601 completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget,
1602 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001603 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001604 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001605 }
1606 }
Romain Guycbb89e42009-06-08 15:52:54 -07001607
Adam Cohenfbba09b2011-07-18 21:43:05 -07001608 /**
1609 * Process a shortcut drop.
1610 *
1611 * @param componentName The name of the component
1612 * @param screen The screen where it should be added
1613 * @param cell The cell it should be added to, optional
1614 * @param position The location on the screen where it was dropped, optional
1615 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001616 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1617 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001618 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001619 mPendingAddInfo.container = container;
1620 mPendingAddInfo.screen = screen;
1621 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001622
1623 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001624 mPendingAddInfo.cellX = cell[0];
1625 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001626 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001627
1628 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1629 createShortcutIntent.setComponent(componentName);
1630 processShortcut(createShortcutIntent);
1631 }
1632
Adam Cohenfbba09b2011-07-18 21:43:05 -07001633 /**
1634 * Process a widget drop.
1635 *
1636 * @param info The PendingAppWidgetInfo of the widget being added.
1637 * @param screen The screen where it should be added
1638 * @param cell The cell it should be added to, optional
1639 * @param position The location on the screen where it was dropped, optional
1640 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001641 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
Adam Cohend41fbf52012-02-16 23:53:59 -08001642 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001643 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001644 mPendingAddInfo.container = info.container = container;
1645 mPendingAddInfo.screen = info.screen = screen;
1646 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001647 mPendingAddInfo.minSpanX = info.minSpanX;
1648 mPendingAddInfo.minSpanY = info.minSpanY;
1649
Adam Cohenfbba09b2011-07-18 21:43:05 -07001650 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001651 mPendingAddInfo.cellX = cell[0];
1652 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001653 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001654 if (span != null) {
1655 mPendingAddInfo.spanX = span[0];
1656 mPendingAddInfo.spanY = span[1];
1657 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001658
Adam Cohened66b2b2012-01-23 17:28:51 -08001659 AppWidgetHostView hostView = info.boundWidget;
1660 int appWidgetId;
1661 if (hostView != null) {
1662 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001663 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001664 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001665 // In this case, we either need to start an activity to get permission to bind
1666 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001667 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Michael Jurka8b805b12012-04-18 14:23:14 -07001668 if (mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName)) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001669 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001670 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001671 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001672 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1673 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1674 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
1675 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1676 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001677 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001678 }
1679
Joe Onoratodeb98af2010-02-19 14:59:39 -08001680 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001681 // Handle case where user selected "Applications"
1682 String applicationName = getResources().getString(R.string.group_applications);
1683 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001684
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001685 if (applicationName != null && applicationName.equals(shortcutName)) {
1686 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1687 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001688
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001689 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1690 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001691 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001692 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001693 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001694 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001695 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001696 }
1697
Winson Chung24ab2f12010-09-16 14:10:47 -07001698 void processWallpaper(Intent intent) {
1699 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1700 }
1701
Winson Chung3d503fb2011-07-13 17:25:49 -07001702 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1703 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001704 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001705 folderInfo.title = getText(R.string.folder_name);
1706
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001707 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001708 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1709 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001710 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001711
1712 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001713 FolderIcon newFolder =
1714 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1715 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1716 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001717 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001718 }
Romain Guycbb89e42009-06-08 15:52:54 -07001719
Joe Onorato9c1289c2009-08-17 11:03:03 -04001720 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001721 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001722 }
1723
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001724 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001725 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001726 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001727 Intent chooser = Intent.createChooser(pickWallpaper,
1728 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001729 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1730 // Removed in Eclair MR1
1731// WallpaperManager wm = (WallpaperManager)
1732// getSystemService(Context.WALLPAPER_SERVICE);
1733// WallpaperInfo wi = wm.getWallpaperInfo();
1734// if (wi != null && wi.getSettingsActivity() != null) {
1735// LabeledIntent li = new LabeledIntent(getPackageName(),
1736// R.string.configure_wallpaper, 0);
1737// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1738// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1739// }
Mike Clerona0618e42009-10-22 13:55:21 -07001740 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001741 }
1742
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001743 /**
1744 * Registers various content observers. The current implementation registers
1745 * only a favorites observer to keep track of the favorites applications.
1746 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001747 private void registerContentObservers() {
1748 ContentResolver resolver = getContentResolver();
1749 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1750 true, mWidgetObserver);
1751 }
1752
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001753 @Override
1754 public boolean dispatchKeyEvent(KeyEvent event) {
1755 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1756 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001757 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001758 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001759 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001760 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001761 dumpState();
1762 return true;
1763 }
1764 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001765 }
1766 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1767 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001768 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001769 return true;
1770 }
1771 }
1772
1773 return super.dispatchKeyEvent(event);
1774 }
1775
Joe Onorato88ec0992009-11-19 13:16:06 -08001776 @Override
1777 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001778 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001779 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001780 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001781 Folder openFolder = mWorkspace.getOpenFolder();
1782 if (openFolder.isEditingName()) {
1783 openFolder.dismissEditingName();
1784 } else {
1785 closeFolder();
1786 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001787 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001788 mWorkspace.exitWidgetResizeMode();
1789
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001790 // Back button is a no-op here, but give at least some feedback for the button press
1791 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001792 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001793 }
1794
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001795 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001796 * Re-listen when widgets are reset.
1797 */
1798 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001799 if (mAppWidgetHost != null) {
1800 mAppWidgetHost.startListening();
1801 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001802 }
1803
1804 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001805 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1806 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001807 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001808 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001809 if (mModel != null) {
1810 mModel.unbindWorkspaceItems();
1811 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001812 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001813
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001814 /**
1815 * Launches the intent referred by the clicked shortcut.
1816 *
1817 * @param v The view representing the clicked shortcut.
1818 */
1819 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001820 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1821 // view has detached (it's possible for this to happen if the view is removed mid touch).
1822 if (v.getWindowToken() == null) {
1823 return;
1824 }
1825
Winson Chung9b0b2fe2012-02-24 13:03:34 -08001826 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001827 return;
1828 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001829
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001830 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001831 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001832 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001833 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001834 int[] pos = new int[2];
1835 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001836 intent.setSourceBounds(new Rect(pos[0], pos[1],
1837 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07001838
1839 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001840
1841 if (success && v instanceof BubbleTextView) {
1842 mWaitingForResume = (BubbleTextView) v;
1843 mWaitingForResume.setStayPressed(true);
1844 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001845 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001846 if (v instanceof FolderIcon) {
1847 FolderIcon fi = (FolderIcon) v;
1848 handleFolderClick(fi);
1849 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001850 } else if (v == mAllAppsButton) {
1851 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001852 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001853 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001854 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001855 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001856 }
1857 }
1858
Michael Jurka0e260592010-06-30 17:07:39 -07001859 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001860 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001861 // clicking anywhere on the workspace causes the customization drawer to slide down
1862 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001863 return false;
1864 }
1865
Michael Jurkaaf442092010-06-10 17:01:57 -07001866 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001867 * Event handler for the search button
1868 *
1869 * @param v The view that was clicked.
1870 */
1871 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001872 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1873
Amith Yamasania135ba82011-08-09 17:42:01 -07001874 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001875 }
1876
1877 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001878 * Event handler for the voice button
1879 *
1880 * @param v The view that was clicked.
1881 */
1882 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001883 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001884
Michael Jurkaae65ee32012-04-30 11:45:54 -07001885 try {
1886 final SearchManager searchManager =
1887 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1888 ComponentName activityName = searchManager.getGlobalSearchActivity();
1889 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07001890 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001891 if (activityName != null) {
1892 intent.setPackage(activityName.getPackageName());
1893 }
Michael Jurka86a720e2012-05-09 11:23:23 -07001894 startActivity(null, intent, "onClickVoiceButton");
Winson Chung01b0b632012-05-22 10:18:14 -07001895 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001896 } catch (ActivityNotFoundException e) {
1897 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07001898 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001899 startActivitySafely(null, intent, "onClickVoiceButton");
1900 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001901 }
1902
1903 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001904 * Event handler for the "grid" button that appears on the home screen, which
1905 * enters all apps mode.
1906 *
1907 * @param v The view that was clicked.
1908 */
1909 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001910 showAllApps(true);
1911 }
1912
1913 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001914 // Provide the same haptic feedback that the system offers for virtual keys.
1915 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001916 }
1917
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001918 public void onClickAppMarketButton(View v) {
1919 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07001920 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07001921 } else {
1922 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001923 }
1924 }
1925
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001926 void startApplicationDetailsActivity(ComponentName componentName) {
1927 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001928 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1929 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001930 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07001931 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001932 }
1933
Patrick Dubroy5539af72010-09-07 15:22:01 -07001934 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1935 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1936 // System applications cannot be installed. For now, show a toast explaining that.
1937 // We may give them the option of disabling apps this way.
1938 int messageId = R.string.uninstall_system_app_text;
1939 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1940 } else {
1941 String packageName = appInfo.componentName.getPackageName();
1942 String className = appInfo.componentName.getClassName();
1943 Intent intent = new Intent(
1944 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001945 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1946 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001947 startActivity(intent);
1948 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001949 }
1950
Michael Jurka86a720e2012-05-09 11:23:23 -07001951 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001952 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07001953
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001954 try {
Winson Chung2672ff92012-05-04 16:22:30 -07001955 // Only launch using the new animation if the shortcut has not opted out (this is a
1956 // private contract between launcher and may be ignored in the future).
1957 boolean useLaunchAnimation = (v != null) &&
1958 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
1959 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07001960 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
1961 v.getMeasuredWidth(), v.getMeasuredHeight());
1962
1963 startActivity(intent, opts.toBundle());
1964 } else {
1965 startActivity(intent);
1966 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001967 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001968 } catch (SecurityException e) {
1969 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001970 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001971 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001972 "or use the exported attribute for this activity. "
1973 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001974 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001975 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001976 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001977
Michael Jurka86a720e2012-05-09 11:23:23 -07001978 boolean startActivitySafely(View v, Intent intent, Object tag) {
1979 boolean success = false;
1980 try {
1981 success = startActivity(v, intent, tag);
1982 } catch (ActivityNotFoundException e) {
1983 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1984 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
1985 }
1986 return success;
1987 }
1988
Romain Guy8e633c52010-03-04 12:51:36 -08001989 void startActivityForResultSafely(Intent intent, int requestCode) {
1990 try {
1991 startActivityForResult(intent, requestCode);
1992 } catch (ActivityNotFoundException e) {
1993 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1994 } catch (SecurityException e) {
1995 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1996 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1997 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1998 "or use the exported attribute for this activity.", e);
1999 }
2000 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002001
Adam Cohena9cf38f2011-05-02 15:36:58 -07002002 private void handleFolderClick(FolderIcon folderIcon) {
2003 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07002004 Folder openFolder = mWorkspace.getFolderForTag(info);
2005
2006 // If the folder info reports that the associated folder is open, then verify that
2007 // it is actually opened. There have been a few instances where this gets out of sync.
2008 if (info.opened && openFolder == null) {
2009 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2010 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
2011 info.opened = false;
2012 }
2013
Adam Cohena9cf38f2011-05-02 15:36:58 -07002014 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002015 // Close any open folder
2016 closeFolder();
2017 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002018 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002019 } else {
2020 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002021 int folderScreen;
2022 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002023 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002024 // .. and close it
2025 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002026 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002027 // Close any folder open on the current screen
2028 closeFolder();
2029 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002030 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031 }
2032 }
2033 }
2034 }
2035
Adam Cohen268c4752012-06-06 17:47:33 -07002036 /**
2037 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2038 * in the DragLayer in the exact absolute location of the original FolderIcon.
2039 */
2040 private void copyFolderIconToImage(FolderIcon fi) {
2041 final int width = fi.getMeasuredWidth();
2042 final int height = fi.getMeasuredHeight();
2043
2044 // Lazy load ImageView, Bitmap and Canvas
2045 if (mFolderIconImageView == null) {
2046 mFolderIconImageView = new ImageView(this);
2047 }
2048 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2049 mFolderIconBitmap.getHeight() != height) {
2050 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2051 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2052 }
2053
2054 DragLayer.LayoutParams lp;
2055 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2056 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2057 } else {
2058 lp = new DragLayer.LayoutParams(width, height);
2059 }
2060
2061 mDragLayer.getViewRectRelativeToSelf(fi, mRectForFolderAnimation);
2062 lp.customPosition = true;
2063 lp.x = mRectForFolderAnimation.left;
2064 lp.y = mRectForFolderAnimation.top;
2065
2066 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2067 fi.draw(mFolderIconCanvas);
2068 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
2069 mFolderIconImageView.setPivotX(fi.mFolder.getPivotXForIconAnimation());
2070 mFolderIconImageView.setPivotY(fi.mFolder.getPivotYForIconAnimation());
2071
2072 // Just in case this image view is still in the drag layer from a previous animation,
2073 // we remove it and re-add it.
2074 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2075 mDragLayer.removeView(mFolderIconImageView);
2076 }
2077 mDragLayer.addView(mFolderIconImageView, lp);
2078 }
2079
Adam Cohen2801caf2011-05-13 20:57:39 -07002080 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002081 if (fi == null) return;
Adam Cohen268c4752012-06-06 17:47:33 -07002082
Adam Cohen2801caf2011-05-13 20:57:39 -07002083 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2084 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2085 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2086
Adam Cohenc51934b2011-07-26 21:07:43 -07002087 FolderInfo info = (FolderInfo) fi.getTag();
2088 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2089 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002090 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2091 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002092 }
2093
Adam Cohen268c4752012-06-06 17:47:33 -07002094 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2095 copyFolderIconToImage(fi);
2096 fi.setVisibility(View.INVISIBLE);
2097
2098 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(mFolderIconImageView, alpha,
2099 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002100 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2101 oa.start();
2102 }
2103
Adam Cohen268c4752012-06-06 17:47:33 -07002104 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002105 if (fi == null) return;
Adam Cohen268c4752012-06-06 17:47:33 -07002106
Adam Cohen2801caf2011-05-13 20:57:39 -07002107 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2108 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2109 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2110
Adam Cohen268c4752012-06-06 17:47:33 -07002111 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002112
Adam Cohen268c4752012-06-06 17:47:33 -07002113 // We remove and re-draw the FolderIcon in-case it has changed
2114 mDragLayer.removeView(mFolderIconImageView);
2115 copyFolderIconToImage(fi);
2116
2117 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(mFolderIconImageView, alpha,
2118 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002119 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002120 oa.addListener(new AnimatorListenerAdapter() {
2121 @Override
2122 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002123 if (cl != null) {
2124 cl.clearFolderLeaveBehind();
2125 // Remove the ImageView copy of the FolderIcon and make the original visible.
2126 mDragLayer.removeView(mFolderIconImageView);
2127 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002128 }
2129 }
2130 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002131 oa.start();
2132 }
2133
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002134 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002135 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002136 * is animated relative to the specified View. If the View is null, no animation
2137 * is played.
2138 *
2139 * @param folderInfo The FolderInfo describing the folder to open.
2140 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002141 public void openFolder(FolderIcon folderIcon) {
2142 Folder folder = folderIcon.mFolder;
2143 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002144
Adam Cohena9cf38f2011-05-02 15:36:58 -07002145 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002146
Adam Cohen4554ee12011-08-03 16:13:21 -07002147 // Just verify that the folder hasn't already been added to the DragLayer.
2148 // There was a one-off crash where the folder had a parent already.
2149 if (folder.getParent() == null) {
2150 mDragLayer.addView(folder);
2151 mDragController.addDropTarget((DropTarget) folder);
2152 } else {
2153 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2154 folder.getParent() + ").");
2155 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002156 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002157 growAndFadeOutFolderIcon(folderIcon);
Adam Cohen4554ee12011-08-03 16:13:21 -07002158 }
2159
2160 public void closeFolder() {
2161 Folder folder = mWorkspace.getOpenFolder();
2162 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002163 if (folder.isEditingName()) {
2164 folder.dismissEditingName();
2165 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002166 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002167
2168 // Dismiss the folder cling
2169 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002170 }
2171 }
2172
2173 void closeFolder(Folder folder) {
2174 folder.getInfo().opened = false;
2175
2176 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2177 if (parent != null) {
2178 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2179 shrinkAndFadeInFolderIcon(fi);
2180 }
2181 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002182 }
2183
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002184 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002185 if (!isDraggingEnabled()) return false;
2186 if (isWorkspaceLocked()) return false;
2187 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002188
2189 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002190 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002191 }
2192
Michael Jurka0280c3b2010-09-17 15:00:07 -07002193 resetAddInfo();
2194 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002195 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002196 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002197 return true;
2198 }
2199
Winson Chung3d503fb2011-07-13 17:25:49 -07002200 // The hotseat touch handling does not go through Workspace, and we always allow long press
2201 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002202 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002203 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2204 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002205 if (itemUnderLongClick == null) {
2206 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002207 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2208 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002209 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002210 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002211 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002212 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002213 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002214 }
2215 }
2216 }
2217 return true;
2218 }
2219
Winson Chung3d503fb2011-07-13 17:25:49 -07002220 boolean isHotseatLayout(View layout) {
2221 return mHotseat != null && layout != null &&
2222 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2223 }
2224 Hotseat getHotseat() {
2225 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002226 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002227 SearchDropTargetBar getSearchBar() {
2228 return mSearchDropTargetBar;
2229 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002230
Winson Chung3d503fb2011-07-13 17:25:49 -07002231 /**
2232 * Returns the CellLayout of the specified container at the specified screen.
2233 */
2234 CellLayout getCellLayout(long container, int screen) {
2235 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2236 if (mHotseat != null) {
2237 return mHotseat.getLayout();
2238 } else {
2239 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002240 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002241 } else {
2242 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002243 }
2244 }
2245
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002246 Workspace getWorkspace() {
2247 return mWorkspace;
2248 }
2249
Daniel Sandler843e8602010-06-07 14:59:01 -04002250 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2251 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002252 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002253 }
2254
Andrew Flynn0dca1ec2012-02-29 13:33:22 -08002255 public boolean isAllAppsButtonRank(int rank) {
2256 return mHotseat.isAllAppsButtonRank(rank);
2257 }
2258
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002259 // AllAppsView.Watcher
2260 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002261 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002262 mWorkspace.setVisibility(View.GONE);
2263 }
2264 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002265
2266 /**
2267 * Helper method for the cameraZoomIn/cameraZoomOut animations
2268 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002269 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002270 * @param scaleFactor The scale factor used for the zoom
2271 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002272 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002273 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002274 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002275 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002276
Winson Chung18f41f82012-05-09 13:28:10 -07002277 void disableWallpaperIfInAllApps() {
2278 // Only disable it if we are in all apps
2279 if (mState == State.APPS_CUSTOMIZE) {
2280 if (mAppsCustomizeTabHost != null &&
2281 !mAppsCustomizeTabHost.isTransitioning()) {
2282 updateWallpaperVisibility(false);
2283 }
2284 }
2285 }
2286
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002287 void updateWallpaperVisibility(boolean visible) {
2288 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2289 int curflags = getWindow().getAttributes().flags
2290 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2291 if (wpflags != curflags) {
2292 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2293 }
2294 }
2295
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002296 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2297 if (v instanceof LauncherTransitionable) {
2298 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2299 }
2300 }
2301
Michael Jurkabed61d22012-02-14 22:51:29 -08002302 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
Winson Chung7c7a22d2012-06-01 13:46:48 -07002303 if (toWorkspace) {
2304 Log.d(TAG, "6549598 Start animation to workspace");
2305 } else {
2306 Log.d(TAG, "6549598 Start animation to all apps");
2307 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002308 if (v instanceof LauncherTransitionable) {
2309 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2310 }
Winson Chung70442722012-02-10 15:43:22 -08002311
2312 // Update the workspace transition step as well
2313 dispatchOnLauncherTransitionStep(v, 0f);
2314 }
2315
2316 private void dispatchOnLauncherTransitionStep(View v, float t) {
2317 if (v instanceof LauncherTransitionable) {
2318 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2319 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002320 }
2321
2322 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
Winson Chung7c7a22d2012-06-01 13:46:48 -07002323 if (toWorkspace) {
2324 Log.d(TAG, "6549598 End animation to workspace");
2325 } else {
2326 Log.d(TAG, "6549598 End animation to all apps");
2327 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002328 if (v instanceof LauncherTransitionable) {
2329 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2330 }
Winson Chung70442722012-02-10 15:43:22 -08002331
2332 // Update the workspace transition step as well
2333 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002334 }
2335
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002336 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002337 * Things to test when changing the following seven functions.
2338 * - Home from workspace
2339 * - from center screen
2340 * - from other screens
2341 * - Home from all apps
2342 * - from center screen
2343 * - from other screens
2344 * - Back from all apps
2345 * - from center screen
2346 * - from other screens
2347 * - Launch app from workspace and quit
2348 * - with back
2349 * - with home
2350 * - Launch app from all apps and quit
2351 * - with back
2352 * - with home
2353 * - Go to a screen that's not the default, then all
2354 * apps, and launch and app, and go back
2355 * - with back
2356 * -with home
2357 * - On workspace, long press power and go back
2358 * - with back
2359 * - with home
2360 * - On all apps, long press power and go back
2361 * - with back
2362 * - with home
2363 * - On workspace, power off
2364 * - On all apps, power off
2365 * - Launch an app and turn off the screen while in that app
2366 * - Go back with home key
2367 * - Go back with back key TODO: make this not go to workspace
2368 * - From all apps
2369 * - From workspace
2370 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2371 * - From all apps
2372 * - From the center workspace
2373 * - From another workspace
2374 */
2375
2376 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002377 * Zoom the camera out from the workspace to reveal 'toView'.
2378 * Assumes that the view to show is anchored at either the very top or very bottom
2379 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002380 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002381 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002382 if (mStateAnimation != null) {
2383 mStateAnimation.cancel();
2384 mStateAnimation = null;
2385 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002386 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002387
Winson Chungf0ea4d32011-06-06 14:27:16 -07002388 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2389 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2390 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002391 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002392 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002393 final int startDelay =
2394 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002395
Michael Jurkab3e22d92011-10-31 15:58:33 -07002396 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002397
Michael Jurkad74c9842011-07-10 12:44:21 -07002398 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002399 Animator workspaceAnim =
2400 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002401
2402 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002403 toView.setScaleX(scale);
2404 toView.setScaleY(scale);
2405 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2406 scaleAnim.
2407 scaleX(1f).scaleY(1f).
2408 setDuration(duration).
2409 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002410
Winson Chungf0ea4d32011-06-06 14:27:16 -07002411 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002412 toView.setAlpha(0f);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002413 final ObjectAnimator alphaAnim = ObjectAnimator
2414 .ofFloat(toView, "alpha", 0f, 1f)
2415 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002416 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002417 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2418 @Override
2419 public void onAnimationUpdate(ValueAnimator animation) {
2420 float t = (Float) animation.getAnimatedValue();
2421 dispatchOnLauncherTransitionStep(fromView, t);
2422 dispatchOnLauncherTransitionStep(toView, t);
2423 }
2424 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002425
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002426 // toView should appear right at the end of the workspace shrink
2427 // animation
2428 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002429 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002430 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002431
2432 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002433 boolean animationCancelled = false;
2434
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002435 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002436 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002437 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002438 // Prepare the position
2439 toView.setTranslationX(0.0f);
2440 toView.setTranslationY(0.0f);
2441 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002442 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002443 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002444 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002445 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002446 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2447 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002448
2449 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2450 // Hide the workspace scrollbar
2451 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002452 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002453 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002454 if (!animationCancelled) {
2455 updateWallpaperVisibility(false);
2456 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002457
2458 // Hide the search bar
2459 mSearchDropTargetBar.hideSearchBar(false);
Adam Cohenf4ddea32011-09-12 13:46:42 -07002460 }
2461
Adam Cohencff6af82011-09-13 14:51:53 -07002462 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002463 public void onAnimationCancel(Animator animation) {
2464 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002465 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002466 });
2467
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002468 if (workspaceAnim != null) {
2469 mStateAnimation.play(workspaceAnim);
2470 }
Michael Jurka1899a362011-11-03 13:50:45 -07002471
2472 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002473 final ViewTreeObserver observer;
2474
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002475 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2476 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002477
2478 // If any of the objects being animated haven't been measured/laid out
2479 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002480 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002481 (mWorkspace.getMeasuredWidth() == 0) ||
2482 (toView.getMeasuredWidth() == 0)) {
2483 observer = mWorkspace.getViewTreeObserver();
2484 delayAnim = true;
2485 } else {
2486 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002487 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002488
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002489 final AnimatorSet stateAnimation = mStateAnimation;
2490 final Runnable startAnimRunnable = new Runnable() {
2491 public void run() {
2492 // Check that mStateAnimation hasn't changed while
2493 // we waited for a layout/draw pass
2494 if (mStateAnimation != stateAnimation)
2495 return;
2496 setPivotsForZoom(toView, scale);
2497 dispatchOnLauncherTransitionStart(fromView, animated, false);
2498 dispatchOnLauncherTransitionStart(toView, animated, false);
2499 mWorkspace.post(new Runnable() {
2500 public void run() {
2501 // Check that mStateAnimation hasn't changed while
2502 // we waited for a layout/draw pass
2503 if (mStateAnimation != stateAnimation)
2504 return;
2505 mStateAnimation.start();
2506 }
2507 });
2508 }
2509 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002510 if (delayAnim) {
2511 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2512 public void onGlobalLayout() {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002513 mWorkspace.post(startAnimRunnable);
Michael Jurka3a9fced2012-04-13 14:44:29 -07002514 observer.removeOnGlobalLayoutListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002515 }
2516 };
2517 observer.addOnGlobalLayoutListener(delayedStart);
2518 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002519 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002520 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002521 } else {
2522 toView.setTranslationX(0.0f);
2523 toView.setTranslationY(0.0f);
2524 toView.setScaleX(1.0f);
2525 toView.setScaleY(1.0f);
2526 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002527 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002528
Michael Jurkabed61d22012-02-14 22:51:29 -08002529 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2530 // Hide the workspace scrollbar
2531 mWorkspace.hideScrollingIndicator(true);
2532 hideDockDivider();
Winson Chungc7d2b602012-05-16 17:02:20 -07002533
2534 // Hide the search bar
2535 mSearchDropTargetBar.hideSearchBar(false);
Michael Jurkaabded662011-03-04 12:06:57 -08002536 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002537 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002538 dispatchOnLauncherTransitionStart(fromView, animated, false);
2539 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002540 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002541 dispatchOnLauncherTransitionStart(toView, animated, false);
2542 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002543 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002544 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002545 }
2546
2547 /**
2548 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002549 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002550 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002551 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002552 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2553 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002554
Michael Jurkab3e22d92011-10-31 15:58:33 -07002555 if (mStateAnimation != null) {
2556 mStateAnimation.cancel();
2557 mStateAnimation = null;
2558 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002559 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002560
Winson Chungf0ea4d32011-06-06 14:27:16 -07002561 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002562 final int fadeOutDuration =
2563 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002564 final float scaleFactor = (float)
2565 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2566 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002567 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002568 Animator workspaceAnim = null;
2569
2570 if (toState == State.WORKSPACE) {
2571 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2572 workspaceAnim = mWorkspace.getChangeStateAnimation(
2573 Workspace.State.NORMAL, animated, stagger);
2574 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2575 workspaceAnim = mWorkspace.getChangeStateAnimation(
2576 Workspace.State.SPRING_LOADED, animated);
2577 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002578
Michael Jurkab3e22d92011-10-31 15:58:33 -07002579 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002580 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002581 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002582 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002583 final LauncherViewPropertyAnimator scaleAnim =
2584 new LauncherViewPropertyAnimator(fromView);
2585 scaleAnim.
2586 scaleX(scaleFactor).scaleY(scaleFactor).
2587 setDuration(duration).
2588 setInterpolator(new Workspace.ZoomInInterpolator());
2589
2590 final ObjectAnimator alphaAnim = ObjectAnimator
2591 .ofFloat(fromView, "alpha", 1f, 0f)
2592 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002593 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002594 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2595 @Override
2596 public void onAnimationUpdate(ValueAnimator animation) {
2597 float t = 1f - (Float) animation.getAnimatedValue();
2598 dispatchOnLauncherTransitionStep(fromView, t);
2599 dispatchOnLauncherTransitionStep(toView, t);
2600 }
2601 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002602
Michael Jurkabed61d22012-02-14 22:51:29 -08002603 mStateAnimation = new AnimatorSet();
2604
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002605 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2606 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002607
2608 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002609 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002610 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002611 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002612 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002613 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2614 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkabafdaaf2012-04-26 13:43:25 -07002615 if (mWorkspace != null) {
2616 mWorkspace.hideScrollingIndicator(false);
2617 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002618 if (onCompleteRunnable != null) {
2619 onCompleteRunnable.run();
2620 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002621 }
2622 });
2623
Winson Chungf0ea4d32011-06-06 14:27:16 -07002624 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002625 if (workspaceAnim != null) {
2626 mStateAnimation.play(workspaceAnim);
2627 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002628 dispatchOnLauncherTransitionStart(fromView, animated, true);
2629 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002630 final Animator stateAnimation = mStateAnimation;
2631 mWorkspace.post(new Runnable() {
2632 public void run() {
2633 if (stateAnimation != mStateAnimation)
2634 return;
2635 mStateAnimation.start();
2636 }
2637 });
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002638 } else {
2639 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002640 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002641 dispatchOnLauncherTransitionStart(fromView, animated, true);
2642 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002643 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002644 dispatchOnLauncherTransitionStart(toView, animated, true);
2645 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002646 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002647 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002648 }
2649
Michael Jurkae326f182011-11-21 14:05:46 -08002650 @Override
2651 public void onTrimMemory(int level) {
2652 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002653 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002654 mAppsCustomizeTabHost.onTrimMemory();
2655 }
2656 }
2657
Winson Chung18f41f82012-05-09 13:28:10 -07002658 @Override
2659 public void onWindowFocusChanged(boolean hasFocus) {
2660 if (!hasFocus) {
2661 // When another window occludes launcher (like the notification shade, or recents),
2662 // ensure that we enable the wallpaper flag so that transitions are done correctly.
2663 updateWallpaperVisibility(true);
2664 } else {
2665 // When launcher has focus again, disable the wallpaper if we are in AllApps
2666 disableWallpaperIfInAllApps();
2667 }
2668 }
2669
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002670 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002671 showWorkspace(animated, null);
2672 }
2673
2674 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002675 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002676 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002677 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002678 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002679
Winson Chungc7d2b602012-05-16 17:02:20 -07002680 // Show the search bar (only animate if we were showing the drop target bar in spring
2681 // loaded mode)
2682 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
2683
Michael Jurkab737ee62011-11-15 15:57:22 -08002684 // We only need to animate in the dock divider if we're going from spring loaded mode
Winson Chungc7d2b602012-05-16 17:02:20 -07002685 showDockDivider(animated && wasInSpringLoadedMode);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002686
2687 // Set focus to the AppsCustomize button
2688 if (mAllAppsButton != null) {
2689 mAllAppsButton.requestFocus();
2690 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002691 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002692
Michael Jurkab737ee62011-11-15 15:57:22 -08002693 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002694
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002695 // Change the state *after* we've called all the transition code
2696 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002697
Winson Chung5fb63472011-02-02 17:03:37 -08002698 // Resume the auto-advance of widgets
2699 mUserPresent = true;
2700 updateRunning();
2701
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002702 // send an accessibility event to announce the context change
2703 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002704 }
2705
Michael Jurkab3e22d92011-10-31 15:58:33 -07002706 void showAllApps(boolean animated) {
2707 if (mState != State.WORKSPACE) return;
2708
2709 showAppsCustomizeHelper(animated, false);
2710 mAppsCustomizeTabHost.requestFocus();
2711
Michael Jurkab3e22d92011-10-31 15:58:33 -07002712 // Change the state *after* we've called all the transition code
2713 mState = State.APPS_CUSTOMIZE;
2714
2715 // Pause the auto-advance of widgets until we are out of AllApps
2716 mUserPresent = false;
2717 updateRunning();
2718 closeFolder();
2719
2720 // Send an accessibility event to announce the context change
2721 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2722 }
2723
Adam Cohen7777d962011-08-18 18:58:38 -07002724 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002725 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002726 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002727 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002728 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002729 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002730 }
Adam Cohen7777d962011-08-18 18:58:38 -07002731
Adam Cohened66b2b2012-01-23 17:28:51 -08002732 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2733 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002734 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2735
Winson Chunge7a03942011-08-05 15:05:12 -07002736 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002737 @Override
2738 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002739 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002740 // Before we show workspace, hide all apps again because
2741 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2742 // clean up our state transition functions
2743 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002744 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002745 } else {
2746 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002747 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002748 }
2749 }, (extendedDelay ?
2750 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2751 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2752 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002753
Michael Jurkad3ef3062010-11-23 16:23:58 -08002754 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002755 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002756 final boolean animated = true;
2757 final boolean springLoaded = true;
2758 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002759 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002760 }
2761 // Otherwise, we are not in spring loaded mode, so don't do anything.
2762 }
2763
Michael Jurkab737ee62011-11-15 15:57:22 -08002764 void hideDockDivider() {
2765 if (mQsbDivider != null && mDockDivider != null) {
2766 mQsbDivider.setVisibility(View.INVISIBLE);
2767 mDockDivider.setVisibility(View.INVISIBLE);
2768 }
2769 }
2770
2771 void showDockDivider(boolean animated) {
2772 if (mQsbDivider != null && mDockDivider != null) {
2773 mQsbDivider.setVisibility(View.VISIBLE);
2774 mDockDivider.setVisibility(View.VISIBLE);
2775 if (mDividerAnimator != null) {
2776 mDividerAnimator.cancel();
2777 mQsbDivider.setAlpha(1f);
2778 mDockDivider.setAlpha(1f);
2779 mDividerAnimator = null;
2780 }
2781 if (animated) {
2782 mDividerAnimator = new AnimatorSet();
2783 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2784 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2785 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2786 mDividerAnimator.start();
2787 }
2788 }
2789 }
2790
Michael Jurkab3e22d92011-10-31 15:58:33 -07002791 void lockAllApps() {
2792 // TODO
2793 }
2794
2795 void unlockAllApps() {
2796 // TODO
2797 }
2798
Adam Cohenfc53cd22011-07-20 15:45:11 -07002799 public boolean isAllAppsCustomizeOpen() {
2800 return mState == State.APPS_CUSTOMIZE;
2801 }
2802
Winson Chungf0ea4d32011-06-06 14:27:16 -07002803 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002804 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002805 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002806 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002807 if (!LauncherApplication.isScreenLarge()) {
2808 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002809 if (mHotseat.getAlpha() != 1f) {
2810 int duration = mSearchDropTargetBar.getTransitionInDuration();
2811 mHotseat.animate().alpha(1f).setDuration(duration);
2812 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002813 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002814 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002815 }
2816 }
2817 }
2818
2819 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002820 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002821 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002822 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002823 if (!LauncherApplication.isScreenLarge()) {
2824 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002825 if (mHotseat.getAlpha() != 0f) {
2826 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2827 mHotseat.animate().alpha(0f).setDuration(duration);
2828 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002829 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002830 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002831 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002832 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002833 }
2834
Patrick Dubroy5f445422011-02-18 14:35:21 -08002835 /**
2836 * Add an item from all apps or customize onto the given workspace screen.
2837 * If layout is null, add to the current screen.
2838 */
2839 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002840 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07002841 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07002842 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002843 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002844
Winson Chungdff8ebb2011-09-08 17:25:31 -07002845 /** Maps the current orientation to an index for referencing orientation correct global icons */
2846 private int getCurrentOrientationIndexForGlobalIcons() {
2847 // default - 0, landscape - 1
2848 switch (getResources().getConfiguration().orientation) {
2849 case Configuration.ORIENTATION_LANDSCAPE:
2850 return 1;
2851 default:
2852 return 0;
2853 }
2854 }
2855
Michael Jurkaae65ee32012-04-30 11:45:54 -07002856 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002857 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002858 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002859 // Look for the toolbar icon specified in the activity meta-data
2860 Bundle metaData = packageManager.getActivityInfo(
2861 activityName, PackageManager.GET_META_DATA).metaData;
2862 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002863 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002864 if (iconResId != 0) {
2865 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002866 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002867 }
2868 }
2869 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002870 // This can happen if the activity defines an invalid drawable
2871 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2872 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002873 } catch (Resources.NotFoundException nfe) {
2874 // This can happen if the activity defines an invalid drawable
2875 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2876 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002877 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002878 return null;
2879 }
2880
2881 // if successful in getting icon, return it; otherwise, set button to use default drawable
2882 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002883 int buttonId, ComponentName activityName, int fallbackDrawableId,
2884 String toolbarResourceName) {
2885 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002886 Resources r = getResources();
2887 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2888 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002889
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002890 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002891 // If we were unable to find the icon via the meta-data, use a generic one
2892 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002893 toolbarIcon = r.getDrawable(fallbackDrawableId);
2894 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002895 if (button != null) {
2896 button.setCompoundDrawables(toolbarIcon, null, null, null);
2897 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002898 return null;
2899 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002900 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002901 if (button != null) {
2902 button.setCompoundDrawables(toolbarIcon, null, null, null);
2903 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002904 return toolbarIcon.getConstantState();
2905 }
2906 }
2907
2908 // if successful in getting icon, return it; otherwise, set button to use default drawable
2909 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002910 int buttonId, ComponentName activityName, int fallbackDrawableId,
2911 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002912 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002913 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002914
Michael Jurka19e0fc52011-07-22 18:00:21 -07002915 if (button != null) {
2916 // If we were unable to find the icon via the meta-data, use a
2917 // generic one
2918 if (toolbarIcon == null) {
2919 button.setImageResource(fallbackDrawableId);
2920 } else {
2921 button.setImageDrawable(toolbarIcon);
2922 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002923 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002924
2925 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2926
Michael Jurka0423dcf2010-10-05 14:56:18 -07002927 }
2928
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002929 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2930 TextView button = (TextView) findViewById(buttonId);
2931 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2932 }
2933
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002934 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002935 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002936 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002937 }
2938
Winson Chungbb185bd2011-11-21 12:31:42 -08002939 private void invalidatePressedFocusedStates(View container, View button) {
2940 if (container instanceof HolographicLinearLayout) {
2941 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2942 layout.invalidatePressedFocusedStates();
2943 } else if (button instanceof HolographicImageView) {
2944 HolographicImageView view = (HolographicImageView) button;
2945 view.invalidatePressedFocusedStates();
2946 }
2947 }
2948
Winson Chungc51db6a2011-10-05 11:44:49 -07002949 private boolean updateGlobalSearchIcon() {
2950 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002951 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2952 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002953 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002954 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07002955 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07002956
Winson Chung1cad91e2011-05-25 17:41:01 -07002957 final SearchManager searchManager =
2958 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2959 ComponentName activityName = searchManager.getGlobalSearchActivity();
2960 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002961 int coi = getCurrentOrientationIndexForGlobalIcons();
2962 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002963 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2964 TOOLBAR_SEARCH_ICON_METADATA_NAME);
2965 if (sGlobalSearchIcon[coi] == null) {
2966 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
2967 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2968 TOOLBAR_ICON_METADATA_NAME);
2969 }
2970
Winson Chung649723c2011-07-06 20:41:23 -07002971 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002972 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2973 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002974 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002975 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002976 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002977 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002978 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002979 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2980 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2981 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002982 voiceButton.setVisibility(View.GONE);
Michael Jurkac60498a2012-05-07 15:29:42 -07002983 if (voiceButtonProxy != null) {
2984 voiceButtonProxy.setVisibility(View.GONE);
2985 }
Winson Chungc51db6a2011-10-05 11:44:49 -07002986 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002987 }
2988 }
2989
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002990 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002991 final View searchButtonContainer = findViewById(R.id.search_button_container);
2992 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002993 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002994 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002995 }
2996
Winson Chungc51db6a2011-10-05 11:44:49 -07002997 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002998 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002999 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003000 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07003001 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07003002
Winson Chungc51db6a2011-10-05 11:44:49 -07003003 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003004 final SearchManager searchManager =
3005 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3006 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3007
3008 ComponentName activityName = null;
3009 if (globalSearchActivity != null) {
3010 // Check if the global search activity handles voice search
3011 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3012 intent.setPackage(globalSearchActivity.getPackageName());
3013 activityName = intent.resolveActivity(getPackageManager());
3014 }
3015
3016 if (activityName == null) {
3017 // Fallback: check if an activity other than the global search activity
3018 // resolves this
3019 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3020 activityName = intent.resolveActivity(getPackageManager());
3021 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003022 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003023 int coi = getCurrentOrientationIndexForGlobalIcons();
3024 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003025 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3026 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3027 if (sVoiceSearchIcon[coi] == null) {
3028 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3029 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3030 TOOLBAR_ICON_METADATA_NAME);
3031 }
Winson Chung649723c2011-07-06 20:41:23 -07003032 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07003033 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003034 voiceButton.setVisibility(View.VISIBLE);
Jim Miller14091b12012-04-24 19:27:54 -07003035 if (voiceButtonProxy != null) {
3036 voiceButtonProxy.setVisibility(View.VISIBLE);
3037 }
Winson Chungbb185bd2011-11-21 12:31:42 -08003038 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003039 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003040 } else {
Winson Chung649723c2011-07-06 20:41:23 -07003041 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07003042 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003043 voiceButton.setVisibility(View.GONE);
Jim Miller14091b12012-04-24 19:27:54 -07003044 if (voiceButtonProxy != null) {
3045 voiceButtonProxy.setVisibility(View.GONE);
3046 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003047 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003048 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003049 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003050
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003051 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003052 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3053 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003054 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003055 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003056 }
3057
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003058 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003059 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003060 */
3061 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003062 final View marketButton = findViewById(R.id.market_button);
3063 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3064 // Find the app market activity by resolving an intent.
3065 // (If multiple app markets are installed, it will return the ResolverActivity.)
3066 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003067 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003068 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003069 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003070 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003071 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3072 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003073 marketButton.setVisibility(View.VISIBLE);
3074 } else {
3075 // We should hide and disable the view so that we don't try and restore the visibility
3076 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3077 marketButton.setVisibility(View.GONE);
3078 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003079 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003080 }
3081
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003082 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003083 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003084 }
3085
Michael Jurkad7c28052012-04-27 15:43:36 -07003086 @Override
3087 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
3088 boolean result = super.dispatchPopulateAccessibilityEvent(event);
3089 final List<CharSequence> text = event.getText();
3090 text.clear();
3091 text.add(getString(R.string.home));
3092 return result;
3093 }
3094
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003095 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003096 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003097 */
3098 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3099 @Override
3100 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003101 closeSystemDialogs();
3102 }
3103 }
3104
3105 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003106 * Receives notifications whenever the appwidgets are reset.
3107 */
3108 private class AppWidgetResetObserver extends ContentObserver {
3109 public AppWidgetResetObserver() {
3110 super(new Handler());
3111 }
3112
3113 @Override
3114 public void onChange(boolean selfChange) {
3115 onAppWidgetReset();
3116 }
3117 }
3118
3119 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003120 * If the activity is currently paused, signal that we need to re-run the loader
3121 * in onResume.
3122 *
3123 * This needs to be called from incoming places where resources might have been loaded
3124 * while we are paused. That is becaues the Configuration might be wrong
3125 * when we're not running, and if it comes back to what it was when we
3126 * were paused, we are not restarted.
3127 *
3128 * Implementation of the method from LauncherModel.Callbacks.
3129 *
3130 * @return true if we are currently paused. The caller might be able to
3131 * skip some work in that case since we will come back again.
3132 */
3133 public boolean setLoadOnResume() {
3134 if (mPaused) {
3135 Log.i(TAG, "setLoadOnResume");
3136 mOnResumeNeedsLoad = true;
3137 return true;
3138 } else {
3139 return false;
3140 }
3141 }
3142
3143 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003144 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003145 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003146 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003147 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003148 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003149 } else {
3150 return SCREEN_COUNT / 2;
3151 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003152 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003153
Joe Onorato9c1289c2009-08-17 11:03:03 -04003154 /**
3155 * Refreshes the shortcuts shown on the workspace.
3156 *
3157 * Implementation of the method from LauncherModel.Callbacks.
3158 */
3159 public void startBinding() {
3160 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07003161
Winson Chungf0c6ae02012-03-21 16:10:31 -07003162 mNewShortcutAnimatePage = -1;
3163 mNewShortcutAnimateViews.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003164 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003165 int count = workspace.getChildCount();
3166 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003167 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003168 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3169 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003170 }
Michael Jurka05bf6442011-11-30 20:28:53 -08003171 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003172 if (mHotseat != null) {
3173 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003174 }
3175 }
3176
3177 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003178 * Bind the items start-end from the list.
3179 *
3180 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003181 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003182 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003183 setLoadOnResume();
3184
Winson Chungf0c6ae02012-03-21 16:10:31 -07003185 // Get the list of added shortcuts and intersect them with the set of shortcuts here
3186 Set<String> newApps = new HashSet<String>();
3187 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);
3188
3189 Workspace workspace = mWorkspace;
3190 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003191 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003192
3193 // Short circuit if we are loading dock items for a configuration which has no dock
3194 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3195 mHotseat == null) {
3196 continue;
3197 }
3198
Joe Onorato9c1289c2009-08-17 11:03:03 -04003199 switch (item.itemType) {
3200 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3201 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003202 ShortcutInfo info = (ShortcutInfo) item;
3203 String uri = info.intent.toUri(0).toString();
3204 View shortcut = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -07003205 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3206 item.cellY, 1, 1, false);
Winson Chungbfeac062012-06-06 15:56:08 -07003207 boolean animateIconUp = false;
3208 synchronized (newApps) {
3209 if (newApps.contains(uri)) {
3210 animateIconUp = newApps.remove(uri);
3211 }
3212 }
3213 if (animateIconUp) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003214 // Prepare the view to be animated up
3215 shortcut.setAlpha(0f);
3216 shortcut.setScaleX(0f);
3217 shortcut.setScaleY(0f);
3218 mNewShortcutAnimatePage = item.screen;
3219 if (!mNewShortcutAnimateViews.contains(shortcut)) {
3220 mNewShortcutAnimateViews.add(shortcut);
3221 }
3222 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003223 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003224 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003225 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003226 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003227 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003228 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3229 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003230 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003231 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003232 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003233
Joe Onorato9c1289c2009-08-17 11:03:03 -04003234 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003235 }
3236
Joe Onorato9c1289c2009-08-17 11:03:03 -04003237 /**
3238 * Implementation of the method from LauncherModel.Callbacks.
3239 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003240 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003241 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003242 sFolders.clear();
3243 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003244 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003245
3246 /**
3247 * Add the views for a widget to the workspace.
3248 *
3249 * Implementation of the method from LauncherModel.Callbacks.
3250 */
3251 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003252 setLoadOnResume();
3253
Daniel Sandler843e8602010-06-07 14:59:01 -04003254 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3255 if (DEBUG_WIDGETS) {
3256 Log.d(TAG, "bindAppWidget: " + item);
3257 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003258 final Workspace workspace = mWorkspace;
3259
3260 final int appWidgetId = item.appWidgetId;
3261 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003262 if (DEBUG_WIDGETS) {
3263 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3264 }
3265
Joe Onorato9c1289c2009-08-17 11:03:03 -04003266 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3267
Joe Onorato9c1289c2009-08-17 11:03:03 -04003268 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003269 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003270
Winson Chung3d503fb2011-07-13 17:25:49 -07003271 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003272 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003273 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3274
Joe Onorato9c1289c2009-08-17 11:03:03 -04003275 workspace.requestLayout();
3276
Daniel Sandler843e8602010-06-07 14:59:01 -04003277 if (DEBUG_WIDGETS) {
3278 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3279 + (SystemClock.uptimeMillis()-start) + "ms");
3280 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003281 }
3282
3283 /**
3284 * Callback saying that there aren't any more items to bind.
3285 *
3286 * Implementation of the method from LauncherModel.Callbacks.
3287 */
3288 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003289 setLoadOnResume();
3290
Joe Onorato9c1289c2009-08-17 11:03:03 -04003291 if (mSavedState != null) {
3292 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003293 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003294 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003295 mSavedState = null;
3296 }
3297
3298 if (mSavedInstanceState != null) {
3299 super.onRestoreInstanceState(mSavedInstanceState);
3300 mSavedInstanceState = null;
3301 }
3302
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003303 // If we received the result of any pending adds while the loader was running (e.g. the
3304 // widget configuration forced an orientation change), process them now.
3305 for (int i = 0; i < sPendingAddList.size(); i++) {
3306 completeAdd(sPendingAddList.get(i));
3307 }
3308 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003309
Winson Chungc51db6a2011-10-05 11:44:49 -07003310 // Update the market app icon as necessary (the other icons will be managed in response to
3311 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003312 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003313
Winson Chungf0c6ae02012-03-21 16:10:31 -07003314 // Animate up any icons as necessary
3315 if (mVisible || mWorkspaceLoading) {
3316 Runnable newAppsRunnable = new Runnable() {
3317 @Override
3318 public void run() {
Winson Chunga2413752012-04-03 14:22:34 -07003319 runNewAppsAnimation(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003320 }
3321 };
Winson Chunga2413752012-04-03 14:22:34 -07003322
3323 boolean willSnapPage = mNewShortcutAnimatePage > -1 &&
3324 mNewShortcutAnimatePage != mWorkspace.getCurrentPage();
3325 if (canRunNewAppsAnimation()) {
3326 // If the user has not interacted recently, then either snap to the new page to show
3327 // the new-apps animation or just run them if they are to appear on the current page
3328 if (willSnapPage) {
3329 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable);
3330 } else {
3331 runNewAppsAnimation(false);
3332 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003333 } else {
Winson Chung318eee02012-04-12 10:59:27 -07003334 // If the user has interacted recently, then just add the items in place if they
Winson Chunga2413752012-04-03 14:22:34 -07003335 // are on another page (or just normally if they are added to the current page)
3336 runNewAppsAnimation(willSnapPage);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003337 }
3338 }
3339
3340 mWorkspaceLoading = false;
3341 }
3342
Winson Chunga2413752012-04-03 14:22:34 -07003343 private boolean canRunNewAppsAnimation() {
3344 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3345 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3346 }
3347
Winson Chungf0c6ae02012-03-21 16:10:31 -07003348 /**
3349 * Runs a new animation that scales up icons that were added while Launcher was in the
3350 * background.
Winson Chunga2413752012-04-03 14:22:34 -07003351 *
3352 * @param immediate whether to run the animation or show the results immediately
Winson Chungf0c6ae02012-03-21 16:10:31 -07003353 */
Winson Chunga2413752012-04-03 14:22:34 -07003354 private void runNewAppsAnimation(boolean immediate) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003355 AnimatorSet anim = new AnimatorSet();
3356 Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chunga2413752012-04-03 14:22:34 -07003357
3358 // Order these new views spatially so that they animate in order
Winson Chungf0c6ae02012-03-21 16:10:31 -07003359 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
3360 @Override
3361 public int compare(View a, View b) {
3362 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
3363 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
3364 int cellCountX = LauncherModel.getCellCountX();
3365 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
3366 }
3367 });
Winson Chunga2413752012-04-03 14:22:34 -07003368
3369 // Animate each of the views in place (or show them immediately if requested)
3370 if (immediate) {
3371 for (View v : mNewShortcutAnimateViews) {
3372 v.setAlpha(1f);
3373 v.setScaleX(1f);
3374 v.setScaleY(1f);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003375 }
Winson Chunga2413752012-04-03 14:22:34 -07003376 } else {
3377 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
3378 View v = mNewShortcutAnimateViews.get(i);
3379 ValueAnimator bounceAnim = ObjectAnimator.ofPropertyValuesHolder(v,
3380 PropertyValuesHolder.ofFloat("alpha", 1f),
3381 PropertyValuesHolder.ofFloat("scaleX", 1f),
3382 PropertyValuesHolder.ofFloat("scaleY", 1f));
3383 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3384 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3385 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3386 bounceAnims.add(bounceAnim);
3387 }
3388 anim.playTogether(bounceAnims);
3389 anim.addListener(new AnimatorListenerAdapter() {
3390 @Override
3391 public void onAnimationEnd(Animator animation) {
3392 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
3393 }
3394 });
3395 anim.start();
3396 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003397
3398 // Clean up
3399 mNewShortcutAnimatePage = -1;
3400 mNewShortcutAnimateViews.clear();
3401 new Thread("clearNewAppsThread") {
3402 public void run() {
3403 mSharedPrefs.edit()
3404 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
3405 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null)
3406 .commit();
3407 }
3408 }.start();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003409 }
3410
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003411 @Override
3412 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003413 boolean searchVisible = updateGlobalSearchIcon();
3414 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3415 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003416 }
3417
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003418 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003419 * Add the icons for all apps.
3420 *
3421 * Implementation of the method from LauncherModel.Callbacks.
3422 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003423 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3424 // Remove the progress bar entirely; we could also make it GONE
3425 // but better to remove it since we know it's not going to be used
3426 View progressBar = mAppsCustomizeTabHost.
3427 findViewById(R.id.apps_customize_progress_bar);
3428 if (progressBar != null) {
3429 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003430 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003431 // We just post the call to setApps so the user sees the progress bar
3432 // disappear-- otherwise, it just looks like the progress bar froze
3433 // which doesn't look great
3434 mAppsCustomizeTabHost.post(new Runnable() {
3435 public void run() {
3436 if (mAppsCustomizeContent != null) {
3437 mAppsCustomizeContent.setApps(apps);
3438 }
3439 }
3440 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003441 }
3442
3443 /**
3444 * A package was installed.
3445 *
3446 * Implementation of the method from LauncherModel.Callbacks.
3447 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003448 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003449 setLoadOnResume();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003450
Winson Chung785d2eb2011-04-14 16:08:02 -07003451 if (mAppsCustomizeContent != null) {
3452 mAppsCustomizeContent.addApps(apps);
3453 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003454 }
3455
3456 /**
3457 * A package was updated.
3458 *
3459 * Implementation of the method from LauncherModel.Callbacks.
3460 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003461 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003462 setLoadOnResume();
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003463 if (mWorkspace != null) {
3464 mWorkspace.updateShortcuts(apps);
3465 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003466
Winson Chung785d2eb2011-04-14 16:08:02 -07003467 if (mAppsCustomizeContent != null) {
3468 mAppsCustomizeContent.updateApps(apps);
3469 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003470 }
3471
3472 /**
3473 * A package was uninstalled.
3474 *
3475 * Implementation of the method from LauncherModel.Callbacks.
3476 */
Joe Onorato36115782010-06-17 13:28:48 -04003477 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato36115782010-06-17 13:28:48 -04003478 if (permanent) {
3479 mWorkspace.removeItems(apps);
3480 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003481
Winson Chung785d2eb2011-04-14 16:08:02 -07003482 if (mAppsCustomizeContent != null) {
3483 mAppsCustomizeContent.removeApps(apps);
3484 }
Winson Chunga1820962011-10-03 16:31:06 -07003485
3486 // Notify the drag controller
3487 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003488 }
Joe Onoratobe386092009-11-17 17:32:16 -08003489
3490 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003491 * A number of packages were updated.
3492 */
3493 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003494 if (mAppsCustomizeContent != null) {
3495 mAppsCustomizeContent.onPackagesUpdated();
3496 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003497 }
3498
Winson Chung400438b2011-01-16 17:53:48 -08003499 private int mapConfigurationOriActivityInfoOri(int configOri) {
3500 final Display d = getWindowManager().getDefaultDisplay();
3501 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3502 switch (d.getRotation()) {
3503 case Surface.ROTATION_0:
3504 case Surface.ROTATION_180:
3505 // We are currently in the same basic orientation as the natural orientation
3506 naturalOri = configOri;
3507 break;
3508 case Surface.ROTATION_90:
3509 case Surface.ROTATION_270:
3510 // We are currently in the other basic orientation to the natural orientation
3511 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3512 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3513 break;
3514 }
3515
3516 int[] oriMap = {
3517 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3518 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3519 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3520 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3521 };
3522 // Since the map starts at portrait, we need to offset if this device's natural orientation
3523 // is landscape.
3524 int indexOffset = 0;
3525 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3526 indexOffset = 1;
3527 }
3528 return oriMap[(d.getRotation() + indexOffset) % 4];
3529 }
Adam Cohen446e9402011-09-15 18:21:21 -07003530
Winson Chung4b919f82012-05-01 10:44:08 -07003531 public boolean isRotationEnabled() {
3532 boolean forceEnableRotation = "true".equalsIgnoreCase(SystemProperties.get(
3533 FORCE_ENABLE_ROTATION_PROPERTY, "false"));
3534 boolean enableRotation = forceEnableRotation ||
3535 getResources().getBoolean(R.bool.allow_rotation);
3536 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08003537 }
Winson Chung4b919f82012-05-01 10:44:08 -07003538 public void lockScreenOrientation() {
3539 if (isRotationEnabled()) {
3540 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3541 .getConfiguration().orientation));
3542 }
3543 }
3544 public void unlockScreenOrientation(boolean immediate) {
3545 if (isRotationEnabled()) {
3546 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07003547 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07003548 } else {
3549 mHandler.postDelayed(new Runnable() {
3550 public void run() {
3551 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3552 }
3553 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07003554 }
Winson Chung4b919f82012-05-01 10:44:08 -07003555 }
Winson Chung400438b2011-01-16 17:53:48 -08003556 }
3557
Winson Chung82f55532011-08-09 14:14:23 -07003558 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003559 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003560 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003561 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003562
Winson Chung7d7541e2011-09-16 20:14:36 -07003563 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003564 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003565 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3566 Cling cling = (Cling) findViewById(clingId);
3567 if (cling != null) {
3568 cling.init(this, positionData);
3569 cling.setVisibility(View.VISIBLE);
3570 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Svetoslav Ganov55d225d2012-05-22 15:19:14 -07003571 cling.requestAccessibilityFocus();
Winson Chung7d7541e2011-09-16 20:14:36 -07003572 if (animate) {
3573 cling.buildLayer();
3574 cling.setAlpha(0f);
3575 cling.animate()
3576 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003577 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003578 .setDuration(SHOW_CLING_DURATION)
3579 .setStartDelay(delay)
3580 .start();
3581 } else {
3582 cling.setAlpha(1f);
3583 }
3584 }
3585 return cling;
3586 }
3587 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003588 if (cling != null) {
3589 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003590 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003591 anim.addListener(new AnimatorListenerAdapter() {
3592 public void onAnimationEnd(Animator animation) {
3593 cling.setVisibility(View.GONE);
3594 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003595 // We should update the shared preferences on a background thread
3596 new Thread("dismissClingThread") {
3597 public void run() {
3598 SharedPreferences.Editor editor = mSharedPrefs.edit();
3599 editor.putBoolean(flag, true);
3600 editor.commit();
3601 }
3602 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003603 };
3604 });
3605 anim.start();
3606 }
3607 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003608 private void removeCling(int id) {
3609 final View cling = findViewById(id);
3610 if (cling != null) {
3611 final ViewGroup parent = (ViewGroup) cling.getParent();
3612 parent.post(new Runnable() {
3613 @Override
3614 public void run() {
3615 parent.removeView(cling);
3616 }
3617 });
3618 }
3619 }
Michael Jurka974c3862012-05-22 22:00:31 -07003620
3621 private boolean skipCustomClingIfNoAccounts() {
3622 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3623 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
3624 if (customCling) {
3625 AccountManager am = AccountManager.get(this);
3626 Account[] accounts = am.getAccountsByType("com.google");
3627 return accounts.length == 0;
3628 }
3629 return false;
3630 }
3631
Winson Chung7d7541e2011-09-16 20:14:36 -07003632 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003633 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003634 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07003635 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
3636 !skipCustomClingIfNoAccounts() ) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003637 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003638 } else {
3639 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003640 }
3641 }
3642 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003643 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003644 if (isClingsEnabled() &&
3645 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003646 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003647 } else {
3648 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003649 }
3650 }
3651 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003652 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003653 if (isClingsEnabled() &&
3654 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
3655 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003656 } else {
3657 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08003658 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07003659 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003660 }
3661 public boolean isFolderClingVisible() {
3662 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003663 if (cling != null) {
3664 return cling.getVisibility() == View.VISIBLE;
3665 }
3666 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003667 }
Winson Chung82f55532011-08-09 14:14:23 -07003668 public void dismissWorkspaceCling(View v) {
3669 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003670 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003671 }
3672 public void dismissAllAppsCling(View v) {
3673 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003674 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3675 }
3676 public void dismissFolderCling(View v) {
3677 Cling cling = (Cling) findViewById(R.id.folder_cling);
3678 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003679 }
3680
Winson Chung80baf5a2010-08-09 16:03:15 -07003681 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003682 * Prints out out state for debugging.
3683 */
3684 public void dumpState() {
3685 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003686 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003687 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3688 Log.d(TAG, "mRestoring=" + mRestoring);
3689 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3690 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003691 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003692 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003693
Winson Chung785d2eb2011-04-14 16:08:02 -07003694 if (mAppsCustomizeContent != null) {
3695 mAppsCustomizeContent.dumpState();
3696 }
Joe Onoratobe386092009-11-17 17:32:16 -08003697 Log.d(TAG, "END launcher2 dump state");
3698 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003699
3700 @Override
3701 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3702 super.dump(prefix, fd, writer, args);
3703 writer.println(" ");
3704 writer.println("Debug logs: ");
3705 for (int i = 0; i < sDumpLogs.size(); i++) {
3706 writer.println(" " + sDumpLogs.get(i));
3707 }
3708 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003709}
Michael Jurka2763be32011-02-24 11:19:57 -08003710
Michael Jurkaabded662011-03-04 12:06:57 -08003711interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003712 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003713 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08003714 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08003715 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08003716 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003717}