blob: 07c8dc0dd1656eec6deabd67f9aeb95c959b87d4 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Joe Onoratoa5902522009-07-30 13:37:37 -070018package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
24import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070025import android.animation.ValueAnimator;
Michael Jurka946ad472010-07-09 18:05:18 -070026import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070027import android.app.ActivityManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029import android.app.Dialog;
30import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080031import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070032import android.appwidget.AppWidgetManager;
33import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080035import android.content.BroadcastReceiver;
Winson Chung68846fd2010-10-29 11:00:27 -070036import android.content.ClipData;
37import android.content.ClipDescription;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
42import android.content.DialogInterface;
43import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070044import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070045import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070048import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohened66b2b2012-01-23 17:28:51 -080052import android.graphics.Bitmap;
Michael Jurkaaf442092010-06-10 17:01:57 -070053import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070054import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040055import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070056import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020058import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080059import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070060import android.os.Message;
Daniel Sandler843e8602010-06-07 14:59:01 -040061import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080062import android.os.SystemProperties;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070063import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080064import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065import android.text.Selection;
66import android.text.SpannableStringBuilder;
67import android.text.TextUtils;
68import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070069import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080070import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080071import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072import android.view.KeyEvent;
73import android.view.LayoutInflater;
74import android.view.Menu;
75import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070076import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080077import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080078import android.view.View;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080079import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070080import android.view.ViewGroup;
Michael Jurkab737ee62011-11-15 15:57:22 -080081import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080082import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Dianne Hackbornbb003a52011-08-30 14:40:07 -070083import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080084import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070085import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070086import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080087import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070089import android.widget.Advanceable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080090import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070091import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070092import android.widget.TextView;
93import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070094
Adam Cohendf2cc412011-04-27 16:56:57 -070095import com.android.common.Search;
96import com.android.launcher.R;
Adam Cohen558baaf2011-08-15 15:22:57 -070097import com.android.launcher2.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080098
Adam Cohenc0dcf592011-06-01 15:30:43 -070099import java.io.DataInputStream;
100import java.io.DataOutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700101import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.FileNotFoundException;
103import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700104import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700105import java.util.ArrayList;
106import java.util.HashMap;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800108/**
109 * Default launcher application.
110 */
Michael Jurka946ad472010-07-09 18:05:18 -0700111public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700112 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
113 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800114 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700115 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800116
Joe Onorato9c1289c2009-08-17 11:03:03 -0400117 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400118 static final boolean DEBUG_WIDGETS = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700119
Winson Chung70d72102011-08-12 11:24:35 -0700120 private static final int MENU_GROUP_WALLPAPER = 1;
121 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
122 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700123 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
124 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125
126 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700127 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128 private static final int REQUEST_PICK_APPLICATION = 6;
129 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700130 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700131 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132
133 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
134
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800135 static final int SCREEN_COUNT = 5;
136 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137
Joe Onorato7c312c12009-08-13 21:36:53 -0700138 static final int DIALOG_CREATE_SHORTCUT = 1;
139 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140
Romain Guy98d01652009-06-30 16:21:04 -0700141 private static final String PREFERENCES = "launcher.preferences";
Adam Cohen23a4d302011-12-01 17:26:44 -0800142 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher.force_enable_rotation";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143
144 // Type: int
145 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700146 // Type: int
147 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700149 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
150 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
152 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700153 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700155 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156 // Type: boolean
157 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
158 // Type: long
159 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
160
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700161 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
162
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700163 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700164 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700165 private State mState = State.WORKSPACE;
166 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800167 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700168
Joe Onorato9c1289c2009-08-17 11:03:03 -0400169 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700170 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
171 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700172 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700173 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800176 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800178 private final BroadcastReceiver mCloseSystemDialogsReceiver
179 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800180 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
181
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 private LayoutInflater mInflater;
183
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800185 private View mQsbDivider;
186 private View mDockDivider;
187 private DragLayer mDragLayer;
188 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700189
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700190 private AppWidgetManager mAppWidgetManager;
191 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700192
Michael Jurkac9d95c52011-08-29 14:03:34 -0700193 private ItemInfo mPendingAddInfo = new ItemInfo();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700194 private int[] mTmpAddItemCellCoordinates = new int[2];
195
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800196 private FolderInfo mFolderInfo;
197
Winson Chung3d503fb2011-07-13 17:25:49 -0700198 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800199 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700200
Winson Chungc51db6a2011-10-05 11:44:49 -0700201 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700202 private AppsCustomizeTabHost mAppsCustomizeTabHost;
203 private AppsCustomizePagedView mAppsCustomizeContent;
204 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800206 private Bundle mSavedState;
207
208 private SpannableStringBuilder mDefaultKeySsb = null;
209
Joe Onorato9c1289c2009-08-17 11:03:03 -0400210 private boolean mWorkspaceLoading = true;
211
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800212 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800213 private boolean mRestoring;
214 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700215 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800216
217 private Bundle mSavedInstanceState;
218
Joe Onorato9c1289c2009-08-17 11:03:03 -0400219 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800220 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800221 private boolean mUserPresent = true;
222 private boolean mVisible = false;
223 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400224
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700225 private static LocaleConfiguration sLocaleConfiguration = null;
226
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700227 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700228
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700229 private Intent mAppMarketIntent = null;
230
Adam Cohended9f8d2010-11-03 13:25:16 -0700231 // Related to the auto-advancing of widgets
232 private final int ADVANCE_MSG = 1;
233 private final int mAdvanceInterval = 20000;
234 private final int mAdvanceStagger = 250;
235 private long mAutoAdvanceSentTime;
236 private long mAutoAdvanceTimeLeft = -1;
237 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
238 new HashMap<View, AppWidgetProviderInfo>();
239
Winson Chung400438b2011-01-16 17:53:48 -0800240 // Determines how long to wait after a rotation before restoring the screen orientation to
241 // match the sensor state.
242 private final int mRestoreScreenOrientationDelay = 500;
243
Michael Jurka4ef207b2010-11-29 17:05:45 -0800244 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700245 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
246 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
247 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800248
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700249 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohened66b2b2012-01-23 17:28:51 -0800250 PendingAddWidgetInfo mWidgetBeingConfigured = null;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700251
Adam Cohen2801caf2011-05-13 20:57:39 -0700252
Michael Jurkaddd62e92011-02-16 17:49:14 -0800253 private BubbleTextView mWaitingForResume;
254
Michael Jurkac1f5d262011-09-30 19:32:27 -0700255 private Runnable mBuildLayersRunnable = new Runnable() {
256 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700257 if (mWorkspace != null) {
258 mWorkspace.buildPageHardwareLayers();
259 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700260 }
261 };
262
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800263 private static ArrayList<PendingAddArguments> sPendingAddList
264 = new ArrayList<PendingAddArguments>();
265
266 private static class PendingAddArguments {
267 int requestCode;
268 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700269 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800270 int screen;
271 int cellX;
272 int cellY;
273 }
274
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800275 @Override
276 protected void onCreate(Bundle savedInstanceState) {
277 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800278 LauncherApplication app = ((LauncherApplication)getApplication());
279 mModel = app.setLauncher(this);
280 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400281 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800282 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700283
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700284 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700285 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
286 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700287
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800288 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200289 android.os.Debug.startMethodTracing(
290 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800291 }
292
293 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800294 setContentView(R.layout.launcher);
295 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700296 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800297
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800298 registerContentObservers();
299
Joe Onorato7c312c12009-08-13 21:36:53 -0700300 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700301
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800302 mSavedState = savedInstanceState;
303 restoreState(mSavedState);
304
Winson Chunga12a2502010-12-20 14:41:35 -0800305 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700306 if (mAppsCustomizeContent != null) {
307 mAppsCustomizeContent.onPackagesUpdated();
308 }
Winson Chunga12a2502010-12-20 14:41:35 -0800309
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800310 if (PROFILE_STARTUP) {
311 android.os.Debug.stopMethodTracing();
312 }
313
314 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400315 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800316 }
317
Michael Jurkac57b7a82011-08-09 22:02:20 -0700318 if (!mModel.isAllAppsLoaded()) {
319 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
320 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
321 }
322
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800323 // For handling default keys
324 mDefaultKeySsb = new SpannableStringBuilder();
325 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800326
327 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
328 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800329
Winson Chungc51db6a2011-10-05 11:44:49 -0700330 boolean searchVisible = false;
331 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800332 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700333 int coi = getCurrentOrientationIndexForGlobalIcons();
334 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
335 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700336 updateAppMarketIcon();
337 searchVisible = updateGlobalSearchIcon();
338 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700339 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700340 if (sGlobalSearchIcon[coi] != null) {
341 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700342 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700343 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700344 if (sVoiceSearchIcon[coi] != null) {
345 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700346 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700347 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700348 if (sAppMarketIcon[coi] != null) {
349 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800350 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700351 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Adam Cohen446e9402011-09-15 18:21:21 -0700352
Adam Cohen23a4d302011-12-01 17:26:44 -0800353 final String forceEnableRotation =
354 SystemProperties.get(FORCE_ENABLE_ROTATION_PROPERTY, "false");
355
Adam Cohen446e9402011-09-15 18:21:21 -0700356 // On large interfaces, we want the screen to auto-rotate based on the current orientation
Adam Cohen23a4d302011-12-01 17:26:44 -0800357 if (LauncherApplication.isScreenLarge() || "true".equalsIgnoreCase(forceEnableRotation)) {
Adam Cohen446e9402011-09-15 18:21:21 -0700358 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
359 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800360 }
Romain Guycbb89e42009-06-08 15:52:54 -0700361
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800362 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700363 if (sLocaleConfiguration == null) {
364 new AsyncTask<Void, Void, LocaleConfiguration>() {
365 @Override
366 protected LocaleConfiguration doInBackground(Void... unused) {
367 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
368 readConfiguration(Launcher.this, localeConfiguration);
369 return localeConfiguration;
370 }
371
372 @Override
373 protected void onPostExecute(LocaleConfiguration result) {
374 sLocaleConfiguration = result;
375 checkForLocaleChange(); // recursive, but now with a locale configuration
376 }
377 }.execute();
378 return;
379 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700380
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800381 final Configuration configuration = getResources().getConfiguration();
382
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700383 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800384 final String locale = configuration.locale.toString();
385
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700386 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800387 final int mcc = configuration.mcc;
388
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700389 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800390 final int mnc = configuration.mnc;
391
Romain Guy84f296c2009-11-04 15:00:44 -0800392 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800393
Romain Guy84f296c2009-11-04 15:00:44 -0800394 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700395 sLocaleConfiguration.locale = locale;
396 sLocaleConfiguration.mcc = mcc;
397 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700398
Joe Onorato0589f0f2010-02-08 13:44:00 -0800399 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700400
401 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
402 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700403 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700404 public void run() {
405 writeConfiguration(Launcher.this, localeConfiguration);
406 }
407 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700408 }
409 }
410
411 private static class LocaleConfiguration {
412 public String locale;
413 public int mcc = -1;
414 public int mnc = -1;
415 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700416
Romain Guy98d01652009-06-30 16:21:04 -0700417 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
418 DataInputStream in = null;
419 try {
420 in = new DataInputStream(context.openFileInput(PREFERENCES));
421 configuration.locale = in.readUTF();
422 configuration.mcc = in.readInt();
423 configuration.mnc = in.readInt();
424 } catch (FileNotFoundException e) {
425 // Ignore
426 } catch (IOException e) {
427 // Ignore
428 } finally {
429 if (in != null) {
430 try {
431 in.close();
432 } catch (IOException e) {
433 // Ignore
434 }
435 }
436 }
437 }
438
439 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
440 DataOutputStream out = null;
441 try {
442 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
443 out.writeUTF(configuration.locale);
444 out.writeInt(configuration.mcc);
445 out.writeInt(configuration.mnc);
446 out.flush();
447 } catch (FileNotFoundException e) {
448 // Ignore
449 } catch (IOException e) {
450 //noinspection ResultOfMethodCallIgnored
451 context.getFileStreamPath(PREFERENCES).delete();
452 } finally {
453 if (out != null) {
454 try {
455 out.close();
456 } catch (IOException e) {
457 // Ignore
458 }
459 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 }
461 }
462
Adam Cohen716b51e2011-06-30 12:09:54 -0700463 public DragLayer getDragLayer() {
464 return mDragLayer;
465 }
466
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800467 static int getScreen() {
468 synchronized (sLock) {
469 return sScreen;
470 }
471 }
472
473 static void setScreen(int screen) {
474 synchronized (sLock) {
475 sScreen = screen;
476 }
477 }
478
Winson Chung557d6ed2011-07-08 15:34:52 -0700479 /**
480 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
481 * a configuration step, this allows the proper animations to run after other transitions.
482 */
483 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700484 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800485 switch (args.requestCode) {
486 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700487 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
488 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800489 break;
490 case REQUEST_PICK_SHORTCUT:
491 processShortcut(args.intent);
492 break;
493 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700494 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
495 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700496 result = true;
497 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800498 case REQUEST_PICK_APPWIDGET:
499 addAppWidgetFromPick(args.intent);
500 break;
501 case REQUEST_CREATE_APPWIDGET:
502 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800503 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700504 result = true;
505 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800506 case REQUEST_PICK_WALLPAPER:
507 // We just wanted the activity result here so we can clear mWaitingForResult
508 break;
509 }
Winson Chungb8472bb2011-08-05 13:49:21 -0700510 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800511 }
512
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800513 @Override
Adam Cohened66b2b2012-01-23 17:28:51 -0800514 protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
Winson Chung557d6ed2011-07-08 15:34:52 -0700515 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800516 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
517 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700518 mWaitingForResult = false;
519
Adam Cohened66b2b2012-01-23 17:28:51 -0800520 // We have special handling for widgets
521 if (isWidgetDrop) {
522 int appWidgetId = data != null ?
523 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
524 completeTwoStageWidgetDrop(resultCode, appWidgetId);
525 return;
526 }
527
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800528 // The pattern used here is that a user PICKs a specific application,
529 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700530
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800531 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
532 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700533 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800534 final PendingAddArguments args = new PendingAddArguments();
535 args.requestCode = requestCode;
536 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700537 args.container = mPendingAddInfo.container;
538 args.screen = mPendingAddInfo.screen;
539 args.cellX = mPendingAddInfo.cellX;
540 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800541 if (isWorkspaceLocked()) {
542 sPendingAddList.add(args);
543 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700544 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800545 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800546 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800547 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700548 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800549 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
550 null);
551 }
552
553 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
554 CellLayout cellLayout = (CellLayout) mWorkspace.getChildAt(mWidgetBeingConfigured.screen);
555 Runnable onCompleteRunnable = null;
556 int animationType = 0;
557
558 if (resultCode == RESULT_OK) {
559 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
560 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
561 mWidgetBeingConfigured.info);
562 mWidgetBeingConfigured.boundWidget = layout;
563 onCompleteRunnable = new Runnable() {
564 @Override
565 public void run() {
566 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
567 mPendingAddInfo.screen, layout, null);
568 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
569 null);
570 }
571 };
572 } else if (resultCode == RESULT_CANCELED) {
573 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
574 onCompleteRunnable = new Runnable() {
575 @Override
576 public void run() {
577 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
578 null);
579 }
580 };
581 }
582 mWorkspace.animateExternalDrop(mWidgetBeingConfigured, cellLayout,
583 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
584 animationType);
Adam Cohen1b36dc32012-02-13 19:27:37 -0800585 mWidgetBeingConfigured = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800586 }
587
588 @Override
589 protected void onResume() {
590 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800591 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700592 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400593 mWorkspaceLoading = true;
594 mModel.startLoader(this, true);
595 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700596 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800597 }
Winson Chunge4e50662012-01-23 14:45:13 -0800598
599 // Reset the pressed state of icons that were locked in the press state while activities
600 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800601 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800602 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800603 mWaitingForResume.setStayPressed(false);
604 }
Winson Chunge4e50662012-01-23 14:45:13 -0800605 if (mAppsCustomizeContent != null) {
606 // Resets the previous all apps icon press state
607 mAppsCustomizeContent.resetDrawableState();
608 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800609 }
610
611 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700612 protected void onPause() {
613 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700614 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800615 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700616 }
Romain Guycbb89e42009-06-08 15:52:54 -0700617
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700618 @Override
619 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400620 // Flag the loader to stop early before switching
621 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700622 if (mAppsCustomizeContent != null) {
623 mAppsCustomizeContent.surrender();
624 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800625 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700626 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700627
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800628 // We can't hide the IME if it was forced open. So don't bother
629 /*
630 @Override
631 public void onWindowFocusChanged(boolean hasFocus) {
632 super.onWindowFocusChanged(hasFocus);
633
634 if (hasFocus) {
635 final InputMethodManager inputManager = (InputMethodManager)
636 getSystemService(Context.INPUT_METHOD_SERVICE);
637 WindowManager.LayoutParams lp = getWindow().getAttributes();
638 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
639 android.os.Handler()) {
640 protected void onReceiveResult(int resultCode, Bundle resultData) {
641 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
642 }
643 });
644 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
645 }
646 }
647 */
648
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800649 private boolean acceptFilter() {
650 final InputMethodManager inputManager = (InputMethodManager)
651 getSystemService(Context.INPUT_METHOD_SERVICE);
652 return !inputManager.isFullscreenMode();
653 }
654
655 @Override
656 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700657 final int uniChar = event.getUnicodeChar();
658 final boolean handled = super.onKeyDown(keyCode, event);
659 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
660 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800661 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
662 keyCode, event);
663 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700664 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700665 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700666 // showSearchDialog()
667 // If there are multiple keystrokes before the search dialog takes focus,
668 // onSearchRequested() will be called for every keystroke,
669 // but it is idempotent, so it's fine.
670 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800671 }
672 }
673
Joe Onorato8a9625e2010-01-28 15:55:35 -0800674 // Eat the long press event so the keyboard doesn't come up.
675 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
676 return true;
677 }
678
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800679 return handled;
680 }
681
Karl Rosaen138a0412009-04-23 19:00:21 -0700682 private String getTypedText() {
683 return mDefaultKeySsb.toString();
684 }
685
686 private void clearTypedText() {
687 mDefaultKeySsb.clear();
688 mDefaultKeySsb.clearSpans();
689 Selection.setSelection(mDefaultKeySsb, 0);
690 }
691
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800692 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700693 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
694 * State
695 */
696 private static State intToState(int stateOrdinal) {
697 State state = State.WORKSPACE;
698 final State[] stateValues = State.values();
699 for (int i = 0; i < stateValues.length; i++) {
700 if (stateValues[i].ordinal() == stateOrdinal) {
701 state = stateValues[i];
702 break;
703 }
704 }
705 return state;
706 }
707
708 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800709 * Restores the previous state, if it exists.
710 *
711 * @param savedState The previous state.
712 */
713 private void restoreState(Bundle savedState) {
714 if (savedState == null) {
715 return;
716 }
717
Michael Jurka883f55b2010-10-21 15:47:14 -0700718 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700719 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800720 showAllApps(false);
721 }
722
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800723 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
724 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700725 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800726 }
727
Winson Chung3d503fb2011-07-13 17:25:49 -0700728 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
729 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700730
Winson Chung3d503fb2011-07-13 17:25:49 -0700731 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
732 mPendingAddInfo.container = pendingAddContainer;
733 mPendingAddInfo.screen = pendingAddScreen;
734 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
735 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800736 mRestoring = true;
737 }
738
739 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
740 if (renameFolder) {
741 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700742 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800743 mRestoring = true;
744 }
Winson Chunga12a2502010-12-20 14:41:35 -0800745
Winson Chung785d2eb2011-04-14 16:08:02 -0700746
747 // Restore the AppsCustomize tab
748 if (mAppsCustomizeTabHost != null) {
749 String curTab = savedState.getString("apps_customize_currentTab");
750 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700751 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700752 mAppsCustomizeContent.setContentType(
753 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
754 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700755 mAppsCustomizeContent.loadAssociatedPages(
756 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700757 }
758
Winson Chung5afbf7b2011-07-25 11:53:08 -0700759 int currentIndex = savedState.getInt("apps_customize_currentIndex");
760 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700761 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800762 }
763
764 /**
765 * Finds all the views we need and configure them properly.
766 */
767 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700768 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400769
Winson Chung4c98d922011-05-31 16:50:48 -0700770 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
771 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800772 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
773 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800774
Winson Chung4c98d922011-05-31 16:50:48 -0700775 // Setup the drag layer
776 mDragLayer.setup(this, dragController);
777
Winson Chung3d503fb2011-07-13 17:25:49 -0700778 // Setup the hotseat
779 mHotseat = (Hotseat) findViewById(R.id.hotseat);
780 if (mHotseat != null) {
781 mHotseat.setup(this);
782 }
783
Winson Chung4c98d922011-05-31 16:50:48 -0700784 // Setup the workspace
785 mWorkspace.setHapticFeedbackEnabled(false);
786 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700787 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700788 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700789
Winson Chungf0ea4d32011-06-06 14:27:16 -0700790 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700791 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700792
Winson Chungf0ea4d32011-06-06 14:27:16 -0700793 // Setup AppsCustomize
794 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
795 findViewById(R.id.apps_customize_pane);
796 mAppsCustomizeContent = (AppsCustomizePagedView)
797 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
798 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400799
Michael Jurka5130e402011-10-13 04:55:35 -0700800 // Get the all apps button
801 mAllAppsButton = findViewById(R.id.all_apps_button);
802 if (mAllAppsButton != null) {
803 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
804 @Override
805 public boolean onTouch(View v, MotionEvent event) {
806 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
807 onTouchDownAllAppsButton(v);
808 }
809 return false;
810 }
811 });
812 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700813 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700814 dragController.setDragScoller(mWorkspace);
815 dragController.setScrollView(mDragLayer);
816 dragController.setMoveTarget(mWorkspace);
817 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700818 if (mSearchDropTargetBar != null) {
819 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800820 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800821 }
822
823 /**
824 * Creates a view representing a shortcut.
825 *
826 * @param info The data structure describing the shortcut.
827 *
828 * @return A View inflated from R.layout.application.
829 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800830 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800831 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700832 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800833 }
834
835 /**
836 * Creates a view representing a shortcut inflated from the specified resource.
837 *
838 * @param layoutResId The id of the XML layout used to create the shortcut.
839 * @param parent The group the shortcut belongs to.
840 * @param info The data structure describing the shortcut.
841 *
842 * @return A View inflated from layoutResId.
843 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800844 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800845 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
846 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800847 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800848 return favorite;
849 }
850
851 /**
852 * Add an application shortcut to the workspace.
853 *
854 * @param data The intent describing the application.
855 * @param cellInfo The position on screen where to create the shortcut.
856 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700857 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700858 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700859 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700860
Adam Cohenfbba09b2011-07-18 21:43:05 -0700861 // First we check if we already know the exact location where we want to add this item.
862 if (cellX >= 0 && cellY >= 0) {
863 cellXY[0] = cellX;
864 cellXY[1] = cellY;
865 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700866 showOutOfSpaceMessage();
867 return;
868 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800869
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800870 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800871
Romain Guy73b979d2009-06-09 12:57:21 -0700872 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800873 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800874 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800875 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700876 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700877 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800878 } else {
879 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800880 }
881 }
Romain Guycbb89e42009-06-08 15:52:54 -0700882
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800883 /**
884 * Add a shortcut to the workspace.
885 *
886 * @param data The intent describing the shortcut.
887 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800888 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700889 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
890 int cellY) {
891 int[] cellXY = mTmpAddItemCellCoordinates;
892 int[] touchXY = mPendingAddInfo.dropPos;
893 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -0700894
Michael Jurkad3ef3062010-11-23 16:23:58 -0800895 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700896
Adam Cohen558baaf2011-08-15 15:22:57 -0700897 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -0800898 if (info == null) {
899 return;
900 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700901 final View view = createShortcut(info);
902
Adam Cohenfbba09b2011-07-18 21:43:05 -0700903 // First we check if we already know the exact location where we want to add this item.
904 if (cellX >= 0 && cellY >= 0) {
905 cellXY[0] = cellX;
906 cellXY[1] = cellY;
907 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -0700908
909 // If appropriate, either create a folder or add to an existing folder
910 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY,
911 true, null,null)) {
912 return;
913 }
914 DragObject dragObject = new DragObject();
915 dragObject.dragInfo = info;
916 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, dragObject, true)) {
917 return;
918 }
Adam Cohenfbba09b2011-07-18 21:43:05 -0700919 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800920 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700921 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800922 foundCellSpan = (result != null);
923 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700924 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800925 }
926
927 if (!foundCellSpan) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700928 showOutOfSpaceMessage();
929 return;
930 }
931
Adam Cohen558baaf2011-08-15 15:22:57 -0700932 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800933
934 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -0700935 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
936 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800937 }
938 }
939
Adam Cohenf814aa02011-09-01 13:48:05 -0700940 int[] getSpanForWidget(ComponentName component, int minWidth, int minHeight, int[] spanXY) {
941 if (spanXY == null) {
942 spanXY = new int[2];
943 }
944
Adam Cohen0cf2a7c2011-11-08 15:07:01 -0800945 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(this, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -0700946 // We want to account for the extra amount of padding that we are adding to the widget
947 // to ensure that it gets the full amount of space that it has requested
948 int requiredWidth = minWidth + padding.left + padding.right;
949 int requiredHeight = minHeight + padding.top + padding.bottom;
950 return CellLayout.rectToCell(getResources(), requiredWidth, requiredHeight, null);
951 }
952
953 int[] getSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
954 return getSpanForWidget(info.provider, info.minWidth, info.minHeight, spanXY);
955 }
956
Adam Cohencbf47e32011-09-16 17:32:37 -0700957 int[] getMinResizeSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
958 return getSpanForWidget(info.provider, info.minResizeWidth, info.minResizeHeight, spanXY);
959 }
960
Adam Cohenf814aa02011-09-01 13:48:05 -0700961 int[] getSpanForWidget(PendingAddWidgetInfo info, int[] spanXY) {
962 return getSpanForWidget(info.componentName, info.minWidth, info.minHeight, spanXY);
963 }
964
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800965 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700966 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800967 *
Romain Guy5bbc91b2010-08-18 11:38:46 -0700968 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700969 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800970 */
Adam Cohened66b2b2012-01-23 17:28:51 -0800971 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
972 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
973 if (appWidgetInfo == null) {
974 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
975 }
Romain Guycbb89e42009-06-08 15:52:54 -0700976
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700977 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -0700978 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -0700979
Adam Cohenf814aa02011-09-01 13:48:05 -0700980 int[] spanXY = getSpanForWidget(appWidgetInfo, null);
Romain Guycbb89e42009-06-08 15:52:54 -0700981
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800982 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -0700983 // We have saved the position to which the widget was dragged-- this really only matters
984 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -0700985 int[] cellXY = mTmpAddItemCellCoordinates;
986 int[] touchXY = mPendingAddInfo.dropPos;
Michael Jurka0280c3b2010-09-17 15:00:07 -0700987 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -0700988 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
989 cellXY[0] = mPendingAddInfo.cellX;
990 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700991 foundCellSpan = true;
992 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700993 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700994 int[] result = layout.findNearestVacantArea(
Michael Jurka0280c3b2010-09-17 15:00:07 -0700995 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800996 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700997 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700998 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -0700999 }
1000
Michael Jurka0280c3b2010-09-17 15:00:07 -07001001 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001002 if (appWidgetId != -1) {
1003 // Deleting an app widget ID is a void call but writes to disk before returning
1004 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001005 new Thread("deleteAppWidgetId") {
1006 public void run() {
1007 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1008 }
1009 }.start();
1010 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001011 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001012 return;
1013 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001014
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001015 // Build Launcher-specific widget info and save to database
Michael Jurkac9d95c52011-08-29 14:03:34 -07001016 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001017 launcherInfo.spanX = spanXY[0];
1018 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001019
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001020 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001021 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001022
1023 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001024 if (hostView == null) {
1025 // Perform actual inflation because we're live
1026 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1027 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1028 } else {
1029 // The AppWidgetHostView has already been inflated and instantiated
1030 launcherInfo.hostView = hostView;
1031 }
Romain Guycbb89e42009-06-08 15:52:54 -07001032
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001033 launcherInfo.hostView.setTag(launcherInfo);
Winson Chung3d503fb2011-07-13 17:25:49 -07001034 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001035 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001036
1037 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001038 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001039 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001040 }
Romain Guycbb89e42009-06-08 15:52:54 -07001041
Adam Cohended9f8d2010-11-03 13:25:16 -07001042 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1043 @Override
1044 public void onReceive(Context context, Intent intent) {
1045 final String action = intent.getAction();
1046 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1047 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001048 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001049 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001050
Winson Chungc100e8e2011-08-09 16:02:43 -07001051 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001052 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001053 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1054 mAppsCustomizeTabHost.reset();
1055 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001056 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001057 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1058 mUserPresent = true;
1059 updateRunning();
1060 }
1061 }
1062 };
1063
1064 @Override
1065 public void onAttachedToWindow() {
1066 super.onAttachedToWindow();
1067
1068 // Listen for broadcasts related to user-presence
1069 final IntentFilter filter = new IntentFilter();
1070 filter.addAction(Intent.ACTION_SCREEN_OFF);
1071 filter.addAction(Intent.ACTION_USER_PRESENT);
1072 registerReceiver(mReceiver, filter);
1073
Adam Cohend113e0c2010-11-11 10:48:05 -08001074 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001075 mVisible = true;
1076 }
1077
1078 @Override
1079 public void onDetachedFromWindow() {
1080 super.onDetachedFromWindow();
1081 mVisible = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001082 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001083
Adam Cohend113e0c2010-11-11 10:48:05 -08001084 if (mAttached) {
1085 unregisterReceiver(mReceiver);
1086 mAttached = false;
1087 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001088 updateRunning();
1089 }
1090
1091 public void onWindowVisibilityChanged(int visibility) {
1092 mVisible = visibility == View.VISIBLE;
1093 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001094 // The following code used to be in onResume, but it turns out onResume is called when
1095 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1096 // is a more appropriate event to handle
1097 if (mVisible) {
1098 mAppsCustomizeTabHost.onWindowVisible();
1099 if (!mWorkspaceLoading) {
1100 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001101 // We want to let Launcher draw itself at least once before we force it to build
1102 // layers on all the workspace pages, so that transitioning to Launcher from other
1103 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
1104 // a true draw so we wait until the second preDraw call to be safe
1105 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001106 public boolean onPreDraw() {
Michael Jurka6ee21d22012-02-21 18:20:27 -08001107 // We delay the layer building a bit in order to give
1108 // other message processing a time to run. In particular
1109 // this avoids a delay in hiding the IME if it was
1110 // currently shown, because doing that may involve
1111 // some communication back with the app.
1112 workspace.postDelayed(mBuildLayersRunnable, 500);
1113 observer.removeOnPreDrawListener(this);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001114 return true;
1115 }
1116 });
1117 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001118 // When Launcher comes back to foreground, a different Activity might be responsible for
1119 // the app market intent, so refresh the icon
1120 updateAppMarketIcon();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001121 clearTypedText();
1122 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001123 }
1124
1125 private void sendAdvanceMessage(long delay) {
1126 mHandler.removeMessages(ADVANCE_MSG);
1127 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1128 mHandler.sendMessageDelayed(msg, delay);
1129 mAutoAdvanceSentTime = System.currentTimeMillis();
1130 }
1131
1132 private void updateRunning() {
1133 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1134 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1135 mAutoAdvanceRunning = autoAdvanceRunning;
1136 if (autoAdvanceRunning) {
1137 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1138 sendAdvanceMessage(delay);
1139 } else {
1140 if (!mWidgetsToAdvance.isEmpty()) {
1141 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1142 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1143 }
1144 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001145 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001146 }
1147 }
1148 }
1149
1150 private final Handler mHandler = new Handler() {
1151 @Override
1152 public void handleMessage(Message msg) {
1153 if (msg.what == ADVANCE_MSG) {
1154 int i = 0;
1155 for (View key: mWidgetsToAdvance.keySet()) {
1156 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1157 final int delay = mAdvanceStagger * i;
1158 if (v instanceof Advanceable) {
1159 postDelayed(new Runnable() {
1160 public void run() {
1161 ((Advanceable) v).advance();
1162 }
1163 }, delay);
1164 }
1165 i++;
1166 }
1167 sendAdvanceMessage(mAdvanceInterval);
1168 }
1169 }
1170 };
1171
1172 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001173 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001174 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1175 if (v instanceof Advanceable) {
1176 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001177 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001178 updateRunning();
1179 }
1180 }
1181
1182 void removeWidgetToAutoAdvance(View hostView) {
1183 if (mWidgetsToAdvance.containsKey(hostView)) {
1184 mWidgetsToAdvance.remove(hostView);
1185 updateRunning();
1186 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001187 }
1188
Joe Onorato9c1289c2009-08-17 11:03:03 -04001189 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001190 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001191 launcherInfo.hostView = null;
1192 }
1193
Adam Cohended9f8d2010-11-03 13:25:16 -07001194 void showOutOfSpaceMessage() {
1195 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1196 }
1197
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001198 public LauncherAppWidgetHost getAppWidgetHost() {
1199 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001200 }
Romain Guycbb89e42009-06-08 15:52:54 -07001201
Winson Chunga9abd0e2010-10-27 17:18:37 -07001202 public LauncherModel getModel() {
1203 return mModel;
1204 }
1205
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001206 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001207 getWindow().closeAllPanels();
1208
Winson Chung87acb482011-08-23 17:28:05 -07001209 /**
1210 * We should remove this code when we remove all the dialog code.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001211 try {
1212 dismissDialog(DIALOG_CREATE_SHORTCUT);
1213 // Unlock the workspace if the dialog was showing
1214 } catch (Exception e) {
1215 // An exception is thrown if the dialog is not visible, which is fine
1216 }
1217
1218 try {
1219 dismissDialog(DIALOG_RENAME_FOLDER);
1220 // Unlock the workspace if the dialog was showing
1221 } catch (Exception e) {
1222 // An exception is thrown if the dialog is not visible, which is fine
1223 }
Winson Chung87acb482011-08-23 17:28:05 -07001224 */
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001225
1226 // Whatever we were doing is hereby canceled.
1227 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001228 }
1229
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001230 @Override
1231 protected void onNewIntent(Intent intent) {
1232 super.onNewIntent(intent);
1233
1234 // Close the menu
1235 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001236 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001237 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001238
Joe Onorato14f122b2009-11-19 14:06:36 -08001239 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1240 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001241
Adam Cohenac56cff2011-09-28 20:45:37 -07001242 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001243 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001244 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001245 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1246 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001247 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001248 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001249
1250 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001251 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001252 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001253
Joe Onorato3a8820b2009-11-10 15:06:42 -08001254 final View v = getWindow().peekDecorView();
1255 if (v != null && v.getWindowToken() != null) {
1256 InputMethodManager imm = (InputMethodManager)getSystemService(
1257 INPUT_METHOD_SERVICE);
1258 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001260
Michael Jurka35aa14d2011-07-07 17:01:08 -07001261 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001262 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001263 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001264 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265 }
1266 }
1267
1268 @Override
1269 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1270 // Do not call super here
1271 mSavedInstanceState = savedInstanceState;
1272 }
1273
1274 @Override
1275 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001276 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001277 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001278
Michael Jurka883f55b2010-10-21 15:47:14 -07001279 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001280 // We close any open folder since it will not be re-opened, and we need to make sure
1281 // this state is reflected.
1282 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001283
Winson Chung3d503fb2011-07-13 17:25:49 -07001284 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1285 mWaitingForResult) {
1286 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1287 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1288 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1289 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001290 }
1291
1292 if (mFolderInfo != null && mWaitingForResult) {
1293 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1294 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1295 }
Michael Jurka946ad472010-07-09 18:05:18 -07001296
Winson Chung785d2eb2011-04-14 16:08:02 -07001297 // Save the current AppsCustomize tab
1298 if (mAppsCustomizeTabHost != null) {
1299 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1300 if (currentTabTag != null) {
1301 outState.putString("apps_customize_currentTab", currentTabTag);
1302 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001303 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1304 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001305 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001306 }
1307
1308 @Override
1309 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001310 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001311
Winson Chunge7a03942011-08-05 15:05:12 -07001312 // Remove all pending runnables
1313 mHandler.removeMessages(ADVANCE_MSG);
1314 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001315 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001316
Winson Chungcd2b0142011-06-08 16:02:26 -07001317 // Stop callbacks from LauncherModel
1318 LauncherApplication app = ((LauncherApplication) getApplication());
1319 mModel.stopLoader();
1320 app.setLauncher(null);
1321
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001322 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001323 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001324 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001325 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001326 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001327 mAppWidgetHost = null;
1328
1329 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001330
1331 TextKeyListener.getInstance().release();
1332
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001333
Winson Chung3d503fb2011-07-13 17:25:49 -07001334 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001335
1336 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001337 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001338
1339 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1340 mWorkspace.removeAllViews();
1341 mWorkspace = null;
1342 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001343
1344 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001345 }
1346
Adam Cohena9cf38f2011-05-02 15:36:58 -07001347 public DragController getDragController() {
1348 return mDragController;
1349 }
1350
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001351 @Override
1352 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001353 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001354 super.startActivityForResult(intent, requestCode);
1355 }
1356
Winson Chung70d72102011-08-12 11:24:35 -07001357 /**
1358 * Indicates that we want global search for this activity by setting the globalSearch
1359 * argument for {@link #startSearch} to true.
1360 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001361 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001362 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001363 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001364
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001365 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001366
Karl Rosaen138a0412009-04-23 19:00:21 -07001367 if (initialQuery == null) {
1368 // Use any text typed in the launcher as the initial query
1369 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001370 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001371 if (appSearchData == null) {
1372 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001373 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001374 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001375 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001376
Karl Rosaen138a0412009-04-23 19:00:21 -07001377 final SearchManager searchManager =
1378 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001379 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001380 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001381 }
1382
Winson Chung70d72102011-08-12 11:24:35 -07001383 @Override
1384 public boolean onCreateOptionsMenu(Menu menu) {
1385 if (isWorkspaceLocked()) {
1386 return false;
1387 }
1388
1389 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001390
1391 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1392 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1393 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001394 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1395 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1396 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001397 String helpUrl = getString(R.string.help_url);
1398 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001399 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1400 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1401
Winson Chung70d72102011-08-12 11:24:35 -07001402 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1403 .setIcon(android.R.drawable.ic_menu_gallery)
1404 .setAlphabeticShortcut('W');
1405 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1406 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001407 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001408 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001409 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1410 .setIcon(android.R.drawable.ic_menu_preferences)
1411 .setIntent(settings)
1412 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001413 if (!helpUrl.isEmpty()) {
1414 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1415 .setIcon(android.R.drawable.ic_menu_help)
1416 .setIntent(help)
1417 .setAlphabeticShortcut('H');
1418 }
Winson Chung70d72102011-08-12 11:24:35 -07001419 return true;
1420 }
1421
1422 @Override
1423 public boolean onPrepareOptionsMenu(Menu menu) {
1424 super.onPrepareOptionsMenu(menu);
1425
1426 if (mAppsCustomizeTabHost.isTransitioning()) {
1427 return false;
1428 }
1429 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1430 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1431
1432 return true;
1433 }
1434
1435 @Override
1436 public boolean onOptionsItemSelected(MenuItem item) {
1437 switch (item.getItemId()) {
1438 case MENU_WALLPAPER_SETTINGS:
1439 startWallpaper();
1440 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001441 }
1442
1443 return super.onOptionsItemSelected(item);
1444 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001445
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001446 @Override
1447 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001448 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001449 // Use a custom animation for launching search
1450 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001451 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001452 }
1453
Joe Onorato9c1289c2009-08-17 11:03:03 -04001454 public boolean isWorkspaceLocked() {
1455 return mWorkspaceLoading || mWaitingForResult;
1456 }
1457
Michael Jurka0280c3b2010-09-17 15:00:07 -07001458 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001459 mPendingAddInfo.container = ItemInfo.NO_ID;
1460 mPendingAddInfo.screen = -1;
1461 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1462 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
1463 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001464 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001465
Michael Jurkaaf442092010-06-10 17:01:57 -07001466 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001467 // TODO: catch bad widget exception when sent
1468 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001469 // TODO: Is this log message meaningful?
1470 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001471 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001472 }
1473
Adam Cohened66b2b2012-01-23 17:28:51 -08001474 void addAppWidgetImpl(final int appWidgetId, final PendingAddWidgetInfo info) {
1475 final AppWidgetProviderInfo appWidget = info.info;
1476 Runnable configurationActivity = null;
Bjorn Bringert7984c942009-12-09 15:38:25 +00001477 if (appWidget.configure != null) {
1478 // Launch over to configure widget, if needed
1479 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1480 intent.setComponent(appWidget.configure);
1481 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001482 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001483 if (info.mimeType != null && !info.mimeType.isEmpty()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001484 intent.putExtra(InstallWidgetReceiver.
1485 EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE, info.mimeType);
Winson Chung68846fd2010-10-29 11:00:27 -07001486
1487 final String mimeType = info.mimeType;
1488 final ClipData clipData = (ClipData) info.configurationData;
1489 final ClipDescription clipDesc = clipData.getDescription();
1490 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1491 if (clipDesc.getMimeType(i).equals(mimeType)) {
Dianne Hackborn0d5aad72011-01-17 15:28:58 -08001492 final ClipData.Item item = clipData.getItemAt(i);
Winson Chung68846fd2010-10-29 11:00:27 -07001493 final CharSequence stringData = item.getText();
1494 final Uri uriData = item.getUri();
1495 final Intent intentData = item.getIntent();
Adam Cohened66b2b2012-01-23 17:28:51 -08001496 final String key = InstallWidgetReceiver.
1497 EXTRA_APPWIDGET_CONFIGURATION_DATA;
Winson Chung68846fd2010-10-29 11:00:27 -07001498 if (uriData != null) {
1499 intent.putExtra(key, uriData);
1500 } else if (intentData != null) {
1501 intent.putExtra(key, intentData);
1502 } else if (stringData != null) {
1503 intent.putExtra(key, stringData);
1504 }
1505 break;
1506 }
1507 }
1508 }
Winson Chung55cef262010-10-28 14:14:18 -07001509 }
Romain Guy8e633c52010-03-04 12:51:36 -08001510 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
Adam Cohened66b2b2012-01-23 17:28:51 -08001511 mWidgetBeingConfigured = info;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001512 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001513 // Otherwise just add it
Adam Cohened66b2b2012-01-23 17:28:51 -08001514 completeAddAppWidget(appWidgetId, info.container, info.screen, info.boundWidget, appWidget);
Winson Chung557d6ed2011-07-08 15:34:52 -07001515 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001516 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001517 }
1518 }
Romain Guycbb89e42009-06-08 15:52:54 -07001519
Adam Cohenfbba09b2011-07-18 21:43:05 -07001520 /**
1521 * Process a shortcut drop.
1522 *
1523 * @param componentName The name of the component
1524 * @param screen The screen where it should be added
1525 * @param cell The cell it should be added to, optional
1526 * @param position The location on the screen where it was dropped, optional
1527 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001528 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1529 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001530 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001531 mPendingAddInfo.container = container;
1532 mPendingAddInfo.screen = screen;
1533 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001534
1535 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001536 mPendingAddInfo.cellX = cell[0];
1537 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001538 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001539
1540 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1541 createShortcutIntent.setComponent(componentName);
1542 processShortcut(createShortcutIntent);
1543 }
1544
Adam Cohenfbba09b2011-07-18 21:43:05 -07001545 /**
1546 * Process a widget drop.
1547 *
1548 * @param info The PendingAppWidgetInfo of the widget being added.
1549 * @param screen The screen where it should be added
1550 * @param cell The cell it should be added to, optional
1551 * @param position The location on the screen where it was dropped, optional
1552 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001553 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
1554 int[] cell, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001555 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001556 mPendingAddInfo.container = info.container = container;
1557 mPendingAddInfo.screen = info.screen = screen;
1558 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001559 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001560 mPendingAddInfo.cellX = cell[0];
1561 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001562 }
1563
Adam Cohened66b2b2012-01-23 17:28:51 -08001564 AppWidgetHostView hostView = info.boundWidget;
1565 int appWidgetId;
1566 if (hostView != null) {
1567 appWidgetId = hostView.getAppWidgetId();
1568 } else {
1569 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1570 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1571 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001572 addAppWidgetImpl(appWidgetId, info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001573
Adam Cohenfbba09b2011-07-18 21:43:05 -07001574 }
1575
Joe Onoratodeb98af2010-02-19 14:59:39 -08001576 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001577 // Handle case where user selected "Applications"
1578 String applicationName = getResources().getString(R.string.group_applications);
1579 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001580
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001581 if (applicationName != null && applicationName.equals(shortcutName)) {
1582 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1583 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001584
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001585 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1586 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001587 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001588 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001589 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001590 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001591 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001592 }
1593
Winson Chung24ab2f12010-09-16 14:10:47 -07001594 void processWallpaper(Intent intent) {
1595 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1596 }
1597
Winson Chung3d503fb2011-07-13 17:25:49 -07001598 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1599 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001600 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001601 folderInfo.title = getText(R.string.folder_name);
1602
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001603 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001604 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1605 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001606 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001607
1608 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001609 FolderIcon newFolder =
1610 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1611 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1612 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001613 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001614 }
Romain Guycbb89e42009-06-08 15:52:54 -07001615
Joe Onorato9c1289c2009-08-17 11:03:03 -04001616 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001617 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001618 }
1619
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001620 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001621 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001622 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001623 Intent chooser = Intent.createChooser(pickWallpaper,
1624 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001625 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1626 // Removed in Eclair MR1
1627// WallpaperManager wm = (WallpaperManager)
1628// getSystemService(Context.WALLPAPER_SERVICE);
1629// WallpaperInfo wi = wm.getWallpaperInfo();
1630// if (wi != null && wi.getSettingsActivity() != null) {
1631// LabeledIntent li = new LabeledIntent(getPackageName(),
1632// R.string.configure_wallpaper, 0);
1633// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1634// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1635// }
Mike Clerona0618e42009-10-22 13:55:21 -07001636 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001637 }
1638
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001639 /**
1640 * Registers various content observers. The current implementation registers
1641 * only a favorites observer to keep track of the favorites applications.
1642 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001643 private void registerContentObservers() {
1644 ContentResolver resolver = getContentResolver();
1645 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1646 true, mWidgetObserver);
1647 }
1648
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001649 @Override
1650 public boolean dispatchKeyEvent(KeyEvent event) {
1651 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1652 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001653 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001654 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001655 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001656 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001657 dumpState();
1658 return true;
1659 }
1660 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001661 }
1662 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1663 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001664 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001665 return true;
1666 }
1667 }
1668
1669 return super.dispatchKeyEvent(event);
1670 }
1671
Joe Onorato88ec0992009-11-19 13:16:06 -08001672 @Override
1673 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001674 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001675 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001676 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001677 Folder openFolder = mWorkspace.getOpenFolder();
1678 if (openFolder.isEditingName()) {
1679 openFolder.dismissEditingName();
1680 } else {
1681 closeFolder();
1682 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001683 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001684 mWorkspace.exitWidgetResizeMode();
1685
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001686 // Back button is a no-op here, but give at least some feedback for the button press
1687 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001688 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001689 }
1690
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001691 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001692 * Re-listen when widgets are reset.
1693 */
1694 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001695 if (mAppWidgetHost != null) {
1696 mAppWidgetHost.startListening();
1697 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001698 }
1699
1700 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001701 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1702 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001703 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001704 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001705 if (mModel != null) {
1706 mModel.unbindWorkspaceItems();
1707 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001708 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001709
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001710 /**
1711 * Launches the intent referred by the clicked shortcut.
1712 *
1713 * @param v The view representing the clicked shortcut.
1714 */
1715 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001716 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1717 // view has detached (it's possible for this to happen if the view is removed mid touch).
1718 if (v.getWindowToken() == null) {
1719 return;
1720 }
1721
1722 if (mWorkspace.isSwitchingState()) {
1723 return;
1724 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001725
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001726 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001727 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001728 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001729 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001730 int[] pos = new int[2];
1731 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001732 intent.setSourceBounds(new Rect(pos[0], pos[1],
1733 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Michael Jurkaddd62e92011-02-16 17:49:14 -08001734 boolean success = startActivitySafely(intent, tag);
1735
1736 if (success && v instanceof BubbleTextView) {
1737 mWaitingForResume = (BubbleTextView) v;
1738 mWaitingForResume.setStayPressed(true);
1739 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001740 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001741 if (v instanceof FolderIcon) {
1742 FolderIcon fi = (FolderIcon) v;
1743 handleFolderClick(fi);
1744 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001745 } else if (v == mAllAppsButton) {
1746 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001747 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001748 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001749 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001750 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001751 }
1752 }
1753
Michael Jurka0e260592010-06-30 17:07:39 -07001754 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001755 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001756 // clicking anywhere on the workspace causes the customization drawer to slide down
1757 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001758 return false;
1759 }
1760
Michael Jurkaaf442092010-06-10 17:01:57 -07001761 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001762 * Event handler for the search button
1763 *
1764 * @param v The view that was clicked.
1765 */
1766 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001767 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1768
Amith Yamasania135ba82011-08-09 17:42:01 -07001769 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001770 }
1771
1772 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001773 * Event handler for the voice button
1774 *
1775 * @param v The view that was clicked.
1776 */
1777 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001778 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001779
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001780 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001781 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001782 startActivity(intent);
1783 }
1784
1785 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001786 * Event handler for the "grid" button that appears on the home screen, which
1787 * enters all apps mode.
1788 *
1789 * @param v The view that was clicked.
1790 */
1791 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001792 showAllApps(true);
1793 }
1794
1795 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001796 // Provide the same haptic feedback that the system offers for virtual keys.
1797 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001798 }
1799
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001800 public void onClickAppMarketButton(View v) {
1801 if (mAppMarketIntent != null) {
1802 startActivitySafely(mAppMarketIntent, "app market");
1803 }
1804 }
1805
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001806 void startApplicationDetailsActivity(ComponentName componentName) {
1807 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001808 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1809 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001810 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001811 startActivity(intent);
1812 }
1813
Patrick Dubroy5539af72010-09-07 15:22:01 -07001814 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1815 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1816 // System applications cannot be installed. For now, show a toast explaining that.
1817 // We may give them the option of disabling apps this way.
1818 int messageId = R.string.uninstall_system_app_text;
1819 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1820 } else {
1821 String packageName = appInfo.componentName.getPackageName();
1822 String className = appInfo.componentName.getClassName();
1823 Intent intent = new Intent(
1824 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001825 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1826 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001827 startActivity(intent);
1828 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001829 }
1830
Michael Jurkaddd62e92011-02-16 17:49:14 -08001831 boolean startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001832 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1833 try {
1834 startActivity(intent);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001835 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001836 } catch (ActivityNotFoundException e) {
1837 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001838 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001839 } catch (SecurityException e) {
1840 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001841 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001842 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001843 "or use the exported attribute for this activity. "
1844 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001845 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001846 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001847 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001848
Romain Guy8e633c52010-03-04 12:51:36 -08001849 void startActivityForResultSafely(Intent intent, int requestCode) {
1850 try {
1851 startActivityForResult(intent, requestCode);
1852 } catch (ActivityNotFoundException e) {
1853 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1854 } catch (SecurityException e) {
1855 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1856 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1857 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1858 "or use the exported attribute for this activity.", e);
1859 }
1860 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001861
Adam Cohena9cf38f2011-05-02 15:36:58 -07001862 private void handleFolderClick(FolderIcon folderIcon) {
1863 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07001864 Folder openFolder = mWorkspace.getFolderForTag(info);
1865
1866 // If the folder info reports that the associated folder is open, then verify that
1867 // it is actually opened. There have been a few instances where this gets out of sync.
1868 if (info.opened && openFolder == null) {
1869 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
1870 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
1871 info.opened = false;
1872 }
1873
Adam Cohena9cf38f2011-05-02 15:36:58 -07001874 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001875 // Close any open folder
1876 closeFolder();
1877 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07001878 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001879 } else {
1880 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001881 int folderScreen;
1882 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001883 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001884 // .. and close it
1885 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001886 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001887 // Close any folder open on the current screen
1888 closeFolder();
1889 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07001890 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001891 }
1892 }
1893 }
1894 }
1895
Adam Cohen2801caf2011-05-13 20:57:39 -07001896 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001897 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001898 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
1899 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
1900 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
1901
Adam Cohenc51934b2011-07-26 21:07:43 -07001902 FolderInfo info = (FolderInfo) fi.getTag();
1903 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1904 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07001905 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
1906 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07001907 }
1908
Adam Cohen2801caf2011-05-13 20:57:39 -07001909 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1910 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1911 oa.start();
1912 }
1913
1914 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001915 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001916 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1917 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1918 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1919
Adam Cohenc51934b2011-07-26 21:07:43 -07001920 FolderInfo info = (FolderInfo) fi.getTag();
1921 CellLayout cl = null;
1922 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1923 cl = (CellLayout) fi.getParent().getParent();
1924 }
1925
1926 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07001927 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1928 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07001929 oa.addListener(new AnimatorListenerAdapter() {
1930 @Override
1931 public void onAnimationEnd(Animator animation) {
1932 if (layout != null) {
1933 layout.clearFolderLeaveBehind();
1934 }
1935 }
1936 });
Adam Cohen2801caf2011-05-13 20:57:39 -07001937 oa.start();
1938 }
1939
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001940 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001941 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001942 * is animated relative to the specified View. If the View is null, no animation
1943 * is played.
1944 *
1945 * @param folderInfo The FolderInfo describing the folder to open.
1946 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001947 public void openFolder(FolderIcon folderIcon) {
1948 Folder folder = folderIcon.mFolder;
1949 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001950
Adam Cohen2801caf2011-05-13 20:57:39 -07001951 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001952 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001953
Adam Cohen4554ee12011-08-03 16:13:21 -07001954 // Just verify that the folder hasn't already been added to the DragLayer.
1955 // There was a one-off crash where the folder had a parent already.
1956 if (folder.getParent() == null) {
1957 mDragLayer.addView(folder);
1958 mDragController.addDropTarget((DropTarget) folder);
1959 } else {
1960 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
1961 folder.getParent() + ").");
1962 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001963 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07001964 }
1965
1966 public void closeFolder() {
1967 Folder folder = mWorkspace.getOpenFolder();
1968 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07001969 if (folder.isEditingName()) {
1970 folder.dismissEditingName();
1971 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001972 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07001973
1974 // Dismiss the folder cling
1975 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07001976 }
1977 }
1978
1979 void closeFolder(Folder folder) {
1980 folder.getInfo().opened = false;
1981
1982 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
1983 if (parent != null) {
1984 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
1985 shrinkAndFadeInFolderIcon(fi);
1986 }
1987 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001988 }
1989
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001990 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08001991 if (mState != State.WORKSPACE) {
1992 return false;
1993 }
1994
Joe Onorato9c1289c2009-08-17 11:03:03 -04001995 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001996 return false;
1997 }
1998
1999 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002000 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002001 }
2002
Michael Jurka0280c3b2010-09-17 15:00:07 -07002003 resetAddInfo();
2004 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002005 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002006 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002007 return true;
2008 }
2009
Winson Chung3d503fb2011-07-13 17:25:49 -07002010 // The hotseat touch handling does not go through Workspace, and we always allow long press
2011 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002012 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002013 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2014 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002015 if (itemUnderLongClick == null) {
2016 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002017 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2018 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002019 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002020 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002021 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002022 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002023 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002024 }
2025 }
2026 }
2027 return true;
2028 }
2029
Winson Chung3d503fb2011-07-13 17:25:49 -07002030 boolean isHotseatLayout(View layout) {
2031 return mHotseat != null && layout != null &&
2032 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2033 }
2034 Hotseat getHotseat() {
2035 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002036 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002037 SearchDropTargetBar getSearchBar() {
2038 return mSearchDropTargetBar;
2039 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002040
Winson Chung3d503fb2011-07-13 17:25:49 -07002041 /**
2042 * Returns the CellLayout of the specified container at the specified screen.
2043 */
2044 CellLayout getCellLayout(long container, int screen) {
2045 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2046 if (mHotseat != null) {
2047 return mHotseat.getLayout();
2048 } else {
2049 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002050 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002051 } else {
2052 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002053 }
2054 }
2055
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002056 Workspace getWorkspace() {
2057 return mWorkspace;
2058 }
2059
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002060 @Override
2061 protected Dialog onCreateDialog(int id) {
2062 switch (id) {
2063 case DIALOG_CREATE_SHORTCUT:
2064 return new CreateShortcut().createDialog();
2065 case DIALOG_RENAME_FOLDER:
2066 return new RenameFolder().createDialog();
2067 }
2068
2069 return super.onCreateDialog(id);
2070 }
2071
2072 @Override
2073 protected void onPrepareDialog(int id, Dialog dialog) {
2074 switch (id) {
2075 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002076 break;
2077 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002078 if (mFolderInfo != null) {
2079 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2080 final CharSequence text = mFolderInfo.title;
2081 input.setText(text);
2082 input.setSelection(0, text.length());
2083 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002084 break;
2085 }
2086 }
2087
2088 void showRenameDialog(FolderInfo info) {
2089 mFolderInfo = info;
2090 mWaitingForResult = true;
2091 showDialog(DIALOG_RENAME_FOLDER);
2092 }
2093
Adam Cohenfbba09b2011-07-18 21:43:05 -07002094 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002095 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002096 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
2097 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002098 mWaitingForResult = true;
2099 showDialog(DIALOG_CREATE_SHORTCUT);
2100 }
2101
2102 private class RenameFolder {
2103 private EditText mInput;
2104
2105 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002106 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2107 mInput = (EditText) layout.findViewById(R.id.folder_name);
2108
2109 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2110 builder.setIcon(0);
2111 builder.setTitle(getString(R.string.rename_folder_title));
2112 builder.setCancelable(true);
2113 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2114 public void onCancel(DialogInterface dialog) {
2115 cleanup();
2116 }
2117 });
2118 builder.setNegativeButton(getString(R.string.cancel_action),
2119 new Dialog.OnClickListener() {
2120 public void onClick(DialogInterface dialog, int which) {
2121 cleanup();
2122 }
2123 }
2124 );
2125 builder.setPositiveButton(getString(R.string.rename_action),
2126 new Dialog.OnClickListener() {
2127 public void onClick(DialogInterface dialog, int which) {
2128 changeFolderName();
2129 }
2130 }
2131 );
2132 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002133
2134 final AlertDialog dialog = builder.create();
2135 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2136 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002137 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002138 mInput.requestFocus();
2139 InputMethodManager inputManager = (InputMethodManager)
2140 getSystemService(Context.INPUT_METHOD_SERVICE);
2141 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002142 }
2143 });
2144
2145 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002146 }
2147
2148 private void changeFolderName() {
2149 final String name = mInput.getText().toString();
2150 if (!TextUtils.isEmpty(name)) {
2151 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002152 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002153 mFolderInfo.title = name;
2154 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2155
Joe Onorato9c1289c2009-08-17 11:03:03 -04002156 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002157 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002158 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002159 } else {
2160 final FolderIcon folderIcon = (FolderIcon)
2161 mWorkspace.getViewForTag(mFolderInfo);
2162 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002163 // TODO: At some point we'll probably want some version of setting
2164 // the text for a folder icon.
2165 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002166 getWorkspace().requestLayout();
2167 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002168 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002169 mWorkspaceLoading = true;
2170 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002171 }
2172 }
2173 }
2174 cleanup();
2175 }
2176
2177 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002178 dismissDialog(DIALOG_RENAME_FOLDER);
2179 mWaitingForResult = false;
2180 mFolderInfo = null;
2181 }
2182 }
2183
Daniel Sandler843e8602010-06-07 14:59:01 -04002184 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2185 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002186 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002187 }
2188
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002189 // AllAppsView.Watcher
2190 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002191 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002192 mWorkspace.setVisibility(View.GONE);
2193 }
2194 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002195
2196 /**
2197 * Helper method for the cameraZoomIn/cameraZoomOut animations
2198 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002199 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002200 * @param scaleFactor The scale factor used for the zoom
2201 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002202 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002203 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002204 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002205 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002206
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002207 void updateWallpaperVisibility(boolean visible) {
2208 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2209 int curflags = getWindow().getAttributes().flags
2210 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2211 if (wpflags != curflags) {
2212 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2213 }
2214 }
2215
Michael Jurkabed61d22012-02-14 22:51:29 -08002216 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2217 if (v instanceof LauncherTransitionable) {
2218 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2219 }
2220 }
2221
2222 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2223 if (v instanceof LauncherTransitionable) {
2224 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2225 }
2226 }
2227
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002228 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002229 * Things to test when changing the following seven functions.
2230 * - Home from workspace
2231 * - from center screen
2232 * - from other screens
2233 * - Home from all apps
2234 * - from center screen
2235 * - from other screens
2236 * - Back from all apps
2237 * - from center screen
2238 * - from other screens
2239 * - Launch app from workspace and quit
2240 * - with back
2241 * - with home
2242 * - Launch app from all apps and quit
2243 * - with back
2244 * - with home
2245 * - Go to a screen that's not the default, then all
2246 * apps, and launch and app, and go back
2247 * - with back
2248 * -with home
2249 * - On workspace, long press power and go back
2250 * - with back
2251 * - with home
2252 * - On all apps, long press power and go back
2253 * - with back
2254 * - with home
2255 * - On workspace, power off
2256 * - On all apps, power off
2257 * - Launch an app and turn off the screen while in that app
2258 * - Go back with home key
2259 * - Go back with back key TODO: make this not go to workspace
2260 * - From all apps
2261 * - From workspace
2262 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2263 * - From all apps
2264 * - From the center workspace
2265 * - From another workspace
2266 */
2267
2268 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002269 * Zoom the camera out from the workspace to reveal 'toView'.
2270 * Assumes that the view to show is anchored at either the very top or very bottom
2271 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002272 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002273 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002274 if (mStateAnimation != null) {
2275 mStateAnimation.cancel();
2276 mStateAnimation = null;
2277 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002278 final Resources res = getResources();
Winson Chung7d7541e2011-09-16 20:14:36 -07002279 final Launcher instance = this;
Adam Cohenf16e5712011-01-13 13:31:45 -08002280
Winson Chungf0ea4d32011-06-06 14:27:16 -07002281 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2282 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2283 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002284 final View fromView = mWorkspace;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002285 final View toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002286 final int startDelay =
2287 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002288
Michael Jurkab3e22d92011-10-31 15:58:33 -07002289 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002290
Michael Jurkad74c9842011-07-10 12:44:21 -07002291 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002292 Animator workspaceAnim =
2293 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002294
2295 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002296 toView.setScaleX(scale);
2297 toView.setScaleY(scale);
2298 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2299 scaleAnim.
2300 scaleX(1f).scaleY(1f).
2301 setDuration(duration).
2302 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002303
Winson Chungf0ea4d32011-06-06 14:27:16 -07002304 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002305 toView.setAlpha(0f);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002306 final ObjectAnimator alphaAnim = ObjectAnimator
2307 .ofFloat(toView, "alpha", 0f, 1f)
2308 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002309 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Adam Cohenf16e5712011-01-13 13:31:45 -08002310
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002311 // toView should appear right at the end of the workspace shrink
2312 // animation
2313 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002314 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002315 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002316
2317 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002318 boolean animationCancelled = false;
2319
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002320 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002321 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002322 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002323 // Prepare the position
2324 toView.setTranslationX(0.0f);
2325 toView.setTranslationY(0.0f);
2326 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002327 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002328 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002329 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002330 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002331 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2332 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002333
2334 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2335 // Hide the workspace scrollbar
2336 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002337 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002338 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002339 if (!animationCancelled) {
2340 updateWallpaperVisibility(false);
2341 }
2342 }
2343
Adam Cohencff6af82011-09-13 14:51:53 -07002344 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002345 public void onAnimationCancel(Animator animation) {
2346 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002347 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002348 });
2349
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002350 if (workspaceAnim != null) {
2351 mStateAnimation.play(workspaceAnim);
2352 }
Michael Jurka1899a362011-11-03 13:50:45 -07002353
2354 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002355 final ViewTreeObserver observer;
2356
Michael Jurkabed61d22012-02-14 22:51:29 -08002357 dispatchOnLauncherTransitionStart(fromView, animated, false);
2358 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002359
2360 // If any of the objects being animated haven't been measured/laid out
2361 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002362 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002363 (mWorkspace.getMeasuredWidth() == 0) ||
2364 (toView.getMeasuredWidth() == 0)) {
2365 observer = mWorkspace.getViewTreeObserver();
2366 delayAnim = true;
2367 } else {
2368 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002369 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002370
2371 if (delayAnim) {
Michael Jurka49779a12012-01-16 04:10:08 -08002372 final AnimatorSet stateAnimation = mStateAnimation;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002373 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2374 public void onGlobalLayout() {
2375 mWorkspace.post(new Runnable() {
2376 public void run() {
Michael Jurka49779a12012-01-16 04:10:08 -08002377 // Check that mStateAnimation hasn't changed while
2378 // we waited for a layout pass
2379 if (mStateAnimation == stateAnimation) {
2380 // Need to update pivots for zoom if layout changed
2381 setPivotsForZoom(toView, scale);
2382 mStateAnimation.start();
2383 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002384 }
2385 });
2386 observer.removeGlobalOnLayoutListener(this);
2387 }
2388 };
2389 observer.addOnGlobalLayoutListener(delayedStart);
2390 } else {
2391 setPivotsForZoom(toView, scale);
Michael Jurka1899a362011-11-03 13:50:45 -07002392 mStateAnimation.start();
2393 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002394 } else {
2395 toView.setTranslationX(0.0f);
2396 toView.setTranslationY(0.0f);
2397 toView.setScaleX(1.0f);
2398 toView.setScaleY(1.0f);
2399 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002400 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002401
Michael Jurkabed61d22012-02-14 22:51:29 -08002402 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2403 // Hide the workspace scrollbar
2404 mWorkspace.hideScrollingIndicator(true);
2405 hideDockDivider();
Michael Jurkaabded662011-03-04 12:06:57 -08002406 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002407 dispatchOnLauncherTransitionStart(fromView, animated, false);
2408 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2409 dispatchOnLauncherTransitionStart(toView, animated, false);
2410 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002411 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002412 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002413 }
2414
2415 /**
2416 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002417 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002418 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002419 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002420 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2421 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002422
Michael Jurkab3e22d92011-10-31 15:58:33 -07002423 if (mStateAnimation != null) {
2424 mStateAnimation.cancel();
2425 mStateAnimation = null;
2426 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002427 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002428
Winson Chungf0ea4d32011-06-06 14:27:16 -07002429 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002430 final int fadeOutDuration =
2431 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002432 final float scaleFactor = (float)
2433 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2434 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002435 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002436 Animator workspaceAnim = null;
2437
2438 if (toState == State.WORKSPACE) {
2439 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2440 workspaceAnim = mWorkspace.getChangeStateAnimation(
2441 Workspace.State.NORMAL, animated, stagger);
2442 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2443 workspaceAnim = mWorkspace.getChangeStateAnimation(
2444 Workspace.State.SPRING_LOADED, animated);
2445 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002446
Michael Jurkab3e22d92011-10-31 15:58:33 -07002447 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002448 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002449 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002450 if (animated) {
Michael Jurka742574b2011-02-02 23:51:01 -08002451 final float oldScaleX = fromView.getScaleX();
2452 final float oldScaleY = fromView.getScaleY();
2453
Michael Jurka159b4cc2012-01-17 03:00:35 -08002454 final LauncherViewPropertyAnimator scaleAnim =
2455 new LauncherViewPropertyAnimator(fromView);
2456 scaleAnim.
2457 scaleX(scaleFactor).scaleY(scaleFactor).
2458 setDuration(duration).
2459 setInterpolator(new Workspace.ZoomInInterpolator());
2460
2461 final ObjectAnimator alphaAnim = ObjectAnimator
2462 .ofFloat(fromView, "alpha", 1f, 0f)
2463 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002464 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Michael Jurka159b4cc2012-01-17 03:00:35 -08002465
Michael Jurkabed61d22012-02-14 22:51:29 -08002466 mStateAnimation = new AnimatorSet();
2467
2468 dispatchOnLauncherTransitionStart(fromView, animated, true);
2469 dispatchOnLauncherTransitionStart(toView, animated, true);
2470
2471 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002472 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002473 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002474 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002475 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002476 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2477 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurka430e8a52011-08-08 15:52:14 -07002478 mWorkspace.hideScrollingIndicator(false);
Adam Cohened66b2b2012-01-23 17:28:51 -08002479 if (onCompleteRunnable != null) {
2480 onCompleteRunnable.run();
2481 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002482 }
2483 });
2484
Winson Chungf0ea4d32011-06-06 14:27:16 -07002485 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002486 if (workspaceAnim != null) {
2487 mStateAnimation.play(workspaceAnim);
2488 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002489 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002490 } else {
2491 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002492 dispatchOnLauncherTransitionStart(fromView, animated, true);
2493 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2494 dispatchOnLauncherTransitionStart(toView, animated, true);
2495 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002496 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002497 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002498 }
2499
Michael Jurkae326f182011-11-21 14:05:46 -08002500 @Override
2501 public void onTrimMemory(int level) {
2502 super.onTrimMemory(level);
2503 if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
2504 mAppsCustomizeTabHost.onTrimMemory();
2505 }
2506 }
2507
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002508 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002509 showWorkspace(animated, null);
2510 }
2511
2512 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002513 if (mState != State.WORKSPACE) {
2514 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002515 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002516
2517 // Show the search bar and hotseat
2518 mSearchDropTargetBar.showSearchBar(animated);
Michael Jurkab737ee62011-11-15 15:57:22 -08002519 // We only need to animate in the dock divider if we're going from spring loaded mode
2520 showDockDivider(animated && mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002521
2522 // Set focus to the AppsCustomize button
2523 if (mAllAppsButton != null) {
2524 mAllAppsButton.requestFocus();
2525 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002526 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002527
Michael Jurkab737ee62011-11-15 15:57:22 -08002528 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002529
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002530 // Change the state *after* we've called all the transition code
2531 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002532
Winson Chung5fb63472011-02-02 17:03:37 -08002533 // Resume the auto-advance of widgets
2534 mUserPresent = true;
2535 updateRunning();
2536
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002537 // send an accessibility event to announce the context change
2538 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002539 }
2540
Michael Jurkab3e22d92011-10-31 15:58:33 -07002541 void showAllApps(boolean animated) {
2542 if (mState != State.WORKSPACE) return;
2543
2544 showAppsCustomizeHelper(animated, false);
2545 mAppsCustomizeTabHost.requestFocus();
2546
2547 // Hide the search bar and hotseat
2548 mSearchDropTargetBar.hideSearchBar(animated);
2549
2550 // Change the state *after* we've called all the transition code
2551 mState = State.APPS_CUSTOMIZE;
2552
2553 // Pause the auto-advance of widgets until we are out of AllApps
2554 mUserPresent = false;
2555 updateRunning();
2556 closeFolder();
2557
2558 // Send an accessibility event to announce the context change
2559 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2560 }
2561
Adam Cohen7777d962011-08-18 18:58:38 -07002562 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002563 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002564 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002565 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002566 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002567 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002568 }
Adam Cohen7777d962011-08-18 18:58:38 -07002569
Adam Cohened66b2b2012-01-23 17:28:51 -08002570 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2571 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002572 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2573
Winson Chunge7a03942011-08-05 15:05:12 -07002574 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002575 @Override
2576 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002577 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002578 // Before we show workspace, hide all apps again because
2579 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2580 // clean up our state transition functions
2581 mAppsCustomizeTabHost.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002582 mSearchDropTargetBar.showSearchBar(true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002583 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002584 } else {
2585 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002586 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002587 }
2588 }, (extendedDelay ?
2589 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2590 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2591 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002592
Michael Jurkad3ef3062010-11-23 16:23:58 -08002593 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002594 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002595 final boolean animated = true;
2596 final boolean springLoaded = true;
2597 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002598 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002599 }
2600 // Otherwise, we are not in spring loaded mode, so don't do anything.
2601 }
2602
Michael Jurkab737ee62011-11-15 15:57:22 -08002603 void hideDockDivider() {
2604 if (mQsbDivider != null && mDockDivider != null) {
2605 mQsbDivider.setVisibility(View.INVISIBLE);
2606 mDockDivider.setVisibility(View.INVISIBLE);
2607 }
2608 }
2609
2610 void showDockDivider(boolean animated) {
2611 if (mQsbDivider != null && mDockDivider != null) {
2612 mQsbDivider.setVisibility(View.VISIBLE);
2613 mDockDivider.setVisibility(View.VISIBLE);
2614 if (mDividerAnimator != null) {
2615 mDividerAnimator.cancel();
2616 mQsbDivider.setAlpha(1f);
2617 mDockDivider.setAlpha(1f);
2618 mDividerAnimator = null;
2619 }
2620 if (animated) {
2621 mDividerAnimator = new AnimatorSet();
2622 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2623 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2624 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2625 mDividerAnimator.start();
2626 }
2627 }
2628 }
2629
Michael Jurkab3e22d92011-10-31 15:58:33 -07002630 void lockAllApps() {
2631 // TODO
2632 }
2633
2634 void unlockAllApps() {
2635 // TODO
2636 }
2637
Adam Cohenfc53cd22011-07-20 15:45:11 -07002638 public boolean isAllAppsCustomizeOpen() {
2639 return mState == State.APPS_CUSTOMIZE;
2640 }
2641
Winson Chungf0ea4d32011-06-06 14:27:16 -07002642 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002643 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002644 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002645 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002646 if (!LauncherApplication.isScreenLarge()) {
2647 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002648 if (mHotseat.getAlpha() != 1f) {
2649 int duration = mSearchDropTargetBar.getTransitionInDuration();
2650 mHotseat.animate().alpha(1f).setDuration(duration);
2651 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002652 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002653 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002654 }
2655 }
2656 }
2657
2658 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002659 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002660 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002661 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002662 if (!LauncherApplication.isScreenLarge()) {
2663 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002664 if (mHotseat.getAlpha() != 0f) {
2665 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2666 mHotseat.animate().alpha(0f).setDuration(duration);
2667 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002668 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002669 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002670 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002671 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002672 }
2673
Patrick Dubroy5f445422011-02-18 14:35:21 -08002674 /**
2675 * Add an item from all apps or customize onto the given workspace screen.
2676 * If layout is null, add to the current screen.
2677 */
2678 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002679 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2680 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07002681 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002682 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002683
Winson Chungdff8ebb2011-09-08 17:25:31 -07002684 /** Maps the current orientation to an index for referencing orientation correct global icons */
2685 private int getCurrentOrientationIndexForGlobalIcons() {
2686 // default - 0, landscape - 1
2687 switch (getResources().getConfiguration().orientation) {
2688 case Configuration.ORIENTATION_LANDSCAPE:
2689 return 1;
2690 default:
2691 return 0;
2692 }
2693 }
2694
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002695 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002696 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002697 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002698 // Look for the toolbar icon specified in the activity meta-data
2699 Bundle metaData = packageManager.getActivityInfo(
2700 activityName, PackageManager.GET_META_DATA).metaData;
2701 if (metaData != null) {
2702 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2703 if (iconResId != 0) {
2704 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002705 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002706 }
2707 }
2708 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002709 // This can happen if the activity defines an invalid drawable
2710 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2711 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002712 } catch (Resources.NotFoundException nfe) {
2713 // This can happen if the activity defines an invalid drawable
2714 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2715 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002716 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002717 return null;
2718 }
2719
2720 // if successful in getting icon, return it; otherwise, set button to use default drawable
2721 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2722 int buttonId, ComponentName activityName, int fallbackDrawableId) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002723 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002724 Resources r = getResources();
2725 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2726 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002727
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002728 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002729 // If we were unable to find the icon via the meta-data, use a generic one
2730 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002731 toolbarIcon = r.getDrawable(fallbackDrawableId);
2732 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002733 if (button != null) {
2734 button.setCompoundDrawables(toolbarIcon, null, null, null);
2735 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002736 return null;
2737 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002738 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002739 if (button != null) {
2740 button.setCompoundDrawables(toolbarIcon, null, null, null);
2741 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002742 return toolbarIcon.getConstantState();
2743 }
2744 }
2745
2746 // if successful in getting icon, return it; otherwise, set button to use default drawable
2747 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2748 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2749 ImageView button = (ImageView) findViewById(buttonId);
2750 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2751
Michael Jurka19e0fc52011-07-22 18:00:21 -07002752 if (button != null) {
2753 // If we were unable to find the icon via the meta-data, use a
2754 // generic one
2755 if (toolbarIcon == null) {
2756 button.setImageResource(fallbackDrawableId);
2757 } else {
2758 button.setImageDrawable(toolbarIcon);
2759 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002760 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002761
2762 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2763
Michael Jurka0423dcf2010-10-05 14:56:18 -07002764 }
2765
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002766 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2767 TextView button = (TextView) findViewById(buttonId);
2768 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2769 }
2770
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002771 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002772 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002773 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002774 }
2775
Winson Chungbb185bd2011-11-21 12:31:42 -08002776 private void invalidatePressedFocusedStates(View container, View button) {
2777 if (container instanceof HolographicLinearLayout) {
2778 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2779 layout.invalidatePressedFocusedStates();
2780 } else if (button instanceof HolographicImageView) {
2781 HolographicImageView view = (HolographicImageView) button;
2782 view.invalidatePressedFocusedStates();
2783 }
2784 }
2785
Winson Chungc51db6a2011-10-05 11:44:49 -07002786 private boolean updateGlobalSearchIcon() {
2787 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002788 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2789 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002790 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002791 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002792
Winson Chung1cad91e2011-05-25 17:41:01 -07002793 final SearchManager searchManager =
2794 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2795 ComponentName activityName = searchManager.getGlobalSearchActivity();
2796 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002797 int coi = getCurrentOrientationIndexForGlobalIcons();
2798 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002799 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002800 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002801 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2802 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002803 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002804 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002805 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002806 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002807 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002808 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2809 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2810 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002811 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002812 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002813 }
2814 }
2815
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002816 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002817 final View searchButtonContainer = findViewById(R.id.search_button_container);
2818 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002819 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002820 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002821 }
2822
Winson Chungc51db6a2011-10-05 11:44:49 -07002823 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002824 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002825 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002826 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002827
Winson Chungc51db6a2011-10-05 11:44:49 -07002828 // We only show/update the voice search icon if the search icon is enabled as well
Winson Chung1cad91e2011-05-25 17:41:01 -07002829 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2830 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chungc51db6a2011-10-05 11:44:49 -07002831 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002832 int coi = getCurrentOrientationIndexForGlobalIcons();
2833 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002834 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002835 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002836 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002837 voiceButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002838 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002839 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002840 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002841 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002842 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002843 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002844 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002845 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002846 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002847
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002848 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002849 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
2850 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002851 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002852 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002853 }
2854
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002855 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002856 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002857 */
2858 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002859 final View marketButton = findViewById(R.id.market_button);
2860 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2861 // Find the app market activity by resolving an intent.
2862 // (If multiple app markets are installed, it will return the ResolverActivity.)
2863 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002864 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002865 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07002866 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07002867 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002868 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002869 marketButton.setVisibility(View.VISIBLE);
2870 } else {
2871 // We should hide and disable the view so that we don't try and restore the visibility
2872 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2873 marketButton.setVisibility(View.GONE);
2874 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002875 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002876 }
2877
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002878 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002879 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002880 }
2881
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002882 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002883 * Displays the shortcut creation dialog and launches, if necessary, the
2884 * appropriate activity.
2885 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002886 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002887 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2888 DialogInterface.OnShowListener {
2889
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002890 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002891
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002892 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002893 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002894
Winson Chung55b65502011-05-26 12:03:43 -07002895 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2896 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002897 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002898
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002899 AlertDialog dialog = builder.create();
2900 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002901 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002902 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002903
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002904 return dialog;
2905 }
2906
2907 public void onCancel(DialogInterface dialog) {
2908 mWaitingForResult = false;
2909 cleanup();
2910 }
2911
Romain Guycbb89e42009-06-08 15:52:54 -07002912 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002913 mWaitingForResult = false;
2914 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002915 }
2916
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002917 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002918 try {
2919 dismissDialog(DIALOG_CREATE_SHORTCUT);
2920 } catch (Exception e) {
2921 // An exception is thrown if the dialog is not visible, which is fine
2922 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002923 }
2924
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002925 /**
2926 * Handle the action clicked in the "Add to home" dialog.
2927 */
2928 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002929 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002930
Winson Chung55b65502011-05-26 12:03:43 -07002931 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2932 switch (item.actionTag) {
Winson Chung55b65502011-05-26 12:03:43 -07002933 case AddAdapter.ITEM_APPLICATION: {
2934 if (mAppsCustomizeTabHost != null) {
2935 mAppsCustomizeTabHost.selectAppsTab();
2936 }
2937 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002938 break;
2939 }
Winson Chung55b65502011-05-26 12:03:43 -07002940 case AddAdapter.ITEM_APPWIDGET: {
2941 if (mAppsCustomizeTabHost != null) {
2942 mAppsCustomizeTabHost.selectWidgetsTab();
2943 }
2944 showAllApps(true);
2945 break;
2946 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002947 case AddAdapter.ITEM_WALLPAPER: {
2948 startWallpaper();
2949 break;
2950 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002951 }
2952 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002953
2954 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002955 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002956 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002957 }
2958
2959 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07002960 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002961 */
2962 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2963 @Override
2964 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002965 closeSystemDialogs();
2966 }
2967 }
2968
2969 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002970 * Receives notifications whenever the appwidgets are reset.
2971 */
2972 private class AppWidgetResetObserver extends ContentObserver {
2973 public AppWidgetResetObserver() {
2974 super(new Handler());
2975 }
2976
2977 @Override
2978 public void onChange(boolean selfChange) {
2979 onAppWidgetReset();
2980 }
2981 }
2982
2983 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002984 * If the activity is currently paused, signal that we need to re-run the loader
2985 * in onResume.
2986 *
2987 * This needs to be called from incoming places where resources might have been loaded
2988 * while we are paused. That is becaues the Configuration might be wrong
2989 * when we're not running, and if it comes back to what it was when we
2990 * were paused, we are not restarted.
2991 *
2992 * Implementation of the method from LauncherModel.Callbacks.
2993 *
2994 * @return true if we are currently paused. The caller might be able to
2995 * skip some work in that case since we will come back again.
2996 */
2997 public boolean setLoadOnResume() {
2998 if (mPaused) {
2999 Log.i(TAG, "setLoadOnResume");
3000 mOnResumeNeedsLoad = true;
3001 return true;
3002 } else {
3003 return false;
3004 }
3005 }
3006
3007 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003008 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003009 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003010 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003011 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003012 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003013 } else {
3014 return SCREEN_COUNT / 2;
3015 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003016 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003017
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003018
Joe Onorato9c1289c2009-08-17 11:03:03 -04003019 /**
3020 * Refreshes the shortcuts shown on the workspace.
3021 *
3022 * Implementation of the method from LauncherModel.Callbacks.
3023 */
3024 public void startBinding() {
3025 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07003026
3027 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003028 int count = workspace.getChildCount();
3029 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003030 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003031 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3032 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003033 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08003034 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003035 if (mHotseat != null) {
3036 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003037 }
3038 }
3039
3040 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003041 * Bind the items start-end from the list.
3042 *
3043 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003044 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003045 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003046 setLoadOnResume();
3047
Joe Onorato9c1289c2009-08-17 11:03:03 -04003048 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003049 for (int i=start; i<end; i++) {
3050 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003051
3052 // Short circuit if we are loading dock items for a configuration which has no dock
3053 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3054 mHotseat == null) {
3055 continue;
3056 }
3057
Joe Onorato9c1289c2009-08-17 11:03:03 -04003058 switch (item.itemType) {
3059 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3060 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07003061 View shortcut = createShortcut((ShortcutInfo)item);
3062 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3063 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003064 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003065 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003066 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003067 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003068 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003069 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3070 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003071 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003072 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003073 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003074 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003075 }
3076
Joe Onorato9c1289c2009-08-17 11:03:03 -04003077 /**
3078 * Implementation of the method from LauncherModel.Callbacks.
3079 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003080 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003081 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003082 sFolders.clear();
3083 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003084 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003085
3086 /**
3087 * Add the views for a widget to the workspace.
3088 *
3089 * Implementation of the method from LauncherModel.Callbacks.
3090 */
3091 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003092 setLoadOnResume();
3093
Daniel Sandler843e8602010-06-07 14:59:01 -04003094 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3095 if (DEBUG_WIDGETS) {
3096 Log.d(TAG, "bindAppWidget: " + item);
3097 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003098 final Workspace workspace = mWorkspace;
3099
3100 final int appWidgetId = item.appWidgetId;
3101 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003102 if (DEBUG_WIDGETS) {
3103 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3104 }
3105
Joe Onorato9c1289c2009-08-17 11:03:03 -04003106 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3107
Joe Onorato9c1289c2009-08-17 11:03:03 -04003108 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
3109 item.hostView.setTag(item);
3110
Winson Chung3d503fb2011-07-13 17:25:49 -07003111 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003112 item.cellY, item.spanX, item.spanY, false);
3113
Adam Cohended9f8d2010-11-03 13:25:16 -07003114 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3115
Joe Onorato9c1289c2009-08-17 11:03:03 -04003116 workspace.requestLayout();
3117
Daniel Sandler843e8602010-06-07 14:59:01 -04003118 if (DEBUG_WIDGETS) {
3119 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3120 + (SystemClock.uptimeMillis()-start) + "ms");
3121 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003122 }
3123
3124 /**
3125 * Callback saying that there aren't any more items to bind.
3126 *
3127 * Implementation of the method from LauncherModel.Callbacks.
3128 */
3129 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003130 setLoadOnResume();
3131
Joe Onorato9c1289c2009-08-17 11:03:03 -04003132 if (mSavedState != null) {
3133 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003134 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003135 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003136 mSavedState = null;
3137 }
3138
3139 if (mSavedInstanceState != null) {
3140 super.onRestoreInstanceState(mSavedInstanceState);
3141 mSavedInstanceState = null;
3142 }
3143
Joe Onorato9c1289c2009-08-17 11:03:03 -04003144 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003145
3146 // If we received the result of any pending adds while the loader was running (e.g. the
3147 // widget configuration forced an orientation change), process them now.
3148 for (int i = 0; i < sPendingAddList.size(); i++) {
3149 completeAdd(sPendingAddList.get(i));
3150 }
3151 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003152
Winson Chungc51db6a2011-10-05 11:44:49 -07003153 // Update the market app icon as necessary (the other icons will be managed in response to
3154 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003155 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003156
Michael Jurka6ee21d22012-02-21 18:20:27 -08003157 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003158 }
3159
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003160 @Override
3161 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003162 boolean searchVisible = updateGlobalSearchIcon();
3163 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3164 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003165 }
3166
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003167 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003168 * Add the icons for all apps.
3169 *
3170 * Implementation of the method from LauncherModel.Callbacks.
3171 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003172 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3173 // Remove the progress bar entirely; we could also make it GONE
3174 // but better to remove it since we know it's not going to be used
3175 View progressBar = mAppsCustomizeTabHost.
3176 findViewById(R.id.apps_customize_progress_bar);
3177 if (progressBar != null) {
3178 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003179 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003180 // We just post the call to setApps so the user sees the progress bar
3181 // disappear-- otherwise, it just looks like the progress bar froze
3182 // which doesn't look great
3183 mAppsCustomizeTabHost.post(new Runnable() {
3184 public void run() {
3185 if (mAppsCustomizeContent != null) {
3186 mAppsCustomizeContent.setApps(apps);
3187 }
3188 }
3189 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003190 }
3191
3192 /**
3193 * A package was installed.
3194 *
3195 * Implementation of the method from LauncherModel.Callbacks.
3196 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003197 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003198 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003199 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003200
Winson Chung785d2eb2011-04-14 16:08:02 -07003201 if (mAppsCustomizeContent != null) {
3202 mAppsCustomizeContent.addApps(apps);
3203 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003204 }
3205
3206 /**
3207 * A package was updated.
3208 *
3209 * Implementation of the method from LauncherModel.Callbacks.
3210 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003211 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003212 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003213 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003214 if (mWorkspace != null) {
3215 mWorkspace.updateShortcuts(apps);
3216 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003217
Winson Chung785d2eb2011-04-14 16:08:02 -07003218 if (mAppsCustomizeContent != null) {
3219 mAppsCustomizeContent.updateApps(apps);
3220 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003221 }
3222
3223 /**
3224 * A package was uninstalled.
3225 *
3226 * Implementation of the method from LauncherModel.Callbacks.
3227 */
Joe Onorato36115782010-06-17 13:28:48 -04003228 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003229 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003230 if (permanent) {
3231 mWorkspace.removeItems(apps);
3232 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003233
Winson Chung785d2eb2011-04-14 16:08:02 -07003234 if (mAppsCustomizeContent != null) {
3235 mAppsCustomizeContent.removeApps(apps);
3236 }
Winson Chunga1820962011-10-03 16:31:06 -07003237
3238 // Notify the drag controller
3239 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003240 }
Joe Onoratobe386092009-11-17 17:32:16 -08003241
3242 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003243 * A number of packages were updated.
3244 */
3245 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003246 if (mAppsCustomizeContent != null) {
3247 mAppsCustomizeContent.onPackagesUpdated();
3248 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003249 }
3250
Winson Chung400438b2011-01-16 17:53:48 -08003251 private int mapConfigurationOriActivityInfoOri(int configOri) {
3252 final Display d = getWindowManager().getDefaultDisplay();
3253 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3254 switch (d.getRotation()) {
3255 case Surface.ROTATION_0:
3256 case Surface.ROTATION_180:
3257 // We are currently in the same basic orientation as the natural orientation
3258 naturalOri = configOri;
3259 break;
3260 case Surface.ROTATION_90:
3261 case Surface.ROTATION_270:
3262 // We are currently in the other basic orientation to the natural orientation
3263 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3264 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3265 break;
3266 }
3267
3268 int[] oriMap = {
3269 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3270 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3271 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3272 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3273 };
3274 // Since the map starts at portrait, we need to offset if this device's natural orientation
3275 // is landscape.
3276 int indexOffset = 0;
3277 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3278 indexOffset = 1;
3279 }
3280 return oriMap[(d.getRotation() + indexOffset) % 4];
3281 }
Adam Cohen446e9402011-09-15 18:21:21 -07003282
3283 public void lockScreenOrientationOnLargeUI() {
3284 if (LauncherApplication.isScreenLarge()) {
3285 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3286 .getConfiguration().orientation));
3287 }
Winson Chung400438b2011-01-16 17:53:48 -08003288 }
Adam Cohen446e9402011-09-15 18:21:21 -07003289 public void unlockScreenOrientationOnLargeUI() {
3290 if (LauncherApplication.isScreenLarge()) {
3291 mHandler.postDelayed(new Runnable() {
3292 public void run() {
3293 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3294 }
3295 }, mRestoreScreenOrientationDelay);
3296 }
Winson Chung400438b2011-01-16 17:53:48 -08003297 }
3298
Winson Chung82f55532011-08-09 14:14:23 -07003299 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003300 private static final String PREFS_KEY = "com.android.launcher2.prefs";
3301 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003302 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003303 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003304
Winson Chung7d7541e2011-09-16 20:14:36 -07003305 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003306 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003307 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3308 Cling cling = (Cling) findViewById(clingId);
3309 if (cling != null) {
3310 cling.init(this, positionData);
3311 cling.setVisibility(View.VISIBLE);
3312 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3313 if (animate) {
3314 cling.buildLayer();
3315 cling.setAlpha(0f);
3316 cling.animate()
3317 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003318 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003319 .setDuration(SHOW_CLING_DURATION)
3320 .setStartDelay(delay)
3321 .start();
3322 } else {
3323 cling.setAlpha(1f);
3324 }
3325 }
3326 return cling;
3327 }
3328 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003329 if (cling != null) {
3330 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003331 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003332 anim.addListener(new AnimatorListenerAdapter() {
3333 public void onAnimationEnd(Animator animation) {
3334 cling.setVisibility(View.GONE);
3335 cling.cleanup();
3336 SharedPreferences prefs =
3337 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
3338 SharedPreferences.Editor editor = prefs.edit();
3339 editor.putBoolean(flag, true);
3340 editor.commit();
3341 };
3342 });
3343 anim.start();
3344 }
3345 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003346 private void removeCling(int id) {
3347 final View cling = findViewById(id);
3348 if (cling != null) {
3349 final ViewGroup parent = (ViewGroup) cling.getParent();
3350 parent.post(new Runnable() {
3351 @Override
3352 public void run() {
3353 parent.removeView(cling);
3354 }
3355 });
3356 }
3357 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003358 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003359 // Enable the clings only if they have not been dismissed before
3360 SharedPreferences prefs =
3361 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003362 if (isClingsEnabled() && !prefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003363 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003364 } else {
3365 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003366 }
3367 }
3368 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003369 // Enable the clings only if they have not been dismissed before
3370 SharedPreferences prefs =
3371 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003372 if (isClingsEnabled() && !prefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003373 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003374 } else {
3375 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003376 }
3377 }
3378 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003379 // Enable the clings only if they have not been dismissed before
3380 SharedPreferences prefs =
3381 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
3382 Cling cling = null;
Winson Chung9d9d74f2011-09-19 11:49:12 -07003383 if (isClingsEnabled() && !prefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003384 cling = initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003385 } else {
3386 removeCling(R.id.folder_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003387 }
3388 return cling;
3389 }
3390 public boolean isFolderClingVisible() {
3391 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003392 if (cling != null) {
3393 return cling.getVisibility() == View.VISIBLE;
3394 }
3395 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003396 }
Winson Chung82f55532011-08-09 14:14:23 -07003397 public void dismissWorkspaceCling(View v) {
3398 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003399 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003400 }
3401 public void dismissAllAppsCling(View v) {
3402 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003403 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3404 }
3405 public void dismissFolderCling(View v) {
3406 Cling cling = (Cling) findViewById(R.id.folder_cling);
3407 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003408 }
3409
Winson Chung80baf5a2010-08-09 16:03:15 -07003410 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003411 * Prints out out state for debugging.
3412 */
3413 public void dumpState() {
3414 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003415 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003416 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3417 Log.d(TAG, "mRestoring=" + mRestoring);
3418 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3419 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003420 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003421 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003422
Winson Chung785d2eb2011-04-14 16:08:02 -07003423 if (mAppsCustomizeContent != null) {
3424 mAppsCustomizeContent.dumpState();
3425 }
Joe Onoratobe386092009-11-17 17:32:16 -08003426 Log.d(TAG, "END launcher2 dump state");
3427 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003428
3429 @Override
3430 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3431 super.dump(prefix, fd, writer, args);
3432 writer.println(" ");
3433 writer.println("Debug logs: ");
3434 for (int i = 0; i < sDumpLogs.size(); i++) {
3435 writer.println(" " + sDumpLogs.get(i));
3436 }
3437 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003438}
Michael Jurka2763be32011-02-24 11:19:57 -08003439
Michael Jurkaabded662011-03-04 12:06:57 -08003440interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003441 View getContent();
Michael Jurkabed61d22012-02-14 22:51:29 -08003442 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
3443 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003444}