blob: 92a3d08a07eb3aa1ffb16dccc1ffdf4f191666cc [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
Michael Jurkabed61d22012-02-14 22:51:29 -0800619 protected void onStart() {
620 super.onStart();
621 // When Launcher comes back to foreground, a different Activity might be responsible for
622 // the app market intent, so refresh the icon
623 // We don't do this in onResume() because onResume() is triggered every time the home
624 // button is pressed (even if we were already in Launcher)
625 updateAppMarketIcon();
626 }
627
628 @Override
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700629 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400630 // Flag the loader to stop early before switching
631 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700632 if (mAppsCustomizeContent != null) {
633 mAppsCustomizeContent.surrender();
634 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800635 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700636 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700637
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800638 // We can't hide the IME if it was forced open. So don't bother
639 /*
640 @Override
641 public void onWindowFocusChanged(boolean hasFocus) {
642 super.onWindowFocusChanged(hasFocus);
643
644 if (hasFocus) {
645 final InputMethodManager inputManager = (InputMethodManager)
646 getSystemService(Context.INPUT_METHOD_SERVICE);
647 WindowManager.LayoutParams lp = getWindow().getAttributes();
648 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
649 android.os.Handler()) {
650 protected void onReceiveResult(int resultCode, Bundle resultData) {
651 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
652 }
653 });
654 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
655 }
656 }
657 */
658
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800659 private boolean acceptFilter() {
660 final InputMethodManager inputManager = (InputMethodManager)
661 getSystemService(Context.INPUT_METHOD_SERVICE);
662 return !inputManager.isFullscreenMode();
663 }
664
665 @Override
666 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700667 final int uniChar = event.getUnicodeChar();
668 final boolean handled = super.onKeyDown(keyCode, event);
669 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
670 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800671 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
672 keyCode, event);
673 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700674 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700675 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700676 // showSearchDialog()
677 // If there are multiple keystrokes before the search dialog takes focus,
678 // onSearchRequested() will be called for every keystroke,
679 // but it is idempotent, so it's fine.
680 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800681 }
682 }
683
Joe Onorato8a9625e2010-01-28 15:55:35 -0800684 // Eat the long press event so the keyboard doesn't come up.
685 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
686 return true;
687 }
688
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800689 return handled;
690 }
691
Karl Rosaen138a0412009-04-23 19:00:21 -0700692 private String getTypedText() {
693 return mDefaultKeySsb.toString();
694 }
695
696 private void clearTypedText() {
697 mDefaultKeySsb.clear();
698 mDefaultKeySsb.clearSpans();
699 Selection.setSelection(mDefaultKeySsb, 0);
700 }
701
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800702 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700703 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
704 * State
705 */
706 private static State intToState(int stateOrdinal) {
707 State state = State.WORKSPACE;
708 final State[] stateValues = State.values();
709 for (int i = 0; i < stateValues.length; i++) {
710 if (stateValues[i].ordinal() == stateOrdinal) {
711 state = stateValues[i];
712 break;
713 }
714 }
715 return state;
716 }
717
718 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800719 * Restores the previous state, if it exists.
720 *
721 * @param savedState The previous state.
722 */
723 private void restoreState(Bundle savedState) {
724 if (savedState == null) {
725 return;
726 }
727
Michael Jurka883f55b2010-10-21 15:47:14 -0700728 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700729 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800730 showAllApps(false);
731 }
732
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800733 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
734 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700735 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800736 }
737
Winson Chung3d503fb2011-07-13 17:25:49 -0700738 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
739 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700740
Winson Chung3d503fb2011-07-13 17:25:49 -0700741 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
742 mPendingAddInfo.container = pendingAddContainer;
743 mPendingAddInfo.screen = pendingAddScreen;
744 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
745 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800746 mRestoring = true;
747 }
748
749 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
750 if (renameFolder) {
751 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700752 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800753 mRestoring = true;
754 }
Winson Chunga12a2502010-12-20 14:41:35 -0800755
Winson Chung785d2eb2011-04-14 16:08:02 -0700756
757 // Restore the AppsCustomize tab
758 if (mAppsCustomizeTabHost != null) {
759 String curTab = savedState.getString("apps_customize_currentTab");
760 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700761 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700762 mAppsCustomizeContent.setContentType(
763 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
764 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700765 mAppsCustomizeContent.loadAssociatedPages(
766 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700767 }
768
Winson Chung5afbf7b2011-07-25 11:53:08 -0700769 int currentIndex = savedState.getInt("apps_customize_currentIndex");
770 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700771 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800772 }
773
774 /**
775 * Finds all the views we need and configure them properly.
776 */
777 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700778 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400779
Winson Chung4c98d922011-05-31 16:50:48 -0700780 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
781 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800782 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
783 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800784
Winson Chung4c98d922011-05-31 16:50:48 -0700785 // Setup the drag layer
786 mDragLayer.setup(this, dragController);
787
Winson Chung3d503fb2011-07-13 17:25:49 -0700788 // Setup the hotseat
789 mHotseat = (Hotseat) findViewById(R.id.hotseat);
790 if (mHotseat != null) {
791 mHotseat.setup(this);
792 }
793
Winson Chung4c98d922011-05-31 16:50:48 -0700794 // Setup the workspace
795 mWorkspace.setHapticFeedbackEnabled(false);
796 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700797 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700798 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700799
Winson Chungf0ea4d32011-06-06 14:27:16 -0700800 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700801 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700802
Winson Chungf0ea4d32011-06-06 14:27:16 -0700803 // Setup AppsCustomize
804 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
805 findViewById(R.id.apps_customize_pane);
806 mAppsCustomizeContent = (AppsCustomizePagedView)
807 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
808 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400809
Michael Jurka5130e402011-10-13 04:55:35 -0700810 // Get the all apps button
811 mAllAppsButton = findViewById(R.id.all_apps_button);
812 if (mAllAppsButton != null) {
813 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
814 @Override
815 public boolean onTouch(View v, MotionEvent event) {
816 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
817 onTouchDownAllAppsButton(v);
818 }
819 return false;
820 }
821 });
822 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700823 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700824 dragController.setDragScoller(mWorkspace);
825 dragController.setScrollView(mDragLayer);
826 dragController.setMoveTarget(mWorkspace);
827 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700828 if (mSearchDropTargetBar != null) {
829 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800830 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800831 }
832
833 /**
834 * Creates a view representing a shortcut.
835 *
836 * @param info The data structure describing the shortcut.
837 *
838 * @return A View inflated from R.layout.application.
839 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800840 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800841 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700842 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800843 }
844
845 /**
846 * Creates a view representing a shortcut inflated from the specified resource.
847 *
848 * @param layoutResId The id of the XML layout used to create the shortcut.
849 * @param parent The group the shortcut belongs to.
850 * @param info The data structure describing the shortcut.
851 *
852 * @return A View inflated from layoutResId.
853 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800854 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800855 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
856 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800857 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800858 return favorite;
859 }
860
861 /**
862 * Add an application shortcut to the workspace.
863 *
864 * @param data The intent describing the application.
865 * @param cellInfo The position on screen where to create the shortcut.
866 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700867 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700868 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700869 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700870
Adam Cohenfbba09b2011-07-18 21:43:05 -0700871 // First we check if we already know the exact location where we want to add this item.
872 if (cellX >= 0 && cellY >= 0) {
873 cellXY[0] = cellX;
874 cellXY[1] = cellY;
875 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700876 showOutOfSpaceMessage();
877 return;
878 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800879
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800880 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800881
Romain Guy73b979d2009-06-09 12:57:21 -0700882 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800883 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800884 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800885 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700886 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700887 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800888 } else {
889 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800890 }
891 }
Romain Guycbb89e42009-06-08 15:52:54 -0700892
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800893 /**
894 * Add a shortcut to the workspace.
895 *
896 * @param data The intent describing the shortcut.
897 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700899 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
900 int cellY) {
901 int[] cellXY = mTmpAddItemCellCoordinates;
902 int[] touchXY = mPendingAddInfo.dropPos;
903 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -0700904
Michael Jurkad3ef3062010-11-23 16:23:58 -0800905 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700906
Adam Cohen558baaf2011-08-15 15:22:57 -0700907 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -0800908 if (info == null) {
909 return;
910 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700911 final View view = createShortcut(info);
912
Adam Cohenfbba09b2011-07-18 21:43:05 -0700913 // First we check if we already know the exact location where we want to add this item.
914 if (cellX >= 0 && cellY >= 0) {
915 cellXY[0] = cellX;
916 cellXY[1] = cellY;
917 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -0700918
919 // If appropriate, either create a folder or add to an existing folder
920 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY,
921 true, null,null)) {
922 return;
923 }
924 DragObject dragObject = new DragObject();
925 dragObject.dragInfo = info;
926 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, dragObject, true)) {
927 return;
928 }
Adam Cohenfbba09b2011-07-18 21:43:05 -0700929 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800930 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700931 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800932 foundCellSpan = (result != null);
933 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700934 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800935 }
936
937 if (!foundCellSpan) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700938 showOutOfSpaceMessage();
939 return;
940 }
941
Adam Cohen558baaf2011-08-15 15:22:57 -0700942 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800943
944 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -0700945 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
946 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800947 }
948 }
949
Adam Cohenf814aa02011-09-01 13:48:05 -0700950 int[] getSpanForWidget(ComponentName component, int minWidth, int minHeight, int[] spanXY) {
951 if (spanXY == null) {
952 spanXY = new int[2];
953 }
954
Adam Cohen0cf2a7c2011-11-08 15:07:01 -0800955 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(this, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -0700956 // We want to account for the extra amount of padding that we are adding to the widget
957 // to ensure that it gets the full amount of space that it has requested
958 int requiredWidth = minWidth + padding.left + padding.right;
959 int requiredHeight = minHeight + padding.top + padding.bottom;
960 return CellLayout.rectToCell(getResources(), requiredWidth, requiredHeight, null);
961 }
962
963 int[] getSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
964 return getSpanForWidget(info.provider, info.minWidth, info.minHeight, spanXY);
965 }
966
Adam Cohencbf47e32011-09-16 17:32:37 -0700967 int[] getMinResizeSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
968 return getSpanForWidget(info.provider, info.minResizeWidth, info.minResizeHeight, spanXY);
969 }
970
Adam Cohenf814aa02011-09-01 13:48:05 -0700971 int[] getSpanForWidget(PendingAddWidgetInfo info, int[] spanXY) {
972 return getSpanForWidget(info.componentName, info.minWidth, info.minHeight, spanXY);
973 }
974
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800975 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700976 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800977 *
Romain Guy5bbc91b2010-08-18 11:38:46 -0700978 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700979 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800980 */
Adam Cohened66b2b2012-01-23 17:28:51 -0800981 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
982 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
983 if (appWidgetInfo == null) {
984 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
985 }
Romain Guycbb89e42009-06-08 15:52:54 -0700986
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700987 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -0700988 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -0700989
Adam Cohenf814aa02011-09-01 13:48:05 -0700990 int[] spanXY = getSpanForWidget(appWidgetInfo, null);
Romain Guycbb89e42009-06-08 15:52:54 -0700991
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800992 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -0700993 // We have saved the position to which the widget was dragged-- this really only matters
994 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -0700995 int[] cellXY = mTmpAddItemCellCoordinates;
996 int[] touchXY = mPendingAddInfo.dropPos;
Michael Jurka0280c3b2010-09-17 15:00:07 -0700997 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -0700998 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
999 cellXY[0] = mPendingAddInfo.cellX;
1000 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001001 foundCellSpan = true;
1002 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001003 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001004 int[] result = layout.findNearestVacantArea(
Michael Jurka0280c3b2010-09-17 15:00:07 -07001005 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001006 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001007 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001008 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001009 }
1010
Michael Jurka0280c3b2010-09-17 15:00:07 -07001011 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001012 if (appWidgetId != -1) {
1013 // Deleting an app widget ID is a void call but writes to disk before returning
1014 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001015 new Thread("deleteAppWidgetId") {
1016 public void run() {
1017 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1018 }
1019 }.start();
1020 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001021 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001022 return;
1023 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001024
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001025 // Build Launcher-specific widget info and save to database
Michael Jurkac9d95c52011-08-29 14:03:34 -07001026 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001027 launcherInfo.spanX = spanXY[0];
1028 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001029
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001030 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001031 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001032
1033 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001034 if (hostView == null) {
1035 // Perform actual inflation because we're live
1036 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1037 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1038 } else {
1039 // The AppWidgetHostView has already been inflated and instantiated
1040 launcherInfo.hostView = hostView;
1041 }
Romain Guycbb89e42009-06-08 15:52:54 -07001042
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001043 launcherInfo.hostView.setTag(launcherInfo);
Winson Chung3d503fb2011-07-13 17:25:49 -07001044 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001045 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001046
1047 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001048 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001049 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001050 }
Romain Guycbb89e42009-06-08 15:52:54 -07001051
Adam Cohended9f8d2010-11-03 13:25:16 -07001052 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1053 @Override
1054 public void onReceive(Context context, Intent intent) {
1055 final String action = intent.getAction();
1056 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1057 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001058 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001059 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001060
Winson Chungc100e8e2011-08-09 16:02:43 -07001061 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001062 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001063 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1064 mAppsCustomizeTabHost.reset();
1065 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001066 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001067 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1068 mUserPresent = true;
1069 updateRunning();
1070 }
1071 }
1072 };
1073
1074 @Override
1075 public void onAttachedToWindow() {
1076 super.onAttachedToWindow();
1077
1078 // Listen for broadcasts related to user-presence
1079 final IntentFilter filter = new IntentFilter();
1080 filter.addAction(Intent.ACTION_SCREEN_OFF);
1081 filter.addAction(Intent.ACTION_USER_PRESENT);
1082 registerReceiver(mReceiver, filter);
1083
Adam Cohend113e0c2010-11-11 10:48:05 -08001084 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001085 mVisible = true;
1086 }
1087
1088 @Override
1089 public void onDetachedFromWindow() {
1090 super.onDetachedFromWindow();
1091 mVisible = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001092 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001093
Adam Cohend113e0c2010-11-11 10:48:05 -08001094 if (mAttached) {
1095 unregisterReceiver(mReceiver);
1096 mAttached = false;
1097 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001098 updateRunning();
1099 }
1100
1101 public void onWindowVisibilityChanged(int visibility) {
1102 mVisible = visibility == View.VISIBLE;
1103 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001104 // The following code used to be in onResume, but it turns out onResume is called when
1105 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1106 // is a more appropriate event to handle
1107 if (mVisible) {
1108 mAppsCustomizeTabHost.onWindowVisible();
1109 if (!mWorkspaceLoading) {
1110 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001111 // We want to let Launcher draw itself at least once before we force it to build
1112 // layers on all the workspace pages, so that transitioning to Launcher from other
1113 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
1114 // a true draw so we wait until the second preDraw call to be safe
1115 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
1116 boolean mFirstTime = true;
1117 public boolean onPreDraw() {
1118 if (mFirstTime) {
1119 mFirstTime = false;
1120 } else {
1121 //workspace.post(mBuildLayersRunnable);
1122 observer.removeOnPreDrawListener(this);
1123 }
1124 return true;
1125 }
1126 });
1127 }
1128 clearTypedText();
1129 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001130 }
1131
1132 private void sendAdvanceMessage(long delay) {
1133 mHandler.removeMessages(ADVANCE_MSG);
1134 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1135 mHandler.sendMessageDelayed(msg, delay);
1136 mAutoAdvanceSentTime = System.currentTimeMillis();
1137 }
1138
1139 private void updateRunning() {
1140 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1141 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1142 mAutoAdvanceRunning = autoAdvanceRunning;
1143 if (autoAdvanceRunning) {
1144 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1145 sendAdvanceMessage(delay);
1146 } else {
1147 if (!mWidgetsToAdvance.isEmpty()) {
1148 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1149 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1150 }
1151 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001152 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001153 }
1154 }
1155 }
1156
1157 private final Handler mHandler = new Handler() {
1158 @Override
1159 public void handleMessage(Message msg) {
1160 if (msg.what == ADVANCE_MSG) {
1161 int i = 0;
1162 for (View key: mWidgetsToAdvance.keySet()) {
1163 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1164 final int delay = mAdvanceStagger * i;
1165 if (v instanceof Advanceable) {
1166 postDelayed(new Runnable() {
1167 public void run() {
1168 ((Advanceable) v).advance();
1169 }
1170 }, delay);
1171 }
1172 i++;
1173 }
1174 sendAdvanceMessage(mAdvanceInterval);
1175 }
1176 }
1177 };
1178
1179 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001180 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001181 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1182 if (v instanceof Advanceable) {
1183 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001184 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001185 updateRunning();
1186 }
1187 }
1188
1189 void removeWidgetToAutoAdvance(View hostView) {
1190 if (mWidgetsToAdvance.containsKey(hostView)) {
1191 mWidgetsToAdvance.remove(hostView);
1192 updateRunning();
1193 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001194 }
1195
Joe Onorato9c1289c2009-08-17 11:03:03 -04001196 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001197 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001198 launcherInfo.hostView = null;
1199 }
1200
Adam Cohended9f8d2010-11-03 13:25:16 -07001201 void showOutOfSpaceMessage() {
1202 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1203 }
1204
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001205 public LauncherAppWidgetHost getAppWidgetHost() {
1206 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001207 }
Romain Guycbb89e42009-06-08 15:52:54 -07001208
Winson Chunga9abd0e2010-10-27 17:18:37 -07001209 public LauncherModel getModel() {
1210 return mModel;
1211 }
1212
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001213 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001214 getWindow().closeAllPanels();
1215
Winson Chung87acb482011-08-23 17:28:05 -07001216 /**
1217 * We should remove this code when we remove all the dialog code.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001218 try {
1219 dismissDialog(DIALOG_CREATE_SHORTCUT);
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 }
1224
1225 try {
1226 dismissDialog(DIALOG_RENAME_FOLDER);
1227 // Unlock the workspace if the dialog was showing
1228 } catch (Exception e) {
1229 // An exception is thrown if the dialog is not visible, which is fine
1230 }
Winson Chung87acb482011-08-23 17:28:05 -07001231 */
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001232
1233 // Whatever we were doing is hereby canceled.
1234 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001235 }
1236
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001237 @Override
1238 protected void onNewIntent(Intent intent) {
1239 super.onNewIntent(intent);
1240
1241 // Close the menu
1242 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001243 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001244 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001245
Joe Onorato14f122b2009-11-19 14:06:36 -08001246 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1247 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001248
Adam Cohenac56cff2011-09-28 20:45:37 -07001249 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001250 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001251 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001252 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1253 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001254 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001255 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001256
1257 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001258 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001259 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001260
Joe Onorato3a8820b2009-11-10 15:06:42 -08001261 final View v = getWindow().peekDecorView();
1262 if (v != null && v.getWindowToken() != null) {
1263 InputMethodManager imm = (InputMethodManager)getSystemService(
1264 INPUT_METHOD_SERVICE);
1265 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001266 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001267
Michael Jurka35aa14d2011-07-07 17:01:08 -07001268 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001269 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001270 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001271 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001272 }
1273 }
1274
1275 @Override
1276 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1277 // Do not call super here
1278 mSavedInstanceState = savedInstanceState;
1279 }
1280
1281 @Override
1282 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001283 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001284 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001285
Michael Jurka883f55b2010-10-21 15:47:14 -07001286 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001287 // We close any open folder since it will not be re-opened, and we need to make sure
1288 // this state is reflected.
1289 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001290
Winson Chung3d503fb2011-07-13 17:25:49 -07001291 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1292 mWaitingForResult) {
1293 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1294 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1295 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1296 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001297 }
1298
1299 if (mFolderInfo != null && mWaitingForResult) {
1300 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1301 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1302 }
Michael Jurka946ad472010-07-09 18:05:18 -07001303
Winson Chung785d2eb2011-04-14 16:08:02 -07001304 // Save the current AppsCustomize tab
1305 if (mAppsCustomizeTabHost != null) {
1306 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1307 if (currentTabTag != null) {
1308 outState.putString("apps_customize_currentTab", currentTabTag);
1309 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001310 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1311 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001312 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001313 }
1314
1315 @Override
1316 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001317 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001318
Winson Chunge7a03942011-08-05 15:05:12 -07001319 // Remove all pending runnables
1320 mHandler.removeMessages(ADVANCE_MSG);
1321 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001322 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001323
Winson Chungcd2b0142011-06-08 16:02:26 -07001324 // Stop callbacks from LauncherModel
1325 LauncherApplication app = ((LauncherApplication) getApplication());
1326 mModel.stopLoader();
1327 app.setLauncher(null);
1328
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001329 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001330 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001331 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001332 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001333 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001334 mAppWidgetHost = null;
1335
1336 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001337
1338 TextKeyListener.getInstance().release();
1339
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001340
Winson Chung3d503fb2011-07-13 17:25:49 -07001341 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001342
1343 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001344 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001345
1346 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1347 mWorkspace.removeAllViews();
1348 mWorkspace = null;
1349 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001350
1351 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001352 }
1353
Adam Cohena9cf38f2011-05-02 15:36:58 -07001354 public DragController getDragController() {
1355 return mDragController;
1356 }
1357
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001358 @Override
1359 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001360 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001361 super.startActivityForResult(intent, requestCode);
1362 }
1363
Winson Chung70d72102011-08-12 11:24:35 -07001364 /**
1365 * Indicates that we want global search for this activity by setting the globalSearch
1366 * argument for {@link #startSearch} to true.
1367 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001368 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001369 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001370 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001371
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001372 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001373
Karl Rosaen138a0412009-04-23 19:00:21 -07001374 if (initialQuery == null) {
1375 // Use any text typed in the launcher as the initial query
1376 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001377 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001378 if (appSearchData == null) {
1379 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001380 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001381 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001382 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001383
Karl Rosaen138a0412009-04-23 19:00:21 -07001384 final SearchManager searchManager =
1385 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001386 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001387 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001388 }
1389
Winson Chung70d72102011-08-12 11:24:35 -07001390 @Override
1391 public boolean onCreateOptionsMenu(Menu menu) {
1392 if (isWorkspaceLocked()) {
1393 return false;
1394 }
1395
1396 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001397
1398 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1399 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1400 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001401 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1402 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1403 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001404 String helpUrl = getString(R.string.help_url);
1405 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001406 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1407 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1408
Winson Chung70d72102011-08-12 11:24:35 -07001409 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1410 .setIcon(android.R.drawable.ic_menu_gallery)
1411 .setAlphabeticShortcut('W');
1412 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1413 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001414 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001415 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001416 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1417 .setIcon(android.R.drawable.ic_menu_preferences)
1418 .setIntent(settings)
1419 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001420 if (!helpUrl.isEmpty()) {
1421 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1422 .setIcon(android.R.drawable.ic_menu_help)
1423 .setIntent(help)
1424 .setAlphabeticShortcut('H');
1425 }
Winson Chung70d72102011-08-12 11:24:35 -07001426 return true;
1427 }
1428
1429 @Override
1430 public boolean onPrepareOptionsMenu(Menu menu) {
1431 super.onPrepareOptionsMenu(menu);
1432
1433 if (mAppsCustomizeTabHost.isTransitioning()) {
1434 return false;
1435 }
1436 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1437 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1438
1439 return true;
1440 }
1441
1442 @Override
1443 public boolean onOptionsItemSelected(MenuItem item) {
1444 switch (item.getItemId()) {
1445 case MENU_WALLPAPER_SETTINGS:
1446 startWallpaper();
1447 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001448 }
1449
1450 return super.onOptionsItemSelected(item);
1451 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001452
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001453 @Override
1454 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001455 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001456 // Use a custom animation for launching search
1457 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001458 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001459 }
1460
Joe Onorato9c1289c2009-08-17 11:03:03 -04001461 public boolean isWorkspaceLocked() {
1462 return mWorkspaceLoading || mWaitingForResult;
1463 }
1464
Michael Jurka0280c3b2010-09-17 15:00:07 -07001465 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001466 mPendingAddInfo.container = ItemInfo.NO_ID;
1467 mPendingAddInfo.screen = -1;
1468 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1469 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
1470 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001471 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001472
Michael Jurkaaf442092010-06-10 17:01:57 -07001473 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001474 // TODO: catch bad widget exception when sent
1475 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001476 // TODO: Is this log message meaningful?
1477 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001478 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001479 }
1480
Adam Cohened66b2b2012-01-23 17:28:51 -08001481 void addAppWidgetImpl(final int appWidgetId, final PendingAddWidgetInfo info) {
1482 final AppWidgetProviderInfo appWidget = info.info;
1483 Runnable configurationActivity = null;
Bjorn Bringert7984c942009-12-09 15:38:25 +00001484 if (appWidget.configure != null) {
1485 // Launch over to configure widget, if needed
1486 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1487 intent.setComponent(appWidget.configure);
1488 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001489 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001490 if (info.mimeType != null && !info.mimeType.isEmpty()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001491 intent.putExtra(InstallWidgetReceiver.
1492 EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE, info.mimeType);
Winson Chung68846fd2010-10-29 11:00:27 -07001493
1494 final String mimeType = info.mimeType;
1495 final ClipData clipData = (ClipData) info.configurationData;
1496 final ClipDescription clipDesc = clipData.getDescription();
1497 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1498 if (clipDesc.getMimeType(i).equals(mimeType)) {
Dianne Hackborn0d5aad72011-01-17 15:28:58 -08001499 final ClipData.Item item = clipData.getItemAt(i);
Winson Chung68846fd2010-10-29 11:00:27 -07001500 final CharSequence stringData = item.getText();
1501 final Uri uriData = item.getUri();
1502 final Intent intentData = item.getIntent();
Adam Cohened66b2b2012-01-23 17:28:51 -08001503 final String key = InstallWidgetReceiver.
1504 EXTRA_APPWIDGET_CONFIGURATION_DATA;
Winson Chung68846fd2010-10-29 11:00:27 -07001505 if (uriData != null) {
1506 intent.putExtra(key, uriData);
1507 } else if (intentData != null) {
1508 intent.putExtra(key, intentData);
1509 } else if (stringData != null) {
1510 intent.putExtra(key, stringData);
1511 }
1512 break;
1513 }
1514 }
1515 }
Winson Chung55cef262010-10-28 14:14:18 -07001516 }
Romain Guy8e633c52010-03-04 12:51:36 -08001517 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
Adam Cohened66b2b2012-01-23 17:28:51 -08001518 mWidgetBeingConfigured = info;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001519 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001520 // Otherwise just add it
Adam Cohened66b2b2012-01-23 17:28:51 -08001521 completeAddAppWidget(appWidgetId, info.container, info.screen, info.boundWidget, appWidget);
Winson Chung557d6ed2011-07-08 15:34:52 -07001522 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001523 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001524 }
1525 }
Romain Guycbb89e42009-06-08 15:52:54 -07001526
Adam Cohenfbba09b2011-07-18 21:43:05 -07001527 /**
1528 * Process a shortcut drop.
1529 *
1530 * @param componentName The name of the component
1531 * @param screen The screen where it should be added
1532 * @param cell The cell it should be added to, optional
1533 * @param position The location on the screen where it was dropped, optional
1534 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001535 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1536 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001537 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001538 mPendingAddInfo.container = container;
1539 mPendingAddInfo.screen = screen;
1540 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001541
1542 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001543 mPendingAddInfo.cellX = cell[0];
1544 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001545 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001546
1547 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1548 createShortcutIntent.setComponent(componentName);
1549 processShortcut(createShortcutIntent);
1550 }
1551
Adam Cohenfbba09b2011-07-18 21:43:05 -07001552 /**
1553 * Process a widget drop.
1554 *
1555 * @param info The PendingAppWidgetInfo of the widget being added.
1556 * @param screen The screen where it should be added
1557 * @param cell The cell it should be added to, optional
1558 * @param position The location on the screen where it was dropped, optional
1559 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001560 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
1561 int[] cell, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001562 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001563 mPendingAddInfo.container = info.container = container;
1564 mPendingAddInfo.screen = info.screen = screen;
1565 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001566 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001567 mPendingAddInfo.cellX = cell[0];
1568 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001569 }
1570
Adam Cohened66b2b2012-01-23 17:28:51 -08001571 AppWidgetHostView hostView = info.boundWidget;
1572 int appWidgetId;
1573 if (hostView != null) {
1574 appWidgetId = hostView.getAppWidgetId();
1575 } else {
1576 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1577 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1578 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001579 addAppWidgetImpl(appWidgetId, info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001580
Adam Cohenfbba09b2011-07-18 21:43:05 -07001581 }
1582
Joe Onoratodeb98af2010-02-19 14:59:39 -08001583 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001584 // Handle case where user selected "Applications"
1585 String applicationName = getResources().getString(R.string.group_applications);
1586 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001587
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001588 if (applicationName != null && applicationName.equals(shortcutName)) {
1589 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1590 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001591
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001592 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1593 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001594 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001595 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001596 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001597 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001598 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001599 }
1600
Winson Chung24ab2f12010-09-16 14:10:47 -07001601 void processWallpaper(Intent intent) {
1602 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1603 }
1604
Winson Chung3d503fb2011-07-13 17:25:49 -07001605 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1606 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001607 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001608 folderInfo.title = getText(R.string.folder_name);
1609
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001610 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001611 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1612 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001613 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001614
1615 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001616 FolderIcon newFolder =
1617 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1618 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1619 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001620 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001621 }
Romain Guycbb89e42009-06-08 15:52:54 -07001622
Joe Onorato9c1289c2009-08-17 11:03:03 -04001623 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001624 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001625 }
1626
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001627 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001628 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001629 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001630 Intent chooser = Intent.createChooser(pickWallpaper,
1631 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001632 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1633 // Removed in Eclair MR1
1634// WallpaperManager wm = (WallpaperManager)
1635// getSystemService(Context.WALLPAPER_SERVICE);
1636// WallpaperInfo wi = wm.getWallpaperInfo();
1637// if (wi != null && wi.getSettingsActivity() != null) {
1638// LabeledIntent li = new LabeledIntent(getPackageName(),
1639// R.string.configure_wallpaper, 0);
1640// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1641// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1642// }
Mike Clerona0618e42009-10-22 13:55:21 -07001643 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001644 }
1645
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001646 /**
1647 * Registers various content observers. The current implementation registers
1648 * only a favorites observer to keep track of the favorites applications.
1649 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001650 private void registerContentObservers() {
1651 ContentResolver resolver = getContentResolver();
1652 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1653 true, mWidgetObserver);
1654 }
1655
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001656 @Override
1657 public boolean dispatchKeyEvent(KeyEvent event) {
1658 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1659 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001660 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001661 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001662 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001663 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001664 dumpState();
1665 return true;
1666 }
1667 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001668 }
1669 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1670 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001671 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001672 return true;
1673 }
1674 }
1675
1676 return super.dispatchKeyEvent(event);
1677 }
1678
Joe Onorato88ec0992009-11-19 13:16:06 -08001679 @Override
1680 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001681 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001682 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001683 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001684 Folder openFolder = mWorkspace.getOpenFolder();
1685 if (openFolder.isEditingName()) {
1686 openFolder.dismissEditingName();
1687 } else {
1688 closeFolder();
1689 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001690 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001691 mWorkspace.exitWidgetResizeMode();
1692
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001693 // Back button is a no-op here, but give at least some feedback for the button press
1694 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001695 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001696 }
1697
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001698 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001699 * Re-listen when widgets are reset.
1700 */
1701 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001702 if (mAppWidgetHost != null) {
1703 mAppWidgetHost.startListening();
1704 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001705 }
1706
1707 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001708 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1709 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001710 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001711 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001712 if (mModel != null) {
1713 mModel.unbindWorkspaceItems();
1714 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001715 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001716
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717 /**
1718 * Launches the intent referred by the clicked shortcut.
1719 *
1720 * @param v The view representing the clicked shortcut.
1721 */
1722 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001723 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1724 // view has detached (it's possible for this to happen if the view is removed mid touch).
1725 if (v.getWindowToken() == null) {
1726 return;
1727 }
1728
1729 if (mWorkspace.isSwitchingState()) {
1730 return;
1731 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001732
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001733 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001734 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001735 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001736 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001737 int[] pos = new int[2];
1738 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001739 intent.setSourceBounds(new Rect(pos[0], pos[1],
1740 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Michael Jurkaddd62e92011-02-16 17:49:14 -08001741 boolean success = startActivitySafely(intent, tag);
1742
1743 if (success && v instanceof BubbleTextView) {
1744 mWaitingForResume = (BubbleTextView) v;
1745 mWaitingForResume.setStayPressed(true);
1746 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001747 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001748 if (v instanceof FolderIcon) {
1749 FolderIcon fi = (FolderIcon) v;
1750 handleFolderClick(fi);
1751 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001752 } else if (v == mAllAppsButton) {
1753 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001754 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001755 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001756 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001757 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001758 }
1759 }
1760
Michael Jurka0e260592010-06-30 17:07:39 -07001761 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001762 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001763 // clicking anywhere on the workspace causes the customization drawer to slide down
1764 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001765 return false;
1766 }
1767
Michael Jurkaaf442092010-06-10 17:01:57 -07001768 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001769 * Event handler for the search button
1770 *
1771 * @param v The view that was clicked.
1772 */
1773 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001774 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1775
Amith Yamasania135ba82011-08-09 17:42:01 -07001776 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001777 }
1778
1779 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001780 * Event handler for the voice button
1781 *
1782 * @param v The view that was clicked.
1783 */
1784 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001785 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001786
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001787 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001788 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001789 startActivity(intent);
1790 }
1791
1792 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001793 * Event handler for the "grid" button that appears on the home screen, which
1794 * enters all apps mode.
1795 *
1796 * @param v The view that was clicked.
1797 */
1798 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001799 showAllApps(true);
1800 }
1801
1802 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001803 // Provide the same haptic feedback that the system offers for virtual keys.
1804 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001805 }
1806
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001807 public void onClickAppMarketButton(View v) {
1808 if (mAppMarketIntent != null) {
1809 startActivitySafely(mAppMarketIntent, "app market");
1810 }
1811 }
1812
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001813 void startApplicationDetailsActivity(ComponentName componentName) {
1814 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001815 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1816 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001817 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001818 startActivity(intent);
1819 }
1820
Patrick Dubroy5539af72010-09-07 15:22:01 -07001821 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1822 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1823 // System applications cannot be installed. For now, show a toast explaining that.
1824 // We may give them the option of disabling apps this way.
1825 int messageId = R.string.uninstall_system_app_text;
1826 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1827 } else {
1828 String packageName = appInfo.componentName.getPackageName();
1829 String className = appInfo.componentName.getClassName();
1830 Intent intent = new Intent(
1831 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001832 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1833 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001834 startActivity(intent);
1835 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001836 }
1837
Michael Jurkaddd62e92011-02-16 17:49:14 -08001838 boolean startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001839 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1840 try {
1841 startActivity(intent);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001842 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001843 } catch (ActivityNotFoundException e) {
1844 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001845 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001846 } catch (SecurityException e) {
1847 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001848 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001849 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001850 "or use the exported attribute for this activity. "
1851 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001852 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001853 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001854 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001855
Romain Guy8e633c52010-03-04 12:51:36 -08001856 void startActivityForResultSafely(Intent intent, int requestCode) {
1857 try {
1858 startActivityForResult(intent, requestCode);
1859 } catch (ActivityNotFoundException e) {
1860 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1861 } catch (SecurityException e) {
1862 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1863 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1864 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1865 "or use the exported attribute for this activity.", e);
1866 }
1867 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001868
Adam Cohena9cf38f2011-05-02 15:36:58 -07001869 private void handleFolderClick(FolderIcon folderIcon) {
1870 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07001871 Folder openFolder = mWorkspace.getFolderForTag(info);
1872
1873 // If the folder info reports that the associated folder is open, then verify that
1874 // it is actually opened. There have been a few instances where this gets out of sync.
1875 if (info.opened && openFolder == null) {
1876 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
1877 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
1878 info.opened = false;
1879 }
1880
Adam Cohena9cf38f2011-05-02 15:36:58 -07001881 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001882 // Close any open folder
1883 closeFolder();
1884 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07001885 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001886 } else {
1887 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001888 int folderScreen;
1889 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001890 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001891 // .. and close it
1892 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001893 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001894 // Close any folder open on the current screen
1895 closeFolder();
1896 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07001897 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001898 }
1899 }
1900 }
1901 }
1902
Adam Cohen2801caf2011-05-13 20:57:39 -07001903 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001904 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001905 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
1906 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
1907 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
1908
Adam Cohenc51934b2011-07-26 21:07:43 -07001909 FolderInfo info = (FolderInfo) fi.getTag();
1910 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1911 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07001912 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
1913 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07001914 }
1915
Adam Cohen2801caf2011-05-13 20:57:39 -07001916 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1917 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1918 oa.start();
1919 }
1920
1921 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001922 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001923 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1924 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1925 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1926
Adam Cohenc51934b2011-07-26 21:07:43 -07001927 FolderInfo info = (FolderInfo) fi.getTag();
1928 CellLayout cl = null;
1929 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1930 cl = (CellLayout) fi.getParent().getParent();
1931 }
1932
1933 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07001934 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1935 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07001936 oa.addListener(new AnimatorListenerAdapter() {
1937 @Override
1938 public void onAnimationEnd(Animator animation) {
1939 if (layout != null) {
1940 layout.clearFolderLeaveBehind();
1941 }
1942 }
1943 });
Adam Cohen2801caf2011-05-13 20:57:39 -07001944 oa.start();
1945 }
1946
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001947 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001948 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001949 * is animated relative to the specified View. If the View is null, no animation
1950 * is played.
1951 *
1952 * @param folderInfo The FolderInfo describing the folder to open.
1953 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001954 public void openFolder(FolderIcon folderIcon) {
1955 Folder folder = folderIcon.mFolder;
1956 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001957
Adam Cohen2801caf2011-05-13 20:57:39 -07001958 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001959 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001960
Adam Cohen4554ee12011-08-03 16:13:21 -07001961 // Just verify that the folder hasn't already been added to the DragLayer.
1962 // There was a one-off crash where the folder had a parent already.
1963 if (folder.getParent() == null) {
1964 mDragLayer.addView(folder);
1965 mDragController.addDropTarget((DropTarget) folder);
1966 } else {
1967 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
1968 folder.getParent() + ").");
1969 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001970 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07001971 }
1972
1973 public void closeFolder() {
1974 Folder folder = mWorkspace.getOpenFolder();
1975 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07001976 if (folder.isEditingName()) {
1977 folder.dismissEditingName();
1978 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001979 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07001980
1981 // Dismiss the folder cling
1982 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07001983 }
1984 }
1985
1986 void closeFolder(Folder folder) {
1987 folder.getInfo().opened = false;
1988
1989 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
1990 if (parent != null) {
1991 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
1992 shrinkAndFadeInFolderIcon(fi);
1993 }
1994 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001995 }
1996
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001997 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08001998 if (mState != State.WORKSPACE) {
1999 return false;
2000 }
2001
Joe Onorato9c1289c2009-08-17 11:03:03 -04002002 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003 return false;
2004 }
2005
2006 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002007 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002008 }
2009
Michael Jurka0280c3b2010-09-17 15:00:07 -07002010 resetAddInfo();
2011 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002012 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002013 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002014 return true;
2015 }
2016
Winson Chung3d503fb2011-07-13 17:25:49 -07002017 // The hotseat touch handling does not go through Workspace, and we always allow long press
2018 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002019 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002020 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2021 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002022 if (itemUnderLongClick == null) {
2023 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002024 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2025 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002026 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002027 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002028 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002029 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002030 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031 }
2032 }
2033 }
2034 return true;
2035 }
2036
Winson Chung3d503fb2011-07-13 17:25:49 -07002037 boolean isHotseatLayout(View layout) {
2038 return mHotseat != null && layout != null &&
2039 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2040 }
2041 Hotseat getHotseat() {
2042 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002043 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002044 SearchDropTargetBar getSearchBar() {
2045 return mSearchDropTargetBar;
2046 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002047
Winson Chung3d503fb2011-07-13 17:25:49 -07002048 /**
2049 * Returns the CellLayout of the specified container at the specified screen.
2050 */
2051 CellLayout getCellLayout(long container, int screen) {
2052 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2053 if (mHotseat != null) {
2054 return mHotseat.getLayout();
2055 } else {
2056 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002057 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002058 } else {
2059 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002060 }
2061 }
2062
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002063 Workspace getWorkspace() {
2064 return mWorkspace;
2065 }
2066
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002067 @Override
2068 protected Dialog onCreateDialog(int id) {
2069 switch (id) {
2070 case DIALOG_CREATE_SHORTCUT:
2071 return new CreateShortcut().createDialog();
2072 case DIALOG_RENAME_FOLDER:
2073 return new RenameFolder().createDialog();
2074 }
2075
2076 return super.onCreateDialog(id);
2077 }
2078
2079 @Override
2080 protected void onPrepareDialog(int id, Dialog dialog) {
2081 switch (id) {
2082 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002083 break;
2084 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002085 if (mFolderInfo != null) {
2086 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2087 final CharSequence text = mFolderInfo.title;
2088 input.setText(text);
2089 input.setSelection(0, text.length());
2090 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002091 break;
2092 }
2093 }
2094
2095 void showRenameDialog(FolderInfo info) {
2096 mFolderInfo = info;
2097 mWaitingForResult = true;
2098 showDialog(DIALOG_RENAME_FOLDER);
2099 }
2100
Adam Cohenfbba09b2011-07-18 21:43:05 -07002101 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002102 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002103 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
2104 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002105 mWaitingForResult = true;
2106 showDialog(DIALOG_CREATE_SHORTCUT);
2107 }
2108
2109 private class RenameFolder {
2110 private EditText mInput;
2111
2112 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002113 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2114 mInput = (EditText) layout.findViewById(R.id.folder_name);
2115
2116 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2117 builder.setIcon(0);
2118 builder.setTitle(getString(R.string.rename_folder_title));
2119 builder.setCancelable(true);
2120 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2121 public void onCancel(DialogInterface dialog) {
2122 cleanup();
2123 }
2124 });
2125 builder.setNegativeButton(getString(R.string.cancel_action),
2126 new Dialog.OnClickListener() {
2127 public void onClick(DialogInterface dialog, int which) {
2128 cleanup();
2129 }
2130 }
2131 );
2132 builder.setPositiveButton(getString(R.string.rename_action),
2133 new Dialog.OnClickListener() {
2134 public void onClick(DialogInterface dialog, int which) {
2135 changeFolderName();
2136 }
2137 }
2138 );
2139 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002140
2141 final AlertDialog dialog = builder.create();
2142 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2143 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002144 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002145 mInput.requestFocus();
2146 InputMethodManager inputManager = (InputMethodManager)
2147 getSystemService(Context.INPUT_METHOD_SERVICE);
2148 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002149 }
2150 });
2151
2152 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002153 }
2154
2155 private void changeFolderName() {
2156 final String name = mInput.getText().toString();
2157 if (!TextUtils.isEmpty(name)) {
2158 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002159 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002160 mFolderInfo.title = name;
2161 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2162
Joe Onorato9c1289c2009-08-17 11:03:03 -04002163 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002164 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002165 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002166 } else {
2167 final FolderIcon folderIcon = (FolderIcon)
2168 mWorkspace.getViewForTag(mFolderInfo);
2169 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002170 // TODO: At some point we'll probably want some version of setting
2171 // the text for a folder icon.
2172 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002173 getWorkspace().requestLayout();
2174 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002175 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002176 mWorkspaceLoading = true;
2177 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002178 }
2179 }
2180 }
2181 cleanup();
2182 }
2183
2184 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002185 dismissDialog(DIALOG_RENAME_FOLDER);
2186 mWaitingForResult = false;
2187 mFolderInfo = null;
2188 }
2189 }
2190
Daniel Sandler843e8602010-06-07 14:59:01 -04002191 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2192 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002193 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002194 }
2195
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002196 // AllAppsView.Watcher
2197 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002198 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002199 mWorkspace.setVisibility(View.GONE);
2200 }
2201 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002202
2203 /**
2204 * Helper method for the cameraZoomIn/cameraZoomOut animations
2205 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002206 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002207 * @param scaleFactor The scale factor used for the zoom
2208 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002209 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002210 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002211 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002212 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002213
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002214 void updateWallpaperVisibility(boolean visible) {
2215 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2216 int curflags = getWindow().getAttributes().flags
2217 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2218 if (wpflags != curflags) {
2219 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2220 }
2221 }
2222
Michael Jurkabed61d22012-02-14 22:51:29 -08002223 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2224 if (v instanceof LauncherTransitionable) {
2225 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2226 }
2227 }
2228
2229 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2230 if (v instanceof LauncherTransitionable) {
2231 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2232 }
2233 }
2234
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002235 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002236 * Things to test when changing the following seven functions.
2237 * - Home from workspace
2238 * - from center screen
2239 * - from other screens
2240 * - Home from all apps
2241 * - from center screen
2242 * - from other screens
2243 * - Back from all apps
2244 * - from center screen
2245 * - from other screens
2246 * - Launch app from workspace and quit
2247 * - with back
2248 * - with home
2249 * - Launch app from all apps and quit
2250 * - with back
2251 * - with home
2252 * - Go to a screen that's not the default, then all
2253 * apps, and launch and app, and go back
2254 * - with back
2255 * -with home
2256 * - On workspace, long press power and go back
2257 * - with back
2258 * - with home
2259 * - On all apps, long press power and go back
2260 * - with back
2261 * - with home
2262 * - On workspace, power off
2263 * - On all apps, power off
2264 * - Launch an app and turn off the screen while in that app
2265 * - Go back with home key
2266 * - Go back with back key TODO: make this not go to workspace
2267 * - From all apps
2268 * - From workspace
2269 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2270 * - From all apps
2271 * - From the center workspace
2272 * - From another workspace
2273 */
2274
2275 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002276 * Zoom the camera out from the workspace to reveal 'toView'.
2277 * Assumes that the view to show is anchored at either the very top or very bottom
2278 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002279 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002280 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002281 if (mStateAnimation != null) {
2282 mStateAnimation.cancel();
2283 mStateAnimation = null;
2284 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002285 final Resources res = getResources();
Winson Chung7d7541e2011-09-16 20:14:36 -07002286 final Launcher instance = this;
Adam Cohenf16e5712011-01-13 13:31:45 -08002287
Winson Chungf0ea4d32011-06-06 14:27:16 -07002288 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2289 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2290 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002291 final View fromView = mWorkspace;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002292 final View toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002293 final int startDelay =
2294 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002295
Michael Jurkab3e22d92011-10-31 15:58:33 -07002296 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002297
Michael Jurkad74c9842011-07-10 12:44:21 -07002298 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002299 Animator workspaceAnim =
2300 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002301
2302 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002303 toView.setScaleX(scale);
2304 toView.setScaleY(scale);
2305 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2306 scaleAnim.
2307 scaleX(1f).scaleY(1f).
2308 setDuration(duration).
2309 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002310
Winson Chungf0ea4d32011-06-06 14:27:16 -07002311 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002312 toView.setAlpha(0f);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002313 final ObjectAnimator alphaAnim = ObjectAnimator
2314 .ofFloat(toView, "alpha", 0f, 1f)
2315 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002316 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Adam Cohenf16e5712011-01-13 13:31:45 -08002317
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002318 // toView should appear right at the end of the workspace shrink
2319 // animation
2320 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002321 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002322 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002323
2324 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002325 boolean animationCancelled = false;
2326
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002327 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002328 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002329 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002330 // Prepare the position
2331 toView.setTranslationX(0.0f);
2332 toView.setTranslationY(0.0f);
2333 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002334 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002335 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002336 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002337 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002338 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2339 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002340
2341 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2342 // Hide the workspace scrollbar
2343 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002344 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002345 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002346 if (!animationCancelled) {
2347 updateWallpaperVisibility(false);
2348 }
2349 }
2350
Adam Cohencff6af82011-09-13 14:51:53 -07002351 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002352 public void onAnimationCancel(Animator animation) {
2353 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002354 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002355 });
2356
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002357 if (workspaceAnim != null) {
2358 mStateAnimation.play(workspaceAnim);
2359 }
Michael Jurka1899a362011-11-03 13:50:45 -07002360
2361 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002362 final ViewTreeObserver observer;
2363
Michael Jurkabed61d22012-02-14 22:51:29 -08002364 dispatchOnLauncherTransitionStart(fromView, animated, false);
2365 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002366
2367 // If any of the objects being animated haven't been measured/laid out
2368 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002369 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002370 (mWorkspace.getMeasuredWidth() == 0) ||
2371 (toView.getMeasuredWidth() == 0)) {
2372 observer = mWorkspace.getViewTreeObserver();
2373 delayAnim = true;
2374 } else {
2375 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002376 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002377
2378 if (delayAnim) {
Michael Jurka49779a12012-01-16 04:10:08 -08002379 final AnimatorSet stateAnimation = mStateAnimation;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002380 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2381 public void onGlobalLayout() {
2382 mWorkspace.post(new Runnable() {
2383 public void run() {
Michael Jurka49779a12012-01-16 04:10:08 -08002384 // Check that mStateAnimation hasn't changed while
2385 // we waited for a layout pass
2386 if (mStateAnimation == stateAnimation) {
2387 // Need to update pivots for zoom if layout changed
2388 setPivotsForZoom(toView, scale);
2389 mStateAnimation.start();
2390 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002391 }
2392 });
2393 observer.removeGlobalOnLayoutListener(this);
2394 }
2395 };
2396 observer.addOnGlobalLayoutListener(delayedStart);
2397 } else {
2398 setPivotsForZoom(toView, scale);
Michael Jurka1899a362011-11-03 13:50:45 -07002399 mStateAnimation.start();
2400 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002401 } else {
2402 toView.setTranslationX(0.0f);
2403 toView.setTranslationY(0.0f);
2404 toView.setScaleX(1.0f);
2405 toView.setScaleY(1.0f);
2406 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002407 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002408
Michael Jurkabed61d22012-02-14 22:51:29 -08002409 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2410 // Hide the workspace scrollbar
2411 mWorkspace.hideScrollingIndicator(true);
2412 hideDockDivider();
Michael Jurkaabded662011-03-04 12:06:57 -08002413 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002414 dispatchOnLauncherTransitionStart(fromView, animated, false);
2415 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2416 dispatchOnLauncherTransitionStart(toView, animated, false);
2417 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002418 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002419 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002420 }
2421
2422 /**
2423 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002424 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002425 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002426 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002427 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2428 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002429
Michael Jurkab3e22d92011-10-31 15:58:33 -07002430 if (mStateAnimation != null) {
2431 mStateAnimation.cancel();
2432 mStateAnimation = null;
2433 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002434 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002435
Winson Chungf0ea4d32011-06-06 14:27:16 -07002436 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002437 final int fadeOutDuration =
2438 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002439 final float scaleFactor = (float)
2440 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2441 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002442 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002443 Animator workspaceAnim = null;
2444
2445 if (toState == State.WORKSPACE) {
2446 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2447 workspaceAnim = mWorkspace.getChangeStateAnimation(
2448 Workspace.State.NORMAL, animated, stagger);
2449 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2450 workspaceAnim = mWorkspace.getChangeStateAnimation(
2451 Workspace.State.SPRING_LOADED, animated);
2452 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002453
Michael Jurkab3e22d92011-10-31 15:58:33 -07002454 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002455 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002456 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002457 if (animated) {
Michael Jurka742574b2011-02-02 23:51:01 -08002458 final float oldScaleX = fromView.getScaleX();
2459 final float oldScaleY = fromView.getScaleY();
2460
Michael Jurka159b4cc2012-01-17 03:00:35 -08002461 final LauncherViewPropertyAnimator scaleAnim =
2462 new LauncherViewPropertyAnimator(fromView);
2463 scaleAnim.
2464 scaleX(scaleFactor).scaleY(scaleFactor).
2465 setDuration(duration).
2466 setInterpolator(new Workspace.ZoomInInterpolator());
2467
2468 final ObjectAnimator alphaAnim = ObjectAnimator
2469 .ofFloat(fromView, "alpha", 1f, 0f)
2470 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002471 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Michael Jurka159b4cc2012-01-17 03:00:35 -08002472
Michael Jurkabed61d22012-02-14 22:51:29 -08002473 mStateAnimation = new AnimatorSet();
2474
2475 dispatchOnLauncherTransitionStart(fromView, animated, true);
2476 dispatchOnLauncherTransitionStart(toView, animated, true);
2477
2478 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002479 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002480 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002481 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002482 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002483 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2484 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurka430e8a52011-08-08 15:52:14 -07002485 mWorkspace.hideScrollingIndicator(false);
Adam Cohened66b2b2012-01-23 17:28:51 -08002486 if (onCompleteRunnable != null) {
2487 onCompleteRunnable.run();
2488 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002489 }
2490 });
2491
Winson Chungf0ea4d32011-06-06 14:27:16 -07002492 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002493 if (workspaceAnim != null) {
2494 mStateAnimation.play(workspaceAnim);
2495 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002496 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002497 } else {
2498 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002499 dispatchOnLauncherTransitionStart(fromView, animated, true);
2500 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2501 dispatchOnLauncherTransitionStart(toView, animated, true);
2502 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002503 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002504 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002505 }
2506
Michael Jurkae326f182011-11-21 14:05:46 -08002507 @Override
2508 public void onTrimMemory(int level) {
2509 super.onTrimMemory(level);
2510 if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
2511 mAppsCustomizeTabHost.onTrimMemory();
2512 }
2513 }
2514
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002515 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002516 showWorkspace(animated, null);
2517 }
2518
2519 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002520 if (mState != State.WORKSPACE) {
2521 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002522 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002523
2524 // Show the search bar and hotseat
2525 mSearchDropTargetBar.showSearchBar(animated);
Michael Jurkab737ee62011-11-15 15:57:22 -08002526 // We only need to animate in the dock divider if we're going from spring loaded mode
2527 showDockDivider(animated && mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002528
2529 // Set focus to the AppsCustomize button
2530 if (mAllAppsButton != null) {
2531 mAllAppsButton.requestFocus();
2532 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002533 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002534
Michael Jurkab737ee62011-11-15 15:57:22 -08002535 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002536
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002537 // Change the state *after* we've called all the transition code
2538 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002539
Winson Chung5fb63472011-02-02 17:03:37 -08002540 // Resume the auto-advance of widgets
2541 mUserPresent = true;
2542 updateRunning();
2543
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002544 // send an accessibility event to announce the context change
2545 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002546 }
2547
Michael Jurkab3e22d92011-10-31 15:58:33 -07002548 void showAllApps(boolean animated) {
2549 if (mState != State.WORKSPACE) return;
2550
2551 showAppsCustomizeHelper(animated, false);
2552 mAppsCustomizeTabHost.requestFocus();
2553
2554 // Hide the search bar and hotseat
2555 mSearchDropTargetBar.hideSearchBar(animated);
2556
2557 // Change the state *after* we've called all the transition code
2558 mState = State.APPS_CUSTOMIZE;
2559
2560 // Pause the auto-advance of widgets until we are out of AllApps
2561 mUserPresent = false;
2562 updateRunning();
2563 closeFolder();
2564
2565 // Send an accessibility event to announce the context change
2566 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2567 }
2568
Adam Cohen7777d962011-08-18 18:58:38 -07002569 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002570 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002571 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002572 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002573 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002574 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002575 }
Adam Cohen7777d962011-08-18 18:58:38 -07002576
Adam Cohened66b2b2012-01-23 17:28:51 -08002577 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2578 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002579 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2580
Winson Chunge7a03942011-08-05 15:05:12 -07002581 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002582 @Override
2583 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002584 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002585 // Before we show workspace, hide all apps again because
2586 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2587 // clean up our state transition functions
2588 mAppsCustomizeTabHost.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002589 mSearchDropTargetBar.showSearchBar(true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002590 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002591 } else {
2592 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002593 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002594 }
2595 }, (extendedDelay ?
2596 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2597 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2598 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002599
Michael Jurkad3ef3062010-11-23 16:23:58 -08002600 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002601 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002602 final boolean animated = true;
2603 final boolean springLoaded = true;
2604 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002605 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002606 }
2607 // Otherwise, we are not in spring loaded mode, so don't do anything.
2608 }
2609
Michael Jurkab737ee62011-11-15 15:57:22 -08002610 void hideDockDivider() {
2611 if (mQsbDivider != null && mDockDivider != null) {
2612 mQsbDivider.setVisibility(View.INVISIBLE);
2613 mDockDivider.setVisibility(View.INVISIBLE);
2614 }
2615 }
2616
2617 void showDockDivider(boolean animated) {
2618 if (mQsbDivider != null && mDockDivider != null) {
2619 mQsbDivider.setVisibility(View.VISIBLE);
2620 mDockDivider.setVisibility(View.VISIBLE);
2621 if (mDividerAnimator != null) {
2622 mDividerAnimator.cancel();
2623 mQsbDivider.setAlpha(1f);
2624 mDockDivider.setAlpha(1f);
2625 mDividerAnimator = null;
2626 }
2627 if (animated) {
2628 mDividerAnimator = new AnimatorSet();
2629 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2630 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2631 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2632 mDividerAnimator.start();
2633 }
2634 }
2635 }
2636
Michael Jurkab3e22d92011-10-31 15:58:33 -07002637 void lockAllApps() {
2638 // TODO
2639 }
2640
2641 void unlockAllApps() {
2642 // TODO
2643 }
2644
Adam Cohenfc53cd22011-07-20 15:45:11 -07002645 public boolean isAllAppsCustomizeOpen() {
2646 return mState == State.APPS_CUSTOMIZE;
2647 }
2648
Winson Chungf0ea4d32011-06-06 14:27:16 -07002649 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002650 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002651 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002652 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002653 if (!LauncherApplication.isScreenLarge()) {
2654 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002655 if (mHotseat.getAlpha() != 1f) {
2656 int duration = mSearchDropTargetBar.getTransitionInDuration();
2657 mHotseat.animate().alpha(1f).setDuration(duration);
2658 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002659 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002660 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002661 }
2662 }
2663 }
2664
2665 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002666 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002667 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002668 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002669 if (!LauncherApplication.isScreenLarge()) {
2670 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002671 if (mHotseat.getAlpha() != 0f) {
2672 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2673 mHotseat.animate().alpha(0f).setDuration(duration);
2674 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002675 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002676 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002677 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002678 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002679 }
2680
Patrick Dubroy5f445422011-02-18 14:35:21 -08002681 /**
2682 * Add an item from all apps or customize onto the given workspace screen.
2683 * If layout is null, add to the current screen.
2684 */
2685 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002686 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2687 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07002688 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002689 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002690
Winson Chungdff8ebb2011-09-08 17:25:31 -07002691 /** Maps the current orientation to an index for referencing orientation correct global icons */
2692 private int getCurrentOrientationIndexForGlobalIcons() {
2693 // default - 0, landscape - 1
2694 switch (getResources().getConfiguration().orientation) {
2695 case Configuration.ORIENTATION_LANDSCAPE:
2696 return 1;
2697 default:
2698 return 0;
2699 }
2700 }
2701
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002702 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002703 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002704 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002705 // Look for the toolbar icon specified in the activity meta-data
2706 Bundle metaData = packageManager.getActivityInfo(
2707 activityName, PackageManager.GET_META_DATA).metaData;
2708 if (metaData != null) {
2709 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2710 if (iconResId != 0) {
2711 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002712 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002713 }
2714 }
2715 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002716 // This can happen if the activity defines an invalid drawable
2717 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2718 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002719 } catch (Resources.NotFoundException nfe) {
2720 // This can happen if the activity defines an invalid drawable
2721 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2722 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002723 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002724 return null;
2725 }
2726
2727 // if successful in getting icon, return it; otherwise, set button to use default drawable
2728 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2729 int buttonId, ComponentName activityName, int fallbackDrawableId) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002730 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002731 Resources r = getResources();
2732 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2733 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002734
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002735 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002736 // If we were unable to find the icon via the meta-data, use a generic one
2737 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002738 toolbarIcon = r.getDrawable(fallbackDrawableId);
2739 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002740 if (button != null) {
2741 button.setCompoundDrawables(toolbarIcon, null, null, null);
2742 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002743 return null;
2744 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002745 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002746 if (button != null) {
2747 button.setCompoundDrawables(toolbarIcon, null, null, null);
2748 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002749 return toolbarIcon.getConstantState();
2750 }
2751 }
2752
2753 // if successful in getting icon, return it; otherwise, set button to use default drawable
2754 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2755 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2756 ImageView button = (ImageView) findViewById(buttonId);
2757 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2758
Michael Jurka19e0fc52011-07-22 18:00:21 -07002759 if (button != null) {
2760 // If we were unable to find the icon via the meta-data, use a
2761 // generic one
2762 if (toolbarIcon == null) {
2763 button.setImageResource(fallbackDrawableId);
2764 } else {
2765 button.setImageDrawable(toolbarIcon);
2766 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002767 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002768
2769 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2770
Michael Jurka0423dcf2010-10-05 14:56:18 -07002771 }
2772
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002773 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2774 TextView button = (TextView) findViewById(buttonId);
2775 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2776 }
2777
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002778 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002779 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002780 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002781 }
2782
Winson Chungbb185bd2011-11-21 12:31:42 -08002783 private void invalidatePressedFocusedStates(View container, View button) {
2784 if (container instanceof HolographicLinearLayout) {
2785 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2786 layout.invalidatePressedFocusedStates();
2787 } else if (button instanceof HolographicImageView) {
2788 HolographicImageView view = (HolographicImageView) button;
2789 view.invalidatePressedFocusedStates();
2790 }
2791 }
2792
Winson Chungc51db6a2011-10-05 11:44:49 -07002793 private boolean updateGlobalSearchIcon() {
2794 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002795 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2796 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002797 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002798 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002799
Winson Chung1cad91e2011-05-25 17:41:01 -07002800 final SearchManager searchManager =
2801 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2802 ComponentName activityName = searchManager.getGlobalSearchActivity();
2803 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002804 int coi = getCurrentOrientationIndexForGlobalIcons();
2805 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002806 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002807 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002808 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2809 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002810 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002811 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002812 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002813 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002814 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002815 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2816 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2817 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002818 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002819 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002820 }
2821 }
2822
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002823 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002824 final View searchButtonContainer = findViewById(R.id.search_button_container);
2825 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002826 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002827 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002828 }
2829
Winson Chungc51db6a2011-10-05 11:44:49 -07002830 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002831 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002832 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002833 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002834
Winson Chungc51db6a2011-10-05 11:44:49 -07002835 // We only show/update the voice search icon if the search icon is enabled as well
Winson Chung1cad91e2011-05-25 17:41:01 -07002836 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2837 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chungc51db6a2011-10-05 11:44:49 -07002838 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002839 int coi = getCurrentOrientationIndexForGlobalIcons();
2840 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002841 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002842 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002843 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002844 voiceButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002845 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002846 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002847 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002848 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002849 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002850 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002851 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002852 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002853 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002854
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002855 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002856 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
2857 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002858 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002859 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002860 }
2861
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002862 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002863 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002864 */
2865 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002866 final View marketButton = findViewById(R.id.market_button);
2867 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2868 // Find the app market activity by resolving an intent.
2869 // (If multiple app markets are installed, it will return the ResolverActivity.)
2870 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002871 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002872 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07002873 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07002874 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002875 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002876 marketButton.setVisibility(View.VISIBLE);
2877 } else {
2878 // We should hide and disable the view so that we don't try and restore the visibility
2879 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2880 marketButton.setVisibility(View.GONE);
2881 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002882 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002883 }
2884
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002885 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002886 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002887 }
2888
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002889 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002890 * Displays the shortcut creation dialog and launches, if necessary, the
2891 * appropriate activity.
2892 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002893 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002894 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2895 DialogInterface.OnShowListener {
2896
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002897 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002898
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002899 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002900 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002901
Winson Chung55b65502011-05-26 12:03:43 -07002902 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2903 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002904 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002905
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002906 AlertDialog dialog = builder.create();
2907 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002908 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002909 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002910
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002911 return dialog;
2912 }
2913
2914 public void onCancel(DialogInterface dialog) {
2915 mWaitingForResult = false;
2916 cleanup();
2917 }
2918
Romain Guycbb89e42009-06-08 15:52:54 -07002919 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002920 mWaitingForResult = false;
2921 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002922 }
2923
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002924 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002925 try {
2926 dismissDialog(DIALOG_CREATE_SHORTCUT);
2927 } catch (Exception e) {
2928 // An exception is thrown if the dialog is not visible, which is fine
2929 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002930 }
2931
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002932 /**
2933 * Handle the action clicked in the "Add to home" dialog.
2934 */
2935 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002936 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002937
Winson Chung55b65502011-05-26 12:03:43 -07002938 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2939 switch (item.actionTag) {
Winson Chung55b65502011-05-26 12:03:43 -07002940 case AddAdapter.ITEM_APPLICATION: {
2941 if (mAppsCustomizeTabHost != null) {
2942 mAppsCustomizeTabHost.selectAppsTab();
2943 }
2944 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002945 break;
2946 }
Winson Chung55b65502011-05-26 12:03:43 -07002947 case AddAdapter.ITEM_APPWIDGET: {
2948 if (mAppsCustomizeTabHost != null) {
2949 mAppsCustomizeTabHost.selectWidgetsTab();
2950 }
2951 showAllApps(true);
2952 break;
2953 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002954 case AddAdapter.ITEM_WALLPAPER: {
2955 startWallpaper();
2956 break;
2957 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002958 }
2959 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002960
2961 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002962 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002963 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002964 }
2965
2966 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07002967 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002968 */
2969 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2970 @Override
2971 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002972 closeSystemDialogs();
2973 }
2974 }
2975
2976 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002977 * Receives notifications whenever the appwidgets are reset.
2978 */
2979 private class AppWidgetResetObserver extends ContentObserver {
2980 public AppWidgetResetObserver() {
2981 super(new Handler());
2982 }
2983
2984 @Override
2985 public void onChange(boolean selfChange) {
2986 onAppWidgetReset();
2987 }
2988 }
2989
2990 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002991 * If the activity is currently paused, signal that we need to re-run the loader
2992 * in onResume.
2993 *
2994 * This needs to be called from incoming places where resources might have been loaded
2995 * while we are paused. That is becaues the Configuration might be wrong
2996 * when we're not running, and if it comes back to what it was when we
2997 * were paused, we are not restarted.
2998 *
2999 * Implementation of the method from LauncherModel.Callbacks.
3000 *
3001 * @return true if we are currently paused. The caller might be able to
3002 * skip some work in that case since we will come back again.
3003 */
3004 public boolean setLoadOnResume() {
3005 if (mPaused) {
3006 Log.i(TAG, "setLoadOnResume");
3007 mOnResumeNeedsLoad = true;
3008 return true;
3009 } else {
3010 return false;
3011 }
3012 }
3013
3014 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003015 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003016 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003017 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003018 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003019 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003020 } else {
3021 return SCREEN_COUNT / 2;
3022 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003023 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003024
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003025
Joe Onorato9c1289c2009-08-17 11:03:03 -04003026 /**
3027 * Refreshes the shortcuts shown on the workspace.
3028 *
3029 * Implementation of the method from LauncherModel.Callbacks.
3030 */
3031 public void startBinding() {
3032 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07003033
3034 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003035 int count = workspace.getChildCount();
3036 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003037 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003038 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3039 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003040 }
Michael Jurka05bf644e2011-11-30 20:28:53 -08003041 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003042 if (mHotseat != null) {
3043 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003044 }
3045 }
3046
3047 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003048 * Bind the items start-end from the list.
3049 *
3050 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003051 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003052 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003053 setLoadOnResume();
3054
Joe Onorato9c1289c2009-08-17 11:03:03 -04003055 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003056 for (int i=start; i<end; i++) {
3057 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003058
3059 // Short circuit if we are loading dock items for a configuration which has no dock
3060 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3061 mHotseat == null) {
3062 continue;
3063 }
3064
Joe Onorato9c1289c2009-08-17 11:03:03 -04003065 switch (item.itemType) {
3066 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3067 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07003068 View shortcut = createShortcut((ShortcutInfo)item);
3069 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3070 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003071 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003072 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003073 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003074 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003075 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003076 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3077 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003078 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003079 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003080 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003081 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003082 }
3083
Joe Onorato9c1289c2009-08-17 11:03:03 -04003084 /**
3085 * Implementation of the method from LauncherModel.Callbacks.
3086 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003087 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003088 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003089 sFolders.clear();
3090 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003091 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003092
3093 /**
3094 * Add the views for a widget to the workspace.
3095 *
3096 * Implementation of the method from LauncherModel.Callbacks.
3097 */
3098 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003099 setLoadOnResume();
3100
Daniel Sandler843e8602010-06-07 14:59:01 -04003101 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3102 if (DEBUG_WIDGETS) {
3103 Log.d(TAG, "bindAppWidget: " + item);
3104 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003105 final Workspace workspace = mWorkspace;
3106
3107 final int appWidgetId = item.appWidgetId;
3108 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003109 if (DEBUG_WIDGETS) {
3110 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3111 }
3112
Joe Onorato9c1289c2009-08-17 11:03:03 -04003113 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3114
Joe Onorato9c1289c2009-08-17 11:03:03 -04003115 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
3116 item.hostView.setTag(item);
3117
Winson Chung3d503fb2011-07-13 17:25:49 -07003118 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003119 item.cellY, item.spanX, item.spanY, false);
3120
Adam Cohended9f8d2010-11-03 13:25:16 -07003121 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3122
Joe Onorato9c1289c2009-08-17 11:03:03 -04003123 workspace.requestLayout();
3124
Daniel Sandler843e8602010-06-07 14:59:01 -04003125 if (DEBUG_WIDGETS) {
3126 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3127 + (SystemClock.uptimeMillis()-start) + "ms");
3128 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003129 }
3130
3131 /**
3132 * Callback saying that there aren't any more items to bind.
3133 *
3134 * Implementation of the method from LauncherModel.Callbacks.
3135 */
3136 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003137 setLoadOnResume();
3138
Joe Onorato9c1289c2009-08-17 11:03:03 -04003139 if (mSavedState != null) {
3140 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003141 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003142 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003143 mSavedState = null;
3144 }
3145
3146 if (mSavedInstanceState != null) {
3147 super.onRestoreInstanceState(mSavedInstanceState);
3148 mSavedInstanceState = null;
3149 }
3150
Joe Onorato9c1289c2009-08-17 11:03:03 -04003151 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003152
3153 // If we received the result of any pending adds while the loader was running (e.g. the
3154 // widget configuration forced an orientation change), process them now.
3155 for (int i = 0; i < sPendingAddList.size(); i++) {
3156 completeAdd(sPendingAddList.get(i));
3157 }
3158 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003159
Winson Chungc51db6a2011-10-05 11:44:49 -07003160 // Update the market app icon as necessary (the other icons will be managed in response to
3161 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003162 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003163
3164 mWorkspace.post(mBuildLayersRunnable);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003165 }
3166
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003167 @Override
3168 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003169 boolean searchVisible = updateGlobalSearchIcon();
3170 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3171 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003172 }
3173
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003174 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003175 * Add the icons for all apps.
3176 *
3177 * Implementation of the method from LauncherModel.Callbacks.
3178 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003179 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3180 // Remove the progress bar entirely; we could also make it GONE
3181 // but better to remove it since we know it's not going to be used
3182 View progressBar = mAppsCustomizeTabHost.
3183 findViewById(R.id.apps_customize_progress_bar);
3184 if (progressBar != null) {
3185 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003186 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003187 // We just post the call to setApps so the user sees the progress bar
3188 // disappear-- otherwise, it just looks like the progress bar froze
3189 // which doesn't look great
3190 mAppsCustomizeTabHost.post(new Runnable() {
3191 public void run() {
3192 if (mAppsCustomizeContent != null) {
3193 mAppsCustomizeContent.setApps(apps);
3194 }
3195 }
3196 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003197 }
3198
3199 /**
3200 * A package was installed.
3201 *
3202 * Implementation of the method from LauncherModel.Callbacks.
3203 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003204 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003205 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003206 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003207
Winson Chung785d2eb2011-04-14 16:08:02 -07003208 if (mAppsCustomizeContent != null) {
3209 mAppsCustomizeContent.addApps(apps);
3210 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003211 }
3212
3213 /**
3214 * A package was updated.
3215 *
3216 * Implementation of the method from LauncherModel.Callbacks.
3217 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003218 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003219 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003220 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003221 if (mWorkspace != null) {
3222 mWorkspace.updateShortcuts(apps);
3223 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003224
Winson Chung785d2eb2011-04-14 16:08:02 -07003225 if (mAppsCustomizeContent != null) {
3226 mAppsCustomizeContent.updateApps(apps);
3227 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003228 }
3229
3230 /**
3231 * A package was uninstalled.
3232 *
3233 * Implementation of the method from LauncherModel.Callbacks.
3234 */
Joe Onorato36115782010-06-17 13:28:48 -04003235 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003236 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003237 if (permanent) {
3238 mWorkspace.removeItems(apps);
3239 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003240
Winson Chung785d2eb2011-04-14 16:08:02 -07003241 if (mAppsCustomizeContent != null) {
3242 mAppsCustomizeContent.removeApps(apps);
3243 }
Winson Chunga1820962011-10-03 16:31:06 -07003244
3245 // Notify the drag controller
3246 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003247 }
Joe Onoratobe386092009-11-17 17:32:16 -08003248
3249 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003250 * A number of packages were updated.
3251 */
3252 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003253 if (mAppsCustomizeContent != null) {
3254 mAppsCustomizeContent.onPackagesUpdated();
3255 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003256 }
3257
Winson Chung400438b2011-01-16 17:53:48 -08003258 private int mapConfigurationOriActivityInfoOri(int configOri) {
3259 final Display d = getWindowManager().getDefaultDisplay();
3260 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3261 switch (d.getRotation()) {
3262 case Surface.ROTATION_0:
3263 case Surface.ROTATION_180:
3264 // We are currently in the same basic orientation as the natural orientation
3265 naturalOri = configOri;
3266 break;
3267 case Surface.ROTATION_90:
3268 case Surface.ROTATION_270:
3269 // We are currently in the other basic orientation to the natural orientation
3270 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3271 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3272 break;
3273 }
3274
3275 int[] oriMap = {
3276 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3277 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3278 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3279 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3280 };
3281 // Since the map starts at portrait, we need to offset if this device's natural orientation
3282 // is landscape.
3283 int indexOffset = 0;
3284 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3285 indexOffset = 1;
3286 }
3287 return oriMap[(d.getRotation() + indexOffset) % 4];
3288 }
Adam Cohen446e9402011-09-15 18:21:21 -07003289
3290 public void lockScreenOrientationOnLargeUI() {
3291 if (LauncherApplication.isScreenLarge()) {
3292 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3293 .getConfiguration().orientation));
3294 }
Winson Chung400438b2011-01-16 17:53:48 -08003295 }
Adam Cohen446e9402011-09-15 18:21:21 -07003296 public void unlockScreenOrientationOnLargeUI() {
3297 if (LauncherApplication.isScreenLarge()) {
3298 mHandler.postDelayed(new Runnable() {
3299 public void run() {
3300 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3301 }
3302 }, mRestoreScreenOrientationDelay);
3303 }
Winson Chung400438b2011-01-16 17:53:48 -08003304 }
3305
Winson Chung82f55532011-08-09 14:14:23 -07003306 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003307 private static final String PREFS_KEY = "com.android.launcher2.prefs";
3308 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003309 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003310 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003311
Winson Chung7d7541e2011-09-16 20:14:36 -07003312 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003313 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003314 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3315 Cling cling = (Cling) findViewById(clingId);
3316 if (cling != null) {
3317 cling.init(this, positionData);
3318 cling.setVisibility(View.VISIBLE);
3319 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3320 if (animate) {
3321 cling.buildLayer();
3322 cling.setAlpha(0f);
3323 cling.animate()
3324 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003325 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003326 .setDuration(SHOW_CLING_DURATION)
3327 .setStartDelay(delay)
3328 .start();
3329 } else {
3330 cling.setAlpha(1f);
3331 }
3332 }
3333 return cling;
3334 }
3335 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003336 if (cling != null) {
3337 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003338 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003339 anim.addListener(new AnimatorListenerAdapter() {
3340 public void onAnimationEnd(Animator animation) {
3341 cling.setVisibility(View.GONE);
3342 cling.cleanup();
3343 SharedPreferences prefs =
3344 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
3345 SharedPreferences.Editor editor = prefs.edit();
3346 editor.putBoolean(flag, true);
3347 editor.commit();
3348 };
3349 });
3350 anim.start();
3351 }
3352 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003353 private void removeCling(int id) {
3354 final View cling = findViewById(id);
3355 if (cling != null) {
3356 final ViewGroup parent = (ViewGroup) cling.getParent();
3357 parent.post(new Runnable() {
3358 @Override
3359 public void run() {
3360 parent.removeView(cling);
3361 }
3362 });
3363 }
3364 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003365 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003366 // Enable the clings only if they have not been dismissed before
3367 SharedPreferences prefs =
3368 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003369 if (isClingsEnabled() && !prefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003370 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003371 } else {
3372 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003373 }
3374 }
3375 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003376 // Enable the clings only if they have not been dismissed before
3377 SharedPreferences prefs =
3378 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003379 if (isClingsEnabled() && !prefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003380 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003381 } else {
3382 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003383 }
3384 }
3385 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003386 // Enable the clings only if they have not been dismissed before
3387 SharedPreferences prefs =
3388 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
3389 Cling cling = null;
Winson Chung9d9d74f2011-09-19 11:49:12 -07003390 if (isClingsEnabled() && !prefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003391 cling = initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003392 } else {
3393 removeCling(R.id.folder_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003394 }
3395 return cling;
3396 }
3397 public boolean isFolderClingVisible() {
3398 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003399 if (cling != null) {
3400 return cling.getVisibility() == View.VISIBLE;
3401 }
3402 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003403 }
Winson Chung82f55532011-08-09 14:14:23 -07003404 public void dismissWorkspaceCling(View v) {
3405 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003406 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003407 }
3408 public void dismissAllAppsCling(View v) {
3409 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003410 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3411 }
3412 public void dismissFolderCling(View v) {
3413 Cling cling = (Cling) findViewById(R.id.folder_cling);
3414 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003415 }
3416
Winson Chung80baf5a2010-08-09 16:03:15 -07003417 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003418 * Prints out out state for debugging.
3419 */
3420 public void dumpState() {
3421 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003422 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003423 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3424 Log.d(TAG, "mRestoring=" + mRestoring);
3425 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3426 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003427 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003428 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003429
Winson Chung785d2eb2011-04-14 16:08:02 -07003430 if (mAppsCustomizeContent != null) {
3431 mAppsCustomizeContent.dumpState();
3432 }
Joe Onoratobe386092009-11-17 17:32:16 -08003433 Log.d(TAG, "END launcher2 dump state");
3434 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003435
3436 @Override
3437 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3438 super.dump(prefix, fd, writer, args);
3439 writer.println(" ");
3440 writer.println("Debug logs: ");
3441 for (int i = 0; i < sDumpLogs.size(); i++) {
3442 writer.println(" " + sDumpLogs.get(i));
3443 }
3444 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003445}
Michael Jurka2763be32011-02-24 11:19:57 -08003446
Michael Jurkaabded662011-03-04 12:06:57 -08003447interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003448 View getContent();
Michael Jurkabed61d22012-02-14 22:51:29 -08003449 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
3450 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003451}