blob: 708d5d63162db1836471d91511513dc935dd4771 [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);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800585 }
586
587 @Override
588 protected void onResume() {
589 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800590 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700591 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400592 mWorkspaceLoading = true;
593 mModel.startLoader(this, true);
594 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700595 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800596 }
Winson Chunge4e50662012-01-23 14:45:13 -0800597
598 // Reset the pressed state of icons that were locked in the press state while activities
599 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800600 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800601 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800602 mWaitingForResume.setStayPressed(false);
603 }
Winson Chunge4e50662012-01-23 14:45:13 -0800604 if (mAppsCustomizeContent != null) {
605 // Resets the previous all apps icon press state
606 mAppsCustomizeContent.resetDrawableState();
607 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700608 // When we resume Launcher, a different Activity might be responsible for the app
609 // market intent, so refresh the icon
610 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800611 }
612
613 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700614 protected void onPause() {
615 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700616 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800617 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700618 }
Romain Guycbb89e42009-06-08 15:52:54 -0700619
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700620 @Override
621 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400622 // Flag the loader to stop early before switching
623 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700624 if (mAppsCustomizeContent != null) {
625 mAppsCustomizeContent.surrender();
626 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800627 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700628 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700629
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800630 // We can't hide the IME if it was forced open. So don't bother
631 /*
632 @Override
633 public void onWindowFocusChanged(boolean hasFocus) {
634 super.onWindowFocusChanged(hasFocus);
635
636 if (hasFocus) {
637 final InputMethodManager inputManager = (InputMethodManager)
638 getSystemService(Context.INPUT_METHOD_SERVICE);
639 WindowManager.LayoutParams lp = getWindow().getAttributes();
640 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
641 android.os.Handler()) {
642 protected void onReceiveResult(int resultCode, Bundle resultData) {
643 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
644 }
645 });
646 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
647 }
648 }
649 */
650
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800651 private boolean acceptFilter() {
652 final InputMethodManager inputManager = (InputMethodManager)
653 getSystemService(Context.INPUT_METHOD_SERVICE);
654 return !inputManager.isFullscreenMode();
655 }
656
657 @Override
658 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700659 final int uniChar = event.getUnicodeChar();
660 final boolean handled = super.onKeyDown(keyCode, event);
661 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
662 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800663 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
664 keyCode, event);
665 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700666 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700667 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700668 // showSearchDialog()
669 // If there are multiple keystrokes before the search dialog takes focus,
670 // onSearchRequested() will be called for every keystroke,
671 // but it is idempotent, so it's fine.
672 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 }
674 }
675
Joe Onorato8a9625e2010-01-28 15:55:35 -0800676 // Eat the long press event so the keyboard doesn't come up.
677 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
678 return true;
679 }
680
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800681 return handled;
682 }
683
Karl Rosaen138a0412009-04-23 19:00:21 -0700684 private String getTypedText() {
685 return mDefaultKeySsb.toString();
686 }
687
688 private void clearTypedText() {
689 mDefaultKeySsb.clear();
690 mDefaultKeySsb.clearSpans();
691 Selection.setSelection(mDefaultKeySsb, 0);
692 }
693
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800694 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700695 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
696 * State
697 */
698 private static State intToState(int stateOrdinal) {
699 State state = State.WORKSPACE;
700 final State[] stateValues = State.values();
701 for (int i = 0; i < stateValues.length; i++) {
702 if (stateValues[i].ordinal() == stateOrdinal) {
703 state = stateValues[i];
704 break;
705 }
706 }
707 return state;
708 }
709
710 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800711 * Restores the previous state, if it exists.
712 *
713 * @param savedState The previous state.
714 */
715 private void restoreState(Bundle savedState) {
716 if (savedState == null) {
717 return;
718 }
719
Michael Jurka883f55b2010-10-21 15:47:14 -0700720 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700721 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800722 showAllApps(false);
723 }
724
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800725 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
726 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700727 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800728 }
729
Winson Chung3d503fb2011-07-13 17:25:49 -0700730 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
731 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700732
Winson Chung3d503fb2011-07-13 17:25:49 -0700733 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
734 mPendingAddInfo.container = pendingAddContainer;
735 mPendingAddInfo.screen = pendingAddScreen;
736 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
737 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800738 mRestoring = true;
739 }
740
741 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
742 if (renameFolder) {
743 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700744 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800745 mRestoring = true;
746 }
Winson Chunga12a2502010-12-20 14:41:35 -0800747
Winson Chung785d2eb2011-04-14 16:08:02 -0700748
749 // Restore the AppsCustomize tab
750 if (mAppsCustomizeTabHost != null) {
751 String curTab = savedState.getString("apps_customize_currentTab");
752 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700753 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700754 mAppsCustomizeContent.setContentType(
755 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
756 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700757 mAppsCustomizeContent.loadAssociatedPages(
758 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700759 }
760
Winson Chung5afbf7b2011-07-25 11:53:08 -0700761 int currentIndex = savedState.getInt("apps_customize_currentIndex");
762 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700763 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800764 }
765
766 /**
767 * Finds all the views we need and configure them properly.
768 */
769 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700770 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400771
Winson Chung4c98d922011-05-31 16:50:48 -0700772 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
773 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800774 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
775 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800776
Winson Chung4c98d922011-05-31 16:50:48 -0700777 // Setup the drag layer
778 mDragLayer.setup(this, dragController);
779
Winson Chung3d503fb2011-07-13 17:25:49 -0700780 // Setup the hotseat
781 mHotseat = (Hotseat) findViewById(R.id.hotseat);
782 if (mHotseat != null) {
783 mHotseat.setup(this);
784 }
785
Winson Chung4c98d922011-05-31 16:50:48 -0700786 // Setup the workspace
787 mWorkspace.setHapticFeedbackEnabled(false);
788 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700789 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700790 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700791
Winson Chungf0ea4d32011-06-06 14:27:16 -0700792 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700793 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700794
Winson Chungf0ea4d32011-06-06 14:27:16 -0700795 // Setup AppsCustomize
796 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
797 findViewById(R.id.apps_customize_pane);
798 mAppsCustomizeContent = (AppsCustomizePagedView)
799 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
800 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400801
Michael Jurka5130e402011-10-13 04:55:35 -0700802 // Get the all apps button
803 mAllAppsButton = findViewById(R.id.all_apps_button);
804 if (mAllAppsButton != null) {
805 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
806 @Override
807 public boolean onTouch(View v, MotionEvent event) {
808 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
809 onTouchDownAllAppsButton(v);
810 }
811 return false;
812 }
813 });
814 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700815 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700816 dragController.setDragScoller(mWorkspace);
817 dragController.setScrollView(mDragLayer);
818 dragController.setMoveTarget(mWorkspace);
819 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700820 if (mSearchDropTargetBar != null) {
821 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800822 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800823 }
824
825 /**
826 * Creates a view representing a shortcut.
827 *
828 * @param info The data structure describing the shortcut.
829 *
830 * @return A View inflated from R.layout.application.
831 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800832 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800833 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700834 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800835 }
836
837 /**
838 * Creates a view representing a shortcut inflated from the specified resource.
839 *
840 * @param layoutResId The id of the XML layout used to create the shortcut.
841 * @param parent The group the shortcut belongs to.
842 * @param info The data structure describing the shortcut.
843 *
844 * @return A View inflated from layoutResId.
845 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800846 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800847 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
848 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800849 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800850 return favorite;
851 }
852
853 /**
854 * Add an application shortcut to the workspace.
855 *
856 * @param data The intent describing the application.
857 * @param cellInfo The position on screen where to create the shortcut.
858 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700859 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700860 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700861 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700862
Adam Cohenfbba09b2011-07-18 21:43:05 -0700863 // First we check if we already know the exact location where we want to add this item.
864 if (cellX >= 0 && cellY >= 0) {
865 cellXY[0] = cellX;
866 cellXY[1] = cellY;
867 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700868 showOutOfSpaceMessage();
869 return;
870 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800871
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800872 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800873
Romain Guy73b979d2009-06-09 12:57:21 -0700874 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800875 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800876 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800877 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700878 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700879 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800880 } else {
881 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800882 }
883 }
Romain Guycbb89e42009-06-08 15:52:54 -0700884
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800885 /**
886 * Add a shortcut to the workspace.
887 *
888 * @param data The intent describing the shortcut.
889 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800890 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700891 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
892 int cellY) {
893 int[] cellXY = mTmpAddItemCellCoordinates;
894 int[] touchXY = mPendingAddInfo.dropPos;
895 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -0700896
Michael Jurkad3ef3062010-11-23 16:23:58 -0800897 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700898
Adam Cohen558baaf2011-08-15 15:22:57 -0700899 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -0800900 if (info == null) {
901 return;
902 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700903 final View view = createShortcut(info);
904
Adam Cohenfbba09b2011-07-18 21:43:05 -0700905 // First we check if we already know the exact location where we want to add this item.
906 if (cellX >= 0 && cellY >= 0) {
907 cellXY[0] = cellX;
908 cellXY[1] = cellY;
909 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -0700910
911 // If appropriate, either create a folder or add to an existing folder
912 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY,
913 true, null,null)) {
914 return;
915 }
916 DragObject dragObject = new DragObject();
917 dragObject.dragInfo = info;
918 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, dragObject, true)) {
919 return;
920 }
Adam Cohenfbba09b2011-07-18 21:43:05 -0700921 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800922 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700923 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800924 foundCellSpan = (result != null);
925 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700926 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800927 }
928
929 if (!foundCellSpan) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700930 showOutOfSpaceMessage();
931 return;
932 }
933
Adam Cohen558baaf2011-08-15 15:22:57 -0700934 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800935
936 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -0700937 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
938 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800939 }
940 }
941
Adam Cohenf814aa02011-09-01 13:48:05 -0700942 int[] getSpanForWidget(ComponentName component, int minWidth, int minHeight, int[] spanXY) {
943 if (spanXY == null) {
944 spanXY = new int[2];
945 }
946
Adam Cohen0cf2a7c2011-11-08 15:07:01 -0800947 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(this, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -0700948 // We want to account for the extra amount of padding that we are adding to the widget
949 // to ensure that it gets the full amount of space that it has requested
950 int requiredWidth = minWidth + padding.left + padding.right;
951 int requiredHeight = minHeight + padding.top + padding.bottom;
952 return CellLayout.rectToCell(getResources(), requiredWidth, requiredHeight, null);
953 }
954
955 int[] getSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
956 return getSpanForWidget(info.provider, info.minWidth, info.minHeight, spanXY);
957 }
958
Adam Cohencbf47e32011-09-16 17:32:37 -0700959 int[] getMinResizeSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
960 return getSpanForWidget(info.provider, info.minResizeWidth, info.minResizeHeight, spanXY);
961 }
962
Adam Cohenf814aa02011-09-01 13:48:05 -0700963 int[] getSpanForWidget(PendingAddWidgetInfo info, int[] spanXY) {
964 return getSpanForWidget(info.componentName, info.minWidth, info.minHeight, spanXY);
965 }
966
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800967 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700968 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800969 *
Romain Guy5bbc91b2010-08-18 11:38:46 -0700970 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700971 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800972 */
Adam Cohened66b2b2012-01-23 17:28:51 -0800973 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
974 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
975 if (appWidgetInfo == null) {
976 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
977 }
Romain Guycbb89e42009-06-08 15:52:54 -0700978
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700979 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -0700980 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -0700981
Adam Cohenf814aa02011-09-01 13:48:05 -0700982 int[] spanXY = getSpanForWidget(appWidgetInfo, null);
Romain Guycbb89e42009-06-08 15:52:54 -0700983
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800984 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -0700985 // We have saved the position to which the widget was dragged-- this really only matters
986 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -0700987 int[] cellXY = mTmpAddItemCellCoordinates;
988 int[] touchXY = mPendingAddInfo.dropPos;
Michael Jurka0280c3b2010-09-17 15:00:07 -0700989 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -0700990 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
991 cellXY[0] = mPendingAddInfo.cellX;
992 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700993 foundCellSpan = true;
994 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700995 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700996 int[] result = layout.findNearestVacantArea(
Michael Jurka0280c3b2010-09-17 15:00:07 -0700997 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800998 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700999 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001000 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001001 }
1002
Michael Jurka0280c3b2010-09-17 15:00:07 -07001003 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001004 if (appWidgetId != -1) {
1005 // Deleting an app widget ID is a void call but writes to disk before returning
1006 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001007 new Thread("deleteAppWidgetId") {
1008 public void run() {
1009 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1010 }
1011 }.start();
1012 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001013 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001014 return;
1015 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001016
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001017 // Build Launcher-specific widget info and save to database
Michael Jurkac9d95c52011-08-29 14:03:34 -07001018 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001019 launcherInfo.spanX = spanXY[0];
1020 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001021
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001022 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001023 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001024
1025 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001026 if (hostView == null) {
1027 // Perform actual inflation because we're live
1028 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1029 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1030 } else {
1031 // The AppWidgetHostView has already been inflated and instantiated
1032 launcherInfo.hostView = hostView;
1033 }
Romain Guycbb89e42009-06-08 15:52:54 -07001034
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001035 launcherInfo.hostView.setTag(launcherInfo);
Winson Chung3d503fb2011-07-13 17:25:49 -07001036 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001037 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001038
1039 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001040 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001041 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001042 }
Romain Guycbb89e42009-06-08 15:52:54 -07001043
Adam Cohended9f8d2010-11-03 13:25:16 -07001044 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1045 @Override
1046 public void onReceive(Context context, Intent intent) {
1047 final String action = intent.getAction();
1048 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1049 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001050 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001051 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001052
Winson Chungc100e8e2011-08-09 16:02:43 -07001053 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001054 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001055 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1056 mAppsCustomizeTabHost.reset();
1057 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001058 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001059 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1060 mUserPresent = true;
1061 updateRunning();
1062 }
1063 }
1064 };
1065
1066 @Override
1067 public void onAttachedToWindow() {
1068 super.onAttachedToWindow();
1069
1070 // Listen for broadcasts related to user-presence
1071 final IntentFilter filter = new IntentFilter();
1072 filter.addAction(Intent.ACTION_SCREEN_OFF);
1073 filter.addAction(Intent.ACTION_USER_PRESENT);
1074 registerReceiver(mReceiver, filter);
1075
Adam Cohend113e0c2010-11-11 10:48:05 -08001076 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001077 mVisible = true;
1078 }
1079
1080 @Override
1081 public void onDetachedFromWindow() {
1082 super.onDetachedFromWindow();
1083 mVisible = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001084 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001085
Adam Cohend113e0c2010-11-11 10:48:05 -08001086 if (mAttached) {
1087 unregisterReceiver(mReceiver);
1088 mAttached = false;
1089 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001090 updateRunning();
1091 }
1092
1093 public void onWindowVisibilityChanged(int visibility) {
1094 mVisible = visibility == View.VISIBLE;
1095 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001096 // The following code used to be in onResume, but it turns out onResume is called when
1097 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1098 // is a more appropriate event to handle
1099 if (mVisible) {
1100 mAppsCustomizeTabHost.onWindowVisible();
1101 if (!mWorkspaceLoading) {
1102 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001103 // We want to let Launcher draw itself at least once before we force it to build
1104 // layers on all the workspace pages, so that transitioning to Launcher from other
1105 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
1106 // a true draw so we wait until the second preDraw call to be safe
1107 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
1108 boolean mFirstTime = true;
1109 public boolean onPreDraw() {
1110 if (mFirstTime) {
1111 mFirstTime = false;
1112 } else {
1113 //workspace.post(mBuildLayersRunnable);
1114 observer.removeOnPreDrawListener(this);
1115 }
1116 return true;
1117 }
1118 });
1119 }
1120 clearTypedText();
1121 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001122 }
1123
1124 private void sendAdvanceMessage(long delay) {
1125 mHandler.removeMessages(ADVANCE_MSG);
1126 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1127 mHandler.sendMessageDelayed(msg, delay);
1128 mAutoAdvanceSentTime = System.currentTimeMillis();
1129 }
1130
1131 private void updateRunning() {
1132 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1133 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1134 mAutoAdvanceRunning = autoAdvanceRunning;
1135 if (autoAdvanceRunning) {
1136 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1137 sendAdvanceMessage(delay);
1138 } else {
1139 if (!mWidgetsToAdvance.isEmpty()) {
1140 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1141 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1142 }
1143 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001144 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001145 }
1146 }
1147 }
1148
1149 private final Handler mHandler = new Handler() {
1150 @Override
1151 public void handleMessage(Message msg) {
1152 if (msg.what == ADVANCE_MSG) {
1153 int i = 0;
1154 for (View key: mWidgetsToAdvance.keySet()) {
1155 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1156 final int delay = mAdvanceStagger * i;
1157 if (v instanceof Advanceable) {
1158 postDelayed(new Runnable() {
1159 public void run() {
1160 ((Advanceable) v).advance();
1161 }
1162 }, delay);
1163 }
1164 i++;
1165 }
1166 sendAdvanceMessage(mAdvanceInterval);
1167 }
1168 }
1169 };
1170
1171 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001172 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001173 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1174 if (v instanceof Advanceable) {
1175 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001176 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001177 updateRunning();
1178 }
1179 }
1180
1181 void removeWidgetToAutoAdvance(View hostView) {
1182 if (mWidgetsToAdvance.containsKey(hostView)) {
1183 mWidgetsToAdvance.remove(hostView);
1184 updateRunning();
1185 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001186 }
1187
Joe Onorato9c1289c2009-08-17 11:03:03 -04001188 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001189 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001190 launcherInfo.hostView = null;
1191 }
1192
Adam Cohended9f8d2010-11-03 13:25:16 -07001193 void showOutOfSpaceMessage() {
1194 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1195 }
1196
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001197 public LauncherAppWidgetHost getAppWidgetHost() {
1198 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001199 }
Romain Guycbb89e42009-06-08 15:52:54 -07001200
Winson Chunga9abd0e2010-10-27 17:18:37 -07001201 public LauncherModel getModel() {
1202 return mModel;
1203 }
1204
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001205 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001206 getWindow().closeAllPanels();
1207
Winson Chung87acb482011-08-23 17:28:05 -07001208 /**
1209 * We should remove this code when we remove all the dialog code.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001210 try {
1211 dismissDialog(DIALOG_CREATE_SHORTCUT);
1212 // Unlock the workspace if the dialog was showing
1213 } catch (Exception e) {
1214 // An exception is thrown if the dialog is not visible, which is fine
1215 }
1216
1217 try {
1218 dismissDialog(DIALOG_RENAME_FOLDER);
1219 // Unlock the workspace if the dialog was showing
1220 } catch (Exception e) {
1221 // An exception is thrown if the dialog is not visible, which is fine
1222 }
Winson Chung87acb482011-08-23 17:28:05 -07001223 */
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001224
1225 // Whatever we were doing is hereby canceled.
1226 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001227 }
1228
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229 @Override
1230 protected void onNewIntent(Intent intent) {
1231 super.onNewIntent(intent);
1232
1233 // Close the menu
1234 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001235 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001236 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001237
Joe Onorato14f122b2009-11-19 14:06:36 -08001238 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1239 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001240
Adam Cohenac56cff2011-09-28 20:45:37 -07001241 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001242 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001243 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001244 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1245 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001246 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001247 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001248
1249 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001250 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001251 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001252
Joe Onorato3a8820b2009-11-10 15:06:42 -08001253 final View v = getWindow().peekDecorView();
1254 if (v != null && v.getWindowToken() != null) {
1255 InputMethodManager imm = (InputMethodManager)getSystemService(
1256 INPUT_METHOD_SERVICE);
1257 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001258 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001259
Michael Jurka35aa14d2011-07-07 17:01:08 -07001260 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001261 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001262 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001263 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001264 }
1265 }
1266
1267 @Override
1268 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1269 // Do not call super here
1270 mSavedInstanceState = savedInstanceState;
1271 }
1272
1273 @Override
1274 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001275 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001276 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001277
Michael Jurka883f55b2010-10-21 15:47:14 -07001278 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001279 // We close any open folder since it will not be re-opened, and we need to make sure
1280 // this state is reflected.
1281 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001282
Winson Chung3d503fb2011-07-13 17:25:49 -07001283 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1284 mWaitingForResult) {
1285 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1286 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1287 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1288 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001289 }
1290
1291 if (mFolderInfo != null && mWaitingForResult) {
1292 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1293 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1294 }
Michael Jurka946ad472010-07-09 18:05:18 -07001295
Winson Chung785d2eb2011-04-14 16:08:02 -07001296 // Save the current AppsCustomize tab
1297 if (mAppsCustomizeTabHost != null) {
1298 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1299 if (currentTabTag != null) {
1300 outState.putString("apps_customize_currentTab", currentTabTag);
1301 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001302 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1303 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001304 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001305 }
1306
1307 @Override
1308 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001309 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001310
Winson Chunge7a03942011-08-05 15:05:12 -07001311 // Remove all pending runnables
1312 mHandler.removeMessages(ADVANCE_MSG);
1313 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001314 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001315
Winson Chungcd2b0142011-06-08 16:02:26 -07001316 // Stop callbacks from LauncherModel
1317 LauncherApplication app = ((LauncherApplication) getApplication());
1318 mModel.stopLoader();
1319 app.setLauncher(null);
1320
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001321 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001322 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001323 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001324 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001325 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001326 mAppWidgetHost = null;
1327
1328 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001329
1330 TextKeyListener.getInstance().release();
1331
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001332
Winson Chung3d503fb2011-07-13 17:25:49 -07001333 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001334
1335 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001336 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001337
1338 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1339 mWorkspace.removeAllViews();
1340 mWorkspace = null;
1341 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001342
1343 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001344 }
1345
Adam Cohena9cf38f2011-05-02 15:36:58 -07001346 public DragController getDragController() {
1347 return mDragController;
1348 }
1349
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001350 @Override
1351 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001352 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001353 super.startActivityForResult(intent, requestCode);
1354 }
1355
Winson Chung70d72102011-08-12 11:24:35 -07001356 /**
1357 * Indicates that we want global search for this activity by setting the globalSearch
1358 * argument for {@link #startSearch} to true.
1359 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001360 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001361 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001362 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001363
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001364 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001365
Karl Rosaen138a0412009-04-23 19:00:21 -07001366 if (initialQuery == null) {
1367 // Use any text typed in the launcher as the initial query
1368 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001369 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001370 if (appSearchData == null) {
1371 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001372 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001373 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001374 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001375
Karl Rosaen138a0412009-04-23 19:00:21 -07001376 final SearchManager searchManager =
1377 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001378 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001379 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001380 }
1381
Winson Chung70d72102011-08-12 11:24:35 -07001382 @Override
1383 public boolean onCreateOptionsMenu(Menu menu) {
1384 if (isWorkspaceLocked()) {
1385 return false;
1386 }
1387
1388 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001389
1390 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1391 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1392 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001393 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1394 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1395 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001396 String helpUrl = getString(R.string.help_url);
1397 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001398 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1399 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1400
Winson Chung70d72102011-08-12 11:24:35 -07001401 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1402 .setIcon(android.R.drawable.ic_menu_gallery)
1403 .setAlphabeticShortcut('W');
1404 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1405 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001406 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001407 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001408 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1409 .setIcon(android.R.drawable.ic_menu_preferences)
1410 .setIntent(settings)
1411 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001412 if (!helpUrl.isEmpty()) {
1413 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1414 .setIcon(android.R.drawable.ic_menu_help)
1415 .setIntent(help)
1416 .setAlphabeticShortcut('H');
1417 }
Winson Chung70d72102011-08-12 11:24:35 -07001418 return true;
1419 }
1420
1421 @Override
1422 public boolean onPrepareOptionsMenu(Menu menu) {
1423 super.onPrepareOptionsMenu(menu);
1424
1425 if (mAppsCustomizeTabHost.isTransitioning()) {
1426 return false;
1427 }
1428 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1429 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1430
1431 return true;
1432 }
1433
1434 @Override
1435 public boolean onOptionsItemSelected(MenuItem item) {
1436 switch (item.getItemId()) {
1437 case MENU_WALLPAPER_SETTINGS:
1438 startWallpaper();
1439 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001440 }
1441
1442 return super.onOptionsItemSelected(item);
1443 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001444
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001445 @Override
1446 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001447 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001448 // Use a custom animation for launching search
1449 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001450 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001451 }
1452
Joe Onorato9c1289c2009-08-17 11:03:03 -04001453 public boolean isWorkspaceLocked() {
1454 return mWorkspaceLoading || mWaitingForResult;
1455 }
1456
Michael Jurka0280c3b2010-09-17 15:00:07 -07001457 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001458 mPendingAddInfo.container = ItemInfo.NO_ID;
1459 mPendingAddInfo.screen = -1;
1460 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1461 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
1462 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001463 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001464
Michael Jurkaaf442092010-06-10 17:01:57 -07001465 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001466 // TODO: catch bad widget exception when sent
1467 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001468 // TODO: Is this log message meaningful?
1469 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001470 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001471 }
1472
Adam Cohened66b2b2012-01-23 17:28:51 -08001473 void addAppWidgetImpl(final int appWidgetId, final PendingAddWidgetInfo info) {
1474 final AppWidgetProviderInfo appWidget = info.info;
1475 Runnable configurationActivity = null;
Bjorn Bringert7984c942009-12-09 15:38:25 +00001476 if (appWidget.configure != null) {
1477 // Launch over to configure widget, if needed
1478 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1479 intent.setComponent(appWidget.configure);
1480 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001481 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001482 if (info.mimeType != null && !info.mimeType.isEmpty()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001483 intent.putExtra(InstallWidgetReceiver.
1484 EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE, info.mimeType);
Winson Chung68846fd2010-10-29 11:00:27 -07001485
1486 final String mimeType = info.mimeType;
1487 final ClipData clipData = (ClipData) info.configurationData;
1488 final ClipDescription clipDesc = clipData.getDescription();
1489 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1490 if (clipDesc.getMimeType(i).equals(mimeType)) {
Dianne Hackborn0d5aad72011-01-17 15:28:58 -08001491 final ClipData.Item item = clipData.getItemAt(i);
Winson Chung68846fd2010-10-29 11:00:27 -07001492 final CharSequence stringData = item.getText();
1493 final Uri uriData = item.getUri();
1494 final Intent intentData = item.getIntent();
Adam Cohened66b2b2012-01-23 17:28:51 -08001495 final String key = InstallWidgetReceiver.
1496 EXTRA_APPWIDGET_CONFIGURATION_DATA;
Winson Chung68846fd2010-10-29 11:00:27 -07001497 if (uriData != null) {
1498 intent.putExtra(key, uriData);
1499 } else if (intentData != null) {
1500 intent.putExtra(key, intentData);
1501 } else if (stringData != null) {
1502 intent.putExtra(key, stringData);
1503 }
1504 break;
1505 }
1506 }
1507 }
Winson Chung55cef262010-10-28 14:14:18 -07001508 }
Romain Guy8e633c52010-03-04 12:51:36 -08001509 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
Adam Cohened66b2b2012-01-23 17:28:51 -08001510 mWidgetBeingConfigured = info;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001511 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001512 // Otherwise just add it
Adam Cohened66b2b2012-01-23 17:28:51 -08001513 completeAddAppWidget(appWidgetId, info.container, info.screen, info.boundWidget, appWidget);
Winson Chung557d6ed2011-07-08 15:34:52 -07001514 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001515 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001516 }
1517 }
Romain Guycbb89e42009-06-08 15:52:54 -07001518
Adam Cohenfbba09b2011-07-18 21:43:05 -07001519 /**
1520 * Process a shortcut drop.
1521 *
1522 * @param componentName The name of the component
1523 * @param screen The screen where it should be added
1524 * @param cell The cell it should be added to, optional
1525 * @param position The location on the screen where it was dropped, optional
1526 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001527 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1528 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001529 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001530 mPendingAddInfo.container = container;
1531 mPendingAddInfo.screen = screen;
1532 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001533
1534 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001535 mPendingAddInfo.cellX = cell[0];
1536 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001537 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001538
1539 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1540 createShortcutIntent.setComponent(componentName);
1541 processShortcut(createShortcutIntent);
1542 }
1543
Adam Cohenfbba09b2011-07-18 21:43:05 -07001544 /**
1545 * Process a widget drop.
1546 *
1547 * @param info The PendingAppWidgetInfo of the widget being added.
1548 * @param screen The screen where it should be added
1549 * @param cell The cell it should be added to, optional
1550 * @param position The location on the screen where it was dropped, optional
1551 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001552 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
1553 int[] cell, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001554 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001555 mPendingAddInfo.container = info.container = container;
1556 mPendingAddInfo.screen = info.screen = screen;
1557 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001558 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001559 mPendingAddInfo.cellX = cell[0];
1560 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001561 }
1562
Adam Cohened66b2b2012-01-23 17:28:51 -08001563 AppWidgetHostView hostView = info.boundWidget;
1564 int appWidgetId;
1565 if (hostView != null) {
1566 appWidgetId = hostView.getAppWidgetId();
1567 } else {
1568 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1569 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1570 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001571 addAppWidgetImpl(appWidgetId, info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001572
Adam Cohenfbba09b2011-07-18 21:43:05 -07001573 }
1574
Joe Onoratodeb98af2010-02-19 14:59:39 -08001575 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001576 // Handle case where user selected "Applications"
1577 String applicationName = getResources().getString(R.string.group_applications);
1578 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001579
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001580 if (applicationName != null && applicationName.equals(shortcutName)) {
1581 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1582 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001583
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001584 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1585 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001586 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001587 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001588 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001589 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001590 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001591 }
1592
Winson Chung24ab2f12010-09-16 14:10:47 -07001593 void processWallpaper(Intent intent) {
1594 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1595 }
1596
Winson Chung3d503fb2011-07-13 17:25:49 -07001597 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1598 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001599 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001600 folderInfo.title = getText(R.string.folder_name);
1601
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001602 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001603 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1604 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001605 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001606
1607 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001608 FolderIcon newFolder =
1609 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1610 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1611 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001612 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001613 }
Romain Guycbb89e42009-06-08 15:52:54 -07001614
Joe Onorato9c1289c2009-08-17 11:03:03 -04001615 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001616 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001617 }
1618
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001619 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001620 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001621 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001622 Intent chooser = Intent.createChooser(pickWallpaper,
1623 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001624 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1625 // Removed in Eclair MR1
1626// WallpaperManager wm = (WallpaperManager)
1627// getSystemService(Context.WALLPAPER_SERVICE);
1628// WallpaperInfo wi = wm.getWallpaperInfo();
1629// if (wi != null && wi.getSettingsActivity() != null) {
1630// LabeledIntent li = new LabeledIntent(getPackageName(),
1631// R.string.configure_wallpaper, 0);
1632// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1633// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1634// }
Mike Clerona0618e42009-10-22 13:55:21 -07001635 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001636 }
1637
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001638 /**
1639 * Registers various content observers. The current implementation registers
1640 * only a favorites observer to keep track of the favorites applications.
1641 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001642 private void registerContentObservers() {
1643 ContentResolver resolver = getContentResolver();
1644 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1645 true, mWidgetObserver);
1646 }
1647
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001648 @Override
1649 public boolean dispatchKeyEvent(KeyEvent event) {
1650 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1651 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001652 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001653 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001654 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001655 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001656 dumpState();
1657 return true;
1658 }
1659 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001660 }
1661 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1662 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001663 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001664 return true;
1665 }
1666 }
1667
1668 return super.dispatchKeyEvent(event);
1669 }
1670
Joe Onorato88ec0992009-11-19 13:16:06 -08001671 @Override
1672 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001673 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001674 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001675 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001676 Folder openFolder = mWorkspace.getOpenFolder();
1677 if (openFolder.isEditingName()) {
1678 openFolder.dismissEditingName();
1679 } else {
1680 closeFolder();
1681 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001682 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001683 mWorkspace.exitWidgetResizeMode();
1684
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001685 // Back button is a no-op here, but give at least some feedback for the button press
1686 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001687 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001688 }
1689
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001690 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001691 * Re-listen when widgets are reset.
1692 */
1693 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001694 if (mAppWidgetHost != null) {
1695 mAppWidgetHost.startListening();
1696 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001697 }
1698
1699 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001700 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1701 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001702 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001703 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001704 if (mModel != null) {
1705 mModel.unbindWorkspaceItems();
1706 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001707 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001708
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001709 /**
1710 * Launches the intent referred by the clicked shortcut.
1711 *
1712 * @param v The view representing the clicked shortcut.
1713 */
1714 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001715 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1716 // view has detached (it's possible for this to happen if the view is removed mid touch).
1717 if (v.getWindowToken() == null) {
1718 return;
1719 }
1720
1721 if (mWorkspace.isSwitchingState()) {
1722 return;
1723 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001724
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001725 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001726 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001727 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001728 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001729 int[] pos = new int[2];
1730 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001731 intent.setSourceBounds(new Rect(pos[0], pos[1],
1732 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Michael Jurkaddd62e92011-02-16 17:49:14 -08001733 boolean success = startActivitySafely(intent, tag);
1734
1735 if (success && v instanceof BubbleTextView) {
1736 mWaitingForResume = (BubbleTextView) v;
1737 mWaitingForResume.setStayPressed(true);
1738 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001739 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001740 if (v instanceof FolderIcon) {
1741 FolderIcon fi = (FolderIcon) v;
1742 handleFolderClick(fi);
1743 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001744 } else if (v == mAllAppsButton) {
1745 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001746 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001747 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001748 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001749 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001750 }
1751 }
1752
Michael Jurka0e260592010-06-30 17:07:39 -07001753 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001754 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001755 // clicking anywhere on the workspace causes the customization drawer to slide down
1756 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001757 return false;
1758 }
1759
Michael Jurkaaf442092010-06-10 17:01:57 -07001760 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001761 * Event handler for the search button
1762 *
1763 * @param v The view that was clicked.
1764 */
1765 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001766 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1767
Amith Yamasania135ba82011-08-09 17:42:01 -07001768 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001769 }
1770
1771 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001772 * Event handler for the voice button
1773 *
1774 * @param v The view that was clicked.
1775 */
1776 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001777 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001778
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001779 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001780 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001781 startActivity(intent);
1782 }
1783
1784 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001785 * Event handler for the "grid" button that appears on the home screen, which
1786 * enters all apps mode.
1787 *
1788 * @param v The view that was clicked.
1789 */
1790 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001791 showAllApps(true);
1792 }
1793
1794 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001795 // Provide the same haptic feedback that the system offers for virtual keys.
1796 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001797 }
1798
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001799 public void onClickAppMarketButton(View v) {
1800 if (mAppMarketIntent != null) {
1801 startActivitySafely(mAppMarketIntent, "app market");
1802 }
1803 }
1804
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001805 void startApplicationDetailsActivity(ComponentName componentName) {
1806 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001807 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1808 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001809 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001810 startActivity(intent);
1811 }
1812
Patrick Dubroy5539af72010-09-07 15:22:01 -07001813 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1814 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1815 // System applications cannot be installed. For now, show a toast explaining that.
1816 // We may give them the option of disabling apps this way.
1817 int messageId = R.string.uninstall_system_app_text;
1818 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1819 } else {
1820 String packageName = appInfo.componentName.getPackageName();
1821 String className = appInfo.componentName.getClassName();
1822 Intent intent = new Intent(
1823 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001824 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1825 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001826 startActivity(intent);
1827 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001828 }
1829
Michael Jurkaddd62e92011-02-16 17:49:14 -08001830 boolean startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001831 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1832 try {
1833 startActivity(intent);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001834 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001835 } catch (ActivityNotFoundException e) {
1836 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001837 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001838 } catch (SecurityException e) {
1839 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001840 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001841 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001842 "or use the exported attribute for this activity. "
1843 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001844 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001845 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001846 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001847
Romain Guy8e633c52010-03-04 12:51:36 -08001848 void startActivityForResultSafely(Intent intent, int requestCode) {
1849 try {
1850 startActivityForResult(intent, requestCode);
1851 } catch (ActivityNotFoundException e) {
1852 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1853 } catch (SecurityException e) {
1854 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1855 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1856 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1857 "or use the exported attribute for this activity.", e);
1858 }
1859 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001860
Adam Cohena9cf38f2011-05-02 15:36:58 -07001861 private void handleFolderClick(FolderIcon folderIcon) {
1862 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07001863 Folder openFolder = mWorkspace.getFolderForTag(info);
1864
1865 // If the folder info reports that the associated folder is open, then verify that
1866 // it is actually opened. There have been a few instances where this gets out of sync.
1867 if (info.opened && openFolder == null) {
1868 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
1869 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
1870 info.opened = false;
1871 }
1872
Adam Cohena9cf38f2011-05-02 15:36:58 -07001873 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001874 // Close any open folder
1875 closeFolder();
1876 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07001877 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001878 } else {
1879 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001880 int folderScreen;
1881 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001882 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001883 // .. and close it
1884 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001885 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001886 // Close any folder open on the current screen
1887 closeFolder();
1888 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07001889 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001890 }
1891 }
1892 }
1893 }
1894
Adam Cohen2801caf2011-05-13 20:57:39 -07001895 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001896 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001897 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
1898 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
1899 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
1900
Adam Cohenc51934b2011-07-26 21:07:43 -07001901 FolderInfo info = (FolderInfo) fi.getTag();
1902 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1903 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07001904 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
1905 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07001906 }
1907
Adam Cohen2801caf2011-05-13 20:57:39 -07001908 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1909 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1910 oa.start();
1911 }
1912
1913 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001914 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001915 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1916 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1917 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1918
Adam Cohenc51934b2011-07-26 21:07:43 -07001919 FolderInfo info = (FolderInfo) fi.getTag();
1920 CellLayout cl = null;
1921 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1922 cl = (CellLayout) fi.getParent().getParent();
1923 }
1924
1925 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07001926 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1927 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07001928 oa.addListener(new AnimatorListenerAdapter() {
1929 @Override
1930 public void onAnimationEnd(Animator animation) {
1931 if (layout != null) {
1932 layout.clearFolderLeaveBehind();
1933 }
1934 }
1935 });
Adam Cohen2801caf2011-05-13 20:57:39 -07001936 oa.start();
1937 }
1938
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001939 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001940 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001941 * is animated relative to the specified View. If the View is null, no animation
1942 * is played.
1943 *
1944 * @param folderInfo The FolderInfo describing the folder to open.
1945 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001946 public void openFolder(FolderIcon folderIcon) {
1947 Folder folder = folderIcon.mFolder;
1948 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001949
Adam Cohen2801caf2011-05-13 20:57:39 -07001950 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001951 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001952
Adam Cohen4554ee12011-08-03 16:13:21 -07001953 // Just verify that the folder hasn't already been added to the DragLayer.
1954 // There was a one-off crash where the folder had a parent already.
1955 if (folder.getParent() == null) {
1956 mDragLayer.addView(folder);
1957 mDragController.addDropTarget((DropTarget) folder);
1958 } else {
1959 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
1960 folder.getParent() + ").");
1961 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001962 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07001963 }
1964
1965 public void closeFolder() {
1966 Folder folder = mWorkspace.getOpenFolder();
1967 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07001968 if (folder.isEditingName()) {
1969 folder.dismissEditingName();
1970 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001971 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07001972
1973 // Dismiss the folder cling
1974 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07001975 }
1976 }
1977
1978 void closeFolder(Folder folder) {
1979 folder.getInfo().opened = false;
1980
1981 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
1982 if (parent != null) {
1983 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
1984 shrinkAndFadeInFolderIcon(fi);
1985 }
1986 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001987 }
1988
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001989 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08001990 if (mState != State.WORKSPACE) {
1991 return false;
1992 }
1993
Joe Onorato9c1289c2009-08-17 11:03:03 -04001994 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001995 return false;
1996 }
1997
1998 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08001999 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002000 }
2001
Michael Jurka0280c3b2010-09-17 15:00:07 -07002002 resetAddInfo();
2003 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002004 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002005 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002006 return true;
2007 }
2008
Winson Chung3d503fb2011-07-13 17:25:49 -07002009 // The hotseat touch handling does not go through Workspace, and we always allow long press
2010 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002011 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002012 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2013 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002014 if (itemUnderLongClick == null) {
2015 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002016 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2017 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002018 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002019 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002020 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002021 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002022 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002023 }
2024 }
2025 }
2026 return true;
2027 }
2028
Winson Chung3d503fb2011-07-13 17:25:49 -07002029 boolean isHotseatLayout(View layout) {
2030 return mHotseat != null && layout != null &&
2031 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2032 }
2033 Hotseat getHotseat() {
2034 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002035 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002036 SearchDropTargetBar getSearchBar() {
2037 return mSearchDropTargetBar;
2038 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002039
Winson Chung3d503fb2011-07-13 17:25:49 -07002040 /**
2041 * Returns the CellLayout of the specified container at the specified screen.
2042 */
2043 CellLayout getCellLayout(long container, int screen) {
2044 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2045 if (mHotseat != null) {
2046 return mHotseat.getLayout();
2047 } else {
2048 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002049 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002050 } else {
2051 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002052 }
2053 }
2054
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002055 Workspace getWorkspace() {
2056 return mWorkspace;
2057 }
2058
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002059 @Override
2060 protected Dialog onCreateDialog(int id) {
2061 switch (id) {
2062 case DIALOG_CREATE_SHORTCUT:
2063 return new CreateShortcut().createDialog();
2064 case DIALOG_RENAME_FOLDER:
2065 return new RenameFolder().createDialog();
2066 }
2067
2068 return super.onCreateDialog(id);
2069 }
2070
2071 @Override
2072 protected void onPrepareDialog(int id, Dialog dialog) {
2073 switch (id) {
2074 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002075 break;
2076 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002077 if (mFolderInfo != null) {
2078 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2079 final CharSequence text = mFolderInfo.title;
2080 input.setText(text);
2081 input.setSelection(0, text.length());
2082 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002083 break;
2084 }
2085 }
2086
2087 void showRenameDialog(FolderInfo info) {
2088 mFolderInfo = info;
2089 mWaitingForResult = true;
2090 showDialog(DIALOG_RENAME_FOLDER);
2091 }
2092
Adam Cohenfbba09b2011-07-18 21:43:05 -07002093 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002094 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002095 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
2096 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002097 mWaitingForResult = true;
2098 showDialog(DIALOG_CREATE_SHORTCUT);
2099 }
2100
2101 private class RenameFolder {
2102 private EditText mInput;
2103
2104 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002105 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2106 mInput = (EditText) layout.findViewById(R.id.folder_name);
2107
2108 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2109 builder.setIcon(0);
2110 builder.setTitle(getString(R.string.rename_folder_title));
2111 builder.setCancelable(true);
2112 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2113 public void onCancel(DialogInterface dialog) {
2114 cleanup();
2115 }
2116 });
2117 builder.setNegativeButton(getString(R.string.cancel_action),
2118 new Dialog.OnClickListener() {
2119 public void onClick(DialogInterface dialog, int which) {
2120 cleanup();
2121 }
2122 }
2123 );
2124 builder.setPositiveButton(getString(R.string.rename_action),
2125 new Dialog.OnClickListener() {
2126 public void onClick(DialogInterface dialog, int which) {
2127 changeFolderName();
2128 }
2129 }
2130 );
2131 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002132
2133 final AlertDialog dialog = builder.create();
2134 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2135 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002136 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002137 mInput.requestFocus();
2138 InputMethodManager inputManager = (InputMethodManager)
2139 getSystemService(Context.INPUT_METHOD_SERVICE);
2140 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002141 }
2142 });
2143
2144 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002145 }
2146
2147 private void changeFolderName() {
2148 final String name = mInput.getText().toString();
2149 if (!TextUtils.isEmpty(name)) {
2150 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002151 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002152 mFolderInfo.title = name;
2153 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2154
Joe Onorato9c1289c2009-08-17 11:03:03 -04002155 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002156 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002157 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002158 } else {
2159 final FolderIcon folderIcon = (FolderIcon)
2160 mWorkspace.getViewForTag(mFolderInfo);
2161 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002162 // TODO: At some point we'll probably want some version of setting
2163 // the text for a folder icon.
2164 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002165 getWorkspace().requestLayout();
2166 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002167 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002168 mWorkspaceLoading = true;
2169 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002170 }
2171 }
2172 }
2173 cleanup();
2174 }
2175
2176 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002177 dismissDialog(DIALOG_RENAME_FOLDER);
2178 mWaitingForResult = false;
2179 mFolderInfo = null;
2180 }
2181 }
2182
Daniel Sandler843e8602010-06-07 14:59:01 -04002183 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2184 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002185 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002186 }
2187
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002188 // AllAppsView.Watcher
2189 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002190 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002191 mWorkspace.setVisibility(View.GONE);
2192 }
2193 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002194
2195 /**
2196 * Helper method for the cameraZoomIn/cameraZoomOut animations
2197 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002198 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002199 * @param scaleFactor The scale factor used for the zoom
2200 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002201 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002202 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002203 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002204 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002205
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002206 void updateWallpaperVisibility(boolean visible) {
2207 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2208 int curflags = getWindow().getAttributes().flags
2209 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2210 if (wpflags != curflags) {
2211 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2212 }
2213 }
2214
Michael Jurka9433fa72012-01-19 08:50:41 -08002215 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2216 if (v instanceof LauncherTransitionable) {
2217 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2218 }
2219 }
2220
2221 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2222 if (v instanceof LauncherTransitionable) {
2223 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2224 }
2225 }
2226
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002227 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002228 * Things to test when changing the following seven functions.
2229 * - Home from workspace
2230 * - from center screen
2231 * - from other screens
2232 * - Home from all apps
2233 * - from center screen
2234 * - from other screens
2235 * - Back from all apps
2236 * - from center screen
2237 * - from other screens
2238 * - Launch app from workspace and quit
2239 * - with back
2240 * - with home
2241 * - Launch app from all apps and quit
2242 * - with back
2243 * - with home
2244 * - Go to a screen that's not the default, then all
2245 * apps, and launch and app, and go back
2246 * - with back
2247 * -with home
2248 * - On workspace, long press power and go back
2249 * - with back
2250 * - with home
2251 * - On all apps, long press power and go back
2252 * - with back
2253 * - with home
2254 * - On workspace, power off
2255 * - On all apps, power off
2256 * - Launch an app and turn off the screen while in that app
2257 * - Go back with home key
2258 * - Go back with back key TODO: make this not go to workspace
2259 * - From all apps
2260 * - From workspace
2261 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2262 * - From all apps
2263 * - From the center workspace
2264 * - From another workspace
2265 */
2266
2267 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002268 * Zoom the camera out from the workspace to reveal 'toView'.
2269 * Assumes that the view to show is anchored at either the very top or very bottom
2270 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002271 */
Michael Jurka9433fa72012-01-19 08:50:41 -08002272 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002273 if (mStateAnimation != null) {
2274 mStateAnimation.cancel();
2275 mStateAnimation = null;
2276 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002277 final Resources res = getResources();
Winson Chung7d7541e2011-09-16 20:14:36 -07002278 final Launcher instance = this;
Adam Cohenf16e5712011-01-13 13:31:45 -08002279
Winson Chungf0ea4d32011-06-06 14:27:16 -07002280 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2281 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2282 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurka9433fa72012-01-19 08:50:41 -08002283 final View fromView = mWorkspace;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002284 final View toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002285 final int startDelay =
2286 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002287
Michael Jurkab3e22d92011-10-31 15:58:33 -07002288 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002289
Michael Jurkad74c9842011-07-10 12:44:21 -07002290 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002291 Animator workspaceAnim =
2292 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002293
2294 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002295 toView.setScaleX(scale);
2296 toView.setScaleY(scale);
2297 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2298 scaleAnim.
2299 scaleX(1f).scaleY(1f).
2300 setDuration(duration).
2301 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002302
Winson Chungf0ea4d32011-06-06 14:27:16 -07002303 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002304 toView.setAlpha(0f);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002305 final ObjectAnimator alphaAnim = ObjectAnimator
2306 .ofFloat(toView, "alpha", 0f, 1f)
2307 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002308 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Adam Cohenf16e5712011-01-13 13:31:45 -08002309
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002310 // toView should appear right at the end of the workspace shrink
2311 // animation
2312 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002313 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002314 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002315
2316 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002317 boolean animationCancelled = false;
2318
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002319 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002320 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002321 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002322 // Prepare the position
2323 toView.setTranslationX(0.0f);
2324 toView.setTranslationY(0.0f);
2325 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002326 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002327 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002328 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002329 public void onAnimationEnd(Animator animation) {
Michael Jurka9433fa72012-01-19 08:50:41 -08002330 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2331 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002332
2333 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2334 // Hide the workspace scrollbar
2335 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002336 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002337 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002338 if (!animationCancelled) {
2339 updateWallpaperVisibility(false);
2340 }
2341 }
2342
Adam Cohencff6af82011-09-13 14:51:53 -07002343 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002344 public void onAnimationCancel(Animator animation) {
2345 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002346 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002347 });
2348
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002349 if (workspaceAnim != null) {
2350 mStateAnimation.play(workspaceAnim);
2351 }
Michael Jurka1899a362011-11-03 13:50:45 -07002352
2353 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002354 final ViewTreeObserver observer;
2355
Michael Jurka9433fa72012-01-19 08:50:41 -08002356 dispatchOnLauncherTransitionStart(fromView, animated, false);
2357 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002358
2359 // If any of the objects being animated haven't been measured/laid out
2360 // yet, delay the animation until we get a layout pass
Michael Jurka9433fa72012-01-19 08:50:41 -08002361 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002362 (mWorkspace.getMeasuredWidth() == 0) ||
2363 (toView.getMeasuredWidth() == 0)) {
2364 observer = mWorkspace.getViewTreeObserver();
2365 delayAnim = true;
2366 } else {
2367 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002368 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002369
2370 if (delayAnim) {
Michael Jurka49779a12012-01-16 04:10:08 -08002371 final AnimatorSet stateAnimation = mStateAnimation;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002372 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2373 public void onGlobalLayout() {
2374 mWorkspace.post(new Runnable() {
2375 public void run() {
Michael Jurka49779a12012-01-16 04:10:08 -08002376 // Check that mStateAnimation hasn't changed while
2377 // we waited for a layout pass
2378 if (mStateAnimation == stateAnimation) {
2379 // Need to update pivots for zoom if layout changed
2380 setPivotsForZoom(toView, scale);
2381 mStateAnimation.start();
2382 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002383 }
2384 });
2385 observer.removeGlobalOnLayoutListener(this);
2386 }
2387 };
2388 observer.addOnGlobalLayoutListener(delayedStart);
2389 } else {
2390 setPivotsForZoom(toView, scale);
Michael Jurka1899a362011-11-03 13:50:45 -07002391 mStateAnimation.start();
2392 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002393 } else {
2394 toView.setTranslationX(0.0f);
2395 toView.setTranslationY(0.0f);
2396 toView.setScaleX(1.0f);
2397 toView.setScaleY(1.0f);
2398 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002399 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002400
Michael Jurka9433fa72012-01-19 08:50:41 -08002401 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2402 // Hide the workspace scrollbar
2403 mWorkspace.hideScrollingIndicator(true);
2404 hideDockDivider();
Michael Jurkaabded662011-03-04 12:06:57 -08002405 }
Michael Jurka9433fa72012-01-19 08:50:41 -08002406 dispatchOnLauncherTransitionStart(fromView, animated, false);
2407 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2408 dispatchOnLauncherTransitionStart(toView, animated, false);
2409 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002410 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002411 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002412 }
2413
2414 /**
2415 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002416 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002417 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002418 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002419 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2420 final boolean springLoaded, final Runnable onCompleteRunnable) {
2421
Michael Jurkab3e22d92011-10-31 15:58:33 -07002422 if (mStateAnimation != null) {
2423 mStateAnimation.cancel();
2424 mStateAnimation = null;
2425 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002426 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002427
Winson Chungf0ea4d32011-06-06 14:27:16 -07002428 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002429 final int fadeOutDuration =
2430 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002431 final float scaleFactor = (float)
2432 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2433 final View fromView = mAppsCustomizeTabHost;
Michael Jurka9433fa72012-01-19 08:50:41 -08002434 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002435 Animator workspaceAnim = null;
2436
2437 if (toState == State.WORKSPACE) {
2438 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2439 workspaceAnim = mWorkspace.getChangeStateAnimation(
2440 Workspace.State.NORMAL, animated, stagger);
2441 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2442 workspaceAnim = mWorkspace.getChangeStateAnimation(
2443 Workspace.State.SPRING_LOADED, animated);
2444 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002445
Michael Jurkab3e22d92011-10-31 15:58:33 -07002446 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002447 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002448 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002449 if (animated) {
Michael Jurka742574b2011-02-02 23:51:01 -08002450 final float oldScaleX = fromView.getScaleX();
2451 final float oldScaleY = fromView.getScaleY();
2452
Michael Jurka159b4cc2012-01-17 03:00:35 -08002453 final LauncherViewPropertyAnimator scaleAnim =
2454 new LauncherViewPropertyAnimator(fromView);
2455 scaleAnim.
2456 scaleX(scaleFactor).scaleY(scaleFactor).
2457 setDuration(duration).
2458 setInterpolator(new Workspace.ZoomInInterpolator());
2459
2460 final ObjectAnimator alphaAnim = ObjectAnimator
2461 .ofFloat(fromView, "alpha", 1f, 0f)
2462 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002463 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Michael Jurka159b4cc2012-01-17 03:00:35 -08002464
Michael Jurka9433fa72012-01-19 08:50:41 -08002465 mStateAnimation = new AnimatorSet();
2466
2467 dispatchOnLauncherTransitionStart(fromView, animated, true);
2468 dispatchOnLauncherTransitionStart(toView, animated, true);
2469
2470 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002471 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002472 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002473 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002474 fromView.setVisibility(View.GONE);
Michael Jurka9433fa72012-01-19 08:50:41 -08002475 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2476 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurka430e8a52011-08-08 15:52:14 -07002477 mWorkspace.hideScrollingIndicator(false);
Adam Cohened66b2b2012-01-23 17:28:51 -08002478 if (onCompleteRunnable != null) {
2479 onCompleteRunnable.run();
2480 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002481 }
2482 });
2483
Winson Chungf0ea4d32011-06-06 14:27:16 -07002484 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002485 if (workspaceAnim != null) {
2486 mStateAnimation.play(workspaceAnim);
2487 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002488 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002489 } else {
2490 fromView.setVisibility(View.GONE);
Michael Jurka9433fa72012-01-19 08:50:41 -08002491 dispatchOnLauncherTransitionStart(fromView, animated, false);
2492 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2493 dispatchOnLauncherTransitionStart(toView, animated, false);
2494 dispatchOnLauncherTransitionEnd(toView, animated, false);
Michael Jurkab737ee62011-11-15 15:57:22 -08002495 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002496 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002497 }
2498
Michael Jurkae326f182011-11-21 14:05:46 -08002499 @Override
2500 public void onTrimMemory(int level) {
2501 super.onTrimMemory(level);
2502 if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
2503 mAppsCustomizeTabHost.onTrimMemory();
2504 }
2505 }
2506
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002507 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002508 showWorkspace(animated, null);
2509 }
2510
2511 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002512 if (mState != State.WORKSPACE) {
2513 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002514 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002515
2516 // Show the search bar and hotseat
2517 mSearchDropTargetBar.showSearchBar(animated);
Michael Jurkab737ee62011-11-15 15:57:22 -08002518 // We only need to animate in the dock divider if we're going from spring loaded mode
2519 showDockDivider(animated && mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002520
2521 // Set focus to the AppsCustomize button
2522 if (mAllAppsButton != null) {
2523 mAllAppsButton.requestFocus();
2524 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002525 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002526
Michael Jurkab737ee62011-11-15 15:57:22 -08002527 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002528
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002529 // Change the state *after* we've called all the transition code
2530 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002531
Winson Chung5fb63472011-02-02 17:03:37 -08002532 // Resume the auto-advance of widgets
2533 mUserPresent = true;
2534 updateRunning();
2535
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002536 // send an accessibility event to announce the context change
2537 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002538 }
2539
Michael Jurkab3e22d92011-10-31 15:58:33 -07002540 void showAllApps(boolean animated) {
2541 if (mState != State.WORKSPACE) return;
2542
2543 showAppsCustomizeHelper(animated, false);
2544 mAppsCustomizeTabHost.requestFocus();
2545
2546 // Hide the search bar and hotseat
2547 mSearchDropTargetBar.hideSearchBar(animated);
2548
2549 // Change the state *after* we've called all the transition code
2550 mState = State.APPS_CUSTOMIZE;
2551
2552 // Pause the auto-advance of widgets until we are out of AllApps
2553 mUserPresent = false;
2554 updateRunning();
2555 closeFolder();
2556
2557 // Send an accessibility event to announce the context change
2558 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2559 }
2560
Adam Cohen7777d962011-08-18 18:58:38 -07002561 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002562 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002563 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002564 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002565 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002566 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002567 }
Adam Cohen7777d962011-08-18 18:58:38 -07002568
Adam Cohened66b2b2012-01-23 17:28:51 -08002569 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2570 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002571 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2572
Winson Chunge7a03942011-08-05 15:05:12 -07002573 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002574 @Override
2575 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002576 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002577 // Before we show workspace, hide all apps again because
2578 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2579 // clean up our state transition functions
2580 mAppsCustomizeTabHost.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002581 mSearchDropTargetBar.showSearchBar(true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002582 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002583 } else {
2584 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002585 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002586 }
2587 }, (extendedDelay ?
2588 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2589 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2590 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002591
Michael Jurkad3ef3062010-11-23 16:23:58 -08002592 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002593 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002594 final boolean animated = true;
2595 final boolean springLoaded = true;
2596 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002597 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002598 }
2599 // Otherwise, we are not in spring loaded mode, so don't do anything.
2600 }
2601
Michael Jurkab737ee62011-11-15 15:57:22 -08002602 void hideDockDivider() {
2603 if (mQsbDivider != null && mDockDivider != null) {
2604 mQsbDivider.setVisibility(View.INVISIBLE);
2605 mDockDivider.setVisibility(View.INVISIBLE);
2606 }
2607 }
2608
2609 void showDockDivider(boolean animated) {
2610 if (mQsbDivider != null && mDockDivider != null) {
2611 mQsbDivider.setVisibility(View.VISIBLE);
2612 mDockDivider.setVisibility(View.VISIBLE);
2613 if (mDividerAnimator != null) {
2614 mDividerAnimator.cancel();
2615 mQsbDivider.setAlpha(1f);
2616 mDockDivider.setAlpha(1f);
2617 mDividerAnimator = null;
2618 }
2619 if (animated) {
2620 mDividerAnimator = new AnimatorSet();
2621 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2622 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2623 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2624 mDividerAnimator.start();
2625 }
2626 }
2627 }
2628
Michael Jurkab3e22d92011-10-31 15:58:33 -07002629 void lockAllApps() {
2630 // TODO
2631 }
2632
2633 void unlockAllApps() {
2634 // TODO
2635 }
2636
Adam Cohenfc53cd22011-07-20 15:45:11 -07002637 public boolean isAllAppsCustomizeOpen() {
2638 return mState == State.APPS_CUSTOMIZE;
2639 }
2640
Winson Chungf0ea4d32011-06-06 14:27:16 -07002641 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002642 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002643 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002644 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002645 if (!LauncherApplication.isScreenLarge()) {
2646 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002647 if (mHotseat.getAlpha() != 1f) {
2648 int duration = mSearchDropTargetBar.getTransitionInDuration();
2649 mHotseat.animate().alpha(1f).setDuration(duration);
2650 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002651 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002652 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002653 }
2654 }
2655 }
2656
2657 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002658 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002659 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002660 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002661 if (!LauncherApplication.isScreenLarge()) {
2662 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002663 if (mHotseat.getAlpha() != 0f) {
2664 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2665 mHotseat.animate().alpha(0f).setDuration(duration);
2666 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002667 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002668 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002669 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002670 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002671 }
2672
Patrick Dubroy5f445422011-02-18 14:35:21 -08002673 /**
2674 * Add an item from all apps or customize onto the given workspace screen.
2675 * If layout is null, add to the current screen.
2676 */
2677 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002678 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2679 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07002680 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002681 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002682
Winson Chungdff8ebb2011-09-08 17:25:31 -07002683 /** Maps the current orientation to an index for referencing orientation correct global icons */
2684 private int getCurrentOrientationIndexForGlobalIcons() {
2685 // default - 0, landscape - 1
2686 switch (getResources().getConfiguration().orientation) {
2687 case Configuration.ORIENTATION_LANDSCAPE:
2688 return 1;
2689 default:
2690 return 0;
2691 }
2692 }
2693
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002694 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002695 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002696 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002697 // Look for the toolbar icon specified in the activity meta-data
2698 Bundle metaData = packageManager.getActivityInfo(
2699 activityName, PackageManager.GET_META_DATA).metaData;
2700 if (metaData != null) {
2701 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2702 if (iconResId != 0) {
2703 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002704 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002705 }
2706 }
2707 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002708 // This can happen if the activity defines an invalid drawable
2709 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2710 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002711 } catch (Resources.NotFoundException nfe) {
2712 // This can happen if the activity defines an invalid drawable
2713 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2714 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002715 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002716 return null;
2717 }
2718
2719 // if successful in getting icon, return it; otherwise, set button to use default drawable
2720 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2721 int buttonId, ComponentName activityName, int fallbackDrawableId) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002722 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002723 Resources r = getResources();
2724 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2725 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002726
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002727 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002728 // If we were unable to find the icon via the meta-data, use a generic one
2729 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002730 toolbarIcon = r.getDrawable(fallbackDrawableId);
2731 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002732 if (button != null) {
2733 button.setCompoundDrawables(toolbarIcon, null, null, null);
2734 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002735 return null;
2736 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002737 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002738 if (button != null) {
2739 button.setCompoundDrawables(toolbarIcon, null, null, null);
2740 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002741 return toolbarIcon.getConstantState();
2742 }
2743 }
2744
2745 // if successful in getting icon, return it; otherwise, set button to use default drawable
2746 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2747 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2748 ImageView button = (ImageView) findViewById(buttonId);
2749 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2750
Michael Jurka19e0fc52011-07-22 18:00:21 -07002751 if (button != null) {
2752 // If we were unable to find the icon via the meta-data, use a
2753 // generic one
2754 if (toolbarIcon == null) {
2755 button.setImageResource(fallbackDrawableId);
2756 } else {
2757 button.setImageDrawable(toolbarIcon);
2758 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002759 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002760
2761 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2762
Michael Jurka0423dcf2010-10-05 14:56:18 -07002763 }
2764
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002765 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2766 TextView button = (TextView) findViewById(buttonId);
2767 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2768 }
2769
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002770 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002771 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002772 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002773 }
2774
Winson Chungbb185bd2011-11-21 12:31:42 -08002775 private void invalidatePressedFocusedStates(View container, View button) {
2776 if (container instanceof HolographicLinearLayout) {
2777 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2778 layout.invalidatePressedFocusedStates();
2779 } else if (button instanceof HolographicImageView) {
2780 HolographicImageView view = (HolographicImageView) button;
2781 view.invalidatePressedFocusedStates();
2782 }
2783 }
2784
Winson Chungc51db6a2011-10-05 11:44:49 -07002785 private boolean updateGlobalSearchIcon() {
2786 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002787 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2788 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002789 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002790 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002791
Winson Chung1cad91e2011-05-25 17:41:01 -07002792 final SearchManager searchManager =
2793 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2794 ComponentName activityName = searchManager.getGlobalSearchActivity();
2795 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002796 int coi = getCurrentOrientationIndexForGlobalIcons();
2797 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002798 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002799 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002800 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2801 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002802 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002803 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002804 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002805 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002806 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002807 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2808 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2809 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002810 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002811 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002812 }
2813 }
2814
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002815 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002816 final View searchButtonContainer = findViewById(R.id.search_button_container);
2817 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002818 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002819 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002820 }
2821
Winson Chungc51db6a2011-10-05 11:44:49 -07002822 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002823 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002824 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002825 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002826
Winson Chungc51db6a2011-10-05 11:44:49 -07002827 // We only show/update the voice search icon if the search icon is enabled as well
Winson Chung1cad91e2011-05-25 17:41:01 -07002828 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2829 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chungc51db6a2011-10-05 11:44:49 -07002830 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002831 int coi = getCurrentOrientationIndexForGlobalIcons();
2832 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002833 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002834 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002835 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002836 voiceButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002837 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002838 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002839 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002840 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002841 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002842 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002843 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002844 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002845 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002846
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002847 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002848 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
2849 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002850 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002851 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002852 }
2853
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002854 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002855 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002856 */
2857 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002858 final View marketButton = findViewById(R.id.market_button);
2859 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2860 // Find the app market activity by resolving an intent.
2861 // (If multiple app markets are installed, it will return the ResolverActivity.)
2862 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002863 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002864 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07002865 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07002866 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002867 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002868 marketButton.setVisibility(View.VISIBLE);
2869 } else {
2870 // We should hide and disable the view so that we don't try and restore the visibility
2871 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2872 marketButton.setVisibility(View.GONE);
2873 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002874 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002875 }
2876
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002877 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002878 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002879 }
2880
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002881 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002882 * Displays the shortcut creation dialog and launches, if necessary, the
2883 * appropriate activity.
2884 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002885 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002886 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2887 DialogInterface.OnShowListener {
2888
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002889 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002890
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002891 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002892 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002893
Winson Chung55b65502011-05-26 12:03:43 -07002894 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2895 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002896 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002897
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002898 AlertDialog dialog = builder.create();
2899 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002900 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002901 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002902
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002903 return dialog;
2904 }
2905
2906 public void onCancel(DialogInterface dialog) {
2907 mWaitingForResult = false;
2908 cleanup();
2909 }
2910
Romain Guycbb89e42009-06-08 15:52:54 -07002911 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002912 mWaitingForResult = false;
2913 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002914 }
2915
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002916 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002917 try {
2918 dismissDialog(DIALOG_CREATE_SHORTCUT);
2919 } catch (Exception e) {
2920 // An exception is thrown if the dialog is not visible, which is fine
2921 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002922 }
2923
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002924 /**
2925 * Handle the action clicked in the "Add to home" dialog.
2926 */
2927 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002928 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002929
Winson Chung55b65502011-05-26 12:03:43 -07002930 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2931 switch (item.actionTag) {
Winson Chung55b65502011-05-26 12:03:43 -07002932 case AddAdapter.ITEM_APPLICATION: {
2933 if (mAppsCustomizeTabHost != null) {
2934 mAppsCustomizeTabHost.selectAppsTab();
2935 }
2936 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002937 break;
2938 }
Winson Chung55b65502011-05-26 12:03:43 -07002939 case AddAdapter.ITEM_APPWIDGET: {
2940 if (mAppsCustomizeTabHost != null) {
2941 mAppsCustomizeTabHost.selectWidgetsTab();
2942 }
2943 showAllApps(true);
2944 break;
2945 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002946 case AddAdapter.ITEM_WALLPAPER: {
2947 startWallpaper();
2948 break;
2949 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002950 }
2951 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002952
2953 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002954 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002955 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002956 }
2957
2958 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07002959 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002960 */
2961 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2962 @Override
2963 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002964 closeSystemDialogs();
2965 }
2966 }
2967
2968 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002969 * Receives notifications whenever the appwidgets are reset.
2970 */
2971 private class AppWidgetResetObserver extends ContentObserver {
2972 public AppWidgetResetObserver() {
2973 super(new Handler());
2974 }
2975
2976 @Override
2977 public void onChange(boolean selfChange) {
2978 onAppWidgetReset();
2979 }
2980 }
2981
2982 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002983 * If the activity is currently paused, signal that we need to re-run the loader
2984 * in onResume.
2985 *
2986 * This needs to be called from incoming places where resources might have been loaded
2987 * while we are paused. That is becaues the Configuration might be wrong
2988 * when we're not running, and if it comes back to what it was when we
2989 * were paused, we are not restarted.
2990 *
2991 * Implementation of the method from LauncherModel.Callbacks.
2992 *
2993 * @return true if we are currently paused. The caller might be able to
2994 * skip some work in that case since we will come back again.
2995 */
2996 public boolean setLoadOnResume() {
2997 if (mPaused) {
2998 Log.i(TAG, "setLoadOnResume");
2999 mOnResumeNeedsLoad = true;
3000 return true;
3001 } else {
3002 return false;
3003 }
3004 }
3005
3006 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003007 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003008 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003009 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003010 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003011 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003012 } else {
3013 return SCREEN_COUNT / 2;
3014 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003015 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003016
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003017
Joe Onorato9c1289c2009-08-17 11:03:03 -04003018 /**
3019 * Refreshes the shortcuts shown on the workspace.
3020 *
3021 * Implementation of the method from LauncherModel.Callbacks.
3022 */
3023 public void startBinding() {
3024 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07003025
3026 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003027 int count = workspace.getChildCount();
3028 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003029 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003030 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3031 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003032 }
Michael Jurka05bf6442011-11-30 20:28:53 -08003033 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003034 if (mHotseat != null) {
3035 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003036 }
3037 }
3038
3039 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003040 * Bind the items start-end from the list.
3041 *
3042 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003043 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003044 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003045 setLoadOnResume();
3046
Joe Onorato9c1289c2009-08-17 11:03:03 -04003047 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003048 for (int i=start; i<end; i++) {
3049 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003050
3051 // Short circuit if we are loading dock items for a configuration which has no dock
3052 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3053 mHotseat == null) {
3054 continue;
3055 }
3056
Joe Onorato9c1289c2009-08-17 11:03:03 -04003057 switch (item.itemType) {
3058 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3059 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07003060 View shortcut = createShortcut((ShortcutInfo)item);
3061 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3062 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003063 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003064 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003065 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003066 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003067 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003068 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3069 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003070 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003071 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003072 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003073 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003074 }
3075
Joe Onorato9c1289c2009-08-17 11:03:03 -04003076 /**
3077 * Implementation of the method from LauncherModel.Callbacks.
3078 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003079 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003080 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003081 sFolders.clear();
3082 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003083 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003084
3085 /**
3086 * Add the views for a widget to the workspace.
3087 *
3088 * Implementation of the method from LauncherModel.Callbacks.
3089 */
3090 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003091 setLoadOnResume();
3092
Daniel Sandler843e8602010-06-07 14:59:01 -04003093 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3094 if (DEBUG_WIDGETS) {
3095 Log.d(TAG, "bindAppWidget: " + item);
3096 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003097 final Workspace workspace = mWorkspace;
3098
3099 final int appWidgetId = item.appWidgetId;
3100 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003101 if (DEBUG_WIDGETS) {
3102 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3103 }
3104
Joe Onorato9c1289c2009-08-17 11:03:03 -04003105 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3106
Joe Onorato9c1289c2009-08-17 11:03:03 -04003107 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
3108 item.hostView.setTag(item);
3109
Winson Chung3d503fb2011-07-13 17:25:49 -07003110 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003111 item.cellY, item.spanX, item.spanY, false);
3112
Adam Cohended9f8d2010-11-03 13:25:16 -07003113 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3114
Joe Onorato9c1289c2009-08-17 11:03:03 -04003115 workspace.requestLayout();
3116
Daniel Sandler843e8602010-06-07 14:59:01 -04003117 if (DEBUG_WIDGETS) {
3118 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3119 + (SystemClock.uptimeMillis()-start) + "ms");
3120 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003121 }
3122
3123 /**
3124 * Callback saying that there aren't any more items to bind.
3125 *
3126 * Implementation of the method from LauncherModel.Callbacks.
3127 */
3128 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003129 setLoadOnResume();
3130
Joe Onorato9c1289c2009-08-17 11:03:03 -04003131 if (mSavedState != null) {
3132 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003133 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003134 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003135 mSavedState = null;
3136 }
3137
3138 if (mSavedInstanceState != null) {
3139 super.onRestoreInstanceState(mSavedInstanceState);
3140 mSavedInstanceState = null;
3141 }
3142
Joe Onorato9c1289c2009-08-17 11:03:03 -04003143 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003144
3145 // If we received the result of any pending adds while the loader was running (e.g. the
3146 // widget configuration forced an orientation change), process them now.
3147 for (int i = 0; i < sPendingAddList.size(); i++) {
3148 completeAdd(sPendingAddList.get(i));
3149 }
3150 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003151
Winson Chungc51db6a2011-10-05 11:44:49 -07003152 // Update the market app icon as necessary (the other icons will be managed in response to
3153 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003154 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003155
3156 mWorkspace.post(mBuildLayersRunnable);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003157 }
3158
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003159 @Override
3160 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003161 boolean searchVisible = updateGlobalSearchIcon();
3162 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3163 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003164 }
3165
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003166 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003167 * Add the icons for all apps.
3168 *
3169 * Implementation of the method from LauncherModel.Callbacks.
3170 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003171 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3172 // Remove the progress bar entirely; we could also make it GONE
3173 // but better to remove it since we know it's not going to be used
3174 View progressBar = mAppsCustomizeTabHost.
3175 findViewById(R.id.apps_customize_progress_bar);
3176 if (progressBar != null) {
3177 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003178 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003179 // We just post the call to setApps so the user sees the progress bar
3180 // disappear-- otherwise, it just looks like the progress bar froze
3181 // which doesn't look great
3182 mAppsCustomizeTabHost.post(new Runnable() {
3183 public void run() {
3184 if (mAppsCustomizeContent != null) {
3185 mAppsCustomizeContent.setApps(apps);
3186 }
3187 }
3188 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003189 }
3190
3191 /**
3192 * A package was installed.
3193 *
3194 * Implementation of the method from LauncherModel.Callbacks.
3195 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003196 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003197 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003198 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003199
Winson Chung785d2eb2011-04-14 16:08:02 -07003200 if (mAppsCustomizeContent != null) {
3201 mAppsCustomizeContent.addApps(apps);
3202 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003203 }
3204
3205 /**
3206 * A package was updated.
3207 *
3208 * Implementation of the method from LauncherModel.Callbacks.
3209 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003210 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003211 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003212 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003213 if (mWorkspace != null) {
3214 mWorkspace.updateShortcuts(apps);
3215 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003216
Winson Chung785d2eb2011-04-14 16:08:02 -07003217 if (mAppsCustomizeContent != null) {
3218 mAppsCustomizeContent.updateApps(apps);
3219 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003220 }
3221
3222 /**
3223 * A package was uninstalled.
3224 *
3225 * Implementation of the method from LauncherModel.Callbacks.
3226 */
Joe Onorato36115782010-06-17 13:28:48 -04003227 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003228 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003229 if (permanent) {
3230 mWorkspace.removeItems(apps);
3231 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003232
Winson Chung785d2eb2011-04-14 16:08:02 -07003233 if (mAppsCustomizeContent != null) {
3234 mAppsCustomizeContent.removeApps(apps);
3235 }
Winson Chunga1820962011-10-03 16:31:06 -07003236
3237 // Notify the drag controller
3238 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003239 }
Joe Onoratobe386092009-11-17 17:32:16 -08003240
3241 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003242 * A number of packages were updated.
3243 */
3244 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003245 if (mAppsCustomizeContent != null) {
3246 mAppsCustomizeContent.onPackagesUpdated();
3247 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003248 }
3249
Winson Chung400438b2011-01-16 17:53:48 -08003250 private int mapConfigurationOriActivityInfoOri(int configOri) {
3251 final Display d = getWindowManager().getDefaultDisplay();
3252 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3253 switch (d.getRotation()) {
3254 case Surface.ROTATION_0:
3255 case Surface.ROTATION_180:
3256 // We are currently in the same basic orientation as the natural orientation
3257 naturalOri = configOri;
3258 break;
3259 case Surface.ROTATION_90:
3260 case Surface.ROTATION_270:
3261 // We are currently in the other basic orientation to the natural orientation
3262 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3263 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3264 break;
3265 }
3266
3267 int[] oriMap = {
3268 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3269 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3270 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3271 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3272 };
3273 // Since the map starts at portrait, we need to offset if this device's natural orientation
3274 // is landscape.
3275 int indexOffset = 0;
3276 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3277 indexOffset = 1;
3278 }
3279 return oriMap[(d.getRotation() + indexOffset) % 4];
3280 }
Adam Cohen446e9402011-09-15 18:21:21 -07003281
3282 public void lockScreenOrientationOnLargeUI() {
3283 if (LauncherApplication.isScreenLarge()) {
3284 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3285 .getConfiguration().orientation));
3286 }
Winson Chung400438b2011-01-16 17:53:48 -08003287 }
Adam Cohen446e9402011-09-15 18:21:21 -07003288 public void unlockScreenOrientationOnLargeUI() {
3289 if (LauncherApplication.isScreenLarge()) {
3290 mHandler.postDelayed(new Runnable() {
3291 public void run() {
3292 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3293 }
3294 }, mRestoreScreenOrientationDelay);
3295 }
Winson Chung400438b2011-01-16 17:53:48 -08003296 }
3297
Winson Chung82f55532011-08-09 14:14:23 -07003298 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003299 private static final String PREFS_KEY = "com.android.launcher2.prefs";
3300 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003301 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003302 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003303
Winson Chung7d7541e2011-09-16 20:14:36 -07003304 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003305 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003306 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3307 Cling cling = (Cling) findViewById(clingId);
3308 if (cling != null) {
3309 cling.init(this, positionData);
3310 cling.setVisibility(View.VISIBLE);
3311 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3312 if (animate) {
3313 cling.buildLayer();
3314 cling.setAlpha(0f);
3315 cling.animate()
3316 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003317 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003318 .setDuration(SHOW_CLING_DURATION)
3319 .setStartDelay(delay)
3320 .start();
3321 } else {
3322 cling.setAlpha(1f);
3323 }
3324 }
3325 return cling;
3326 }
3327 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003328 if (cling != null) {
3329 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003330 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003331 anim.addListener(new AnimatorListenerAdapter() {
3332 public void onAnimationEnd(Animator animation) {
3333 cling.setVisibility(View.GONE);
3334 cling.cleanup();
3335 SharedPreferences prefs =
3336 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
3337 SharedPreferences.Editor editor = prefs.edit();
3338 editor.putBoolean(flag, true);
3339 editor.commit();
3340 };
3341 });
3342 anim.start();
3343 }
3344 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003345 private void removeCling(int id) {
3346 final View cling = findViewById(id);
3347 if (cling != null) {
3348 final ViewGroup parent = (ViewGroup) cling.getParent();
3349 parent.post(new Runnable() {
3350 @Override
3351 public void run() {
3352 parent.removeView(cling);
3353 }
3354 });
3355 }
3356 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003357 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003358 // Enable the clings only if they have not been dismissed before
3359 SharedPreferences prefs =
3360 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003361 if (isClingsEnabled() && !prefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003362 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003363 } else {
3364 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003365 }
3366 }
3367 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003368 // Enable the clings only if they have not been dismissed before
3369 SharedPreferences prefs =
3370 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003371 if (isClingsEnabled() && !prefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003372 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003373 } else {
3374 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003375 }
3376 }
3377 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003378 // Enable the clings only if they have not been dismissed before
3379 SharedPreferences prefs =
3380 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
3381 Cling cling = null;
Winson Chung9d9d74f2011-09-19 11:49:12 -07003382 if (isClingsEnabled() && !prefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003383 cling = initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003384 } else {
3385 removeCling(R.id.folder_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003386 }
3387 return cling;
3388 }
3389 public boolean isFolderClingVisible() {
3390 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003391 if (cling != null) {
3392 return cling.getVisibility() == View.VISIBLE;
3393 }
3394 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003395 }
Winson Chung82f55532011-08-09 14:14:23 -07003396 public void dismissWorkspaceCling(View v) {
3397 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003398 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003399 }
3400 public void dismissAllAppsCling(View v) {
3401 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003402 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3403 }
3404 public void dismissFolderCling(View v) {
3405 Cling cling = (Cling) findViewById(R.id.folder_cling);
3406 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003407 }
3408
Winson Chung80baf5a2010-08-09 16:03:15 -07003409 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003410 * Prints out out state for debugging.
3411 */
3412 public void dumpState() {
3413 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003414 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003415 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3416 Log.d(TAG, "mRestoring=" + mRestoring);
3417 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3418 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003419 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003420 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003421
Winson Chung785d2eb2011-04-14 16:08:02 -07003422 if (mAppsCustomizeContent != null) {
3423 mAppsCustomizeContent.dumpState();
3424 }
Joe Onoratobe386092009-11-17 17:32:16 -08003425 Log.d(TAG, "END launcher2 dump state");
3426 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003427
3428 @Override
3429 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3430 super.dump(prefix, fd, writer, args);
3431 writer.println(" ");
3432 writer.println("Debug logs: ");
3433 for (int i = 0; i < sDumpLogs.size(); i++) {
3434 writer.println(" " + sDumpLogs.get(i));
3435 }
3436 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003437}
Michael Jurka2763be32011-02-24 11:19:57 -08003438
Michael Jurkaabded662011-03-04 12:06:57 -08003439interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003440 View getContent();
Michael Jurka9433fa72012-01-19 08:50:41 -08003441 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
3442 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003443}