blob: 3354d49bdb2cb104a9955906ebb13477ebdc3195 [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;
Michael Jurkaaf442092010-06-10 17:01:57 -070051import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070052import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040053import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070054import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080055import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020056import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080057import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070058import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070059import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040060import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080061import android.os.SystemProperties;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070062import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080063import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064import android.text.Selection;
65import android.text.SpannableStringBuilder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070067import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080068import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080069import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.view.KeyEvent;
71import android.view.LayoutInflater;
72import android.view.Menu;
73import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070074import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080075import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076import android.view.View;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080077import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070078import android.view.ViewGroup;
Michael Jurkab737ee62011-11-15 15:57:22 -080079import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080080import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Dianne Hackbornbb003a52011-08-30 14:40:07 -070081import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080082import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070083import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070084import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080085import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080086import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070087import android.widget.Advanceable;
Michael Jurkaaf442092010-06-10 17:01:57 -070088import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070089import android.widget.TextView;
90import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070091
Adam Cohendf2cc412011-04-27 16:56:57 -070092import com.android.common.Search;
93import com.android.launcher.R;
Adam Cohen558baaf2011-08-15 15:22:57 -070094import com.android.launcher2.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080095
Adam Cohenc0dcf592011-06-01 15:30:43 -070096import java.io.DataInputStream;
97import java.io.DataOutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -070098import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -070099import java.io.FileNotFoundException;
100import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700101import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700103import java.util.Collection;
104import java.util.Collections;
105import java.util.Comparator;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700106import java.util.HashMap;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700107import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700108import java.util.List;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700109import java.util.Set;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700110
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800111/**
112 * Default launcher application.
113 */
Michael Jurka946ad472010-07-09 18:05:18 -0700114public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700115 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
116 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800117 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700118 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800119
Joe Onorato9c1289c2009-08-17 11:03:03 -0400120 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400121 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700122 static final boolean DEBUG_STRICT_MODE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700123
Winson Chung70d72102011-08-12 11:24:35 -0700124 private static final int MENU_GROUP_WALLPAPER = 1;
125 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
126 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700127 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
128 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800129
130 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700131 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132 private static final int REQUEST_PICK_APPLICATION = 6;
133 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700134 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700135 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136
Michael Jurka8b805b12012-04-18 14:23:14 -0700137 private static final int REQUEST_BIND_APPWIDGET = 11;
138
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
140
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800141 static final int SCREEN_COUNT = 5;
142 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143
Romain Guy98d01652009-06-30 16:21:04 -0700144 private static final String PREFERENCES = "launcher.preferences";
Adam Cohen23a4d302011-12-01 17:26:44 -0800145 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher.force_enable_rotation";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146
Winson Chung2672ff92012-05-04 16:22:30 -0700147 // The Intent extra that defines whether to ignore the launch animation
148 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
149 "com.android.launcher.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
150
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151 // Type: int
152 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700153 // Type: int
154 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800155 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700156 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
157 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
159 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700160 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800161 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700162 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 // Type: boolean
164 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
165 // Type: long
166 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700167 // Type: int
168 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
169 // Type: int
170 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
171 // Type: parcelable
172 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700174 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700175 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
176 "com.android.launcher.toolbar_search_icon";
177 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
178 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700179
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700180 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700181 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700182 private State mState = State.WORKSPACE;
183 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800184 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700185
Joe Onorato9c1289c2009-08-17 11:03:03 -0400186 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700187 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
188 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700189 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700190 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800193 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800194
Winson Chunga2413752012-04-03 14:22:34 -0700195 // How long to wait before the new-shortcut animation automatically pans the workspace
196 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
197
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800198 private final BroadcastReceiver mCloseSystemDialogsReceiver
199 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800200 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
201
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202 private LayoutInflater mInflater;
203
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800205 private View mQsbDivider;
206 private View mDockDivider;
207 private DragLayer mDragLayer;
208 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700209
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700210 private AppWidgetManager mAppWidgetManager;
211 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700212
Michael Jurkac9d95c52011-08-29 14:03:34 -0700213 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700214 private AppWidgetProviderInfo mPendingAddWidgetInfo;
215
Michael Jurka0280c3b2010-09-17 15:00:07 -0700216 private int[] mTmpAddItemCellCoordinates = new int[2];
217
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218 private FolderInfo mFolderInfo;
219
Winson Chung3d503fb2011-07-13 17:25:49 -0700220 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800221 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700222
Winson Chungc51db6a2011-10-05 11:44:49 -0700223 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700224 private AppsCustomizeTabHost mAppsCustomizeTabHost;
225 private AppsCustomizePagedView mAppsCustomizeContent;
226 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800227
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800228 private Bundle mSavedState;
229
230 private SpannableStringBuilder mDefaultKeySsb = null;
231
Joe Onorato9c1289c2009-08-17 11:03:03 -0400232 private boolean mWorkspaceLoading = true;
233
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800234 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235 private boolean mRestoring;
236 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700237 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800238
239 private Bundle mSavedInstanceState;
240
Joe Onorato9c1289c2009-08-17 11:03:03 -0400241 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800242 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800243 private boolean mUserPresent = true;
244 private boolean mVisible = false;
245 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400246
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700247 private static LocaleConfiguration sLocaleConfiguration = null;
248
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700249 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700250
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700251 private Intent mAppMarketIntent = null;
252
Adam Cohended9f8d2010-11-03 13:25:16 -0700253 // Related to the auto-advancing of widgets
254 private final int ADVANCE_MSG = 1;
255 private final int mAdvanceInterval = 20000;
256 private final int mAdvanceStagger = 250;
257 private long mAutoAdvanceSentTime;
258 private long mAutoAdvanceTimeLeft = -1;
259 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
260 new HashMap<View, AppWidgetProviderInfo>();
261
Winson Chung400438b2011-01-16 17:53:48 -0800262 // Determines how long to wait after a rotation before restoring the screen orientation to
263 // match the sensor state.
264 private final int mRestoreScreenOrientationDelay = 500;
265
Michael Jurka4ef207b2010-11-29 17:05:45 -0800266 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700267 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
268 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
269 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800270
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700271 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
272
Winson Chung46353de2012-02-16 14:05:10 -0800273 // We only want to get the SharedPreferences once since it does an FS stat each time we get
274 // it from the context.
275 private SharedPreferences mSharedPrefs;
276
Winson Chungf0c6ae02012-03-21 16:10:31 -0700277 // Holds the page that we need to animate to, and the icon views that we need to animate up
278 // when we scroll to that page on resume.
279 private int mNewShortcutAnimatePage = -1;
280 private ArrayList<View> mNewShortcutAnimateViews = new ArrayList<View>();
Adam Cohen2801caf2011-05-13 20:57:39 -0700281
Michael Jurkaddd62e92011-02-16 17:49:14 -0800282 private BubbleTextView mWaitingForResume;
283
Michael Jurkac1f5d262011-09-30 19:32:27 -0700284 private Runnable mBuildLayersRunnable = new Runnable() {
285 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700286 if (mWorkspace != null) {
287 mWorkspace.buildPageHardwareLayers();
288 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700289 }
290 };
291
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800292 private static ArrayList<PendingAddArguments> sPendingAddList
293 = new ArrayList<PendingAddArguments>();
294
295 private static class PendingAddArguments {
296 int requestCode;
297 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700298 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800299 int screen;
300 int cellX;
301 int cellY;
302 }
303
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800304 @Override
305 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700306 if (DEBUG_STRICT_MODE) {
307 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
308 .detectDiskReads()
309 .detectDiskWrites()
310 .detectNetwork() // or .detectAll() for all detectable problems
311 .penaltyLog()
312 .build());
313 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
314 .detectLeakedSqlLiteObjects()
315 .detectLeakedClosableObjects()
316 .penaltyLog()
317 .penaltyDeath()
318 .build());
319 }
320
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800321 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800322 LauncherApplication app = ((LauncherApplication)getApplication());
Winson Chungf0c6ae02012-03-21 16:10:31 -0700323 mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(),
324 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800325 mModel = app.setLauncher(this);
326 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400327 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800328 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700329
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700330 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700331 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
332 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700333
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800334 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200335 android.os.Debug.startMethodTracing(
336 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800337 }
338
339 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800340 setContentView(R.layout.launcher);
341 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700342 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800343
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800344 registerContentObservers();
345
Joe Onorato7c312c12009-08-13 21:36:53 -0700346 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700347
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800348 mSavedState = savedInstanceState;
349 restoreState(mSavedState);
350
Winson Chunga12a2502010-12-20 14:41:35 -0800351 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700352 if (mAppsCustomizeContent != null) {
Winson Chung7c7a22d2012-06-01 13:46:48 -0700353 Log.d(TAG, "6549598 Launcher.onCreate()");
Winson Chung785d2eb2011-04-14 16:08:02 -0700354 mAppsCustomizeContent.onPackagesUpdated();
355 }
Winson Chunga12a2502010-12-20 14:41:35 -0800356
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800357 if (PROFILE_STARTUP) {
358 android.os.Debug.stopMethodTracing();
359 }
360
361 if (!mRestoring) {
Winson Chungf0c6ae02012-03-21 16:10:31 -0700362 mModel.startLoader(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800363 }
364
Michael Jurkac57b7a82011-08-09 22:02:20 -0700365 if (!mModel.isAllAppsLoaded()) {
366 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
367 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
368 }
369
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800370 // For handling default keys
371 mDefaultKeySsb = new SpannableStringBuilder();
372 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800373
374 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
375 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800376
Winson Chungc51db6a2011-10-05 11:44:49 -0700377 boolean searchVisible = false;
378 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800379 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700380 int coi = getCurrentOrientationIndexForGlobalIcons();
381 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
382 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700383 updateAppMarketIcon();
384 searchVisible = updateGlobalSearchIcon();
385 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700386 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700387 if (sGlobalSearchIcon[coi] != null) {
388 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700389 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700390 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700391 if (sVoiceSearchIcon[coi] != null) {
392 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700393 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700394 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700395 if (sAppMarketIcon[coi] != null) {
396 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800397 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700398 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Adam Cohen446e9402011-09-15 18:21:21 -0700399
400 // On large interfaces, we want the screen to auto-rotate based on the current orientation
Winson Chung4b919f82012-05-01 10:44:08 -0700401 unlockScreenOrientation(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800402 }
Romain Guycbb89e42009-06-08 15:52:54 -0700403
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800404 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700405 if (sLocaleConfiguration == null) {
406 new AsyncTask<Void, Void, LocaleConfiguration>() {
407 @Override
408 protected LocaleConfiguration doInBackground(Void... unused) {
409 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
410 readConfiguration(Launcher.this, localeConfiguration);
411 return localeConfiguration;
412 }
413
414 @Override
415 protected void onPostExecute(LocaleConfiguration result) {
416 sLocaleConfiguration = result;
417 checkForLocaleChange(); // recursive, but now with a locale configuration
418 }
419 }.execute();
420 return;
421 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700422
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800423 final Configuration configuration = getResources().getConfiguration();
424
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700425 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800426 final String locale = configuration.locale.toString();
427
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700428 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800429 final int mcc = configuration.mcc;
430
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700431 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800432 final int mnc = configuration.mnc;
433
Romain Guy84f296c2009-11-04 15:00:44 -0800434 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800435
Romain Guy84f296c2009-11-04 15:00:44 -0800436 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700437 sLocaleConfiguration.locale = locale;
438 sLocaleConfiguration.mcc = mcc;
439 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700440
Joe Onorato0589f0f2010-02-08 13:44:00 -0800441 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700442
443 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
444 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700445 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700446 public void run() {
447 writeConfiguration(Launcher.this, localeConfiguration);
448 }
449 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700450 }
451 }
452
453 private static class LocaleConfiguration {
454 public String locale;
455 public int mcc = -1;
456 public int mnc = -1;
457 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700458
Romain Guy98d01652009-06-30 16:21:04 -0700459 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
460 DataInputStream in = null;
461 try {
462 in = new DataInputStream(context.openFileInput(PREFERENCES));
463 configuration.locale = in.readUTF();
464 configuration.mcc = in.readInt();
465 configuration.mnc = in.readInt();
466 } catch (FileNotFoundException e) {
467 // Ignore
468 } catch (IOException e) {
469 // Ignore
470 } finally {
471 if (in != null) {
472 try {
473 in.close();
474 } catch (IOException e) {
475 // Ignore
476 }
477 }
478 }
479 }
480
481 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
482 DataOutputStream out = null;
483 try {
484 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
485 out.writeUTF(configuration.locale);
486 out.writeInt(configuration.mcc);
487 out.writeInt(configuration.mnc);
488 out.flush();
489 } catch (FileNotFoundException e) {
490 // Ignore
491 } catch (IOException e) {
492 //noinspection ResultOfMethodCallIgnored
493 context.getFileStreamPath(PREFERENCES).delete();
494 } finally {
495 if (out != null) {
496 try {
497 out.close();
498 } catch (IOException e) {
499 // Ignore
500 }
501 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800502 }
503 }
504
Adam Cohen716b51e2011-06-30 12:09:54 -0700505 public DragLayer getDragLayer() {
506 return mDragLayer;
507 }
508
Winson Chung36a62fe2012-05-06 18:04:42 -0700509 boolean isDraggingEnabled() {
510 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
511 // that is subsequently removed from the workspace in startBinding().
512 return !mModel.isLoadingWorkspace();
513 }
514
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800515 static int getScreen() {
516 synchronized (sLock) {
517 return sScreen;
518 }
519 }
520
521 static void setScreen(int screen) {
522 synchronized (sLock) {
523 sScreen = screen;
524 }
525 }
526
Winson Chung557d6ed2011-07-08 15:34:52 -0700527 /**
528 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
529 * a configuration step, this allows the proper animations to run after other transitions.
530 */
531 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700532 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800533 switch (args.requestCode) {
534 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700535 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
536 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800537 break;
538 case REQUEST_PICK_SHORTCUT:
539 processShortcut(args.intent);
540 break;
541 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700542 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
543 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700544 result = true;
545 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800546 case REQUEST_CREATE_APPWIDGET:
547 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800548 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700549 result = true;
550 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800551 case REQUEST_PICK_WALLPAPER:
552 // We just wanted the activity result here so we can clear mWaitingForResult
553 break;
554 }
Michael Jurka27614d22012-04-02 06:40:22 -0700555 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
556 // if you turned the screen off and then back while in All Apps, Launcher would not
557 // return to the workspace. Clearing mAddInfo.container here fixes this issue
558 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700559 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800560 }
561
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800562 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700563 protected void onActivityResult(
564 final int requestCode, final int resultCode, final Intent data) {
565 if (requestCode == REQUEST_BIND_APPWIDGET) {
566 int appWidgetId = data != null ?
567 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
568 if (resultCode == RESULT_CANCELED) {
569 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
570 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700571 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700572 }
573 return;
574 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700575 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800576 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
577 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700578 mWaitingForResult = false;
579
Adam Cohened66b2b2012-01-23 17:28:51 -0800580 // We have special handling for widgets
581 if (isWidgetDrop) {
582 int appWidgetId = data != null ?
583 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700584 if (appWidgetId < 0) {
585 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
586 "widget configuration activity.");
587 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
588 } else {
589 completeTwoStageWidgetDrop(resultCode, appWidgetId);
590 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800591 return;
592 }
593
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800594 // The pattern used here is that a user PICKs a specific application,
595 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700596
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800597 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
598 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700599 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800600 final PendingAddArguments args = new PendingAddArguments();
601 args.requestCode = requestCode;
602 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700603 args.container = mPendingAddInfo.container;
604 args.screen = mPendingAddInfo.screen;
605 args.cellX = mPendingAddInfo.cellX;
606 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800607 if (isWorkspaceLocked()) {
608 sPendingAddList.add(args);
609 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700610 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800611 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800612 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800613 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700614 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800615 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
616 null);
617 }
618
619 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700620 CellLayout cellLayout =
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700621 (CellLayout) mWorkspace.getChildAt(mPendingAddInfo.screen);
Adam Cohened66b2b2012-01-23 17:28:51 -0800622 Runnable onCompleteRunnable = null;
623 int animationType = 0;
624
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700625 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800626 if (resultCode == RESULT_OK) {
627 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
628 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700629 mPendingAddWidgetInfo);
630 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800631 onCompleteRunnable = new Runnable() {
632 @Override
633 public void run() {
634 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
635 mPendingAddInfo.screen, layout, null);
636 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
637 null);
638 }
639 };
640 } else if (resultCode == RESULT_CANCELED) {
641 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
642 onCompleteRunnable = new Runnable() {
643 @Override
644 public void run() {
645 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
646 null);
647 }
648 };
649 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700650 if (mDragLayer.getAnimatedView() != null) {
651 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
652 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
653 animationType, boundWidget, true);
654 } else {
655 // The animated view may be null in the case of a rotation during widget configuration
656 onCompleteRunnable.run();
657 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800658 }
659
660 @Override
661 protected void onResume() {
662 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700663
Winson Chungde0fb8f2012-05-08 14:37:08 -0700664 // Process any items that were added while Launcher was away
665 InstallShortcutReceiver.flushInstallQueue(this);
666
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800667 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700668 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400669 mWorkspaceLoading = true;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700670 mModel.startLoader(true);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400671 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700672 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 }
Winson Chunge4e50662012-01-23 14:45:13 -0800674
675 // Reset the pressed state of icons that were locked in the press state while activities
676 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800677 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800678 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800679 mWaitingForResume.setStayPressed(false);
680 }
Winson Chunge4e50662012-01-23 14:45:13 -0800681 if (mAppsCustomizeContent != null) {
682 // Resets the previous all apps icon press state
683 mAppsCustomizeContent.resetDrawableState();
684 }
Adam Cohen06dff352012-06-01 17:17:08 -0700685 // It is possible that widgets can receive updates while launcher is not in the foreground.
686 // Consequently, the widgets will be inflated in the orientation of the foreground activity
687 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
688 // orientation.
689 reinflateWidgetsIfNecessary();
690 }
691
692 void reinflateWidgetsIfNecessary() {
693 for (LauncherAppWidgetInfo info: LauncherModel.getWidgets()) {
694 LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) info.hostView;
695 if (lahv != null && lahv.orientationChangedSincedInflation()) {
696 AppWidgetProviderInfo pInfo = lahv.getAppWidgetInfo();
697
698 // Remove the current widget which is inflated with the wrong orientation
699 getWorkspace().getParentCellLayoutForView(lahv).removeView(lahv);
700 // Re-inflate the widget using the correct orientation
701 AppWidgetHostView widget = mAppWidgetHost.createView(this, info.appWidgetId, pInfo);
702
703 // Add the new widget back
704 widget.setTag(info);
705 info.hostView = widget;
706 getWorkspace().addInScreen(widget, info.container, info.screen,
707 info.cellX, info.cellY, info.spanX, info.spanY);
708 }
709 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800710 }
711
712 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700713 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700714 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
715 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
716 // when Launcher resumes and we are still in AllApps.
717 updateWallpaperVisibility(true);
718
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700719 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700720 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800721 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700722 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700723 }
Romain Guycbb89e42009-06-08 15:52:54 -0700724
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700725 @Override
726 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400727 // Flag the loader to stop early before switching
728 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700729 if (mAppsCustomizeContent != null) {
730 mAppsCustomizeContent.surrender();
731 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800732 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700733 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700734
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800735 // We can't hide the IME if it was forced open. So don't bother
736 /*
737 @Override
738 public void onWindowFocusChanged(boolean hasFocus) {
739 super.onWindowFocusChanged(hasFocus);
740
741 if (hasFocus) {
742 final InputMethodManager inputManager = (InputMethodManager)
743 getSystemService(Context.INPUT_METHOD_SERVICE);
744 WindowManager.LayoutParams lp = getWindow().getAttributes();
745 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
746 android.os.Handler()) {
747 protected void onReceiveResult(int resultCode, Bundle resultData) {
748 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
749 }
750 });
751 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
752 }
753 }
754 */
755
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800756 private boolean acceptFilter() {
757 final InputMethodManager inputManager = (InputMethodManager)
758 getSystemService(Context.INPUT_METHOD_SERVICE);
759 return !inputManager.isFullscreenMode();
760 }
761
762 @Override
763 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700764 final int uniChar = event.getUnicodeChar();
765 final boolean handled = super.onKeyDown(keyCode, event);
766 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
767 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800768 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
769 keyCode, event);
770 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700771 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700772 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700773 // showSearchDialog()
774 // If there are multiple keystrokes before the search dialog takes focus,
775 // onSearchRequested() will be called for every keystroke,
776 // but it is idempotent, so it's fine.
777 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800778 }
779 }
780
Joe Onorato8a9625e2010-01-28 15:55:35 -0800781 // Eat the long press event so the keyboard doesn't come up.
782 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
783 return true;
784 }
785
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800786 return handled;
787 }
788
Karl Rosaen138a0412009-04-23 19:00:21 -0700789 private String getTypedText() {
790 return mDefaultKeySsb.toString();
791 }
792
793 private void clearTypedText() {
794 mDefaultKeySsb.clear();
795 mDefaultKeySsb.clearSpans();
796 Selection.setSelection(mDefaultKeySsb, 0);
797 }
798
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800799 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700800 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
801 * State
802 */
803 private static State intToState(int stateOrdinal) {
804 State state = State.WORKSPACE;
805 final State[] stateValues = State.values();
806 for (int i = 0; i < stateValues.length; i++) {
807 if (stateValues[i].ordinal() == stateOrdinal) {
808 state = stateValues[i];
809 break;
810 }
811 }
812 return state;
813 }
814
815 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800816 * Restores the previous state, if it exists.
817 *
818 * @param savedState The previous state.
819 */
820 private void restoreState(Bundle savedState) {
821 if (savedState == null) {
822 return;
823 }
824
Michael Jurka883f55b2010-10-21 15:47:14 -0700825 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700826 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800827 showAllApps(false);
828 }
829
Winson Chungf0c6ae02012-03-21 16:10:31 -0700830 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800831 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700832 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800833 }
834
Winson Chung3d503fb2011-07-13 17:25:49 -0700835 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
836 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700837
Winson Chung3d503fb2011-07-13 17:25:49 -0700838 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
839 mPendingAddInfo.container = pendingAddContainer;
840 mPendingAddInfo.screen = pendingAddScreen;
841 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
842 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700843 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
844 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
845 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -0700846 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800847 mRestoring = true;
848 }
849
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700850
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800851 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
852 if (renameFolder) {
853 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700854 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800855 mRestoring = true;
856 }
Winson Chunga12a2502010-12-20 14:41:35 -0800857
Winson Chung785d2eb2011-04-14 16:08:02 -0700858
859 // Restore the AppsCustomize tab
860 if (mAppsCustomizeTabHost != null) {
861 String curTab = savedState.getString("apps_customize_currentTab");
862 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700863 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700864 mAppsCustomizeContent.setContentType(
865 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
866 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700867 mAppsCustomizeContent.loadAssociatedPages(
868 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700869 }
870
Winson Chung5afbf7b2011-07-25 11:53:08 -0700871 int currentIndex = savedState.getInt("apps_customize_currentIndex");
872 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700873 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800874 }
875
876 /**
877 * Finds all the views we need and configure them properly.
878 */
879 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700880 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400881
Winson Chung4c98d922011-05-31 16:50:48 -0700882 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
883 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800884 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
885 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800886
Winson Chung4c98d922011-05-31 16:50:48 -0700887 // Setup the drag layer
888 mDragLayer.setup(this, dragController);
889
Winson Chung3d503fb2011-07-13 17:25:49 -0700890 // Setup the hotseat
891 mHotseat = (Hotseat) findViewById(R.id.hotseat);
892 if (mHotseat != null) {
893 mHotseat.setup(this);
894 }
895
Winson Chung4c98d922011-05-31 16:50:48 -0700896 // Setup the workspace
897 mWorkspace.setHapticFeedbackEnabled(false);
898 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700899 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700900 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700901
Winson Chungf0ea4d32011-06-06 14:27:16 -0700902 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700903 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700904
Winson Chungf0ea4d32011-06-06 14:27:16 -0700905 // Setup AppsCustomize
906 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
907 findViewById(R.id.apps_customize_pane);
908 mAppsCustomizeContent = (AppsCustomizePagedView)
909 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
Winson Chungc7450e32012-04-17 17:34:08 -0700910 mAppsCustomizeTabHost.setup(this);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700911 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400912
Michael Jurka5130e402011-10-13 04:55:35 -0700913 // Get the all apps button
914 mAllAppsButton = findViewById(R.id.all_apps_button);
915 if (mAllAppsButton != null) {
916 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
917 @Override
918 public boolean onTouch(View v, MotionEvent event) {
919 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
920 onTouchDownAllAppsButton(v);
921 }
922 return false;
923 }
924 });
925 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700926 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700927 dragController.setDragScoller(mWorkspace);
928 dragController.setScrollView(mDragLayer);
929 dragController.setMoveTarget(mWorkspace);
930 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700931 if (mSearchDropTargetBar != null) {
932 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800933 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800934 }
935
936 /**
937 * Creates a view representing a shortcut.
938 *
939 * @param info The data structure describing the shortcut.
940 *
941 * @return A View inflated from R.layout.application.
942 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800943 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800944 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700945 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800946 }
947
948 /**
949 * Creates a view representing a shortcut inflated from the specified resource.
950 *
951 * @param layoutResId The id of the XML layout used to create the shortcut.
952 * @param parent The group the shortcut belongs to.
953 * @param info The data structure describing the shortcut.
954 *
955 * @return A View inflated from layoutResId.
956 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800957 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800958 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
959 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800960 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800961 return favorite;
962 }
963
964 /**
965 * Add an application shortcut to the workspace.
966 *
967 * @param data The intent describing the application.
968 * @param cellInfo The position on screen where to create the shortcut.
969 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700970 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700971 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700972 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700973
Adam Cohenfbba09b2011-07-18 21:43:05 -0700974 // First we check if we already know the exact location where we want to add this item.
975 if (cellX >= 0 && cellY >= 0) {
976 cellXY[0] = cellX;
977 cellXY[1] = cellY;
978 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -0700979 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -0700980 return;
981 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800982
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800983 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800984
Romain Guy73b979d2009-06-09 12:57:21 -0700985 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800986 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800987 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800988 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700989 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700990 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800991 } else {
992 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800993 }
994 }
Romain Guycbb89e42009-06-08 15:52:54 -0700995
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800996 /**
997 * Add a shortcut to the workspace.
998 *
999 * @param data The intent describing the shortcut.
1000 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001001 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001002 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
1003 int cellY) {
1004 int[] cellXY = mTmpAddItemCellCoordinates;
1005 int[] touchXY = mPendingAddInfo.dropPos;
1006 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001007
Michael Jurkad3ef3062010-11-23 16:23:58 -08001008 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001009
Adam Cohen558baaf2011-08-15 15:22:57 -07001010 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001011 if (info == null) {
1012 return;
1013 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001014 final View view = createShortcut(info);
1015
Adam Cohenfbba09b2011-07-18 21:43:05 -07001016 // First we check if we already know the exact location where we want to add this item.
1017 if (cellX >= 0 && cellY >= 0) {
1018 cellXY[0] = cellX;
1019 cellXY[1] = cellY;
1020 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001021
1022 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001023 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001024 true, null,null)) {
1025 return;
1026 }
1027 DragObject dragObject = new DragObject();
1028 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001029 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1030 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001031 return;
1032 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001033 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001034 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001035 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001036 foundCellSpan = (result != null);
1037 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001038 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001039 }
1040
1041 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001042 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001043 return;
1044 }
1045
Adam Cohen558baaf2011-08-15 15:22:57 -07001046 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001047
1048 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001049 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
1050 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001051 }
1052 }
1053
Adam Cohen2f093b62012-04-30 18:59:53 -07001054 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1055 int minHeight) {
1056 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001057 // We want to account for the extra amount of padding that we are adding to the widget
1058 // to ensure that it gets the full amount of space that it has requested
1059 int requiredWidth = minWidth + padding.left + padding.right;
1060 int requiredHeight = minHeight + padding.top + padding.bottom;
Adam Cohen2f093b62012-04-30 18:59:53 -07001061 return CellLayout.rectToCell(context.getResources(), requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001062 }
1063
Adam Cohen2f093b62012-04-30 18:59:53 -07001064 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1065 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001066 }
1067
Adam Cohen2f093b62012-04-30 18:59:53 -07001068 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1069 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001070 }
1071
Adam Cohen2f093b62012-04-30 18:59:53 -07001072 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1073 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001074 }
1075
Adam Cohen2f093b62012-04-30 18:59:53 -07001076 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1077 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001078 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001079 }
1080
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001081 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001082 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001083 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001084 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001085 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001086 */
Adam Cohened66b2b2012-01-23 17:28:51 -08001087 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
1088 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1089 if (appWidgetInfo == null) {
1090 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1091 }
Romain Guycbb89e42009-06-08 15:52:54 -07001092
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001093 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -07001094 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -07001095
Adam Cohen2f093b62012-04-30 18:59:53 -07001096 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1097 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001098
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001099 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001100 // We have saved the position to which the widget was dragged-- this really only matters
1101 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001102 int[] cellXY = mTmpAddItemCellCoordinates;
1103 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001104 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001105 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001106 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1107 cellXY[0] = mPendingAddInfo.cellX;
1108 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001109 spanXY[0] = mPendingAddInfo.spanX;
1110 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001111 foundCellSpan = true;
1112 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001113 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001114 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001115 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1116 spanXY[1], cellXY, finalSpan);
1117 spanXY[0] = finalSpan[0];
1118 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001119 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001120 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001121 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001122 }
1123
Michael Jurka0280c3b2010-09-17 15:00:07 -07001124 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001125 if (appWidgetId != -1) {
1126 // Deleting an app widget ID is a void call but writes to disk before returning
1127 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001128 new Thread("deleteAppWidgetId") {
1129 public void run() {
1130 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1131 }
1132 }.start();
1133 }
Winson Chung93eef082012-03-23 15:59:27 -07001134 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001135 return;
1136 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001137
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001138 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001139 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1140 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001141 launcherInfo.spanX = spanXY[0];
1142 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001143 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1144 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001145
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001146 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001147 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001148
1149 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001150 if (hostView == null) {
1151 // Perform actual inflation because we're live
1152 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1153 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1154 } else {
1155 // The AppWidgetHostView has already been inflated and instantiated
1156 launcherInfo.hostView = hostView;
1157 }
Romain Guycbb89e42009-06-08 15:52:54 -07001158
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001159 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001160 launcherInfo.hostView.setVisibility(View.VISIBLE);
Winson Chung211bac32012-05-15 13:43:57 -07001161 launcherInfo.notifyWidgetSizeChanged(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001162 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001163 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001164
1165 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001166 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001167 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001168 }
Romain Guycbb89e42009-06-08 15:52:54 -07001169
Adam Cohended9f8d2010-11-03 13:25:16 -07001170 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1171 @Override
1172 public void onReceive(Context context, Intent intent) {
1173 final String action = intent.getAction();
1174 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1175 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001176 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001177 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001178
Winson Chungc100e8e2011-08-09 16:02:43 -07001179 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001180 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001181 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1182 mAppsCustomizeTabHost.reset();
1183 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001184 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001185 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1186 mUserPresent = true;
1187 updateRunning();
1188 }
1189 }
1190 };
1191
1192 @Override
1193 public void onAttachedToWindow() {
1194 super.onAttachedToWindow();
1195
1196 // Listen for broadcasts related to user-presence
1197 final IntentFilter filter = new IntentFilter();
1198 filter.addAction(Intent.ACTION_SCREEN_OFF);
1199 filter.addAction(Intent.ACTION_USER_PRESENT);
1200 registerReceiver(mReceiver, filter);
1201
Adam Cohend113e0c2010-11-11 10:48:05 -08001202 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001203 mVisible = true;
1204 }
1205
1206 @Override
1207 public void onDetachedFromWindow() {
1208 super.onDetachedFromWindow();
1209 mVisible = false;
1210
Adam Cohend113e0c2010-11-11 10:48:05 -08001211 if (mAttached) {
1212 unregisterReceiver(mReceiver);
1213 mAttached = false;
1214 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001215 updateRunning();
1216 }
1217
1218 public void onWindowVisibilityChanged(int visibility) {
1219 mVisible = visibility == View.VISIBLE;
1220 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001221 // The following code used to be in onResume, but it turns out onResume is called when
1222 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1223 // is a more appropriate event to handle
1224 if (mVisible) {
1225 mAppsCustomizeTabHost.onWindowVisible();
1226 if (!mWorkspaceLoading) {
1227 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001228 // We want to let Launcher draw itself at least once before we force it to build
1229 // layers on all the workspace pages, so that transitioning to Launcher from other
1230 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
1231 // a true draw so we wait until the second preDraw call to be safe
1232 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001233 public boolean onPreDraw() {
Michael Jurka6ee21d22012-02-21 18:20:27 -08001234 // We delay the layer building a bit in order to give
1235 // other message processing a time to run. In particular
1236 // this avoids a delay in hiding the IME if it was
1237 // currently shown, because doing that may involve
1238 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001239 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Winson Chung31ce0732012-05-06 13:36:43 -07001240
1241 // We had to enable the wallpaper visibility when launching apps from all
1242 // apps (so that the transitions would be the same as when launching from
1243 // workspace) so take this time to see if we need to re-disable the
1244 // wallpaper visibility to ensure performance.
1245 mWorkspace.post(new Runnable() {
1246 @Override
1247 public void run() {
Winson Chung18f41f82012-05-09 13:28:10 -07001248 disableWallpaperIfInAllApps();
Winson Chung31ce0732012-05-06 13:36:43 -07001249 }
1250 });
1251
Michael Jurka6ee21d22012-02-21 18:20:27 -08001252 observer.removeOnPreDrawListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001253 return true;
1254 }
1255 });
1256 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001257 // When Launcher comes back to foreground, a different Activity might be responsible for
1258 // the app market intent, so refresh the icon
1259 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001260 clearTypedText();
1261 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001262 }
1263
1264 private void sendAdvanceMessage(long delay) {
1265 mHandler.removeMessages(ADVANCE_MSG);
1266 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1267 mHandler.sendMessageDelayed(msg, delay);
1268 mAutoAdvanceSentTime = System.currentTimeMillis();
1269 }
1270
1271 private void updateRunning() {
1272 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1273 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1274 mAutoAdvanceRunning = autoAdvanceRunning;
1275 if (autoAdvanceRunning) {
1276 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1277 sendAdvanceMessage(delay);
1278 } else {
1279 if (!mWidgetsToAdvance.isEmpty()) {
1280 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1281 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1282 }
1283 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001284 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001285 }
1286 }
1287 }
1288
1289 private final Handler mHandler = new Handler() {
1290 @Override
1291 public void handleMessage(Message msg) {
1292 if (msg.what == ADVANCE_MSG) {
1293 int i = 0;
1294 for (View key: mWidgetsToAdvance.keySet()) {
1295 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1296 final int delay = mAdvanceStagger * i;
1297 if (v instanceof Advanceable) {
1298 postDelayed(new Runnable() {
1299 public void run() {
1300 ((Advanceable) v).advance();
1301 }
1302 }, delay);
1303 }
1304 i++;
1305 }
1306 sendAdvanceMessage(mAdvanceInterval);
1307 }
1308 }
1309 };
1310
1311 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001312 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001313 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1314 if (v instanceof Advanceable) {
1315 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001316 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001317 updateRunning();
1318 }
1319 }
1320
1321 void removeWidgetToAutoAdvance(View hostView) {
1322 if (mWidgetsToAdvance.containsKey(hostView)) {
1323 mWidgetsToAdvance.remove(hostView);
1324 updateRunning();
1325 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001326 }
1327
Joe Onorato9c1289c2009-08-17 11:03:03 -04001328 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001329 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001330 launcherInfo.hostView = null;
1331 }
1332
Winson Chung93eef082012-03-23 15:59:27 -07001333 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1334 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1335 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001336 }
1337
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001338 public LauncherAppWidgetHost getAppWidgetHost() {
1339 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001340 }
Romain Guycbb89e42009-06-08 15:52:54 -07001341
Winson Chunga9abd0e2010-10-27 17:18:37 -07001342 public LauncherModel getModel() {
1343 return mModel;
1344 }
1345
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001346 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001347 getWindow().closeAllPanels();
1348
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001349 // Whatever we were doing is hereby canceled.
1350 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001351 }
1352
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001353 @Override
1354 protected void onNewIntent(Intent intent) {
1355 super.onNewIntent(intent);
1356
1357 // Close the menu
1358 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001359 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001360 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001361
Joe Onorato14f122b2009-11-19 14:06:36 -08001362 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1363 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001364
Adam Cohenac56cff2011-09-28 20:45:37 -07001365 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001366 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001367 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001368 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1369 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001370 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001371 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001372
1373 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001374 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001375 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001376
Joe Onorato3a8820b2009-11-10 15:06:42 -08001377 final View v = getWindow().peekDecorView();
1378 if (v != null && v.getWindowToken() != null) {
1379 InputMethodManager imm = (InputMethodManager)getSystemService(
1380 INPUT_METHOD_SERVICE);
1381 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001382 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001383
Michael Jurka35aa14d2011-07-07 17:01:08 -07001384 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001385 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001386 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001387 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001388 }
1389 }
1390
1391 @Override
1392 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1393 // Do not call super here
1394 mSavedInstanceState = savedInstanceState;
1395 }
1396
1397 @Override
1398 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001399 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001400 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001401
Michael Jurka883f55b2010-10-21 15:47:14 -07001402 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001403 // We close any open folder since it will not be re-opened, and we need to make sure
1404 // this state is reflected.
1405 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001406
Winson Chung3d503fb2011-07-13 17:25:49 -07001407 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1408 mWaitingForResult) {
1409 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1410 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1411 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1412 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001413 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1414 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1415 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001416 }
1417
1418 if (mFolderInfo != null && mWaitingForResult) {
1419 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1420 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1421 }
Michael Jurka946ad472010-07-09 18:05:18 -07001422
Winson Chung785d2eb2011-04-14 16:08:02 -07001423 // Save the current AppsCustomize tab
1424 if (mAppsCustomizeTabHost != null) {
1425 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1426 if (currentTabTag != null) {
1427 outState.putString("apps_customize_currentTab", currentTabTag);
1428 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001429 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1430 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001431 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001432 }
1433
1434 @Override
1435 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001436 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001437
Winson Chunge7a03942011-08-05 15:05:12 -07001438 // Remove all pending runnables
1439 mHandler.removeMessages(ADVANCE_MSG);
1440 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001441 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001442
Winson Chungcd2b0142011-06-08 16:02:26 -07001443 // Stop callbacks from LauncherModel
1444 LauncherApplication app = ((LauncherApplication) getApplication());
1445 mModel.stopLoader();
1446 app.setLauncher(null);
1447
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001448 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001449 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001450 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001451 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001452 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001453 mAppWidgetHost = null;
1454
1455 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001456
1457 TextKeyListener.getInstance().release();
1458
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001459
Winson Chung3d503fb2011-07-13 17:25:49 -07001460 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001461
1462 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001463 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001464
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001465 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001466 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1467 mWorkspace.removeAllViews();
1468 mWorkspace = null;
1469 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001470
1471 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001472 }
1473
Adam Cohena9cf38f2011-05-02 15:36:58 -07001474 public DragController getDragController() {
1475 return mDragController;
1476 }
1477
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001478 @Override
1479 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001480 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001481 super.startActivityForResult(intent, requestCode);
1482 }
1483
Winson Chung70d72102011-08-12 11:24:35 -07001484 /**
1485 * Indicates that we want global search for this activity by setting the globalSearch
1486 * argument for {@link #startSearch} to true.
1487 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001488 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001489 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001490 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001491
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001492 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001493
Karl Rosaen138a0412009-04-23 19:00:21 -07001494 if (initialQuery == null) {
1495 // Use any text typed in the launcher as the initial query
1496 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001497 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001498 if (appSearchData == null) {
1499 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001500 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001501 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001502 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001503
Karl Rosaen138a0412009-04-23 19:00:21 -07001504 final SearchManager searchManager =
1505 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001506 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001507 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001508 }
1509
Winson Chung70d72102011-08-12 11:24:35 -07001510 @Override
1511 public boolean onCreateOptionsMenu(Menu menu) {
1512 if (isWorkspaceLocked()) {
1513 return false;
1514 }
1515
1516 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001517
1518 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1519 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1520 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001521 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1522 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1523 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001524 String helpUrl = getString(R.string.help_url);
1525 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001526 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1527 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1528
Winson Chung70d72102011-08-12 11:24:35 -07001529 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1530 .setIcon(android.R.drawable.ic_menu_gallery)
1531 .setAlphabeticShortcut('W');
1532 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1533 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001534 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001535 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001536 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1537 .setIcon(android.R.drawable.ic_menu_preferences)
1538 .setIntent(settings)
1539 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001540 if (!helpUrl.isEmpty()) {
1541 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1542 .setIcon(android.R.drawable.ic_menu_help)
1543 .setIntent(help)
1544 .setAlphabeticShortcut('H');
1545 }
Winson Chung70d72102011-08-12 11:24:35 -07001546 return true;
1547 }
1548
1549 @Override
1550 public boolean onPrepareOptionsMenu(Menu menu) {
1551 super.onPrepareOptionsMenu(menu);
1552
1553 if (mAppsCustomizeTabHost.isTransitioning()) {
1554 return false;
1555 }
1556 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1557 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1558
1559 return true;
1560 }
1561
1562 @Override
1563 public boolean onOptionsItemSelected(MenuItem item) {
1564 switch (item.getItemId()) {
1565 case MENU_WALLPAPER_SETTINGS:
1566 startWallpaper();
1567 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001568 }
1569
1570 return super.onOptionsItemSelected(item);
1571 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001572
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001573 @Override
1574 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001575 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001576 // Use a custom animation for launching search
1577 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001578 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001579 }
1580
Joe Onorato9c1289c2009-08-17 11:03:03 -04001581 public boolean isWorkspaceLocked() {
1582 return mWorkspaceLoading || mWaitingForResult;
1583 }
1584
Michael Jurka0280c3b2010-09-17 15:00:07 -07001585 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001586 mPendingAddInfo.container = ItemInfo.NO_ID;
1587 mPendingAddInfo.screen = -1;
1588 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1589 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001590 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001591 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001592 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001593
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001594 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1595 AppWidgetProviderInfo appWidgetInfo) {
1596 if (appWidgetInfo.configure != null) {
1597 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001598
Bjorn Bringert7984c942009-12-09 15:38:25 +00001599 // Launch over to configure widget, if needed
1600 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001601 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001602 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Romain Guy8e633c52010-03-04 12:51:36 -08001603 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001604 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001605 // Otherwise just add it
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001606 completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget,
1607 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001608 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001609 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001610 }
1611 }
Romain Guycbb89e42009-06-08 15:52:54 -07001612
Adam Cohenfbba09b2011-07-18 21:43:05 -07001613 /**
1614 * Process a shortcut drop.
1615 *
1616 * @param componentName The name of the component
1617 * @param screen The screen where it should be added
1618 * @param cell The cell it should be added to, optional
1619 * @param position The location on the screen where it was dropped, optional
1620 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001621 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1622 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001623 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001624 mPendingAddInfo.container = container;
1625 mPendingAddInfo.screen = screen;
1626 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001627
1628 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001629 mPendingAddInfo.cellX = cell[0];
1630 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001631 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001632
1633 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1634 createShortcutIntent.setComponent(componentName);
1635 processShortcut(createShortcutIntent);
1636 }
1637
Adam Cohenfbba09b2011-07-18 21:43:05 -07001638 /**
1639 * Process a widget drop.
1640 *
1641 * @param info The PendingAppWidgetInfo of the widget being added.
1642 * @param screen The screen where it should be added
1643 * @param cell The cell it should be added to, optional
1644 * @param position The location on the screen where it was dropped, optional
1645 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001646 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
Adam Cohend41fbf52012-02-16 23:53:59 -08001647 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001648 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001649 mPendingAddInfo.container = info.container = container;
1650 mPendingAddInfo.screen = info.screen = screen;
1651 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001652 mPendingAddInfo.minSpanX = info.minSpanX;
1653 mPendingAddInfo.minSpanY = info.minSpanY;
1654
Adam Cohenfbba09b2011-07-18 21:43:05 -07001655 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001656 mPendingAddInfo.cellX = cell[0];
1657 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001658 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001659 if (span != null) {
1660 mPendingAddInfo.spanX = span[0];
1661 mPendingAddInfo.spanY = span[1];
1662 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001663
Adam Cohened66b2b2012-01-23 17:28:51 -08001664 AppWidgetHostView hostView = info.boundWidget;
1665 int appWidgetId;
1666 if (hostView != null) {
1667 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001668 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001669 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001670 // In this case, we either need to start an activity to get permission to bind
1671 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001672 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Michael Jurka8b805b12012-04-18 14:23:14 -07001673 if (mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName)) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001674 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001675 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001676 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001677 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1678 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1679 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
1680 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1681 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001682 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001683 }
1684
Joe Onoratodeb98af2010-02-19 14:59:39 -08001685 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001686 // Handle case where user selected "Applications"
1687 String applicationName = getResources().getString(R.string.group_applications);
1688 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001689
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001690 if (applicationName != null && applicationName.equals(shortcutName)) {
1691 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1692 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001693
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001694 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1695 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001696 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001697 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001698 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001699 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001700 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001701 }
1702
Winson Chung24ab2f12010-09-16 14:10:47 -07001703 void processWallpaper(Intent intent) {
1704 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1705 }
1706
Winson Chung3d503fb2011-07-13 17:25:49 -07001707 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1708 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001709 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001710 folderInfo.title = getText(R.string.folder_name);
1711
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001712 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001713 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1714 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001715 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001716
1717 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001718 FolderIcon newFolder =
1719 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1720 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1721 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001722 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001723 }
Romain Guycbb89e42009-06-08 15:52:54 -07001724
Joe Onorato9c1289c2009-08-17 11:03:03 -04001725 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001726 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001727 }
1728
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001729 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001730 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001731 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001732 Intent chooser = Intent.createChooser(pickWallpaper,
1733 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001734 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1735 // Removed in Eclair MR1
1736// WallpaperManager wm = (WallpaperManager)
1737// getSystemService(Context.WALLPAPER_SERVICE);
1738// WallpaperInfo wi = wm.getWallpaperInfo();
1739// if (wi != null && wi.getSettingsActivity() != null) {
1740// LabeledIntent li = new LabeledIntent(getPackageName(),
1741// R.string.configure_wallpaper, 0);
1742// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1743// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1744// }
Mike Clerona0618e42009-10-22 13:55:21 -07001745 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001746 }
1747
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001748 /**
1749 * Registers various content observers. The current implementation registers
1750 * only a favorites observer to keep track of the favorites applications.
1751 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001752 private void registerContentObservers() {
1753 ContentResolver resolver = getContentResolver();
1754 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1755 true, mWidgetObserver);
1756 }
1757
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001758 @Override
1759 public boolean dispatchKeyEvent(KeyEvent event) {
1760 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1761 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001762 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001763 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001764 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001765 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001766 dumpState();
1767 return true;
1768 }
1769 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001770 }
1771 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1772 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001773 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001774 return true;
1775 }
1776 }
1777
1778 return super.dispatchKeyEvent(event);
1779 }
1780
Joe Onorato88ec0992009-11-19 13:16:06 -08001781 @Override
1782 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001783 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001784 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001785 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001786 Folder openFolder = mWorkspace.getOpenFolder();
1787 if (openFolder.isEditingName()) {
1788 openFolder.dismissEditingName();
1789 } else {
1790 closeFolder();
1791 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001792 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001793 mWorkspace.exitWidgetResizeMode();
1794
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001795 // Back button is a no-op here, but give at least some feedback for the button press
1796 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001797 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001798 }
1799
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001800 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001801 * Re-listen when widgets are reset.
1802 */
1803 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001804 if (mAppWidgetHost != null) {
1805 mAppWidgetHost.startListening();
1806 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001807 }
1808
1809 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001810 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1811 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001812 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001813 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001814 if (mModel != null) {
1815 mModel.unbindWorkspaceItems();
1816 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001817 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001818
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001819 /**
1820 * Launches the intent referred by the clicked shortcut.
1821 *
1822 * @param v The view representing the clicked shortcut.
1823 */
1824 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001825 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1826 // view has detached (it's possible for this to happen if the view is removed mid touch).
1827 if (v.getWindowToken() == null) {
1828 return;
1829 }
1830
Winson Chung9b0b2fe2012-02-24 13:03:34 -08001831 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001832 return;
1833 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001834
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001835 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001836 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001837 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001838 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001839 int[] pos = new int[2];
1840 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001841 intent.setSourceBounds(new Rect(pos[0], pos[1],
1842 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07001843
1844 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001845
1846 if (success && v instanceof BubbleTextView) {
1847 mWaitingForResume = (BubbleTextView) v;
1848 mWaitingForResume.setStayPressed(true);
1849 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001850 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001851 if (v instanceof FolderIcon) {
1852 FolderIcon fi = (FolderIcon) v;
1853 handleFolderClick(fi);
1854 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001855 } else if (v == mAllAppsButton) {
1856 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001857 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001858 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001859 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001860 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001861 }
1862 }
1863
Michael Jurka0e260592010-06-30 17:07:39 -07001864 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001865 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001866 // clicking anywhere on the workspace causes the customization drawer to slide down
1867 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001868 return false;
1869 }
1870
Michael Jurkaaf442092010-06-10 17:01:57 -07001871 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001872 * Event handler for the search button
1873 *
1874 * @param v The view that was clicked.
1875 */
1876 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001877 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1878
Amith Yamasania135ba82011-08-09 17:42:01 -07001879 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001880 }
1881
1882 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001883 * Event handler for the voice button
1884 *
1885 * @param v The view that was clicked.
1886 */
1887 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001888 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001889
Michael Jurkaae65ee32012-04-30 11:45:54 -07001890 try {
1891 final SearchManager searchManager =
1892 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1893 ComponentName activityName = searchManager.getGlobalSearchActivity();
1894 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
1895 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1896 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1897 if (activityName != null) {
1898 intent.setPackage(activityName.getPackageName());
1899 }
Michael Jurka86a720e2012-05-09 11:23:23 -07001900 startActivity(null, intent, "onClickVoiceButton");
Winson Chung01b0b632012-05-22 10:18:14 -07001901 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001902 } catch (ActivityNotFoundException e) {
1903 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
1904 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1905 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1906 startActivitySafely(null, intent, "onClickVoiceButton");
1907 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001908 }
1909
1910 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001911 * Event handler for the "grid" button that appears on the home screen, which
1912 * enters all apps mode.
1913 *
1914 * @param v The view that was clicked.
1915 */
1916 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001917 showAllApps(true);
1918 }
1919
1920 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001921 // Provide the same haptic feedback that the system offers for virtual keys.
1922 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001923 }
1924
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001925 public void onClickAppMarketButton(View v) {
1926 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07001927 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07001928 } else {
1929 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001930 }
1931 }
1932
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001933 void startApplicationDetailsActivity(ComponentName componentName) {
1934 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001935 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1936 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001937 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07001938 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001939 }
1940
Patrick Dubroy5539af72010-09-07 15:22:01 -07001941 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1942 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1943 // System applications cannot be installed. For now, show a toast explaining that.
1944 // We may give them the option of disabling apps this way.
1945 int messageId = R.string.uninstall_system_app_text;
1946 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1947 } else {
1948 String packageName = appInfo.componentName.getPackageName();
1949 String className = appInfo.componentName.getClassName();
1950 Intent intent = new Intent(
1951 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001952 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1953 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001954 startActivity(intent);
1955 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001956 }
1957
Michael Jurka86a720e2012-05-09 11:23:23 -07001958 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001959 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07001960
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001961 try {
Winson Chung2672ff92012-05-04 16:22:30 -07001962 // Only launch using the new animation if the shortcut has not opted out (this is a
1963 // private contract between launcher and may be ignored in the future).
1964 boolean useLaunchAnimation = (v != null) &&
1965 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
1966 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07001967 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
1968 v.getMeasuredWidth(), v.getMeasuredHeight());
1969
1970 startActivity(intent, opts.toBundle());
1971 } else {
1972 startActivity(intent);
1973 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001974 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001975 } catch (SecurityException e) {
1976 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001977 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001978 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001979 "or use the exported attribute for this activity. "
1980 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001981 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001982 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001983 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001984
Michael Jurka86a720e2012-05-09 11:23:23 -07001985 boolean startActivitySafely(View v, Intent intent, Object tag) {
1986 boolean success = false;
1987 try {
1988 success = startActivity(v, intent, tag);
1989 } catch (ActivityNotFoundException e) {
1990 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1991 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
1992 }
1993 return success;
1994 }
1995
Romain Guy8e633c52010-03-04 12:51:36 -08001996 void startActivityForResultSafely(Intent intent, int requestCode) {
1997 try {
1998 startActivityForResult(intent, requestCode);
1999 } catch (ActivityNotFoundException e) {
2000 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2001 } catch (SecurityException e) {
2002 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2003 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2004 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2005 "or use the exported attribute for this activity.", e);
2006 }
2007 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002008
Adam Cohena9cf38f2011-05-02 15:36:58 -07002009 private void handleFolderClick(FolderIcon folderIcon) {
2010 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07002011 Folder openFolder = mWorkspace.getFolderForTag(info);
2012
2013 // If the folder info reports that the associated folder is open, then verify that
2014 // it is actually opened. There have been a few instances where this gets out of sync.
2015 if (info.opened && openFolder == null) {
2016 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2017 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
2018 info.opened = false;
2019 }
2020
Adam Cohena9cf38f2011-05-02 15:36:58 -07002021 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002022 // Close any open folder
2023 closeFolder();
2024 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002025 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002026 } else {
2027 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002028 int folderScreen;
2029 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002030 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031 // .. and close it
2032 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002033 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002034 // Close any folder open on the current screen
2035 closeFolder();
2036 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002037 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002038 }
2039 }
2040 }
2041 }
2042
Adam Cohen2801caf2011-05-13 20:57:39 -07002043 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002044 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002045 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2046 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2047 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2048
Adam Cohenc51934b2011-07-26 21:07:43 -07002049 FolderInfo info = (FolderInfo) fi.getTag();
2050 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2051 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002052 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2053 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002054 }
2055
Adam Cohen2801caf2011-05-13 20:57:39 -07002056 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
2057 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2058 oa.start();
2059 }
2060
2061 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002062 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002063 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2064 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2065 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2066
Adam Cohenc51934b2011-07-26 21:07:43 -07002067 FolderInfo info = (FolderInfo) fi.getTag();
2068 CellLayout cl = null;
2069 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2070 cl = (CellLayout) fi.getParent().getParent();
2071 }
2072
2073 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07002074 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
2075 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002076 oa.addListener(new AnimatorListenerAdapter() {
2077 @Override
2078 public void onAnimationEnd(Animator animation) {
2079 if (layout != null) {
2080 layout.clearFolderLeaveBehind();
2081 }
2082 }
2083 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002084 oa.start();
2085 }
2086
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002087 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002088 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002089 * is animated relative to the specified View. If the View is null, no animation
2090 * is played.
2091 *
2092 * @param folderInfo The FolderInfo describing the folder to open.
2093 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002094 public void openFolder(FolderIcon folderIcon) {
2095 Folder folder = folderIcon.mFolder;
2096 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002097
Adam Cohen2801caf2011-05-13 20:57:39 -07002098 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002099 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002100
Adam Cohen4554ee12011-08-03 16:13:21 -07002101 // Just verify that the folder hasn't already been added to the DragLayer.
2102 // There was a one-off crash where the folder had a parent already.
2103 if (folder.getParent() == null) {
2104 mDragLayer.addView(folder);
2105 mDragController.addDropTarget((DropTarget) folder);
2106 } else {
2107 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2108 folder.getParent() + ").");
2109 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002110 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07002111 }
2112
2113 public void closeFolder() {
2114 Folder folder = mWorkspace.getOpenFolder();
2115 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002116 if (folder.isEditingName()) {
2117 folder.dismissEditingName();
2118 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002119 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002120
2121 // Dismiss the folder cling
2122 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002123 }
2124 }
2125
2126 void closeFolder(Folder folder) {
2127 folder.getInfo().opened = false;
2128
2129 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2130 if (parent != null) {
2131 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2132 shrinkAndFadeInFolderIcon(fi);
2133 }
2134 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002135 }
2136
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002137 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002138 if (!isDraggingEnabled()) return false;
2139 if (isWorkspaceLocked()) return false;
2140 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002141
2142 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002143 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002144 }
2145
Michael Jurka0280c3b2010-09-17 15:00:07 -07002146 resetAddInfo();
2147 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002148 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002149 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002150 return true;
2151 }
2152
Winson Chung3d503fb2011-07-13 17:25:49 -07002153 // The hotseat touch handling does not go through Workspace, and we always allow long press
2154 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002155 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002156 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2157 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002158 if (itemUnderLongClick == null) {
2159 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002160 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2161 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002162 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002163 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002164 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002165 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002166 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002167 }
2168 }
2169 }
2170 return true;
2171 }
2172
Winson Chung3d503fb2011-07-13 17:25:49 -07002173 boolean isHotseatLayout(View layout) {
2174 return mHotseat != null && layout != null &&
2175 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2176 }
2177 Hotseat getHotseat() {
2178 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002179 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002180 SearchDropTargetBar getSearchBar() {
2181 return mSearchDropTargetBar;
2182 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002183
Winson Chung3d503fb2011-07-13 17:25:49 -07002184 /**
2185 * Returns the CellLayout of the specified container at the specified screen.
2186 */
2187 CellLayout getCellLayout(long container, int screen) {
2188 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2189 if (mHotseat != null) {
2190 return mHotseat.getLayout();
2191 } else {
2192 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002193 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002194 } else {
2195 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002196 }
2197 }
2198
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002199 Workspace getWorkspace() {
2200 return mWorkspace;
2201 }
2202
Daniel Sandler843e8602010-06-07 14:59:01 -04002203 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2204 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002205 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002206 }
2207
Andrew Flynn0dca1ec2012-02-29 13:33:22 -08002208 public boolean isAllAppsButtonRank(int rank) {
2209 return mHotseat.isAllAppsButtonRank(rank);
2210 }
2211
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002212 // AllAppsView.Watcher
2213 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002214 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002215 mWorkspace.setVisibility(View.GONE);
2216 }
2217 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002218
2219 /**
2220 * Helper method for the cameraZoomIn/cameraZoomOut animations
2221 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002222 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002223 * @param scaleFactor The scale factor used for the zoom
2224 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002225 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002226 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002227 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002228 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002229
Winson Chung18f41f82012-05-09 13:28:10 -07002230 void disableWallpaperIfInAllApps() {
2231 // Only disable it if we are in all apps
2232 if (mState == State.APPS_CUSTOMIZE) {
2233 if (mAppsCustomizeTabHost != null &&
2234 !mAppsCustomizeTabHost.isTransitioning()) {
2235 updateWallpaperVisibility(false);
2236 }
2237 }
2238 }
2239
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002240 void updateWallpaperVisibility(boolean visible) {
2241 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2242 int curflags = getWindow().getAttributes().flags
2243 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2244 if (wpflags != curflags) {
2245 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2246 }
2247 }
2248
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002249 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2250 if (v instanceof LauncherTransitionable) {
2251 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2252 }
2253 }
2254
Michael Jurkabed61d22012-02-14 22:51:29 -08002255 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
Winson Chung7c7a22d2012-06-01 13:46:48 -07002256 if (toWorkspace) {
2257 Log.d(TAG, "6549598 Start animation to workspace");
2258 } else {
2259 Log.d(TAG, "6549598 Start animation to all apps");
2260 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002261 if (v instanceof LauncherTransitionable) {
2262 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2263 }
Winson Chung70442722012-02-10 15:43:22 -08002264
2265 // Update the workspace transition step as well
2266 dispatchOnLauncherTransitionStep(v, 0f);
2267 }
2268
2269 private void dispatchOnLauncherTransitionStep(View v, float t) {
2270 if (v instanceof LauncherTransitionable) {
2271 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2272 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002273 }
2274
2275 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
Winson Chung7c7a22d2012-06-01 13:46:48 -07002276 if (toWorkspace) {
2277 Log.d(TAG, "6549598 End animation to workspace");
2278 } else {
2279 Log.d(TAG, "6549598 End animation to all apps");
2280 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002281 if (v instanceof LauncherTransitionable) {
2282 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2283 }
Winson Chung70442722012-02-10 15:43:22 -08002284
2285 // Update the workspace transition step as well
2286 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002287 }
2288
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002289 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002290 * Things to test when changing the following seven functions.
2291 * - Home from workspace
2292 * - from center screen
2293 * - from other screens
2294 * - Home from all apps
2295 * - from center screen
2296 * - from other screens
2297 * - Back from all apps
2298 * - from center screen
2299 * - from other screens
2300 * - Launch app from workspace and quit
2301 * - with back
2302 * - with home
2303 * - Launch app from all apps and quit
2304 * - with back
2305 * - with home
2306 * - Go to a screen that's not the default, then all
2307 * apps, and launch and app, and go back
2308 * - with back
2309 * -with home
2310 * - On workspace, long press power and go back
2311 * - with back
2312 * - with home
2313 * - On all apps, long press power and go back
2314 * - with back
2315 * - with home
2316 * - On workspace, power off
2317 * - On all apps, power off
2318 * - Launch an app and turn off the screen while in that app
2319 * - Go back with home key
2320 * - Go back with back key TODO: make this not go to workspace
2321 * - From all apps
2322 * - From workspace
2323 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2324 * - From all apps
2325 * - From the center workspace
2326 * - From another workspace
2327 */
2328
2329 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002330 * Zoom the camera out from the workspace to reveal 'toView'.
2331 * Assumes that the view to show is anchored at either the very top or very bottom
2332 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002333 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002334 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002335 if (mStateAnimation != null) {
2336 mStateAnimation.cancel();
2337 mStateAnimation = null;
2338 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002339 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002340
Winson Chungf0ea4d32011-06-06 14:27:16 -07002341 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2342 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2343 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002344 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002345 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002346 final int startDelay =
2347 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002348
Michael Jurkab3e22d92011-10-31 15:58:33 -07002349 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002350
Michael Jurkad74c9842011-07-10 12:44:21 -07002351 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002352 Animator workspaceAnim =
2353 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002354
2355 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002356 toView.setScaleX(scale);
2357 toView.setScaleY(scale);
2358 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2359 scaleAnim.
2360 scaleX(1f).scaleY(1f).
2361 setDuration(duration).
2362 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002363
Winson Chungf0ea4d32011-06-06 14:27:16 -07002364 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002365 toView.setAlpha(0f);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002366 final ObjectAnimator alphaAnim = ObjectAnimator
2367 .ofFloat(toView, "alpha", 0f, 1f)
2368 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002369 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002370 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2371 @Override
2372 public void onAnimationUpdate(ValueAnimator animation) {
2373 float t = (Float) animation.getAnimatedValue();
2374 dispatchOnLauncherTransitionStep(fromView, t);
2375 dispatchOnLauncherTransitionStep(toView, t);
2376 }
2377 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002378
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002379 // toView should appear right at the end of the workspace shrink
2380 // animation
2381 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002382 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002383 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002384
2385 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002386 boolean animationCancelled = false;
2387
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002388 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002389 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002390 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002391 // Prepare the position
2392 toView.setTranslationX(0.0f);
2393 toView.setTranslationY(0.0f);
2394 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002395 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002396 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002397 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002398 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002399 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2400 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002401
2402 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2403 // Hide the workspace scrollbar
2404 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002405 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002406 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002407 if (!animationCancelled) {
2408 updateWallpaperVisibility(false);
2409 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002410
2411 // Hide the search bar
2412 mSearchDropTargetBar.hideSearchBar(false);
Adam Cohenf4ddea32011-09-12 13:46:42 -07002413 }
2414
Adam Cohencff6af82011-09-13 14:51:53 -07002415 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002416 public void onAnimationCancel(Animator animation) {
2417 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002418 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002419 });
2420
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002421 if (workspaceAnim != null) {
2422 mStateAnimation.play(workspaceAnim);
2423 }
Michael Jurka1899a362011-11-03 13:50:45 -07002424
2425 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002426 final ViewTreeObserver observer;
2427
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002428 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2429 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002430
2431 // If any of the objects being animated haven't been measured/laid out
2432 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002433 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002434 (mWorkspace.getMeasuredWidth() == 0) ||
2435 (toView.getMeasuredWidth() == 0)) {
2436 observer = mWorkspace.getViewTreeObserver();
2437 delayAnim = true;
2438 } else {
2439 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002440 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002441
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002442 final AnimatorSet stateAnimation = mStateAnimation;
2443 final Runnable startAnimRunnable = new Runnable() {
2444 public void run() {
2445 // Check that mStateAnimation hasn't changed while
2446 // we waited for a layout/draw pass
2447 if (mStateAnimation != stateAnimation)
2448 return;
2449 setPivotsForZoom(toView, scale);
2450 dispatchOnLauncherTransitionStart(fromView, animated, false);
2451 dispatchOnLauncherTransitionStart(toView, animated, false);
2452 mWorkspace.post(new Runnable() {
2453 public void run() {
2454 // Check that mStateAnimation hasn't changed while
2455 // we waited for a layout/draw pass
2456 if (mStateAnimation != stateAnimation)
2457 return;
2458 mStateAnimation.start();
2459 }
2460 });
2461 }
2462 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002463 if (delayAnim) {
2464 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2465 public void onGlobalLayout() {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002466 mWorkspace.post(startAnimRunnable);
Michael Jurka3a9fced2012-04-13 14:44:29 -07002467 observer.removeOnGlobalLayoutListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002468 }
2469 };
2470 observer.addOnGlobalLayoutListener(delayedStart);
2471 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002472 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002473 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002474 } else {
2475 toView.setTranslationX(0.0f);
2476 toView.setTranslationY(0.0f);
2477 toView.setScaleX(1.0f);
2478 toView.setScaleY(1.0f);
2479 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002480 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002481
Michael Jurkabed61d22012-02-14 22:51:29 -08002482 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2483 // Hide the workspace scrollbar
2484 mWorkspace.hideScrollingIndicator(true);
2485 hideDockDivider();
Winson Chungc7d2b602012-05-16 17:02:20 -07002486
2487 // Hide the search bar
2488 mSearchDropTargetBar.hideSearchBar(false);
Michael Jurkaabded662011-03-04 12:06:57 -08002489 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002490 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002491 dispatchOnLauncherTransitionStart(fromView, animated, false);
2492 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002493 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002494 dispatchOnLauncherTransitionStart(toView, animated, false);
2495 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002496 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002497 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002498 }
2499
2500 /**
2501 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002502 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002503 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002504 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002505 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2506 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002507
Michael Jurkab3e22d92011-10-31 15:58:33 -07002508 if (mStateAnimation != null) {
2509 mStateAnimation.cancel();
2510 mStateAnimation = null;
2511 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002512 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002513
Winson Chungf0ea4d32011-06-06 14:27:16 -07002514 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002515 final int fadeOutDuration =
2516 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002517 final float scaleFactor = (float)
2518 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2519 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002520 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002521 Animator workspaceAnim = null;
2522
2523 if (toState == State.WORKSPACE) {
2524 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2525 workspaceAnim = mWorkspace.getChangeStateAnimation(
2526 Workspace.State.NORMAL, animated, stagger);
2527 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2528 workspaceAnim = mWorkspace.getChangeStateAnimation(
2529 Workspace.State.SPRING_LOADED, animated);
2530 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002531
Michael Jurkab3e22d92011-10-31 15:58:33 -07002532 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002533 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002534 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002535 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002536 final LauncherViewPropertyAnimator scaleAnim =
2537 new LauncherViewPropertyAnimator(fromView);
2538 scaleAnim.
2539 scaleX(scaleFactor).scaleY(scaleFactor).
2540 setDuration(duration).
2541 setInterpolator(new Workspace.ZoomInInterpolator());
2542
2543 final ObjectAnimator alphaAnim = ObjectAnimator
2544 .ofFloat(fromView, "alpha", 1f, 0f)
2545 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002546 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002547 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2548 @Override
2549 public void onAnimationUpdate(ValueAnimator animation) {
2550 float t = 1f - (Float) animation.getAnimatedValue();
2551 dispatchOnLauncherTransitionStep(fromView, t);
2552 dispatchOnLauncherTransitionStep(toView, t);
2553 }
2554 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002555
Michael Jurkabed61d22012-02-14 22:51:29 -08002556 mStateAnimation = new AnimatorSet();
2557
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002558 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2559 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002560
2561 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002562 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002563 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002564 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002565 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002566 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2567 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkabafdaaf2012-04-26 13:43:25 -07002568 if (mWorkspace != null) {
2569 mWorkspace.hideScrollingIndicator(false);
2570 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002571 if (onCompleteRunnable != null) {
2572 onCompleteRunnable.run();
2573 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002574 }
2575 });
2576
Winson Chungf0ea4d32011-06-06 14:27:16 -07002577 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002578 if (workspaceAnim != null) {
2579 mStateAnimation.play(workspaceAnim);
2580 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002581 dispatchOnLauncherTransitionStart(fromView, animated, true);
2582 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002583 final Animator stateAnimation = mStateAnimation;
2584 mWorkspace.post(new Runnable() {
2585 public void run() {
2586 if (stateAnimation != mStateAnimation)
2587 return;
2588 mStateAnimation.start();
2589 }
2590 });
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002591 } else {
2592 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002593 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002594 dispatchOnLauncherTransitionStart(fromView, animated, true);
2595 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002596 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002597 dispatchOnLauncherTransitionStart(toView, animated, true);
2598 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002599 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002600 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002601 }
2602
Michael Jurkae326f182011-11-21 14:05:46 -08002603 @Override
2604 public void onTrimMemory(int level) {
2605 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002606 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002607 mAppsCustomizeTabHost.onTrimMemory();
2608 }
2609 }
2610
Winson Chung18f41f82012-05-09 13:28:10 -07002611 @Override
2612 public void onWindowFocusChanged(boolean hasFocus) {
2613 if (!hasFocus) {
2614 // When another window occludes launcher (like the notification shade, or recents),
2615 // ensure that we enable the wallpaper flag so that transitions are done correctly.
2616 updateWallpaperVisibility(true);
2617 } else {
2618 // When launcher has focus again, disable the wallpaper if we are in AllApps
2619 disableWallpaperIfInAllApps();
2620 }
2621 }
2622
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002623 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002624 showWorkspace(animated, null);
2625 }
2626
2627 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002628 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002629 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002630 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002631 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002632
Winson Chungc7d2b602012-05-16 17:02:20 -07002633 // Show the search bar (only animate if we were showing the drop target bar in spring
2634 // loaded mode)
2635 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
2636
Michael Jurkab737ee62011-11-15 15:57:22 -08002637 // We only need to animate in the dock divider if we're going from spring loaded mode
Winson Chungc7d2b602012-05-16 17:02:20 -07002638 showDockDivider(animated && wasInSpringLoadedMode);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002639
2640 // Set focus to the AppsCustomize button
2641 if (mAllAppsButton != null) {
2642 mAllAppsButton.requestFocus();
2643 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002644 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002645
Michael Jurkab737ee62011-11-15 15:57:22 -08002646 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002647
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002648 // Change the state *after* we've called all the transition code
2649 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002650
Winson Chung5fb63472011-02-02 17:03:37 -08002651 // Resume the auto-advance of widgets
2652 mUserPresent = true;
2653 updateRunning();
2654
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002655 // send an accessibility event to announce the context change
2656 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002657 }
2658
Michael Jurkab3e22d92011-10-31 15:58:33 -07002659 void showAllApps(boolean animated) {
2660 if (mState != State.WORKSPACE) return;
2661
2662 showAppsCustomizeHelper(animated, false);
2663 mAppsCustomizeTabHost.requestFocus();
2664
Michael Jurkab3e22d92011-10-31 15:58:33 -07002665 // Change the state *after* we've called all the transition code
2666 mState = State.APPS_CUSTOMIZE;
2667
2668 // Pause the auto-advance of widgets until we are out of AllApps
2669 mUserPresent = false;
2670 updateRunning();
2671 closeFolder();
2672
2673 // Send an accessibility event to announce the context change
2674 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2675 }
2676
Adam Cohen7777d962011-08-18 18:58:38 -07002677 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002678 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002679 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002680 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002681 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002682 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002683 }
Adam Cohen7777d962011-08-18 18:58:38 -07002684
Adam Cohened66b2b2012-01-23 17:28:51 -08002685 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2686 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002687 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2688
Winson Chunge7a03942011-08-05 15:05:12 -07002689 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002690 @Override
2691 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002692 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002693 // Before we show workspace, hide all apps again because
2694 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2695 // clean up our state transition functions
2696 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002697 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002698 } else {
2699 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002700 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002701 }
2702 }, (extendedDelay ?
2703 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2704 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2705 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002706
Michael Jurkad3ef3062010-11-23 16:23:58 -08002707 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002708 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002709 final boolean animated = true;
2710 final boolean springLoaded = true;
2711 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002712 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002713 }
2714 // Otherwise, we are not in spring loaded mode, so don't do anything.
2715 }
2716
Michael Jurkab737ee62011-11-15 15:57:22 -08002717 void hideDockDivider() {
2718 if (mQsbDivider != null && mDockDivider != null) {
2719 mQsbDivider.setVisibility(View.INVISIBLE);
2720 mDockDivider.setVisibility(View.INVISIBLE);
2721 }
2722 }
2723
2724 void showDockDivider(boolean animated) {
2725 if (mQsbDivider != null && mDockDivider != null) {
2726 mQsbDivider.setVisibility(View.VISIBLE);
2727 mDockDivider.setVisibility(View.VISIBLE);
2728 if (mDividerAnimator != null) {
2729 mDividerAnimator.cancel();
2730 mQsbDivider.setAlpha(1f);
2731 mDockDivider.setAlpha(1f);
2732 mDividerAnimator = null;
2733 }
2734 if (animated) {
2735 mDividerAnimator = new AnimatorSet();
2736 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2737 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2738 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2739 mDividerAnimator.start();
2740 }
2741 }
2742 }
2743
Michael Jurkab3e22d92011-10-31 15:58:33 -07002744 void lockAllApps() {
2745 // TODO
2746 }
2747
2748 void unlockAllApps() {
2749 // TODO
2750 }
2751
Adam Cohenfc53cd22011-07-20 15:45:11 -07002752 public boolean isAllAppsCustomizeOpen() {
2753 return mState == State.APPS_CUSTOMIZE;
2754 }
2755
Winson Chungf0ea4d32011-06-06 14:27:16 -07002756 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002757 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002758 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002759 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002760 if (!LauncherApplication.isScreenLarge()) {
2761 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002762 if (mHotseat.getAlpha() != 1f) {
2763 int duration = mSearchDropTargetBar.getTransitionInDuration();
2764 mHotseat.animate().alpha(1f).setDuration(duration);
2765 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002766 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002767 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002768 }
2769 }
2770 }
2771
2772 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002773 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002774 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002775 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002776 if (!LauncherApplication.isScreenLarge()) {
2777 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002778 if (mHotseat.getAlpha() != 0f) {
2779 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2780 mHotseat.animate().alpha(0f).setDuration(duration);
2781 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002782 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002783 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002784 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002785 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002786 }
2787
Patrick Dubroy5f445422011-02-18 14:35:21 -08002788 /**
2789 * Add an item from all apps or customize onto the given workspace screen.
2790 * If layout is null, add to the current screen.
2791 */
2792 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002793 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07002794 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07002795 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002796 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002797
Winson Chungdff8ebb2011-09-08 17:25:31 -07002798 /** Maps the current orientation to an index for referencing orientation correct global icons */
2799 private int getCurrentOrientationIndexForGlobalIcons() {
2800 // default - 0, landscape - 1
2801 switch (getResources().getConfiguration().orientation) {
2802 case Configuration.ORIENTATION_LANDSCAPE:
2803 return 1;
2804 default:
2805 return 0;
2806 }
2807 }
2808
Michael Jurkaae65ee32012-04-30 11:45:54 -07002809 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002810 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002811 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002812 // Look for the toolbar icon specified in the activity meta-data
2813 Bundle metaData = packageManager.getActivityInfo(
2814 activityName, PackageManager.GET_META_DATA).metaData;
2815 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002816 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002817 if (iconResId != 0) {
2818 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002819 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002820 }
2821 }
2822 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002823 // This can happen if the activity defines an invalid drawable
2824 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2825 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002826 } catch (Resources.NotFoundException nfe) {
2827 // This can happen if the activity defines an invalid drawable
2828 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2829 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002830 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002831 return null;
2832 }
2833
2834 // if successful in getting icon, return it; otherwise, set button to use default drawable
2835 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002836 int buttonId, ComponentName activityName, int fallbackDrawableId,
2837 String toolbarResourceName) {
2838 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002839 Resources r = getResources();
2840 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2841 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002842
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002843 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002844 // If we were unable to find the icon via the meta-data, use a generic one
2845 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002846 toolbarIcon = r.getDrawable(fallbackDrawableId);
2847 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002848 if (button != null) {
2849 button.setCompoundDrawables(toolbarIcon, null, null, null);
2850 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002851 return null;
2852 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002853 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002854 if (button != null) {
2855 button.setCompoundDrawables(toolbarIcon, null, null, null);
2856 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002857 return toolbarIcon.getConstantState();
2858 }
2859 }
2860
2861 // if successful in getting icon, return it; otherwise, set button to use default drawable
2862 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002863 int buttonId, ComponentName activityName, int fallbackDrawableId,
2864 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002865 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002866 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002867
Michael Jurka19e0fc52011-07-22 18:00:21 -07002868 if (button != null) {
2869 // If we were unable to find the icon via the meta-data, use a
2870 // generic one
2871 if (toolbarIcon == null) {
2872 button.setImageResource(fallbackDrawableId);
2873 } else {
2874 button.setImageDrawable(toolbarIcon);
2875 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002876 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002877
2878 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2879
Michael Jurka0423dcf2010-10-05 14:56:18 -07002880 }
2881
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002882 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2883 TextView button = (TextView) findViewById(buttonId);
2884 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2885 }
2886
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002887 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002888 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002889 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002890 }
2891
Winson Chungbb185bd2011-11-21 12:31:42 -08002892 private void invalidatePressedFocusedStates(View container, View button) {
2893 if (container instanceof HolographicLinearLayout) {
2894 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2895 layout.invalidatePressedFocusedStates();
2896 } else if (button instanceof HolographicImageView) {
2897 HolographicImageView view = (HolographicImageView) button;
2898 view.invalidatePressedFocusedStates();
2899 }
2900 }
2901
Winson Chungc51db6a2011-10-05 11:44:49 -07002902 private boolean updateGlobalSearchIcon() {
2903 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002904 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2905 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002906 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002907 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07002908 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07002909
Winson Chung1cad91e2011-05-25 17:41:01 -07002910 final SearchManager searchManager =
2911 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2912 ComponentName activityName = searchManager.getGlobalSearchActivity();
2913 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002914 int coi = getCurrentOrientationIndexForGlobalIcons();
2915 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002916 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2917 TOOLBAR_SEARCH_ICON_METADATA_NAME);
2918 if (sGlobalSearchIcon[coi] == null) {
2919 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
2920 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2921 TOOLBAR_ICON_METADATA_NAME);
2922 }
2923
Winson Chung649723c2011-07-06 20:41:23 -07002924 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002925 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2926 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002927 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002928 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002929 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002930 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002931 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002932 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2933 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2934 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002935 voiceButton.setVisibility(View.GONE);
Michael Jurkac60498a2012-05-07 15:29:42 -07002936 if (voiceButtonProxy != null) {
2937 voiceButtonProxy.setVisibility(View.GONE);
2938 }
Winson Chungc51db6a2011-10-05 11:44:49 -07002939 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002940 }
2941 }
2942
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002943 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002944 final View searchButtonContainer = findViewById(R.id.search_button_container);
2945 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002946 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002947 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002948 }
2949
Winson Chungc51db6a2011-10-05 11:44:49 -07002950 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002951 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002952 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002953 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07002954 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07002955
Winson Chungc51db6a2011-10-05 11:44:49 -07002956 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07002957 final SearchManager searchManager =
2958 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2959 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2960
2961 ComponentName activityName = null;
2962 if (globalSearchActivity != null) {
2963 // Check if the global search activity handles voice search
2964 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2965 intent.setPackage(globalSearchActivity.getPackageName());
2966 activityName = intent.resolveActivity(getPackageManager());
2967 }
2968
2969 if (activityName == null) {
2970 // Fallback: check if an activity other than the global search activity
2971 // resolves this
2972 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2973 activityName = intent.resolveActivity(getPackageManager());
2974 }
Winson Chungc51db6a2011-10-05 11:44:49 -07002975 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002976 int coi = getCurrentOrientationIndexForGlobalIcons();
2977 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002978 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
2979 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
2980 if (sVoiceSearchIcon[coi] == null) {
2981 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
2982 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
2983 TOOLBAR_ICON_METADATA_NAME);
2984 }
Winson Chung649723c2011-07-06 20:41:23 -07002985 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002986 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002987 voiceButton.setVisibility(View.VISIBLE);
Jim Miller14091b12012-04-24 19:27:54 -07002988 if (voiceButtonProxy != null) {
2989 voiceButtonProxy.setVisibility(View.VISIBLE);
2990 }
Winson Chungbb185bd2011-11-21 12:31:42 -08002991 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002992 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002993 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002994 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002995 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002996 voiceButton.setVisibility(View.GONE);
Jim Miller14091b12012-04-24 19:27:54 -07002997 if (voiceButtonProxy != null) {
2998 voiceButtonProxy.setVisibility(View.GONE);
2999 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003000 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003001 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003002 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003003
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003004 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003005 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3006 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003007 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003008 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003009 }
3010
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003011 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003012 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003013 */
3014 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003015 final View marketButton = findViewById(R.id.market_button);
3016 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3017 // Find the app market activity by resolving an intent.
3018 // (If multiple app markets are installed, it will return the ResolverActivity.)
3019 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003020 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003021 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003022 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003023 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003024 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3025 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003026 marketButton.setVisibility(View.VISIBLE);
3027 } else {
3028 // We should hide and disable the view so that we don't try and restore the visibility
3029 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3030 marketButton.setVisibility(View.GONE);
3031 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003032 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003033 }
3034
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003035 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003036 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003037 }
3038
Michael Jurkad7c28052012-04-27 15:43:36 -07003039 @Override
3040 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
3041 boolean result = super.dispatchPopulateAccessibilityEvent(event);
3042 final List<CharSequence> text = event.getText();
3043 text.clear();
3044 text.add(getString(R.string.home));
3045 return result;
3046 }
3047
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003048 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003049 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003050 */
3051 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3052 @Override
3053 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003054 closeSystemDialogs();
3055 }
3056 }
3057
3058 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003059 * Receives notifications whenever the appwidgets are reset.
3060 */
3061 private class AppWidgetResetObserver extends ContentObserver {
3062 public AppWidgetResetObserver() {
3063 super(new Handler());
3064 }
3065
3066 @Override
3067 public void onChange(boolean selfChange) {
3068 onAppWidgetReset();
3069 }
3070 }
3071
3072 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003073 * If the activity is currently paused, signal that we need to re-run the loader
3074 * in onResume.
3075 *
3076 * This needs to be called from incoming places where resources might have been loaded
3077 * while we are paused. That is becaues the Configuration might be wrong
3078 * when we're not running, and if it comes back to what it was when we
3079 * were paused, we are not restarted.
3080 *
3081 * Implementation of the method from LauncherModel.Callbacks.
3082 *
3083 * @return true if we are currently paused. The caller might be able to
3084 * skip some work in that case since we will come back again.
3085 */
3086 public boolean setLoadOnResume() {
3087 if (mPaused) {
3088 Log.i(TAG, "setLoadOnResume");
3089 mOnResumeNeedsLoad = true;
3090 return true;
3091 } else {
3092 return false;
3093 }
3094 }
3095
3096 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003097 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003098 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003099 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003100 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003101 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003102 } else {
3103 return SCREEN_COUNT / 2;
3104 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003105 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003106
Joe Onorato9c1289c2009-08-17 11:03:03 -04003107 /**
3108 * Refreshes the shortcuts shown on the workspace.
3109 *
3110 * Implementation of the method from LauncherModel.Callbacks.
3111 */
3112 public void startBinding() {
3113 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07003114
Winson Chungf0c6ae02012-03-21 16:10:31 -07003115 mNewShortcutAnimatePage = -1;
3116 mNewShortcutAnimateViews.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003117 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003118 int count = workspace.getChildCount();
3119 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003120 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003121 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3122 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003123 }
Michael Jurka05bf6442011-11-30 20:28:53 -08003124 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003125 if (mHotseat != null) {
3126 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003127 }
3128 }
3129
3130 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003131 * Bind the items start-end from the list.
3132 *
3133 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003134 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003135 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003136 setLoadOnResume();
3137
Winson Chungf0c6ae02012-03-21 16:10:31 -07003138 // Get the list of added shortcuts and intersect them with the set of shortcuts here
3139 Set<String> newApps = new HashSet<String>();
3140 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);
3141
3142 Workspace workspace = mWorkspace;
3143 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003144 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003145
3146 // Short circuit if we are loading dock items for a configuration which has no dock
3147 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3148 mHotseat == null) {
3149 continue;
3150 }
3151
Joe Onorato9c1289c2009-08-17 11:03:03 -04003152 switch (item.itemType) {
3153 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3154 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003155 ShortcutInfo info = (ShortcutInfo) item;
3156 String uri = info.intent.toUri(0).toString();
3157 View shortcut = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -07003158 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3159 item.cellY, 1, 1, false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003160 if (newApps.contains(uri)) {
3161 newApps.remove(uri);
3162
3163 // Prepare the view to be animated up
3164 shortcut.setAlpha(0f);
3165 shortcut.setScaleX(0f);
3166 shortcut.setScaleY(0f);
3167 mNewShortcutAnimatePage = item.screen;
3168 if (!mNewShortcutAnimateViews.contains(shortcut)) {
3169 mNewShortcutAnimateViews.add(shortcut);
3170 }
3171 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003172 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003173 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003174 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003175 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003176 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003177 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3178 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003179 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003180 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003181 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003182
Joe Onorato9c1289c2009-08-17 11:03:03 -04003183 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003184 }
3185
Joe Onorato9c1289c2009-08-17 11:03:03 -04003186 /**
3187 * Implementation of the method from LauncherModel.Callbacks.
3188 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003189 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003190 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003191 sFolders.clear();
3192 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003193 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003194
3195 /**
3196 * Add the views for a widget to the workspace.
3197 *
3198 * Implementation of the method from LauncherModel.Callbacks.
3199 */
3200 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003201 setLoadOnResume();
3202
Daniel Sandler843e8602010-06-07 14:59:01 -04003203 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3204 if (DEBUG_WIDGETS) {
3205 Log.d(TAG, "bindAppWidget: " + item);
3206 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003207 final Workspace workspace = mWorkspace;
3208
3209 final int appWidgetId = item.appWidgetId;
3210 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003211 if (DEBUG_WIDGETS) {
3212 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3213 }
3214
Joe Onorato9c1289c2009-08-17 11:03:03 -04003215 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3216
Joe Onorato9c1289c2009-08-17 11:03:03 -04003217 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
3218 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003219 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003220
Winson Chung3d503fb2011-07-13 17:25:49 -07003221 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003222 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003223 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3224
Joe Onorato9c1289c2009-08-17 11:03:03 -04003225 workspace.requestLayout();
3226
Daniel Sandler843e8602010-06-07 14:59:01 -04003227 if (DEBUG_WIDGETS) {
3228 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3229 + (SystemClock.uptimeMillis()-start) + "ms");
3230 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003231 }
3232
3233 /**
3234 * Callback saying that there aren't any more items to bind.
3235 *
3236 * Implementation of the method from LauncherModel.Callbacks.
3237 */
3238 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003239 setLoadOnResume();
3240
Joe Onorato9c1289c2009-08-17 11:03:03 -04003241 if (mSavedState != null) {
3242 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003243 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003244 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003245 mSavedState = null;
3246 }
3247
3248 if (mSavedInstanceState != null) {
3249 super.onRestoreInstanceState(mSavedInstanceState);
3250 mSavedInstanceState = null;
3251 }
3252
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003253 // If we received the result of any pending adds while the loader was running (e.g. the
3254 // widget configuration forced an orientation change), process them now.
3255 for (int i = 0; i < sPendingAddList.size(); i++) {
3256 completeAdd(sPendingAddList.get(i));
3257 }
3258 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003259
Winson Chungc51db6a2011-10-05 11:44:49 -07003260 // Update the market app icon as necessary (the other icons will be managed in response to
3261 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003262 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003263
Winson Chungf0c6ae02012-03-21 16:10:31 -07003264 // Animate up any icons as necessary
3265 if (mVisible || mWorkspaceLoading) {
3266 Runnable newAppsRunnable = new Runnable() {
3267 @Override
3268 public void run() {
Winson Chunga2413752012-04-03 14:22:34 -07003269 runNewAppsAnimation(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003270 }
3271 };
Winson Chunga2413752012-04-03 14:22:34 -07003272
3273 boolean willSnapPage = mNewShortcutAnimatePage > -1 &&
3274 mNewShortcutAnimatePage != mWorkspace.getCurrentPage();
3275 if (canRunNewAppsAnimation()) {
3276 // If the user has not interacted recently, then either snap to the new page to show
3277 // the new-apps animation or just run them if they are to appear on the current page
3278 if (willSnapPage) {
3279 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable);
3280 } else {
3281 runNewAppsAnimation(false);
3282 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003283 } else {
Winson Chung318eee02012-04-12 10:59:27 -07003284 // If the user has interacted recently, then just add the items in place if they
Winson Chunga2413752012-04-03 14:22:34 -07003285 // are on another page (or just normally if they are added to the current page)
3286 runNewAppsAnimation(willSnapPage);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003287 }
3288 }
3289
3290 mWorkspaceLoading = false;
3291 }
3292
Winson Chunga2413752012-04-03 14:22:34 -07003293 private boolean canRunNewAppsAnimation() {
3294 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3295 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3296 }
3297
Winson Chungf0c6ae02012-03-21 16:10:31 -07003298 /**
3299 * Runs a new animation that scales up icons that were added while Launcher was in the
3300 * background.
Winson Chunga2413752012-04-03 14:22:34 -07003301 *
3302 * @param immediate whether to run the animation or show the results immediately
Winson Chungf0c6ae02012-03-21 16:10:31 -07003303 */
Winson Chunga2413752012-04-03 14:22:34 -07003304 private void runNewAppsAnimation(boolean immediate) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003305 AnimatorSet anim = new AnimatorSet();
3306 Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chunga2413752012-04-03 14:22:34 -07003307
3308 // Order these new views spatially so that they animate in order
Winson Chungf0c6ae02012-03-21 16:10:31 -07003309 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
3310 @Override
3311 public int compare(View a, View b) {
3312 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
3313 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
3314 int cellCountX = LauncherModel.getCellCountX();
3315 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
3316 }
3317 });
Winson Chunga2413752012-04-03 14:22:34 -07003318
3319 // Animate each of the views in place (or show them immediately if requested)
3320 if (immediate) {
3321 for (View v : mNewShortcutAnimateViews) {
3322 v.setAlpha(1f);
3323 v.setScaleX(1f);
3324 v.setScaleY(1f);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003325 }
Winson Chunga2413752012-04-03 14:22:34 -07003326 } else {
3327 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
3328 View v = mNewShortcutAnimateViews.get(i);
3329 ValueAnimator bounceAnim = ObjectAnimator.ofPropertyValuesHolder(v,
3330 PropertyValuesHolder.ofFloat("alpha", 1f),
3331 PropertyValuesHolder.ofFloat("scaleX", 1f),
3332 PropertyValuesHolder.ofFloat("scaleY", 1f));
3333 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3334 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3335 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3336 bounceAnims.add(bounceAnim);
3337 }
3338 anim.playTogether(bounceAnims);
3339 anim.addListener(new AnimatorListenerAdapter() {
3340 @Override
3341 public void onAnimationEnd(Animator animation) {
3342 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
3343 }
3344 });
3345 anim.start();
3346 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003347
3348 // Clean up
3349 mNewShortcutAnimatePage = -1;
3350 mNewShortcutAnimateViews.clear();
3351 new Thread("clearNewAppsThread") {
3352 public void run() {
3353 mSharedPrefs.edit()
3354 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
3355 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null)
3356 .commit();
3357 }
3358 }.start();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003359 }
3360
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003361 @Override
3362 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003363 boolean searchVisible = updateGlobalSearchIcon();
3364 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3365 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003366 }
3367
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003368 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003369 * Add the icons for all apps.
3370 *
3371 * Implementation of the method from LauncherModel.Callbacks.
3372 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003373 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3374 // Remove the progress bar entirely; we could also make it GONE
3375 // but better to remove it since we know it's not going to be used
3376 View progressBar = mAppsCustomizeTabHost.
3377 findViewById(R.id.apps_customize_progress_bar);
3378 if (progressBar != null) {
3379 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003380 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003381 // We just post the call to setApps so the user sees the progress bar
3382 // disappear-- otherwise, it just looks like the progress bar froze
3383 // which doesn't look great
3384 mAppsCustomizeTabHost.post(new Runnable() {
3385 public void run() {
3386 if (mAppsCustomizeContent != null) {
3387 mAppsCustomizeContent.setApps(apps);
3388 }
3389 }
3390 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003391 }
3392
3393 /**
3394 * A package was installed.
3395 *
3396 * Implementation of the method from LauncherModel.Callbacks.
3397 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003398 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003399 setLoadOnResume();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003400
Winson Chung785d2eb2011-04-14 16:08:02 -07003401 if (mAppsCustomizeContent != null) {
3402 mAppsCustomizeContent.addApps(apps);
3403 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003404 }
3405
3406 /**
3407 * A package was updated.
3408 *
3409 * Implementation of the method from LauncherModel.Callbacks.
3410 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003411 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003412 setLoadOnResume();
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003413 if (mWorkspace != null) {
3414 mWorkspace.updateShortcuts(apps);
3415 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003416
Winson Chung785d2eb2011-04-14 16:08:02 -07003417 if (mAppsCustomizeContent != null) {
3418 mAppsCustomizeContent.updateApps(apps);
3419 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003420 }
3421
3422 /**
3423 * A package was uninstalled.
3424 *
3425 * Implementation of the method from LauncherModel.Callbacks.
3426 */
Joe Onorato36115782010-06-17 13:28:48 -04003427 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato36115782010-06-17 13:28:48 -04003428 if (permanent) {
3429 mWorkspace.removeItems(apps);
3430 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003431
Winson Chung785d2eb2011-04-14 16:08:02 -07003432 if (mAppsCustomizeContent != null) {
3433 mAppsCustomizeContent.removeApps(apps);
3434 }
Winson Chunga1820962011-10-03 16:31:06 -07003435
3436 // Notify the drag controller
3437 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003438 }
Joe Onoratobe386092009-11-17 17:32:16 -08003439
3440 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003441 * A number of packages were updated.
3442 */
3443 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003444 if (mAppsCustomizeContent != null) {
3445 mAppsCustomizeContent.onPackagesUpdated();
3446 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003447 }
3448
Winson Chung400438b2011-01-16 17:53:48 -08003449 private int mapConfigurationOriActivityInfoOri(int configOri) {
3450 final Display d = getWindowManager().getDefaultDisplay();
3451 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3452 switch (d.getRotation()) {
3453 case Surface.ROTATION_0:
3454 case Surface.ROTATION_180:
3455 // We are currently in the same basic orientation as the natural orientation
3456 naturalOri = configOri;
3457 break;
3458 case Surface.ROTATION_90:
3459 case Surface.ROTATION_270:
3460 // We are currently in the other basic orientation to the natural orientation
3461 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3462 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3463 break;
3464 }
3465
3466 int[] oriMap = {
3467 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3468 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3469 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3470 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3471 };
3472 // Since the map starts at portrait, we need to offset if this device's natural orientation
3473 // is landscape.
3474 int indexOffset = 0;
3475 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3476 indexOffset = 1;
3477 }
3478 return oriMap[(d.getRotation() + indexOffset) % 4];
3479 }
Adam Cohen446e9402011-09-15 18:21:21 -07003480
Winson Chung4b919f82012-05-01 10:44:08 -07003481 public boolean isRotationEnabled() {
3482 boolean forceEnableRotation = "true".equalsIgnoreCase(SystemProperties.get(
3483 FORCE_ENABLE_ROTATION_PROPERTY, "false"));
3484 boolean enableRotation = forceEnableRotation ||
3485 getResources().getBoolean(R.bool.allow_rotation);
3486 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08003487 }
Winson Chung4b919f82012-05-01 10:44:08 -07003488 public void lockScreenOrientation() {
3489 if (isRotationEnabled()) {
3490 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3491 .getConfiguration().orientation));
3492 }
3493 }
3494 public void unlockScreenOrientation(boolean immediate) {
3495 if (isRotationEnabled()) {
3496 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07003497 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07003498 } else {
3499 mHandler.postDelayed(new Runnable() {
3500 public void run() {
3501 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3502 }
3503 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07003504 }
Winson Chung4b919f82012-05-01 10:44:08 -07003505 }
Winson Chung400438b2011-01-16 17:53:48 -08003506 }
3507
Winson Chung82f55532011-08-09 14:14:23 -07003508 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003509 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003510 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003511 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003512
Winson Chung7d7541e2011-09-16 20:14:36 -07003513 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003514 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003515 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3516 Cling cling = (Cling) findViewById(clingId);
3517 if (cling != null) {
3518 cling.init(this, positionData);
3519 cling.setVisibility(View.VISIBLE);
3520 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Svetoslav Ganov55d225d2012-05-22 15:19:14 -07003521 cling.requestAccessibilityFocus();
Winson Chung7d7541e2011-09-16 20:14:36 -07003522 if (animate) {
3523 cling.buildLayer();
3524 cling.setAlpha(0f);
3525 cling.animate()
3526 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003527 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003528 .setDuration(SHOW_CLING_DURATION)
3529 .setStartDelay(delay)
3530 .start();
3531 } else {
3532 cling.setAlpha(1f);
3533 }
3534 }
3535 return cling;
3536 }
3537 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003538 if (cling != null) {
3539 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003540 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003541 anim.addListener(new AnimatorListenerAdapter() {
3542 public void onAnimationEnd(Animator animation) {
3543 cling.setVisibility(View.GONE);
3544 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003545 // We should update the shared preferences on a background thread
3546 new Thread("dismissClingThread") {
3547 public void run() {
3548 SharedPreferences.Editor editor = mSharedPrefs.edit();
3549 editor.putBoolean(flag, true);
3550 editor.commit();
3551 }
3552 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003553 };
3554 });
3555 anim.start();
3556 }
3557 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003558 private void removeCling(int id) {
3559 final View cling = findViewById(id);
3560 if (cling != null) {
3561 final ViewGroup parent = (ViewGroup) cling.getParent();
3562 parent.post(new Runnable() {
3563 @Override
3564 public void run() {
3565 parent.removeView(cling);
3566 }
3567 });
3568 }
3569 }
Michael Jurka974c3862012-05-22 22:00:31 -07003570
3571 private boolean skipCustomClingIfNoAccounts() {
3572 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3573 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
3574 if (customCling) {
3575 AccountManager am = AccountManager.get(this);
3576 Account[] accounts = am.getAccountsByType("com.google");
3577 return accounts.length == 0;
3578 }
3579 return false;
3580 }
3581
Winson Chung7d7541e2011-09-16 20:14:36 -07003582 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003583 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003584 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07003585 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
3586 !skipCustomClingIfNoAccounts() ) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003587 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003588 } else {
3589 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003590 }
3591 }
3592 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003593 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003594 if (isClingsEnabled() &&
3595 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003596 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003597 } else {
3598 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003599 }
3600 }
3601 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003602 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003603 if (isClingsEnabled() &&
3604 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
3605 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003606 } else {
3607 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08003608 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07003609 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003610 }
3611 public boolean isFolderClingVisible() {
3612 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003613 if (cling != null) {
3614 return cling.getVisibility() == View.VISIBLE;
3615 }
3616 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003617 }
Winson Chung82f55532011-08-09 14:14:23 -07003618 public void dismissWorkspaceCling(View v) {
3619 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003620 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003621 }
3622 public void dismissAllAppsCling(View v) {
3623 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003624 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3625 }
3626 public void dismissFolderCling(View v) {
3627 Cling cling = (Cling) findViewById(R.id.folder_cling);
3628 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003629 }
3630
Winson Chung80baf5a2010-08-09 16:03:15 -07003631 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003632 * Prints out out state for debugging.
3633 */
3634 public void dumpState() {
3635 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003636 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003637 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3638 Log.d(TAG, "mRestoring=" + mRestoring);
3639 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3640 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003641 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003642 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003643
Winson Chung785d2eb2011-04-14 16:08:02 -07003644 if (mAppsCustomizeContent != null) {
3645 mAppsCustomizeContent.dumpState();
3646 }
Joe Onoratobe386092009-11-17 17:32:16 -08003647 Log.d(TAG, "END launcher2 dump state");
3648 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003649
3650 @Override
3651 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3652 super.dump(prefix, fd, writer, args);
3653 writer.println(" ");
3654 writer.println("Debug logs: ");
3655 for (int i = 0; i < sDumpLogs.size(); i++) {
3656 writer.println(" " + sDumpLogs.get(i));
3657 }
3658 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003659}
Michael Jurka2763be32011-02-24 11:19:57 -08003660
Michael Jurkaabded662011-03-04 12:06:57 -08003661interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003662 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003663 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08003664 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08003665 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08003666 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003667}