blob: fb29a4131ce77a8d2e1552c5c8655515bb32ab2b [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
Adam Cohenf9426d52012-06-04 17:26:21 -0700377 updateGlobalIcons();
378
379 // On large interfaces, we want the screen to auto-rotate based on the current orientation
380 unlockScreenOrientation(true);
381 }
382
383 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700384 boolean searchVisible = false;
385 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800386 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700387 int coi = getCurrentOrientationIndexForGlobalIcons();
388 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
389 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700390 updateAppMarketIcon();
391 searchVisible = updateGlobalSearchIcon();
392 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700393 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700394 if (sGlobalSearchIcon[coi] != null) {
395 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700396 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700397 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700398 if (sVoiceSearchIcon[coi] != null) {
399 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700400 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700401 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700402 if (sAppMarketIcon[coi] != null) {
403 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800404 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700405 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800406 }
Romain Guycbb89e42009-06-08 15:52:54 -0700407
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800408 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700409 if (sLocaleConfiguration == null) {
410 new AsyncTask<Void, Void, LocaleConfiguration>() {
411 @Override
412 protected LocaleConfiguration doInBackground(Void... unused) {
413 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
414 readConfiguration(Launcher.this, localeConfiguration);
415 return localeConfiguration;
416 }
417
418 @Override
419 protected void onPostExecute(LocaleConfiguration result) {
420 sLocaleConfiguration = result;
421 checkForLocaleChange(); // recursive, but now with a locale configuration
422 }
423 }.execute();
424 return;
425 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700426
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800427 final Configuration configuration = getResources().getConfiguration();
428
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700429 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800430 final String locale = configuration.locale.toString();
431
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700432 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800433 final int mcc = configuration.mcc;
434
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700435 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800436 final int mnc = configuration.mnc;
437
Romain Guy84f296c2009-11-04 15:00:44 -0800438 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800439
Romain Guy84f296c2009-11-04 15:00:44 -0800440 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700441 sLocaleConfiguration.locale = locale;
442 sLocaleConfiguration.mcc = mcc;
443 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700444
Joe Onorato0589f0f2010-02-08 13:44:00 -0800445 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700446
447 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
448 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700449 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700450 public void run() {
451 writeConfiguration(Launcher.this, localeConfiguration);
452 }
453 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700454 }
455 }
456
457 private static class LocaleConfiguration {
458 public String locale;
459 public int mcc = -1;
460 public int mnc = -1;
461 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700462
Romain Guy98d01652009-06-30 16:21:04 -0700463 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
464 DataInputStream in = null;
465 try {
466 in = new DataInputStream(context.openFileInput(PREFERENCES));
467 configuration.locale = in.readUTF();
468 configuration.mcc = in.readInt();
469 configuration.mnc = in.readInt();
470 } catch (FileNotFoundException e) {
471 // Ignore
472 } catch (IOException e) {
473 // Ignore
474 } finally {
475 if (in != null) {
476 try {
477 in.close();
478 } catch (IOException e) {
479 // Ignore
480 }
481 }
482 }
483 }
484
485 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
486 DataOutputStream out = null;
487 try {
488 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
489 out.writeUTF(configuration.locale);
490 out.writeInt(configuration.mcc);
491 out.writeInt(configuration.mnc);
492 out.flush();
493 } catch (FileNotFoundException e) {
494 // Ignore
495 } catch (IOException e) {
496 //noinspection ResultOfMethodCallIgnored
497 context.getFileStreamPath(PREFERENCES).delete();
498 } finally {
499 if (out != null) {
500 try {
501 out.close();
502 } catch (IOException e) {
503 // Ignore
504 }
505 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800506 }
507 }
508
Adam Cohen716b51e2011-06-30 12:09:54 -0700509 public DragLayer getDragLayer() {
510 return mDragLayer;
511 }
512
Winson Chung36a62fe2012-05-06 18:04:42 -0700513 boolean isDraggingEnabled() {
514 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
515 // that is subsequently removed from the workspace in startBinding().
516 return !mModel.isLoadingWorkspace();
517 }
518
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800519 static int getScreen() {
520 synchronized (sLock) {
521 return sScreen;
522 }
523 }
524
525 static void setScreen(int screen) {
526 synchronized (sLock) {
527 sScreen = screen;
528 }
529 }
530
Winson Chung557d6ed2011-07-08 15:34:52 -0700531 /**
532 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
533 * a configuration step, this allows the proper animations to run after other transitions.
534 */
535 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700536 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800537 switch (args.requestCode) {
538 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700539 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
540 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800541 break;
542 case REQUEST_PICK_SHORTCUT:
543 processShortcut(args.intent);
544 break;
545 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700546 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
547 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700548 result = true;
549 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800550 case REQUEST_CREATE_APPWIDGET:
551 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800552 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700553 result = true;
554 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800555 case REQUEST_PICK_WALLPAPER:
556 // We just wanted the activity result here so we can clear mWaitingForResult
557 break;
558 }
Michael Jurka27614d22012-04-02 06:40:22 -0700559 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
560 // if you turned the screen off and then back while in All Apps, Launcher would not
561 // return to the workspace. Clearing mAddInfo.container here fixes this issue
562 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700563 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800564 }
565
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800566 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700567 protected void onActivityResult(
568 final int requestCode, final int resultCode, final Intent data) {
569 if (requestCode == REQUEST_BIND_APPWIDGET) {
570 int appWidgetId = data != null ?
571 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
572 if (resultCode == RESULT_CANCELED) {
573 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
574 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700575 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700576 }
577 return;
578 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700579 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800580 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
581 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700582 mWaitingForResult = false;
583
Adam Cohened66b2b2012-01-23 17:28:51 -0800584 // We have special handling for widgets
585 if (isWidgetDrop) {
586 int appWidgetId = data != null ?
587 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700588 if (appWidgetId < 0) {
589 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
590 "widget configuration activity.");
591 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
592 } else {
593 completeTwoStageWidgetDrop(resultCode, appWidgetId);
594 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800595 return;
596 }
597
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800598 // The pattern used here is that a user PICKs a specific application,
599 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700600
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800601 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
602 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700603 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800604 final PendingAddArguments args = new PendingAddArguments();
605 args.requestCode = requestCode;
606 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700607 args.container = mPendingAddInfo.container;
608 args.screen = mPendingAddInfo.screen;
609 args.cellX = mPendingAddInfo.cellX;
610 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800611 if (isWorkspaceLocked()) {
612 sPendingAddList.add(args);
613 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700614 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800615 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800616 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800617 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700618 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800619 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
620 null);
621 }
622
623 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700624 CellLayout cellLayout =
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700625 (CellLayout) mWorkspace.getChildAt(mPendingAddInfo.screen);
Adam Cohened66b2b2012-01-23 17:28:51 -0800626 Runnable onCompleteRunnable = null;
627 int animationType = 0;
628
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700629 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800630 if (resultCode == RESULT_OK) {
631 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
632 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700633 mPendingAddWidgetInfo);
634 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800635 onCompleteRunnable = new Runnable() {
636 @Override
637 public void run() {
638 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
639 mPendingAddInfo.screen, layout, null);
640 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
641 null);
642 }
643 };
644 } else if (resultCode == RESULT_CANCELED) {
645 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
646 onCompleteRunnable = new Runnable() {
647 @Override
648 public void run() {
649 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
650 null);
651 }
652 };
653 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700654 if (mDragLayer.getAnimatedView() != null) {
655 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
656 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
657 animationType, boundWidget, true);
658 } else {
659 // The animated view may be null in the case of a rotation during widget configuration
660 onCompleteRunnable.run();
661 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800662 }
663
664 @Override
665 protected void onResume() {
666 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700667
Winson Chungde0fb8f2012-05-08 14:37:08 -0700668 // Process any items that were added while Launcher was away
669 InstallShortcutReceiver.flushInstallQueue(this);
670
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800671 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700672 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400673 mWorkspaceLoading = true;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700674 mModel.startLoader(true);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400675 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700676 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800677 }
Winson Chunge4e50662012-01-23 14:45:13 -0800678
679 // Reset the pressed state of icons that were locked in the press state while activities
680 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800681 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800682 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800683 mWaitingForResume.setStayPressed(false);
684 }
Winson Chunge4e50662012-01-23 14:45:13 -0800685 if (mAppsCustomizeContent != null) {
686 // Resets the previous all apps icon press state
687 mAppsCustomizeContent.resetDrawableState();
688 }
Adam Cohen06dff352012-06-01 17:17:08 -0700689 // It is possible that widgets can receive updates while launcher is not in the foreground.
690 // Consequently, the widgets will be inflated in the orientation of the foreground activity
691 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
692 // orientation.
693 reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700694
695 // Again, as with the above scenario, it's possible that one or more of the global icons
696 // were updated in the wrong orientation.
697 updateGlobalIcons();
Adam Cohen06dff352012-06-01 17:17:08 -0700698 }
699
700 void reinflateWidgetsIfNecessary() {
701 for (LauncherAppWidgetInfo info: LauncherModel.getWidgets()) {
702 LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) info.hostView;
703 if (lahv != null && lahv.orientationChangedSincedInflation()) {
704 AppWidgetProviderInfo pInfo = lahv.getAppWidgetInfo();
705
Adam Cohen5637b872012-06-05 16:03:36 -0700706 Workspace workspace = getWorkspace();
707 CellLayout parent = workspace.getParentCellLayoutForView(lahv);
Adam Cohen06dff352012-06-01 17:17:08 -0700708
Adam Cohen5637b872012-06-05 16:03:36 -0700709 // It's possible this AppWidgetHostView is associated with a prior Launcher instance
710 // in which case it will not have a parent in the current hierarchy (ie. after rotation).
711 // In this case we will be re-inflating the widgets anyhow, so it's not a problem.
712 if (parent != null) {
713 // Remove the current widget which is inflated with the wrong orientation
714 parent.removeView(lahv);
715 // Re-inflate the widget using the correct orientation
716 AppWidgetHostView widget = mAppWidgetHost.createView(this, info.appWidgetId, pInfo);
717
718 // Add the new widget back
719 widget.setTag(info);
720 info.hostView = widget;
721 getWorkspace().addInScreen(widget, info.container, info.screen,
722 info.cellX, info.cellY, info.spanX, info.spanY);
723 }
Adam Cohen06dff352012-06-01 17:17:08 -0700724 }
725 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800726 }
727
728 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700729 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700730 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
731 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
732 // when Launcher resumes and we are still in AllApps.
733 updateWallpaperVisibility(true);
734
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700735 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700736 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800737 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700738 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700739 }
Romain Guycbb89e42009-06-08 15:52:54 -0700740
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700741 @Override
742 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400743 // Flag the loader to stop early before switching
744 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700745 if (mAppsCustomizeContent != null) {
746 mAppsCustomizeContent.surrender();
747 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800748 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700749 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700750
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800751 // We can't hide the IME if it was forced open. So don't bother
752 /*
753 @Override
754 public void onWindowFocusChanged(boolean hasFocus) {
755 super.onWindowFocusChanged(hasFocus);
756
757 if (hasFocus) {
758 final InputMethodManager inputManager = (InputMethodManager)
759 getSystemService(Context.INPUT_METHOD_SERVICE);
760 WindowManager.LayoutParams lp = getWindow().getAttributes();
761 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
762 android.os.Handler()) {
763 protected void onReceiveResult(int resultCode, Bundle resultData) {
764 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
765 }
766 });
767 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
768 }
769 }
770 */
771
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800772 private boolean acceptFilter() {
773 final InputMethodManager inputManager = (InputMethodManager)
774 getSystemService(Context.INPUT_METHOD_SERVICE);
775 return !inputManager.isFullscreenMode();
776 }
777
778 @Override
779 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700780 final int uniChar = event.getUnicodeChar();
781 final boolean handled = super.onKeyDown(keyCode, event);
782 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
783 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800784 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
785 keyCode, event);
786 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700787 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700788 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700789 // showSearchDialog()
790 // If there are multiple keystrokes before the search dialog takes focus,
791 // onSearchRequested() will be called for every keystroke,
792 // but it is idempotent, so it's fine.
793 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800794 }
795 }
796
Joe Onorato8a9625e2010-01-28 15:55:35 -0800797 // Eat the long press event so the keyboard doesn't come up.
798 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
799 return true;
800 }
801
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800802 return handled;
803 }
804
Karl Rosaen138a0412009-04-23 19:00:21 -0700805 private String getTypedText() {
806 return mDefaultKeySsb.toString();
807 }
808
809 private void clearTypedText() {
810 mDefaultKeySsb.clear();
811 mDefaultKeySsb.clearSpans();
812 Selection.setSelection(mDefaultKeySsb, 0);
813 }
814
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800815 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700816 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
817 * State
818 */
819 private static State intToState(int stateOrdinal) {
820 State state = State.WORKSPACE;
821 final State[] stateValues = State.values();
822 for (int i = 0; i < stateValues.length; i++) {
823 if (stateValues[i].ordinal() == stateOrdinal) {
824 state = stateValues[i];
825 break;
826 }
827 }
828 return state;
829 }
830
831 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800832 * Restores the previous state, if it exists.
833 *
834 * @param savedState The previous state.
835 */
836 private void restoreState(Bundle savedState) {
837 if (savedState == null) {
838 return;
839 }
840
Michael Jurka883f55b2010-10-21 15:47:14 -0700841 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700842 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800843 showAllApps(false);
844 }
845
Winson Chungf0c6ae02012-03-21 16:10:31 -0700846 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800847 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700848 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800849 }
850
Winson Chung3d503fb2011-07-13 17:25:49 -0700851 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
852 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700853
Winson Chung3d503fb2011-07-13 17:25:49 -0700854 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
855 mPendingAddInfo.container = pendingAddContainer;
856 mPendingAddInfo.screen = pendingAddScreen;
857 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
858 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700859 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
860 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
861 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -0700862 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800863 mRestoring = true;
864 }
865
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700866
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800867 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
868 if (renameFolder) {
869 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700870 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800871 mRestoring = true;
872 }
Winson Chunga12a2502010-12-20 14:41:35 -0800873
Winson Chung785d2eb2011-04-14 16:08:02 -0700874
875 // Restore the AppsCustomize tab
876 if (mAppsCustomizeTabHost != null) {
877 String curTab = savedState.getString("apps_customize_currentTab");
878 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700879 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700880 mAppsCustomizeContent.setContentType(
881 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
882 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700883 mAppsCustomizeContent.loadAssociatedPages(
884 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700885 }
886
Winson Chung5afbf7b2011-07-25 11:53:08 -0700887 int currentIndex = savedState.getInt("apps_customize_currentIndex");
888 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700889 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800890 }
891
892 /**
893 * Finds all the views we need and configure them properly.
894 */
895 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700896 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400897
Winson Chung4c98d922011-05-31 16:50:48 -0700898 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
899 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800900 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
901 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800902
Winson Chung4c98d922011-05-31 16:50:48 -0700903 // Setup the drag layer
904 mDragLayer.setup(this, dragController);
905
Winson Chung3d503fb2011-07-13 17:25:49 -0700906 // Setup the hotseat
907 mHotseat = (Hotseat) findViewById(R.id.hotseat);
908 if (mHotseat != null) {
909 mHotseat.setup(this);
910 }
911
Winson Chung4c98d922011-05-31 16:50:48 -0700912 // Setup the workspace
913 mWorkspace.setHapticFeedbackEnabled(false);
914 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700915 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700916 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700917
Winson Chungf0ea4d32011-06-06 14:27:16 -0700918 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700919 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700920
Winson Chungf0ea4d32011-06-06 14:27:16 -0700921 // Setup AppsCustomize
922 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
923 findViewById(R.id.apps_customize_pane);
924 mAppsCustomizeContent = (AppsCustomizePagedView)
925 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
Winson Chungc7450e32012-04-17 17:34:08 -0700926 mAppsCustomizeTabHost.setup(this);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700927 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400928
Michael Jurka5130e402011-10-13 04:55:35 -0700929 // Get the all apps button
930 mAllAppsButton = findViewById(R.id.all_apps_button);
931 if (mAllAppsButton != null) {
932 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
933 @Override
934 public boolean onTouch(View v, MotionEvent event) {
935 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
936 onTouchDownAllAppsButton(v);
937 }
938 return false;
939 }
940 });
941 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700942 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700943 dragController.setDragScoller(mWorkspace);
944 dragController.setScrollView(mDragLayer);
945 dragController.setMoveTarget(mWorkspace);
946 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700947 if (mSearchDropTargetBar != null) {
948 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800949 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800950 }
951
952 /**
953 * Creates a view representing a shortcut.
954 *
955 * @param info The data structure describing the shortcut.
956 *
957 * @return A View inflated from R.layout.application.
958 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800959 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800960 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700961 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800962 }
963
964 /**
965 * Creates a view representing a shortcut inflated from the specified resource.
966 *
967 * @param layoutResId The id of the XML layout used to create the shortcut.
968 * @param parent The group the shortcut belongs to.
969 * @param info The data structure describing the shortcut.
970 *
971 * @return A View inflated from layoutResId.
972 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800973 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800974 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
975 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800976 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800977 return favorite;
978 }
979
980 /**
981 * Add an application shortcut to the workspace.
982 *
983 * @param data The intent describing the application.
984 * @param cellInfo The position on screen where to create the shortcut.
985 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700986 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700987 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700988 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700989
Adam Cohenfbba09b2011-07-18 21:43:05 -0700990 // First we check if we already know the exact location where we want to add this item.
991 if (cellX >= 0 && cellY >= 0) {
992 cellXY[0] = cellX;
993 cellXY[1] = cellY;
994 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -0700995 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -0700996 return;
997 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800998
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800999 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001000
Romain Guy73b979d2009-06-09 12:57:21 -07001001 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001002 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001003 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001004 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -07001005 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001006 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001007 } else {
1008 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001009 }
1010 }
Romain Guycbb89e42009-06-08 15:52:54 -07001011
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001012 /**
1013 * Add a shortcut to the workspace.
1014 *
1015 * @param data The intent describing the shortcut.
1016 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001017 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001018 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
1019 int cellY) {
1020 int[] cellXY = mTmpAddItemCellCoordinates;
1021 int[] touchXY = mPendingAddInfo.dropPos;
1022 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001023
Michael Jurkad3ef3062010-11-23 16:23:58 -08001024 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001025
Adam Cohen558baaf2011-08-15 15:22:57 -07001026 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001027 if (info == null) {
1028 return;
1029 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001030 final View view = createShortcut(info);
1031
Adam Cohenfbba09b2011-07-18 21:43:05 -07001032 // First we check if we already know the exact location where we want to add this item.
1033 if (cellX >= 0 && cellY >= 0) {
1034 cellXY[0] = cellX;
1035 cellXY[1] = cellY;
1036 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001037
1038 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001039 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001040 true, null,null)) {
1041 return;
1042 }
1043 DragObject dragObject = new DragObject();
1044 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001045 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1046 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001047 return;
1048 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001049 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001050 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001051 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001052 foundCellSpan = (result != null);
1053 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001054 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001055 }
1056
1057 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001058 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001059 return;
1060 }
1061
Adam Cohen558baaf2011-08-15 15:22:57 -07001062 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001063
1064 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001065 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
1066 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001067 }
1068 }
1069
Adam Cohen2f093b62012-04-30 18:59:53 -07001070 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1071 int minHeight) {
1072 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001073 // We want to account for the extra amount of padding that we are adding to the widget
1074 // to ensure that it gets the full amount of space that it has requested
1075 int requiredWidth = minWidth + padding.left + padding.right;
1076 int requiredHeight = minHeight + padding.top + padding.bottom;
Adam Cohen2f093b62012-04-30 18:59:53 -07001077 return CellLayout.rectToCell(context.getResources(), requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001078 }
1079
Adam Cohen2f093b62012-04-30 18:59:53 -07001080 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1081 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001082 }
1083
Adam Cohen2f093b62012-04-30 18:59:53 -07001084 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1085 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001086 }
1087
Adam Cohen2f093b62012-04-30 18:59:53 -07001088 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1089 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001090 }
1091
Adam Cohen2f093b62012-04-30 18:59:53 -07001092 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1093 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001094 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001095 }
1096
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001097 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001098 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001099 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001100 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001101 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001102 */
Adam Cohened66b2b2012-01-23 17:28:51 -08001103 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
1104 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1105 if (appWidgetInfo == null) {
1106 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1107 }
Romain Guycbb89e42009-06-08 15:52:54 -07001108
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001109 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -07001110 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -07001111
Adam Cohen2f093b62012-04-30 18:59:53 -07001112 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1113 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001114
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001115 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001116 // We have saved the position to which the widget was dragged-- this really only matters
1117 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001118 int[] cellXY = mTmpAddItemCellCoordinates;
1119 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001120 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001121 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001122 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1123 cellXY[0] = mPendingAddInfo.cellX;
1124 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001125 spanXY[0] = mPendingAddInfo.spanX;
1126 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001127 foundCellSpan = true;
1128 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001129 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001130 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001131 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1132 spanXY[1], cellXY, finalSpan);
1133 spanXY[0] = finalSpan[0];
1134 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001135 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001136 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001137 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001138 }
1139
Michael Jurka0280c3b2010-09-17 15:00:07 -07001140 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001141 if (appWidgetId != -1) {
1142 // Deleting an app widget ID is a void call but writes to disk before returning
1143 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001144 new Thread("deleteAppWidgetId") {
1145 public void run() {
1146 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1147 }
1148 }.start();
1149 }
Winson Chung93eef082012-03-23 15:59:27 -07001150 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001151 return;
1152 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001153
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001154 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001155 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1156 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001157 launcherInfo.spanX = spanXY[0];
1158 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001159 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1160 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001161
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001162 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001163 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001164
1165 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001166 if (hostView == null) {
1167 // Perform actual inflation because we're live
1168 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1169 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1170 } else {
1171 // The AppWidgetHostView has already been inflated and instantiated
1172 launcherInfo.hostView = hostView;
1173 }
Romain Guycbb89e42009-06-08 15:52:54 -07001174
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001175 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001176 launcherInfo.hostView.setVisibility(View.VISIBLE);
Winson Chung211bac32012-05-15 13:43:57 -07001177 launcherInfo.notifyWidgetSizeChanged(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001178 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001179 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001180
1181 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001182 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001183 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001184 }
Romain Guycbb89e42009-06-08 15:52:54 -07001185
Adam Cohended9f8d2010-11-03 13:25:16 -07001186 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1187 @Override
1188 public void onReceive(Context context, Intent intent) {
1189 final String action = intent.getAction();
1190 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1191 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001192 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001193 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001194
Winson Chungc100e8e2011-08-09 16:02:43 -07001195 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001196 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001197 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1198 mAppsCustomizeTabHost.reset();
1199 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001200 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001201 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1202 mUserPresent = true;
1203 updateRunning();
1204 }
1205 }
1206 };
1207
1208 @Override
1209 public void onAttachedToWindow() {
1210 super.onAttachedToWindow();
1211
1212 // Listen for broadcasts related to user-presence
1213 final IntentFilter filter = new IntentFilter();
1214 filter.addAction(Intent.ACTION_SCREEN_OFF);
1215 filter.addAction(Intent.ACTION_USER_PRESENT);
1216 registerReceiver(mReceiver, filter);
1217
Adam Cohend113e0c2010-11-11 10:48:05 -08001218 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001219 mVisible = true;
1220 }
1221
1222 @Override
1223 public void onDetachedFromWindow() {
1224 super.onDetachedFromWindow();
1225 mVisible = false;
1226
Adam Cohend113e0c2010-11-11 10:48:05 -08001227 if (mAttached) {
1228 unregisterReceiver(mReceiver);
1229 mAttached = false;
1230 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001231 updateRunning();
1232 }
1233
1234 public void onWindowVisibilityChanged(int visibility) {
1235 mVisible = visibility == View.VISIBLE;
1236 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001237 // The following code used to be in onResume, but it turns out onResume is called when
1238 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1239 // is a more appropriate event to handle
1240 if (mVisible) {
1241 mAppsCustomizeTabHost.onWindowVisible();
1242 if (!mWorkspaceLoading) {
1243 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001244 // We want to let Launcher draw itself at least once before we force it to build
1245 // layers on all the workspace pages, so that transitioning to Launcher from other
1246 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
1247 // a true draw so we wait until the second preDraw call to be safe
1248 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001249 public boolean onPreDraw() {
Michael Jurka6ee21d22012-02-21 18:20:27 -08001250 // We delay the layer building a bit in order to give
1251 // other message processing a time to run. In particular
1252 // this avoids a delay in hiding the IME if it was
1253 // currently shown, because doing that may involve
1254 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001255 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Winson Chung31ce0732012-05-06 13:36:43 -07001256
1257 // We had to enable the wallpaper visibility when launching apps from all
1258 // apps (so that the transitions would be the same as when launching from
1259 // workspace) so take this time to see if we need to re-disable the
1260 // wallpaper visibility to ensure performance.
1261 mWorkspace.post(new Runnable() {
1262 @Override
1263 public void run() {
Winson Chung18f41f82012-05-09 13:28:10 -07001264 disableWallpaperIfInAllApps();
Winson Chung31ce0732012-05-06 13:36:43 -07001265 }
1266 });
1267
Michael Jurka6ee21d22012-02-21 18:20:27 -08001268 observer.removeOnPreDrawListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001269 return true;
1270 }
1271 });
1272 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001273 // When Launcher comes back to foreground, a different Activity might be responsible for
1274 // the app market intent, so refresh the icon
1275 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001276 clearTypedText();
1277 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001278 }
1279
1280 private void sendAdvanceMessage(long delay) {
1281 mHandler.removeMessages(ADVANCE_MSG);
1282 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1283 mHandler.sendMessageDelayed(msg, delay);
1284 mAutoAdvanceSentTime = System.currentTimeMillis();
1285 }
1286
1287 private void updateRunning() {
1288 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1289 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1290 mAutoAdvanceRunning = autoAdvanceRunning;
1291 if (autoAdvanceRunning) {
1292 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1293 sendAdvanceMessage(delay);
1294 } else {
1295 if (!mWidgetsToAdvance.isEmpty()) {
1296 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1297 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1298 }
1299 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001300 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001301 }
1302 }
1303 }
1304
1305 private final Handler mHandler = new Handler() {
1306 @Override
1307 public void handleMessage(Message msg) {
1308 if (msg.what == ADVANCE_MSG) {
1309 int i = 0;
1310 for (View key: mWidgetsToAdvance.keySet()) {
1311 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1312 final int delay = mAdvanceStagger * i;
1313 if (v instanceof Advanceable) {
1314 postDelayed(new Runnable() {
1315 public void run() {
1316 ((Advanceable) v).advance();
1317 }
1318 }, delay);
1319 }
1320 i++;
1321 }
1322 sendAdvanceMessage(mAdvanceInterval);
1323 }
1324 }
1325 };
1326
1327 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001328 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001329 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1330 if (v instanceof Advanceable) {
1331 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001332 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001333 updateRunning();
1334 }
1335 }
1336
1337 void removeWidgetToAutoAdvance(View hostView) {
1338 if (mWidgetsToAdvance.containsKey(hostView)) {
1339 mWidgetsToAdvance.remove(hostView);
1340 updateRunning();
1341 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001342 }
1343
Joe Onorato9c1289c2009-08-17 11:03:03 -04001344 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001345 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001346 launcherInfo.hostView = null;
1347 }
1348
Winson Chung93eef082012-03-23 15:59:27 -07001349 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1350 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1351 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001352 }
1353
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001354 public LauncherAppWidgetHost getAppWidgetHost() {
1355 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001356 }
Romain Guycbb89e42009-06-08 15:52:54 -07001357
Winson Chunga9abd0e2010-10-27 17:18:37 -07001358 public LauncherModel getModel() {
1359 return mModel;
1360 }
1361
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001362 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001363 getWindow().closeAllPanels();
1364
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001365 // Whatever we were doing is hereby canceled.
1366 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001367 }
1368
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001369 @Override
1370 protected void onNewIntent(Intent intent) {
1371 super.onNewIntent(intent);
1372
1373 // Close the menu
1374 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001375 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001376 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001377
Joe Onorato14f122b2009-11-19 14:06:36 -08001378 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1379 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001380
Adam Cohenac56cff2011-09-28 20:45:37 -07001381 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001382 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001383 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001384 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1385 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001386 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001387 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001388
1389 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001390 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001391 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001392
Joe Onorato3a8820b2009-11-10 15:06:42 -08001393 final View v = getWindow().peekDecorView();
1394 if (v != null && v.getWindowToken() != null) {
1395 InputMethodManager imm = (InputMethodManager)getSystemService(
1396 INPUT_METHOD_SERVICE);
1397 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001398 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001399
Michael Jurka35aa14d2011-07-07 17:01:08 -07001400 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001401 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001402 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001403 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001404 }
1405 }
1406
1407 @Override
1408 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1409 // Do not call super here
1410 mSavedInstanceState = savedInstanceState;
1411 }
1412
1413 @Override
1414 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001415 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001416 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001417
Michael Jurka883f55b2010-10-21 15:47:14 -07001418 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001419 // We close any open folder since it will not be re-opened, and we need to make sure
1420 // this state is reflected.
1421 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001422
Winson Chung3d503fb2011-07-13 17:25:49 -07001423 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1424 mWaitingForResult) {
1425 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1426 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1427 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1428 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001429 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1430 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1431 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001432 }
1433
1434 if (mFolderInfo != null && mWaitingForResult) {
1435 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1436 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1437 }
Michael Jurka946ad472010-07-09 18:05:18 -07001438
Winson Chung785d2eb2011-04-14 16:08:02 -07001439 // Save the current AppsCustomize tab
1440 if (mAppsCustomizeTabHost != null) {
1441 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1442 if (currentTabTag != null) {
1443 outState.putString("apps_customize_currentTab", currentTabTag);
1444 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001445 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1446 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001447 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001448 }
1449
1450 @Override
1451 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001452 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001453
Winson Chunge7a03942011-08-05 15:05:12 -07001454 // Remove all pending runnables
1455 mHandler.removeMessages(ADVANCE_MSG);
1456 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001457 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001458
Winson Chungcd2b0142011-06-08 16:02:26 -07001459 // Stop callbacks from LauncherModel
1460 LauncherApplication app = ((LauncherApplication) getApplication());
1461 mModel.stopLoader();
1462 app.setLauncher(null);
1463
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001464 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001465 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001466 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001467 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001468 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001469 mAppWidgetHost = null;
1470
1471 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001472
1473 TextKeyListener.getInstance().release();
1474
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001475
Winson Chung3d503fb2011-07-13 17:25:49 -07001476 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001477
1478 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001479 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001480
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001481 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001482 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1483 mWorkspace.removeAllViews();
1484 mWorkspace = null;
1485 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001486
1487 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001488 }
1489
Adam Cohena9cf38f2011-05-02 15:36:58 -07001490 public DragController getDragController() {
1491 return mDragController;
1492 }
1493
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001494 @Override
1495 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001496 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001497 super.startActivityForResult(intent, requestCode);
1498 }
1499
Winson Chung70d72102011-08-12 11:24:35 -07001500 /**
1501 * Indicates that we want global search for this activity by setting the globalSearch
1502 * argument for {@link #startSearch} to true.
1503 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001504 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001505 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001506 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001507
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001508 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001509
Karl Rosaen138a0412009-04-23 19:00:21 -07001510 if (initialQuery == null) {
1511 // Use any text typed in the launcher as the initial query
1512 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001513 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001514 if (appSearchData == null) {
1515 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001516 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001517 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001518 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001519
Karl Rosaen138a0412009-04-23 19:00:21 -07001520 final SearchManager searchManager =
1521 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001522 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001523 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001524 }
1525
Winson Chung70d72102011-08-12 11:24:35 -07001526 @Override
1527 public boolean onCreateOptionsMenu(Menu menu) {
1528 if (isWorkspaceLocked()) {
1529 return false;
1530 }
1531
1532 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001533
1534 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1535 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1536 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001537 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1538 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1539 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001540 String helpUrl = getString(R.string.help_url);
1541 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001542 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1543 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1544
Winson Chung70d72102011-08-12 11:24:35 -07001545 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1546 .setIcon(android.R.drawable.ic_menu_gallery)
1547 .setAlphabeticShortcut('W');
1548 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1549 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001550 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001551 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001552 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1553 .setIcon(android.R.drawable.ic_menu_preferences)
1554 .setIntent(settings)
1555 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001556 if (!helpUrl.isEmpty()) {
1557 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1558 .setIcon(android.R.drawable.ic_menu_help)
1559 .setIntent(help)
1560 .setAlphabeticShortcut('H');
1561 }
Winson Chung70d72102011-08-12 11:24:35 -07001562 return true;
1563 }
1564
1565 @Override
1566 public boolean onPrepareOptionsMenu(Menu menu) {
1567 super.onPrepareOptionsMenu(menu);
1568
1569 if (mAppsCustomizeTabHost.isTransitioning()) {
1570 return false;
1571 }
1572 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1573 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1574
1575 return true;
1576 }
1577
1578 @Override
1579 public boolean onOptionsItemSelected(MenuItem item) {
1580 switch (item.getItemId()) {
1581 case MENU_WALLPAPER_SETTINGS:
1582 startWallpaper();
1583 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001584 }
1585
1586 return super.onOptionsItemSelected(item);
1587 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001588
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001589 @Override
1590 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001591 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001592 // Use a custom animation for launching search
1593 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001594 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001595 }
1596
Joe Onorato9c1289c2009-08-17 11:03:03 -04001597 public boolean isWorkspaceLocked() {
1598 return mWorkspaceLoading || mWaitingForResult;
1599 }
1600
Michael Jurka0280c3b2010-09-17 15:00:07 -07001601 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001602 mPendingAddInfo.container = ItemInfo.NO_ID;
1603 mPendingAddInfo.screen = -1;
1604 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1605 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001606 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001607 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001608 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001609
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001610 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1611 AppWidgetProviderInfo appWidgetInfo) {
1612 if (appWidgetInfo.configure != null) {
1613 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001614
Bjorn Bringert7984c942009-12-09 15:38:25 +00001615 // Launch over to configure widget, if needed
1616 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001617 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001618 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Romain Guy8e633c52010-03-04 12:51:36 -08001619 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001620 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001621 // Otherwise just add it
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001622 completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget,
1623 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001624 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001625 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001626 }
1627 }
Romain Guycbb89e42009-06-08 15:52:54 -07001628
Adam Cohenfbba09b2011-07-18 21:43:05 -07001629 /**
1630 * Process a shortcut drop.
1631 *
1632 * @param componentName The name of the component
1633 * @param screen The screen where it should be added
1634 * @param cell The cell it should be added to, optional
1635 * @param position The location on the screen where it was dropped, optional
1636 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001637 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1638 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001639 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001640 mPendingAddInfo.container = container;
1641 mPendingAddInfo.screen = screen;
1642 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001643
1644 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001645 mPendingAddInfo.cellX = cell[0];
1646 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001647 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001648
1649 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1650 createShortcutIntent.setComponent(componentName);
1651 processShortcut(createShortcutIntent);
1652 }
1653
Adam Cohenfbba09b2011-07-18 21:43:05 -07001654 /**
1655 * Process a widget drop.
1656 *
1657 * @param info The PendingAppWidgetInfo of the widget being added.
1658 * @param screen The screen where it should be added
1659 * @param cell The cell it should be added to, optional
1660 * @param position The location on the screen where it was dropped, optional
1661 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001662 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
Adam Cohend41fbf52012-02-16 23:53:59 -08001663 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001664 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001665 mPendingAddInfo.container = info.container = container;
1666 mPendingAddInfo.screen = info.screen = screen;
1667 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001668 mPendingAddInfo.minSpanX = info.minSpanX;
1669 mPendingAddInfo.minSpanY = info.minSpanY;
1670
Adam Cohenfbba09b2011-07-18 21:43:05 -07001671 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001672 mPendingAddInfo.cellX = cell[0];
1673 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001674 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001675 if (span != null) {
1676 mPendingAddInfo.spanX = span[0];
1677 mPendingAddInfo.spanY = span[1];
1678 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001679
Adam Cohened66b2b2012-01-23 17:28:51 -08001680 AppWidgetHostView hostView = info.boundWidget;
1681 int appWidgetId;
1682 if (hostView != null) {
1683 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001684 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001685 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001686 // In this case, we either need to start an activity to get permission to bind
1687 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001688 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Michael Jurka8b805b12012-04-18 14:23:14 -07001689 if (mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName)) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001690 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001691 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001692 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001693 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1694 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1695 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
1696 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1697 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001698 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001699 }
1700
Joe Onoratodeb98af2010-02-19 14:59:39 -08001701 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001702 // Handle case where user selected "Applications"
1703 String applicationName = getResources().getString(R.string.group_applications);
1704 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001705
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001706 if (applicationName != null && applicationName.equals(shortcutName)) {
1707 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1708 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001709
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001710 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1711 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001712 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001713 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001714 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001715 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001716 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717 }
1718
Winson Chung24ab2f12010-09-16 14:10:47 -07001719 void processWallpaper(Intent intent) {
1720 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1721 }
1722
Winson Chung3d503fb2011-07-13 17:25:49 -07001723 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1724 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001725 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001726 folderInfo.title = getText(R.string.folder_name);
1727
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001728 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001729 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1730 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001731 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001732
1733 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001734 FolderIcon newFolder =
1735 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1736 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1737 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001738 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001739 }
Romain Guycbb89e42009-06-08 15:52:54 -07001740
Joe Onorato9c1289c2009-08-17 11:03:03 -04001741 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001742 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001743 }
1744
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001745 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001746 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001747 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001748 Intent chooser = Intent.createChooser(pickWallpaper,
1749 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001750 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1751 // Removed in Eclair MR1
1752// WallpaperManager wm = (WallpaperManager)
1753// getSystemService(Context.WALLPAPER_SERVICE);
1754// WallpaperInfo wi = wm.getWallpaperInfo();
1755// if (wi != null && wi.getSettingsActivity() != null) {
1756// LabeledIntent li = new LabeledIntent(getPackageName(),
1757// R.string.configure_wallpaper, 0);
1758// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1759// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1760// }
Mike Clerona0618e42009-10-22 13:55:21 -07001761 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001762 }
1763
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001764 /**
1765 * Registers various content observers. The current implementation registers
1766 * only a favorites observer to keep track of the favorites applications.
1767 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001768 private void registerContentObservers() {
1769 ContentResolver resolver = getContentResolver();
1770 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1771 true, mWidgetObserver);
1772 }
1773
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001774 @Override
1775 public boolean dispatchKeyEvent(KeyEvent event) {
1776 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1777 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001778 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001779 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001780 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001781 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001782 dumpState();
1783 return true;
1784 }
1785 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001786 }
1787 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1788 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001789 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001790 return true;
1791 }
1792 }
1793
1794 return super.dispatchKeyEvent(event);
1795 }
1796
Joe Onorato88ec0992009-11-19 13:16:06 -08001797 @Override
1798 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001799 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001800 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001801 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001802 Folder openFolder = mWorkspace.getOpenFolder();
1803 if (openFolder.isEditingName()) {
1804 openFolder.dismissEditingName();
1805 } else {
1806 closeFolder();
1807 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001808 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001809 mWorkspace.exitWidgetResizeMode();
1810
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001811 // Back button is a no-op here, but give at least some feedback for the button press
1812 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001813 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001814 }
1815
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001816 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001817 * Re-listen when widgets are reset.
1818 */
1819 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001820 if (mAppWidgetHost != null) {
1821 mAppWidgetHost.startListening();
1822 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001823 }
1824
1825 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001826 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1827 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001828 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001829 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001830 if (mModel != null) {
1831 mModel.unbindWorkspaceItems();
1832 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001833 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001834
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001835 /**
1836 * Launches the intent referred by the clicked shortcut.
1837 *
1838 * @param v The view representing the clicked shortcut.
1839 */
1840 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001841 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1842 // view has detached (it's possible for this to happen if the view is removed mid touch).
1843 if (v.getWindowToken() == null) {
1844 return;
1845 }
1846
Winson Chung9b0b2fe2012-02-24 13:03:34 -08001847 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001848 return;
1849 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001850
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001851 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001852 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001853 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001854 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001855 int[] pos = new int[2];
1856 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001857 intent.setSourceBounds(new Rect(pos[0], pos[1],
1858 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07001859
1860 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001861
1862 if (success && v instanceof BubbleTextView) {
1863 mWaitingForResume = (BubbleTextView) v;
1864 mWaitingForResume.setStayPressed(true);
1865 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001866 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001867 if (v instanceof FolderIcon) {
1868 FolderIcon fi = (FolderIcon) v;
1869 handleFolderClick(fi);
1870 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001871 } else if (v == mAllAppsButton) {
1872 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001873 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001874 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001875 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001876 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001877 }
1878 }
1879
Michael Jurka0e260592010-06-30 17:07:39 -07001880 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001881 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001882 // clicking anywhere on the workspace causes the customization drawer to slide down
1883 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001884 return false;
1885 }
1886
Michael Jurkaaf442092010-06-10 17:01:57 -07001887 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001888 * Event handler for the search button
1889 *
1890 * @param v The view that was clicked.
1891 */
1892 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001893 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1894
Amith Yamasania135ba82011-08-09 17:42:01 -07001895 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001896 }
1897
1898 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001899 * Event handler for the voice button
1900 *
1901 * @param v The view that was clicked.
1902 */
1903 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001904 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001905
Michael Jurkaae65ee32012-04-30 11:45:54 -07001906 try {
1907 final SearchManager searchManager =
1908 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1909 ComponentName activityName = searchManager.getGlobalSearchActivity();
1910 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
1911 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1912 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1913 if (activityName != null) {
1914 intent.setPackage(activityName.getPackageName());
1915 }
Michael Jurka86a720e2012-05-09 11:23:23 -07001916 startActivity(null, intent, "onClickVoiceButton");
Winson Chung01b0b632012-05-22 10:18:14 -07001917 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001918 } catch (ActivityNotFoundException e) {
1919 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
1920 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1921 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1922 startActivitySafely(null, intent, "onClickVoiceButton");
1923 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001924 }
1925
1926 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001927 * Event handler for the "grid" button that appears on the home screen, which
1928 * enters all apps mode.
1929 *
1930 * @param v The view that was clicked.
1931 */
1932 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001933 showAllApps(true);
1934 }
1935
1936 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001937 // Provide the same haptic feedback that the system offers for virtual keys.
1938 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001939 }
1940
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001941 public void onClickAppMarketButton(View v) {
1942 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07001943 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07001944 } else {
1945 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001946 }
1947 }
1948
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001949 void startApplicationDetailsActivity(ComponentName componentName) {
1950 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001951 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1952 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001953 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07001954 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001955 }
1956
Patrick Dubroy5539af72010-09-07 15:22:01 -07001957 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1958 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1959 // System applications cannot be installed. For now, show a toast explaining that.
1960 // We may give them the option of disabling apps this way.
1961 int messageId = R.string.uninstall_system_app_text;
1962 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1963 } else {
1964 String packageName = appInfo.componentName.getPackageName();
1965 String className = appInfo.componentName.getClassName();
1966 Intent intent = new Intent(
1967 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001968 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1969 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001970 startActivity(intent);
1971 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001972 }
1973
Michael Jurka86a720e2012-05-09 11:23:23 -07001974 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001975 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07001976
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001977 try {
Winson Chung2672ff92012-05-04 16:22:30 -07001978 // Only launch using the new animation if the shortcut has not opted out (this is a
1979 // private contract between launcher and may be ignored in the future).
1980 boolean useLaunchAnimation = (v != null) &&
1981 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
1982 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07001983 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
1984 v.getMeasuredWidth(), v.getMeasuredHeight());
1985
1986 startActivity(intent, opts.toBundle());
1987 } else {
1988 startActivity(intent);
1989 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001990 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001991 } catch (SecurityException e) {
1992 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001993 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001994 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001995 "or use the exported attribute for this activity. "
1996 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001997 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001998 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001999 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002000
Michael Jurka86a720e2012-05-09 11:23:23 -07002001 boolean startActivitySafely(View v, Intent intent, Object tag) {
2002 boolean success = false;
2003 try {
2004 success = startActivity(v, intent, tag);
2005 } catch (ActivityNotFoundException e) {
2006 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2007 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2008 }
2009 return success;
2010 }
2011
Romain Guy8e633c52010-03-04 12:51:36 -08002012 void startActivityForResultSafely(Intent intent, int requestCode) {
2013 try {
2014 startActivityForResult(intent, requestCode);
2015 } catch (ActivityNotFoundException e) {
2016 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2017 } catch (SecurityException e) {
2018 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2019 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2020 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2021 "or use the exported attribute for this activity.", e);
2022 }
2023 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002024
Adam Cohena9cf38f2011-05-02 15:36:58 -07002025 private void handleFolderClick(FolderIcon folderIcon) {
2026 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07002027 Folder openFolder = mWorkspace.getFolderForTag(info);
2028
2029 // If the folder info reports that the associated folder is open, then verify that
2030 // it is actually opened. There have been a few instances where this gets out of sync.
2031 if (info.opened && openFolder == null) {
2032 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2033 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
2034 info.opened = false;
2035 }
2036
Adam Cohena9cf38f2011-05-02 15:36:58 -07002037 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002038 // Close any open folder
2039 closeFolder();
2040 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002041 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002042 } else {
2043 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002044 int folderScreen;
2045 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002046 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002047 // .. and close it
2048 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002049 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002050 // Close any folder open on the current screen
2051 closeFolder();
2052 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002053 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002054 }
2055 }
2056 }
2057 }
2058
Adam Cohen2801caf2011-05-13 20:57:39 -07002059 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002060 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002061 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2062 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2063 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2064
Adam Cohenc51934b2011-07-26 21:07:43 -07002065 FolderInfo info = (FolderInfo) fi.getTag();
2066 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2067 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002068 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2069 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002070 }
2071
Adam Cohen2801caf2011-05-13 20:57:39 -07002072 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
2073 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2074 oa.start();
2075 }
2076
2077 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002078 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002079 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2080 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2081 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2082
Adam Cohenc51934b2011-07-26 21:07:43 -07002083 FolderInfo info = (FolderInfo) fi.getTag();
2084 CellLayout cl = null;
2085 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2086 cl = (CellLayout) fi.getParent().getParent();
2087 }
2088
2089 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07002090 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
2091 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002092 oa.addListener(new AnimatorListenerAdapter() {
2093 @Override
2094 public void onAnimationEnd(Animator animation) {
2095 if (layout != null) {
2096 layout.clearFolderLeaveBehind();
2097 }
2098 }
2099 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002100 oa.start();
2101 }
2102
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002103 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002104 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002105 * is animated relative to the specified View. If the View is null, no animation
2106 * is played.
2107 *
2108 * @param folderInfo The FolderInfo describing the folder to open.
2109 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002110 public void openFolder(FolderIcon folderIcon) {
2111 Folder folder = folderIcon.mFolder;
2112 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002113
Adam Cohen2801caf2011-05-13 20:57:39 -07002114 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002115 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002116
Adam Cohen4554ee12011-08-03 16:13:21 -07002117 // Just verify that the folder hasn't already been added to the DragLayer.
2118 // There was a one-off crash where the folder had a parent already.
2119 if (folder.getParent() == null) {
2120 mDragLayer.addView(folder);
2121 mDragController.addDropTarget((DropTarget) folder);
2122 } else {
2123 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2124 folder.getParent() + ").");
2125 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002126 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07002127 }
2128
2129 public void closeFolder() {
2130 Folder folder = mWorkspace.getOpenFolder();
2131 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002132 if (folder.isEditingName()) {
2133 folder.dismissEditingName();
2134 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002135 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002136
2137 // Dismiss the folder cling
2138 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002139 }
2140 }
2141
2142 void closeFolder(Folder folder) {
2143 folder.getInfo().opened = false;
2144
2145 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2146 if (parent != null) {
2147 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2148 shrinkAndFadeInFolderIcon(fi);
2149 }
2150 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002151 }
2152
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002153 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002154 if (!isDraggingEnabled()) return false;
2155 if (isWorkspaceLocked()) return false;
2156 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002157
2158 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002159 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002160 }
2161
Michael Jurka0280c3b2010-09-17 15:00:07 -07002162 resetAddInfo();
2163 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002164 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002165 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002166 return true;
2167 }
2168
Winson Chung3d503fb2011-07-13 17:25:49 -07002169 // The hotseat touch handling does not go through Workspace, and we always allow long press
2170 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002171 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002172 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2173 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002174 if (itemUnderLongClick == null) {
2175 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002176 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2177 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002178 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002179 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002180 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002181 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002182 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002183 }
2184 }
2185 }
2186 return true;
2187 }
2188
Winson Chung3d503fb2011-07-13 17:25:49 -07002189 boolean isHotseatLayout(View layout) {
2190 return mHotseat != null && layout != null &&
2191 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2192 }
2193 Hotseat getHotseat() {
2194 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002195 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002196 SearchDropTargetBar getSearchBar() {
2197 return mSearchDropTargetBar;
2198 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002199
Winson Chung3d503fb2011-07-13 17:25:49 -07002200 /**
2201 * Returns the CellLayout of the specified container at the specified screen.
2202 */
2203 CellLayout getCellLayout(long container, int screen) {
2204 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2205 if (mHotseat != null) {
2206 return mHotseat.getLayout();
2207 } else {
2208 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002209 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002210 } else {
2211 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002212 }
2213 }
2214
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002215 Workspace getWorkspace() {
2216 return mWorkspace;
2217 }
2218
Daniel Sandler843e8602010-06-07 14:59:01 -04002219 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2220 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002221 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002222 }
2223
Andrew Flynn0dca1ec2012-02-29 13:33:22 -08002224 public boolean isAllAppsButtonRank(int rank) {
2225 return mHotseat.isAllAppsButtonRank(rank);
2226 }
2227
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002228 // AllAppsView.Watcher
2229 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002230 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002231 mWorkspace.setVisibility(View.GONE);
2232 }
2233 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002234
2235 /**
2236 * Helper method for the cameraZoomIn/cameraZoomOut animations
2237 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002238 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002239 * @param scaleFactor The scale factor used for the zoom
2240 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002241 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002242 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002243 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002244 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002245
Winson Chung18f41f82012-05-09 13:28:10 -07002246 void disableWallpaperIfInAllApps() {
2247 // Only disable it if we are in all apps
2248 if (mState == State.APPS_CUSTOMIZE) {
2249 if (mAppsCustomizeTabHost != null &&
2250 !mAppsCustomizeTabHost.isTransitioning()) {
2251 updateWallpaperVisibility(false);
2252 }
2253 }
2254 }
2255
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002256 void updateWallpaperVisibility(boolean visible) {
2257 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2258 int curflags = getWindow().getAttributes().flags
2259 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2260 if (wpflags != curflags) {
2261 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2262 }
2263 }
2264
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002265 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2266 if (v instanceof LauncherTransitionable) {
2267 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2268 }
2269 }
2270
Michael Jurkabed61d22012-02-14 22:51:29 -08002271 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
Winson Chung7c7a22d2012-06-01 13:46:48 -07002272 if (toWorkspace) {
2273 Log.d(TAG, "6549598 Start animation to workspace");
2274 } else {
2275 Log.d(TAG, "6549598 Start animation to all apps");
2276 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002277 if (v instanceof LauncherTransitionable) {
2278 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2279 }
Winson Chung70442722012-02-10 15:43:22 -08002280
2281 // Update the workspace transition step as well
2282 dispatchOnLauncherTransitionStep(v, 0f);
2283 }
2284
2285 private void dispatchOnLauncherTransitionStep(View v, float t) {
2286 if (v instanceof LauncherTransitionable) {
2287 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2288 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002289 }
2290
2291 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
Winson Chung7c7a22d2012-06-01 13:46:48 -07002292 if (toWorkspace) {
2293 Log.d(TAG, "6549598 End animation to workspace");
2294 } else {
2295 Log.d(TAG, "6549598 End animation to all apps");
2296 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002297 if (v instanceof LauncherTransitionable) {
2298 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2299 }
Winson Chung70442722012-02-10 15:43:22 -08002300
2301 // Update the workspace transition step as well
2302 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002303 }
2304
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002305 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002306 * Things to test when changing the following seven functions.
2307 * - Home from workspace
2308 * - from center screen
2309 * - from other screens
2310 * - Home from all apps
2311 * - from center screen
2312 * - from other screens
2313 * - Back from all apps
2314 * - from center screen
2315 * - from other screens
2316 * - Launch app from workspace and quit
2317 * - with back
2318 * - with home
2319 * - Launch app from all apps and quit
2320 * - with back
2321 * - with home
2322 * - Go to a screen that's not the default, then all
2323 * apps, and launch and app, and go back
2324 * - with back
2325 * -with home
2326 * - On workspace, long press power and go back
2327 * - with back
2328 * - with home
2329 * - On all apps, long press power and go back
2330 * - with back
2331 * - with home
2332 * - On workspace, power off
2333 * - On all apps, power off
2334 * - Launch an app and turn off the screen while in that app
2335 * - Go back with home key
2336 * - Go back with back key TODO: make this not go to workspace
2337 * - From all apps
2338 * - From workspace
2339 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2340 * - From all apps
2341 * - From the center workspace
2342 * - From another workspace
2343 */
2344
2345 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002346 * Zoom the camera out from the workspace to reveal 'toView'.
2347 * Assumes that the view to show is anchored at either the very top or very bottom
2348 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002349 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002350 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002351 if (mStateAnimation != null) {
2352 mStateAnimation.cancel();
2353 mStateAnimation = null;
2354 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002355 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002356
Winson Chungf0ea4d32011-06-06 14:27:16 -07002357 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2358 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2359 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002360 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002361 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002362 final int startDelay =
2363 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002364
Michael Jurkab3e22d92011-10-31 15:58:33 -07002365 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002366
Michael Jurkad74c9842011-07-10 12:44:21 -07002367 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002368 Animator workspaceAnim =
2369 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002370
2371 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002372 toView.setScaleX(scale);
2373 toView.setScaleY(scale);
2374 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2375 scaleAnim.
2376 scaleX(1f).scaleY(1f).
2377 setDuration(duration).
2378 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002379
Winson Chungf0ea4d32011-06-06 14:27:16 -07002380 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002381 toView.setAlpha(0f);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002382 final ObjectAnimator alphaAnim = ObjectAnimator
2383 .ofFloat(toView, "alpha", 0f, 1f)
2384 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002385 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002386 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2387 @Override
2388 public void onAnimationUpdate(ValueAnimator animation) {
2389 float t = (Float) animation.getAnimatedValue();
2390 dispatchOnLauncherTransitionStep(fromView, t);
2391 dispatchOnLauncherTransitionStep(toView, t);
2392 }
2393 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002394
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002395 // toView should appear right at the end of the workspace shrink
2396 // animation
2397 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002398 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002399 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002400
2401 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002402 boolean animationCancelled = false;
2403
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002404 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002405 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002406 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002407 // Prepare the position
2408 toView.setTranslationX(0.0f);
2409 toView.setTranslationY(0.0f);
2410 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002411 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002412 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002413 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002414 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002415 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2416 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002417
2418 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2419 // Hide the workspace scrollbar
2420 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002421 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002422 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002423 if (!animationCancelled) {
2424 updateWallpaperVisibility(false);
2425 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002426
2427 // Hide the search bar
2428 mSearchDropTargetBar.hideSearchBar(false);
Adam Cohenf4ddea32011-09-12 13:46:42 -07002429 }
2430
Adam Cohencff6af82011-09-13 14:51:53 -07002431 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002432 public void onAnimationCancel(Animator animation) {
2433 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002434 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002435 });
2436
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002437 if (workspaceAnim != null) {
2438 mStateAnimation.play(workspaceAnim);
2439 }
Michael Jurka1899a362011-11-03 13:50:45 -07002440
2441 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002442 final ViewTreeObserver observer;
2443
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002444 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2445 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002446
2447 // If any of the objects being animated haven't been measured/laid out
2448 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002449 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002450 (mWorkspace.getMeasuredWidth() == 0) ||
2451 (toView.getMeasuredWidth() == 0)) {
2452 observer = mWorkspace.getViewTreeObserver();
2453 delayAnim = true;
2454 } else {
2455 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002456 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002457
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002458 final AnimatorSet stateAnimation = mStateAnimation;
2459 final Runnable startAnimRunnable = new Runnable() {
2460 public void run() {
2461 // Check that mStateAnimation hasn't changed while
2462 // we waited for a layout/draw pass
2463 if (mStateAnimation != stateAnimation)
2464 return;
2465 setPivotsForZoom(toView, scale);
2466 dispatchOnLauncherTransitionStart(fromView, animated, false);
2467 dispatchOnLauncherTransitionStart(toView, animated, false);
2468 mWorkspace.post(new Runnable() {
2469 public void run() {
2470 // Check that mStateAnimation hasn't changed while
2471 // we waited for a layout/draw pass
2472 if (mStateAnimation != stateAnimation)
2473 return;
2474 mStateAnimation.start();
2475 }
2476 });
2477 }
2478 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002479 if (delayAnim) {
2480 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2481 public void onGlobalLayout() {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002482 mWorkspace.post(startAnimRunnable);
Michael Jurka3a9fced2012-04-13 14:44:29 -07002483 observer.removeOnGlobalLayoutListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002484 }
2485 };
2486 observer.addOnGlobalLayoutListener(delayedStart);
2487 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002488 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002489 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002490 } else {
2491 toView.setTranslationX(0.0f);
2492 toView.setTranslationY(0.0f);
2493 toView.setScaleX(1.0f);
2494 toView.setScaleY(1.0f);
2495 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002496 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002497
Michael Jurkabed61d22012-02-14 22:51:29 -08002498 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2499 // Hide the workspace scrollbar
2500 mWorkspace.hideScrollingIndicator(true);
2501 hideDockDivider();
Winson Chungc7d2b602012-05-16 17:02:20 -07002502
2503 // Hide the search bar
2504 mSearchDropTargetBar.hideSearchBar(false);
Michael Jurkaabded662011-03-04 12:06:57 -08002505 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002506 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002507 dispatchOnLauncherTransitionStart(fromView, animated, false);
2508 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002509 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002510 dispatchOnLauncherTransitionStart(toView, animated, false);
2511 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002512 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002513 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002514 }
2515
2516 /**
2517 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002518 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002519 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002520 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002521 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2522 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002523
Michael Jurkab3e22d92011-10-31 15:58:33 -07002524 if (mStateAnimation != null) {
2525 mStateAnimation.cancel();
2526 mStateAnimation = null;
2527 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002528 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002529
Winson Chungf0ea4d32011-06-06 14:27:16 -07002530 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002531 final int fadeOutDuration =
2532 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002533 final float scaleFactor = (float)
2534 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2535 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002536 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002537 Animator workspaceAnim = null;
2538
2539 if (toState == State.WORKSPACE) {
2540 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2541 workspaceAnim = mWorkspace.getChangeStateAnimation(
2542 Workspace.State.NORMAL, animated, stagger);
2543 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2544 workspaceAnim = mWorkspace.getChangeStateAnimation(
2545 Workspace.State.SPRING_LOADED, animated);
2546 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002547
Michael Jurkab3e22d92011-10-31 15:58:33 -07002548 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002549 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002550 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002551 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002552 final LauncherViewPropertyAnimator scaleAnim =
2553 new LauncherViewPropertyAnimator(fromView);
2554 scaleAnim.
2555 scaleX(scaleFactor).scaleY(scaleFactor).
2556 setDuration(duration).
2557 setInterpolator(new Workspace.ZoomInInterpolator());
2558
2559 final ObjectAnimator alphaAnim = ObjectAnimator
2560 .ofFloat(fromView, "alpha", 1f, 0f)
2561 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002562 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002563 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2564 @Override
2565 public void onAnimationUpdate(ValueAnimator animation) {
2566 float t = 1f - (Float) animation.getAnimatedValue();
2567 dispatchOnLauncherTransitionStep(fromView, t);
2568 dispatchOnLauncherTransitionStep(toView, t);
2569 }
2570 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002571
Michael Jurkabed61d22012-02-14 22:51:29 -08002572 mStateAnimation = new AnimatorSet();
2573
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002574 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2575 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002576
2577 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002578 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002579 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002580 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002581 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002582 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2583 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkabafdaaf2012-04-26 13:43:25 -07002584 if (mWorkspace != null) {
2585 mWorkspace.hideScrollingIndicator(false);
2586 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002587 if (onCompleteRunnable != null) {
2588 onCompleteRunnable.run();
2589 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002590 }
2591 });
2592
Winson Chungf0ea4d32011-06-06 14:27:16 -07002593 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002594 if (workspaceAnim != null) {
2595 mStateAnimation.play(workspaceAnim);
2596 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002597 dispatchOnLauncherTransitionStart(fromView, animated, true);
2598 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002599 final Animator stateAnimation = mStateAnimation;
2600 mWorkspace.post(new Runnable() {
2601 public void run() {
2602 if (stateAnimation != mStateAnimation)
2603 return;
2604 mStateAnimation.start();
2605 }
2606 });
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002607 } else {
2608 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002609 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002610 dispatchOnLauncherTransitionStart(fromView, animated, true);
2611 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002612 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002613 dispatchOnLauncherTransitionStart(toView, animated, true);
2614 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002615 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002616 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002617 }
2618
Michael Jurkae326f182011-11-21 14:05:46 -08002619 @Override
2620 public void onTrimMemory(int level) {
2621 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002622 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002623 mAppsCustomizeTabHost.onTrimMemory();
2624 }
2625 }
2626
Winson Chung18f41f82012-05-09 13:28:10 -07002627 @Override
2628 public void onWindowFocusChanged(boolean hasFocus) {
2629 if (!hasFocus) {
2630 // When another window occludes launcher (like the notification shade, or recents),
2631 // ensure that we enable the wallpaper flag so that transitions are done correctly.
2632 updateWallpaperVisibility(true);
2633 } else {
2634 // When launcher has focus again, disable the wallpaper if we are in AllApps
2635 disableWallpaperIfInAllApps();
2636 }
2637 }
2638
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002639 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002640 showWorkspace(animated, null);
2641 }
2642
2643 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002644 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002645 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002646 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002647 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002648
Winson Chungc7d2b602012-05-16 17:02:20 -07002649 // Show the search bar (only animate if we were showing the drop target bar in spring
2650 // loaded mode)
2651 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
2652
Michael Jurkab737ee62011-11-15 15:57:22 -08002653 // We only need to animate in the dock divider if we're going from spring loaded mode
Winson Chungc7d2b602012-05-16 17:02:20 -07002654 showDockDivider(animated && wasInSpringLoadedMode);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002655
2656 // Set focus to the AppsCustomize button
2657 if (mAllAppsButton != null) {
2658 mAllAppsButton.requestFocus();
2659 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002660 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002661
Michael Jurkab737ee62011-11-15 15:57:22 -08002662 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002663
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002664 // Change the state *after* we've called all the transition code
2665 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002666
Winson Chung5fb63472011-02-02 17:03:37 -08002667 // Resume the auto-advance of widgets
2668 mUserPresent = true;
2669 updateRunning();
2670
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002671 // send an accessibility event to announce the context change
2672 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002673 }
2674
Michael Jurkab3e22d92011-10-31 15:58:33 -07002675 void showAllApps(boolean animated) {
2676 if (mState != State.WORKSPACE) return;
2677
2678 showAppsCustomizeHelper(animated, false);
2679 mAppsCustomizeTabHost.requestFocus();
2680
Michael Jurkab3e22d92011-10-31 15:58:33 -07002681 // Change the state *after* we've called all the transition code
2682 mState = State.APPS_CUSTOMIZE;
2683
2684 // Pause the auto-advance of widgets until we are out of AllApps
2685 mUserPresent = false;
2686 updateRunning();
2687 closeFolder();
2688
2689 // Send an accessibility event to announce the context change
2690 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2691 }
2692
Adam Cohen7777d962011-08-18 18:58:38 -07002693 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002694 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002695 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002696 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002697 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002698 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002699 }
Adam Cohen7777d962011-08-18 18:58:38 -07002700
Adam Cohened66b2b2012-01-23 17:28:51 -08002701 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2702 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002703 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2704
Winson Chunge7a03942011-08-05 15:05:12 -07002705 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002706 @Override
2707 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002708 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002709 // Before we show workspace, hide all apps again because
2710 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2711 // clean up our state transition functions
2712 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002713 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002714 } else {
2715 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002716 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002717 }
2718 }, (extendedDelay ?
2719 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2720 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2721 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002722
Michael Jurkad3ef3062010-11-23 16:23:58 -08002723 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002724 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002725 final boolean animated = true;
2726 final boolean springLoaded = true;
2727 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002728 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002729 }
2730 // Otherwise, we are not in spring loaded mode, so don't do anything.
2731 }
2732
Michael Jurkab737ee62011-11-15 15:57:22 -08002733 void hideDockDivider() {
2734 if (mQsbDivider != null && mDockDivider != null) {
2735 mQsbDivider.setVisibility(View.INVISIBLE);
2736 mDockDivider.setVisibility(View.INVISIBLE);
2737 }
2738 }
2739
2740 void showDockDivider(boolean animated) {
2741 if (mQsbDivider != null && mDockDivider != null) {
2742 mQsbDivider.setVisibility(View.VISIBLE);
2743 mDockDivider.setVisibility(View.VISIBLE);
2744 if (mDividerAnimator != null) {
2745 mDividerAnimator.cancel();
2746 mQsbDivider.setAlpha(1f);
2747 mDockDivider.setAlpha(1f);
2748 mDividerAnimator = null;
2749 }
2750 if (animated) {
2751 mDividerAnimator = new AnimatorSet();
2752 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2753 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2754 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2755 mDividerAnimator.start();
2756 }
2757 }
2758 }
2759
Michael Jurkab3e22d92011-10-31 15:58:33 -07002760 void lockAllApps() {
2761 // TODO
2762 }
2763
2764 void unlockAllApps() {
2765 // TODO
2766 }
2767
Adam Cohenfc53cd22011-07-20 15:45:11 -07002768 public boolean isAllAppsCustomizeOpen() {
2769 return mState == State.APPS_CUSTOMIZE;
2770 }
2771
Winson Chungf0ea4d32011-06-06 14:27:16 -07002772 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002773 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002774 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002775 void showHotseat(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() != 1f) {
2779 int duration = mSearchDropTargetBar.getTransitionInDuration();
2780 mHotseat.animate().alpha(1f).setDuration(duration);
2781 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002782 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002783 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002784 }
2785 }
2786 }
2787
2788 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002789 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002790 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002791 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002792 if (!LauncherApplication.isScreenLarge()) {
2793 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002794 if (mHotseat.getAlpha() != 0f) {
2795 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2796 mHotseat.animate().alpha(0f).setDuration(duration);
2797 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002798 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002799 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002800 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002801 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002802 }
2803
Patrick Dubroy5f445422011-02-18 14:35:21 -08002804 /**
2805 * Add an item from all apps or customize onto the given workspace screen.
2806 * If layout is null, add to the current screen.
2807 */
2808 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002809 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07002810 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07002811 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002812 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002813
Winson Chungdff8ebb2011-09-08 17:25:31 -07002814 /** Maps the current orientation to an index for referencing orientation correct global icons */
2815 private int getCurrentOrientationIndexForGlobalIcons() {
2816 // default - 0, landscape - 1
2817 switch (getResources().getConfiguration().orientation) {
2818 case Configuration.ORIENTATION_LANDSCAPE:
2819 return 1;
2820 default:
2821 return 0;
2822 }
2823 }
2824
Michael Jurkaae65ee32012-04-30 11:45:54 -07002825 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002826 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002827 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002828 // Look for the toolbar icon specified in the activity meta-data
2829 Bundle metaData = packageManager.getActivityInfo(
2830 activityName, PackageManager.GET_META_DATA).metaData;
2831 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002832 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002833 if (iconResId != 0) {
2834 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002835 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002836 }
2837 }
2838 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002839 // This can happen if the activity defines an invalid drawable
2840 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2841 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002842 } catch (Resources.NotFoundException nfe) {
2843 // This can happen if the activity defines an invalid drawable
2844 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2845 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002846 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002847 return null;
2848 }
2849
2850 // if successful in getting icon, return it; otherwise, set button to use default drawable
2851 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002852 int buttonId, ComponentName activityName, int fallbackDrawableId,
2853 String toolbarResourceName) {
2854 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002855 Resources r = getResources();
2856 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2857 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002858
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002859 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002860 // If we were unable to find the icon via the meta-data, use a generic one
2861 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002862 toolbarIcon = r.getDrawable(fallbackDrawableId);
2863 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002864 if (button != null) {
2865 button.setCompoundDrawables(toolbarIcon, null, null, null);
2866 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002867 return null;
2868 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002869 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002870 if (button != null) {
2871 button.setCompoundDrawables(toolbarIcon, null, null, null);
2872 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002873 return toolbarIcon.getConstantState();
2874 }
2875 }
2876
2877 // if successful in getting icon, return it; otherwise, set button to use default drawable
2878 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002879 int buttonId, ComponentName activityName, int fallbackDrawableId,
2880 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002881 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002882 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002883
Michael Jurka19e0fc52011-07-22 18:00:21 -07002884 if (button != null) {
2885 // If we were unable to find the icon via the meta-data, use a
2886 // generic one
2887 if (toolbarIcon == null) {
2888 button.setImageResource(fallbackDrawableId);
2889 } else {
2890 button.setImageDrawable(toolbarIcon);
2891 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002892 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002893
2894 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2895
Michael Jurka0423dcf2010-10-05 14:56:18 -07002896 }
2897
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002898 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2899 TextView button = (TextView) findViewById(buttonId);
2900 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2901 }
2902
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002903 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002904 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002905 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002906 }
2907
Winson Chungbb185bd2011-11-21 12:31:42 -08002908 private void invalidatePressedFocusedStates(View container, View button) {
2909 if (container instanceof HolographicLinearLayout) {
2910 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2911 layout.invalidatePressedFocusedStates();
2912 } else if (button instanceof HolographicImageView) {
2913 HolographicImageView view = (HolographicImageView) button;
2914 view.invalidatePressedFocusedStates();
2915 }
2916 }
2917
Winson Chungc51db6a2011-10-05 11:44:49 -07002918 private boolean updateGlobalSearchIcon() {
2919 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002920 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2921 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002922 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002923 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07002924 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07002925
Winson Chung1cad91e2011-05-25 17:41:01 -07002926 final SearchManager searchManager =
2927 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2928 ComponentName activityName = searchManager.getGlobalSearchActivity();
2929 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002930 int coi = getCurrentOrientationIndexForGlobalIcons();
2931 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002932 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2933 TOOLBAR_SEARCH_ICON_METADATA_NAME);
2934 if (sGlobalSearchIcon[coi] == null) {
2935 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
2936 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2937 TOOLBAR_ICON_METADATA_NAME);
2938 }
2939
Winson Chung649723c2011-07-06 20:41:23 -07002940 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002941 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2942 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002943 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002944 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002945 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002946 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002947 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002948 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2949 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2950 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002951 voiceButton.setVisibility(View.GONE);
Michael Jurkac60498a2012-05-07 15:29:42 -07002952 if (voiceButtonProxy != null) {
2953 voiceButtonProxy.setVisibility(View.GONE);
2954 }
Winson Chungc51db6a2011-10-05 11:44:49 -07002955 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002956 }
2957 }
2958
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002959 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002960 final View searchButtonContainer = findViewById(R.id.search_button_container);
2961 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002962 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002963 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002964 }
2965
Winson Chungc51db6a2011-10-05 11:44:49 -07002966 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002967 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002968 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002969 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07002970 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07002971
Winson Chungc51db6a2011-10-05 11:44:49 -07002972 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07002973 final SearchManager searchManager =
2974 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2975 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2976
2977 ComponentName activityName = null;
2978 if (globalSearchActivity != null) {
2979 // Check if the global search activity handles voice search
2980 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2981 intent.setPackage(globalSearchActivity.getPackageName());
2982 activityName = intent.resolveActivity(getPackageManager());
2983 }
2984
2985 if (activityName == null) {
2986 // Fallback: check if an activity other than the global search activity
2987 // resolves this
2988 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2989 activityName = intent.resolveActivity(getPackageManager());
2990 }
Winson Chungc51db6a2011-10-05 11:44:49 -07002991 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002992 int coi = getCurrentOrientationIndexForGlobalIcons();
2993 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002994 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
2995 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
2996 if (sVoiceSearchIcon[coi] == null) {
2997 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
2998 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
2999 TOOLBAR_ICON_METADATA_NAME);
3000 }
Winson Chung649723c2011-07-06 20:41:23 -07003001 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07003002 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003003 voiceButton.setVisibility(View.VISIBLE);
Jim Miller14091b12012-04-24 19:27:54 -07003004 if (voiceButtonProxy != null) {
3005 voiceButtonProxy.setVisibility(View.VISIBLE);
3006 }
Winson Chungbb185bd2011-11-21 12:31:42 -08003007 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003008 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003009 } else {
Winson Chung649723c2011-07-06 20:41:23 -07003010 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07003011 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003012 voiceButton.setVisibility(View.GONE);
Jim Miller14091b12012-04-24 19:27:54 -07003013 if (voiceButtonProxy != null) {
3014 voiceButtonProxy.setVisibility(View.GONE);
3015 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003016 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003017 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003018 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003019
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003020 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003021 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3022 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003023 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003024 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003025 }
3026
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003027 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003028 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003029 */
3030 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003031 final View marketButton = findViewById(R.id.market_button);
3032 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3033 // Find the app market activity by resolving an intent.
3034 // (If multiple app markets are installed, it will return the ResolverActivity.)
3035 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003036 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003037 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003038 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003039 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003040 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3041 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003042 marketButton.setVisibility(View.VISIBLE);
3043 } else {
3044 // We should hide and disable the view so that we don't try and restore the visibility
3045 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3046 marketButton.setVisibility(View.GONE);
3047 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003048 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003049 }
3050
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003051 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003052 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003053 }
3054
Michael Jurkad7c28052012-04-27 15:43:36 -07003055 @Override
3056 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
3057 boolean result = super.dispatchPopulateAccessibilityEvent(event);
3058 final List<CharSequence> text = event.getText();
3059 text.clear();
3060 text.add(getString(R.string.home));
3061 return result;
3062 }
3063
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003064 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003065 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003066 */
3067 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3068 @Override
3069 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003070 closeSystemDialogs();
3071 }
3072 }
3073
3074 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003075 * Receives notifications whenever the appwidgets are reset.
3076 */
3077 private class AppWidgetResetObserver extends ContentObserver {
3078 public AppWidgetResetObserver() {
3079 super(new Handler());
3080 }
3081
3082 @Override
3083 public void onChange(boolean selfChange) {
3084 onAppWidgetReset();
3085 }
3086 }
3087
3088 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003089 * If the activity is currently paused, signal that we need to re-run the loader
3090 * in onResume.
3091 *
3092 * This needs to be called from incoming places where resources might have been loaded
3093 * while we are paused. That is becaues the Configuration might be wrong
3094 * when we're not running, and if it comes back to what it was when we
3095 * were paused, we are not restarted.
3096 *
3097 * Implementation of the method from LauncherModel.Callbacks.
3098 *
3099 * @return true if we are currently paused. The caller might be able to
3100 * skip some work in that case since we will come back again.
3101 */
3102 public boolean setLoadOnResume() {
3103 if (mPaused) {
3104 Log.i(TAG, "setLoadOnResume");
3105 mOnResumeNeedsLoad = true;
3106 return true;
3107 } else {
3108 return false;
3109 }
3110 }
3111
3112 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003113 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003114 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003115 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003116 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003117 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003118 } else {
3119 return SCREEN_COUNT / 2;
3120 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003121 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003122
Joe Onorato9c1289c2009-08-17 11:03:03 -04003123 /**
3124 * Refreshes the shortcuts shown on the workspace.
3125 *
3126 * Implementation of the method from LauncherModel.Callbacks.
3127 */
3128 public void startBinding() {
3129 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07003130
Winson Chungf0c6ae02012-03-21 16:10:31 -07003131 mNewShortcutAnimatePage = -1;
3132 mNewShortcutAnimateViews.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003133 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003134 int count = workspace.getChildCount();
3135 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003136 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003137 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3138 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003139 }
Michael Jurka05bf6442011-11-30 20:28:53 -08003140 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003141 if (mHotseat != null) {
3142 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003143 }
3144 }
3145
3146 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003147 * Bind the items start-end from the list.
3148 *
3149 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003150 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003151 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003152 setLoadOnResume();
3153
Winson Chungf0c6ae02012-03-21 16:10:31 -07003154 // Get the list of added shortcuts and intersect them with the set of shortcuts here
3155 Set<String> newApps = new HashSet<String>();
3156 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);
3157
3158 Workspace workspace = mWorkspace;
3159 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003160 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003161
3162 // Short circuit if we are loading dock items for a configuration which has no dock
3163 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3164 mHotseat == null) {
3165 continue;
3166 }
3167
Joe Onorato9c1289c2009-08-17 11:03:03 -04003168 switch (item.itemType) {
3169 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3170 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003171 ShortcutInfo info = (ShortcutInfo) item;
3172 String uri = info.intent.toUri(0).toString();
3173 View shortcut = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -07003174 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3175 item.cellY, 1, 1, false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003176 if (newApps.contains(uri)) {
3177 newApps.remove(uri);
3178
3179 // Prepare the view to be animated up
3180 shortcut.setAlpha(0f);
3181 shortcut.setScaleX(0f);
3182 shortcut.setScaleY(0f);
3183 mNewShortcutAnimatePage = item.screen;
3184 if (!mNewShortcutAnimateViews.contains(shortcut)) {
3185 mNewShortcutAnimateViews.add(shortcut);
3186 }
3187 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003188 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003189 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003190 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003191 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003192 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003193 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3194 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003195 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003196 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003197 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003198
Joe Onorato9c1289c2009-08-17 11:03:03 -04003199 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003200 }
3201
Joe Onorato9c1289c2009-08-17 11:03:03 -04003202 /**
3203 * Implementation of the method from LauncherModel.Callbacks.
3204 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003205 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003206 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003207 sFolders.clear();
3208 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003209 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003210
3211 /**
3212 * Add the views for a widget to the workspace.
3213 *
3214 * Implementation of the method from LauncherModel.Callbacks.
3215 */
3216 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003217 setLoadOnResume();
3218
Daniel Sandler843e8602010-06-07 14:59:01 -04003219 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3220 if (DEBUG_WIDGETS) {
3221 Log.d(TAG, "bindAppWidget: " + item);
3222 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003223 final Workspace workspace = mWorkspace;
3224
3225 final int appWidgetId = item.appWidgetId;
3226 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003227 if (DEBUG_WIDGETS) {
3228 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3229 }
3230
Joe Onorato9c1289c2009-08-17 11:03:03 -04003231 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3232
Joe Onorato9c1289c2009-08-17 11:03:03 -04003233 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
3234 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003235 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003236
Winson Chung3d503fb2011-07-13 17:25:49 -07003237 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003238 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003239 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3240
Joe Onorato9c1289c2009-08-17 11:03:03 -04003241 workspace.requestLayout();
3242
Daniel Sandler843e8602010-06-07 14:59:01 -04003243 if (DEBUG_WIDGETS) {
3244 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3245 + (SystemClock.uptimeMillis()-start) + "ms");
3246 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003247 }
3248
3249 /**
3250 * Callback saying that there aren't any more items to bind.
3251 *
3252 * Implementation of the method from LauncherModel.Callbacks.
3253 */
3254 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003255 setLoadOnResume();
3256
Joe Onorato9c1289c2009-08-17 11:03:03 -04003257 if (mSavedState != null) {
3258 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003259 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003260 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003261 mSavedState = null;
3262 }
3263
3264 if (mSavedInstanceState != null) {
3265 super.onRestoreInstanceState(mSavedInstanceState);
3266 mSavedInstanceState = null;
3267 }
3268
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003269 // If we received the result of any pending adds while the loader was running (e.g. the
3270 // widget configuration forced an orientation change), process them now.
3271 for (int i = 0; i < sPendingAddList.size(); i++) {
3272 completeAdd(sPendingAddList.get(i));
3273 }
3274 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003275
Winson Chungc51db6a2011-10-05 11:44:49 -07003276 // Update the market app icon as necessary (the other icons will be managed in response to
3277 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003278 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003279
Winson Chungf0c6ae02012-03-21 16:10:31 -07003280 // Animate up any icons as necessary
3281 if (mVisible || mWorkspaceLoading) {
3282 Runnable newAppsRunnable = new Runnable() {
3283 @Override
3284 public void run() {
Winson Chunga2413752012-04-03 14:22:34 -07003285 runNewAppsAnimation(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003286 }
3287 };
Winson Chunga2413752012-04-03 14:22:34 -07003288
3289 boolean willSnapPage = mNewShortcutAnimatePage > -1 &&
3290 mNewShortcutAnimatePage != mWorkspace.getCurrentPage();
3291 if (canRunNewAppsAnimation()) {
3292 // If the user has not interacted recently, then either snap to the new page to show
3293 // the new-apps animation or just run them if they are to appear on the current page
3294 if (willSnapPage) {
3295 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable);
3296 } else {
3297 runNewAppsAnimation(false);
3298 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003299 } else {
Winson Chung318eee02012-04-12 10:59:27 -07003300 // If the user has interacted recently, then just add the items in place if they
Winson Chunga2413752012-04-03 14:22:34 -07003301 // are on another page (or just normally if they are added to the current page)
3302 runNewAppsAnimation(willSnapPage);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003303 }
3304 }
3305
3306 mWorkspaceLoading = false;
3307 }
3308
Winson Chunga2413752012-04-03 14:22:34 -07003309 private boolean canRunNewAppsAnimation() {
3310 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3311 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3312 }
3313
Winson Chungf0c6ae02012-03-21 16:10:31 -07003314 /**
3315 * Runs a new animation that scales up icons that were added while Launcher was in the
3316 * background.
Winson Chunga2413752012-04-03 14:22:34 -07003317 *
3318 * @param immediate whether to run the animation or show the results immediately
Winson Chungf0c6ae02012-03-21 16:10:31 -07003319 */
Winson Chunga2413752012-04-03 14:22:34 -07003320 private void runNewAppsAnimation(boolean immediate) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003321 AnimatorSet anim = new AnimatorSet();
3322 Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chunga2413752012-04-03 14:22:34 -07003323
3324 // Order these new views spatially so that they animate in order
Winson Chungf0c6ae02012-03-21 16:10:31 -07003325 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
3326 @Override
3327 public int compare(View a, View b) {
3328 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
3329 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
3330 int cellCountX = LauncherModel.getCellCountX();
3331 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
3332 }
3333 });
Winson Chunga2413752012-04-03 14:22:34 -07003334
3335 // Animate each of the views in place (or show them immediately if requested)
3336 if (immediate) {
3337 for (View v : mNewShortcutAnimateViews) {
3338 v.setAlpha(1f);
3339 v.setScaleX(1f);
3340 v.setScaleY(1f);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003341 }
Winson Chunga2413752012-04-03 14:22:34 -07003342 } else {
3343 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
3344 View v = mNewShortcutAnimateViews.get(i);
3345 ValueAnimator bounceAnim = ObjectAnimator.ofPropertyValuesHolder(v,
3346 PropertyValuesHolder.ofFloat("alpha", 1f),
3347 PropertyValuesHolder.ofFloat("scaleX", 1f),
3348 PropertyValuesHolder.ofFloat("scaleY", 1f));
3349 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3350 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3351 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3352 bounceAnims.add(bounceAnim);
3353 }
3354 anim.playTogether(bounceAnims);
3355 anim.addListener(new AnimatorListenerAdapter() {
3356 @Override
3357 public void onAnimationEnd(Animator animation) {
3358 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
3359 }
3360 });
3361 anim.start();
3362 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003363
3364 // Clean up
3365 mNewShortcutAnimatePage = -1;
3366 mNewShortcutAnimateViews.clear();
3367 new Thread("clearNewAppsThread") {
3368 public void run() {
3369 mSharedPrefs.edit()
3370 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
3371 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null)
3372 .commit();
3373 }
3374 }.start();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003375 }
3376
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003377 @Override
3378 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003379 boolean searchVisible = updateGlobalSearchIcon();
3380 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3381 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003382 }
3383
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003384 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003385 * Add the icons for all apps.
3386 *
3387 * Implementation of the method from LauncherModel.Callbacks.
3388 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003389 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3390 // Remove the progress bar entirely; we could also make it GONE
3391 // but better to remove it since we know it's not going to be used
3392 View progressBar = mAppsCustomizeTabHost.
3393 findViewById(R.id.apps_customize_progress_bar);
3394 if (progressBar != null) {
3395 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003396 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003397 // We just post the call to setApps so the user sees the progress bar
3398 // disappear-- otherwise, it just looks like the progress bar froze
3399 // which doesn't look great
3400 mAppsCustomizeTabHost.post(new Runnable() {
3401 public void run() {
3402 if (mAppsCustomizeContent != null) {
3403 mAppsCustomizeContent.setApps(apps);
3404 }
3405 }
3406 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003407 }
3408
3409 /**
3410 * A package was installed.
3411 *
3412 * Implementation of the method from LauncherModel.Callbacks.
3413 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003414 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003415 setLoadOnResume();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003416
Winson Chung785d2eb2011-04-14 16:08:02 -07003417 if (mAppsCustomizeContent != null) {
3418 mAppsCustomizeContent.addApps(apps);
3419 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003420 }
3421
3422 /**
3423 * A package was updated.
3424 *
3425 * Implementation of the method from LauncherModel.Callbacks.
3426 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003427 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003428 setLoadOnResume();
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003429 if (mWorkspace != null) {
3430 mWorkspace.updateShortcuts(apps);
3431 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003432
Winson Chung785d2eb2011-04-14 16:08:02 -07003433 if (mAppsCustomizeContent != null) {
3434 mAppsCustomizeContent.updateApps(apps);
3435 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003436 }
3437
3438 /**
3439 * A package was uninstalled.
3440 *
3441 * Implementation of the method from LauncherModel.Callbacks.
3442 */
Joe Onorato36115782010-06-17 13:28:48 -04003443 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato36115782010-06-17 13:28:48 -04003444 if (permanent) {
3445 mWorkspace.removeItems(apps);
3446 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003447
Winson Chung785d2eb2011-04-14 16:08:02 -07003448 if (mAppsCustomizeContent != null) {
3449 mAppsCustomizeContent.removeApps(apps);
3450 }
Winson Chunga1820962011-10-03 16:31:06 -07003451
3452 // Notify the drag controller
3453 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003454 }
Joe Onoratobe386092009-11-17 17:32:16 -08003455
3456 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003457 * A number of packages were updated.
3458 */
3459 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003460 if (mAppsCustomizeContent != null) {
3461 mAppsCustomizeContent.onPackagesUpdated();
3462 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003463 }
3464
Winson Chung400438b2011-01-16 17:53:48 -08003465 private int mapConfigurationOriActivityInfoOri(int configOri) {
3466 final Display d = getWindowManager().getDefaultDisplay();
3467 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3468 switch (d.getRotation()) {
3469 case Surface.ROTATION_0:
3470 case Surface.ROTATION_180:
3471 // We are currently in the same basic orientation as the natural orientation
3472 naturalOri = configOri;
3473 break;
3474 case Surface.ROTATION_90:
3475 case Surface.ROTATION_270:
3476 // We are currently in the other basic orientation to the natural orientation
3477 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3478 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3479 break;
3480 }
3481
3482 int[] oriMap = {
3483 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3484 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3485 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3486 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3487 };
3488 // Since the map starts at portrait, we need to offset if this device's natural orientation
3489 // is landscape.
3490 int indexOffset = 0;
3491 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3492 indexOffset = 1;
3493 }
3494 return oriMap[(d.getRotation() + indexOffset) % 4];
3495 }
Adam Cohen446e9402011-09-15 18:21:21 -07003496
Winson Chung4b919f82012-05-01 10:44:08 -07003497 public boolean isRotationEnabled() {
3498 boolean forceEnableRotation = "true".equalsIgnoreCase(SystemProperties.get(
3499 FORCE_ENABLE_ROTATION_PROPERTY, "false"));
3500 boolean enableRotation = forceEnableRotation ||
3501 getResources().getBoolean(R.bool.allow_rotation);
3502 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08003503 }
Winson Chung4b919f82012-05-01 10:44:08 -07003504 public void lockScreenOrientation() {
3505 if (isRotationEnabled()) {
3506 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3507 .getConfiguration().orientation));
3508 }
3509 }
3510 public void unlockScreenOrientation(boolean immediate) {
3511 if (isRotationEnabled()) {
3512 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07003513 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07003514 } else {
3515 mHandler.postDelayed(new Runnable() {
3516 public void run() {
3517 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3518 }
3519 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07003520 }
Winson Chung4b919f82012-05-01 10:44:08 -07003521 }
Winson Chung400438b2011-01-16 17:53:48 -08003522 }
3523
Winson Chung82f55532011-08-09 14:14:23 -07003524 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003525 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003526 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003527 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003528
Winson Chung7d7541e2011-09-16 20:14:36 -07003529 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003530 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003531 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3532 Cling cling = (Cling) findViewById(clingId);
3533 if (cling != null) {
3534 cling.init(this, positionData);
3535 cling.setVisibility(View.VISIBLE);
3536 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Svetoslav Ganov55d225d2012-05-22 15:19:14 -07003537 cling.requestAccessibilityFocus();
Winson Chung7d7541e2011-09-16 20:14:36 -07003538 if (animate) {
3539 cling.buildLayer();
3540 cling.setAlpha(0f);
3541 cling.animate()
3542 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003543 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003544 .setDuration(SHOW_CLING_DURATION)
3545 .setStartDelay(delay)
3546 .start();
3547 } else {
3548 cling.setAlpha(1f);
3549 }
3550 }
3551 return cling;
3552 }
3553 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003554 if (cling != null) {
3555 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003556 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003557 anim.addListener(new AnimatorListenerAdapter() {
3558 public void onAnimationEnd(Animator animation) {
3559 cling.setVisibility(View.GONE);
3560 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003561 // We should update the shared preferences on a background thread
3562 new Thread("dismissClingThread") {
3563 public void run() {
3564 SharedPreferences.Editor editor = mSharedPrefs.edit();
3565 editor.putBoolean(flag, true);
3566 editor.commit();
3567 }
3568 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003569 };
3570 });
3571 anim.start();
3572 }
3573 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003574 private void removeCling(int id) {
3575 final View cling = findViewById(id);
3576 if (cling != null) {
3577 final ViewGroup parent = (ViewGroup) cling.getParent();
3578 parent.post(new Runnable() {
3579 @Override
3580 public void run() {
3581 parent.removeView(cling);
3582 }
3583 });
3584 }
3585 }
Michael Jurka974c3862012-05-22 22:00:31 -07003586
3587 private boolean skipCustomClingIfNoAccounts() {
3588 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3589 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
3590 if (customCling) {
3591 AccountManager am = AccountManager.get(this);
3592 Account[] accounts = am.getAccountsByType("com.google");
3593 return accounts.length == 0;
3594 }
3595 return false;
3596 }
3597
Winson Chung7d7541e2011-09-16 20:14:36 -07003598 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003599 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003600 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07003601 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
3602 !skipCustomClingIfNoAccounts() ) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003603 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003604 } else {
3605 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003606 }
3607 }
3608 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003609 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003610 if (isClingsEnabled() &&
3611 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003612 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003613 } else {
3614 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003615 }
3616 }
3617 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003618 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003619 if (isClingsEnabled() &&
3620 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
3621 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003622 } else {
3623 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08003624 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07003625 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003626 }
3627 public boolean isFolderClingVisible() {
3628 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003629 if (cling != null) {
3630 return cling.getVisibility() == View.VISIBLE;
3631 }
3632 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003633 }
Winson Chung82f55532011-08-09 14:14:23 -07003634 public void dismissWorkspaceCling(View v) {
3635 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003636 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003637 }
3638 public void dismissAllAppsCling(View v) {
3639 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003640 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3641 }
3642 public void dismissFolderCling(View v) {
3643 Cling cling = (Cling) findViewById(R.id.folder_cling);
3644 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003645 }
3646
Winson Chung80baf5a2010-08-09 16:03:15 -07003647 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003648 * Prints out out state for debugging.
3649 */
3650 public void dumpState() {
3651 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003652 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003653 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3654 Log.d(TAG, "mRestoring=" + mRestoring);
3655 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3656 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003657 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003658 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003659
Winson Chung785d2eb2011-04-14 16:08:02 -07003660 if (mAppsCustomizeContent != null) {
3661 mAppsCustomizeContent.dumpState();
3662 }
Joe Onoratobe386092009-11-17 17:32:16 -08003663 Log.d(TAG, "END launcher2 dump state");
3664 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003665
3666 @Override
3667 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3668 super.dump(prefix, fd, writer, args);
3669 writer.println(" ");
3670 writer.println("Debug logs: ");
3671 for (int i = 0; i < sDumpLogs.size(); i++) {
3672 writer.println(" " + sDumpLogs.get(i));
3673 }
3674 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003675}
Michael Jurka2763be32011-02-24 11:19:57 -08003676
Michael Jurkaabded662011-03-04 12:06:57 -08003677interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003678 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003679 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08003680 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08003681 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08003682 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003683}