blob: e3f7b75a83acfde565d7e43ca00579fd3d7e4eb9 [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;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070064import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080065import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066import android.text.Selection;
67import android.text.SpannableStringBuilder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070069import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080070import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080071import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072import android.view.KeyEvent;
73import android.view.LayoutInflater;
74import android.view.Menu;
75import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070076import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080077import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080078import android.view.View;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080079import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070080import android.view.ViewGroup;
Michael Jurkab737ee62011-11-15 15:57:22 -080081import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080082import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Dianne Hackbornbb003a52011-08-30 14:40:07 -070083import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080084import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070085import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070086import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080087import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070089import android.widget.Advanceable;
Michael Jurkaaf442092010-06-10 17:01:57 -070090import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070091import android.widget.TextView;
92import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070093
Adam Cohendf2cc412011-04-27 16:56:57 -070094import com.android.common.Search;
95import com.android.launcher.R;
Adam Cohen558baaf2011-08-15 15:22:57 -070096import com.android.launcher2.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080097
Adam Cohenc0dcf592011-06-01 15:30:43 -070098import java.io.DataInputStream;
99import java.io.DataOutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700100import java.io.FileDescriptor;
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700101import java.io.FileInputStream;
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";
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700149 static final String DUMP_STATE_PROPERTY = "debug.launcher2.dumpstate";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150
Winson Chung2672ff92012-05-04 16:22:30 -0700151 // The Intent extra that defines whether to ignore the launch animation
152 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
153 "com.android.launcher.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
154
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800155 // Type: int
156 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700157 // Type: int
158 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800159 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700160 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
161 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
163 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700164 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700166 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800167 // Type: boolean
168 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
169 // Type: long
170 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700171 // Type: int
172 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
173 // Type: int
174 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
175 // Type: parcelable
176 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700178 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700179 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
180 "com.android.launcher.toolbar_search_icon";
181 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
182 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700183
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700184 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700185 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700186 private State mState = State.WORKSPACE;
187 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800188 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700189
Joe Onorato9c1289c2009-08-17 11:03:03 -0400190 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700191 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
192 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700193 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700194 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800196 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800197 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800198
Winson Chunga2413752012-04-03 14:22:34 -0700199 // How long to wait before the new-shortcut animation automatically pans the workspace
200 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10;
201
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800202 private final BroadcastReceiver mCloseSystemDialogsReceiver
203 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800204 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
205
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800206 private LayoutInflater mInflater;
207
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800208 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800209 private View mQsbDivider;
210 private View mDockDivider;
211 private DragLayer mDragLayer;
212 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700213
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700214 private AppWidgetManager mAppWidgetManager;
215 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700216
Michael Jurkac9d95c52011-08-29 14:03:34 -0700217 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700218 private AppWidgetProviderInfo mPendingAddWidgetInfo;
219
Michael Jurka0280c3b2010-09-17 15:00:07 -0700220 private int[] mTmpAddItemCellCoordinates = new int[2];
221
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800222 private FolderInfo mFolderInfo;
223
Winson Chung3d503fb2011-07-13 17:25:49 -0700224 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800225 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700226
Winson Chungc51db6a2011-10-05 11:44:49 -0700227 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700228 private AppsCustomizeTabHost mAppsCustomizeTabHost;
229 private AppsCustomizePagedView mAppsCustomizeContent;
230 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800231
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800232 private Bundle mSavedState;
233
234 private SpannableStringBuilder mDefaultKeySsb = null;
235
Joe Onorato9c1289c2009-08-17 11:03:03 -0400236 private boolean mWorkspaceLoading = true;
237
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800238 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800239 private boolean mRestoring;
240 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700241 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800242
243 private Bundle mSavedInstanceState;
244
Joe Onorato9c1289c2009-08-17 11:03:03 -0400245 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800246 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800247 private boolean mUserPresent = true;
248 private boolean mVisible = false;
249 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400250
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700251 private static LocaleConfiguration sLocaleConfiguration = null;
252
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700253 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700254
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700255 private Intent mAppMarketIntent = null;
256
Adam Cohended9f8d2010-11-03 13:25:16 -0700257 // Related to the auto-advancing of widgets
258 private final int ADVANCE_MSG = 1;
259 private final int mAdvanceInterval = 20000;
260 private final int mAdvanceStagger = 250;
261 private long mAutoAdvanceSentTime;
262 private long mAutoAdvanceTimeLeft = -1;
263 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
264 new HashMap<View, AppWidgetProviderInfo>();
265
Winson Chung400438b2011-01-16 17:53:48 -0800266 // Determines how long to wait after a rotation before restoring the screen orientation to
267 // match the sensor state.
268 private final int mRestoreScreenOrientationDelay = 500;
269
Michael Jurka4ef207b2010-11-29 17:05:45 -0800270 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700271 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
272 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
273 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800274
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700275 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
276
Winson Chung46353de2012-02-16 14:05:10 -0800277 // We only want to get the SharedPreferences once since it does an FS stat each time we get
278 // it from the context.
279 private SharedPreferences mSharedPrefs;
280
Winson Chungf0c6ae02012-03-21 16:10:31 -0700281 // Holds the page that we need to animate to, and the icon views that we need to animate up
282 // when we scroll to that page on resume.
283 private int mNewShortcutAnimatePage = -1;
284 private ArrayList<View> mNewShortcutAnimateViews = new ArrayList<View>();
Adam Cohen268c4752012-06-06 17:47:33 -0700285 private ImageView mFolderIconImageView;
286 private Bitmap mFolderIconBitmap;
287 private Canvas mFolderIconCanvas;
288 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700289
Michael Jurkaddd62e92011-02-16 17:49:14 -0800290 private BubbleTextView mWaitingForResume;
291
Michael Jurkac1f5d262011-09-30 19:32:27 -0700292 private Runnable mBuildLayersRunnable = new Runnable() {
293 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700294 if (mWorkspace != null) {
295 mWorkspace.buildPageHardwareLayers();
296 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700297 }
298 };
299
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800300 private static ArrayList<PendingAddArguments> sPendingAddList
301 = new ArrayList<PendingAddArguments>();
302
303 private static class PendingAddArguments {
304 int requestCode;
305 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700306 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800307 int screen;
308 int cellX;
309 int cellY;
310 }
311
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700312
313 private boolean doesFileExist(String filename) {
314 FileInputStream fis = null;
315 try {
316 fis = openFileInput(filename);
317 fis.close();
318 return true;
319 } catch (java.io.FileNotFoundException e) {
320 return false;
321 } catch (java.io.IOException e) {
322 return true;
323 }
324 }
325
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800326 @Override
327 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700328 if (DEBUG_STRICT_MODE) {
329 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
330 .detectDiskReads()
331 .detectDiskWrites()
332 .detectNetwork() // or .detectAll() for all detectable problems
333 .penaltyLog()
334 .build());
335 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
336 .detectLeakedSqlLiteObjects()
337 .detectLeakedClosableObjects()
338 .penaltyLog()
339 .penaltyDeath()
340 .build());
341 }
342
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800343 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800344 LauncherApplication app = ((LauncherApplication)getApplication());
Winson Chungf0c6ae02012-03-21 16:10:31 -0700345 mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(),
346 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800347 mModel = app.setLauncher(this);
348 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400349 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800350 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700351
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700352 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700353 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
354 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700355
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800356 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200357 android.os.Debug.startMethodTracing(
358 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800359 }
360
361 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800362 setContentView(R.layout.launcher);
363 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700364 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800365
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800366 registerContentObservers();
367
Joe Onorato7c312c12009-08-13 21:36:53 -0700368 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700369
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800370 mSavedState = savedInstanceState;
371 restoreState(mSavedState);
372
Winson Chunga12a2502010-12-20 14:41:35 -0800373 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700374 if (mAppsCustomizeContent != null) {
Winson Chung7c7a22d2012-06-01 13:46:48 -0700375 Log.d(TAG, "6549598 Launcher.onCreate()");
Winson Chung785d2eb2011-04-14 16:08:02 -0700376 mAppsCustomizeContent.onPackagesUpdated();
377 }
Winson Chunga12a2502010-12-20 14:41:35 -0800378
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800379 if (PROFILE_STARTUP) {
380 android.os.Debug.stopMethodTracing();
381 }
382
383 if (!mRestoring) {
Winson Chungf0c6ae02012-03-21 16:10:31 -0700384 mModel.startLoader(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385 }
386
Michael Jurkac57b7a82011-08-09 22:02:20 -0700387 if (!mModel.isAllAppsLoaded()) {
388 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
389 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
390 }
391
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800392 // For handling default keys
393 mDefaultKeySsb = new SpannableStringBuilder();
394 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800395
396 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
397 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800398
Adam Cohenf9426d52012-06-04 17:26:21 -0700399 updateGlobalIcons();
400
401 // On large interfaces, we want the screen to auto-rotate based on the current orientation
402 unlockScreenOrientation(true);
403 }
404
405 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700406 boolean searchVisible = false;
407 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800408 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700409 int coi = getCurrentOrientationIndexForGlobalIcons();
410 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
411 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700412 updateAppMarketIcon();
413 searchVisible = updateGlobalSearchIcon();
414 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700415 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700416 if (sGlobalSearchIcon[coi] != null) {
417 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700418 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700419 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700420 if (sVoiceSearchIcon[coi] != null) {
421 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700422 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700423 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700424 if (sAppMarketIcon[coi] != null) {
425 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800426 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700427 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800428 }
Romain Guycbb89e42009-06-08 15:52:54 -0700429
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800430 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700431 if (sLocaleConfiguration == null) {
432 new AsyncTask<Void, Void, LocaleConfiguration>() {
433 @Override
434 protected LocaleConfiguration doInBackground(Void... unused) {
435 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
436 readConfiguration(Launcher.this, localeConfiguration);
437 return localeConfiguration;
438 }
439
440 @Override
441 protected void onPostExecute(LocaleConfiguration result) {
442 sLocaleConfiguration = result;
443 checkForLocaleChange(); // recursive, but now with a locale configuration
444 }
445 }.execute();
446 return;
447 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700448
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800449 final Configuration configuration = getResources().getConfiguration();
450
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700451 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800452 final String locale = configuration.locale.toString();
453
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700454 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800455 final int mcc = configuration.mcc;
456
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700457 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800458 final int mnc = configuration.mnc;
459
Romain Guy84f296c2009-11-04 15:00:44 -0800460 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800461
Romain Guy84f296c2009-11-04 15:00:44 -0800462 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700463 sLocaleConfiguration.locale = locale;
464 sLocaleConfiguration.mcc = mcc;
465 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700466
Joe Onorato0589f0f2010-02-08 13:44:00 -0800467 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700468
469 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
470 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700471 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700472 public void run() {
473 writeConfiguration(Launcher.this, localeConfiguration);
474 }
475 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700476 }
477 }
478
479 private static class LocaleConfiguration {
480 public String locale;
481 public int mcc = -1;
482 public int mnc = -1;
483 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700484
Romain Guy98d01652009-06-30 16:21:04 -0700485 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
486 DataInputStream in = null;
487 try {
488 in = new DataInputStream(context.openFileInput(PREFERENCES));
489 configuration.locale = in.readUTF();
490 configuration.mcc = in.readInt();
491 configuration.mnc = in.readInt();
492 } catch (FileNotFoundException e) {
493 // Ignore
494 } catch (IOException e) {
495 // Ignore
496 } finally {
497 if (in != null) {
498 try {
499 in.close();
500 } catch (IOException e) {
501 // Ignore
502 }
503 }
504 }
505 }
506
507 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
508 DataOutputStream out = null;
509 try {
510 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
511 out.writeUTF(configuration.locale);
512 out.writeInt(configuration.mcc);
513 out.writeInt(configuration.mnc);
514 out.flush();
515 } catch (FileNotFoundException e) {
516 // Ignore
517 } catch (IOException e) {
518 //noinspection ResultOfMethodCallIgnored
519 context.getFileStreamPath(PREFERENCES).delete();
520 } finally {
521 if (out != null) {
522 try {
523 out.close();
524 } catch (IOException e) {
525 // Ignore
526 }
527 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800528 }
529 }
530
Adam Cohen716b51e2011-06-30 12:09:54 -0700531 public DragLayer getDragLayer() {
532 return mDragLayer;
533 }
534
Winson Chung36a62fe2012-05-06 18:04:42 -0700535 boolean isDraggingEnabled() {
536 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
537 // that is subsequently removed from the workspace in startBinding().
538 return !mModel.isLoadingWorkspace();
539 }
540
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800541 static int getScreen() {
542 synchronized (sLock) {
543 return sScreen;
544 }
545 }
546
547 static void setScreen(int screen) {
548 synchronized (sLock) {
549 sScreen = screen;
550 }
551 }
552
Winson Chung557d6ed2011-07-08 15:34:52 -0700553 /**
554 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
555 * a configuration step, this allows the proper animations to run after other transitions.
556 */
557 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700558 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800559 switch (args.requestCode) {
560 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700561 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
562 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800563 break;
564 case REQUEST_PICK_SHORTCUT:
565 processShortcut(args.intent);
566 break;
567 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700568 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
569 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700570 result = true;
571 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800572 case REQUEST_CREATE_APPWIDGET:
573 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800574 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700575 result = true;
576 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800577 case REQUEST_PICK_WALLPAPER:
578 // We just wanted the activity result here so we can clear mWaitingForResult
579 break;
580 }
Michael Jurka27614d22012-04-02 06:40:22 -0700581 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
582 // if you turned the screen off and then back while in All Apps, Launcher would not
583 // return to the workspace. Clearing mAddInfo.container here fixes this issue
584 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700585 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800586 }
587
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800588 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700589 protected void onActivityResult(
590 final int requestCode, final int resultCode, final Intent data) {
591 if (requestCode == REQUEST_BIND_APPWIDGET) {
592 int appWidgetId = data != null ?
593 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
594 if (resultCode == RESULT_CANCELED) {
595 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
596 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700597 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700598 }
599 return;
600 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700601 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800602 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
603 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700604 mWaitingForResult = false;
605
Adam Cohened66b2b2012-01-23 17:28:51 -0800606 // We have special handling for widgets
607 if (isWidgetDrop) {
608 int appWidgetId = data != null ?
609 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700610 if (appWidgetId < 0) {
611 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
612 "widget configuration activity.");
613 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
614 } else {
615 completeTwoStageWidgetDrop(resultCode, appWidgetId);
616 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800617 return;
618 }
619
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800620 // The pattern used here is that a user PICKs a specific application,
621 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700622
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800623 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
624 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700625 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800626 final PendingAddArguments args = new PendingAddArguments();
627 args.requestCode = requestCode;
628 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700629 args.container = mPendingAddInfo.container;
630 args.screen = mPendingAddInfo.screen;
631 args.cellX = mPendingAddInfo.cellX;
632 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800633 if (isWorkspaceLocked()) {
634 sPendingAddList.add(args);
635 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700636 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800637 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800638 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800639 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700640 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800641 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
642 null);
643 }
644
645 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700646 CellLayout cellLayout =
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700647 (CellLayout) mWorkspace.getChildAt(mPendingAddInfo.screen);
Adam Cohened66b2b2012-01-23 17:28:51 -0800648 Runnable onCompleteRunnable = null;
649 int animationType = 0;
650
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700651 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800652 if (resultCode == RESULT_OK) {
653 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
654 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700655 mPendingAddWidgetInfo);
656 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800657 onCompleteRunnable = new Runnable() {
658 @Override
659 public void run() {
660 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
661 mPendingAddInfo.screen, layout, null);
662 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
663 null);
664 }
665 };
666 } else if (resultCode == RESULT_CANCELED) {
667 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
668 onCompleteRunnable = new Runnable() {
669 @Override
670 public void run() {
671 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
672 null);
673 }
674 };
675 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700676 if (mDragLayer.getAnimatedView() != null) {
677 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
678 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
679 animationType, boundWidget, true);
680 } else {
681 // The animated view may be null in the case of a rotation during widget configuration
682 onCompleteRunnable.run();
683 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800684 }
685
686 @Override
687 protected void onResume() {
688 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700689
Winson Chungde0fb8f2012-05-08 14:37:08 -0700690 // Process any items that were added while Launcher was away
691 InstallShortcutReceiver.flushInstallQueue(this);
692
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800693 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700694 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400695 mWorkspaceLoading = true;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700696 mModel.startLoader(true);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400697 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700698 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800699 }
Winson Chunge4e50662012-01-23 14:45:13 -0800700
701 // Reset the pressed state of icons that were locked in the press state while activities
702 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800703 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800704 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800705 mWaitingForResume.setStayPressed(false);
706 }
Winson Chunge4e50662012-01-23 14:45:13 -0800707 if (mAppsCustomizeContent != null) {
708 // Resets the previous all apps icon press state
709 mAppsCustomizeContent.resetDrawableState();
710 }
Adam Cohen06dff352012-06-01 17:17:08 -0700711 // It is possible that widgets can receive updates while launcher is not in the foreground.
712 // Consequently, the widgets will be inflated in the orientation of the foreground activity
713 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
714 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700715 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700716
717 // Again, as with the above scenario, it's possible that one or more of the global icons
718 // were updated in the wrong orientation.
719 updateGlobalIcons();
Adam Cohen06dff352012-06-01 17:17:08 -0700720 }
721
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800722 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700723 protected void onPause() {
Winson Chungca889b32012-05-07 15:34:34 -0700724 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
725 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary
726 // when Launcher resumes and we are still in AllApps.
727 updateWallpaperVisibility(true);
728
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700729 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700730 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800731 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700732 mDragController.resetLastGestureUpTime();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700733 }
Romain Guycbb89e42009-06-08 15:52:54 -0700734
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700735 @Override
736 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400737 // Flag the loader to stop early before switching
738 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700739 if (mAppsCustomizeContent != null) {
740 mAppsCustomizeContent.surrender();
741 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800742 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700743 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700744
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800745 // We can't hide the IME if it was forced open. So don't bother
746 /*
747 @Override
748 public void onWindowFocusChanged(boolean hasFocus) {
749 super.onWindowFocusChanged(hasFocus);
750
751 if (hasFocus) {
752 final InputMethodManager inputManager = (InputMethodManager)
753 getSystemService(Context.INPUT_METHOD_SERVICE);
754 WindowManager.LayoutParams lp = getWindow().getAttributes();
755 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
756 android.os.Handler()) {
757 protected void onReceiveResult(int resultCode, Bundle resultData) {
758 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
759 }
760 });
761 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
762 }
763 }
764 */
765
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800766 private boolean acceptFilter() {
767 final InputMethodManager inputManager = (InputMethodManager)
768 getSystemService(Context.INPUT_METHOD_SERVICE);
769 return !inputManager.isFullscreenMode();
770 }
771
772 @Override
773 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700774 final int uniChar = event.getUnicodeChar();
775 final boolean handled = super.onKeyDown(keyCode, event);
776 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
777 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800778 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
779 keyCode, event);
780 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700781 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700782 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700783 // showSearchDialog()
784 // If there are multiple keystrokes before the search dialog takes focus,
785 // onSearchRequested() will be called for every keystroke,
786 // but it is idempotent, so it's fine.
787 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800788 }
789 }
790
Joe Onorato8a9625e2010-01-28 15:55:35 -0800791 // Eat the long press event so the keyboard doesn't come up.
792 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
793 return true;
794 }
795
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800796 return handled;
797 }
798
Karl Rosaen138a0412009-04-23 19:00:21 -0700799 private String getTypedText() {
800 return mDefaultKeySsb.toString();
801 }
802
803 private void clearTypedText() {
804 mDefaultKeySsb.clear();
805 mDefaultKeySsb.clearSpans();
806 Selection.setSelection(mDefaultKeySsb, 0);
807 }
808
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800809 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700810 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
811 * State
812 */
813 private static State intToState(int stateOrdinal) {
814 State state = State.WORKSPACE;
815 final State[] stateValues = State.values();
816 for (int i = 0; i < stateValues.length; i++) {
817 if (stateValues[i].ordinal() == stateOrdinal) {
818 state = stateValues[i];
819 break;
820 }
821 }
822 return state;
823 }
824
825 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800826 * Restores the previous state, if it exists.
827 *
828 * @param savedState The previous state.
829 */
830 private void restoreState(Bundle savedState) {
831 if (savedState == null) {
832 return;
833 }
834
Michael Jurka883f55b2010-10-21 15:47:14 -0700835 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700836 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800837 showAllApps(false);
838 }
839
Winson Chungf0c6ae02012-03-21 16:10:31 -0700840 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800841 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700842 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800843 }
844
Winson Chung3d503fb2011-07-13 17:25:49 -0700845 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
846 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700847
Winson Chung3d503fb2011-07-13 17:25:49 -0700848 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
849 mPendingAddInfo.container = pendingAddContainer;
850 mPendingAddInfo.screen = pendingAddScreen;
851 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
852 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700853 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
854 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
855 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -0700856 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800857 mRestoring = true;
858 }
859
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700860
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800861 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
862 if (renameFolder) {
863 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700864 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800865 mRestoring = true;
866 }
Winson Chunga12a2502010-12-20 14:41:35 -0800867
Winson Chung785d2eb2011-04-14 16:08:02 -0700868
869 // Restore the AppsCustomize tab
870 if (mAppsCustomizeTabHost != null) {
871 String curTab = savedState.getString("apps_customize_currentTab");
872 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700873 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700874 mAppsCustomizeContent.setContentType(
875 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
876 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700877 mAppsCustomizeContent.loadAssociatedPages(
878 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700879 }
880
Winson Chung5afbf7b2011-07-25 11:53:08 -0700881 int currentIndex = savedState.getInt("apps_customize_currentIndex");
882 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700883 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800884 }
885
886 /**
887 * Finds all the views we need and configure them properly.
888 */
889 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700890 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400891
Winson Chung4c98d922011-05-31 16:50:48 -0700892 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
893 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800894 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
895 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800896
Winson Chung4c98d922011-05-31 16:50:48 -0700897 // Setup the drag layer
898 mDragLayer.setup(this, dragController);
899
Winson Chung3d503fb2011-07-13 17:25:49 -0700900 // Setup the hotseat
901 mHotseat = (Hotseat) findViewById(R.id.hotseat);
902 if (mHotseat != null) {
903 mHotseat.setup(this);
904 }
905
Winson Chung4c98d922011-05-31 16:50:48 -0700906 // Setup the workspace
907 mWorkspace.setHapticFeedbackEnabled(false);
908 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700909 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700910 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700911
Winson Chungf0ea4d32011-06-06 14:27:16 -0700912 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700913 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700914
Winson Chungf0ea4d32011-06-06 14:27:16 -0700915 // Setup AppsCustomize
916 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
917 findViewById(R.id.apps_customize_pane);
918 mAppsCustomizeContent = (AppsCustomizePagedView)
919 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
920 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400921
Michael Jurka5130e402011-10-13 04:55:35 -0700922 // Get the all apps button
923 mAllAppsButton = findViewById(R.id.all_apps_button);
924 if (mAllAppsButton != null) {
925 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
926 @Override
927 public boolean onTouch(View v, MotionEvent event) {
928 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
929 onTouchDownAllAppsButton(v);
930 }
931 return false;
932 }
933 });
934 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700935 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700936 dragController.setDragScoller(mWorkspace);
937 dragController.setScrollView(mDragLayer);
938 dragController.setMoveTarget(mWorkspace);
939 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700940 if (mSearchDropTargetBar != null) {
941 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800942 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800943 }
944
945 /**
946 * Creates a view representing a shortcut.
947 *
948 * @param info The data structure describing the shortcut.
949 *
950 * @return A View inflated from R.layout.application.
951 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800952 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800953 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700954 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800955 }
956
957 /**
958 * Creates a view representing a shortcut inflated from the specified resource.
959 *
960 * @param layoutResId The id of the XML layout used to create the shortcut.
961 * @param parent The group the shortcut belongs to.
962 * @param info The data structure describing the shortcut.
963 *
964 * @return A View inflated from layoutResId.
965 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800966 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800967 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
968 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800969 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800970 return favorite;
971 }
972
973 /**
974 * Add an application shortcut to the workspace.
975 *
976 * @param data The intent describing the application.
977 * @param cellInfo The position on screen where to create the shortcut.
978 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700979 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700980 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700981 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700982
Adam Cohenfbba09b2011-07-18 21:43:05 -0700983 // First we check if we already know the exact location where we want to add this item.
984 if (cellX >= 0 && cellY >= 0) {
985 cellXY[0] = cellX;
986 cellXY[1] = cellY;
987 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -0700988 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -0700989 return;
990 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800991
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800992 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800993
Romain Guy73b979d2009-06-09 12:57:21 -0700994 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800995 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800996 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800997 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700998 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700999 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001000 } else {
1001 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001002 }
1003 }
Romain Guycbb89e42009-06-08 15:52:54 -07001004
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001005 /**
1006 * Add a shortcut to the workspace.
1007 *
1008 * @param data The intent describing the shortcut.
1009 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001010 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001011 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
1012 int cellY) {
1013 int[] cellXY = mTmpAddItemCellCoordinates;
1014 int[] touchXY = mPendingAddInfo.dropPos;
1015 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001016
Michael Jurkad3ef3062010-11-23 16:23:58 -08001017 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001018
Adam Cohen558baaf2011-08-15 15:22:57 -07001019 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001020 if (info == null) {
1021 return;
1022 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001023 final View view = createShortcut(info);
1024
Adam Cohenfbba09b2011-07-18 21:43:05 -07001025 // First we check if we already know the exact location where we want to add this item.
1026 if (cellX >= 0 && cellY >= 0) {
1027 cellXY[0] = cellX;
1028 cellXY[1] = cellY;
1029 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001030
1031 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001032 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001033 true, null,null)) {
1034 return;
1035 }
1036 DragObject dragObject = new DragObject();
1037 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001038 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1039 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001040 return;
1041 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001042 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001043 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001044 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001045 foundCellSpan = (result != null);
1046 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001047 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001048 }
1049
1050 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001051 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001052 return;
1053 }
1054
Adam Cohen558baaf2011-08-15 15:22:57 -07001055 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001056
1057 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001058 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
1059 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001060 }
1061 }
1062
Adam Cohen2f093b62012-04-30 18:59:53 -07001063 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1064 int minHeight) {
1065 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001066 // We want to account for the extra amount of padding that we are adding to the widget
1067 // to ensure that it gets the full amount of space that it has requested
1068 int requiredWidth = minWidth + padding.left + padding.right;
1069 int requiredHeight = minHeight + padding.top + padding.bottom;
Adam Cohen2f093b62012-04-30 18:59:53 -07001070 return CellLayout.rectToCell(context.getResources(), requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001071 }
1072
Adam Cohen2f093b62012-04-30 18:59:53 -07001073 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1074 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001075 }
1076
Adam Cohen2f093b62012-04-30 18:59:53 -07001077 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1078 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001079 }
1080
Adam Cohen2f093b62012-04-30 18:59:53 -07001081 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1082 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001083 }
1084
Adam Cohen2f093b62012-04-30 18:59:53 -07001085 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1086 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001087 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001088 }
1089
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001090 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001091 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001092 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001093 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001094 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001095 */
Adam Cohened66b2b2012-01-23 17:28:51 -08001096 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
1097 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1098 if (appWidgetInfo == null) {
1099 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1100 }
Romain Guycbb89e42009-06-08 15:52:54 -07001101
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001102 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -07001103 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -07001104
Adam Cohen2f093b62012-04-30 18:59:53 -07001105 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1106 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001107
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001108 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001109 // We have saved the position to which the widget was dragged-- this really only matters
1110 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001111 int[] cellXY = mTmpAddItemCellCoordinates;
1112 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001113 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001114 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001115 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1116 cellXY[0] = mPendingAddInfo.cellX;
1117 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001118 spanXY[0] = mPendingAddInfo.spanX;
1119 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001120 foundCellSpan = true;
1121 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001122 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001123 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001124 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1125 spanXY[1], cellXY, finalSpan);
1126 spanXY[0] = finalSpan[0];
1127 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001128 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001129 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001130 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001131 }
1132
Michael Jurka0280c3b2010-09-17 15:00:07 -07001133 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001134 if (appWidgetId != -1) {
1135 // Deleting an app widget ID is a void call but writes to disk before returning
1136 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001137 new Thread("deleteAppWidgetId") {
1138 public void run() {
1139 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1140 }
1141 }.start();
1142 }
Winson Chung93eef082012-03-23 15:59:27 -07001143 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001144 return;
1145 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001146
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001147 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001148 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1149 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001150 launcherInfo.spanX = spanXY[0];
1151 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001152 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1153 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001154
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001155 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001156 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001157
1158 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001159 if (hostView == null) {
1160 // Perform actual inflation because we're live
1161 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1162 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1163 } else {
1164 // The AppWidgetHostView has already been inflated and instantiated
1165 launcherInfo.hostView = hostView;
1166 }
Romain Guycbb89e42009-06-08 15:52:54 -07001167
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001168 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001169 launcherInfo.hostView.setVisibility(View.VISIBLE);
Winson Chung211bac32012-05-15 13:43:57 -07001170 launcherInfo.notifyWidgetSizeChanged(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001171 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001172 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001173
1174 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001175 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001176 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001177 }
Romain Guycbb89e42009-06-08 15:52:54 -07001178
Adam Cohended9f8d2010-11-03 13:25:16 -07001179 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1180 @Override
1181 public void onReceive(Context context, Intent intent) {
1182 final String action = intent.getAction();
1183 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1184 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001185 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001186 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001187
Winson Chungc100e8e2011-08-09 16:02:43 -07001188 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001189 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001190 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1191 mAppsCustomizeTabHost.reset();
1192 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001193 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001194 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1195 mUserPresent = true;
1196 updateRunning();
1197 }
1198 }
1199 };
1200
1201 @Override
1202 public void onAttachedToWindow() {
1203 super.onAttachedToWindow();
1204
1205 // Listen for broadcasts related to user-presence
1206 final IntentFilter filter = new IntentFilter();
1207 filter.addAction(Intent.ACTION_SCREEN_OFF);
1208 filter.addAction(Intent.ACTION_USER_PRESENT);
1209 registerReceiver(mReceiver, filter);
1210
Adam Cohend113e0c2010-11-11 10:48:05 -08001211 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001212 mVisible = true;
1213 }
1214
1215 @Override
1216 public void onDetachedFromWindow() {
1217 super.onDetachedFromWindow();
1218 mVisible = false;
1219
Adam Cohend113e0c2010-11-11 10:48:05 -08001220 if (mAttached) {
1221 unregisterReceiver(mReceiver);
1222 mAttached = false;
1223 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001224 updateRunning();
1225 }
1226
1227 public void onWindowVisibilityChanged(int visibility) {
1228 mVisible = visibility == View.VISIBLE;
1229 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001230 // The following code used to be in onResume, but it turns out onResume is called when
1231 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1232 // is a more appropriate event to handle
1233 if (mVisible) {
1234 mAppsCustomizeTabHost.onWindowVisible();
1235 if (!mWorkspaceLoading) {
1236 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001237 // We want to let Launcher draw itself at least once before we force it to build
1238 // layers on all the workspace pages, so that transitioning to Launcher from other
1239 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
1240 // a true draw so we wait until the second preDraw call to be safe
1241 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001242 public boolean onPreDraw() {
Michael Jurka6ee21d22012-02-21 18:20:27 -08001243 // We delay the layer building a bit in order to give
1244 // other message processing a time to run. In particular
1245 // this avoids a delay in hiding the IME if it was
1246 // currently shown, because doing that may involve
1247 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001248 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Winson Chung31ce0732012-05-06 13:36:43 -07001249
Michael Jurka6ee21d22012-02-21 18:20:27 -08001250 observer.removeOnPreDrawListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001251 return true;
1252 }
1253 });
1254 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001255 // When Launcher comes back to foreground, a different Activity might be responsible for
1256 // the app market intent, so refresh the icon
1257 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001258 clearTypedText();
1259 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001260 }
1261
1262 private void sendAdvanceMessage(long delay) {
1263 mHandler.removeMessages(ADVANCE_MSG);
1264 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1265 mHandler.sendMessageDelayed(msg, delay);
1266 mAutoAdvanceSentTime = System.currentTimeMillis();
1267 }
1268
1269 private void updateRunning() {
1270 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1271 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1272 mAutoAdvanceRunning = autoAdvanceRunning;
1273 if (autoAdvanceRunning) {
1274 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1275 sendAdvanceMessage(delay);
1276 } else {
1277 if (!mWidgetsToAdvance.isEmpty()) {
1278 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1279 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1280 }
1281 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001282 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001283 }
1284 }
1285 }
1286
1287 private final Handler mHandler = new Handler() {
1288 @Override
1289 public void handleMessage(Message msg) {
1290 if (msg.what == ADVANCE_MSG) {
1291 int i = 0;
1292 for (View key: mWidgetsToAdvance.keySet()) {
1293 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1294 final int delay = mAdvanceStagger * i;
1295 if (v instanceof Advanceable) {
1296 postDelayed(new Runnable() {
1297 public void run() {
1298 ((Advanceable) v).advance();
1299 }
1300 }, delay);
1301 }
1302 i++;
1303 }
1304 sendAdvanceMessage(mAdvanceInterval);
1305 }
1306 }
1307 };
1308
1309 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001310 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001311 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1312 if (v instanceof Advanceable) {
1313 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001314 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001315 updateRunning();
1316 }
1317 }
1318
1319 void removeWidgetToAutoAdvance(View hostView) {
1320 if (mWidgetsToAdvance.containsKey(hostView)) {
1321 mWidgetsToAdvance.remove(hostView);
1322 updateRunning();
1323 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001324 }
1325
Joe Onorato9c1289c2009-08-17 11:03:03 -04001326 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001327 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001328 launcherInfo.hostView = null;
1329 }
1330
Winson Chung93eef082012-03-23 15:59:27 -07001331 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1332 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1333 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001334 }
1335
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001336 public LauncherAppWidgetHost getAppWidgetHost() {
1337 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001338 }
Romain Guycbb89e42009-06-08 15:52:54 -07001339
Winson Chunga9abd0e2010-10-27 17:18:37 -07001340 public LauncherModel getModel() {
1341 return mModel;
1342 }
1343
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001344 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001345 getWindow().closeAllPanels();
1346
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001347 // Whatever we were doing is hereby canceled.
1348 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001349 }
1350
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001351 @Override
1352 protected void onNewIntent(Intent intent) {
1353 super.onNewIntent(intent);
1354
1355 // Close the menu
1356 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001357 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001358 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001359
Joe Onorato14f122b2009-11-19 14:06:36 -08001360 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1361 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001362
Adam Cohenac56cff2011-09-28 20:45:37 -07001363 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001364 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001365 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001366 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1367 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001368 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001369 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001370
1371 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001372 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001373 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001374
Joe Onorato3a8820b2009-11-10 15:06:42 -08001375 final View v = getWindow().peekDecorView();
1376 if (v != null && v.getWindowToken() != null) {
1377 InputMethodManager imm = (InputMethodManager)getSystemService(
1378 INPUT_METHOD_SERVICE);
1379 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001380 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001381
Michael Jurka35aa14d2011-07-07 17:01:08 -07001382 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001383 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001384 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001385 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001386 }
1387 }
1388
1389 @Override
1390 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1391 // Do not call super here
1392 mSavedInstanceState = savedInstanceState;
1393 }
1394
1395 @Override
1396 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001397 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001398 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001399
Michael Jurka883f55b2010-10-21 15:47:14 -07001400 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001401 // We close any open folder since it will not be re-opened, and we need to make sure
1402 // this state is reflected.
1403 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001404
Winson Chung3d503fb2011-07-13 17:25:49 -07001405 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1406 mWaitingForResult) {
1407 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1408 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1409 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1410 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001411 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1412 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1413 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414 }
1415
1416 if (mFolderInfo != null && mWaitingForResult) {
1417 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1418 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1419 }
Michael Jurka946ad472010-07-09 18:05:18 -07001420
Winson Chung785d2eb2011-04-14 16:08:02 -07001421 // Save the current AppsCustomize tab
1422 if (mAppsCustomizeTabHost != null) {
1423 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1424 if (currentTabTag != null) {
1425 outState.putString("apps_customize_currentTab", currentTabTag);
1426 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001427 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1428 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001429 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001430 }
1431
1432 @Override
1433 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001434 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001435
Winson Chunge7a03942011-08-05 15:05:12 -07001436 // Remove all pending runnables
1437 mHandler.removeMessages(ADVANCE_MSG);
1438 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001439 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001440
Winson Chungcd2b0142011-06-08 16:02:26 -07001441 // Stop callbacks from LauncherModel
1442 LauncherApplication app = ((LauncherApplication) getApplication());
1443 mModel.stopLoader();
1444 app.setLauncher(null);
1445
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001446 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001447 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001448 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001449 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001450 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001451 mAppWidgetHost = null;
1452
1453 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001454
1455 TextKeyListener.getInstance().release();
1456
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001457
Winson Chung3d503fb2011-07-13 17:25:49 -07001458 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001459
1460 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001461 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001462
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001463 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001464 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1465 mWorkspace.removeAllViews();
1466 mWorkspace = null;
1467 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001468
1469 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001470 }
1471
Adam Cohena9cf38f2011-05-02 15:36:58 -07001472 public DragController getDragController() {
1473 return mDragController;
1474 }
1475
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001476 @Override
1477 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001478 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001479 super.startActivityForResult(intent, requestCode);
1480 }
1481
Winson Chung70d72102011-08-12 11:24:35 -07001482 /**
1483 * Indicates that we want global search for this activity by setting the globalSearch
1484 * argument for {@link #startSearch} to true.
1485 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001486 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001487 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001488 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001489
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001490 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001491
Karl Rosaen138a0412009-04-23 19:00:21 -07001492 if (initialQuery == null) {
1493 // Use any text typed in the launcher as the initial query
1494 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001495 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001496 if (appSearchData == null) {
1497 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001498 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001499 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001500 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001501
Karl Rosaen138a0412009-04-23 19:00:21 -07001502 final SearchManager searchManager =
1503 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001504 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001505 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001506 }
1507
Winson Chung70d72102011-08-12 11:24:35 -07001508 @Override
1509 public boolean onCreateOptionsMenu(Menu menu) {
1510 if (isWorkspaceLocked()) {
1511 return false;
1512 }
1513
1514 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001515
1516 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1517 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1518 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001519 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1520 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1521 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001522 String helpUrl = getString(R.string.help_url);
1523 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001524 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1525 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1526
Winson Chung70d72102011-08-12 11:24:35 -07001527 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1528 .setIcon(android.R.drawable.ic_menu_gallery)
1529 .setAlphabeticShortcut('W');
1530 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1531 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001532 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001533 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001534 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1535 .setIcon(android.R.drawable.ic_menu_preferences)
1536 .setIntent(settings)
1537 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001538 if (!helpUrl.isEmpty()) {
1539 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1540 .setIcon(android.R.drawable.ic_menu_help)
1541 .setIntent(help)
1542 .setAlphabeticShortcut('H');
1543 }
Winson Chung70d72102011-08-12 11:24:35 -07001544 return true;
1545 }
1546
1547 @Override
1548 public boolean onPrepareOptionsMenu(Menu menu) {
1549 super.onPrepareOptionsMenu(menu);
1550
1551 if (mAppsCustomizeTabHost.isTransitioning()) {
1552 return false;
1553 }
1554 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1555 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1556
1557 return true;
1558 }
1559
1560 @Override
1561 public boolean onOptionsItemSelected(MenuItem item) {
1562 switch (item.getItemId()) {
1563 case MENU_WALLPAPER_SETTINGS:
1564 startWallpaper();
1565 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001566 }
1567
1568 return super.onOptionsItemSelected(item);
1569 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001570
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001571 @Override
1572 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001573 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001574 // Use a custom animation for launching search
1575 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001576 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001577 }
1578
Joe Onorato9c1289c2009-08-17 11:03:03 -04001579 public boolean isWorkspaceLocked() {
1580 return mWorkspaceLoading || mWaitingForResult;
1581 }
1582
Michael Jurka0280c3b2010-09-17 15:00:07 -07001583 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001584 mPendingAddInfo.container = ItemInfo.NO_ID;
1585 mPendingAddInfo.screen = -1;
1586 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1587 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001588 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001589 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001590 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001591
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001592 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1593 AppWidgetProviderInfo appWidgetInfo) {
1594 if (appWidgetInfo.configure != null) {
1595 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001596
Bjorn Bringert7984c942009-12-09 15:38:25 +00001597 // Launch over to configure widget, if needed
1598 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001599 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001600 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Romain Guy8e633c52010-03-04 12:51:36 -08001601 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001602 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001603 // Otherwise just add it
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001604 completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget,
1605 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001606 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001607 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001608 }
1609 }
Romain Guycbb89e42009-06-08 15:52:54 -07001610
Adam Cohenfbba09b2011-07-18 21:43:05 -07001611 /**
1612 * Process a shortcut drop.
1613 *
1614 * @param componentName The name of the component
1615 * @param screen The screen where it should be added
1616 * @param cell The cell it should be added to, optional
1617 * @param position The location on the screen where it was dropped, optional
1618 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001619 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1620 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001621 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001622 mPendingAddInfo.container = container;
1623 mPendingAddInfo.screen = screen;
1624 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001625
1626 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001627 mPendingAddInfo.cellX = cell[0];
1628 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001629 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001630
1631 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1632 createShortcutIntent.setComponent(componentName);
1633 processShortcut(createShortcutIntent);
1634 }
1635
Adam Cohenfbba09b2011-07-18 21:43:05 -07001636 /**
1637 * Process a widget drop.
1638 *
1639 * @param info The PendingAppWidgetInfo of the widget being added.
1640 * @param screen The screen where it should be added
1641 * @param cell The cell it should be added to, optional
1642 * @param position The location on the screen where it was dropped, optional
1643 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001644 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
Adam Cohend41fbf52012-02-16 23:53:59 -08001645 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001646 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001647 mPendingAddInfo.container = info.container = container;
1648 mPendingAddInfo.screen = info.screen = screen;
1649 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001650 mPendingAddInfo.minSpanX = info.minSpanX;
1651 mPendingAddInfo.minSpanY = info.minSpanY;
1652
Adam Cohenfbba09b2011-07-18 21:43:05 -07001653 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001654 mPendingAddInfo.cellX = cell[0];
1655 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001656 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001657 if (span != null) {
1658 mPendingAddInfo.spanX = span[0];
1659 mPendingAddInfo.spanY = span[1];
1660 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001661
Adam Cohened66b2b2012-01-23 17:28:51 -08001662 AppWidgetHostView hostView = info.boundWidget;
1663 int appWidgetId;
1664 if (hostView != null) {
1665 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001666 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001667 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001668 // In this case, we either need to start an activity to get permission to bind
1669 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08001670 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Michael Jurka8b805b12012-04-18 14:23:14 -07001671 if (mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName)) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001672 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07001673 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001674 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07001675 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
1676 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1677 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
1678 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
1679 }
Adam Cohened66b2b2012-01-23 17:28:51 -08001680 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001681 }
1682
Joe Onoratodeb98af2010-02-19 14:59:39 -08001683 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001684 // Handle case where user selected "Applications"
1685 String applicationName = getResources().getString(R.string.group_applications);
1686 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001687
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001688 if (applicationName != null && applicationName.equals(shortcutName)) {
1689 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1690 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001691
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001692 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1693 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001694 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001695 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001696 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001697 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001698 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001699 }
1700
Winson Chung24ab2f12010-09-16 14:10:47 -07001701 void processWallpaper(Intent intent) {
1702 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1703 }
1704
Winson Chung3d503fb2011-07-13 17:25:49 -07001705 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1706 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001707 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001708 folderInfo.title = getText(R.string.folder_name);
1709
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001710 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001711 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1712 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001713 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001714
1715 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001716 FolderIcon newFolder =
1717 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1718 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1719 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001720 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001721 }
Romain Guycbb89e42009-06-08 15:52:54 -07001722
Joe Onorato9c1289c2009-08-17 11:03:03 -04001723 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001724 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001725 }
1726
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001727 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001728 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001729 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001730 Intent chooser = Intent.createChooser(pickWallpaper,
1731 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001732 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1733 // Removed in Eclair MR1
1734// WallpaperManager wm = (WallpaperManager)
1735// getSystemService(Context.WALLPAPER_SERVICE);
1736// WallpaperInfo wi = wm.getWallpaperInfo();
1737// if (wi != null && wi.getSettingsActivity() != null) {
1738// LabeledIntent li = new LabeledIntent(getPackageName(),
1739// R.string.configure_wallpaper, 0);
1740// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1741// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1742// }
Mike Clerona0618e42009-10-22 13:55:21 -07001743 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001744 }
1745
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001746 /**
1747 * Registers various content observers. The current implementation registers
1748 * only a favorites observer to keep track of the favorites applications.
1749 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001750 private void registerContentObservers() {
1751 ContentResolver resolver = getContentResolver();
1752 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1753 true, mWidgetObserver);
1754 }
1755
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001756 @Override
1757 public boolean dispatchKeyEvent(KeyEvent event) {
1758 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1759 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001760 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001761 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001762 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka9bc8eba2012-05-21 20:36:44 -07001763 if (doesFileExist(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08001764 dumpState();
1765 return true;
1766 }
1767 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001768 }
1769 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1770 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001771 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001772 return true;
1773 }
1774 }
1775
1776 return super.dispatchKeyEvent(event);
1777 }
1778
Joe Onorato88ec0992009-11-19 13:16:06 -08001779 @Override
1780 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001781 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001782 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001783 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001784 Folder openFolder = mWorkspace.getOpenFolder();
1785 if (openFolder.isEditingName()) {
1786 openFolder.dismissEditingName();
1787 } else {
1788 closeFolder();
1789 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001790 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001791 mWorkspace.exitWidgetResizeMode();
1792
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001793 // Back button is a no-op here, but give at least some feedback for the button press
1794 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001795 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001796 }
1797
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001798 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001799 * Re-listen when widgets are reset.
1800 */
1801 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001802 if (mAppWidgetHost != null) {
1803 mAppWidgetHost.startListening();
1804 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001805 }
1806
1807 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001808 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1809 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001810 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001811 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001812 if (mModel != null) {
1813 mModel.unbindWorkspaceItems();
1814 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001815 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001816
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001817 /**
1818 * Launches the intent referred by the clicked shortcut.
1819 *
1820 * @param v The view representing the clicked shortcut.
1821 */
1822 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001823 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1824 // view has detached (it's possible for this to happen if the view is removed mid touch).
1825 if (v.getWindowToken() == null) {
1826 return;
1827 }
1828
Winson Chung9b0b2fe2012-02-24 13:03:34 -08001829 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001830 return;
1831 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001832
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001833 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001834 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001835 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001836 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001837 int[] pos = new int[2];
1838 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001839 intent.setSourceBounds(new Rect(pos[0], pos[1],
1840 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07001841
1842 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001843
1844 if (success && v instanceof BubbleTextView) {
1845 mWaitingForResume = (BubbleTextView) v;
1846 mWaitingForResume.setStayPressed(true);
1847 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001848 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001849 if (v instanceof FolderIcon) {
1850 FolderIcon fi = (FolderIcon) v;
1851 handleFolderClick(fi);
1852 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001853 } else if (v == mAllAppsButton) {
1854 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001855 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001856 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001857 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001858 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001859 }
1860 }
1861
Michael Jurka0e260592010-06-30 17:07:39 -07001862 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001863 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001864 // clicking anywhere on the workspace causes the customization drawer to slide down
1865 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001866 return false;
1867 }
1868
Michael Jurkaaf442092010-06-10 17:01:57 -07001869 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001870 * Event handler for the search button
1871 *
1872 * @param v The view that was clicked.
1873 */
1874 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001875 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1876
Amith Yamasania135ba82011-08-09 17:42:01 -07001877 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001878 }
1879
1880 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001881 * Event handler for the voice button
1882 *
1883 * @param v The view that was clicked.
1884 */
1885 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001886 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001887
Michael Jurkaae65ee32012-04-30 11:45:54 -07001888 try {
1889 final SearchManager searchManager =
1890 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1891 ComponentName activityName = searchManager.getGlobalSearchActivity();
1892 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07001893 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001894 if (activityName != null) {
1895 intent.setPackage(activityName.getPackageName());
1896 }
Michael Jurka86a720e2012-05-09 11:23:23 -07001897 startActivity(null, intent, "onClickVoiceButton");
Winson Chung01b0b632012-05-22 10:18:14 -07001898 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001899 } catch (ActivityNotFoundException e) {
1900 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07001901 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07001902 startActivitySafely(null, intent, "onClickVoiceButton");
1903 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001904 }
1905
1906 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001907 * Event handler for the "grid" button that appears on the home screen, which
1908 * enters all apps mode.
1909 *
1910 * @param v The view that was clicked.
1911 */
1912 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001913 showAllApps(true);
1914 }
1915
1916 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001917 // Provide the same haptic feedback that the system offers for virtual keys.
1918 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001919 }
1920
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001921 public void onClickAppMarketButton(View v) {
1922 if (mAppMarketIntent != null) {
Winson Chungc7450e32012-04-17 17:34:08 -07001923 startActivitySafely(v, mAppMarketIntent, "app market");
Winson Chung4f916f42012-03-26 15:30:59 -07001924 } else {
1925 Log.e(TAG, "Invalid app market intent.");
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001926 }
1927 }
1928
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001929 void startApplicationDetailsActivity(ComponentName componentName) {
1930 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001931 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1932 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001933 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07001934 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001935 }
1936
Patrick Dubroy5539af72010-09-07 15:22:01 -07001937 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1938 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1939 // System applications cannot be installed. For now, show a toast explaining that.
1940 // We may give them the option of disabling apps this way.
1941 int messageId = R.string.uninstall_system_app_text;
1942 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1943 } else {
1944 String packageName = appInfo.componentName.getPackageName();
1945 String className = appInfo.componentName.getClassName();
1946 Intent intent = new Intent(
1947 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001948 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1949 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001950 startActivity(intent);
1951 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001952 }
1953
Michael Jurka86a720e2012-05-09 11:23:23 -07001954 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001955 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07001956
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001957 try {
Winson Chung2672ff92012-05-04 16:22:30 -07001958 // Only launch using the new animation if the shortcut has not opted out (this is a
1959 // private contract between launcher and may be ignored in the future).
1960 boolean useLaunchAnimation = (v != null) &&
1961 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
1962 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07001963 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
1964 v.getMeasuredWidth(), v.getMeasuredHeight());
1965
1966 startActivity(intent, opts.toBundle());
1967 } else {
1968 startActivity(intent);
1969 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001970 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001971 } catch (SecurityException e) {
1972 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001973 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001974 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001975 "or use the exported attribute for this activity. "
1976 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001977 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001978 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001979 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001980
Michael Jurka86a720e2012-05-09 11:23:23 -07001981 boolean startActivitySafely(View v, Intent intent, Object tag) {
1982 boolean success = false;
1983 try {
1984 success = startActivity(v, intent, tag);
1985 } catch (ActivityNotFoundException e) {
1986 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1987 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
1988 }
1989 return success;
1990 }
1991
Romain Guy8e633c52010-03-04 12:51:36 -08001992 void startActivityForResultSafely(Intent intent, int requestCode) {
1993 try {
1994 startActivityForResult(intent, requestCode);
1995 } catch (ActivityNotFoundException e) {
1996 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1997 } catch (SecurityException e) {
1998 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1999 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2000 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2001 "or use the exported attribute for this activity.", e);
2002 }
2003 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002004
Adam Cohena9cf38f2011-05-02 15:36:58 -07002005 private void handleFolderClick(FolderIcon folderIcon) {
2006 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07002007 Folder openFolder = mWorkspace.getFolderForTag(info);
2008
2009 // If the folder info reports that the associated folder is open, then verify that
2010 // it is actually opened. There have been a few instances where this gets out of sync.
2011 if (info.opened && openFolder == null) {
2012 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2013 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
2014 info.opened = false;
2015 }
2016
Adam Cohena9cf38f2011-05-02 15:36:58 -07002017 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002018 // Close any open folder
2019 closeFolder();
2020 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002021 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002022 } else {
2023 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002024 int folderScreen;
2025 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002026 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002027 // .. and close it
2028 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002029 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002030 // Close any folder open on the current screen
2031 closeFolder();
2032 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002033 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002034 }
2035 }
2036 }
2037 }
2038
Adam Cohen268c4752012-06-06 17:47:33 -07002039 /**
2040 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2041 * in the DragLayer in the exact absolute location of the original FolderIcon.
2042 */
2043 private void copyFolderIconToImage(FolderIcon fi) {
2044 final int width = fi.getMeasuredWidth();
2045 final int height = fi.getMeasuredHeight();
2046
2047 // Lazy load ImageView, Bitmap and Canvas
2048 if (mFolderIconImageView == null) {
2049 mFolderIconImageView = new ImageView(this);
2050 }
2051 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2052 mFolderIconBitmap.getHeight() != height) {
2053 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2054 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2055 }
2056
2057 DragLayer.LayoutParams lp;
2058 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2059 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2060 } else {
2061 lp = new DragLayer.LayoutParams(width, height);
2062 }
2063
2064 mDragLayer.getViewRectRelativeToSelf(fi, mRectForFolderAnimation);
2065 lp.customPosition = true;
2066 lp.x = mRectForFolderAnimation.left;
2067 lp.y = mRectForFolderAnimation.top;
Adam Cohen8ec23032012-06-08 14:46:22 -07002068 lp.width = width;
2069 lp.height = height;
Adam Cohen268c4752012-06-06 17:47:33 -07002070
2071 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2072 fi.draw(mFolderIconCanvas);
2073 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohen8ec23032012-06-08 14:46:22 -07002074 if (fi.mFolder != null) {
2075 mFolderIconImageView.setPivotX(fi.mFolder.getPivotXForIconAnimation());
2076 mFolderIconImageView.setPivotY(fi.mFolder.getPivotYForIconAnimation());
2077 }
Adam Cohen268c4752012-06-06 17:47:33 -07002078 // Just in case this image view is still in the drag layer from a previous animation,
2079 // we remove it and re-add it.
2080 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2081 mDragLayer.removeView(mFolderIconImageView);
2082 }
2083 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohen8ec23032012-06-08 14:46:22 -07002084 if (fi.mFolder != null) {
2085 fi.mFolder.bringToFront();
2086 }
Adam Cohen268c4752012-06-06 17:47:33 -07002087 }
2088
Adam Cohen2801caf2011-05-13 20:57:39 -07002089 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002090 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002091 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2092 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2093 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2094
Adam Cohenc51934b2011-07-26 21:07:43 -07002095 FolderInfo info = (FolderInfo) fi.getTag();
2096 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2097 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002098 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2099 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002100 }
2101
Adam Cohen268c4752012-06-06 17:47:33 -07002102 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2103 copyFolderIconToImage(fi);
2104 fi.setVisibility(View.INVISIBLE);
2105
2106 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(mFolderIconImageView, alpha,
2107 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002108 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2109 oa.start();
2110 }
2111
Adam Cohen268c4752012-06-06 17:47:33 -07002112 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002113 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002114 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2115 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2116 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2117
Adam Cohen268c4752012-06-06 17:47:33 -07002118 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002119
Adam Cohen268c4752012-06-06 17:47:33 -07002120 // We remove and re-draw the FolderIcon in-case it has changed
2121 mDragLayer.removeView(mFolderIconImageView);
2122 copyFolderIconToImage(fi);
Adam Cohen268c4752012-06-06 17:47:33 -07002123 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(mFolderIconImageView, alpha,
2124 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002125 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002126 oa.addListener(new AnimatorListenerAdapter() {
2127 @Override
2128 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002129 if (cl != null) {
2130 cl.clearFolderLeaveBehind();
2131 // Remove the ImageView copy of the FolderIcon and make the original visible.
2132 mDragLayer.removeView(mFolderIconImageView);
2133 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002134 }
2135 }
2136 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002137 oa.start();
2138 }
2139
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002140 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002141 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002142 * is animated relative to the specified View. If the View is null, no animation
2143 * is played.
2144 *
2145 * @param folderInfo The FolderInfo describing the folder to open.
2146 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002147 public void openFolder(FolderIcon folderIcon) {
2148 Folder folder = folderIcon.mFolder;
2149 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002150
Adam Cohena9cf38f2011-05-02 15:36:58 -07002151 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002152
Adam Cohen4554ee12011-08-03 16:13:21 -07002153 // Just verify that the folder hasn't already been added to the DragLayer.
2154 // There was a one-off crash where the folder had a parent already.
2155 if (folder.getParent() == null) {
2156 mDragLayer.addView(folder);
2157 mDragController.addDropTarget((DropTarget) folder);
2158 } else {
2159 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2160 folder.getParent() + ").");
2161 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002162 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002163 growAndFadeOutFolderIcon(folderIcon);
Adam Cohen4554ee12011-08-03 16:13:21 -07002164 }
2165
2166 public void closeFolder() {
2167 Folder folder = mWorkspace.getOpenFolder();
2168 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002169 if (folder.isEditingName()) {
2170 folder.dismissEditingName();
2171 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002172 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002173
2174 // Dismiss the folder cling
2175 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002176 }
2177 }
2178
2179 void closeFolder(Folder folder) {
2180 folder.getInfo().opened = false;
2181
2182 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2183 if (parent != null) {
2184 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2185 shrinkAndFadeInFolderIcon(fi);
2186 }
2187 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002188 }
2189
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002190 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002191 if (!isDraggingEnabled()) return false;
2192 if (isWorkspaceLocked()) return false;
2193 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002194
2195 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002196 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002197 }
2198
Michael Jurka0280c3b2010-09-17 15:00:07 -07002199 resetAddInfo();
2200 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002201 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002202 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002203 return true;
2204 }
2205
Winson Chung3d503fb2011-07-13 17:25:49 -07002206 // The hotseat touch handling does not go through Workspace, and we always allow long press
2207 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002208 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002209 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2210 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002211 if (itemUnderLongClick == null) {
2212 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002213 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2214 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002215 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002216 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002217 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002218 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002219 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002220 }
2221 }
2222 }
2223 return true;
2224 }
2225
Winson Chung3d503fb2011-07-13 17:25:49 -07002226 boolean isHotseatLayout(View layout) {
2227 return mHotseat != null && layout != null &&
2228 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2229 }
2230 Hotseat getHotseat() {
2231 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002232 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002233 SearchDropTargetBar getSearchBar() {
2234 return mSearchDropTargetBar;
2235 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002236
Winson Chung3d503fb2011-07-13 17:25:49 -07002237 /**
2238 * Returns the CellLayout of the specified container at the specified screen.
2239 */
2240 CellLayout getCellLayout(long container, int screen) {
2241 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2242 if (mHotseat != null) {
2243 return mHotseat.getLayout();
2244 } else {
2245 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002246 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002247 } else {
2248 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002249 }
2250 }
2251
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002252 Workspace getWorkspace() {
2253 return mWorkspace;
2254 }
2255
Daniel Sandler843e8602010-06-07 14:59:01 -04002256 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2257 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002258 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002259 }
2260
Andrew Flynn0dca1ec2012-02-29 13:33:22 -08002261 public boolean isAllAppsButtonRank(int rank) {
2262 return mHotseat.isAllAppsButtonRank(rank);
2263 }
2264
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002265 // AllAppsView.Watcher
2266 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002267 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002268 mWorkspace.setVisibility(View.GONE);
2269 }
2270 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002271
2272 /**
2273 * Helper method for the cameraZoomIn/cameraZoomOut animations
2274 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002275 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002276 * @param scaleFactor The scale factor used for the zoom
2277 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002278 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002279 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002280 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002281 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002282
Winson Chung18f41f82012-05-09 13:28:10 -07002283 void disableWallpaperIfInAllApps() {
2284 // Only disable it if we are in all apps
2285 if (mState == State.APPS_CUSTOMIZE) {
2286 if (mAppsCustomizeTabHost != null &&
2287 !mAppsCustomizeTabHost.isTransitioning()) {
2288 updateWallpaperVisibility(false);
2289 }
2290 }
2291 }
2292
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002293 void updateWallpaperVisibility(boolean visible) {
2294 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2295 int curflags = getWindow().getAttributes().flags
2296 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2297 if (wpflags != curflags) {
2298 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2299 }
2300 }
2301
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002302 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2303 if (v instanceof LauncherTransitionable) {
2304 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2305 }
2306 }
2307
Michael Jurkabed61d22012-02-14 22:51:29 -08002308 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
Winson Chung7c7a22d2012-06-01 13:46:48 -07002309 if (toWorkspace) {
2310 Log.d(TAG, "6549598 Start animation to workspace");
2311 } else {
2312 Log.d(TAG, "6549598 Start animation to all apps");
2313 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002314 if (v instanceof LauncherTransitionable) {
2315 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2316 }
Winson Chung70442722012-02-10 15:43:22 -08002317
2318 // Update the workspace transition step as well
2319 dispatchOnLauncherTransitionStep(v, 0f);
2320 }
2321
2322 private void dispatchOnLauncherTransitionStep(View v, float t) {
2323 if (v instanceof LauncherTransitionable) {
2324 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2325 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002326 }
2327
2328 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
Winson Chung7c7a22d2012-06-01 13:46:48 -07002329 if (toWorkspace) {
2330 Log.d(TAG, "6549598 End animation to workspace");
2331 } else {
2332 Log.d(TAG, "6549598 End animation to all apps");
2333 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002334 if (v instanceof LauncherTransitionable) {
2335 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2336 }
Winson Chung70442722012-02-10 15:43:22 -08002337
2338 // Update the workspace transition step as well
2339 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002340 }
2341
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002342 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002343 * Things to test when changing the following seven functions.
2344 * - Home from workspace
2345 * - from center screen
2346 * - from other screens
2347 * - Home from all apps
2348 * - from center screen
2349 * - from other screens
2350 * - Back from all apps
2351 * - from center screen
2352 * - from other screens
2353 * - Launch app from workspace and quit
2354 * - with back
2355 * - with home
2356 * - Launch app from all apps and quit
2357 * - with back
2358 * - with home
2359 * - Go to a screen that's not the default, then all
2360 * apps, and launch and app, and go back
2361 * - with back
2362 * -with home
2363 * - On workspace, long press power and go back
2364 * - with back
2365 * - with home
2366 * - On all apps, long press power and go back
2367 * - with back
2368 * - with home
2369 * - On workspace, power off
2370 * - On all apps, power off
2371 * - Launch an app and turn off the screen while in that app
2372 * - Go back with home key
2373 * - Go back with back key TODO: make this not go to workspace
2374 * - From all apps
2375 * - From workspace
2376 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2377 * - From all apps
2378 * - From the center workspace
2379 * - From another workspace
2380 */
2381
2382 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002383 * Zoom the camera out from the workspace to reveal 'toView'.
2384 * Assumes that the view to show is anchored at either the very top or very bottom
2385 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002386 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002387 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002388 if (mStateAnimation != null) {
2389 mStateAnimation.cancel();
2390 mStateAnimation = null;
2391 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002392 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002393
Winson Chungf0ea4d32011-06-06 14:27:16 -07002394 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2395 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2396 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002397 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002398 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002399 final int startDelay =
2400 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002401
Michael Jurkab3e22d92011-10-31 15:58:33 -07002402 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002403
Michael Jurkad74c9842011-07-10 12:44:21 -07002404 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002405 Animator workspaceAnim =
2406 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002407
2408 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002409 toView.setScaleX(scale);
2410 toView.setScaleY(scale);
2411 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2412 scaleAnim.
2413 scaleX(1f).scaleY(1f).
2414 setDuration(duration).
2415 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002416
Winson Chungf0ea4d32011-06-06 14:27:16 -07002417 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002418 toView.setAlpha(0f);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002419 final ObjectAnimator alphaAnim = ObjectAnimator
2420 .ofFloat(toView, "alpha", 0f, 1f)
2421 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002422 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002423 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2424 @Override
2425 public void onAnimationUpdate(ValueAnimator animation) {
2426 float t = (Float) animation.getAnimatedValue();
2427 dispatchOnLauncherTransitionStep(fromView, t);
2428 dispatchOnLauncherTransitionStep(toView, t);
2429 }
2430 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002431
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002432 // toView should appear right at the end of the workspace shrink
2433 // animation
2434 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002435 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002436 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002437
2438 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002439 boolean animationCancelled = false;
2440
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002441 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002442 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002443 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002444 // Prepare the position
2445 toView.setTranslationX(0.0f);
2446 toView.setTranslationY(0.0f);
2447 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002448 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002449 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002450 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002451 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002452 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2453 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002454
2455 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2456 // Hide the workspace scrollbar
2457 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002458 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002459 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002460 if (!animationCancelled) {
2461 updateWallpaperVisibility(false);
2462 }
Winson Chungc7d2b602012-05-16 17:02:20 -07002463
2464 // Hide the search bar
2465 mSearchDropTargetBar.hideSearchBar(false);
Adam Cohenf4ddea32011-09-12 13:46:42 -07002466 }
2467
Adam Cohencff6af82011-09-13 14:51:53 -07002468 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002469 public void onAnimationCancel(Animator animation) {
2470 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002471 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002472 });
2473
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002474 if (workspaceAnim != null) {
2475 mStateAnimation.play(workspaceAnim);
2476 }
Michael Jurka1899a362011-11-03 13:50:45 -07002477
2478 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002479 final ViewTreeObserver observer;
2480
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002481 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2482 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002483
2484 // If any of the objects being animated haven't been measured/laid out
2485 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002486 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002487 (mWorkspace.getMeasuredWidth() == 0) ||
2488 (toView.getMeasuredWidth() == 0)) {
2489 observer = mWorkspace.getViewTreeObserver();
2490 delayAnim = true;
2491 } else {
2492 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002493 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002494
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002495 final AnimatorSet stateAnimation = mStateAnimation;
2496 final Runnable startAnimRunnable = new Runnable() {
2497 public void run() {
2498 // Check that mStateAnimation hasn't changed while
2499 // we waited for a layout/draw pass
2500 if (mStateAnimation != stateAnimation)
2501 return;
2502 setPivotsForZoom(toView, scale);
2503 dispatchOnLauncherTransitionStart(fromView, animated, false);
2504 dispatchOnLauncherTransitionStart(toView, animated, false);
2505 mWorkspace.post(new Runnable() {
2506 public void run() {
2507 // Check that mStateAnimation hasn't changed while
2508 // we waited for a layout/draw pass
2509 if (mStateAnimation != stateAnimation)
2510 return;
2511 mStateAnimation.start();
2512 }
2513 });
2514 }
2515 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002516 if (delayAnim) {
2517 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2518 public void onGlobalLayout() {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002519 mWorkspace.post(startAnimRunnable);
Michael Jurka3a9fced2012-04-13 14:44:29 -07002520 observer.removeOnGlobalLayoutListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002521 }
2522 };
2523 observer.addOnGlobalLayoutListener(delayedStart);
2524 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002525 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002526 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002527 } else {
2528 toView.setTranslationX(0.0f);
2529 toView.setTranslationY(0.0f);
2530 toView.setScaleX(1.0f);
2531 toView.setScaleY(1.0f);
2532 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002533 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002534
Michael Jurkabed61d22012-02-14 22:51:29 -08002535 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2536 // Hide the workspace scrollbar
2537 mWorkspace.hideScrollingIndicator(true);
2538 hideDockDivider();
Winson Chungc7d2b602012-05-16 17:02:20 -07002539
2540 // Hide the search bar
2541 mSearchDropTargetBar.hideSearchBar(false);
Michael Jurkaabded662011-03-04 12:06:57 -08002542 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002543 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002544 dispatchOnLauncherTransitionStart(fromView, animated, false);
2545 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002546 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002547 dispatchOnLauncherTransitionStart(toView, animated, false);
2548 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002549 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002550 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002551 }
2552
2553 /**
2554 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002555 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002556 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002557 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002558 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2559 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002560
Michael Jurkab3e22d92011-10-31 15:58:33 -07002561 if (mStateAnimation != null) {
2562 mStateAnimation.cancel();
2563 mStateAnimation = null;
2564 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002565 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002566
Winson Chungf0ea4d32011-06-06 14:27:16 -07002567 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002568 final int fadeOutDuration =
2569 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002570 final float scaleFactor = (float)
2571 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2572 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002573 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002574 Animator workspaceAnim = null;
2575
2576 if (toState == State.WORKSPACE) {
2577 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2578 workspaceAnim = mWorkspace.getChangeStateAnimation(
2579 Workspace.State.NORMAL, animated, stagger);
2580 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2581 workspaceAnim = mWorkspace.getChangeStateAnimation(
2582 Workspace.State.SPRING_LOADED, animated);
2583 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002584
Michael Jurkab3e22d92011-10-31 15:58:33 -07002585 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002586 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002587 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002588 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002589 final LauncherViewPropertyAnimator scaleAnim =
2590 new LauncherViewPropertyAnimator(fromView);
2591 scaleAnim.
2592 scaleX(scaleFactor).scaleY(scaleFactor).
2593 setDuration(duration).
2594 setInterpolator(new Workspace.ZoomInInterpolator());
2595
2596 final ObjectAnimator alphaAnim = ObjectAnimator
2597 .ofFloat(fromView, "alpha", 1f, 0f)
2598 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002599 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002600 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2601 @Override
2602 public void onAnimationUpdate(ValueAnimator animation) {
2603 float t = 1f - (Float) animation.getAnimatedValue();
2604 dispatchOnLauncherTransitionStep(fromView, t);
2605 dispatchOnLauncherTransitionStep(toView, t);
2606 }
2607 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002608
Michael Jurkabed61d22012-02-14 22:51:29 -08002609 mStateAnimation = new AnimatorSet();
2610
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002611 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2612 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002613
2614 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002615 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002616 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002617 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002618 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002619 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2620 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkabafdaaf2012-04-26 13:43:25 -07002621 if (mWorkspace != null) {
2622 mWorkspace.hideScrollingIndicator(false);
2623 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002624 if (onCompleteRunnable != null) {
2625 onCompleteRunnable.run();
2626 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002627 }
2628 });
2629
Winson Chungf0ea4d32011-06-06 14:27:16 -07002630 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002631 if (workspaceAnim != null) {
2632 mStateAnimation.play(workspaceAnim);
2633 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002634 dispatchOnLauncherTransitionStart(fromView, animated, true);
2635 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002636 final Animator stateAnimation = mStateAnimation;
2637 mWorkspace.post(new Runnable() {
2638 public void run() {
2639 if (stateAnimation != mStateAnimation)
2640 return;
2641 mStateAnimation.start();
2642 }
2643 });
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002644 } else {
2645 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002646 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002647 dispatchOnLauncherTransitionStart(fromView, animated, true);
2648 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002649 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08002650 dispatchOnLauncherTransitionStart(toView, animated, true);
2651 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002652 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002653 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002654 }
2655
Michael Jurkae326f182011-11-21 14:05:46 -08002656 @Override
2657 public void onTrimMemory(int level) {
2658 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07002659 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08002660 mAppsCustomizeTabHost.onTrimMemory();
2661 }
2662 }
2663
Winson Chung18f41f82012-05-09 13:28:10 -07002664 @Override
2665 public void onWindowFocusChanged(boolean hasFocus) {
2666 if (!hasFocus) {
2667 // When another window occludes launcher (like the notification shade, or recents),
2668 // ensure that we enable the wallpaper flag so that transitions are done correctly.
2669 updateWallpaperVisibility(true);
2670 } else {
2671 // When launcher has focus again, disable the wallpaper if we are in AllApps
Winson Chung6cf79092012-06-07 14:50:10 -07002672 mWorkspace.postDelayed(new Runnable() {
2673 @Override
2674 public void run() {
2675 disableWallpaperIfInAllApps();
2676 }
2677 }, 500);
Winson Chung18f41f82012-05-09 13:28:10 -07002678 }
2679 }
2680
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002681 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002682 showWorkspace(animated, null);
2683 }
2684
2685 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002686 if (mState != State.WORKSPACE) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002687 boolean wasInSpringLoadedMode = (mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002688 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002689 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002690
Winson Chungc7d2b602012-05-16 17:02:20 -07002691 // Show the search bar (only animate if we were showing the drop target bar in spring
2692 // loaded mode)
2693 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
2694
Michael Jurkab737ee62011-11-15 15:57:22 -08002695 // We only need to animate in the dock divider if we're going from spring loaded mode
Winson Chungc7d2b602012-05-16 17:02:20 -07002696 showDockDivider(animated && wasInSpringLoadedMode);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002697
2698 // Set focus to the AppsCustomize button
2699 if (mAllAppsButton != null) {
2700 mAllAppsButton.requestFocus();
2701 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002702 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002703
Michael Jurkab737ee62011-11-15 15:57:22 -08002704 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002705
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002706 // Change the state *after* we've called all the transition code
2707 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002708
Winson Chung5fb63472011-02-02 17:03:37 -08002709 // Resume the auto-advance of widgets
2710 mUserPresent = true;
2711 updateRunning();
2712
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002713 // send an accessibility event to announce the context change
2714 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002715 }
2716
Michael Jurkab3e22d92011-10-31 15:58:33 -07002717 void showAllApps(boolean animated) {
2718 if (mState != State.WORKSPACE) return;
2719
2720 showAppsCustomizeHelper(animated, false);
2721 mAppsCustomizeTabHost.requestFocus();
2722
Michael Jurkab3e22d92011-10-31 15:58:33 -07002723 // Change the state *after* we've called all the transition code
2724 mState = State.APPS_CUSTOMIZE;
2725
2726 // Pause the auto-advance of widgets until we are out of AllApps
2727 mUserPresent = false;
2728 updateRunning();
2729 closeFolder();
2730
2731 // Send an accessibility event to announce the context change
2732 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2733 }
2734
Adam Cohen7777d962011-08-18 18:58:38 -07002735 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002736 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002737 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002738 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002739 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002740 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002741 }
Adam Cohen7777d962011-08-18 18:58:38 -07002742
Adam Cohened66b2b2012-01-23 17:28:51 -08002743 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2744 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002745 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2746
Winson Chunge7a03942011-08-05 15:05:12 -07002747 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002748 @Override
2749 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002750 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002751 // Before we show workspace, hide all apps again because
2752 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2753 // clean up our state transition functions
2754 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002755 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002756 } else {
2757 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002758 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002759 }
2760 }, (extendedDelay ?
2761 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2762 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2763 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002764
Michael Jurkad3ef3062010-11-23 16:23:58 -08002765 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002766 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002767 final boolean animated = true;
2768 final boolean springLoaded = true;
2769 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002770 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002771 }
2772 // Otherwise, we are not in spring loaded mode, so don't do anything.
2773 }
2774
Michael Jurkab737ee62011-11-15 15:57:22 -08002775 void hideDockDivider() {
2776 if (mQsbDivider != null && mDockDivider != null) {
2777 mQsbDivider.setVisibility(View.INVISIBLE);
2778 mDockDivider.setVisibility(View.INVISIBLE);
2779 }
2780 }
2781
2782 void showDockDivider(boolean animated) {
2783 if (mQsbDivider != null && mDockDivider != null) {
2784 mQsbDivider.setVisibility(View.VISIBLE);
2785 mDockDivider.setVisibility(View.VISIBLE);
2786 if (mDividerAnimator != null) {
2787 mDividerAnimator.cancel();
2788 mQsbDivider.setAlpha(1f);
2789 mDockDivider.setAlpha(1f);
2790 mDividerAnimator = null;
2791 }
2792 if (animated) {
2793 mDividerAnimator = new AnimatorSet();
2794 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2795 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2796 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2797 mDividerAnimator.start();
2798 }
2799 }
2800 }
2801
Michael Jurkab3e22d92011-10-31 15:58:33 -07002802 void lockAllApps() {
2803 // TODO
2804 }
2805
2806 void unlockAllApps() {
2807 // TODO
2808 }
2809
Adam Cohenfc53cd22011-07-20 15:45:11 -07002810 public boolean isAllAppsCustomizeOpen() {
2811 return mState == State.APPS_CUSTOMIZE;
2812 }
2813
Winson Chungf0ea4d32011-06-06 14:27:16 -07002814 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002815 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002816 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002817 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002818 if (!LauncherApplication.isScreenLarge()) {
2819 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002820 if (mHotseat.getAlpha() != 1f) {
2821 int duration = mSearchDropTargetBar.getTransitionInDuration();
2822 mHotseat.animate().alpha(1f).setDuration(duration);
2823 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002824 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002825 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002826 }
2827 }
2828 }
2829
2830 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002831 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002832 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002833 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002834 if (!LauncherApplication.isScreenLarge()) {
2835 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002836 if (mHotseat.getAlpha() != 0f) {
2837 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2838 mHotseat.animate().alpha(0f).setDuration(duration);
2839 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002840 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002841 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002842 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002843 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002844 }
2845
Patrick Dubroy5f445422011-02-18 14:35:21 -08002846 /**
2847 * Add an item from all apps or customize onto the given workspace screen.
2848 * If layout is null, add to the current screen.
2849 */
2850 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002851 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07002852 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07002853 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002854 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002855
Winson Chungdff8ebb2011-09-08 17:25:31 -07002856 /** Maps the current orientation to an index for referencing orientation correct global icons */
2857 private int getCurrentOrientationIndexForGlobalIcons() {
2858 // default - 0, landscape - 1
2859 switch (getResources().getConfiguration().orientation) {
2860 case Configuration.ORIENTATION_LANDSCAPE:
2861 return 1;
2862 default:
2863 return 0;
2864 }
2865 }
2866
Michael Jurkaae65ee32012-04-30 11:45:54 -07002867 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002868 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002869 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002870 // Look for the toolbar icon specified in the activity meta-data
2871 Bundle metaData = packageManager.getActivityInfo(
2872 activityName, PackageManager.GET_META_DATA).metaData;
2873 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002874 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002875 if (iconResId != 0) {
2876 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002877 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002878 }
2879 }
2880 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002881 // This can happen if the activity defines an invalid drawable
2882 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2883 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002884 } catch (Resources.NotFoundException nfe) {
2885 // This can happen if the activity defines an invalid drawable
2886 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2887 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002888 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002889 return null;
2890 }
2891
2892 // if successful in getting icon, return it; otherwise, set button to use default drawable
2893 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002894 int buttonId, ComponentName activityName, int fallbackDrawableId,
2895 String toolbarResourceName) {
2896 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002897 Resources r = getResources();
2898 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2899 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002900
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002901 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002902 // If we were unable to find the icon via the meta-data, use a generic one
2903 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002904 toolbarIcon = r.getDrawable(fallbackDrawableId);
2905 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002906 if (button != null) {
2907 button.setCompoundDrawables(toolbarIcon, null, null, null);
2908 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002909 return null;
2910 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002911 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002912 if (button != null) {
2913 button.setCompoundDrawables(toolbarIcon, null, null, null);
2914 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002915 return toolbarIcon.getConstantState();
2916 }
2917 }
2918
2919 // if successful in getting icon, return it; otherwise, set button to use default drawable
2920 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002921 int buttonId, ComponentName activityName, int fallbackDrawableId,
2922 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002923 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002924 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002925
Michael Jurka19e0fc52011-07-22 18:00:21 -07002926 if (button != null) {
2927 // If we were unable to find the icon via the meta-data, use a
2928 // generic one
2929 if (toolbarIcon == null) {
2930 button.setImageResource(fallbackDrawableId);
2931 } else {
2932 button.setImageDrawable(toolbarIcon);
2933 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002934 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002935
2936 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2937
Michael Jurka0423dcf2010-10-05 14:56:18 -07002938 }
2939
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002940 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2941 TextView button = (TextView) findViewById(buttonId);
2942 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2943 }
2944
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002945 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002946 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002947 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002948 }
2949
Winson Chungbb185bd2011-11-21 12:31:42 -08002950 private void invalidatePressedFocusedStates(View container, View button) {
2951 if (container instanceof HolographicLinearLayout) {
2952 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2953 layout.invalidatePressedFocusedStates();
2954 } else if (button instanceof HolographicImageView) {
2955 HolographicImageView view = (HolographicImageView) button;
2956 view.invalidatePressedFocusedStates();
2957 }
2958 }
2959
Winson Chungc51db6a2011-10-05 11:44:49 -07002960 private boolean updateGlobalSearchIcon() {
2961 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002962 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2963 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002964 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002965 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07002966 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07002967
Winson Chung1cad91e2011-05-25 17:41:01 -07002968 final SearchManager searchManager =
2969 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2970 ComponentName activityName = searchManager.getGlobalSearchActivity();
2971 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002972 int coi = getCurrentOrientationIndexForGlobalIcons();
2973 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07002974 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2975 TOOLBAR_SEARCH_ICON_METADATA_NAME);
2976 if (sGlobalSearchIcon[coi] == null) {
2977 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
2978 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
2979 TOOLBAR_ICON_METADATA_NAME);
2980 }
2981
Winson Chung649723c2011-07-06 20:41:23 -07002982 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002983 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2984 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002985 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002986 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002987 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002988 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002989 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002990 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2991 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2992 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002993 voiceButton.setVisibility(View.GONE);
Michael Jurkac60498a2012-05-07 15:29:42 -07002994 if (voiceButtonProxy != null) {
2995 voiceButtonProxy.setVisibility(View.GONE);
2996 }
Winson Chungc51db6a2011-10-05 11:44:49 -07002997 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002998 }
2999 }
3000
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003001 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003002 final View searchButtonContainer = findViewById(R.id.search_button_container);
3003 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003004 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003005 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003006 }
3007
Winson Chungc51db6a2011-10-05 11:44:49 -07003008 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07003009 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07003010 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003011 final View voiceButton = findViewById(R.id.voice_button);
Winson Chunge3fbfa92012-04-24 14:34:28 -07003012 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
Winson Chung97d85d22011-04-13 11:27:36 -07003013
Winson Chungc51db6a2011-10-05 11:44:49 -07003014 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003015 final SearchManager searchManager =
3016 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3017 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3018
3019 ComponentName activityName = null;
3020 if (globalSearchActivity != null) {
3021 // Check if the global search activity handles voice search
3022 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3023 intent.setPackage(globalSearchActivity.getPackageName());
3024 activityName = intent.resolveActivity(getPackageManager());
3025 }
3026
3027 if (activityName == null) {
3028 // Fallback: check if an activity other than the global search activity
3029 // resolves this
3030 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3031 activityName = intent.resolveActivity(getPackageManager());
3032 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003033 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003034 int coi = getCurrentOrientationIndexForGlobalIcons();
3035 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003036 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3037 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3038 if (sVoiceSearchIcon[coi] == null) {
3039 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3040 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3041 TOOLBAR_ICON_METADATA_NAME);
3042 }
Winson Chung649723c2011-07-06 20:41:23 -07003043 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07003044 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003045 voiceButton.setVisibility(View.VISIBLE);
Jim Miller14091b12012-04-24 19:27:54 -07003046 if (voiceButtonProxy != null) {
3047 voiceButtonProxy.setVisibility(View.VISIBLE);
3048 }
Winson Chungbb185bd2011-11-21 12:31:42 -08003049 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003050 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003051 } else {
Winson Chung649723c2011-07-06 20:41:23 -07003052 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07003053 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003054 voiceButton.setVisibility(View.GONE);
Jim Miller14091b12012-04-24 19:27:54 -07003055 if (voiceButtonProxy != null) {
3056 voiceButtonProxy.setVisibility(View.GONE);
3057 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003058 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003059 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003060 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003061
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003062 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003063 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3064 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003065 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003066 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003067 }
3068
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003069 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003070 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003071 */
3072 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003073 final View marketButton = findViewById(R.id.market_button);
3074 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3075 // Find the app market activity by resolving an intent.
3076 // (If multiple app markets are installed, it will return the ResolverActivity.)
3077 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07003078 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003079 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07003080 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07003081 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003082 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3083 TOOLBAR_ICON_METADATA_NAME);
Winson Chung785d2eb2011-04-14 16:08:02 -07003084 marketButton.setVisibility(View.VISIBLE);
3085 } else {
3086 // We should hide and disable the view so that we don't try and restore the visibility
3087 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3088 marketButton.setVisibility(View.GONE);
3089 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003090 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003091 }
3092
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003093 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003094 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003095 }
3096
Michael Jurkad7c28052012-04-27 15:43:36 -07003097 @Override
3098 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
3099 boolean result = super.dispatchPopulateAccessibilityEvent(event);
3100 final List<CharSequence> text = event.getText();
3101 text.clear();
3102 text.add(getString(R.string.home));
3103 return result;
3104 }
3105
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003106 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003107 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003108 */
3109 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3110 @Override
3111 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003112 closeSystemDialogs();
3113 }
3114 }
3115
3116 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003117 * Receives notifications whenever the appwidgets are reset.
3118 */
3119 private class AppWidgetResetObserver extends ContentObserver {
3120 public AppWidgetResetObserver() {
3121 super(new Handler());
3122 }
3123
3124 @Override
3125 public void onChange(boolean selfChange) {
3126 onAppWidgetReset();
3127 }
3128 }
3129
3130 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003131 * If the activity is currently paused, signal that we need to re-run the loader
3132 * in onResume.
3133 *
3134 * This needs to be called from incoming places where resources might have been loaded
3135 * while we are paused. That is becaues the Configuration might be wrong
3136 * when we're not running, and if it comes back to what it was when we
3137 * were paused, we are not restarted.
3138 *
3139 * Implementation of the method from LauncherModel.Callbacks.
3140 *
3141 * @return true if we are currently paused. The caller might be able to
3142 * skip some work in that case since we will come back again.
3143 */
3144 public boolean setLoadOnResume() {
3145 if (mPaused) {
3146 Log.i(TAG, "setLoadOnResume");
3147 mOnResumeNeedsLoad = true;
3148 return true;
3149 } else {
3150 return false;
3151 }
3152 }
3153
3154 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003155 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003156 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003157 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003158 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003159 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003160 } else {
3161 return SCREEN_COUNT / 2;
3162 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003163 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003164
Joe Onorato9c1289c2009-08-17 11:03:03 -04003165 /**
3166 * Refreshes the shortcuts shown on the workspace.
3167 *
3168 * Implementation of the method from LauncherModel.Callbacks.
3169 */
3170 public void startBinding() {
3171 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07003172
Winson Chungf0c6ae02012-03-21 16:10:31 -07003173 mNewShortcutAnimatePage = -1;
3174 mNewShortcutAnimateViews.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003175 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003176 int count = workspace.getChildCount();
3177 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003178 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003179 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3180 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003181 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08003182 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003183 if (mHotseat != null) {
3184 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003185 }
3186 }
3187
3188 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003189 * Bind the items start-end from the list.
3190 *
3191 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003192 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003193 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003194 setLoadOnResume();
3195
Winson Chungf0c6ae02012-03-21 16:10:31 -07003196 // Get the list of added shortcuts and intersect them with the set of shortcuts here
3197 Set<String> newApps = new HashSet<String>();
3198 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);
3199
3200 Workspace workspace = mWorkspace;
3201 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003202 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003203
3204 // Short circuit if we are loading dock items for a configuration which has no dock
3205 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3206 mHotseat == null) {
3207 continue;
3208 }
3209
Joe Onorato9c1289c2009-08-17 11:03:03 -04003210 switch (item.itemType) {
3211 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3212 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003213 ShortcutInfo info = (ShortcutInfo) item;
3214 String uri = info.intent.toUri(0).toString();
3215 View shortcut = createShortcut(info);
Winson Chung3d503fb2011-07-13 17:25:49 -07003216 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3217 item.cellY, 1, 1, false);
Winson Chungbfeac062012-06-06 15:56:08 -07003218 boolean animateIconUp = false;
3219 synchronized (newApps) {
3220 if (newApps.contains(uri)) {
3221 animateIconUp = newApps.remove(uri);
3222 }
3223 }
3224 if (animateIconUp) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003225 // Prepare the view to be animated up
3226 shortcut.setAlpha(0f);
3227 shortcut.setScaleX(0f);
3228 shortcut.setScaleY(0f);
3229 mNewShortcutAnimatePage = item.screen;
3230 if (!mNewShortcutAnimateViews.contains(shortcut)) {
3231 mNewShortcutAnimateViews.add(shortcut);
3232 }
3233 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003234 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003235 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003236 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003237 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003238 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003239 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3240 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003241 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003242 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003243 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003244
Joe Onorato9c1289c2009-08-17 11:03:03 -04003245 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003246 }
3247
Joe Onorato9c1289c2009-08-17 11:03:03 -04003248 /**
3249 * Implementation of the method from LauncherModel.Callbacks.
3250 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003251 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003252 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003253 sFolders.clear();
3254 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003255 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003256
3257 /**
3258 * Add the views for a widget to the workspace.
3259 *
3260 * Implementation of the method from LauncherModel.Callbacks.
3261 */
3262 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003263 setLoadOnResume();
3264
Daniel Sandler843e8602010-06-07 14:59:01 -04003265 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3266 if (DEBUG_WIDGETS) {
3267 Log.d(TAG, "bindAppWidget: " + item);
3268 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003269 final Workspace workspace = mWorkspace;
3270
3271 final int appWidgetId = item.appWidgetId;
3272 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003273 if (DEBUG_WIDGETS) {
3274 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3275 }
3276
Joe Onorato9c1289c2009-08-17 11:03:03 -04003277 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3278
Joe Onorato9c1289c2009-08-17 11:03:03 -04003279 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003280 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003281
Winson Chung3d503fb2011-07-13 17:25:49 -07003282 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003283 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003284 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3285
Joe Onorato9c1289c2009-08-17 11:03:03 -04003286 workspace.requestLayout();
3287
Daniel Sandler843e8602010-06-07 14:59:01 -04003288 if (DEBUG_WIDGETS) {
3289 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3290 + (SystemClock.uptimeMillis()-start) + "ms");
3291 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003292 }
3293
3294 /**
3295 * Callback saying that there aren't any more items to bind.
3296 *
3297 * Implementation of the method from LauncherModel.Callbacks.
3298 */
3299 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003300 setLoadOnResume();
3301
Joe Onorato9c1289c2009-08-17 11:03:03 -04003302 if (mSavedState != null) {
3303 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003304 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003305 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003306 mSavedState = null;
3307 }
3308
3309 if (mSavedInstanceState != null) {
3310 super.onRestoreInstanceState(mSavedInstanceState);
3311 mSavedInstanceState = null;
3312 }
3313
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003314 // If we received the result of any pending adds while the loader was running (e.g. the
3315 // widget configuration forced an orientation change), process them now.
3316 for (int i = 0; i < sPendingAddList.size(); i++) {
3317 completeAdd(sPendingAddList.get(i));
3318 }
3319 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003320
Winson Chungc51db6a2011-10-05 11:44:49 -07003321 // Update the market app icon as necessary (the other icons will be managed in response to
3322 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003323 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003324
Winson Chungf0c6ae02012-03-21 16:10:31 -07003325 // Animate up any icons as necessary
3326 if (mVisible || mWorkspaceLoading) {
3327 Runnable newAppsRunnable = new Runnable() {
3328 @Override
3329 public void run() {
Winson Chunga2413752012-04-03 14:22:34 -07003330 runNewAppsAnimation(false);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003331 }
3332 };
Winson Chunga2413752012-04-03 14:22:34 -07003333
3334 boolean willSnapPage = mNewShortcutAnimatePage > -1 &&
3335 mNewShortcutAnimatePage != mWorkspace.getCurrentPage();
3336 if (canRunNewAppsAnimation()) {
3337 // If the user has not interacted recently, then either snap to the new page to show
3338 // the new-apps animation or just run them if they are to appear on the current page
3339 if (willSnapPage) {
3340 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable);
3341 } else {
3342 runNewAppsAnimation(false);
3343 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003344 } else {
Winson Chung318eee02012-04-12 10:59:27 -07003345 // If the user has interacted recently, then just add the items in place if they
Winson Chunga2413752012-04-03 14:22:34 -07003346 // are on another page (or just normally if they are added to the current page)
3347 runNewAppsAnimation(willSnapPage);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003348 }
3349 }
3350
3351 mWorkspaceLoading = false;
3352 }
3353
Winson Chunga2413752012-04-03 14:22:34 -07003354 private boolean canRunNewAppsAnimation() {
3355 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3356 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3357 }
3358
Winson Chungf0c6ae02012-03-21 16:10:31 -07003359 /**
3360 * Runs a new animation that scales up icons that were added while Launcher was in the
3361 * background.
Winson Chunga2413752012-04-03 14:22:34 -07003362 *
3363 * @param immediate whether to run the animation or show the results immediately
Winson Chungf0c6ae02012-03-21 16:10:31 -07003364 */
Winson Chunga2413752012-04-03 14:22:34 -07003365 private void runNewAppsAnimation(boolean immediate) {
Winson Chungf0c6ae02012-03-21 16:10:31 -07003366 AnimatorSet anim = new AnimatorSet();
3367 Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chunga2413752012-04-03 14:22:34 -07003368
3369 // Order these new views spatially so that they animate in order
Winson Chungf0c6ae02012-03-21 16:10:31 -07003370 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
3371 @Override
3372 public int compare(View a, View b) {
3373 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
3374 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
3375 int cellCountX = LauncherModel.getCellCountX();
3376 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
3377 }
3378 });
Winson Chunga2413752012-04-03 14:22:34 -07003379
3380 // Animate each of the views in place (or show them immediately if requested)
3381 if (immediate) {
3382 for (View v : mNewShortcutAnimateViews) {
3383 v.setAlpha(1f);
3384 v.setScaleX(1f);
3385 v.setScaleY(1f);
Winson Chungf0c6ae02012-03-21 16:10:31 -07003386 }
Winson Chunga2413752012-04-03 14:22:34 -07003387 } else {
3388 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
3389 View v = mNewShortcutAnimateViews.get(i);
3390 ValueAnimator bounceAnim = ObjectAnimator.ofPropertyValuesHolder(v,
3391 PropertyValuesHolder.ofFloat("alpha", 1f),
3392 PropertyValuesHolder.ofFloat("scaleX", 1f),
3393 PropertyValuesHolder.ofFloat("scaleY", 1f));
3394 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3395 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3396 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3397 bounceAnims.add(bounceAnim);
3398 }
3399 anim.playTogether(bounceAnims);
3400 anim.addListener(new AnimatorListenerAdapter() {
3401 @Override
3402 public void onAnimationEnd(Animator animation) {
3403 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
3404 }
3405 });
3406 anim.start();
3407 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003408
3409 // Clean up
3410 mNewShortcutAnimatePage = -1;
3411 mNewShortcutAnimateViews.clear();
3412 new Thread("clearNewAppsThread") {
3413 public void run() {
3414 mSharedPrefs.edit()
3415 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
3416 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null)
3417 .commit();
3418 }
3419 }.start();
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003420 }
3421
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003422 @Override
3423 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003424 boolean searchVisible = updateGlobalSearchIcon();
3425 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3426 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003427 }
3428
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003429 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003430 * Add the icons for all apps.
3431 *
3432 * Implementation of the method from LauncherModel.Callbacks.
3433 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003434 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3435 // Remove the progress bar entirely; we could also make it GONE
3436 // but better to remove it since we know it's not going to be used
3437 View progressBar = mAppsCustomizeTabHost.
3438 findViewById(R.id.apps_customize_progress_bar);
3439 if (progressBar != null) {
3440 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003441 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003442 // We just post the call to setApps so the user sees the progress bar
3443 // disappear-- otherwise, it just looks like the progress bar froze
3444 // which doesn't look great
3445 mAppsCustomizeTabHost.post(new Runnable() {
3446 public void run() {
3447 if (mAppsCustomizeContent != null) {
3448 mAppsCustomizeContent.setApps(apps);
3449 }
3450 }
3451 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003452 }
3453
3454 /**
3455 * A package was installed.
3456 *
3457 * Implementation of the method from LauncherModel.Callbacks.
3458 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003459 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003460 setLoadOnResume();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003461
Winson Chung785d2eb2011-04-14 16:08:02 -07003462 if (mAppsCustomizeContent != null) {
3463 mAppsCustomizeContent.addApps(apps);
3464 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003465 }
3466
3467 /**
3468 * A package was updated.
3469 *
3470 * Implementation of the method from LauncherModel.Callbacks.
3471 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003472 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003473 setLoadOnResume();
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003474 if (mWorkspace != null) {
3475 mWorkspace.updateShortcuts(apps);
3476 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003477
Winson Chung785d2eb2011-04-14 16:08:02 -07003478 if (mAppsCustomizeContent != null) {
3479 mAppsCustomizeContent.updateApps(apps);
3480 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003481 }
3482
3483 /**
3484 * A package was uninstalled.
3485 *
3486 * Implementation of the method from LauncherModel.Callbacks.
3487 */
Joe Onorato36115782010-06-17 13:28:48 -04003488 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato36115782010-06-17 13:28:48 -04003489 if (permanent) {
3490 mWorkspace.removeItems(apps);
3491 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003492
Winson Chung785d2eb2011-04-14 16:08:02 -07003493 if (mAppsCustomizeContent != null) {
3494 mAppsCustomizeContent.removeApps(apps);
3495 }
Winson Chunga1820962011-10-03 16:31:06 -07003496
3497 // Notify the drag controller
3498 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003499 }
Joe Onoratobe386092009-11-17 17:32:16 -08003500
3501 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003502 * A number of packages were updated.
3503 */
3504 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003505 if (mAppsCustomizeContent != null) {
3506 mAppsCustomizeContent.onPackagesUpdated();
3507 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003508 }
3509
Winson Chung400438b2011-01-16 17:53:48 -08003510 private int mapConfigurationOriActivityInfoOri(int configOri) {
3511 final Display d = getWindowManager().getDefaultDisplay();
3512 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3513 switch (d.getRotation()) {
3514 case Surface.ROTATION_0:
3515 case Surface.ROTATION_180:
3516 // We are currently in the same basic orientation as the natural orientation
3517 naturalOri = configOri;
3518 break;
3519 case Surface.ROTATION_90:
3520 case Surface.ROTATION_270:
3521 // We are currently in the other basic orientation to the natural orientation
3522 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3523 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3524 break;
3525 }
3526
3527 int[] oriMap = {
3528 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3529 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3530 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3531 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3532 };
3533 // Since the map starts at portrait, we need to offset if this device's natural orientation
3534 // is landscape.
3535 int indexOffset = 0;
3536 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3537 indexOffset = 1;
3538 }
3539 return oriMap[(d.getRotation() + indexOffset) % 4];
3540 }
Adam Cohen446e9402011-09-15 18:21:21 -07003541
Winson Chung4b919f82012-05-01 10:44:08 -07003542 public boolean isRotationEnabled() {
Michael Jurka9bc8eba2012-05-21 20:36:44 -07003543 boolean forceEnableRotation = doesFileExist(FORCE_ENABLE_ROTATION_PROPERTY);
Winson Chung4b919f82012-05-01 10:44:08 -07003544 boolean enableRotation = forceEnableRotation ||
3545 getResources().getBoolean(R.bool.allow_rotation);
3546 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08003547 }
Winson Chung4b919f82012-05-01 10:44:08 -07003548 public void lockScreenOrientation() {
3549 if (isRotationEnabled()) {
3550 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3551 .getConfiguration().orientation));
3552 }
3553 }
3554 public void unlockScreenOrientation(boolean immediate) {
3555 if (isRotationEnabled()) {
3556 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07003557 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07003558 } else {
3559 mHandler.postDelayed(new Runnable() {
3560 public void run() {
3561 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3562 }
3563 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07003564 }
Winson Chung4b919f82012-05-01 10:44:08 -07003565 }
Winson Chung400438b2011-01-16 17:53:48 -08003566 }
3567
Winson Chung82f55532011-08-09 14:14:23 -07003568 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003569 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003570 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003571 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003572
Winson Chung7d7541e2011-09-16 20:14:36 -07003573 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003574 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003575 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3576 Cling cling = (Cling) findViewById(clingId);
3577 if (cling != null) {
3578 cling.init(this, positionData);
3579 cling.setVisibility(View.VISIBLE);
3580 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3581 if (animate) {
3582 cling.buildLayer();
3583 cling.setAlpha(0f);
3584 cling.animate()
3585 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003586 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003587 .setDuration(SHOW_CLING_DURATION)
3588 .setStartDelay(delay)
3589 .start();
3590 } else {
3591 cling.setAlpha(1f);
3592 }
3593 }
3594 return cling;
3595 }
3596 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003597 if (cling != null) {
3598 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003599 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003600 anim.addListener(new AnimatorListenerAdapter() {
3601 public void onAnimationEnd(Animator animation) {
3602 cling.setVisibility(View.GONE);
3603 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003604 // We should update the shared preferences on a background thread
3605 new Thread("dismissClingThread") {
3606 public void run() {
3607 SharedPreferences.Editor editor = mSharedPrefs.edit();
3608 editor.putBoolean(flag, true);
3609 editor.commit();
3610 }
3611 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003612 };
3613 });
3614 anim.start();
3615 }
3616 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003617 private void removeCling(int id) {
3618 final View cling = findViewById(id);
3619 if (cling != null) {
3620 final ViewGroup parent = (ViewGroup) cling.getParent();
3621 parent.post(new Runnable() {
3622 @Override
3623 public void run() {
3624 parent.removeView(cling);
3625 }
3626 });
3627 }
3628 }
Michael Jurka974c3862012-05-22 22:00:31 -07003629
3630 private boolean skipCustomClingIfNoAccounts() {
3631 Cling cling = (Cling) findViewById(R.id.workspace_cling);
3632 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
3633 if (customCling) {
3634 AccountManager am = AccountManager.get(this);
3635 Account[] accounts = am.getAccountsByType("com.google");
3636 return accounts.length == 0;
3637 }
3638 return false;
3639 }
3640
Winson Chung7d7541e2011-09-16 20:14:36 -07003641 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003642 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003643 if (isClingsEnabled() &&
Michael Jurka974c3862012-05-22 22:00:31 -07003644 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) &&
3645 !skipCustomClingIfNoAccounts() ) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003646 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003647 } else {
3648 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003649 }
3650 }
3651 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003652 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003653 if (isClingsEnabled() &&
3654 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003655 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003656 } else {
3657 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003658 }
3659 }
3660 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003661 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003662 if (isClingsEnabled() &&
3663 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
3664 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003665 } else {
3666 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08003667 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07003668 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003669 }
3670 public boolean isFolderClingVisible() {
3671 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003672 if (cling != null) {
3673 return cling.getVisibility() == View.VISIBLE;
3674 }
3675 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003676 }
Winson Chung82f55532011-08-09 14:14:23 -07003677 public void dismissWorkspaceCling(View v) {
3678 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003679 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003680 }
3681 public void dismissAllAppsCling(View v) {
3682 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003683 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3684 }
3685 public void dismissFolderCling(View v) {
3686 Cling cling = (Cling) findViewById(R.id.folder_cling);
3687 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003688 }
3689
Winson Chung80baf5a2010-08-09 16:03:15 -07003690 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003691 * Prints out out state for debugging.
3692 */
3693 public void dumpState() {
3694 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003695 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003696 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3697 Log.d(TAG, "mRestoring=" + mRestoring);
3698 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3699 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003700 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003701 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003702
Winson Chung785d2eb2011-04-14 16:08:02 -07003703 if (mAppsCustomizeContent != null) {
3704 mAppsCustomizeContent.dumpState();
3705 }
Joe Onoratobe386092009-11-17 17:32:16 -08003706 Log.d(TAG, "END launcher2 dump state");
3707 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003708
3709 @Override
3710 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3711 super.dump(prefix, fd, writer, args);
3712 writer.println(" ");
3713 writer.println("Debug logs: ");
3714 for (int i = 0; i < sDumpLogs.size(); i++) {
3715 writer.println(" " + sDumpLogs.get(i));
3716 }
3717 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003718}
Michael Jurka2763be32011-02-24 11:19:57 -08003719
Michael Jurkaabded662011-03-04 12:06:57 -08003720interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003721 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003722 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08003723 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08003724 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08003725 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003726}