blob: f4180cd002c5bd2265e964052ddaf9e6de67b7c1 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Joe Onoratoa5902522009-07-30 13:37:37 -070018package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Michael Jurka974c3862012-05-22 22:00:31 -070020import android.accounts.Account;
21import android.accounts.AccountManager;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080023import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070030import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070031import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070049import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080050import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070051import android.graphics.Bitmap;
52import android.graphics.Canvas;
53import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070054import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070055import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040056import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070057import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080058import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020059import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080060import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070061import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070062import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040063import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080064import android.os.SystemProperties;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070065import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080066import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067import android.text.Selection;
68import android.text.SpannableStringBuilder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070070import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080071import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080072import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073import android.view.KeyEvent;
74import android.view.LayoutInflater;
75import android.view.Menu;
76import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070077import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080078import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080079import android.view.View;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080080import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070081import android.view.ViewGroup;
Michael Jurkab737ee62011-11-15 15:57:22 -080082import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080083import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Dianne Hackbornbb003a52011-08-30 14:40:07 -070084import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080085import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070086import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070087import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080088import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070090import android.widget.Advanceable;
Michael Jurkaaf442092010-06-10 17:01:57 -070091import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070092import android.widget.TextView;
93import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070094
Adam Cohendf2cc412011-04-27 16:56:57 -070095import com.android.common.Search;
96import com.android.launcher.R;
Adam Cohen558baaf2011-08-15 15:22:57 -070097import com.android.launcher2.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080098
Adam Cohenc0dcf592011-06-01 15:30:43 -070099import java.io.DataInputStream;
100import java.io.DataOutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700101import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.FileNotFoundException;
103import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700104import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700105import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700106import java.util.Collection;
107import java.util.Collections;
108import java.util.Comparator;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.util.HashMap;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700110import java.util.HashSet;
Michael Jurkad7c28052012-04-27 15:43:36 -0700111import java.util.List;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700112import java.util.Set;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700113
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800114/**
115 * Default launcher application.
116 */
Michael Jurka946ad472010-07-09 18:05:18 -0700117public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700118 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
119 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800120 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700121 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122
Joe Onorato9c1289c2009-08-17 11:03:03 -0400123 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400124 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700125 static final boolean DEBUG_STRICT_MODE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700126
Winson Chung70d72102011-08-12 11:24:35 -0700127 private static final int MENU_GROUP_WALLPAPER = 1;
128 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
129 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700130 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
131 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132
133 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700134 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_PICK_APPLICATION = 6;
136 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700137 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700138 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
Michael Jurka8b805b12012-04-18 14:23:14 -0700140 private static final int REQUEST_BIND_APPWIDGET = 11;
141
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
143
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800144 static final int SCREEN_COUNT = 5;
145 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146
Romain Guy98d01652009-06-30 16:21:04 -0700147 private static final String PREFERENCES = "launcher.preferences";
Adam Cohen23a4d302011-12-01 17:26:44 -0800148 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher.force_enable_rotation";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149
Winson Chung2672ff92012-05-04 16:22:30 -0700150 // The Intent extra that defines whether to ignore the launch animation
151 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
152 "com.android.launcher.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
153
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154 // Type: int
155 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700156 // Type: int
157 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700159 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
160 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800161 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
162 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700163 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700165 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166 // Type: boolean
167 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
168 // Type: long
169 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700170 // Type: int
171 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
172 // Type: int
173 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
174 // Type: parcelable
175 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700177 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700178 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
179 "com.android.launcher.toolbar_search_icon";
180 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
181 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700182
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700183 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700184 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700185 private State mState = State.WORKSPACE;
186 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800187 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700188
Joe Onorato9c1289c2009-08-17 11:03:03 -0400189 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700190 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
191 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700192 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700193 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800194
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800196 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800197
Winson Chunga2413752012-04-03 14:22:34 -0700198 // How long to wait before the new-shortcut animation automatically pans the workspace
199 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
200
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800201 private final BroadcastReceiver mCloseSystemDialogsReceiver
202 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800203 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
204
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205 private LayoutInflater mInflater;
206
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800208 private View mQsbDivider;
209 private View mDockDivider;
210 private DragLayer mDragLayer;
211 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700212
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700213 private AppWidgetManager mAppWidgetManager;
214 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700215
Michael Jurkac9d95c52011-08-29 14:03:34 -0700216 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700217 private AppWidgetProviderInfo mPendingAddWidgetInfo;
218
Michael Jurka0280c3b2010-09-17 15:00:07 -0700219 private int[] mTmpAddItemCellCoordinates = new int[2];
220
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221 private FolderInfo mFolderInfo;
222
Winson Chung3d503fb2011-07-13 17:25:49 -0700223 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800224 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700225
Winson Chungc51db6a2011-10-05 11:44:49 -0700226 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700227 private AppsCustomizeTabHost mAppsCustomizeTabHost;
228 private AppsCustomizePagedView mAppsCustomizeContent;
229 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800230
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800231 private Bundle mSavedState;
232
233 private SpannableStringBuilder mDefaultKeySsb = null;
234
Joe Onorato9c1289c2009-08-17 11:03:03 -0400235 private boolean mWorkspaceLoading = true;
236
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800237 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800238 private boolean mRestoring;
239 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700240 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800241
242 private Bundle mSavedInstanceState;
243
Joe Onorato9c1289c2009-08-17 11:03:03 -0400244 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800245 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800246 private boolean mUserPresent = true;
247 private boolean mVisible = false;
248 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400249
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700250 private static LocaleConfiguration sLocaleConfiguration = null;
251
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700252 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700253
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700254 private Intent mAppMarketIntent = null;
255
Adam Cohended9f8d2010-11-03 13:25:16 -0700256 // Related to the auto-advancing of widgets
257 private final int ADVANCE_MSG = 1;
258 private final int mAdvanceInterval = 20000;
259 private final int mAdvanceStagger = 250;
260 private long mAutoAdvanceSentTime;
261 private long mAutoAdvanceTimeLeft = -1;
262 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
263 new HashMap<View, AppWidgetProviderInfo>();
264
Winson Chung400438b2011-01-16 17:53:48 -0800265 // Determines how long to wait after a rotation before restoring the screen orientation to
266 // match the sensor state.
267 private final int mRestoreScreenOrientationDelay = 500;
268
Michael Jurka4ef207b2010-11-29 17:05:45 -0800269 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700270 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
271 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
272 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800273
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700274 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
275
Winson Chung46353de2012-02-16 14:05:10 -0800276 // We only want to get the SharedPreferences once since it does an FS stat each time we get
277 // it from the context.
278 private SharedPreferences mSharedPrefs;
279
Winson Chungf0c6ae02012-03-21 16:10:31 -0700280 // Holds the page that we need to animate to, and the icon views that we need to animate up
281 // when we scroll to that page on resume.
282 private int mNewShortcutAnimatePage = -1;
283 private ArrayList<View> mNewShortcutAnimateViews = new ArrayList<View>();
Adam Cohen268c4752012-06-06 17:47:33 -0700284 private ImageView mFolderIconImageView;
285 private Bitmap mFolderIconBitmap;
286 private Canvas mFolderIconCanvas;
287 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700288
Michael Jurkaddd62e92011-02-16 17:49:14 -0800289 private BubbleTextView mWaitingForResume;
290
Michael Jurkac1f5d262011-09-30 19:32:27 -0700291 private Runnable mBuildLayersRunnable = new Runnable() {
292 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700293 if (mWorkspace != null) {
294 mWorkspace.buildPageHardwareLayers();
295 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700296 }
297 };
298
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800299 private static ArrayList<PendingAddArguments> sPendingAddList
300 = new ArrayList<PendingAddArguments>();
301
302 private static class PendingAddArguments {
303 int requestCode;
304 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700305 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800306 int screen;
307 int cellX;
308 int cellY;
309 }
310
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800311 @Override
312 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700313 if (DEBUG_STRICT_MODE) {
314 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
315 .detectDiskReads()
316 .detectDiskWrites()
317 .detectNetwork() // or .detectAll() for all detectable problems
318 .penaltyLog()
319 .build());
320 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
321 .detectLeakedSqlLiteObjects()
322 .detectLeakedClosableObjects()
323 .penaltyLog()
324 .penaltyDeath()
325 .build());
326 }
327
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800328 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800329 LauncherApplication app = ((LauncherApplication)getApplication());
Winson Chungf0c6ae02012-03-21 16:10:31 -0700330 mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(),
331 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800332 mModel = app.setLauncher(this);
333 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400334 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800335 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700336
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700337 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700338 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
339 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700340
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800341 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200342 android.os.Debug.startMethodTracing(
343 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800344 }
345
346 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800347 setContentView(R.layout.launcher);
348 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700349 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800350
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800351 registerContentObservers();
352
Joe Onorato7c312c12009-08-13 21:36:53 -0700353 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700354
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800355 mSavedState = savedInstanceState;
356 restoreState(mSavedState);
357
Winson Chunga12a2502010-12-20 14:41:35 -0800358 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700359 if (mAppsCustomizeContent != null) {
360 mAppsCustomizeContent.onPackagesUpdated();
361 }
Winson Chunga12a2502010-12-20 14:41:35 -0800362
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800363 if (PROFILE_STARTUP) {
364 android.os.Debug.stopMethodTracing();
365 }
366
367 if (!mRestoring) {
Winson Chungf0c6ae02012-03-21 16:10:31 -0700368 mModel.startLoader(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800369 }
370
Michael Jurkac57b7a82011-08-09 22:02:20 -0700371 if (!mModel.isAllAppsLoaded()) {
372 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
373 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
374 }
375
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 // For handling default keys
377 mDefaultKeySsb = new SpannableStringBuilder();
378 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800379
380 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
381 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800382
Adam Cohenf9426d52012-06-04 17:26:21 -0700383 updateGlobalIcons();
384
385 // On large interfaces, we want the screen to auto-rotate based on the current orientation
386 unlockScreenOrientation(true);
387 }
388
389 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700390 boolean searchVisible = false;
391 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800392 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700393 int coi = getCurrentOrientationIndexForGlobalIcons();
394 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
395 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700396 updateAppMarketIcon();
397 searchVisible = updateGlobalSearchIcon();
398 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700399 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700400 if (sGlobalSearchIcon[coi] != null) {
401 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700402 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700403 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700404 if (sVoiceSearchIcon[coi] != null) {
405 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700406 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700407 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700408 if (sAppMarketIcon[coi] != null) {
409 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800410 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700411 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800412 }
Romain Guycbb89e42009-06-08 15:52:54 -0700413
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800414 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700415 if (sLocaleConfiguration == null) {
416 new AsyncTask<Void, Void, LocaleConfiguration>() {
417 @Override
418 protected LocaleConfiguration doInBackground(Void... unused) {
419 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
420 readConfiguration(Launcher.this, localeConfiguration);
421 return localeConfiguration;
422 }
423
424 @Override
425 protected void onPostExecute(LocaleConfiguration result) {
426 sLocaleConfiguration = result;
427 checkForLocaleChange(); // recursive, but now with a locale configuration
428 }
429 }.execute();
430 return;
431 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700432
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800433 final Configuration configuration = getResources().getConfiguration();
434
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700435 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800436 final String locale = configuration.locale.toString();
437
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700438 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800439 final int mcc = configuration.mcc;
440
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700441 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800442 final int mnc = configuration.mnc;
443
Romain Guy84f296c2009-11-04 15:00:44 -0800444 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800445
Romain Guy84f296c2009-11-04 15:00:44 -0800446 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700447 sLocaleConfiguration.locale = locale;
448 sLocaleConfiguration.mcc = mcc;
449 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700450
Joe Onorato0589f0f2010-02-08 13:44:00 -0800451 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700452
453 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
454 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700455 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700456 public void run() {
457 writeConfiguration(Launcher.this, localeConfiguration);
458 }
459 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700460 }
461 }
462
463 private static class LocaleConfiguration {
464 public String locale;
465 public int mcc = -1;
466 public int mnc = -1;
467 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700468
Romain Guy98d01652009-06-30 16:21:04 -0700469 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
470 DataInputStream in = null;
471 try {
472 in = new DataInputStream(context.openFileInput(PREFERENCES));
473 configuration.locale = in.readUTF();
474 configuration.mcc = in.readInt();
475 configuration.mnc = in.readInt();
476 } catch (FileNotFoundException e) {
477 // Ignore
478 } catch (IOException e) {
479 // Ignore
480 } finally {
481 if (in != null) {
482 try {
483 in.close();
484 } catch (IOException e) {
485 // Ignore
486 }
487 }
488 }
489 }
490
491 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
492 DataOutputStream out = null;
493 try {
494 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
495 out.writeUTF(configuration.locale);
496 out.writeInt(configuration.mcc);
497 out.writeInt(configuration.mnc);
498 out.flush();
499 } catch (FileNotFoundException e) {
500 // Ignore
501 } catch (IOException e) {
502 //noinspection ResultOfMethodCallIgnored
503 context.getFileStreamPath(PREFERENCES).delete();
504 } finally {
505 if (out != null) {
506 try {
507 out.close();
508 } catch (IOException e) {
509 // Ignore
510 }
511 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800512 }
513 }
514
Adam Cohen716b51e2011-06-30 12:09:54 -0700515 public DragLayer getDragLayer() {
516 return mDragLayer;
517 }
518
Winson Chung36a62fe2012-05-06 18:04:42 -0700519 boolean isDraggingEnabled() {
520 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
521 // that is subsequently removed from the workspace in startBinding().
522 return !mModel.isLoadingWorkspace();
523 }
524
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800525 static int getScreen() {
526 synchronized (sLock) {
527 return sScreen;
528 }
529 }
530
531 static void setScreen(int screen) {
532 synchronized (sLock) {
533 sScreen = screen;
534 }
535 }
536
Winson Chung557d6ed2011-07-08 15:34:52 -0700537 /**
538 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
539 * a configuration step, this allows the proper animations to run after other transitions.
540 */
541 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700542 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800543 switch (args.requestCode) {
544 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700545 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
546 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800547 break;
548 case REQUEST_PICK_SHORTCUT:
549 processShortcut(args.intent);
550 break;
551 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700552 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
553 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700554 result = true;
555 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800556 case REQUEST_CREATE_APPWIDGET:
557 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800558 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700559 result = true;
560 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800561 case REQUEST_PICK_WALLPAPER:
562 // We just wanted the activity result here so we can clear mWaitingForResult
563 break;
564 }
Michael Jurka27614d22012-04-02 06:40:22 -0700565 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
566 // if you turned the screen off and then back while in All Apps, Launcher would not
567 // return to the workspace. Clearing mAddInfo.container here fixes this issue
568 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700569 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800570 }
571
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800572 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700573 protected void onActivityResult(
574 final int requestCode, final int resultCode, final Intent data) {
575 if (requestCode == REQUEST_BIND_APPWIDGET) {
576 int appWidgetId = data != null ?
577 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
578 if (resultCode == RESULT_CANCELED) {
579 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
580 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700581 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700582 }
583 return;
584 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700585 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800586 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
587 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700588 mWaitingForResult = false;
589
Adam Cohened66b2b2012-01-23 17:28:51 -0800590 // We have special handling for widgets
591 if (isWidgetDrop) {
592 int appWidgetId = data != null ?
593 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700594 if (appWidgetId < 0) {
595 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
596 "widget configuration activity.");
597 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
598 } else {
599 completeTwoStageWidgetDrop(resultCode, appWidgetId);
600 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800601 return;
602 }
603
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800604 // The pattern used here is that a user PICKs a specific application,
605 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700606
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800607 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
608 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700609 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800610 final PendingAddArguments args = new PendingAddArguments();
611 args.requestCode = requestCode;
612 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700613 args.container = mPendingAddInfo.container;
614 args.screen = mPendingAddInfo.screen;
615 args.cellX = mPendingAddInfo.cellX;
616 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800617 if (isWorkspaceLocked()) {
618 sPendingAddList.add(args);
619 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700620 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800621 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800622 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800623 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700624 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800625 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
626 null);
627 }
628
629 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700630 CellLayout cellLayout =
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700631 (CellLayout) mWorkspace.getChildAt(mPendingAddInfo.screen);
Adam Cohened66b2b2012-01-23 17:28:51 -0800632 Runnable onCompleteRunnable = null;
633 int animationType = 0;
634
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700635 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800636 if (resultCode == RESULT_OK) {
637 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
638 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700639 mPendingAddWidgetInfo);
640 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800641 onCompleteRunnable = new Runnable() {
642 @Override
643 public void run() {
644 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
645 mPendingAddInfo.screen, layout, null);
646 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
647 null);
648 }
649 };
650 } else if (resultCode == RESULT_CANCELED) {
651 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
652 onCompleteRunnable = new Runnable() {
653 @Override
654 public void run() {
655 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
656 null);
657 }
658 };
659 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700660 if (mDragLayer.getAnimatedView() != null) {
661 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
662 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
663 animationType, boundWidget, true);
664 } else {
665 // The animated view may be null in the case of a rotation during widget configuration
666 onCompleteRunnable.run();
667 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800668 }
669
670 @Override
671 protected void onResume() {
672 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700673
Winson Chungde0fb8f2012-05-08 14:37:08 -0700674 // Process any items that were added while Launcher was away
675 InstallShortcutReceiver.flushInstallQueue(this);
676
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800677 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700678 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400679 mWorkspaceLoading = true;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700680 mModel.startLoader(true);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400681 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700682 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800683 }
Winson Chunge4e50662012-01-23 14:45:13 -0800684
685 // Reset the pressed state of icons that were locked in the press state while activities
686 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800687 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800688 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800689 mWaitingForResume.setStayPressed(false);
690 }
Winson Chunge4e50662012-01-23 14:45:13 -0800691 if (mAppsCustomizeContent != null) {
692 // Resets the previous all apps icon press state
693 mAppsCustomizeContent.resetDrawableState();
694 }
Adam Cohen06dff352012-06-01 17:17:08 -0700695 // It is possible that widgets can receive updates while launcher is not in the foreground.
696 // Consequently, the widgets will be inflated in the orientation of the foreground activity
697 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
698 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700699 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700700
701 // Again, as with the above scenario, it's possible that one or more of the global icons
702 // were updated in the wrong orientation.
703 updateGlobalIcons();
Adam Cohen06dff352012-06-01 17:17:08 -0700704 }
705
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800706 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700707 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700708 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
709 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
710 // when Launcher resumes and we are still in AllApps.
711 updateWallpaperVisibility(true);
712
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700713 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700714 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800715 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700716 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700717 }
Romain Guycbb89e42009-06-08 15:52:54 -0700718
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700719 @Override
720 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400721 // Flag the loader to stop early before switching
722 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700723 if (mAppsCustomizeContent != null) {
724 mAppsCustomizeContent.surrender();
725 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800726 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700727 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700728
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800729 // We can't hide the IME if it was forced open. So don't bother
730 /*
731 @Override
732 public void onWindowFocusChanged(boolean hasFocus) {
733 super.onWindowFocusChanged(hasFocus);
734
735 if (hasFocus) {
736 final InputMethodManager inputManager = (InputMethodManager)
737 getSystemService(Context.INPUT_METHOD_SERVICE);
738 WindowManager.LayoutParams lp = getWindow().getAttributes();
739 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
740 android.os.Handler()) {
741 protected void onReceiveResult(int resultCode, Bundle resultData) {
742 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
743 }
744 });
745 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
746 }
747 }
748 */
749
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800750 private boolean acceptFilter() {
751 final InputMethodManager inputManager = (InputMethodManager)
752 getSystemService(Context.INPUT_METHOD_SERVICE);
753 return !inputManager.isFullscreenMode();
754 }
755
756 @Override
757 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700758 final int uniChar = event.getUnicodeChar();
759 final boolean handled = super.onKeyDown(keyCode, event);
760 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
761 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800762 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
763 keyCode, event);
764 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700765 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700766 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700767 // showSearchDialog()
768 // If there are multiple keystrokes before the search dialog takes focus,
769 // onSearchRequested() will be called for every keystroke,
770 // but it is idempotent, so it's fine.
771 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800772 }
773 }
774
Joe Onorato8a9625e2010-01-28 15:55:35 -0800775 // Eat the long press event so the keyboard doesn't come up.
776 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
777 return true;
778 }
779
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800780 return handled;
781 }
782
Karl Rosaen138a0412009-04-23 19:00:21 -0700783 private String getTypedText() {
784 return mDefaultKeySsb.toString();
785 }
786
787 private void clearTypedText() {
788 mDefaultKeySsb.clear();
789 mDefaultKeySsb.clearSpans();
790 Selection.setSelection(mDefaultKeySsb, 0);
791 }
792
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800793 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700794 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
795 * State
796 */
797 private static State intToState(int stateOrdinal) {
798 State state = State.WORKSPACE;
799 final State[] stateValues = State.values();
800 for (int i = 0; i < stateValues.length; i++) {
801 if (stateValues[i].ordinal() == stateOrdinal) {
802 state = stateValues[i];
803 break;
804 }
805 }
806 return state;
807 }
808
809 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800810 * Restores the previous state, if it exists.
811 *
812 * @param savedState The previous state.
813 */
814 private void restoreState(Bundle savedState) {
815 if (savedState == null) {
816 return;
817 }
818
Michael Jurka883f55b2010-10-21 15:47:14 -0700819 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700820 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800821 showAllApps(false);
822 }
823
Winson Chungf0c6ae02012-03-21 16:10:31 -0700824 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800825 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700826 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800827 }
828
Winson Chung3d503fb2011-07-13 17:25:49 -0700829 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
830 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700831
Winson Chung3d503fb2011-07-13 17:25:49 -0700832 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
833 mPendingAddInfo.container = pendingAddContainer;
834 mPendingAddInfo.screen = pendingAddScreen;
835 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
836 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700837 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
838 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
839 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -0700840 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800841 mRestoring = true;
842 }
843
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700844
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800845 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
846 if (renameFolder) {
847 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700848 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800849 mRestoring = true;
850 }
Winson Chunga12a2502010-12-20 14:41:35 -0800851
Winson Chung785d2eb2011-04-14 16:08:02 -0700852
853 // Restore the AppsCustomize tab
854 if (mAppsCustomizeTabHost != null) {
855 String curTab = savedState.getString("apps_customize_currentTab");
856 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700857 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700858 mAppsCustomizeContent.setContentType(
859 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
860 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700861 mAppsCustomizeContent.loadAssociatedPages(
862 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700863 }
864
Winson Chung5afbf7b2011-07-25 11:53:08 -0700865 int currentIndex = savedState.getInt("apps_customize_currentIndex");
866 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700867 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800868 }
869
870 /**
871 * Finds all the views we need and configure them properly.
872 */
873 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700874 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400875
Winson Chung4c98d922011-05-31 16:50:48 -0700876 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
877 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800878 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
879 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800880
Winson Chung4c98d922011-05-31 16:50:48 -0700881 // Setup the drag layer
882 mDragLayer.setup(this, dragController);
883
Winson Chung3d503fb2011-07-13 17:25:49 -0700884 // Setup the hotseat
885 mHotseat = (Hotseat) findViewById(R.id.hotseat);
886 if (mHotseat != null) {
887 mHotseat.setup(this);
888 }
889
Winson Chung4c98d922011-05-31 16:50:48 -0700890 // Setup the workspace
891 mWorkspace.setHapticFeedbackEnabled(false);
892 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700893 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700894 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700895
Winson Chungf0ea4d32011-06-06 14:27:16 -0700896 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700897 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700898
Winson Chungf0ea4d32011-06-06 14:27:16 -0700899 // Setup AppsCustomize
900 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
901 findViewById(R.id.apps_customize_pane);
902 mAppsCustomizeContent = (AppsCustomizePagedView)
903 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
Winson Chungc7450e32012-04-17 17:34:08 -0700904 mAppsCustomizeTabHost.setup(this);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700905 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400906
Michael Jurka5130e402011-10-13 04:55:35 -0700907 // Get the all apps button
908 mAllAppsButton = findViewById(R.id.all_apps_button);
909 if (mAllAppsButton != null) {
910 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
911 @Override
912 public boolean onTouch(View v, MotionEvent event) {
913 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
914 onTouchDownAllAppsButton(v);
915 }
916 return false;
917 }
918 });
919 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700920 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700921 dragController.setDragScoller(mWorkspace);
922 dragController.setScrollView(mDragLayer);
923 dragController.setMoveTarget(mWorkspace);
924 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700925 if (mSearchDropTargetBar != null) {
926 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800927 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800928 }
929
930 /**
931 * Creates a view representing a shortcut.
932 *
933 * @param info The data structure describing the shortcut.
934 *
935 * @return A View inflated from R.layout.application.
936 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800937 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800938 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700939 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800940 }
941
942 /**
943 * Creates a view representing a shortcut inflated from the specified resource.
944 *
945 * @param layoutResId The id of the XML layout used to create the shortcut.
946 * @param parent The group the shortcut belongs to.
947 * @param info The data structure describing the shortcut.
948 *
949 * @return A View inflated from layoutResId.
950 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800951 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800952 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
953 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800954 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800955 return favorite;
956 }
957
958 /**
959 * Add an application shortcut to the workspace.
960 *
961 * @param data The intent describing the application.
962 * @param cellInfo The position on screen where to create the shortcut.
963 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700964 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700965 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700966 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700967
Adam Cohenfbba09b2011-07-18 21:43:05 -0700968 // First we check if we already know the exact location where we want to add this item.
969 if (cellX >= 0 && cellY >= 0) {
970 cellXY[0] = cellX;
971 cellXY[1] = cellY;
972 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -0700973 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -0700974 return;
975 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800976
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800977 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800978
Romain Guy73b979d2009-06-09 12:57:21 -0700979 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800980 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800981 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800982 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700983 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700984 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800985 } else {
986 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800987 }
988 }
Romain Guycbb89e42009-06-08 15:52:54 -0700989
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800990 /**
991 * Add a shortcut to the workspace.
992 *
993 * @param data The intent describing the shortcut.
994 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800995 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700996 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
997 int cellY) {
998 int[] cellXY = mTmpAddItemCellCoordinates;
999 int[] touchXY = mPendingAddInfo.dropPos;
1000 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001001
Michael Jurkad3ef3062010-11-23 16:23:58 -08001002 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001003
Adam Cohen558baaf2011-08-15 15:22:57 -07001004 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001005 if (info == null) {
1006 return;
1007 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001008 final View view = createShortcut(info);
1009
Adam Cohenfbba09b2011-07-18 21:43:05 -07001010 // First we check if we already know the exact location where we want to add this item.
1011 if (cellX >= 0 && cellY >= 0) {
1012 cellXY[0] = cellX;
1013 cellXY[1] = cellY;
1014 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001015
1016 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001017 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001018 true, null,null)) {
1019 return;
1020 }
1021 DragObject dragObject = new DragObject();
1022 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001023 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1024 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001025 return;
1026 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001027 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001028 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001029 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001030 foundCellSpan = (result != null);
1031 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001032 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001033 }
1034
1035 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001036 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001037 return;
1038 }
1039
Adam Cohen558baaf2011-08-15 15:22:57 -07001040 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001041
1042 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001043 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
1044 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001045 }
1046 }
1047
Adam Cohen2f093b62012-04-30 18:59:53 -07001048 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1049 int minHeight) {
1050 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001051 // We want to account for the extra amount of padding that we are adding to the widget
1052 // to ensure that it gets the full amount of space that it has requested
1053 int requiredWidth = minWidth + padding.left + padding.right;
1054 int requiredHeight = minHeight + padding.top + padding.bottom;
Adam Cohen2f093b62012-04-30 18:59:53 -07001055 return CellLayout.rectToCell(context.getResources(), requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001056 }
1057
Adam Cohen2f093b62012-04-30 18:59:53 -07001058 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1059 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001060 }
1061
Adam Cohen2f093b62012-04-30 18:59:53 -07001062 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1063 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001064 }
1065
Adam Cohen2f093b62012-04-30 18:59:53 -07001066 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1067 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001068 }
1069
Adam Cohen2f093b62012-04-30 18:59:53 -07001070 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1071 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001072 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001073 }
1074
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001075 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001076 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001077 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001078 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001079 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001080 */
Adam Cohened66b2b2012-01-23 17:28:51 -08001081 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
1082 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1083 if (appWidgetInfo == null) {
1084 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1085 }
Romain Guycbb89e42009-06-08 15:52:54 -07001086
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001087 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -07001088 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -07001089
Adam Cohen2f093b62012-04-30 18:59:53 -07001090 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1091 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001092
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001093 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001094 // We have saved the position to which the widget was dragged-- this really only matters
1095 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001096 int[] cellXY = mTmpAddItemCellCoordinates;
1097 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001098 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001099 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001100 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1101 cellXY[0] = mPendingAddInfo.cellX;
1102 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001103 spanXY[0] = mPendingAddInfo.spanX;
1104 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001105 foundCellSpan = true;
1106 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001107 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001108 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001109 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1110 spanXY[1], cellXY, finalSpan);
1111 spanXY[0] = finalSpan[0];
1112 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001113 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001114 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001115 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001116 }
1117
Michael Jurka0280c3b2010-09-17 15:00:07 -07001118 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001119 if (appWidgetId != -1) {
1120 // Deleting an app widget ID is a void call but writes to disk before returning
1121 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001122 new Thread("deleteAppWidgetId") {
1123 public void run() {
1124 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1125 }
1126 }.start();
1127 }
Winson Chung93eef082012-03-23 15:59:27 -07001128 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001129 return;
1130 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001131
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001132 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001133 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1134 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001135 launcherInfo.spanX = spanXY[0];
1136 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001137 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1138 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001139
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001140 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001141 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001142
1143 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001144 if (hostView == null) {
1145 // Perform actual inflation because we're live
1146 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1147 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1148 } else {
1149 // The AppWidgetHostView has already been inflated and instantiated
1150 launcherInfo.hostView = hostView;
1151 }
Romain Guycbb89e42009-06-08 15:52:54 -07001152
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001153 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001154 launcherInfo.hostView.setVisibility(View.VISIBLE);
Winson Chung211bac32012-05-15 13:43:57 -07001155 launcherInfo.notifyWidgetSizeChanged(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001156 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001157 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001158
1159 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001160 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001161 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001162 }
Romain Guycbb89e42009-06-08 15:52:54 -07001163
Adam Cohended9f8d2010-11-03 13:25:16 -07001164 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1165 @Override
1166 public void onReceive(Context context, Intent intent) {
1167 final String action = intent.getAction();
1168 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1169 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001170 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001171 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001172
Winson Chungc100e8e2011-08-09 16:02:43 -07001173 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001174 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001175 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1176 mAppsCustomizeTabHost.reset();
1177 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001178 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001179 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1180 mUserPresent = true;
1181 updateRunning();
1182 }
1183 }
1184 };
1185
1186 @Override
1187 public void onAttachedToWindow() {
1188 super.onAttachedToWindow();
1189
1190 // Listen for broadcasts related to user-presence
1191 final IntentFilter filter = new IntentFilter();
1192 filter.addAction(Intent.ACTION_SCREEN_OFF);
1193 filter.addAction(Intent.ACTION_USER_PRESENT);
1194 registerReceiver(mReceiver, filter);
1195
Adam Cohend113e0c2010-11-11 10:48:05 -08001196 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001197 mVisible = true;
1198 }
1199
1200 @Override
1201 public void onDetachedFromWindow() {
1202 super.onDetachedFromWindow();
1203 mVisible = false;
1204
Adam Cohend113e0c2010-11-11 10:48:05 -08001205 if (mAttached) {
1206 unregisterReceiver(mReceiver);
1207 mAttached = false;
1208 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001209 updateRunning();
1210 }
1211
1212 public void onWindowVisibilityChanged(int visibility) {
1213 mVisible = visibility == View.VISIBLE;
1214 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001215 // The following code used to be in onResume, but it turns out onResume is called when
1216 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1217 // is a more appropriate event to handle
1218 if (mVisible) {
1219 mAppsCustomizeTabHost.onWindowVisible();
1220 if (!mWorkspaceLoading) {
1221 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001222 // We want to let Launcher draw itself at least once before we force it to build
1223 // layers on all the workspace pages, so that transitioning to Launcher from other
1224 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
1225 // a true draw so we wait until the second preDraw call to be safe
1226 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001227 public boolean onPreDraw() {
Michael Jurka6ee21d22012-02-21 18:20:27 -08001228 // We delay the layer building a bit in order to give
1229 // other message processing a time to run. In particular
1230 // this avoids a delay in hiding the IME if it was
1231 // currently shown, because doing that may involve
1232 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001233 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Winson Chung31ce0732012-05-06 13:36:43 -07001234
Michael Jurka6ee21d22012-02-21 18:20:27 -08001235 observer.removeOnPreDrawListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001236 return true;
1237 }
1238 });
1239 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001240 // When Launcher comes back to foreground, a different Activity might be responsible for
1241 // the app market intent, so refresh the icon
1242 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001243 clearTypedText();
1244 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001245 }
1246
1247 private void sendAdvanceMessage(long delay) {
1248 mHandler.removeMessages(ADVANCE_MSG);
1249 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1250 mHandler.sendMessageDelayed(msg, delay);
1251 mAutoAdvanceSentTime = System.currentTimeMillis();
1252 }
1253
1254 private void updateRunning() {
1255 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1256 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1257 mAutoAdvanceRunning = autoAdvanceRunning;
1258 if (autoAdvanceRunning) {
1259 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1260 sendAdvanceMessage(delay);
1261 } else {
1262 if (!mWidgetsToAdvance.isEmpty()) {
1263 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1264 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1265 }
1266 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001267 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001268 }
1269 }
1270 }
1271
1272 private final Handler mHandler = new Handler() {
1273 @Override
1274 public void handleMessage(Message msg) {
1275 if (msg.what == ADVANCE_MSG) {
1276 int i = 0;
1277 for (View key: mWidgetsToAdvance.keySet()) {
1278 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1279 final int delay = mAdvanceStagger * i;
1280 if (v instanceof Advanceable) {
1281 postDelayed(new Runnable() {
1282 public void run() {
1283 ((Advanceable) v).advance();
1284 }
1285 }, delay);
1286 }
1287 i++;
1288 }
1289 sendAdvanceMessage(mAdvanceInterval);
1290 }
1291 }
1292 };
1293
1294 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001295 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001296 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1297 if (v instanceof Advanceable) {
1298 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001299 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001300 updateRunning();
1301 }
1302 }
1303
1304 void removeWidgetToAutoAdvance(View hostView) {
1305 if (mWidgetsToAdvance.containsKey(hostView)) {
1306 mWidgetsToAdvance.remove(hostView);
1307 updateRunning();
1308 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001309 }
1310
Joe Onorato9c1289c2009-08-17 11:03:03 -04001311 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001312 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001313 launcherInfo.hostView = null;
1314 }
1315
Winson Chung93eef082012-03-23 15:59:27 -07001316 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1317 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1318 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001319 }
1320
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001321 public LauncherAppWidgetHost getAppWidgetHost() {
1322 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001323 }
Romain Guycbb89e42009-06-08 15:52:54 -07001324
Winson Chunga9abd0e2010-10-27 17:18:37 -07001325 public LauncherModel getModel() {
1326 return mModel;
1327 }
1328
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001329 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001330 getWindow().closeAllPanels();
1331
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001332 // Whatever we were doing is hereby canceled.
1333 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001334 }
1335
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001336 @Override
1337 protected void onNewIntent(Intent intent) {
1338 super.onNewIntent(intent);
1339
1340 // Close the menu
1341 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001342 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001343 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001344
Joe Onorato14f122b2009-11-19 14:06:36 -08001345 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1346 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001347
Adam Cohenac56cff2011-09-28 20:45:37 -07001348 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001349 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001350 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001351 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1352 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001353 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001354 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001355
1356 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001357 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001358 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001359
Joe Onorato3a8820b2009-11-10 15:06:42 -08001360 final View v = getWindow().peekDecorView();
1361 if (v != null && v.getWindowToken() != null) {
1362 InputMethodManager imm = (InputMethodManager)getSystemService(
1363 INPUT_METHOD_SERVICE);
1364 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001365 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001366
Michael Jurka35aa14d2011-07-07 17:01:08 -07001367 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001368 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001369 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001370 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001371 }
1372 }
1373
1374 @Override
1375 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1376 // Do not call super here
1377 mSavedInstanceState = savedInstanceState;
1378 }
1379
1380 @Override
1381 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001382 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001383 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001384
Michael Jurka883f55b2010-10-21 15:47:14 -07001385 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001386 // We close any open folder since it will not be re-opened, and we need to make sure
1387 // this state is reflected.
1388 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001389
Winson Chung3d503fb2011-07-13 17:25:49 -07001390 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1391 mWaitingForResult) {
1392 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1393 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1394 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1395 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001396 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1397 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1398 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001399 }
1400
1401 if (mFolderInfo != null && mWaitingForResult) {
1402 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1403 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1404 }
Michael Jurka946ad472010-07-09 18:05:18 -07001405
Winson Chung785d2eb2011-04-14 16:08:02 -07001406 // Save the current AppsCustomize tab
1407 if (mAppsCustomizeTabHost != null) {
1408 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1409 if (currentTabTag != null) {
1410 outState.putString("apps_customize_currentTab", currentTabTag);
1411 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001412 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1413 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001414 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001415 }
1416
1417 @Override
1418 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001419 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001420
Winson Chunge7a03942011-08-05 15:05:12 -07001421 // Remove all pending runnables
1422 mHandler.removeMessages(ADVANCE_MSG);
1423 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001424 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001425
Winson Chungcd2b0142011-06-08 16:02:26 -07001426 // Stop callbacks from LauncherModel
1427 LauncherApplication app = ((LauncherApplication) getApplication());
1428 mModel.stopLoader();
1429 app.setLauncher(null);
1430
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001431 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001432 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001433 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001434 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001435 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001436 mAppWidgetHost = null;
1437
1438 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001439
1440 TextKeyListener.getInstance().release();
1441
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001442
Winson Chung3d503fb2011-07-13 17:25:49 -07001443 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001444
1445 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001446 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001447
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001448 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001449 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1450 mWorkspace.removeAllViews();
1451 mWorkspace = null;
1452 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001453
1454 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001455 }
1456
Adam Cohena9cf38f2011-05-02 15:36:58 -07001457 public DragController getDragController() {
1458 return mDragController;
1459 }
1460
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001461 @Override
1462 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001463 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001464 super.startActivityForResult(intent, requestCode);
1465 }
1466
Winson Chung70d72102011-08-12 11:24:35 -07001467 /**
1468 * Indicates that we want global search for this activity by setting the globalSearch
1469 * argument for {@link #startSearch} to true.
1470 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001471 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001472 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001473 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001474
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001475 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001476
Karl Rosaen138a0412009-04-23 19:00:21 -07001477 if (initialQuery == null) {
1478 // Use any text typed in the launcher as the initial query
1479 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001480 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001481 if (appSearchData == null) {
1482 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001483 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001484 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001485 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001486
Karl Rosaen138a0412009-04-23 19:00:21 -07001487 final SearchManager searchManager =
1488 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001489 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001490 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001491 }
1492
Winson Chung70d72102011-08-12 11:24:35 -07001493 @Override
1494 public boolean onCreateOptionsMenu(Menu menu) {
1495 if (isWorkspaceLocked()) {
1496 return false;
1497 }
1498
1499 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001500
1501 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1502 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1503 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001504 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1505 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1506 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001507 String helpUrl = getString(R.string.help_url);
1508 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001509 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1510 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1511
Winson Chung70d72102011-08-12 11:24:35 -07001512 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1513 .setIcon(android.R.drawable.ic_menu_gallery)
1514 .setAlphabeticShortcut('W');
1515 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1516 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001517 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001518 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001519 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1520 .setIcon(android.R.drawable.ic_menu_preferences)
1521 .setIntent(settings)
1522 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001523 if (!helpUrl.isEmpty()) {
1524 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1525 .setIcon(android.R.drawable.ic_menu_help)
1526 .setIntent(help)
1527 .setAlphabeticShortcut('H');
1528 }
Winson Chung70d72102011-08-12 11:24:35 -07001529 return true;
1530 }
1531
1532 @Override
1533 public boolean onPrepareOptionsMenu(Menu menu) {
1534 super.onPrepareOptionsMenu(menu);
1535
1536 if (mAppsCustomizeTabHost.isTransitioning()) {
1537 return false;
1538 }
1539 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1540 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1541
1542 return true;
1543 }
1544
1545 @Override
1546 public boolean onOptionsItemSelected(MenuItem item) {
1547 switch (item.getItemId()) {
1548 case MENU_WALLPAPER_SETTINGS:
1549 startWallpaper();
1550 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001551 }
1552
1553 return super.onOptionsItemSelected(item);
1554 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001555
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001556 @Override
1557 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001558 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001559 // Use a custom animation for launching search
1560 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001561 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001562 }
1563
Joe Onorato9c1289c2009-08-17 11:03:03 -04001564 public boolean isWorkspaceLocked() {
1565 return mWorkspaceLoading || mWaitingForResult;
1566 }
1567
Michael Jurka0280c3b2010-09-17 15:00:07 -07001568 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001569 mPendingAddInfo.container = ItemInfo.NO_ID;
1570 mPendingAddInfo.screen = -1;
1571 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1572 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001573 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001574 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001575 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001576
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001577 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1578 AppWidgetProviderInfo appWidgetInfo) {
1579 if (appWidgetInfo.configure != null) {
1580 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001581
Bjorn Bringert7984c942009-12-09 15:38:25 +00001582 // Launch over to configure widget, if needed
1583 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001584 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001585 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Romain Guy8e633c52010-03-04 12:51:36 -08001586 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001587 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001588 // Otherwise just add it
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001589 completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget,
1590 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001591 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001592 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001593 }
1594 }
Romain Guycbb89e42009-06-08 15:52:54 -07001595
Adam Cohenfbba09b2011-07-18 21:43:05 -07001596 /**
1597 * Process a shortcut drop.
1598 *
1599 * @param componentName The name of the component
1600 * @param screen The screen where it should be added
1601 * @param cell The cell it should be added to, optional
1602 * @param position The location on the screen where it was dropped, optional
1603 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001604 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1605 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001606 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001607 mPendingAddInfo.container = container;
1608 mPendingAddInfo.screen = screen;
1609 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001610
1611 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001612 mPendingAddInfo.cellX = cell[0];
1613 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001614 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001615
1616 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1617 createShortcutIntent.setComponent(componentName);
1618 processShortcut(createShortcutIntent);
1619 }
1620
Adam Cohenfbba09b2011-07-18 21:43:05 -07001621 /**
1622 * Process a widget drop.
1623 *
1624 * @param info The PendingAppWidgetInfo of the widget being added.
1625 * @param screen The screen where it should be added
1626 * @param cell The cell it should be added to, optional
1627 * @param position The location on the screen where it was dropped, optional
1628 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001629 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
Adam Cohend41fbf52012-02-16 23:53:59 -08001630 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001631 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001632 mPendingAddInfo.container = info.container = container;
1633 mPendingAddInfo.screen = info.screen = screen;
1634 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001635 mPendingAddInfo.minSpanX = info.minSpanX;
1636 mPendingAddInfo.minSpanY = info.minSpanY;
1637
Adam Cohenfbba09b2011-07-18 21:43:05 -07001638 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001639 mPendingAddInfo.cellX = cell[0];
1640 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001641 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001642 if (span != null) {
1643 mPendingAddInfo.spanX = span[0];
1644 mPendingAddInfo.spanY = span[1];
1645 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001646
Adam Cohened66b2b2012-01-23 17:28:51 -08001647 AppWidgetHostView hostView = info.boundWidget;
1648 int appWidgetId;
1649 if (hostView != null) {
1650 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001651 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001652 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001653 // In this case, we either need to start an activity to get permission to bind
1654 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001655 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Michael Jurka8b805b12012-04-18 14:23:14 -07001656 if (mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName)) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001657 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001658 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001659 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001660 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1661 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1662 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
1663 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1664 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001665 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001666 }
1667
Joe Onoratodeb98af2010-02-19 14:59:39 -08001668 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001669 // Handle case where user selected "Applications"
1670 String applicationName = getResources().getString(R.string.group_applications);
1671 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001672
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001673 if (applicationName != null && applicationName.equals(shortcutName)) {
1674 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1675 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001676
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001677 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1678 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001679 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001680 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001681 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001682 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001683 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001684 }
1685
Winson Chung24ab2f12010-09-16 14:10:47 -07001686 void processWallpaper(Intent intent) {
1687 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1688 }
1689
Winson Chung3d503fb2011-07-13 17:25:49 -07001690 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1691 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001692 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001693 folderInfo.title = getText(R.string.folder_name);
1694
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001695 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001696 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1697 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001698 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001699
1700 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001701 FolderIcon newFolder =
1702 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1703 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1704 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001705 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001706 }
Romain Guycbb89e42009-06-08 15:52:54 -07001707
Joe Onorato9c1289c2009-08-17 11:03:03 -04001708 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001709 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001710 }
1711
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001712 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001713 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001714 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001715 Intent chooser = Intent.createChooser(pickWallpaper,
1716 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001717 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1718 // Removed in Eclair MR1
1719// WallpaperManager wm = (WallpaperManager)
1720// getSystemService(Context.WALLPAPER_SERVICE);
1721// WallpaperInfo wi = wm.getWallpaperInfo();
1722// if (wi != null && wi.getSettingsActivity() != null) {
1723// LabeledIntent li = new LabeledIntent(getPackageName(),
1724// R.string.configure_wallpaper, 0);
1725// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1726// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1727// }
Mike Clerona0618e42009-10-22 13:55:21 -07001728 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001729 }
1730
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001731 /**
1732 * Registers various content observers. The current implementation registers
1733 * only a favorites observer to keep track of the favorites applications.
1734 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001735 private void registerContentObservers() {
1736 ContentResolver resolver = getContentResolver();
1737 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1738 true, mWidgetObserver);
1739 }
1740
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001741 @Override
1742 public boolean dispatchKeyEvent(KeyEvent event) {
1743 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1744 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001745 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001746 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001747 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001748 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001749 dumpState();
1750 return true;
1751 }
1752 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001753 }
1754 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1755 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001756 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001757 return true;
1758 }
1759 }
1760
1761 return super.dispatchKeyEvent(event);
1762 }
1763
Joe Onorato88ec0992009-11-19 13:16:06 -08001764 @Override
1765 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001766 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001767 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001768 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001769 Folder openFolder = mWorkspace.getOpenFolder();
1770 if (openFolder.isEditingName()) {
1771 openFolder.dismissEditingName();
1772 } else {
1773 closeFolder();
1774 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001775 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001776 mWorkspace.exitWidgetResizeMode();
1777
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001778 // Back button is a no-op here, but give at least some feedback for the button press
1779 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001780 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001781 }
1782
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001783 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001784 * Re-listen when widgets are reset.
1785 */
1786 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001787 if (mAppWidgetHost != null) {
1788 mAppWidgetHost.startListening();
1789 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001790 }
1791
1792 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001793 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1794 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001795 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001796 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001797 if (mModel != null) {
1798 mModel.unbindWorkspaceItems();
1799 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001800 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001801
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001802 /**
1803 * Launches the intent referred by the clicked shortcut.
1804 *
1805 * @param v The view representing the clicked shortcut.
1806 */
1807 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001808 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1809 // view has detached (it's possible for this to happen if the view is removed mid touch).
1810 if (v.getWindowToken() == null) {
1811 return;
1812 }
1813
Winson Chung9b0b2fe2012-02-24 13:03:34 -08001814 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001815 return;
1816 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001817
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001818 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001819 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001820 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001821 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001822 int[] pos = new int[2];
1823 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001824 intent.setSourceBounds(new Rect(pos[0], pos[1],
1825 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07001826
1827 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001828
1829 if (success && v instanceof BubbleTextView) {
1830 mWaitingForResume = (BubbleTextView) v;
1831 mWaitingForResume.setStayPressed(true);
1832 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001833 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001834 if (v instanceof FolderIcon) {
1835 FolderIcon fi = (FolderIcon) v;
1836 handleFolderClick(fi);
1837 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001838 } else if (v == mAllAppsButton) {
1839 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001840 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001841 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001842 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001843 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001844 }
1845 }
1846
Michael Jurka0e260592010-06-30 17:07:39 -07001847 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001848 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001849 // clicking anywhere on the workspace causes the customization drawer to slide down
1850 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001851 return false;
1852 }
1853
Michael Jurkaaf442092010-06-10 17:01:57 -07001854 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001855 * Event handler for the search button
1856 *
1857 * @param v The view that was clicked.
1858 */
1859 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001860 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1861
Amith Yamasania135ba82011-08-09 17:42:01 -07001862 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001863 }
1864
1865 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001866 * Event handler for the voice button
1867 *
1868 * @param v The view that was clicked.
1869 */
1870 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001871 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001872
Michael Jurkaae65ee32012-04-30 11:45:54 -07001873 try {
1874 final SearchManager searchManager =
1875 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1876 ComponentName activityName = searchManager.getGlobalSearchActivity();
1877 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07001878 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001879 if (activityName != null) {
1880 intent.setPackage(activityName.getPackageName());
1881 }
Michael Jurka86a720e2012-05-09 11:23:23 -07001882 startActivity(null, intent, "onClickVoiceButton");
Winson Chung01b0b632012-05-22 10:18:14 -07001883 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001884 } catch (ActivityNotFoundException e) {
1885 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07001886 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001887 startActivitySafely(null, intent, "onClickVoiceButton");
1888 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001889 }
1890
1891 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001892 * Event handler for the "grid" button that appears on the home screen, which
1893 * enters all apps mode.
1894 *
1895 * @param v The view that was clicked.
1896 */
1897 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001898 showAllApps(true);
1899 }
1900
1901 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001902 // Provide the same haptic feedback that the system offers for virtual keys.
1903 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001904 }
1905
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001906 public void onClickAppMarketButton(View v) {
1907 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07001908 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07001909 } else {
1910 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001911 }
1912 }
1913
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001914 void startApplicationDetailsActivity(ComponentName componentName) {
1915 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001916 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1917 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001918 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07001919 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001920 }
1921
Patrick Dubroy5539af72010-09-07 15:22:01 -07001922 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1923 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1924 // System applications cannot be installed. For now, show a toast explaining that.
1925 // We may give them the option of disabling apps this way.
1926 int messageId = R.string.uninstall_system_app_text;
1927 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1928 } else {
1929 String packageName = appInfo.componentName.getPackageName();
1930 String className = appInfo.componentName.getClassName();
1931 Intent intent = new Intent(
1932 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001933 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1934 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001935 startActivity(intent);
1936 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001937 }
1938
Michael Jurka86a720e2012-05-09 11:23:23 -07001939 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001940 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07001941
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001942 try {
Winson Chung2672ff92012-05-04 16:22:30 -07001943 // Only launch using the new animation if the shortcut has not opted out (this is a
1944 // private contract between launcher and may be ignored in the future).
1945 boolean useLaunchAnimation = (v != null) &&
1946 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
1947 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07001948 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
1949 v.getMeasuredWidth(), v.getMeasuredHeight());
1950
1951 startActivity(intent, opts.toBundle());
1952 } else {
1953 startActivity(intent);
1954 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001955 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001956 } catch (SecurityException e) {
1957 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001958 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001959 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001960 "or use the exported attribute for this activity. "
1961 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001962 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001963 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001964 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001965
Michael Jurka86a720e2012-05-09 11:23:23 -07001966 boolean startActivitySafely(View v, Intent intent, Object tag) {
1967 boolean success = false;
1968 try {
1969 success = startActivity(v, intent, tag);
1970 } catch (ActivityNotFoundException e) {
1971 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1972 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
1973 }
1974 return success;
1975 }
1976
Romain Guy8e633c52010-03-04 12:51:36 -08001977 void startActivityForResultSafely(Intent intent, int requestCode) {
1978 try {
1979 startActivityForResult(intent, requestCode);
1980 } catch (ActivityNotFoundException e) {
1981 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1982 } catch (SecurityException e) {
1983 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1984 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1985 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1986 "or use the exported attribute for this activity.", e);
1987 }
1988 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001989
Adam Cohena9cf38f2011-05-02 15:36:58 -07001990 private void handleFolderClick(FolderIcon folderIcon) {
1991 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07001992 Folder openFolder = mWorkspace.getFolderForTag(info);
1993
1994 // If the folder info reports that the associated folder is open, then verify that
1995 // it is actually opened. There have been a few instances where this gets out of sync.
1996 if (info.opened && openFolder == null) {
1997 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
1998 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
1999 info.opened = false;
2000 }
2001
Adam Cohena9cf38f2011-05-02 15:36:58 -07002002 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003 // Close any open folder
2004 closeFolder();
2005 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002006 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002007 } else {
2008 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002009 int folderScreen;
2010 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002011 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002012 // .. and close it
2013 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002014 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002015 // Close any folder open on the current screen
2016 closeFolder();
2017 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002018 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002019 }
2020 }
2021 }
2022 }
2023
Adam Cohen268c4752012-06-06 17:47:33 -07002024 /**
2025 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2026 * in the DragLayer in the exact absolute location of the original FolderIcon.
2027 */
2028 private void copyFolderIconToImage(FolderIcon fi) {
2029 final int width = fi.getMeasuredWidth();
2030 final int height = fi.getMeasuredHeight();
2031
2032 // Lazy load ImageView, Bitmap and Canvas
2033 if (mFolderIconImageView == null) {
2034 mFolderIconImageView = new ImageView(this);
2035 }
2036 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2037 mFolderIconBitmap.getHeight() != height) {
2038 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2039 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2040 }
2041
2042 DragLayer.LayoutParams lp;
2043 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2044 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2045 } else {
2046 lp = new DragLayer.LayoutParams(width, height);
2047 }
2048
2049 mDragLayer.getViewRectRelativeToSelf(fi, mRectForFolderAnimation);
2050 lp.customPosition = true;
2051 lp.x = mRectForFolderAnimation.left;
2052 lp.y = mRectForFolderAnimation.top;
Adam Cohen8ec23032012-06-08 14:46:22 -07002053 lp.width = width;
2054 lp.height = height;
Adam Cohen268c4752012-06-06 17:47:33 -07002055
2056 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2057 fi.draw(mFolderIconCanvas);
2058 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohen8ec23032012-06-08 14:46:22 -07002059 if (fi.mFolder != null) {
2060 mFolderIconImageView.setPivotX(fi.mFolder.getPivotXForIconAnimation());
2061 mFolderIconImageView.setPivotY(fi.mFolder.getPivotYForIconAnimation());
2062 }
Adam Cohen268c4752012-06-06 17:47:33 -07002063 // Just in case this image view is still in the drag layer from a previous animation,
2064 // we remove it and re-add it.
2065 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2066 mDragLayer.removeView(mFolderIconImageView);
2067 }
2068 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohen8ec23032012-06-08 14:46:22 -07002069 if (fi.mFolder != null) {
2070 fi.mFolder.bringToFront();
2071 }
Adam Cohen268c4752012-06-06 17:47:33 -07002072 }
2073
Adam Cohen2801caf2011-05-13 20:57:39 -07002074 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002075 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002076 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2077 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2078 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2079
Adam Cohenc51934b2011-07-26 21:07:43 -07002080 FolderInfo info = (FolderInfo) fi.getTag();
2081 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2082 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002083 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2084 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002085 }
2086
Adam Cohen268c4752012-06-06 17:47:33 -07002087 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2088 copyFolderIconToImage(fi);
2089 fi.setVisibility(View.INVISIBLE);
2090
2091 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(mFolderIconImageView, alpha,
2092 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002093 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2094 oa.start();
2095 }
2096
Adam Cohen268c4752012-06-06 17:47:33 -07002097 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002098 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002099 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2100 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2101 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2102
Adam Cohen268c4752012-06-06 17:47:33 -07002103 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002104
Adam Cohen268c4752012-06-06 17:47:33 -07002105 // We remove and re-draw the FolderIcon in-case it has changed
2106 mDragLayer.removeView(mFolderIconImageView);
2107 copyFolderIconToImage(fi);
Adam Cohen268c4752012-06-06 17:47:33 -07002108 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(mFolderIconImageView, alpha,
2109 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002110 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002111 oa.addListener(new AnimatorListenerAdapter() {
2112 @Override
2113 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002114 if (cl != null) {
2115 cl.clearFolderLeaveBehind();
2116 // Remove the ImageView copy of the FolderIcon and make the original visible.
2117 mDragLayer.removeView(mFolderIconImageView);
2118 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002119 }
2120 }
2121 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002122 oa.start();
2123 }
2124
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002125 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002126 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002127 * is animated relative to the specified View. If the View is null, no animation
2128 * is played.
2129 *
2130 * @param folderInfo The FolderInfo describing the folder to open.
2131 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002132 public void openFolder(FolderIcon folderIcon) {
2133 Folder folder = folderIcon.mFolder;
2134 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002135
Adam Cohena9cf38f2011-05-02 15:36:58 -07002136 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002137
Adam Cohen4554ee12011-08-03 16:13:21 -07002138 // Just verify that the folder hasn't already been added to the DragLayer.
2139 // There was a one-off crash where the folder had a parent already.
2140 if (folder.getParent() == null) {
2141 mDragLayer.addView(folder);
2142 mDragController.addDropTarget((DropTarget) folder);
2143 } else {
2144 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2145 folder.getParent() + ").");
2146 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002147 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002148 growAndFadeOutFolderIcon(folderIcon);
Adam Cohen4554ee12011-08-03 16:13:21 -07002149 }
2150
2151 public void closeFolder() {
2152 Folder folder = mWorkspace.getOpenFolder();
2153 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002154 if (folder.isEditingName()) {
2155 folder.dismissEditingName();
2156 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002157 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002158
2159 // Dismiss the folder cling
2160 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002161 }
2162 }
2163
2164 void closeFolder(Folder folder) {
2165 folder.getInfo().opened = false;
2166
2167 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2168 if (parent != null) {
2169 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2170 shrinkAndFadeInFolderIcon(fi);
2171 }
2172 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002173 }
2174
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002175 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002176 if (!isDraggingEnabled()) return false;
2177 if (isWorkspaceLocked()) return false;
2178 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002179
2180 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002181 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002182 }
2183
Michael Jurka0280c3b2010-09-17 15:00:07 -07002184 resetAddInfo();
2185 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002186 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002187 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002188 return true;
2189 }
2190
Winson Chung3d503fb2011-07-13 17:25:49 -07002191 // The hotseat touch handling does not go through Workspace, and we always allow long press
2192 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002193 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002194 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2195 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002196 if (itemUnderLongClick == null) {
2197 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002198 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2199 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002200 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002201 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002202 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002203 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002204 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002205 }
2206 }
2207 }
2208 return true;
2209 }
2210
Winson Chung3d503fb2011-07-13 17:25:49 -07002211 boolean isHotseatLayout(View layout) {
2212 return mHotseat != null && layout != null &&
2213 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2214 }
2215 Hotseat getHotseat() {
2216 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002217 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002218 SearchDropTargetBar getSearchBar() {
2219 return mSearchDropTargetBar;
2220 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002221
Winson Chung3d503fb2011-07-13 17:25:49 -07002222 /**
2223 * Returns the CellLayout of the specified container at the specified screen.
2224 */
2225 CellLayout getCellLayout(long container, int screen) {
2226 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2227 if (mHotseat != null) {
2228 return mHotseat.getLayout();
2229 } else {
2230 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002231 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002232 } else {
2233 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002234 }
2235 }
2236
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002237 Workspace getWorkspace() {
2238 return mWorkspace;
2239 }
2240
Daniel Sandler843e8602010-06-07 14:59:01 -04002241 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2242 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002243 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002244 }
2245
Andrew Flynn0dca1ec2012-02-29 13:33:22 -08002246 public boolean isAllAppsButtonRank(int rank) {
2247 return mHotseat.isAllAppsButtonRank(rank);
2248 }
2249
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002250 // AllAppsView.Watcher
2251 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002252 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002253 mWorkspace.setVisibility(View.GONE);
2254 }
2255 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002256
2257 /**
2258 * Helper method for the cameraZoomIn/cameraZoomOut animations
2259 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002260 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002261 * @param scaleFactor The scale factor used for the zoom
2262 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002263 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002264 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002265 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002266 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002267
Winson Chung18f41f82012-05-09 13:28:10 -07002268 void disableWallpaperIfInAllApps() {
2269 // Only disable it if we are in all apps
2270 if (mState == State.APPS_CUSTOMIZE) {
2271 if (mAppsCustomizeTabHost != null &&
2272 !mAppsCustomizeTabHost.isTransitioning()) {
2273 updateWallpaperVisibility(false);
2274 }
2275 }
2276 }
2277
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002278 void updateWallpaperVisibility(boolean visible) {
2279 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2280 int curflags = getWindow().getAttributes().flags
2281 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2282 if (wpflags != curflags) {
2283 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2284 }
2285 }
2286
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002287 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2288 if (v instanceof LauncherTransitionable) {
2289 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2290 }
2291 }
2292
Michael Jurkabed61d22012-02-14 22:51:29 -08002293 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2294 if (v instanceof LauncherTransitionable) {
2295 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2296 }
Winson Chung70442722012-02-10 15:43:22 -08002297
2298 // Update the workspace transition step as well
2299 dispatchOnLauncherTransitionStep(v, 0f);
2300 }
2301
2302 private void dispatchOnLauncherTransitionStep(View v, float t) {
2303 if (v instanceof LauncherTransitionable) {
2304 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2305 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002306 }
2307
2308 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2309 if (v instanceof LauncherTransitionable) {
2310 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2311 }
Winson Chung70442722012-02-10 15:43:22 -08002312
2313 // Update the workspace transition step as well
2314 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002315 }
2316
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002317 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002318 * Things to test when changing the following seven functions.
2319 * - Home from workspace
2320 * - from center screen
2321 * - from other screens
2322 * - Home from all apps
2323 * - from center screen
2324 * - from other screens
2325 * - Back from all apps
2326 * - from center screen
2327 * - from other screens
2328 * - Launch app from workspace and quit
2329 * - with back
2330 * - with home
2331 * - Launch app from all apps and quit
2332 * - with back
2333 * - with home
2334 * - Go to a screen that's not the default, then all
2335 * apps, and launch and app, and go back
2336 * - with back
2337 * -with home
2338 * - On workspace, long press power and go back
2339 * - with back
2340 * - with home
2341 * - On all apps, long press power and go back
2342 * - with back
2343 * - with home
2344 * - On workspace, power off
2345 * - On all apps, power off
2346 * - Launch an app and turn off the screen while in that app
2347 * - Go back with home key
2348 * - Go back with back key TODO: make this not go to workspace
2349 * - From all apps
2350 * - From workspace
2351 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2352 * - From all apps
2353 * - From the center workspace
2354 * - From another workspace
2355 */
2356
2357 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002358 * Zoom the camera out from the workspace to reveal 'toView'.
2359 * Assumes that the view to show is anchored at either the very top or very bottom
2360 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002361 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002362 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002363 if (mStateAnimation != null) {
2364 mStateAnimation.cancel();
2365 mStateAnimation = null;
2366 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002367 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002368
Winson Chungf0ea4d32011-06-06 14:27:16 -07002369 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2370 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2371 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002372 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002373 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002374 final int startDelay =
2375 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002376
Michael Jurkab3e22d92011-10-31 15:58:33 -07002377 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002378
Michael Jurkad74c9842011-07-10 12:44:21 -07002379 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002380 Animator workspaceAnim =
2381 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002382
2383 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002384 toView.setScaleX(scale);
2385 toView.setScaleY(scale);
2386 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2387 scaleAnim.
2388 scaleX(1f).scaleY(1f).
2389 setDuration(duration).
2390 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002391
Winson Chungf0ea4d32011-06-06 14:27:16 -07002392 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002393 toView.setAlpha(0f);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002394 final ObjectAnimator alphaAnim = ObjectAnimator
2395 .ofFloat(toView, "alpha", 0f, 1f)
2396 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002397 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002398 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2399 @Override
2400 public void onAnimationUpdate(ValueAnimator animation) {
2401 float t = (Float) animation.getAnimatedValue();
2402 dispatchOnLauncherTransitionStep(fromView, t);
2403 dispatchOnLauncherTransitionStep(toView, t);
2404 }
2405 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002406
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002407 // toView should appear right at the end of the workspace shrink
2408 // animation
2409 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002410 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002411 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002412
2413 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002414 boolean animationCancelled = false;
2415
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002416 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002417 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002418 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002419 // Prepare the position
2420 toView.setTranslationX(0.0f);
2421 toView.setTranslationY(0.0f);
2422 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002423 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002424 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002425 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002426 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002427 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2428 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002429
2430 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2431 // Hide the workspace scrollbar
2432 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002433 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002434 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002435 if (!animationCancelled) {
2436 updateWallpaperVisibility(false);
2437 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002438
2439 // Hide the search bar
2440 mSearchDropTargetBar.hideSearchBar(false);
Adam Cohenf4ddea32011-09-12 13:46:42 -07002441 }
2442
Adam Cohencff6af82011-09-13 14:51:53 -07002443 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002444 public void onAnimationCancel(Animator animation) {
2445 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002446 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002447 });
2448
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002449 if (workspaceAnim != null) {
2450 mStateAnimation.play(workspaceAnim);
2451 }
Michael Jurka1899a362011-11-03 13:50:45 -07002452
2453 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002454 final ViewTreeObserver observer;
2455
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002456 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2457 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002458
2459 // If any of the objects being animated haven't been measured/laid out
2460 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002461 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002462 (mWorkspace.getMeasuredWidth() == 0) ||
2463 (toView.getMeasuredWidth() == 0)) {
2464 observer = mWorkspace.getViewTreeObserver();
2465 delayAnim = true;
2466 } else {
2467 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002468 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002469
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002470 final AnimatorSet stateAnimation = mStateAnimation;
2471 final Runnable startAnimRunnable = new Runnable() {
2472 public void run() {
2473 // Check that mStateAnimation hasn't changed while
2474 // we waited for a layout/draw pass
2475 if (mStateAnimation != stateAnimation)
2476 return;
2477 setPivotsForZoom(toView, scale);
2478 dispatchOnLauncherTransitionStart(fromView, animated, false);
2479 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurka382aa182012-06-11 15:42:07 -07002480 toView.post(new Runnable() {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002481 public void run() {
2482 // Check that mStateAnimation hasn't changed while
2483 // we waited for a layout/draw pass
2484 if (mStateAnimation != stateAnimation)
2485 return;
2486 mStateAnimation.start();
2487 }
2488 });
2489 }
2490 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002491 if (delayAnim) {
2492 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2493 public void onGlobalLayout() {
Michael Jurka382aa182012-06-11 15:42:07 -07002494 toView.post(startAnimRunnable);
Michael Jurka3a9fced2012-04-13 14:44:29 -07002495 observer.removeOnGlobalLayoutListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002496 }
2497 };
2498 observer.addOnGlobalLayoutListener(delayedStart);
2499 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002500 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002501 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002502 } else {
2503 toView.setTranslationX(0.0f);
2504 toView.setTranslationY(0.0f);
2505 toView.setScaleX(1.0f);
2506 toView.setScaleY(1.0f);
2507 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002508 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002509
Michael Jurkabed61d22012-02-14 22:51:29 -08002510 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2511 // Hide the workspace scrollbar
2512 mWorkspace.hideScrollingIndicator(true);
2513 hideDockDivider();
Winson Chungc7d2b602012-05-16 17:02:20 -07002514
2515 // Hide the search bar
2516 mSearchDropTargetBar.hideSearchBar(false);
Michael Jurkaabded662011-03-04 12:06:57 -08002517 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002518 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002519 dispatchOnLauncherTransitionStart(fromView, animated, false);
2520 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002521 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002522 dispatchOnLauncherTransitionStart(toView, animated, false);
2523 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002524 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002525 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002526 }
2527
2528 /**
2529 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002530 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002531 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002532 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002533 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2534 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002535
Michael Jurkab3e22d92011-10-31 15:58:33 -07002536 if (mStateAnimation != null) {
2537 mStateAnimation.cancel();
2538 mStateAnimation = null;
2539 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002540 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002541
Winson Chungf0ea4d32011-06-06 14:27:16 -07002542 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002543 final int fadeOutDuration =
2544 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002545 final float scaleFactor = (float)
2546 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2547 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002548 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002549 Animator workspaceAnim = null;
2550
2551 if (toState == State.WORKSPACE) {
2552 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2553 workspaceAnim = mWorkspace.getChangeStateAnimation(
2554 Workspace.State.NORMAL, animated, stagger);
2555 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2556 workspaceAnim = mWorkspace.getChangeStateAnimation(
2557 Workspace.State.SPRING_LOADED, animated);
2558 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002559
Michael Jurkab3e22d92011-10-31 15:58:33 -07002560 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002561 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002562 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002563 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002564 final LauncherViewPropertyAnimator scaleAnim =
2565 new LauncherViewPropertyAnimator(fromView);
2566 scaleAnim.
2567 scaleX(scaleFactor).scaleY(scaleFactor).
2568 setDuration(duration).
2569 setInterpolator(new Workspace.ZoomInInterpolator());
2570
2571 final ObjectAnimator alphaAnim = ObjectAnimator
2572 .ofFloat(fromView, "alpha", 1f, 0f)
2573 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002574 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002575 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2576 @Override
2577 public void onAnimationUpdate(ValueAnimator animation) {
2578 float t = 1f - (Float) animation.getAnimatedValue();
2579 dispatchOnLauncherTransitionStep(fromView, t);
2580 dispatchOnLauncherTransitionStep(toView, t);
2581 }
2582 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002583
Michael Jurkabed61d22012-02-14 22:51:29 -08002584 mStateAnimation = new AnimatorSet();
2585
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002586 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2587 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002588
2589 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002590 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002591 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002592 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002593 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002594 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2595 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkabafdaaf2012-04-26 13:43:25 -07002596 if (mWorkspace != null) {
2597 mWorkspace.hideScrollingIndicator(false);
2598 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002599 if (onCompleteRunnable != null) {
2600 onCompleteRunnable.run();
2601 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002602 }
2603 });
2604
Winson Chungf0ea4d32011-06-06 14:27:16 -07002605 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002606 if (workspaceAnim != null) {
2607 mStateAnimation.play(workspaceAnim);
2608 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002609 dispatchOnLauncherTransitionStart(fromView, animated, true);
2610 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002611 final Animator stateAnimation = mStateAnimation;
2612 mWorkspace.post(new Runnable() {
2613 public void run() {
2614 if (stateAnimation != mStateAnimation)
2615 return;
2616 mStateAnimation.start();
2617 }
2618 });
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002619 } else {
2620 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002621 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002622 dispatchOnLauncherTransitionStart(fromView, animated, true);
2623 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002624 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002625 dispatchOnLauncherTransitionStart(toView, animated, true);
2626 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002627 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002628 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002629 }
2630
Michael Jurkae326f182011-11-21 14:05:46 -08002631 @Override
2632 public void onTrimMemory(int level) {
2633 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002634 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002635 mAppsCustomizeTabHost.onTrimMemory();
2636 }
2637 }
2638
Winson Chung18f41f82012-05-09 13:28:10 -07002639 @Override
2640 public void onWindowFocusChanged(boolean hasFocus) {
2641 if (!hasFocus) {
2642 // When another window occludes launcher (like the notification shade, or recents),
2643 // ensure that we enable the wallpaper flag so that transitions are done correctly.
2644 updateWallpaperVisibility(true);
2645 } else {
2646 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07002647 mWorkspace.postDelayed(new Runnable() {
2648 @Override
2649 public void run() {
2650 disableWallpaperIfInAllApps();
2651 }
2652 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07002653 }
2654 }
2655
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002656 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002657 showWorkspace(animated, null);
2658 }
2659
2660 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002661 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002662 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002663 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002664 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002665
Winson Chungc7d2b602012-05-16 17:02:20 -07002666 // Show the search bar (only animate if we were showing the drop target bar in spring
2667 // loaded mode)
2668 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
2669
Michael Jurkab737ee62011-11-15 15:57:22 -08002670 // We only need to animate in the dock divider if we're going from spring loaded mode
Winson Chungc7d2b602012-05-16 17:02:20 -07002671 showDockDivider(animated && wasInSpringLoadedMode);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002672
2673 // Set focus to the AppsCustomize button
2674 if (mAllAppsButton != null) {
2675 mAllAppsButton.requestFocus();
2676 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002677 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002678
Michael Jurkab737ee62011-11-15 15:57:22 -08002679 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002680
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002681 // Change the state *after* we've called all the transition code
2682 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002683
Winson Chung5fb63472011-02-02 17:03:37 -08002684 // Resume the auto-advance of widgets
2685 mUserPresent = true;
2686 updateRunning();
2687
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002688 // send an accessibility event to announce the context change
2689 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002690 }
2691
Michael Jurkab3e22d92011-10-31 15:58:33 -07002692 void showAllApps(boolean animated) {
2693 if (mState != State.WORKSPACE) return;
2694
2695 showAppsCustomizeHelper(animated, false);
2696 mAppsCustomizeTabHost.requestFocus();
2697
Michael Jurkab3e22d92011-10-31 15:58:33 -07002698 // Change the state *after* we've called all the transition code
2699 mState = State.APPS_CUSTOMIZE;
2700
2701 // Pause the auto-advance of widgets until we are out of AllApps
2702 mUserPresent = false;
2703 updateRunning();
2704 closeFolder();
2705
2706 // Send an accessibility event to announce the context change
2707 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2708 }
2709
Adam Cohen7777d962011-08-18 18:58:38 -07002710 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002711 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002712 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002713 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002714 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002715 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002716 }
Adam Cohen7777d962011-08-18 18:58:38 -07002717
Adam Cohened66b2b2012-01-23 17:28:51 -08002718 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2719 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002720 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2721
Winson Chunge7a03942011-08-05 15:05:12 -07002722 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002723 @Override
2724 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002725 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002726 // Before we show workspace, hide all apps again because
2727 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2728 // clean up our state transition functions
2729 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002730 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002731 } else {
2732 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002733 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002734 }
2735 }, (extendedDelay ?
2736 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2737 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2738 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002739
Michael Jurkad3ef3062010-11-23 16:23:58 -08002740 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002741 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002742 final boolean animated = true;
2743 final boolean springLoaded = true;
2744 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002745 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002746 }
2747 // Otherwise, we are not in spring loaded mode, so don't do anything.
2748 }
2749
Michael Jurkab737ee62011-11-15 15:57:22 -08002750 void hideDockDivider() {
2751 if (mQsbDivider != null && mDockDivider != null) {
2752 mQsbDivider.setVisibility(View.INVISIBLE);
2753 mDockDivider.setVisibility(View.INVISIBLE);
2754 }
2755 }
2756
2757 void showDockDivider(boolean animated) {
2758 if (mQsbDivider != null && mDockDivider != null) {
2759 mQsbDivider.setVisibility(View.VISIBLE);
2760 mDockDivider.setVisibility(View.VISIBLE);
2761 if (mDividerAnimator != null) {
2762 mDividerAnimator.cancel();
2763 mQsbDivider.setAlpha(1f);
2764 mDockDivider.setAlpha(1f);
2765 mDividerAnimator = null;
2766 }
2767 if (animated) {
2768 mDividerAnimator = new AnimatorSet();
2769 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2770 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2771 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2772 mDividerAnimator.start();
2773 }
2774 }
2775 }
2776
Michael Jurkab3e22d92011-10-31 15:58:33 -07002777 void lockAllApps() {
2778 // TODO
2779 }
2780
2781 void unlockAllApps() {
2782 // TODO
2783 }
2784
Adam Cohenfc53cd22011-07-20 15:45:11 -07002785 public boolean isAllAppsCustomizeOpen() {
2786 return mState == State.APPS_CUSTOMIZE;
2787 }
2788
Winson Chungf0ea4d32011-06-06 14:27:16 -07002789 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002790 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002791 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002792 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002793 if (!LauncherApplication.isScreenLarge()) {
2794 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002795 if (mHotseat.getAlpha() != 1f) {
2796 int duration = mSearchDropTargetBar.getTransitionInDuration();
2797 mHotseat.animate().alpha(1f).setDuration(duration);
2798 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002799 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002800 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002801 }
2802 }
2803 }
2804
2805 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002806 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002807 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002808 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002809 if (!LauncherApplication.isScreenLarge()) {
2810 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002811 if (mHotseat.getAlpha() != 0f) {
2812 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2813 mHotseat.animate().alpha(0f).setDuration(duration);
2814 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002815 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002816 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002817 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002818 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002819 }
2820
Patrick Dubroy5f445422011-02-18 14:35:21 -08002821 /**
2822 * Add an item from all apps or customize onto the given workspace screen.
2823 * If layout is null, add to the current screen.
2824 */
2825 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002826 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07002827 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07002828 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002829 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002830
Winson Chungdff8ebb2011-09-08 17:25:31 -07002831 /** Maps the current orientation to an index for referencing orientation correct global icons */
2832 private int getCurrentOrientationIndexForGlobalIcons() {
2833 // default - 0, landscape - 1
2834 switch (getResources().getConfiguration().orientation) {
2835 case Configuration.ORIENTATION_LANDSCAPE:
2836 return 1;
2837 default:
2838 return 0;
2839 }
2840 }
2841
Michael Jurkaae65ee32012-04-30 11:45:54 -07002842 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002843 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002844 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002845 // Look for the toolbar icon specified in the activity meta-data
2846 Bundle metaData = packageManager.getActivityInfo(
2847 activityName, PackageManager.GET_META_DATA).metaData;
2848 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002849 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002850 if (iconResId != 0) {
2851 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002852 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002853 }
2854 }
2855 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002856 // This can happen if the activity defines an invalid drawable
2857 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2858 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002859 } catch (Resources.NotFoundException nfe) {
2860 // This can happen if the activity defines an invalid drawable
2861 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2862 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002863 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002864 return null;
2865 }
2866
2867 // if successful in getting icon, return it; otherwise, set button to use default drawable
2868 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002869 int buttonId, ComponentName activityName, int fallbackDrawableId,
2870 String toolbarResourceName) {
2871 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002872 Resources r = getResources();
2873 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2874 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002875
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002876 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002877 // If we were unable to find the icon via the meta-data, use a generic one
2878 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002879 toolbarIcon = r.getDrawable(fallbackDrawableId);
2880 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002881 if (button != null) {
2882 button.setCompoundDrawables(toolbarIcon, null, null, null);
2883 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002884 return null;
2885 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002886 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002887 if (button != null) {
2888 button.setCompoundDrawables(toolbarIcon, null, null, null);
2889 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002890 return toolbarIcon.getConstantState();
2891 }
2892 }
2893
2894 // if successful in getting icon, return it; otherwise, set button to use default drawable
2895 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002896 int buttonId, ComponentName activityName, int fallbackDrawableId,
2897 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002898 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002899 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002900
Michael Jurka19e0fc52011-07-22 18:00:21 -07002901 if (button != null) {
2902 // If we were unable to find the icon via the meta-data, use a
2903 // generic one
2904 if (toolbarIcon == null) {
2905 button.setImageResource(fallbackDrawableId);
2906 } else {
2907 button.setImageDrawable(toolbarIcon);
2908 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002909 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002910
2911 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2912
Michael Jurka0423dcf2010-10-05 14:56:18 -07002913 }
2914
Winson Chung1b884092012-06-08 17:13:02 -07002915 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002916 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07002917 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002918 }
2919
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002920 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002921 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002922 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002923 }
2924
Winson Chungbb185bd2011-11-21 12:31:42 -08002925 private void invalidatePressedFocusedStates(View container, View button) {
2926 if (container instanceof HolographicLinearLayout) {
2927 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2928 layout.invalidatePressedFocusedStates();
2929 } else if (button instanceof HolographicImageView) {
2930 HolographicImageView view = (HolographicImageView) button;
2931 view.invalidatePressedFocusedStates();
2932 }
2933 }
2934
Winson Chungc51db6a2011-10-05 11:44:49 -07002935 private boolean updateGlobalSearchIcon() {
2936 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002937 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2938 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002939 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002940 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07002941 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07002942
Winson Chung1cad91e2011-05-25 17:41:01 -07002943 final SearchManager searchManager =
2944 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2945 ComponentName activityName = searchManager.getGlobalSearchActivity();
2946 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002947 int coi = getCurrentOrientationIndexForGlobalIcons();
2948 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002949 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2950 TOOLBAR_SEARCH_ICON_METADATA_NAME);
2951 if (sGlobalSearchIcon[coi] == null) {
2952 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
2953 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2954 TOOLBAR_ICON_METADATA_NAME);
2955 }
2956
Winson Chung649723c2011-07-06 20:41:23 -07002957 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002958 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2959 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002960 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002961 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002962 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002963 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002964 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002965 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2966 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2967 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002968 voiceButton.setVisibility(View.GONE);
Michael Jurkac60498a2012-05-07 15:29:42 -07002969 if (voiceButtonProxy != null) {
2970 voiceButtonProxy.setVisibility(View.GONE);
2971 }
Winson Chungc51db6a2011-10-05 11:44:49 -07002972 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002973 }
2974 }
2975
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002976 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002977 final View searchButtonContainer = findViewById(R.id.search_button_container);
2978 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002979 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002980 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002981 }
2982
Winson Chungc51db6a2011-10-05 11:44:49 -07002983 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002984 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002985 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002986 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07002987 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07002988
Winson Chungc51db6a2011-10-05 11:44:49 -07002989 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07002990 final SearchManager searchManager =
2991 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2992 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2993
2994 ComponentName activityName = null;
2995 if (globalSearchActivity != null) {
2996 // Check if the global search activity handles voice search
2997 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2998 intent.setPackage(globalSearchActivity.getPackageName());
2999 activityName = intent.resolveActivity(getPackageManager());
3000 }
3001
3002 if (activityName == null) {
3003 // Fallback: check if an activity other than the global search activity
3004 // resolves this
3005 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3006 activityName = intent.resolveActivity(getPackageManager());
3007 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003008 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003009 int coi = getCurrentOrientationIndexForGlobalIcons();
3010 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003011 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3012 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3013 if (sVoiceSearchIcon[coi] == null) {
3014 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3015 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3016 TOOLBAR_ICON_METADATA_NAME);
3017 }
Winson Chung649723c2011-07-06 20:41:23 -07003018 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07003019 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003020 voiceButton.setVisibility(View.VISIBLE);
Jim Miller14091b12012-04-24 19:27:54 -07003021 if (voiceButtonProxy != null) {
3022 voiceButtonProxy.setVisibility(View.VISIBLE);
3023 }
Winson Chungbb185bd2011-11-21 12:31:42 -08003024 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003025 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003026 } else {
Winson Chung649723c2011-07-06 20:41:23 -07003027 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07003028 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003029 voiceButton.setVisibility(View.GONE);
Jim Miller14091b12012-04-24 19:27:54 -07003030 if (voiceButtonProxy != null) {
3031 voiceButtonProxy.setVisibility(View.GONE);
3032 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003033 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003034 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003035 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003036
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003037 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003038 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3039 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003040 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003041 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003042 }
3043
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003044 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003045 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003046 */
3047 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003048 final View marketButton = findViewById(R.id.market_button);
3049 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3050 // Find the app market activity by resolving an intent.
3051 // (If multiple app markets are installed, it will return the ResolverActivity.)
3052 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003053 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003054 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003055 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003056 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003057 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3058 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003059 marketButton.setVisibility(View.VISIBLE);
3060 } else {
3061 // We should hide and disable the view so that we don't try and restore the visibility
3062 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3063 marketButton.setVisibility(View.GONE);
3064 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003065 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003066 }
3067
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003068 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chung1b884092012-06-08 17:13:02 -07003069 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3070 Resources r = getResources();
3071 Drawable marketIconDrawable = d.newDrawable(r);
3072 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3073 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3074 marketIconDrawable.setBounds(0, 0, w, h);
3075
3076 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003077 }
3078
Michael Jurkad7c28052012-04-27 15:43:36 -07003079 @Override
3080 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
3081 boolean result = super.dispatchPopulateAccessibilityEvent(event);
3082 final List<CharSequence> text = event.getText();
3083 text.clear();
3084 text.add(getString(R.string.home));
3085 return result;
3086 }
3087
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003088 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003089 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003090 */
3091 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3092 @Override
3093 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003094 closeSystemDialogs();
3095 }
3096 }
3097
3098 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003099 * Receives notifications whenever the appwidgets are reset.
3100 */
3101 private class AppWidgetResetObserver extends ContentObserver {
3102 public AppWidgetResetObserver() {
3103 super(new Handler());
3104 }
3105
3106 @Override
3107 public void onChange(boolean selfChange) {
3108 onAppWidgetReset();
3109 }
3110 }
3111
3112 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003113 * If the activity is currently paused, signal that we need to re-run the loader
3114 * in onResume.
3115 *
3116 * This needs to be called from incoming places where resources might have been loaded
3117 * while we are paused. That is becaues the Configuration might be wrong
3118 * when we're not running, and if it comes back to what it was when we
3119 * were paused, we are not restarted.
3120 *
3121 * Implementation of the method from LauncherModel.Callbacks.
3122 *
3123 * @return true if we are currently paused. The caller might be able to
3124 * skip some work in that case since we will come back again.
3125 */
3126 public boolean setLoadOnResume() {
3127 if (mPaused) {
3128 Log.i(TAG, "setLoadOnResume");
3129 mOnResumeNeedsLoad = true;
3130 return true;
3131 } else {
3132 return false;
3133 }
3134 }
3135
3136 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003137 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003138 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003139 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003140 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003141 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003142 } else {
3143 return SCREEN_COUNT / 2;
3144 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003145 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003146
Joe Onorato9c1289c2009-08-17 11:03:03 -04003147 /**
3148 * Refreshes the shortcuts shown on the workspace.
3149 *
3150 * Implementation of the method from LauncherModel.Callbacks.
3151 */
3152 public void startBinding() {
3153 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07003154
Winson Chungf0c6ae02012-03-21 16:10:31 -07003155 mNewShortcutAnimatePage = -1;
3156 mNewShortcutAnimateViews.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003157 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003158 int count = workspace.getChildCount();
3159 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003160 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003161 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3162 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003163 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08003164 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003165 if (mHotseat != null) {
3166 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003167 }
3168 }
3169
3170 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003171 * Bind the items start-end from the list.
3172 *
3173 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003174 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003175 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003176 setLoadOnResume();
3177
Winson Chungf0c6ae02012-03-21 16:10:31 -07003178 // Get the list of added shortcuts and intersect them with the set of shortcuts here
3179 Set<String> newApps = new HashSet<String>();
3180 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);
3181
3182 Workspace workspace = mWorkspace;
3183 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003184 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003185
3186 // Short circuit if we are loading dock items for a configuration which has no dock
3187 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3188 mHotseat == null) {
3189 continue;
3190 }
3191
Joe Onorato9c1289c2009-08-17 11:03:03 -04003192 switch (item.itemType) {
3193 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3194 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003195 ShortcutInfo info = (ShortcutInfo) item;
3196 String uri = info.intent.toUri(0).toString();
3197 View shortcut = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -07003198 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3199 item.cellY, 1, 1, false);
Winson Chungbfeac062012-06-06 15:56:08 -07003200 boolean animateIconUp = false;
3201 synchronized (newApps) {
3202 if (newApps.contains(uri)) {
3203 animateIconUp = newApps.remove(uri);
3204 }
3205 }
3206 if (animateIconUp) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003207 // Prepare the view to be animated up
3208 shortcut.setAlpha(0f);
3209 shortcut.setScaleX(0f);
3210 shortcut.setScaleY(0f);
3211 mNewShortcutAnimatePage = item.screen;
3212 if (!mNewShortcutAnimateViews.contains(shortcut)) {
3213 mNewShortcutAnimateViews.add(shortcut);
3214 }
3215 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003216 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003217 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003218 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003219 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003220 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003221 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3222 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003223 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003224 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003225 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003226
Joe Onorato9c1289c2009-08-17 11:03:03 -04003227 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003228 }
3229
Joe Onorato9c1289c2009-08-17 11:03:03 -04003230 /**
3231 * Implementation of the method from LauncherModel.Callbacks.
3232 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003233 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003234 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003235 sFolders.clear();
3236 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003237 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003238
3239 /**
3240 * Add the views for a widget to the workspace.
3241 *
3242 * Implementation of the method from LauncherModel.Callbacks.
3243 */
3244 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003245 setLoadOnResume();
3246
Daniel Sandler843e8602010-06-07 14:59:01 -04003247 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3248 if (DEBUG_WIDGETS) {
3249 Log.d(TAG, "bindAppWidget: " + item);
3250 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003251 final Workspace workspace = mWorkspace;
3252
3253 final int appWidgetId = item.appWidgetId;
3254 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003255 if (DEBUG_WIDGETS) {
3256 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3257 }
3258
Joe Onorato9c1289c2009-08-17 11:03:03 -04003259 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3260
Joe Onorato9c1289c2009-08-17 11:03:03 -04003261 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003262 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003263
Winson Chung3d503fb2011-07-13 17:25:49 -07003264 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003265 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003266 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3267
Joe Onorato9c1289c2009-08-17 11:03:03 -04003268 workspace.requestLayout();
3269
Daniel Sandler843e8602010-06-07 14:59:01 -04003270 if (DEBUG_WIDGETS) {
3271 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3272 + (SystemClock.uptimeMillis()-start) + "ms");
3273 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003274 }
3275
3276 /**
3277 * Callback saying that there aren't any more items to bind.
3278 *
3279 * Implementation of the method from LauncherModel.Callbacks.
3280 */
3281 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003282 setLoadOnResume();
3283
Joe Onorato9c1289c2009-08-17 11:03:03 -04003284 if (mSavedState != null) {
3285 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003286 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003287 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003288 mSavedState = null;
3289 }
3290
3291 if (mSavedInstanceState != null) {
3292 super.onRestoreInstanceState(mSavedInstanceState);
3293 mSavedInstanceState = null;
3294 }
3295
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003296 // If we received the result of any pending adds while the loader was running (e.g. the
3297 // widget configuration forced an orientation change), process them now.
3298 for (int i = 0; i < sPendingAddList.size(); i++) {
3299 completeAdd(sPendingAddList.get(i));
3300 }
3301 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003302
Winson Chungc51db6a2011-10-05 11:44:49 -07003303 // Update the market app icon as necessary (the other icons will be managed in response to
3304 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003305 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003306
Winson Chungf0c6ae02012-03-21 16:10:31 -07003307 // Animate up any icons as necessary
3308 if (mVisible || mWorkspaceLoading) {
3309 Runnable newAppsRunnable = new Runnable() {
3310 @Override
3311 public void run() {
Winson Chunga2413752012-04-03 14:22:34 -07003312 runNewAppsAnimation(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003313 }
3314 };
Winson Chunga2413752012-04-03 14:22:34 -07003315
3316 boolean willSnapPage = mNewShortcutAnimatePage > -1 &&
3317 mNewShortcutAnimatePage != mWorkspace.getCurrentPage();
3318 if (canRunNewAppsAnimation()) {
3319 // If the user has not interacted recently, then either snap to the new page to show
3320 // the new-apps animation or just run them if they are to appear on the current page
3321 if (willSnapPage) {
3322 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable);
3323 } else {
3324 runNewAppsAnimation(false);
3325 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003326 } else {
Winson Chung318eee02012-04-12 10:59:27 -07003327 // If the user has interacted recently, then just add the items in place if they
Winson Chunga2413752012-04-03 14:22:34 -07003328 // are on another page (or just normally if they are added to the current page)
3329 runNewAppsAnimation(willSnapPage);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003330 }
3331 }
3332
3333 mWorkspaceLoading = false;
3334 }
3335
Winson Chunga2413752012-04-03 14:22:34 -07003336 private boolean canRunNewAppsAnimation() {
3337 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3338 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3339 }
3340
Winson Chungf0c6ae02012-03-21 16:10:31 -07003341 /**
3342 * Runs a new animation that scales up icons that were added while Launcher was in the
3343 * background.
Winson Chunga2413752012-04-03 14:22:34 -07003344 *
3345 * @param immediate whether to run the animation or show the results immediately
Winson Chungf0c6ae02012-03-21 16:10:31 -07003346 */
Winson Chunga2413752012-04-03 14:22:34 -07003347 private void runNewAppsAnimation(boolean immediate) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003348 AnimatorSet anim = new AnimatorSet();
3349 Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chunga2413752012-04-03 14:22:34 -07003350
3351 // Order these new views spatially so that they animate in order
Winson Chungf0c6ae02012-03-21 16:10:31 -07003352 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
3353 @Override
3354 public int compare(View a, View b) {
3355 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
3356 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
3357 int cellCountX = LauncherModel.getCellCountX();
3358 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
3359 }
3360 });
Winson Chunga2413752012-04-03 14:22:34 -07003361
3362 // Animate each of the views in place (or show them immediately if requested)
3363 if (immediate) {
3364 for (View v : mNewShortcutAnimateViews) {
3365 v.setAlpha(1f);
3366 v.setScaleX(1f);
3367 v.setScaleY(1f);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003368 }
Winson Chunga2413752012-04-03 14:22:34 -07003369 } else {
3370 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
3371 View v = mNewShortcutAnimateViews.get(i);
3372 ValueAnimator bounceAnim = ObjectAnimator.ofPropertyValuesHolder(v,
3373 PropertyValuesHolder.ofFloat("alpha", 1f),
3374 PropertyValuesHolder.ofFloat("scaleX", 1f),
3375 PropertyValuesHolder.ofFloat("scaleY", 1f));
3376 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3377 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3378 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3379 bounceAnims.add(bounceAnim);
3380 }
3381 anim.playTogether(bounceAnims);
3382 anim.addListener(new AnimatorListenerAdapter() {
3383 @Override
3384 public void onAnimationEnd(Animator animation) {
3385 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
3386 }
3387 });
3388 anim.start();
3389 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003390
3391 // Clean up
3392 mNewShortcutAnimatePage = -1;
3393 mNewShortcutAnimateViews.clear();
3394 new Thread("clearNewAppsThread") {
3395 public void run() {
3396 mSharedPrefs.edit()
3397 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
3398 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null)
3399 .commit();
3400 }
3401 }.start();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003402 }
3403
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003404 @Override
3405 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003406 boolean searchVisible = updateGlobalSearchIcon();
3407 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3408 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003409 }
3410
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003411 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003412 * Add the icons for all apps.
3413 *
3414 * Implementation of the method from LauncherModel.Callbacks.
3415 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003416 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3417 // Remove the progress bar entirely; we could also make it GONE
3418 // but better to remove it since we know it's not going to be used
3419 View progressBar = mAppsCustomizeTabHost.
3420 findViewById(R.id.apps_customize_progress_bar);
3421 if (progressBar != null) {
3422 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003423 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003424 // We just post the call to setApps so the user sees the progress bar
3425 // disappear-- otherwise, it just looks like the progress bar froze
3426 // which doesn't look great
3427 mAppsCustomizeTabHost.post(new Runnable() {
3428 public void run() {
3429 if (mAppsCustomizeContent != null) {
3430 mAppsCustomizeContent.setApps(apps);
3431 }
3432 }
3433 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003434 }
3435
3436 /**
3437 * A package was installed.
3438 *
3439 * Implementation of the method from LauncherModel.Callbacks.
3440 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003441 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003442 setLoadOnResume();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003443
Winson Chung785d2eb2011-04-14 16:08:02 -07003444 if (mAppsCustomizeContent != null) {
3445 mAppsCustomizeContent.addApps(apps);
3446 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003447 }
3448
3449 /**
3450 * A package was updated.
3451 *
3452 * Implementation of the method from LauncherModel.Callbacks.
3453 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003454 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003455 setLoadOnResume();
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003456 if (mWorkspace != null) {
3457 mWorkspace.updateShortcuts(apps);
3458 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003459
Winson Chung785d2eb2011-04-14 16:08:02 -07003460 if (mAppsCustomizeContent != null) {
3461 mAppsCustomizeContent.updateApps(apps);
3462 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003463 }
3464
3465 /**
3466 * A package was uninstalled.
3467 *
3468 * Implementation of the method from LauncherModel.Callbacks.
3469 */
Joe Onorato36115782010-06-17 13:28:48 -04003470 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato36115782010-06-17 13:28:48 -04003471 if (permanent) {
3472 mWorkspace.removeItems(apps);
3473 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003474
Winson Chung785d2eb2011-04-14 16:08:02 -07003475 if (mAppsCustomizeContent != null) {
3476 mAppsCustomizeContent.removeApps(apps);
3477 }
Winson Chunga1820962011-10-03 16:31:06 -07003478
3479 // Notify the drag controller
3480 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003481 }
Joe Onoratobe386092009-11-17 17:32:16 -08003482
3483 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003484 * A number of packages were updated.
3485 */
3486 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003487 if (mAppsCustomizeContent != null) {
3488 mAppsCustomizeContent.onPackagesUpdated();
3489 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003490 }
3491
Winson Chung400438b2011-01-16 17:53:48 -08003492 private int mapConfigurationOriActivityInfoOri(int configOri) {
3493 final Display d = getWindowManager().getDefaultDisplay();
3494 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3495 switch (d.getRotation()) {
3496 case Surface.ROTATION_0:
3497 case Surface.ROTATION_180:
3498 // We are currently in the same basic orientation as the natural orientation
3499 naturalOri = configOri;
3500 break;
3501 case Surface.ROTATION_90:
3502 case Surface.ROTATION_270:
3503 // We are currently in the other basic orientation to the natural orientation
3504 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3505 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3506 break;
3507 }
3508
3509 int[] oriMap = {
3510 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3511 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3512 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3513 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3514 };
3515 // Since the map starts at portrait, we need to offset if this device's natural orientation
3516 // is landscape.
3517 int indexOffset = 0;
3518 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3519 indexOffset = 1;
3520 }
3521 return oriMap[(d.getRotation() + indexOffset) % 4];
3522 }
Adam Cohen446e9402011-09-15 18:21:21 -07003523
Winson Chung4b919f82012-05-01 10:44:08 -07003524 public boolean isRotationEnabled() {
3525 boolean forceEnableRotation = "true".equalsIgnoreCase(SystemProperties.get(
3526 FORCE_ENABLE_ROTATION_PROPERTY, "false"));
3527 boolean enableRotation = forceEnableRotation ||
3528 getResources().getBoolean(R.bool.allow_rotation);
3529 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08003530 }
Winson Chung4b919f82012-05-01 10:44:08 -07003531 public void lockScreenOrientation() {
3532 if (isRotationEnabled()) {
3533 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3534 .getConfiguration().orientation));
3535 }
3536 }
3537 public void unlockScreenOrientation(boolean immediate) {
3538 if (isRotationEnabled()) {
3539 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07003540 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07003541 } else {
3542 mHandler.postDelayed(new Runnable() {
3543 public void run() {
3544 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3545 }
3546 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07003547 }
Winson Chung4b919f82012-05-01 10:44:08 -07003548 }
Winson Chung400438b2011-01-16 17:53:48 -08003549 }
3550
Winson Chung82f55532011-08-09 14:14:23 -07003551 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003552 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003553 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003554 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003555
Winson Chung7d7541e2011-09-16 20:14:36 -07003556 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003557 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003558 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3559 Cling cling = (Cling) findViewById(clingId);
3560 if (cling != null) {
3561 cling.init(this, positionData);
3562 cling.setVisibility(View.VISIBLE);
3563 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Svetoslav Ganov55d225d2012-05-22 15:19:14 -07003564 cling.requestAccessibilityFocus();
Winson Chung7d7541e2011-09-16 20:14:36 -07003565 if (animate) {
3566 cling.buildLayer();
3567 cling.setAlpha(0f);
3568 cling.animate()
3569 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003570 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003571 .setDuration(SHOW_CLING_DURATION)
3572 .setStartDelay(delay)
3573 .start();
3574 } else {
3575 cling.setAlpha(1f);
3576 }
3577 }
3578 return cling;
3579 }
3580 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003581 if (cling != null) {
3582 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003583 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003584 anim.addListener(new AnimatorListenerAdapter() {
3585 public void onAnimationEnd(Animator animation) {
3586 cling.setVisibility(View.GONE);
3587 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003588 // We should update the shared preferences on a background thread
3589 new Thread("dismissClingThread") {
3590 public void run() {
3591 SharedPreferences.Editor editor = mSharedPrefs.edit();
3592 editor.putBoolean(flag, true);
3593 editor.commit();
3594 }
3595 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003596 };
3597 });
3598 anim.start();
3599 }
3600 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003601 private void removeCling(int id) {
3602 final View cling = findViewById(id);
3603 if (cling != null) {
3604 final ViewGroup parent = (ViewGroup) cling.getParent();
3605 parent.post(new Runnable() {
3606 @Override
3607 public void run() {
3608 parent.removeView(cling);
3609 }
3610 });
3611 }
3612 }
Michael Jurka974c3862012-05-22 22:00:31 -07003613
3614 private boolean skipCustomClingIfNoAccounts() {
3615 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3616 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
3617 if (customCling) {
3618 AccountManager am = AccountManager.get(this);
3619 Account[] accounts = am.getAccountsByType("com.google");
3620 return accounts.length == 0;
3621 }
3622 return false;
3623 }
3624
Winson Chung7d7541e2011-09-16 20:14:36 -07003625 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003626 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003627 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07003628 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
3629 !skipCustomClingIfNoAccounts() ) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003630 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003631 } else {
3632 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003633 }
3634 }
3635 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003636 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003637 if (isClingsEnabled() &&
3638 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003639 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003640 } else {
3641 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003642 }
3643 }
3644 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003645 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003646 if (isClingsEnabled() &&
3647 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
3648 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003649 } else {
3650 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08003651 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07003652 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003653 }
3654 public boolean isFolderClingVisible() {
3655 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003656 if (cling != null) {
3657 return cling.getVisibility() == View.VISIBLE;
3658 }
3659 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003660 }
Winson Chung82f55532011-08-09 14:14:23 -07003661 public void dismissWorkspaceCling(View v) {
3662 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003663 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003664 }
3665 public void dismissAllAppsCling(View v) {
3666 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003667 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3668 }
3669 public void dismissFolderCling(View v) {
3670 Cling cling = (Cling) findViewById(R.id.folder_cling);
3671 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003672 }
3673
Winson Chung80baf5a2010-08-09 16:03:15 -07003674 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003675 * Prints out out state for debugging.
3676 */
3677 public void dumpState() {
3678 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003679 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003680 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3681 Log.d(TAG, "mRestoring=" + mRestoring);
3682 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3683 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003684 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003685 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003686
Winson Chung785d2eb2011-04-14 16:08:02 -07003687 if (mAppsCustomizeContent != null) {
3688 mAppsCustomizeContent.dumpState();
3689 }
Joe Onoratobe386092009-11-17 17:32:16 -08003690 Log.d(TAG, "END launcher2 dump state");
3691 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003692
3693 @Override
3694 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3695 super.dump(prefix, fd, writer, args);
3696 writer.println(" ");
3697 writer.println("Debug logs: ");
3698 for (int i = 0; i < sDumpLogs.size(); i++) {
3699 writer.println(" " + sDumpLogs.get(i));
3700 }
3701 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003702}
Michael Jurka2763be32011-02-24 11:19:57 -08003703
Michael Jurkaabded662011-03-04 12:06:57 -08003704interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003705 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003706 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08003707 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08003708 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08003709 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003710}