blob: 8850cf8062f208fed09475c95c55a78d8778583b [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
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
24import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070025import android.animation.ValueAnimator;
Michael Jurka946ad472010-07-09 18:05:18 -070026import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070027import android.app.ActivityManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029import android.app.Dialog;
30import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080031import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070032import android.appwidget.AppWidgetManager;
33import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080035import android.content.BroadcastReceiver;
Winson Chung68846fd2010-10-29 11:00:27 -070036import android.content.ClipData;
37import android.content.ClipDescription;
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;
42import android.content.DialogInterface;
43import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070044import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070045import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070048import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohened66b2b2012-01-23 17:28:51 -080052import android.graphics.Bitmap;
Michael Jurkaaf442092010-06-10 17:01:57 -070053import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070054import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040055import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070056import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020058import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080059import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070060import android.os.Message;
Daniel Sandler843e8602010-06-07 14:59:01 -040061import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080062import android.os.SystemProperties;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070063import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080064import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065import android.text.Selection;
66import android.text.SpannableStringBuilder;
67import android.text.TextUtils;
68import 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;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080090import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070091import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070092import android.widget.TextView;
93import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070094
Adam Cohendf2cc412011-04-27 16:56:57 -070095import com.android.common.Search;
96import com.android.launcher.R;
Adam Cohen558baaf2011-08-15 15:22:57 -070097import com.android.launcher2.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080098
Adam Cohenc0dcf592011-06-01 15:30:43 -070099import java.io.DataInputStream;
100import java.io.DataOutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700101import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.FileNotFoundException;
103import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700104import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700105import java.util.ArrayList;
106import java.util.HashMap;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800108/**
109 * Default launcher application.
110 */
Michael Jurka946ad472010-07-09 18:05:18 -0700111public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700112 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
113 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800114 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700115 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800116
Joe Onorato9c1289c2009-08-17 11:03:03 -0400117 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400118 static final boolean DEBUG_WIDGETS = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700119
Winson Chung70d72102011-08-12 11:24:35 -0700120 private static final int MENU_GROUP_WALLPAPER = 1;
121 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
122 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700123 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
124 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125
126 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700127 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128 private static final int REQUEST_PICK_APPLICATION = 6;
129 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700130 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700131 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132
133 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
134
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800135 static final int SCREEN_COUNT = 5;
136 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137
Joe Onorato7c312c12009-08-13 21:36:53 -0700138 static final int DIALOG_CREATE_SHORTCUT = 1;
139 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140
Romain Guy98d01652009-06-30 16:21:04 -0700141 private static final String PREFERENCES = "launcher.preferences";
Adam Cohen23a4d302011-12-01 17:26:44 -0800142 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher.force_enable_rotation";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143
144 // Type: int
145 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700146 // Type: int
147 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700149 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
150 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
152 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700153 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700155 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156 // Type: boolean
157 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
158 // Type: long
159 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
160
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700161 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
162
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700163 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700164 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700165 private State mState = State.WORKSPACE;
166 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800167 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700168
Joe Onorato9c1289c2009-08-17 11:03:03 -0400169 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700170 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
171 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700172 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700173 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800176 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800178 private final BroadcastReceiver mCloseSystemDialogsReceiver
179 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800180 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
181
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 private LayoutInflater mInflater;
183
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800185 private View mQsbDivider;
186 private View mDockDivider;
187 private DragLayer mDragLayer;
188 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700189
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700190 private AppWidgetManager mAppWidgetManager;
191 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700192
Michael Jurkac9d95c52011-08-29 14:03:34 -0700193 private ItemInfo mPendingAddInfo = new ItemInfo();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700194 private int[] mTmpAddItemCellCoordinates = new int[2];
195
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800196 private FolderInfo mFolderInfo;
197
Winson Chung3d503fb2011-07-13 17:25:49 -0700198 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800199 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700200
Winson Chungc51db6a2011-10-05 11:44:49 -0700201 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700202 private AppsCustomizeTabHost mAppsCustomizeTabHost;
203 private AppsCustomizePagedView mAppsCustomizeContent;
204 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800206 private Bundle mSavedState;
207
208 private SpannableStringBuilder mDefaultKeySsb = null;
209
Joe Onorato9c1289c2009-08-17 11:03:03 -0400210 private boolean mWorkspaceLoading = true;
211
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800212 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800213 private boolean mRestoring;
214 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700215 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800216
217 private Bundle mSavedInstanceState;
218
Joe Onorato9c1289c2009-08-17 11:03:03 -0400219 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800220 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800221 private boolean mUserPresent = true;
222 private boolean mVisible = false;
223 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400224
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700225 private static LocaleConfiguration sLocaleConfiguration = null;
226
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700227 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700228
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700229 private Intent mAppMarketIntent = null;
230
Adam Cohended9f8d2010-11-03 13:25:16 -0700231 // Related to the auto-advancing of widgets
232 private final int ADVANCE_MSG = 1;
233 private final int mAdvanceInterval = 20000;
234 private final int mAdvanceStagger = 250;
235 private long mAutoAdvanceSentTime;
236 private long mAutoAdvanceTimeLeft = -1;
237 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
238 new HashMap<View, AppWidgetProviderInfo>();
239
Winson Chung400438b2011-01-16 17:53:48 -0800240 // Determines how long to wait after a rotation before restoring the screen orientation to
241 // match the sensor state.
242 private final int mRestoreScreenOrientationDelay = 500;
243
Michael Jurka4ef207b2010-11-29 17:05:45 -0800244 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700245 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
246 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
247 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800248
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700249 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohened66b2b2012-01-23 17:28:51 -0800250 PendingAddWidgetInfo mWidgetBeingConfigured = null;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700251
Adam Cohen2801caf2011-05-13 20:57:39 -0700252
Michael Jurkaddd62e92011-02-16 17:49:14 -0800253 private BubbleTextView mWaitingForResume;
254
Michael Jurkac1f5d262011-09-30 19:32:27 -0700255 private Runnable mBuildLayersRunnable = new Runnable() {
256 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700257 if (mWorkspace != null) {
258 mWorkspace.buildPageHardwareLayers();
259 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700260 }
261 };
262
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800263 private static ArrayList<PendingAddArguments> sPendingAddList
264 = new ArrayList<PendingAddArguments>();
265
266 private static class PendingAddArguments {
267 int requestCode;
268 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700269 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800270 int screen;
271 int cellX;
272 int cellY;
273 }
274
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800275 @Override
276 protected void onCreate(Bundle savedInstanceState) {
277 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800278 LauncherApplication app = ((LauncherApplication)getApplication());
279 mModel = app.setLauncher(this);
280 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400281 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800282 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700283
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700284 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700285 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
286 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700287
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800288 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200289 android.os.Debug.startMethodTracing(
290 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800291 }
292
293 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800294 setContentView(R.layout.launcher);
295 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700296 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800297
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800298 registerContentObservers();
299
Joe Onorato7c312c12009-08-13 21:36:53 -0700300 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700301
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800302 mSavedState = savedInstanceState;
303 restoreState(mSavedState);
304
Winson Chunga12a2502010-12-20 14:41:35 -0800305 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700306 if (mAppsCustomizeContent != null) {
307 mAppsCustomizeContent.onPackagesUpdated();
308 }
Winson Chunga12a2502010-12-20 14:41:35 -0800309
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800310 if (PROFILE_STARTUP) {
311 android.os.Debug.stopMethodTracing();
312 }
313
314 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400315 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800316 }
317
Michael Jurkac57b7a82011-08-09 22:02:20 -0700318 if (!mModel.isAllAppsLoaded()) {
319 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
320 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
321 }
322
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800323 // For handling default keys
324 mDefaultKeySsb = new SpannableStringBuilder();
325 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800326
327 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
328 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800329
Winson Chungc51db6a2011-10-05 11:44:49 -0700330 boolean searchVisible = false;
331 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800332 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700333 int coi = getCurrentOrientationIndexForGlobalIcons();
334 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
335 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700336 updateAppMarketIcon();
337 searchVisible = updateGlobalSearchIcon();
338 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700339 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700340 if (sGlobalSearchIcon[coi] != null) {
341 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700342 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700343 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700344 if (sVoiceSearchIcon[coi] != null) {
345 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700346 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700347 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700348 if (sAppMarketIcon[coi] != null) {
349 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800350 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700351 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Adam Cohen446e9402011-09-15 18:21:21 -0700352
Adam Cohen23a4d302011-12-01 17:26:44 -0800353 final String forceEnableRotation =
354 SystemProperties.get(FORCE_ENABLE_ROTATION_PROPERTY, "false");
355
Adam Cohen446e9402011-09-15 18:21:21 -0700356 // On large interfaces, we want the screen to auto-rotate based on the current orientation
Adam Cohen23a4d302011-12-01 17:26:44 -0800357 if (LauncherApplication.isScreenLarge() || "true".equalsIgnoreCase(forceEnableRotation)) {
Adam Cohen446e9402011-09-15 18:21:21 -0700358 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
359 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800360 }
Romain Guycbb89e42009-06-08 15:52:54 -0700361
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800362 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700363 if (sLocaleConfiguration == null) {
364 new AsyncTask<Void, Void, LocaleConfiguration>() {
365 @Override
366 protected LocaleConfiguration doInBackground(Void... unused) {
367 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
368 readConfiguration(Launcher.this, localeConfiguration);
369 return localeConfiguration;
370 }
371
372 @Override
373 protected void onPostExecute(LocaleConfiguration result) {
374 sLocaleConfiguration = result;
375 checkForLocaleChange(); // recursive, but now with a locale configuration
376 }
377 }.execute();
378 return;
379 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700380
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800381 final Configuration configuration = getResources().getConfiguration();
382
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700383 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800384 final String locale = configuration.locale.toString();
385
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700386 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800387 final int mcc = configuration.mcc;
388
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700389 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800390 final int mnc = configuration.mnc;
391
Romain Guy84f296c2009-11-04 15:00:44 -0800392 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800393
Romain Guy84f296c2009-11-04 15:00:44 -0800394 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700395 sLocaleConfiguration.locale = locale;
396 sLocaleConfiguration.mcc = mcc;
397 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700398
Joe Onorato0589f0f2010-02-08 13:44:00 -0800399 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700400
401 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
402 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700403 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700404 public void run() {
405 writeConfiguration(Launcher.this, localeConfiguration);
406 }
407 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700408 }
409 }
410
411 private static class LocaleConfiguration {
412 public String locale;
413 public int mcc = -1;
414 public int mnc = -1;
415 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700416
Romain Guy98d01652009-06-30 16:21:04 -0700417 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
418 DataInputStream in = null;
419 try {
420 in = new DataInputStream(context.openFileInput(PREFERENCES));
421 configuration.locale = in.readUTF();
422 configuration.mcc = in.readInt();
423 configuration.mnc = in.readInt();
424 } catch (FileNotFoundException e) {
425 // Ignore
426 } catch (IOException e) {
427 // Ignore
428 } finally {
429 if (in != null) {
430 try {
431 in.close();
432 } catch (IOException e) {
433 // Ignore
434 }
435 }
436 }
437 }
438
439 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
440 DataOutputStream out = null;
441 try {
442 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
443 out.writeUTF(configuration.locale);
444 out.writeInt(configuration.mcc);
445 out.writeInt(configuration.mnc);
446 out.flush();
447 } catch (FileNotFoundException e) {
448 // Ignore
449 } catch (IOException e) {
450 //noinspection ResultOfMethodCallIgnored
451 context.getFileStreamPath(PREFERENCES).delete();
452 } finally {
453 if (out != null) {
454 try {
455 out.close();
456 } catch (IOException e) {
457 // Ignore
458 }
459 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 }
461 }
462
Adam Cohen716b51e2011-06-30 12:09:54 -0700463 public DragLayer getDragLayer() {
464 return mDragLayer;
465 }
466
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800467 static int getScreen() {
468 synchronized (sLock) {
469 return sScreen;
470 }
471 }
472
473 static void setScreen(int screen) {
474 synchronized (sLock) {
475 sScreen = screen;
476 }
477 }
478
Winson Chung557d6ed2011-07-08 15:34:52 -0700479 /**
480 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
481 * a configuration step, this allows the proper animations to run after other transitions.
482 */
483 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700484 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800485 switch (args.requestCode) {
486 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700487 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
488 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800489 break;
490 case REQUEST_PICK_SHORTCUT:
491 processShortcut(args.intent);
492 break;
493 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700494 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
495 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700496 result = true;
497 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800498 case REQUEST_PICK_APPWIDGET:
499 addAppWidgetFromPick(args.intent);
500 break;
501 case REQUEST_CREATE_APPWIDGET:
502 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800503 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700504 result = true;
505 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800506 case REQUEST_PICK_WALLPAPER:
507 // We just wanted the activity result here so we can clear mWaitingForResult
508 break;
509 }
Winson Chungb8472bb2011-08-05 13:49:21 -0700510 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800511 }
512
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800513 @Override
Adam Cohened66b2b2012-01-23 17:28:51 -0800514 protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
Winson Chung557d6ed2011-07-08 15:34:52 -0700515 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800516 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
517 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700518 mWaitingForResult = false;
519
Adam Cohened66b2b2012-01-23 17:28:51 -0800520 // We have special handling for widgets
521 if (isWidgetDrop) {
522 int appWidgetId = data != null ?
523 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
524 completeTwoStageWidgetDrop(resultCode, appWidgetId);
525 return;
526 }
527
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800528 // The pattern used here is that a user PICKs a specific application,
529 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700530
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800531 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
532 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700533 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800534 final PendingAddArguments args = new PendingAddArguments();
535 args.requestCode = requestCode;
536 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700537 args.container = mPendingAddInfo.container;
538 args.screen = mPendingAddInfo.screen;
539 args.cellX = mPendingAddInfo.cellX;
540 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800541 if (isWorkspaceLocked()) {
542 sPendingAddList.add(args);
543 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700544 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800545 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800546 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800547 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700548 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800549 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
550 null);
551 }
552
553 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
554 CellLayout cellLayout = (CellLayout) mWorkspace.getChildAt(mWidgetBeingConfigured.screen);
555 Runnable onCompleteRunnable = null;
556 int animationType = 0;
557
558 if (resultCode == RESULT_OK) {
559 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
560 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
561 mWidgetBeingConfigured.info);
562 mWidgetBeingConfigured.boundWidget = layout;
563 onCompleteRunnable = new Runnable() {
564 @Override
565 public void run() {
566 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
567 mPendingAddInfo.screen, layout, null);
568 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
569 null);
570 }
571 };
572 } else if (resultCode == RESULT_CANCELED) {
573 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
574 onCompleteRunnable = new Runnable() {
575 @Override
576 public void run() {
577 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
578 null);
579 }
580 };
581 }
582 mWorkspace.animateExternalDrop(mWidgetBeingConfigured, cellLayout,
583 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
584 animationType);
Adam Cohen1b36dc32012-02-13 19:27:37 -0800585 mWidgetBeingConfigured = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800586 }
587
588 @Override
589 protected void onResume() {
590 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800591 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700592 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400593 mWorkspaceLoading = true;
594 mModel.startLoader(this, true);
595 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700596 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800597 }
Winson Chunge4e50662012-01-23 14:45:13 -0800598
599 // Reset the pressed state of icons that were locked in the press state while activities
600 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800601 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800602 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800603 mWaitingForResume.setStayPressed(false);
604 }
Winson Chunge4e50662012-01-23 14:45:13 -0800605 if (mAppsCustomizeContent != null) {
606 // Resets the previous all apps icon press state
607 mAppsCustomizeContent.resetDrawableState();
608 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700609 // When we resume Launcher, a different Activity might be responsible for the app
610 // market intent, so refresh the icon
611 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800612 }
613
614 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700615 protected void onPause() {
616 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700617 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800618 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700619 }
Romain Guycbb89e42009-06-08 15:52:54 -0700620
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700621 @Override
622 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400623 // Flag the loader to stop early before switching
624 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700625 if (mAppsCustomizeContent != null) {
626 mAppsCustomizeContent.surrender();
627 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800628 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700629 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700630
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800631 // We can't hide the IME if it was forced open. So don't bother
632 /*
633 @Override
634 public void onWindowFocusChanged(boolean hasFocus) {
635 super.onWindowFocusChanged(hasFocus);
636
637 if (hasFocus) {
638 final InputMethodManager inputManager = (InputMethodManager)
639 getSystemService(Context.INPUT_METHOD_SERVICE);
640 WindowManager.LayoutParams lp = getWindow().getAttributes();
641 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
642 android.os.Handler()) {
643 protected void onReceiveResult(int resultCode, Bundle resultData) {
644 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
645 }
646 });
647 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
648 }
649 }
650 */
651
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800652 private boolean acceptFilter() {
653 final InputMethodManager inputManager = (InputMethodManager)
654 getSystemService(Context.INPUT_METHOD_SERVICE);
655 return !inputManager.isFullscreenMode();
656 }
657
658 @Override
659 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700660 final int uniChar = event.getUnicodeChar();
661 final boolean handled = super.onKeyDown(keyCode, event);
662 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
663 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800664 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
665 keyCode, event);
666 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700667 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700668 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700669 // showSearchDialog()
670 // If there are multiple keystrokes before the search dialog takes focus,
671 // onSearchRequested() will be called for every keystroke,
672 // but it is idempotent, so it's fine.
673 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800674 }
675 }
676
Joe Onorato8a9625e2010-01-28 15:55:35 -0800677 // Eat the long press event so the keyboard doesn't come up.
678 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
679 return true;
680 }
681
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800682 return handled;
683 }
684
Karl Rosaen138a0412009-04-23 19:00:21 -0700685 private String getTypedText() {
686 return mDefaultKeySsb.toString();
687 }
688
689 private void clearTypedText() {
690 mDefaultKeySsb.clear();
691 mDefaultKeySsb.clearSpans();
692 Selection.setSelection(mDefaultKeySsb, 0);
693 }
694
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800695 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700696 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
697 * State
698 */
699 private static State intToState(int stateOrdinal) {
700 State state = State.WORKSPACE;
701 final State[] stateValues = State.values();
702 for (int i = 0; i < stateValues.length; i++) {
703 if (stateValues[i].ordinal() == stateOrdinal) {
704 state = stateValues[i];
705 break;
706 }
707 }
708 return state;
709 }
710
711 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800712 * Restores the previous state, if it exists.
713 *
714 * @param savedState The previous state.
715 */
716 private void restoreState(Bundle savedState) {
717 if (savedState == null) {
718 return;
719 }
720
Michael Jurka883f55b2010-10-21 15:47:14 -0700721 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700722 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800723 showAllApps(false);
724 }
725
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800726 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
727 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700728 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800729 }
730
Winson Chung3d503fb2011-07-13 17:25:49 -0700731 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
732 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700733
Winson Chung3d503fb2011-07-13 17:25:49 -0700734 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
735 mPendingAddInfo.container = pendingAddContainer;
736 mPendingAddInfo.screen = pendingAddScreen;
737 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
738 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800739 mRestoring = true;
740 }
741
742 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
743 if (renameFolder) {
744 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700745 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800746 mRestoring = true;
747 }
Winson Chunga12a2502010-12-20 14:41:35 -0800748
Winson Chung785d2eb2011-04-14 16:08:02 -0700749
750 // Restore the AppsCustomize tab
751 if (mAppsCustomizeTabHost != null) {
752 String curTab = savedState.getString("apps_customize_currentTab");
753 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700754 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700755 mAppsCustomizeContent.setContentType(
756 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
757 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700758 mAppsCustomizeContent.loadAssociatedPages(
759 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700760 }
761
Winson Chung5afbf7b2011-07-25 11:53:08 -0700762 int currentIndex = savedState.getInt("apps_customize_currentIndex");
763 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700764 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800765 }
766
767 /**
768 * Finds all the views we need and configure them properly.
769 */
770 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700771 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400772
Winson Chung4c98d922011-05-31 16:50:48 -0700773 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
774 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800775 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
776 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800777
Winson Chung4c98d922011-05-31 16:50:48 -0700778 // Setup the drag layer
779 mDragLayer.setup(this, dragController);
780
Winson Chung3d503fb2011-07-13 17:25:49 -0700781 // Setup the hotseat
782 mHotseat = (Hotseat) findViewById(R.id.hotseat);
783 if (mHotseat != null) {
784 mHotseat.setup(this);
785 }
786
Winson Chung4c98d922011-05-31 16:50:48 -0700787 // Setup the workspace
788 mWorkspace.setHapticFeedbackEnabled(false);
789 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700790 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700791 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700792
Winson Chungf0ea4d32011-06-06 14:27:16 -0700793 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700794 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700795
Winson Chungf0ea4d32011-06-06 14:27:16 -0700796 // Setup AppsCustomize
797 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
798 findViewById(R.id.apps_customize_pane);
799 mAppsCustomizeContent = (AppsCustomizePagedView)
800 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
801 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400802
Michael Jurka5130e402011-10-13 04:55:35 -0700803 // Get the all apps button
804 mAllAppsButton = findViewById(R.id.all_apps_button);
805 if (mAllAppsButton != null) {
806 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
807 @Override
808 public boolean onTouch(View v, MotionEvent event) {
809 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
810 onTouchDownAllAppsButton(v);
811 }
812 return false;
813 }
814 });
815 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700816 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700817 dragController.setDragScoller(mWorkspace);
818 dragController.setScrollView(mDragLayer);
819 dragController.setMoveTarget(mWorkspace);
820 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700821 if (mSearchDropTargetBar != null) {
822 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800823 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800824 }
825
826 /**
827 * Creates a view representing a shortcut.
828 *
829 * @param info The data structure describing the shortcut.
830 *
831 * @return A View inflated from R.layout.application.
832 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800833 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800834 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700835 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800836 }
837
838 /**
839 * Creates a view representing a shortcut inflated from the specified resource.
840 *
841 * @param layoutResId The id of the XML layout used to create the shortcut.
842 * @param parent The group the shortcut belongs to.
843 * @param info The data structure describing the shortcut.
844 *
845 * @return A View inflated from layoutResId.
846 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800847 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800848 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
849 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800850 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800851 return favorite;
852 }
853
854 /**
855 * Add an application shortcut to the workspace.
856 *
857 * @param data The intent describing the application.
858 * @param cellInfo The position on screen where to create the shortcut.
859 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700860 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700861 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700862 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700863
Adam Cohenfbba09b2011-07-18 21:43:05 -0700864 // First we check if we already know the exact location where we want to add this item.
865 if (cellX >= 0 && cellY >= 0) {
866 cellXY[0] = cellX;
867 cellXY[1] = cellY;
868 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700869 showOutOfSpaceMessage();
870 return;
871 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800872
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800873 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800874
Romain Guy73b979d2009-06-09 12:57:21 -0700875 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800876 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800877 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800878 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700879 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700880 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800881 } else {
882 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800883 }
884 }
Romain Guycbb89e42009-06-08 15:52:54 -0700885
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800886 /**
887 * Add a shortcut to the workspace.
888 *
889 * @param data The intent describing the shortcut.
890 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800891 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700892 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
893 int cellY) {
894 int[] cellXY = mTmpAddItemCellCoordinates;
895 int[] touchXY = mPendingAddInfo.dropPos;
896 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -0700897
Michael Jurkad3ef3062010-11-23 16:23:58 -0800898 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700899
Adam Cohen558baaf2011-08-15 15:22:57 -0700900 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -0800901 if (info == null) {
902 return;
903 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700904 final View view = createShortcut(info);
905
Adam Cohenfbba09b2011-07-18 21:43:05 -0700906 // First we check if we already know the exact location where we want to add this item.
907 if (cellX >= 0 && cellY >= 0) {
908 cellXY[0] = cellX;
909 cellXY[1] = cellY;
910 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -0700911
912 // If appropriate, either create a folder or add to an existing folder
913 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY,
914 true, null,null)) {
915 return;
916 }
917 DragObject dragObject = new DragObject();
918 dragObject.dragInfo = info;
919 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, dragObject, true)) {
920 return;
921 }
Adam Cohenfbba09b2011-07-18 21:43:05 -0700922 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800923 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700924 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800925 foundCellSpan = (result != null);
926 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700927 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800928 }
929
930 if (!foundCellSpan) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700931 showOutOfSpaceMessage();
932 return;
933 }
934
Adam Cohen558baaf2011-08-15 15:22:57 -0700935 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800936
937 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -0700938 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
939 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800940 }
941 }
942
Adam Cohenf814aa02011-09-01 13:48:05 -0700943 int[] getSpanForWidget(ComponentName component, int minWidth, int minHeight, int[] spanXY) {
944 if (spanXY == null) {
945 spanXY = new int[2];
946 }
947
Adam Cohen0cf2a7c2011-11-08 15:07:01 -0800948 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(this, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -0700949 // We want to account for the extra amount of padding that we are adding to the widget
950 // to ensure that it gets the full amount of space that it has requested
951 int requiredWidth = minWidth + padding.left + padding.right;
952 int requiredHeight = minHeight + padding.top + padding.bottom;
953 return CellLayout.rectToCell(getResources(), requiredWidth, requiredHeight, null);
954 }
955
956 int[] getSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
957 return getSpanForWidget(info.provider, info.minWidth, info.minHeight, spanXY);
958 }
959
Adam Cohencbf47e32011-09-16 17:32:37 -0700960 int[] getMinResizeSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
961 return getSpanForWidget(info.provider, info.minResizeWidth, info.minResizeHeight, spanXY);
962 }
963
Adam Cohenf814aa02011-09-01 13:48:05 -0700964 int[] getSpanForWidget(PendingAddWidgetInfo info, int[] spanXY) {
965 return getSpanForWidget(info.componentName, info.minWidth, info.minHeight, spanXY);
966 }
967
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800968 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700969 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800970 *
Romain Guy5bbc91b2010-08-18 11:38:46 -0700971 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700972 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800973 */
Adam Cohened66b2b2012-01-23 17:28:51 -0800974 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
975 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
976 if (appWidgetInfo == null) {
977 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
978 }
Romain Guycbb89e42009-06-08 15:52:54 -0700979
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700980 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -0700981 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -0700982
Adam Cohenf814aa02011-09-01 13:48:05 -0700983 int[] spanXY = getSpanForWidget(appWidgetInfo, null);
Romain Guycbb89e42009-06-08 15:52:54 -0700984
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800985 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -0700986 // We have saved the position to which the widget was dragged-- this really only matters
987 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -0700988 int[] cellXY = mTmpAddItemCellCoordinates;
989 int[] touchXY = mPendingAddInfo.dropPos;
Michael Jurka0280c3b2010-09-17 15:00:07 -0700990 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -0700991 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
992 cellXY[0] = mPendingAddInfo.cellX;
993 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700994 foundCellSpan = true;
995 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700996 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700997 int[] result = layout.findNearestVacantArea(
Michael Jurka0280c3b2010-09-17 15:00:07 -0700998 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800999 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001000 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001001 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001002 }
1003
Michael Jurka0280c3b2010-09-17 15:00:07 -07001004 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001005 if (appWidgetId != -1) {
1006 // Deleting an app widget ID is a void call but writes to disk before returning
1007 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001008 new Thread("deleteAppWidgetId") {
1009 public void run() {
1010 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1011 }
1012 }.start();
1013 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001014 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001015 return;
1016 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001017
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001018 // Build Launcher-specific widget info and save to database
Michael Jurkac9d95c52011-08-29 14:03:34 -07001019 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001020 launcherInfo.spanX = spanXY[0];
1021 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001022
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001023 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001024 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001025
1026 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001027 if (hostView == null) {
1028 // Perform actual inflation because we're live
1029 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1030 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1031 } else {
1032 // The AppWidgetHostView has already been inflated and instantiated
1033 launcherInfo.hostView = hostView;
1034 }
Romain Guycbb89e42009-06-08 15:52:54 -07001035
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001036 launcherInfo.hostView.setTag(launcherInfo);
Winson Chung3d503fb2011-07-13 17:25:49 -07001037 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001038 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001039
1040 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001041 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001042 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001043 }
Romain Guycbb89e42009-06-08 15:52:54 -07001044
Adam Cohended9f8d2010-11-03 13:25:16 -07001045 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1046 @Override
1047 public void onReceive(Context context, Intent intent) {
1048 final String action = intent.getAction();
1049 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1050 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001051 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001052 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001053
Winson Chungc100e8e2011-08-09 16:02:43 -07001054 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001055 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001056 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1057 mAppsCustomizeTabHost.reset();
1058 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001059 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001060 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1061 mUserPresent = true;
1062 updateRunning();
1063 }
1064 }
1065 };
1066
1067 @Override
1068 public void onAttachedToWindow() {
1069 super.onAttachedToWindow();
1070
1071 // Listen for broadcasts related to user-presence
1072 final IntentFilter filter = new IntentFilter();
1073 filter.addAction(Intent.ACTION_SCREEN_OFF);
1074 filter.addAction(Intent.ACTION_USER_PRESENT);
1075 registerReceiver(mReceiver, filter);
1076
Adam Cohend113e0c2010-11-11 10:48:05 -08001077 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001078 mVisible = true;
1079 }
1080
1081 @Override
1082 public void onDetachedFromWindow() {
1083 super.onDetachedFromWindow();
1084 mVisible = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001085 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001086
Adam Cohend113e0c2010-11-11 10:48:05 -08001087 if (mAttached) {
1088 unregisterReceiver(mReceiver);
1089 mAttached = false;
1090 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001091 updateRunning();
1092 }
1093
1094 public void onWindowVisibilityChanged(int visibility) {
1095 mVisible = visibility == View.VISIBLE;
1096 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001097 // The following code used to be in onResume, but it turns out onResume is called when
1098 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1099 // is a more appropriate event to handle
1100 if (mVisible) {
1101 mAppsCustomizeTabHost.onWindowVisible();
1102 if (!mWorkspaceLoading) {
1103 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001104 // We want to let Launcher draw itself at least once before we force it to build
1105 // layers on all the workspace pages, so that transitioning to Launcher from other
1106 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
1107 // a true draw so we wait until the second preDraw call to be safe
1108 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
1109 boolean mFirstTime = true;
1110 public boolean onPreDraw() {
1111 if (mFirstTime) {
1112 mFirstTime = false;
1113 } else {
1114 //workspace.post(mBuildLayersRunnable);
1115 observer.removeOnPreDrawListener(this);
1116 }
1117 return true;
1118 }
1119 });
1120 }
1121 clearTypedText();
1122 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001123 }
1124
1125 private void sendAdvanceMessage(long delay) {
1126 mHandler.removeMessages(ADVANCE_MSG);
1127 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1128 mHandler.sendMessageDelayed(msg, delay);
1129 mAutoAdvanceSentTime = System.currentTimeMillis();
1130 }
1131
1132 private void updateRunning() {
1133 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1134 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1135 mAutoAdvanceRunning = autoAdvanceRunning;
1136 if (autoAdvanceRunning) {
1137 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1138 sendAdvanceMessage(delay);
1139 } else {
1140 if (!mWidgetsToAdvance.isEmpty()) {
1141 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1142 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1143 }
1144 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001145 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001146 }
1147 }
1148 }
1149
1150 private final Handler mHandler = new Handler() {
1151 @Override
1152 public void handleMessage(Message msg) {
1153 if (msg.what == ADVANCE_MSG) {
1154 int i = 0;
1155 for (View key: mWidgetsToAdvance.keySet()) {
1156 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1157 final int delay = mAdvanceStagger * i;
1158 if (v instanceof Advanceable) {
1159 postDelayed(new Runnable() {
1160 public void run() {
1161 ((Advanceable) v).advance();
1162 }
1163 }, delay);
1164 }
1165 i++;
1166 }
1167 sendAdvanceMessage(mAdvanceInterval);
1168 }
1169 }
1170 };
1171
1172 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001173 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001174 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1175 if (v instanceof Advanceable) {
1176 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001177 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001178 updateRunning();
1179 }
1180 }
1181
1182 void removeWidgetToAutoAdvance(View hostView) {
1183 if (mWidgetsToAdvance.containsKey(hostView)) {
1184 mWidgetsToAdvance.remove(hostView);
1185 updateRunning();
1186 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001187 }
1188
Joe Onorato9c1289c2009-08-17 11:03:03 -04001189 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001190 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001191 launcherInfo.hostView = null;
1192 }
1193
Adam Cohended9f8d2010-11-03 13:25:16 -07001194 void showOutOfSpaceMessage() {
1195 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1196 }
1197
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001198 public LauncherAppWidgetHost getAppWidgetHost() {
1199 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001200 }
Romain Guycbb89e42009-06-08 15:52:54 -07001201
Winson Chunga9abd0e2010-10-27 17:18:37 -07001202 public LauncherModel getModel() {
1203 return mModel;
1204 }
1205
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001206 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001207 getWindow().closeAllPanels();
1208
Winson Chung87acb482011-08-23 17:28:05 -07001209 /**
1210 * We should remove this code when we remove all the dialog code.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001211 try {
1212 dismissDialog(DIALOG_CREATE_SHORTCUT);
1213 // Unlock the workspace if the dialog was showing
1214 } catch (Exception e) {
1215 // An exception is thrown if the dialog is not visible, which is fine
1216 }
1217
1218 try {
1219 dismissDialog(DIALOG_RENAME_FOLDER);
1220 // Unlock the workspace if the dialog was showing
1221 } catch (Exception e) {
1222 // An exception is thrown if the dialog is not visible, which is fine
1223 }
Winson Chung87acb482011-08-23 17:28:05 -07001224 */
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001225
1226 // Whatever we were doing is hereby canceled.
1227 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001228 }
1229
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001230 @Override
1231 protected void onNewIntent(Intent intent) {
1232 super.onNewIntent(intent);
1233
1234 // Close the menu
1235 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001236 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001237 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001238
Joe Onorato14f122b2009-11-19 14:06:36 -08001239 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1240 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001241
Adam Cohenac56cff2011-09-28 20:45:37 -07001242 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001243 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001244 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001245 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1246 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001247 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001248 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001249
1250 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001251 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001252 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001253
Joe Onorato3a8820b2009-11-10 15:06:42 -08001254 final View v = getWindow().peekDecorView();
1255 if (v != null && v.getWindowToken() != null) {
1256 InputMethodManager imm = (InputMethodManager)getSystemService(
1257 INPUT_METHOD_SERVICE);
1258 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001260
Michael Jurka35aa14d2011-07-07 17:01:08 -07001261 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001262 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001263 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001264 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265 }
1266 }
1267
1268 @Override
1269 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1270 // Do not call super here
1271 mSavedInstanceState = savedInstanceState;
1272 }
1273
1274 @Override
1275 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001276 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001277 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001278
Michael Jurka883f55b2010-10-21 15:47:14 -07001279 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001280 // We close any open folder since it will not be re-opened, and we need to make sure
1281 // this state is reflected.
1282 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001283
Winson Chung3d503fb2011-07-13 17:25:49 -07001284 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1285 mWaitingForResult) {
1286 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1287 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1288 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1289 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001290 }
1291
1292 if (mFolderInfo != null && mWaitingForResult) {
1293 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1294 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1295 }
Michael Jurka946ad472010-07-09 18:05:18 -07001296
Winson Chung785d2eb2011-04-14 16:08:02 -07001297 // Save the current AppsCustomize tab
1298 if (mAppsCustomizeTabHost != null) {
1299 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1300 if (currentTabTag != null) {
1301 outState.putString("apps_customize_currentTab", currentTabTag);
1302 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001303 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1304 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001305 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001306 }
1307
1308 @Override
1309 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001310 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001311
Winson Chunge7a03942011-08-05 15:05:12 -07001312 // Remove all pending runnables
1313 mHandler.removeMessages(ADVANCE_MSG);
1314 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001315 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001316
Winson Chungcd2b0142011-06-08 16:02:26 -07001317 // Stop callbacks from LauncherModel
1318 LauncherApplication app = ((LauncherApplication) getApplication());
1319 mModel.stopLoader();
1320 app.setLauncher(null);
1321
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001322 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001323 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001324 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001325 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001326 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001327 mAppWidgetHost = null;
1328
1329 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001330
1331 TextKeyListener.getInstance().release();
1332
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001333
Winson Chung3d503fb2011-07-13 17:25:49 -07001334 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001335
1336 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001337 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001338
1339 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1340 mWorkspace.removeAllViews();
1341 mWorkspace = null;
1342 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001343
1344 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001345 }
1346
Adam Cohena9cf38f2011-05-02 15:36:58 -07001347 public DragController getDragController() {
1348 return mDragController;
1349 }
1350
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001351 @Override
1352 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001353 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001354 super.startActivityForResult(intent, requestCode);
1355 }
1356
Winson Chung70d72102011-08-12 11:24:35 -07001357 /**
1358 * Indicates that we want global search for this activity by setting the globalSearch
1359 * argument for {@link #startSearch} to true.
1360 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001361 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001362 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001363 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001364
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001365 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001366
Karl Rosaen138a0412009-04-23 19:00:21 -07001367 if (initialQuery == null) {
1368 // Use any text typed in the launcher as the initial query
1369 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001370 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001371 if (appSearchData == null) {
1372 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001373 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001374 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001375 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001376
Karl Rosaen138a0412009-04-23 19:00:21 -07001377 final SearchManager searchManager =
1378 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001379 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001380 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001381 }
1382
Winson Chung70d72102011-08-12 11:24:35 -07001383 @Override
1384 public boolean onCreateOptionsMenu(Menu menu) {
1385 if (isWorkspaceLocked()) {
1386 return false;
1387 }
1388
1389 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001390
1391 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1392 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1393 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001394 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1395 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1396 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001397 String helpUrl = getString(R.string.help_url);
1398 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001399 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1400 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1401
Winson Chung70d72102011-08-12 11:24:35 -07001402 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1403 .setIcon(android.R.drawable.ic_menu_gallery)
1404 .setAlphabeticShortcut('W');
1405 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1406 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001407 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001408 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001409 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1410 .setIcon(android.R.drawable.ic_menu_preferences)
1411 .setIntent(settings)
1412 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001413 if (!helpUrl.isEmpty()) {
1414 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1415 .setIcon(android.R.drawable.ic_menu_help)
1416 .setIntent(help)
1417 .setAlphabeticShortcut('H');
1418 }
Winson Chung70d72102011-08-12 11:24:35 -07001419 return true;
1420 }
1421
1422 @Override
1423 public boolean onPrepareOptionsMenu(Menu menu) {
1424 super.onPrepareOptionsMenu(menu);
1425
1426 if (mAppsCustomizeTabHost.isTransitioning()) {
1427 return false;
1428 }
1429 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1430 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1431
1432 return true;
1433 }
1434
1435 @Override
1436 public boolean onOptionsItemSelected(MenuItem item) {
1437 switch (item.getItemId()) {
1438 case MENU_WALLPAPER_SETTINGS:
1439 startWallpaper();
1440 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001441 }
1442
1443 return super.onOptionsItemSelected(item);
1444 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001445
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001446 @Override
1447 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001448 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001449 // Use a custom animation for launching search
1450 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001451 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001452 }
1453
Joe Onorato9c1289c2009-08-17 11:03:03 -04001454 public boolean isWorkspaceLocked() {
1455 return mWorkspaceLoading || mWaitingForResult;
1456 }
1457
Michael Jurka0280c3b2010-09-17 15:00:07 -07001458 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001459 mPendingAddInfo.container = ItemInfo.NO_ID;
1460 mPendingAddInfo.screen = -1;
1461 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1462 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
1463 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001464 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001465
Michael Jurkaaf442092010-06-10 17:01:57 -07001466 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001467 // TODO: catch bad widget exception when sent
1468 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001469 // TODO: Is this log message meaningful?
1470 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001471 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001472 }
1473
Adam Cohened66b2b2012-01-23 17:28:51 -08001474 void addAppWidgetImpl(final int appWidgetId, final PendingAddWidgetInfo info) {
1475 final AppWidgetProviderInfo appWidget = info.info;
1476 Runnable configurationActivity = null;
Bjorn Bringert7984c942009-12-09 15:38:25 +00001477 if (appWidget.configure != null) {
1478 // Launch over to configure widget, if needed
1479 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1480 intent.setComponent(appWidget.configure);
1481 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001482 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001483 if (info.mimeType != null && !info.mimeType.isEmpty()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001484 intent.putExtra(InstallWidgetReceiver.
1485 EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE, info.mimeType);
Winson Chung68846fd2010-10-29 11:00:27 -07001486
1487 final String mimeType = info.mimeType;
1488 final ClipData clipData = (ClipData) info.configurationData;
1489 final ClipDescription clipDesc = clipData.getDescription();
1490 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1491 if (clipDesc.getMimeType(i).equals(mimeType)) {
Dianne Hackborn0d5aad72011-01-17 15:28:58 -08001492 final ClipData.Item item = clipData.getItemAt(i);
Winson Chung68846fd2010-10-29 11:00:27 -07001493 final CharSequence stringData = item.getText();
1494 final Uri uriData = item.getUri();
1495 final Intent intentData = item.getIntent();
Adam Cohened66b2b2012-01-23 17:28:51 -08001496 final String key = InstallWidgetReceiver.
1497 EXTRA_APPWIDGET_CONFIGURATION_DATA;
Winson Chung68846fd2010-10-29 11:00:27 -07001498 if (uriData != null) {
1499 intent.putExtra(key, uriData);
1500 } else if (intentData != null) {
1501 intent.putExtra(key, intentData);
1502 } else if (stringData != null) {
1503 intent.putExtra(key, stringData);
1504 }
1505 break;
1506 }
1507 }
1508 }
Winson Chung55cef262010-10-28 14:14:18 -07001509 }
Romain Guy8e633c52010-03-04 12:51:36 -08001510 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
Adam Cohened66b2b2012-01-23 17:28:51 -08001511 mWidgetBeingConfigured = info;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001512 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001513 // Otherwise just add it
Adam Cohened66b2b2012-01-23 17:28:51 -08001514 completeAddAppWidget(appWidgetId, info.container, info.screen, info.boundWidget, appWidget);
Winson Chung557d6ed2011-07-08 15:34:52 -07001515 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001516 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001517 }
1518 }
Romain Guycbb89e42009-06-08 15:52:54 -07001519
Adam Cohenfbba09b2011-07-18 21:43:05 -07001520 /**
1521 * Process a shortcut drop.
1522 *
1523 * @param componentName The name of the component
1524 * @param screen The screen where it should be added
1525 * @param cell The cell it should be added to, optional
1526 * @param position The location on the screen where it was dropped, optional
1527 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001528 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1529 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001530 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001531 mPendingAddInfo.container = container;
1532 mPendingAddInfo.screen = screen;
1533 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001534
1535 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001536 mPendingAddInfo.cellX = cell[0];
1537 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001538 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001539
1540 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1541 createShortcutIntent.setComponent(componentName);
1542 processShortcut(createShortcutIntent);
1543 }
1544
Adam Cohenfbba09b2011-07-18 21:43:05 -07001545 /**
1546 * Process a widget drop.
1547 *
1548 * @param info The PendingAppWidgetInfo of the widget being added.
1549 * @param screen The screen where it should be added
1550 * @param cell The cell it should be added to, optional
1551 * @param position The location on the screen where it was dropped, optional
1552 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001553 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
1554 int[] cell, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001555 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001556 mPendingAddInfo.container = info.container = container;
1557 mPendingAddInfo.screen = info.screen = screen;
1558 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001559 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001560 mPendingAddInfo.cellX = cell[0];
1561 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001562 }
1563
Adam Cohened66b2b2012-01-23 17:28:51 -08001564 AppWidgetHostView hostView = info.boundWidget;
1565 int appWidgetId;
1566 if (hostView != null) {
1567 appWidgetId = hostView.getAppWidgetId();
1568 } else {
1569 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1570 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1571 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001572 addAppWidgetImpl(appWidgetId, info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001573
Adam Cohenfbba09b2011-07-18 21:43:05 -07001574 }
1575
Joe Onoratodeb98af2010-02-19 14:59:39 -08001576 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001577 // Handle case where user selected "Applications"
1578 String applicationName = getResources().getString(R.string.group_applications);
1579 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001580
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001581 if (applicationName != null && applicationName.equals(shortcutName)) {
1582 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1583 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001584
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001585 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1586 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001587 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001588 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001589 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001590 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001591 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001592 }
1593
Winson Chung24ab2f12010-09-16 14:10:47 -07001594 void processWallpaper(Intent intent) {
1595 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1596 }
1597
Winson Chung3d503fb2011-07-13 17:25:49 -07001598 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1599 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001600 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001601 folderInfo.title = getText(R.string.folder_name);
1602
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001603 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001604 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1605 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001606 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001607
1608 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001609 FolderIcon newFolder =
1610 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1611 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1612 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001613 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001614 }
Romain Guycbb89e42009-06-08 15:52:54 -07001615
Joe Onorato9c1289c2009-08-17 11:03:03 -04001616 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001617 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001618 }
1619
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001620 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001621 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001622 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001623 Intent chooser = Intent.createChooser(pickWallpaper,
1624 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001625 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1626 // Removed in Eclair MR1
1627// WallpaperManager wm = (WallpaperManager)
1628// getSystemService(Context.WALLPAPER_SERVICE);
1629// WallpaperInfo wi = wm.getWallpaperInfo();
1630// if (wi != null && wi.getSettingsActivity() != null) {
1631// LabeledIntent li = new LabeledIntent(getPackageName(),
1632// R.string.configure_wallpaper, 0);
1633// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1634// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1635// }
Mike Clerona0618e42009-10-22 13:55:21 -07001636 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001637 }
1638
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001639 /**
1640 * Registers various content observers. The current implementation registers
1641 * only a favorites observer to keep track of the favorites applications.
1642 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001643 private void registerContentObservers() {
1644 ContentResolver resolver = getContentResolver();
1645 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1646 true, mWidgetObserver);
1647 }
1648
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001649 @Override
1650 public boolean dispatchKeyEvent(KeyEvent event) {
1651 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1652 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001653 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001654 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001655 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001656 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001657 dumpState();
1658 return true;
1659 }
1660 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001661 }
1662 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1663 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001664 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001665 return true;
1666 }
1667 }
1668
1669 return super.dispatchKeyEvent(event);
1670 }
1671
Joe Onorato88ec0992009-11-19 13:16:06 -08001672 @Override
1673 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001674 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001675 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001676 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001677 Folder openFolder = mWorkspace.getOpenFolder();
1678 if (openFolder.isEditingName()) {
1679 openFolder.dismissEditingName();
1680 } else {
1681 closeFolder();
1682 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001683 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001684 mWorkspace.exitWidgetResizeMode();
1685
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001686 // Back button is a no-op here, but give at least some feedback for the button press
1687 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001688 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001689 }
1690
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001691 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001692 * Re-listen when widgets are reset.
1693 */
1694 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001695 if (mAppWidgetHost != null) {
1696 mAppWidgetHost.startListening();
1697 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001698 }
1699
1700 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001701 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1702 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001703 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001704 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001705 if (mModel != null) {
1706 mModel.unbindWorkspaceItems();
1707 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001708 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001709
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001710 /**
1711 * Launches the intent referred by the clicked shortcut.
1712 *
1713 * @param v The view representing the clicked shortcut.
1714 */
1715 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001716 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1717 // view has detached (it's possible for this to happen if the view is removed mid touch).
1718 if (v.getWindowToken() == null) {
1719 return;
1720 }
1721
1722 if (mWorkspace.isSwitchingState()) {
1723 return;
1724 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001725
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001726 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001727 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001728 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001729 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001730 int[] pos = new int[2];
1731 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001732 intent.setSourceBounds(new Rect(pos[0], pos[1],
1733 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Michael Jurkaddd62e92011-02-16 17:49:14 -08001734 boolean success = startActivitySafely(intent, tag);
1735
1736 if (success && v instanceof BubbleTextView) {
1737 mWaitingForResume = (BubbleTextView) v;
1738 mWaitingForResume.setStayPressed(true);
1739 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001740 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001741 if (v instanceof FolderIcon) {
1742 FolderIcon fi = (FolderIcon) v;
1743 handleFolderClick(fi);
1744 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001745 } else if (v == mAllAppsButton) {
1746 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001747 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001748 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001749 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001750 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001751 }
1752 }
1753
Michael Jurka0e260592010-06-30 17:07:39 -07001754 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001755 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001756 // clicking anywhere on the workspace causes the customization drawer to slide down
1757 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001758 return false;
1759 }
1760
Michael Jurkaaf442092010-06-10 17:01:57 -07001761 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001762 * Event handler for the search button
1763 *
1764 * @param v The view that was clicked.
1765 */
1766 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001767 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1768
Amith Yamasania135ba82011-08-09 17:42:01 -07001769 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001770 }
1771
1772 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001773 * Event handler for the voice button
1774 *
1775 * @param v The view that was clicked.
1776 */
1777 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001778 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001779
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001780 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001781 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001782 startActivity(intent);
1783 }
1784
1785 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001786 * Event handler for the "grid" button that appears on the home screen, which
1787 * enters all apps mode.
1788 *
1789 * @param v The view that was clicked.
1790 */
1791 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001792 showAllApps(true);
1793 }
1794
1795 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001796 // Provide the same haptic feedback that the system offers for virtual keys.
1797 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001798 }
1799
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001800 public void onClickAppMarketButton(View v) {
1801 if (mAppMarketIntent != null) {
1802 startActivitySafely(mAppMarketIntent, "app market");
1803 }
1804 }
1805
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001806 void startApplicationDetailsActivity(ComponentName componentName) {
1807 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001808 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1809 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001810 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001811 startActivity(intent);
1812 }
1813
Patrick Dubroy5539af72010-09-07 15:22:01 -07001814 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1815 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1816 // System applications cannot be installed. For now, show a toast explaining that.
1817 // We may give them the option of disabling apps this way.
1818 int messageId = R.string.uninstall_system_app_text;
1819 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1820 } else {
1821 String packageName = appInfo.componentName.getPackageName();
1822 String className = appInfo.componentName.getClassName();
1823 Intent intent = new Intent(
1824 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001825 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1826 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001827 startActivity(intent);
1828 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001829 }
1830
Michael Jurkaddd62e92011-02-16 17:49:14 -08001831 boolean startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001832 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1833 try {
1834 startActivity(intent);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001835 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001836 } catch (ActivityNotFoundException e) {
1837 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001838 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001839 } catch (SecurityException e) {
1840 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001841 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001842 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001843 "or use the exported attribute for this activity. "
1844 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001845 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001846 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001847 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001848
Romain Guy8e633c52010-03-04 12:51:36 -08001849 void startActivityForResultSafely(Intent intent, int requestCode) {
1850 try {
1851 startActivityForResult(intent, requestCode);
1852 } catch (ActivityNotFoundException e) {
1853 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1854 } catch (SecurityException e) {
1855 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1856 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1857 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1858 "or use the exported attribute for this activity.", e);
1859 }
1860 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001861
Adam Cohena9cf38f2011-05-02 15:36:58 -07001862 private void handleFolderClick(FolderIcon folderIcon) {
1863 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07001864 Folder openFolder = mWorkspace.getFolderForTag(info);
1865
1866 // If the folder info reports that the associated folder is open, then verify that
1867 // it is actually opened. There have been a few instances where this gets out of sync.
1868 if (info.opened && openFolder == null) {
1869 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
1870 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
1871 info.opened = false;
1872 }
1873
Adam Cohena9cf38f2011-05-02 15:36:58 -07001874 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001875 // Close any open folder
1876 closeFolder();
1877 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07001878 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001879 } else {
1880 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001881 int folderScreen;
1882 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001883 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001884 // .. and close it
1885 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001886 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001887 // Close any folder open on the current screen
1888 closeFolder();
1889 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07001890 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001891 }
1892 }
1893 }
1894 }
1895
Adam Cohen2801caf2011-05-13 20:57:39 -07001896 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001897 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001898 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
1899 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
1900 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
1901
Adam Cohenc51934b2011-07-26 21:07:43 -07001902 FolderInfo info = (FolderInfo) fi.getTag();
1903 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1904 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07001905 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
1906 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07001907 }
1908
Adam Cohen2801caf2011-05-13 20:57:39 -07001909 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1910 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1911 oa.start();
1912 }
1913
1914 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001915 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001916 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1917 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1918 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1919
Adam Cohenc51934b2011-07-26 21:07:43 -07001920 FolderInfo info = (FolderInfo) fi.getTag();
1921 CellLayout cl = null;
1922 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1923 cl = (CellLayout) fi.getParent().getParent();
1924 }
1925
1926 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07001927 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1928 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07001929 oa.addListener(new AnimatorListenerAdapter() {
1930 @Override
1931 public void onAnimationEnd(Animator animation) {
1932 if (layout != null) {
1933 layout.clearFolderLeaveBehind();
1934 }
1935 }
1936 });
Adam Cohen2801caf2011-05-13 20:57:39 -07001937 oa.start();
1938 }
1939
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001940 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001941 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001942 * is animated relative to the specified View. If the View is null, no animation
1943 * is played.
1944 *
1945 * @param folderInfo The FolderInfo describing the folder to open.
1946 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001947 public void openFolder(FolderIcon folderIcon) {
1948 Folder folder = folderIcon.mFolder;
1949 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001950
Adam Cohen2801caf2011-05-13 20:57:39 -07001951 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001952 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001953
Adam Cohen4554ee12011-08-03 16:13:21 -07001954 // Just verify that the folder hasn't already been added to the DragLayer.
1955 // There was a one-off crash where the folder had a parent already.
1956 if (folder.getParent() == null) {
1957 mDragLayer.addView(folder);
1958 mDragController.addDropTarget((DropTarget) folder);
1959 } else {
1960 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
1961 folder.getParent() + ").");
1962 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001963 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07001964 }
1965
1966 public void closeFolder() {
1967 Folder folder = mWorkspace.getOpenFolder();
1968 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07001969 if (folder.isEditingName()) {
1970 folder.dismissEditingName();
1971 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001972 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07001973
1974 // Dismiss the folder cling
1975 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07001976 }
1977 }
1978
1979 void closeFolder(Folder folder) {
1980 folder.getInfo().opened = false;
1981
1982 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
1983 if (parent != null) {
1984 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
1985 shrinkAndFadeInFolderIcon(fi);
1986 }
1987 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001988 }
1989
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001990 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08001991 if (mState != State.WORKSPACE) {
1992 return false;
1993 }
1994
Joe Onorato9c1289c2009-08-17 11:03:03 -04001995 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001996 return false;
1997 }
1998
1999 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002000 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002001 }
2002
Michael Jurka0280c3b2010-09-17 15:00:07 -07002003 resetAddInfo();
2004 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002005 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002006 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002007 return true;
2008 }
2009
Winson Chung3d503fb2011-07-13 17:25:49 -07002010 // The hotseat touch handling does not go through Workspace, and we always allow long press
2011 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002012 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002013 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2014 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002015 if (itemUnderLongClick == null) {
2016 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002017 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2018 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002019 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002020 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002021 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002022 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002023 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002024 }
2025 }
2026 }
2027 return true;
2028 }
2029
Winson Chung3d503fb2011-07-13 17:25:49 -07002030 boolean isHotseatLayout(View layout) {
2031 return mHotseat != null && layout != null &&
2032 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2033 }
2034 Hotseat getHotseat() {
2035 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002036 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002037 SearchDropTargetBar getSearchBar() {
2038 return mSearchDropTargetBar;
2039 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002040
Winson Chung3d503fb2011-07-13 17:25:49 -07002041 /**
2042 * Returns the CellLayout of the specified container at the specified screen.
2043 */
2044 CellLayout getCellLayout(long container, int screen) {
2045 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2046 if (mHotseat != null) {
2047 return mHotseat.getLayout();
2048 } else {
2049 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002050 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002051 } else {
2052 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002053 }
2054 }
2055
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002056 Workspace getWorkspace() {
2057 return mWorkspace;
2058 }
2059
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002060 @Override
2061 protected Dialog onCreateDialog(int id) {
2062 switch (id) {
2063 case DIALOG_CREATE_SHORTCUT:
2064 return new CreateShortcut().createDialog();
2065 case DIALOG_RENAME_FOLDER:
2066 return new RenameFolder().createDialog();
2067 }
2068
2069 return super.onCreateDialog(id);
2070 }
2071
2072 @Override
2073 protected void onPrepareDialog(int id, Dialog dialog) {
2074 switch (id) {
2075 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002076 break;
2077 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002078 if (mFolderInfo != null) {
2079 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2080 final CharSequence text = mFolderInfo.title;
2081 input.setText(text);
2082 input.setSelection(0, text.length());
2083 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002084 break;
2085 }
2086 }
2087
2088 void showRenameDialog(FolderInfo info) {
2089 mFolderInfo = info;
2090 mWaitingForResult = true;
2091 showDialog(DIALOG_RENAME_FOLDER);
2092 }
2093
Adam Cohenfbba09b2011-07-18 21:43:05 -07002094 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002095 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002096 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
2097 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002098 mWaitingForResult = true;
2099 showDialog(DIALOG_CREATE_SHORTCUT);
2100 }
2101
2102 private class RenameFolder {
2103 private EditText mInput;
2104
2105 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002106 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2107 mInput = (EditText) layout.findViewById(R.id.folder_name);
2108
2109 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2110 builder.setIcon(0);
2111 builder.setTitle(getString(R.string.rename_folder_title));
2112 builder.setCancelable(true);
2113 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2114 public void onCancel(DialogInterface dialog) {
2115 cleanup();
2116 }
2117 });
2118 builder.setNegativeButton(getString(R.string.cancel_action),
2119 new Dialog.OnClickListener() {
2120 public void onClick(DialogInterface dialog, int which) {
2121 cleanup();
2122 }
2123 }
2124 );
2125 builder.setPositiveButton(getString(R.string.rename_action),
2126 new Dialog.OnClickListener() {
2127 public void onClick(DialogInterface dialog, int which) {
2128 changeFolderName();
2129 }
2130 }
2131 );
2132 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002133
2134 final AlertDialog dialog = builder.create();
2135 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2136 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002137 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002138 mInput.requestFocus();
2139 InputMethodManager inputManager = (InputMethodManager)
2140 getSystemService(Context.INPUT_METHOD_SERVICE);
2141 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002142 }
2143 });
2144
2145 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002146 }
2147
2148 private void changeFolderName() {
2149 final String name = mInput.getText().toString();
2150 if (!TextUtils.isEmpty(name)) {
2151 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002152 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002153 mFolderInfo.title = name;
2154 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2155
Joe Onorato9c1289c2009-08-17 11:03:03 -04002156 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002157 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002158 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002159 } else {
2160 final FolderIcon folderIcon = (FolderIcon)
2161 mWorkspace.getViewForTag(mFolderInfo);
2162 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002163 // TODO: At some point we'll probably want some version of setting
2164 // the text for a folder icon.
2165 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002166 getWorkspace().requestLayout();
2167 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002168 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002169 mWorkspaceLoading = true;
2170 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002171 }
2172 }
2173 }
2174 cleanup();
2175 }
2176
2177 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002178 dismissDialog(DIALOG_RENAME_FOLDER);
2179 mWaitingForResult = false;
2180 mFolderInfo = null;
2181 }
2182 }
2183
Daniel Sandler843e8602010-06-07 14:59:01 -04002184 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2185 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002186 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002187 }
2188
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002189 // AllAppsView.Watcher
2190 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002191 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002192 mWorkspace.setVisibility(View.GONE);
2193 }
2194 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002195
2196 /**
2197 * Helper method for the cameraZoomIn/cameraZoomOut animations
2198 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002199 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002200 * @param scaleFactor The scale factor used for the zoom
2201 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002202 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002203 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002204 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002205 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002206
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002207 void updateWallpaperVisibility(boolean visible) {
2208 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2209 int curflags = getWindow().getAttributes().flags
2210 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2211 if (wpflags != curflags) {
2212 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2213 }
2214 }
2215
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002216 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002217 * Things to test when changing the following seven functions.
2218 * - Home from workspace
2219 * - from center screen
2220 * - from other screens
2221 * - Home from all apps
2222 * - from center screen
2223 * - from other screens
2224 * - Back from all apps
2225 * - from center screen
2226 * - from other screens
2227 * - Launch app from workspace and quit
2228 * - with back
2229 * - with home
2230 * - Launch app from all apps and quit
2231 * - with back
2232 * - with home
2233 * - Go to a screen that's not the default, then all
2234 * apps, and launch and app, and go back
2235 * - with back
2236 * -with home
2237 * - On workspace, long press power and go back
2238 * - with back
2239 * - with home
2240 * - On all apps, long press power and go back
2241 * - with back
2242 * - with home
2243 * - On workspace, power off
2244 * - On all apps, power off
2245 * - Launch an app and turn off the screen while in that app
2246 * - Go back with home key
2247 * - Go back with back key TODO: make this not go to workspace
2248 * - From all apps
2249 * - From workspace
2250 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2251 * - From all apps
2252 * - From the center workspace
2253 * - From another workspace
2254 */
2255
2256 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002257 * Zoom the camera out from the workspace to reveal 'toView'.
2258 * Assumes that the view to show is anchored at either the very top or very bottom
2259 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002260 */
Michael Jurka9753d132012-02-14 12:13:34 -08002261 private void showAppsCustomizeHelper(boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002262 if (mStateAnimation != null) {
2263 mStateAnimation.cancel();
2264 mStateAnimation = null;
2265 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002266 final Resources res = getResources();
Winson Chung7d7541e2011-09-16 20:14:36 -07002267 final Launcher instance = this;
Adam Cohenf16e5712011-01-13 13:31:45 -08002268
Winson Chungf0ea4d32011-06-06 14:27:16 -07002269 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2270 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2271 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2272 final View toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002273 final int startDelay =
2274 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002275
Michael Jurkab3e22d92011-10-31 15:58:33 -07002276 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002277
Michael Jurkad74c9842011-07-10 12:44:21 -07002278 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002279 Animator workspaceAnim =
2280 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002281
2282 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002283 toView.setScaleX(scale);
2284 toView.setScaleY(scale);
2285 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2286 scaleAnim.
2287 scaleX(1f).scaleY(1f).
2288 setDuration(duration).
2289 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002290
Winson Chungf0ea4d32011-06-06 14:27:16 -07002291 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002292 toView.setAlpha(0f);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002293 final ObjectAnimator alphaAnim = ObjectAnimator
2294 .ofFloat(toView, "alpha", 0f, 1f)
2295 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002296 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Adam Cohenf16e5712011-01-13 13:31:45 -08002297
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002298 // toView should appear right at the end of the workspace shrink
2299 // animation
2300 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002301 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002302 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002303
2304 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002305 boolean animationCancelled = false;
2306
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002307 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002308 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002309 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002310 // Prepare the position
2311 toView.setTranslationX(0.0f);
2312 toView.setTranslationY(0.0f);
2313 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002314 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002315 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002316 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002317 public void onAnimationEnd(Animator animation) {
Michael Jurka9753d132012-02-14 12:13:34 -08002318 if (toView instanceof LauncherTransitionable) {
2319 ((LauncherTransitionable) toView).onLauncherTransitionEnd(instance,
2320 scaleAnim, false);
2321 }
Winson Chung32174c82011-07-19 15:47:55 -07002322
2323 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2324 // Hide the workspace scrollbar
2325 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002326 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002327 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002328 if (!animationCancelled) {
2329 updateWallpaperVisibility(false);
2330 }
2331 }
2332
Adam Cohencff6af82011-09-13 14:51:53 -07002333 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002334 public void onAnimationCancel(Animator animation) {
2335 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002336 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002337 });
2338
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002339 if (workspaceAnim != null) {
2340 mStateAnimation.play(workspaceAnim);
2341 }
Michael Jurka1899a362011-11-03 13:50:45 -07002342
2343 boolean delayAnim = false;
Michael Jurka9753d132012-02-14 12:13:34 -08002344 LauncherTransitionable lt = (LauncherTransitionable) toView;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002345 final ViewTreeObserver observer;
2346
Michael Jurka9753d132012-02-14 12:13:34 -08002347 lt.onLauncherTransitionStart(instance, mStateAnimation, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002348
2349 // If any of the objects being animated haven't been measured/laid out
2350 // yet, delay the animation until we get a layout pass
Michael Jurka9753d132012-02-14 12:13:34 -08002351 if ((lt.getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002352 (mWorkspace.getMeasuredWidth() == 0) ||
2353 (toView.getMeasuredWidth() == 0)) {
2354 observer = mWorkspace.getViewTreeObserver();
2355 delayAnim = true;
2356 } else {
2357 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002358 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002359
2360 if (delayAnim) {
Michael Jurka49779a12012-01-16 04:10:08 -08002361 final AnimatorSet stateAnimation = mStateAnimation;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002362 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2363 public void onGlobalLayout() {
2364 mWorkspace.post(new Runnable() {
2365 public void run() {
Michael Jurka49779a12012-01-16 04:10:08 -08002366 // Check that mStateAnimation hasn't changed while
2367 // we waited for a layout pass
2368 if (mStateAnimation == stateAnimation) {
2369 // Need to update pivots for zoom if layout changed
2370 setPivotsForZoom(toView, scale);
2371 mStateAnimation.start();
2372 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002373 }
2374 });
2375 observer.removeGlobalOnLayoutListener(this);
2376 }
2377 };
2378 observer.addOnGlobalLayoutListener(delayedStart);
2379 } else {
2380 setPivotsForZoom(toView, scale);
Michael Jurka1899a362011-11-03 13:50:45 -07002381 mStateAnimation.start();
2382 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002383 } else {
2384 toView.setTranslationX(0.0f);
2385 toView.setTranslationY(0.0f);
2386 toView.setScaleX(1.0f);
2387 toView.setScaleY(1.0f);
2388 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002389 toView.bringToFront();
Michael Jurka9753d132012-02-14 12:13:34 -08002390 if (toView instanceof LauncherTransitionable) {
2391 ((LauncherTransitionable) toView).onLauncherTransitionStart(instance, null, false);
2392 ((LauncherTransitionable) toView).onLauncherTransitionEnd(instance, null, false);
Winson Chung3ac74c52011-06-30 17:39:37 -07002393
Michael Jurka9753d132012-02-14 12:13:34 -08002394 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2395 // Hide the workspace scrollbar
2396 mWorkspace.hideScrollingIndicator(true);
2397 hideDockDivider();
2398 }
Michael Jurkaabded662011-03-04 12:06:57 -08002399 }
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002400 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002401 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002402 }
2403
2404 /**
2405 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002406 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002407 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002408 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002409 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2410 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002411 if (mStateAnimation != null) {
2412 mStateAnimation.cancel();
2413 mStateAnimation = null;
2414 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002415 Resources res = getResources();
Michael Jurka9753d132012-02-14 12:13:34 -08002416 final Launcher instance = this;
Adam Cohenf16e5712011-01-13 13:31:45 -08002417
Winson Chungf0ea4d32011-06-06 14:27:16 -07002418 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002419 final int fadeOutDuration =
2420 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002421 final float scaleFactor = (float)
2422 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2423 final View fromView = mAppsCustomizeTabHost;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002424 Animator workspaceAnim = null;
2425
2426 if (toState == State.WORKSPACE) {
2427 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2428 workspaceAnim = mWorkspace.getChangeStateAnimation(
2429 Workspace.State.NORMAL, animated, stagger);
2430 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2431 workspaceAnim = mWorkspace.getChangeStateAnimation(
2432 Workspace.State.SPRING_LOADED, animated);
2433 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002434
Michael Jurkab3e22d92011-10-31 15:58:33 -07002435 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002436 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002437 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002438 if (animated) {
Michael Jurka742574b2011-02-02 23:51:01 -08002439 final float oldScaleX = fromView.getScaleX();
2440 final float oldScaleY = fromView.getScaleY();
2441
Michael Jurka159b4cc2012-01-17 03:00:35 -08002442 final LauncherViewPropertyAnimator scaleAnim =
2443 new LauncherViewPropertyAnimator(fromView);
2444 scaleAnim.
2445 scaleX(scaleFactor).scaleY(scaleFactor).
2446 setDuration(duration).
2447 setInterpolator(new Workspace.ZoomInInterpolator());
2448
2449 final ObjectAnimator alphaAnim = ObjectAnimator
2450 .ofFloat(fromView, "alpha", 1f, 0f)
2451 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002452 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Michael Jurka159b4cc2012-01-17 03:00:35 -08002453
Michael Jurka9753d132012-02-14 12:13:34 -08002454 if (fromView instanceof LauncherTransitionable) {
2455 ((LauncherTransitionable) fromView).onLauncherTransitionStart(instance, alphaAnim,
2456 true);
2457 }
2458 alphaAnim.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002459 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002460 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002461 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002462 fromView.setVisibility(View.GONE);
Michael Jurka9753d132012-02-14 12:13:34 -08002463 if (fromView instanceof LauncherTransitionable) {
2464 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(instance,
2465 alphaAnim, true);
2466 }
Michael Jurka430e8a52011-08-08 15:52:14 -07002467 mWorkspace.hideScrollingIndicator(false);
Adam Cohened66b2b2012-01-23 17:28:51 -08002468 if (onCompleteRunnable != null) {
2469 onCompleteRunnable.run();
2470 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002471 }
2472 });
2473
Michael Jurka9753d132012-02-14 12:13:34 -08002474 mStateAnimation = new AnimatorSet();
Winson Chungf0ea4d32011-06-06 14:27:16 -07002475 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002476 if (workspaceAnim != null) {
2477 mStateAnimation.play(workspaceAnim);
2478 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002479 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002480 } else {
2481 fromView.setVisibility(View.GONE);
Michael Jurka9753d132012-02-14 12:13:34 -08002482 if (fromView instanceof LauncherTransitionable) {
2483 ((LauncherTransitionable) fromView).onLauncherTransitionStart(instance, null, true);
2484 ((LauncherTransitionable) fromView).onLauncherTransitionEnd(instance, null, true);
2485 }
Michael Jurkab737ee62011-11-15 15:57:22 -08002486 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002487 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002488 }
2489
Michael Jurkae326f182011-11-21 14:05:46 -08002490 @Override
2491 public void onTrimMemory(int level) {
2492 super.onTrimMemory(level);
2493 if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
2494 mAppsCustomizeTabHost.onTrimMemory();
2495 }
2496 }
2497
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002498 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002499 showWorkspace(animated, null);
2500 }
2501
2502 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002503 if (mState != State.WORKSPACE) {
2504 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002505 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002506
2507 // Show the search bar and hotseat
2508 mSearchDropTargetBar.showSearchBar(animated);
Michael Jurkab737ee62011-11-15 15:57:22 -08002509 // We only need to animate in the dock divider if we're going from spring loaded mode
2510 showDockDivider(animated && mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002511
2512 // Set focus to the AppsCustomize button
2513 if (mAllAppsButton != null) {
2514 mAllAppsButton.requestFocus();
2515 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002516 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002517
Michael Jurkab737ee62011-11-15 15:57:22 -08002518 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002519
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002520 // Change the state *after* we've called all the transition code
2521 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002522
Winson Chung5fb63472011-02-02 17:03:37 -08002523 // Resume the auto-advance of widgets
2524 mUserPresent = true;
2525 updateRunning();
2526
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002527 // send an accessibility event to announce the context change
2528 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002529 }
2530
Michael Jurkab3e22d92011-10-31 15:58:33 -07002531 void showAllApps(boolean animated) {
2532 if (mState != State.WORKSPACE) return;
2533
2534 showAppsCustomizeHelper(animated, false);
2535 mAppsCustomizeTabHost.requestFocus();
2536
2537 // Hide the search bar and hotseat
2538 mSearchDropTargetBar.hideSearchBar(animated);
2539
2540 // Change the state *after* we've called all the transition code
2541 mState = State.APPS_CUSTOMIZE;
2542
2543 // Pause the auto-advance of widgets until we are out of AllApps
2544 mUserPresent = false;
2545 updateRunning();
2546 closeFolder();
2547
2548 // Send an accessibility event to announce the context change
2549 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2550 }
2551
Adam Cohen7777d962011-08-18 18:58:38 -07002552 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002553 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002554 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002555 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002556 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002557 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002558 }
Adam Cohen7777d962011-08-18 18:58:38 -07002559
Adam Cohened66b2b2012-01-23 17:28:51 -08002560 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2561 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002562 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2563
Winson Chunge7a03942011-08-05 15:05:12 -07002564 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002565 @Override
2566 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002567 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002568 // Before we show workspace, hide all apps again because
2569 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2570 // clean up our state transition functions
2571 mAppsCustomizeTabHost.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002572 mSearchDropTargetBar.showSearchBar(true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002573 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002574 } else {
2575 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002576 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002577 }
2578 }, (extendedDelay ?
2579 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2580 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2581 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002582
Michael Jurkad3ef3062010-11-23 16:23:58 -08002583 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002584 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002585 final boolean animated = true;
2586 final boolean springLoaded = true;
2587 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002588 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002589 }
2590 // Otherwise, we are not in spring loaded mode, so don't do anything.
2591 }
2592
Michael Jurkab737ee62011-11-15 15:57:22 -08002593 void hideDockDivider() {
2594 if (mQsbDivider != null && mDockDivider != null) {
2595 mQsbDivider.setVisibility(View.INVISIBLE);
2596 mDockDivider.setVisibility(View.INVISIBLE);
2597 }
2598 }
2599
2600 void showDockDivider(boolean animated) {
2601 if (mQsbDivider != null && mDockDivider != null) {
2602 mQsbDivider.setVisibility(View.VISIBLE);
2603 mDockDivider.setVisibility(View.VISIBLE);
2604 if (mDividerAnimator != null) {
2605 mDividerAnimator.cancel();
2606 mQsbDivider.setAlpha(1f);
2607 mDockDivider.setAlpha(1f);
2608 mDividerAnimator = null;
2609 }
2610 if (animated) {
2611 mDividerAnimator = new AnimatorSet();
2612 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2613 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2614 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2615 mDividerAnimator.start();
2616 }
2617 }
2618 }
2619
Michael Jurkab3e22d92011-10-31 15:58:33 -07002620 void lockAllApps() {
2621 // TODO
2622 }
2623
2624 void unlockAllApps() {
2625 // TODO
2626 }
2627
Adam Cohenfc53cd22011-07-20 15:45:11 -07002628 public boolean isAllAppsCustomizeOpen() {
2629 return mState == State.APPS_CUSTOMIZE;
2630 }
2631
Winson Chungf0ea4d32011-06-06 14:27:16 -07002632 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002633 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002634 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002635 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002636 if (!LauncherApplication.isScreenLarge()) {
2637 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002638 if (mHotseat.getAlpha() != 1f) {
2639 int duration = mSearchDropTargetBar.getTransitionInDuration();
2640 mHotseat.animate().alpha(1f).setDuration(duration);
2641 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002642 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002643 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002644 }
2645 }
2646 }
2647
2648 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002649 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002650 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002651 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002652 if (!LauncherApplication.isScreenLarge()) {
2653 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002654 if (mHotseat.getAlpha() != 0f) {
2655 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2656 mHotseat.animate().alpha(0f).setDuration(duration);
2657 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002658 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002659 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002660 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002661 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002662 }
2663
Patrick Dubroy5f445422011-02-18 14:35:21 -08002664 /**
2665 * Add an item from all apps or customize onto the given workspace screen.
2666 * If layout is null, add to the current screen.
2667 */
2668 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002669 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2670 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07002671 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002672 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002673
Winson Chungdff8ebb2011-09-08 17:25:31 -07002674 /** Maps the current orientation to an index for referencing orientation correct global icons */
2675 private int getCurrentOrientationIndexForGlobalIcons() {
2676 // default - 0, landscape - 1
2677 switch (getResources().getConfiguration().orientation) {
2678 case Configuration.ORIENTATION_LANDSCAPE:
2679 return 1;
2680 default:
2681 return 0;
2682 }
2683 }
2684
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002685 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002686 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002687 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002688 // Look for the toolbar icon specified in the activity meta-data
2689 Bundle metaData = packageManager.getActivityInfo(
2690 activityName, PackageManager.GET_META_DATA).metaData;
2691 if (metaData != null) {
2692 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2693 if (iconResId != 0) {
2694 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002695 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002696 }
2697 }
2698 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002699 // This can happen if the activity defines an invalid drawable
2700 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2701 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002702 } catch (Resources.NotFoundException nfe) {
2703 // This can happen if the activity defines an invalid drawable
2704 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2705 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002706 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002707 return null;
2708 }
2709
2710 // if successful in getting icon, return it; otherwise, set button to use default drawable
2711 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2712 int buttonId, ComponentName activityName, int fallbackDrawableId) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002713 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002714 Resources r = getResources();
2715 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2716 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002717
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002718 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002719 // If we were unable to find the icon via the meta-data, use a generic one
2720 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002721 toolbarIcon = r.getDrawable(fallbackDrawableId);
2722 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002723 if (button != null) {
2724 button.setCompoundDrawables(toolbarIcon, null, null, null);
2725 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002726 return null;
2727 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002728 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002729 if (button != null) {
2730 button.setCompoundDrawables(toolbarIcon, null, null, null);
2731 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002732 return toolbarIcon.getConstantState();
2733 }
2734 }
2735
2736 // if successful in getting icon, return it; otherwise, set button to use default drawable
2737 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2738 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2739 ImageView button = (ImageView) findViewById(buttonId);
2740 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2741
Michael Jurka19e0fc52011-07-22 18:00:21 -07002742 if (button != null) {
2743 // If we were unable to find the icon via the meta-data, use a
2744 // generic one
2745 if (toolbarIcon == null) {
2746 button.setImageResource(fallbackDrawableId);
2747 } else {
2748 button.setImageDrawable(toolbarIcon);
2749 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002750 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002751
2752 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2753
Michael Jurka0423dcf2010-10-05 14:56:18 -07002754 }
2755
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002756 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2757 TextView button = (TextView) findViewById(buttonId);
2758 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2759 }
2760
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002761 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002762 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002763 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002764 }
2765
Winson Chungbb185bd2011-11-21 12:31:42 -08002766 private void invalidatePressedFocusedStates(View container, View button) {
2767 if (container instanceof HolographicLinearLayout) {
2768 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2769 layout.invalidatePressedFocusedStates();
2770 } else if (button instanceof HolographicImageView) {
2771 HolographicImageView view = (HolographicImageView) button;
2772 view.invalidatePressedFocusedStates();
2773 }
2774 }
2775
Winson Chungc51db6a2011-10-05 11:44:49 -07002776 private boolean updateGlobalSearchIcon() {
2777 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002778 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2779 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002780 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002781 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002782
Winson Chung1cad91e2011-05-25 17:41:01 -07002783 final SearchManager searchManager =
2784 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2785 ComponentName activityName = searchManager.getGlobalSearchActivity();
2786 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002787 int coi = getCurrentOrientationIndexForGlobalIcons();
2788 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002789 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002790 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002791 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2792 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002793 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002794 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002795 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002796 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002797 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002798 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2799 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2800 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002801 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002802 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002803 }
2804 }
2805
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002806 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002807 final View searchButtonContainer = findViewById(R.id.search_button_container);
2808 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002809 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002810 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002811 }
2812
Winson Chungc51db6a2011-10-05 11:44:49 -07002813 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002814 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002815 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002816 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002817
Winson Chungc51db6a2011-10-05 11:44:49 -07002818 // We only show/update the voice search icon if the search icon is enabled as well
Winson Chung1cad91e2011-05-25 17:41:01 -07002819 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2820 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chungc51db6a2011-10-05 11:44:49 -07002821 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002822 int coi = getCurrentOrientationIndexForGlobalIcons();
2823 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002824 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002825 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002826 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002827 voiceButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002828 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002829 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002830 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002831 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002832 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002833 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002834 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002835 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002836 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002837
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002838 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002839 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
2840 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002841 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002842 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002843 }
2844
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002845 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002846 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002847 */
2848 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002849 final View marketButton = findViewById(R.id.market_button);
2850 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2851 // Find the app market activity by resolving an intent.
2852 // (If multiple app markets are installed, it will return the ResolverActivity.)
2853 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002854 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002855 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07002856 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07002857 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002858 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002859 marketButton.setVisibility(View.VISIBLE);
2860 } else {
2861 // We should hide and disable the view so that we don't try and restore the visibility
2862 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2863 marketButton.setVisibility(View.GONE);
2864 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002865 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002866 }
2867
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002868 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002869 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002870 }
2871
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002872 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002873 * Displays the shortcut creation dialog and launches, if necessary, the
2874 * appropriate activity.
2875 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002876 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002877 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2878 DialogInterface.OnShowListener {
2879
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002880 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002881
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002882 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002883 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002884
Winson Chung55b65502011-05-26 12:03:43 -07002885 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2886 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002887 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002888
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002889 AlertDialog dialog = builder.create();
2890 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002891 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002892 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002893
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002894 return dialog;
2895 }
2896
2897 public void onCancel(DialogInterface dialog) {
2898 mWaitingForResult = false;
2899 cleanup();
2900 }
2901
Romain Guycbb89e42009-06-08 15:52:54 -07002902 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002903 mWaitingForResult = false;
2904 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002905 }
2906
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002907 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002908 try {
2909 dismissDialog(DIALOG_CREATE_SHORTCUT);
2910 } catch (Exception e) {
2911 // An exception is thrown if the dialog is not visible, which is fine
2912 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002913 }
2914
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002915 /**
2916 * Handle the action clicked in the "Add to home" dialog.
2917 */
2918 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002919 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002920
Winson Chung55b65502011-05-26 12:03:43 -07002921 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2922 switch (item.actionTag) {
Winson Chung55b65502011-05-26 12:03:43 -07002923 case AddAdapter.ITEM_APPLICATION: {
2924 if (mAppsCustomizeTabHost != null) {
2925 mAppsCustomizeTabHost.selectAppsTab();
2926 }
2927 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002928 break;
2929 }
Winson Chung55b65502011-05-26 12:03:43 -07002930 case AddAdapter.ITEM_APPWIDGET: {
2931 if (mAppsCustomizeTabHost != null) {
2932 mAppsCustomizeTabHost.selectWidgetsTab();
2933 }
2934 showAllApps(true);
2935 break;
2936 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002937 case AddAdapter.ITEM_WALLPAPER: {
2938 startWallpaper();
2939 break;
2940 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002941 }
2942 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002943
2944 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002945 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002946 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002947 }
2948
2949 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07002950 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002951 */
2952 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2953 @Override
2954 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002955 closeSystemDialogs();
2956 }
2957 }
2958
2959 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002960 * Receives notifications whenever the appwidgets are reset.
2961 */
2962 private class AppWidgetResetObserver extends ContentObserver {
2963 public AppWidgetResetObserver() {
2964 super(new Handler());
2965 }
2966
2967 @Override
2968 public void onChange(boolean selfChange) {
2969 onAppWidgetReset();
2970 }
2971 }
2972
2973 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002974 * If the activity is currently paused, signal that we need to re-run the loader
2975 * in onResume.
2976 *
2977 * This needs to be called from incoming places where resources might have been loaded
2978 * while we are paused. That is becaues the Configuration might be wrong
2979 * when we're not running, and if it comes back to what it was when we
2980 * were paused, we are not restarted.
2981 *
2982 * Implementation of the method from LauncherModel.Callbacks.
2983 *
2984 * @return true if we are currently paused. The caller might be able to
2985 * skip some work in that case since we will come back again.
2986 */
2987 public boolean setLoadOnResume() {
2988 if (mPaused) {
2989 Log.i(TAG, "setLoadOnResume");
2990 mOnResumeNeedsLoad = true;
2991 return true;
2992 } else {
2993 return false;
2994 }
2995 }
2996
2997 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002998 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002999 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003000 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003001 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003002 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003003 } else {
3004 return SCREEN_COUNT / 2;
3005 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003006 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003007
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003008
Joe Onorato9c1289c2009-08-17 11:03:03 -04003009 /**
3010 * Refreshes the shortcuts shown on the workspace.
3011 *
3012 * Implementation of the method from LauncherModel.Callbacks.
3013 */
3014 public void startBinding() {
3015 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07003016
3017 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003018 int count = workspace.getChildCount();
3019 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003020 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003021 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3022 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003023 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08003024 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003025 if (mHotseat != null) {
3026 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003027 }
3028 }
3029
3030 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003031 * Bind the items start-end from the list.
3032 *
3033 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003034 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003035 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003036 setLoadOnResume();
3037
Joe Onorato9c1289c2009-08-17 11:03:03 -04003038 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003039 for (int i=start; i<end; i++) {
3040 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003041
3042 // Short circuit if we are loading dock items for a configuration which has no dock
3043 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3044 mHotseat == null) {
3045 continue;
3046 }
3047
Joe Onorato9c1289c2009-08-17 11:03:03 -04003048 switch (item.itemType) {
3049 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3050 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07003051 View shortcut = createShortcut((ShortcutInfo)item);
3052 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3053 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003054 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003055 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003056 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003057 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003058 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003059 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3060 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003061 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003062 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003063 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003064 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003065 }
3066
Joe Onorato9c1289c2009-08-17 11:03:03 -04003067 /**
3068 * Implementation of the method from LauncherModel.Callbacks.
3069 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003070 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003071 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003072 sFolders.clear();
3073 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003074 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003075
3076 /**
3077 * Add the views for a widget to the workspace.
3078 *
3079 * Implementation of the method from LauncherModel.Callbacks.
3080 */
3081 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003082 setLoadOnResume();
3083
Daniel Sandler843e8602010-06-07 14:59:01 -04003084 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3085 if (DEBUG_WIDGETS) {
3086 Log.d(TAG, "bindAppWidget: " + item);
3087 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003088 final Workspace workspace = mWorkspace;
3089
3090 final int appWidgetId = item.appWidgetId;
3091 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003092 if (DEBUG_WIDGETS) {
3093 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3094 }
3095
Joe Onorato9c1289c2009-08-17 11:03:03 -04003096 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3097
Joe Onorato9c1289c2009-08-17 11:03:03 -04003098 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
3099 item.hostView.setTag(item);
3100
Winson Chung3d503fb2011-07-13 17:25:49 -07003101 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003102 item.cellY, item.spanX, item.spanY, false);
3103
Adam Cohended9f8d2010-11-03 13:25:16 -07003104 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3105
Joe Onorato9c1289c2009-08-17 11:03:03 -04003106 workspace.requestLayout();
3107
Daniel Sandler843e8602010-06-07 14:59:01 -04003108 if (DEBUG_WIDGETS) {
3109 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3110 + (SystemClock.uptimeMillis()-start) + "ms");
3111 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003112 }
3113
3114 /**
3115 * Callback saying that there aren't any more items to bind.
3116 *
3117 * Implementation of the method from LauncherModel.Callbacks.
3118 */
3119 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003120 setLoadOnResume();
3121
Joe Onorato9c1289c2009-08-17 11:03:03 -04003122 if (mSavedState != null) {
3123 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003124 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003125 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003126 mSavedState = null;
3127 }
3128
3129 if (mSavedInstanceState != null) {
3130 super.onRestoreInstanceState(mSavedInstanceState);
3131 mSavedInstanceState = null;
3132 }
3133
Joe Onorato9c1289c2009-08-17 11:03:03 -04003134 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003135
3136 // If we received the result of any pending adds while the loader was running (e.g. the
3137 // widget configuration forced an orientation change), process them now.
3138 for (int i = 0; i < sPendingAddList.size(); i++) {
3139 completeAdd(sPendingAddList.get(i));
3140 }
3141 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003142
Winson Chungc51db6a2011-10-05 11:44:49 -07003143 // Update the market app icon as necessary (the other icons will be managed in response to
3144 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003145 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003146
3147 mWorkspace.post(mBuildLayersRunnable);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003148 }
3149
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003150 @Override
3151 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003152 boolean searchVisible = updateGlobalSearchIcon();
3153 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3154 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003155 }
3156
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003157 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003158 * Add the icons for all apps.
3159 *
3160 * Implementation of the method from LauncherModel.Callbacks.
3161 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003162 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3163 // Remove the progress bar entirely; we could also make it GONE
3164 // but better to remove it since we know it's not going to be used
3165 View progressBar = mAppsCustomizeTabHost.
3166 findViewById(R.id.apps_customize_progress_bar);
3167 if (progressBar != null) {
3168 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003169 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003170 // We just post the call to setApps so the user sees the progress bar
3171 // disappear-- otherwise, it just looks like the progress bar froze
3172 // which doesn't look great
3173 mAppsCustomizeTabHost.post(new Runnable() {
3174 public void run() {
3175 if (mAppsCustomizeContent != null) {
3176 mAppsCustomizeContent.setApps(apps);
3177 }
3178 }
3179 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003180 }
3181
3182 /**
3183 * A package was installed.
3184 *
3185 * Implementation of the method from LauncherModel.Callbacks.
3186 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003187 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003188 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003189 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003190
Winson Chung785d2eb2011-04-14 16:08:02 -07003191 if (mAppsCustomizeContent != null) {
3192 mAppsCustomizeContent.addApps(apps);
3193 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003194 }
3195
3196 /**
3197 * A package was updated.
3198 *
3199 * Implementation of the method from LauncherModel.Callbacks.
3200 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003201 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003202 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003203 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003204 if (mWorkspace != null) {
3205 mWorkspace.updateShortcuts(apps);
3206 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003207
Winson Chung785d2eb2011-04-14 16:08:02 -07003208 if (mAppsCustomizeContent != null) {
3209 mAppsCustomizeContent.updateApps(apps);
3210 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003211 }
3212
3213 /**
3214 * A package was uninstalled.
3215 *
3216 * Implementation of the method from LauncherModel.Callbacks.
3217 */
Joe Onorato36115782010-06-17 13:28:48 -04003218 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003219 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003220 if (permanent) {
3221 mWorkspace.removeItems(apps);
3222 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003223
Winson Chung785d2eb2011-04-14 16:08:02 -07003224 if (mAppsCustomizeContent != null) {
3225 mAppsCustomizeContent.removeApps(apps);
3226 }
Winson Chunga1820962011-10-03 16:31:06 -07003227
3228 // Notify the drag controller
3229 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003230 }
Joe Onoratobe386092009-11-17 17:32:16 -08003231
3232 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003233 * A number of packages were updated.
3234 */
3235 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003236 if (mAppsCustomizeContent != null) {
3237 mAppsCustomizeContent.onPackagesUpdated();
3238 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003239 }
3240
Winson Chung400438b2011-01-16 17:53:48 -08003241 private int mapConfigurationOriActivityInfoOri(int configOri) {
3242 final Display d = getWindowManager().getDefaultDisplay();
3243 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3244 switch (d.getRotation()) {
3245 case Surface.ROTATION_0:
3246 case Surface.ROTATION_180:
3247 // We are currently in the same basic orientation as the natural orientation
3248 naturalOri = configOri;
3249 break;
3250 case Surface.ROTATION_90:
3251 case Surface.ROTATION_270:
3252 // We are currently in the other basic orientation to the natural orientation
3253 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3254 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3255 break;
3256 }
3257
3258 int[] oriMap = {
3259 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3260 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3261 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3262 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3263 };
3264 // Since the map starts at portrait, we need to offset if this device's natural orientation
3265 // is landscape.
3266 int indexOffset = 0;
3267 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3268 indexOffset = 1;
3269 }
3270 return oriMap[(d.getRotation() + indexOffset) % 4];
3271 }
Adam Cohen446e9402011-09-15 18:21:21 -07003272
3273 public void lockScreenOrientationOnLargeUI() {
3274 if (LauncherApplication.isScreenLarge()) {
3275 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3276 .getConfiguration().orientation));
3277 }
Winson Chung400438b2011-01-16 17:53:48 -08003278 }
Adam Cohen446e9402011-09-15 18:21:21 -07003279 public void unlockScreenOrientationOnLargeUI() {
3280 if (LauncherApplication.isScreenLarge()) {
3281 mHandler.postDelayed(new Runnable() {
3282 public void run() {
3283 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3284 }
3285 }, mRestoreScreenOrientationDelay);
3286 }
Winson Chung400438b2011-01-16 17:53:48 -08003287 }
3288
Winson Chung82f55532011-08-09 14:14:23 -07003289 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003290 private static final String PREFS_KEY = "com.android.launcher2.prefs";
3291 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003292 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003293 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003294
Winson Chung7d7541e2011-09-16 20:14:36 -07003295 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003296 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003297 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3298 Cling cling = (Cling) findViewById(clingId);
3299 if (cling != null) {
3300 cling.init(this, positionData);
3301 cling.setVisibility(View.VISIBLE);
3302 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3303 if (animate) {
3304 cling.buildLayer();
3305 cling.setAlpha(0f);
3306 cling.animate()
3307 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003308 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003309 .setDuration(SHOW_CLING_DURATION)
3310 .setStartDelay(delay)
3311 .start();
3312 } else {
3313 cling.setAlpha(1f);
3314 }
3315 }
3316 return cling;
3317 }
3318 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003319 if (cling != null) {
3320 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003321 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003322 anim.addListener(new AnimatorListenerAdapter() {
3323 public void onAnimationEnd(Animator animation) {
3324 cling.setVisibility(View.GONE);
3325 cling.cleanup();
3326 SharedPreferences prefs =
3327 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
3328 SharedPreferences.Editor editor = prefs.edit();
3329 editor.putBoolean(flag, true);
3330 editor.commit();
3331 };
3332 });
3333 anim.start();
3334 }
3335 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003336 private void removeCling(int id) {
3337 final View cling = findViewById(id);
3338 if (cling != null) {
3339 final ViewGroup parent = (ViewGroup) cling.getParent();
3340 parent.post(new Runnable() {
3341 @Override
3342 public void run() {
3343 parent.removeView(cling);
3344 }
3345 });
3346 }
3347 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003348 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003349 // Enable the clings only if they have not been dismissed before
3350 SharedPreferences prefs =
3351 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003352 if (isClingsEnabled() && !prefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003353 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003354 } else {
3355 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003356 }
3357 }
3358 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003359 // Enable the clings only if they have not been dismissed before
3360 SharedPreferences prefs =
3361 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003362 if (isClingsEnabled() && !prefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003363 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003364 } else {
3365 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003366 }
3367 }
3368 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003369 // Enable the clings only if they have not been dismissed before
3370 SharedPreferences prefs =
3371 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
3372 Cling cling = null;
Winson Chung9d9d74f2011-09-19 11:49:12 -07003373 if (isClingsEnabled() && !prefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003374 cling = initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003375 } else {
3376 removeCling(R.id.folder_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003377 }
3378 return cling;
3379 }
3380 public boolean isFolderClingVisible() {
3381 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003382 if (cling != null) {
3383 return cling.getVisibility() == View.VISIBLE;
3384 }
3385 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003386 }
Winson Chung82f55532011-08-09 14:14:23 -07003387 public void dismissWorkspaceCling(View v) {
3388 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003389 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003390 }
3391 public void dismissAllAppsCling(View v) {
3392 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003393 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3394 }
3395 public void dismissFolderCling(View v) {
3396 Cling cling = (Cling) findViewById(R.id.folder_cling);
3397 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003398 }
3399
Winson Chung80baf5a2010-08-09 16:03:15 -07003400 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003401 * Prints out out state for debugging.
3402 */
3403 public void dumpState() {
3404 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003405 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003406 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3407 Log.d(TAG, "mRestoring=" + mRestoring);
3408 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3409 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003410 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003411 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003412
Winson Chung785d2eb2011-04-14 16:08:02 -07003413 if (mAppsCustomizeContent != null) {
3414 mAppsCustomizeContent.dumpState();
3415 }
Joe Onoratobe386092009-11-17 17:32:16 -08003416 Log.d(TAG, "END launcher2 dump state");
3417 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003418
3419 @Override
3420 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3421 super.dump(prefix, fd, writer, args);
3422 writer.println(" ");
3423 writer.println("Debug logs: ");
3424 for (int i = 0; i < sDumpLogs.size(); i++) {
3425 writer.println(" " + sDumpLogs.get(i));
3426 }
3427 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003428}
Michael Jurka2763be32011-02-24 11:19:57 -08003429
Michael Jurkaabded662011-03-04 12:06:57 -08003430interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003431 View getContent();
Michael Jurka9753d132012-02-14 12:13:34 -08003432 void onLauncherTransitionStart(Launcher l, Animator animation, boolean toWorkspace);
3433 void onLauncherTransitionEnd(Launcher l, Animator animation, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003434}