blob: 01f6ab8beb5cb7c89867051058006b5c45a929d7 [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;
Michael Jurkaaf442092010-06-10 17:01:57 -070052import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070053import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040054import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070055import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080056import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020057import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080058import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070059import android.os.Message;
Daniel Sandler843e8602010-06-07 14:59:01 -040060import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080061import android.os.SystemProperties;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070062import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080063import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064import android.text.Selection;
65import android.text.SpannableStringBuilder;
66import android.text.TextUtils;
67import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070068import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080069import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080070import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.view.KeyEvent;
72import android.view.LayoutInflater;
73import android.view.Menu;
74import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070075import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080076import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080077import android.view.View;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080078import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070079import android.view.ViewGroup;
Michael Jurkab737ee62011-11-15 15:57:22 -080080import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080081import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Dianne Hackbornbb003a52011-08-30 14:40:07 -070082import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080083import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070084import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070085import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080086import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080087import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070088import android.widget.Advanceable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070090import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070091import android.widget.TextView;
92import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070093
Adam Cohendf2cc412011-04-27 16:56:57 -070094import com.android.common.Search;
95import com.android.launcher.R;
Adam Cohen558baaf2011-08-15 15:22:57 -070096import com.android.launcher2.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080097
Adam Cohenc0dcf592011-06-01 15:30:43 -070098import java.io.DataInputStream;
99import java.io.DataOutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700100import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700101import java.io.FileNotFoundException;
102import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700103import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700104import java.util.ArrayList;
105import java.util.HashMap;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700106
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800107/**
108 * Default launcher application.
109 */
Michael Jurka946ad472010-07-09 18:05:18 -0700110public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700111 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
112 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800113 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700114 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115
Joe Onorato9c1289c2009-08-17 11:03:03 -0400116 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400117 static final boolean DEBUG_WIDGETS = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700118
Winson Chung70d72102011-08-12 11:24:35 -0700119 private static final int MENU_GROUP_WALLPAPER = 1;
120 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
121 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700122 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
123 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800124
125 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700126 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127 private static final int REQUEST_PICK_APPLICATION = 6;
128 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700129 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700130 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131
132 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
133
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800134 static final int SCREEN_COUNT = 5;
135 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136
Joe Onorato7c312c12009-08-13 21:36:53 -0700137 static final int DIALOG_CREATE_SHORTCUT = 1;
138 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
Romain Guy98d01652009-06-30 16:21:04 -0700140 private static final String PREFERENCES = "launcher.preferences";
Adam Cohen23a4d302011-12-01 17:26:44 -0800141 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher.force_enable_rotation";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142
143 // Type: int
144 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700145 // Type: int
146 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700148 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
149 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
151 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700152 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700154 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800155 // Type: boolean
156 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
157 // Type: long
158 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
159
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700160 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
161
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700162 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700163 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700164 private State mState = State.WORKSPACE;
165 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800166 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700167
Joe Onorato9c1289c2009-08-17 11:03:03 -0400168 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700169 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
170 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700171 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700172 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800175 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800177 private final BroadcastReceiver mCloseSystemDialogsReceiver
178 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800179 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
180
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 private LayoutInflater mInflater;
182
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800184 private View mQsbDivider;
185 private View mDockDivider;
186 private DragLayer mDragLayer;
187 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700188
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700189 private AppWidgetManager mAppWidgetManager;
190 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700191
Michael Jurkac9d95c52011-08-29 14:03:34 -0700192 private ItemInfo mPendingAddInfo = new ItemInfo();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700193 private int[] mTmpAddItemCellCoordinates = new int[2];
194
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195 private FolderInfo mFolderInfo;
196
Winson Chung3d503fb2011-07-13 17:25:49 -0700197 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800198 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700199
Winson Chungc51db6a2011-10-05 11:44:49 -0700200 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700201 private AppsCustomizeTabHost mAppsCustomizeTabHost;
202 private AppsCustomizePagedView mAppsCustomizeContent;
203 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205 private Bundle mSavedState;
206
207 private SpannableStringBuilder mDefaultKeySsb = null;
208
Joe Onorato9c1289c2009-08-17 11:03:03 -0400209 private boolean mWorkspaceLoading = true;
210
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800211 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212 private boolean mRestoring;
213 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700214 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800215
216 private Bundle mSavedInstanceState;
217
Joe Onorato9c1289c2009-08-17 11:03:03 -0400218 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800219 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800220 private boolean mUserPresent = true;
221 private boolean mVisible = false;
222 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400223
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700224 private static LocaleConfiguration sLocaleConfiguration = null;
225
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700226 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700227
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700228 private Intent mAppMarketIntent = null;
229
Adam Cohended9f8d2010-11-03 13:25:16 -0700230 // Related to the auto-advancing of widgets
231 private final int ADVANCE_MSG = 1;
232 private final int mAdvanceInterval = 20000;
233 private final int mAdvanceStagger = 250;
234 private long mAutoAdvanceSentTime;
235 private long mAutoAdvanceTimeLeft = -1;
236 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
237 new HashMap<View, AppWidgetProviderInfo>();
238
Winson Chung400438b2011-01-16 17:53:48 -0800239 // Determines how long to wait after a rotation before restoring the screen orientation to
240 // match the sensor state.
241 private final int mRestoreScreenOrientationDelay = 500;
242
Michael Jurka4ef207b2010-11-29 17:05:45 -0800243 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700244 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
245 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
246 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800247
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700248 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohened66b2b2012-01-23 17:28:51 -0800249 PendingAddWidgetInfo mWidgetBeingConfigured = null;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700250
Winson Chung46353de2012-02-16 14:05:10 -0800251 // We only want to get the SharedPreferences once since it does an FS stat each time we get
252 // it from the context.
253 private SharedPreferences mSharedPrefs;
254
Adam Cohen2801caf2011-05-13 20:57:39 -0700255
Michael Jurkaddd62e92011-02-16 17:49:14 -0800256 private BubbleTextView mWaitingForResume;
257
Michael Jurkac1f5d262011-09-30 19:32:27 -0700258 private Runnable mBuildLayersRunnable = new Runnable() {
259 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700260 if (mWorkspace != null) {
261 mWorkspace.buildPageHardwareLayers();
262 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700263 }
264 };
265
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800266 private static ArrayList<PendingAddArguments> sPendingAddList
267 = new ArrayList<PendingAddArguments>();
268
269 private static class PendingAddArguments {
270 int requestCode;
271 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700272 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800273 int screen;
274 int cellX;
275 int cellY;
276 }
277
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800278 @Override
279 protected void onCreate(Bundle savedInstanceState) {
280 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800281 LauncherApplication app = ((LauncherApplication)getApplication());
Winson Chung46353de2012-02-16 14:05:10 -0800282 mSharedPrefs = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800283 mModel = app.setLauncher(this);
284 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400285 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800286 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700287
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700288 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700289 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
290 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700291
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800292 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200293 android.os.Debug.startMethodTracing(
294 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800295 }
296
297 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800298 setContentView(R.layout.launcher);
299 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700300 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800301
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800302 registerContentObservers();
303
Joe Onorato7c312c12009-08-13 21:36:53 -0700304 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700305
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800306 mSavedState = savedInstanceState;
307 restoreState(mSavedState);
308
Winson Chunga12a2502010-12-20 14:41:35 -0800309 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700310 if (mAppsCustomizeContent != null) {
311 mAppsCustomizeContent.onPackagesUpdated();
312 }
Winson Chunga12a2502010-12-20 14:41:35 -0800313
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800314 if (PROFILE_STARTUP) {
315 android.os.Debug.stopMethodTracing();
316 }
317
318 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400319 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800320 }
321
Michael Jurkac57b7a82011-08-09 22:02:20 -0700322 if (!mModel.isAllAppsLoaded()) {
323 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
324 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
325 }
326
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800327 // For handling default keys
328 mDefaultKeySsb = new SpannableStringBuilder();
329 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800330
331 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
332 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800333
Winson Chungc51db6a2011-10-05 11:44:49 -0700334 boolean searchVisible = false;
335 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800336 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700337 int coi = getCurrentOrientationIndexForGlobalIcons();
338 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
339 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700340 updateAppMarketIcon();
341 searchVisible = updateGlobalSearchIcon();
342 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700343 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700344 if (sGlobalSearchIcon[coi] != null) {
345 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700346 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700347 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700348 if (sVoiceSearchIcon[coi] != null) {
349 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700350 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700351 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700352 if (sAppMarketIcon[coi] != null) {
353 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800354 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700355 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Adam Cohen446e9402011-09-15 18:21:21 -0700356
Adam Cohen23a4d302011-12-01 17:26:44 -0800357 final String forceEnableRotation =
358 SystemProperties.get(FORCE_ENABLE_ROTATION_PROPERTY, "false");
359
Adam Cohen446e9402011-09-15 18:21:21 -0700360 // On large interfaces, we want the screen to auto-rotate based on the current orientation
Adam Cohen23a4d302011-12-01 17:26:44 -0800361 if (LauncherApplication.isScreenLarge() || "true".equalsIgnoreCase(forceEnableRotation)) {
Adam Cohen446e9402011-09-15 18:21:21 -0700362 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
363 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800364 }
Romain Guycbb89e42009-06-08 15:52:54 -0700365
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800366 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700367 if (sLocaleConfiguration == null) {
368 new AsyncTask<Void, Void, LocaleConfiguration>() {
369 @Override
370 protected LocaleConfiguration doInBackground(Void... unused) {
371 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
372 readConfiguration(Launcher.this, localeConfiguration);
373 return localeConfiguration;
374 }
375
376 @Override
377 protected void onPostExecute(LocaleConfiguration result) {
378 sLocaleConfiguration = result;
379 checkForLocaleChange(); // recursive, but now with a locale configuration
380 }
381 }.execute();
382 return;
383 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700384
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385 final Configuration configuration = getResources().getConfiguration();
386
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700387 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800388 final String locale = configuration.locale.toString();
389
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700390 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800391 final int mcc = configuration.mcc;
392
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700393 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800394 final int mnc = configuration.mnc;
395
Romain Guy84f296c2009-11-04 15:00:44 -0800396 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800397
Romain Guy84f296c2009-11-04 15:00:44 -0800398 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700399 sLocaleConfiguration.locale = locale;
400 sLocaleConfiguration.mcc = mcc;
401 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700402
Joe Onorato0589f0f2010-02-08 13:44:00 -0800403 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700404
405 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
406 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700407 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700408 public void run() {
409 writeConfiguration(Launcher.this, localeConfiguration);
410 }
411 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700412 }
413 }
414
415 private static class LocaleConfiguration {
416 public String locale;
417 public int mcc = -1;
418 public int mnc = -1;
419 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700420
Romain Guy98d01652009-06-30 16:21:04 -0700421 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
422 DataInputStream in = null;
423 try {
424 in = new DataInputStream(context.openFileInput(PREFERENCES));
425 configuration.locale = in.readUTF();
426 configuration.mcc = in.readInt();
427 configuration.mnc = in.readInt();
428 } catch (FileNotFoundException e) {
429 // Ignore
430 } catch (IOException e) {
431 // Ignore
432 } finally {
433 if (in != null) {
434 try {
435 in.close();
436 } catch (IOException e) {
437 // Ignore
438 }
439 }
440 }
441 }
442
443 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
444 DataOutputStream out = null;
445 try {
446 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
447 out.writeUTF(configuration.locale);
448 out.writeInt(configuration.mcc);
449 out.writeInt(configuration.mnc);
450 out.flush();
451 } catch (FileNotFoundException e) {
452 // Ignore
453 } catch (IOException e) {
454 //noinspection ResultOfMethodCallIgnored
455 context.getFileStreamPath(PREFERENCES).delete();
456 } finally {
457 if (out != null) {
458 try {
459 out.close();
460 } catch (IOException e) {
461 // Ignore
462 }
463 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800464 }
465 }
466
Adam Cohen716b51e2011-06-30 12:09:54 -0700467 public DragLayer getDragLayer() {
468 return mDragLayer;
469 }
470
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800471 static int getScreen() {
472 synchronized (sLock) {
473 return sScreen;
474 }
475 }
476
477 static void setScreen(int screen) {
478 synchronized (sLock) {
479 sScreen = screen;
480 }
481 }
482
Winson Chung557d6ed2011-07-08 15:34:52 -0700483 /**
484 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
485 * a configuration step, this allows the proper animations to run after other transitions.
486 */
487 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700488 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800489 switch (args.requestCode) {
490 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700491 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
492 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800493 break;
494 case REQUEST_PICK_SHORTCUT:
495 processShortcut(args.intent);
496 break;
497 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700498 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
499 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700500 result = true;
501 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800502 case REQUEST_PICK_APPWIDGET:
503 addAppWidgetFromPick(args.intent);
504 break;
505 case REQUEST_CREATE_APPWIDGET:
506 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohened66b2b2012-01-23 17:28:51 -0800507 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700508 result = true;
509 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800510 case REQUEST_PICK_WALLPAPER:
511 // We just wanted the activity result here so we can clear mWaitingForResult
512 break;
513 }
Winson Chungb8472bb2011-08-05 13:49:21 -0700514 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800515 }
516
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800517 @Override
Adam Cohened66b2b2012-01-23 17:28:51 -0800518 protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
Winson Chung557d6ed2011-07-08 15:34:52 -0700519 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800520 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
521 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700522 mWaitingForResult = false;
523
Adam Cohened66b2b2012-01-23 17:28:51 -0800524 // We have special handling for widgets
525 if (isWidgetDrop) {
526 int appWidgetId = data != null ?
527 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
528 completeTwoStageWidgetDrop(resultCode, appWidgetId);
529 return;
530 }
531
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800532 // The pattern used here is that a user PICKs a specific application,
533 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700534
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800535 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
536 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700537 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800538 final PendingAddArguments args = new PendingAddArguments();
539 args.requestCode = requestCode;
540 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700541 args.container = mPendingAddInfo.container;
542 args.screen = mPendingAddInfo.screen;
543 args.cellX = mPendingAddInfo.cellX;
544 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800545 if (isWorkspaceLocked()) {
546 sPendingAddList.add(args);
547 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700548 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800549 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800550 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800551 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700552 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800553 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
554 null);
555 }
556
557 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
558 CellLayout cellLayout = (CellLayout) mWorkspace.getChildAt(mWidgetBeingConfigured.screen);
559 Runnable onCompleteRunnable = null;
560 int animationType = 0;
561
562 if (resultCode == RESULT_OK) {
563 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
564 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
565 mWidgetBeingConfigured.info);
566 mWidgetBeingConfigured.boundWidget = layout;
567 onCompleteRunnable = new Runnable() {
568 @Override
569 public void run() {
570 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
571 mPendingAddInfo.screen, layout, null);
572 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
573 null);
574 }
575 };
576 } else if (resultCode == RESULT_CANCELED) {
577 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
578 onCompleteRunnable = new Runnable() {
579 @Override
580 public void run() {
581 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
582 null);
583 }
584 };
585 }
586 mWorkspace.animateExternalDrop(mWidgetBeingConfigured, cellLayout,
587 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
588 animationType);
Adam Cohen1b36dc32012-02-13 19:27:37 -0800589 mWidgetBeingConfigured = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800590 }
591
592 @Override
593 protected void onResume() {
594 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800595 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700596 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400597 mWorkspaceLoading = true;
598 mModel.startLoader(this, true);
599 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700600 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800601 }
Winson Chunge4e50662012-01-23 14:45:13 -0800602
603 // Reset the pressed state of icons that were locked in the press state while activities
604 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800605 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800606 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800607 mWaitingForResume.setStayPressed(false);
608 }
Winson Chunge4e50662012-01-23 14:45:13 -0800609 if (mAppsCustomizeContent != null) {
610 // Resets the previous all apps icon press state
611 mAppsCustomizeContent.resetDrawableState();
612 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800613 }
614
615 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700616 protected void onPause() {
617 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700618 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800619 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700620 }
Romain Guycbb89e42009-06-08 15:52:54 -0700621
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700622 @Override
Michael Jurkabed61d22012-02-14 22:51:29 -0800623 protected void onStart() {
624 super.onStart();
625 // When Launcher comes back to foreground, a different Activity might be responsible for
626 // the app market intent, so refresh the icon
627 // We don't do this in onResume() because onResume() is triggered every time the home
628 // button is pressed (even if we were already in Launcher)
629 updateAppMarketIcon();
630 }
631
632 @Override
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700633 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400634 // Flag the loader to stop early before switching
635 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700636 if (mAppsCustomizeContent != null) {
637 mAppsCustomizeContent.surrender();
638 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800639 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700640 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700641
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800642 // We can't hide the IME if it was forced open. So don't bother
643 /*
644 @Override
645 public void onWindowFocusChanged(boolean hasFocus) {
646 super.onWindowFocusChanged(hasFocus);
647
648 if (hasFocus) {
649 final InputMethodManager inputManager = (InputMethodManager)
650 getSystemService(Context.INPUT_METHOD_SERVICE);
651 WindowManager.LayoutParams lp = getWindow().getAttributes();
652 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
653 android.os.Handler()) {
654 protected void onReceiveResult(int resultCode, Bundle resultData) {
655 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
656 }
657 });
658 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
659 }
660 }
661 */
662
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800663 private boolean acceptFilter() {
664 final InputMethodManager inputManager = (InputMethodManager)
665 getSystemService(Context.INPUT_METHOD_SERVICE);
666 return !inputManager.isFullscreenMode();
667 }
668
669 @Override
670 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700671 final int uniChar = event.getUnicodeChar();
672 final boolean handled = super.onKeyDown(keyCode, event);
673 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
674 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800675 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
676 keyCode, event);
677 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700678 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700679 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700680 // showSearchDialog()
681 // If there are multiple keystrokes before the search dialog takes focus,
682 // onSearchRequested() will be called for every keystroke,
683 // but it is idempotent, so it's fine.
684 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800685 }
686 }
687
Joe Onorato8a9625e2010-01-28 15:55:35 -0800688 // Eat the long press event so the keyboard doesn't come up.
689 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
690 return true;
691 }
692
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800693 return handled;
694 }
695
Karl Rosaen138a0412009-04-23 19:00:21 -0700696 private String getTypedText() {
697 return mDefaultKeySsb.toString();
698 }
699
700 private void clearTypedText() {
701 mDefaultKeySsb.clear();
702 mDefaultKeySsb.clearSpans();
703 Selection.setSelection(mDefaultKeySsb, 0);
704 }
705
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800706 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700707 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
708 * State
709 */
710 private static State intToState(int stateOrdinal) {
711 State state = State.WORKSPACE;
712 final State[] stateValues = State.values();
713 for (int i = 0; i < stateValues.length; i++) {
714 if (stateValues[i].ordinal() == stateOrdinal) {
715 state = stateValues[i];
716 break;
717 }
718 }
719 return state;
720 }
721
722 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800723 * Restores the previous state, if it exists.
724 *
725 * @param savedState The previous state.
726 */
727 private void restoreState(Bundle savedState) {
728 if (savedState == null) {
729 return;
730 }
731
Michael Jurka883f55b2010-10-21 15:47:14 -0700732 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700733 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800734 showAllApps(false);
735 }
736
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800737 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
738 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700739 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800740 }
741
Winson Chung3d503fb2011-07-13 17:25:49 -0700742 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
743 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700744
Winson Chung3d503fb2011-07-13 17:25:49 -0700745 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
746 mPendingAddInfo.container = pendingAddContainer;
747 mPendingAddInfo.screen = pendingAddScreen;
748 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
749 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800750 mRestoring = true;
751 }
752
753 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
754 if (renameFolder) {
755 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700756 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800757 mRestoring = true;
758 }
Winson Chunga12a2502010-12-20 14:41:35 -0800759
Winson Chung785d2eb2011-04-14 16:08:02 -0700760
761 // Restore the AppsCustomize tab
762 if (mAppsCustomizeTabHost != null) {
763 String curTab = savedState.getString("apps_customize_currentTab");
764 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700765 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700766 mAppsCustomizeContent.setContentType(
767 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
768 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700769 mAppsCustomizeContent.loadAssociatedPages(
770 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700771 }
772
Winson Chung5afbf7b2011-07-25 11:53:08 -0700773 int currentIndex = savedState.getInt("apps_customize_currentIndex");
774 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700775 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800776 }
777
778 /**
779 * Finds all the views we need and configure them properly.
780 */
781 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700782 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400783
Winson Chung4c98d922011-05-31 16:50:48 -0700784 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
785 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800786 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
787 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800788
Winson Chung4c98d922011-05-31 16:50:48 -0700789 // Setup the drag layer
790 mDragLayer.setup(this, dragController);
791
Winson Chung3d503fb2011-07-13 17:25:49 -0700792 // Setup the hotseat
793 mHotseat = (Hotseat) findViewById(R.id.hotseat);
794 if (mHotseat != null) {
795 mHotseat.setup(this);
796 }
797
Winson Chung4c98d922011-05-31 16:50:48 -0700798 // Setup the workspace
799 mWorkspace.setHapticFeedbackEnabled(false);
800 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700801 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700802 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700803
Winson Chungf0ea4d32011-06-06 14:27:16 -0700804 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700805 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700806
Winson Chungf0ea4d32011-06-06 14:27:16 -0700807 // Setup AppsCustomize
808 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
809 findViewById(R.id.apps_customize_pane);
810 mAppsCustomizeContent = (AppsCustomizePagedView)
811 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
812 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400813
Michael Jurka5130e402011-10-13 04:55:35 -0700814 // Get the all apps button
815 mAllAppsButton = findViewById(R.id.all_apps_button);
816 if (mAllAppsButton != null) {
817 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
818 @Override
819 public boolean onTouch(View v, MotionEvent event) {
820 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
821 onTouchDownAllAppsButton(v);
822 }
823 return false;
824 }
825 });
826 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700827 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700828 dragController.setDragScoller(mWorkspace);
829 dragController.setScrollView(mDragLayer);
830 dragController.setMoveTarget(mWorkspace);
831 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700832 if (mSearchDropTargetBar != null) {
833 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800834 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800835 }
836
837 /**
838 * Creates a view representing a shortcut.
839 *
840 * @param info The data structure describing the shortcut.
841 *
842 * @return A View inflated from R.layout.application.
843 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800844 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800845 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700846 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800847 }
848
849 /**
850 * Creates a view representing a shortcut inflated from the specified resource.
851 *
852 * @param layoutResId The id of the XML layout used to create the shortcut.
853 * @param parent The group the shortcut belongs to.
854 * @param info The data structure describing the shortcut.
855 *
856 * @return A View inflated from layoutResId.
857 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800858 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800859 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
860 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800861 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800862 return favorite;
863 }
864
865 /**
866 * Add an application shortcut to the workspace.
867 *
868 * @param data The intent describing the application.
869 * @param cellInfo The position on screen where to create the shortcut.
870 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700871 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700872 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700873 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700874
Adam Cohenfbba09b2011-07-18 21:43:05 -0700875 // First we check if we already know the exact location where we want to add this item.
876 if (cellX >= 0 && cellY >= 0) {
877 cellXY[0] = cellX;
878 cellXY[1] = cellY;
879 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700880 showOutOfSpaceMessage();
881 return;
882 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800883
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800884 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800885
Romain Guy73b979d2009-06-09 12:57:21 -0700886 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800887 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800888 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800889 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700890 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700891 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800892 } else {
893 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800894 }
895 }
Romain Guycbb89e42009-06-08 15:52:54 -0700896
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800897 /**
898 * Add a shortcut to the workspace.
899 *
900 * @param data The intent describing the shortcut.
901 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800902 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700903 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
904 int cellY) {
905 int[] cellXY = mTmpAddItemCellCoordinates;
906 int[] touchXY = mPendingAddInfo.dropPos;
907 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -0700908
Michael Jurkad3ef3062010-11-23 16:23:58 -0800909 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700910
Adam Cohen558baaf2011-08-15 15:22:57 -0700911 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -0800912 if (info == null) {
913 return;
914 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700915 final View view = createShortcut(info);
916
Adam Cohenfbba09b2011-07-18 21:43:05 -0700917 // First we check if we already know the exact location where we want to add this item.
918 if (cellX >= 0 && cellY >= 0) {
919 cellXY[0] = cellX;
920 cellXY[1] = cellY;
921 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -0700922
923 // If appropriate, either create a folder or add to an existing folder
924 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY,
925 true, null,null)) {
926 return;
927 }
928 DragObject dragObject = new DragObject();
929 dragObject.dragInfo = info;
930 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, dragObject, true)) {
931 return;
932 }
Adam Cohenfbba09b2011-07-18 21:43:05 -0700933 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800934 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700935 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800936 foundCellSpan = (result != null);
937 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700938 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800939 }
940
941 if (!foundCellSpan) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700942 showOutOfSpaceMessage();
943 return;
944 }
945
Adam Cohen558baaf2011-08-15 15:22:57 -0700946 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800947
948 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -0700949 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
950 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800951 }
952 }
953
Adam Cohenf814aa02011-09-01 13:48:05 -0700954 int[] getSpanForWidget(ComponentName component, int minWidth, int minHeight, int[] spanXY) {
955 if (spanXY == null) {
956 spanXY = new int[2];
957 }
958
Adam Cohen0cf2a7c2011-11-08 15:07:01 -0800959 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(this, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -0700960 // We want to account for the extra amount of padding that we are adding to the widget
961 // to ensure that it gets the full amount of space that it has requested
962 int requiredWidth = minWidth + padding.left + padding.right;
963 int requiredHeight = minHeight + padding.top + padding.bottom;
964 return CellLayout.rectToCell(getResources(), requiredWidth, requiredHeight, null);
965 }
966
967 int[] getSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
968 return getSpanForWidget(info.provider, info.minWidth, info.minHeight, spanXY);
969 }
970
Adam Cohencbf47e32011-09-16 17:32:37 -0700971 int[] getMinResizeSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
972 return getSpanForWidget(info.provider, info.minResizeWidth, info.minResizeHeight, spanXY);
973 }
974
Adam Cohenf814aa02011-09-01 13:48:05 -0700975 int[] getSpanForWidget(PendingAddWidgetInfo info, int[] spanXY) {
976 return getSpanForWidget(info.componentName, info.minWidth, info.minHeight, spanXY);
977 }
978
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800979 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700980 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800981 *
Romain Guy5bbc91b2010-08-18 11:38:46 -0700982 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700983 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800984 */
Adam Cohened66b2b2012-01-23 17:28:51 -0800985 private void completeAddAppWidget(final int appWidgetId, long container, int screen,
986 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
987 if (appWidgetInfo == null) {
988 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
989 }
Romain Guycbb89e42009-06-08 15:52:54 -0700990
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700991 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -0700992 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -0700993
Adam Cohenf814aa02011-09-01 13:48:05 -0700994 int[] spanXY = getSpanForWidget(appWidgetInfo, null);
Romain Guycbb89e42009-06-08 15:52:54 -0700995
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800996 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -0700997 // We have saved the position to which the widget was dragged-- this really only matters
998 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -0700999 int[] cellXY = mTmpAddItemCellCoordinates;
1000 int[] touchXY = mPendingAddInfo.dropPos;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001001 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001002 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1003 cellXY[0] = mPendingAddInfo.cellX;
1004 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001005 foundCellSpan = true;
1006 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001007 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001008 int[] result = layout.findNearestVacantArea(
Michael Jurka0280c3b2010-09-17 15:00:07 -07001009 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001010 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001011 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001012 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001013 }
1014
Michael Jurka0280c3b2010-09-17 15:00:07 -07001015 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001016 if (appWidgetId != -1) {
1017 // Deleting an app widget ID is a void call but writes to disk before returning
1018 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001019 new Thread("deleteAppWidgetId") {
1020 public void run() {
1021 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1022 }
1023 }.start();
1024 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001025 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001026 return;
1027 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001028
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001029 // Build Launcher-specific widget info and save to database
Michael Jurkac9d95c52011-08-29 14:03:34 -07001030 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001031 launcherInfo.spanX = spanXY[0];
1032 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001033
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001034 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -07001035 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001036
1037 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001038 if (hostView == null) {
1039 // Perform actual inflation because we're live
1040 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1041 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1042 } else {
1043 // The AppWidgetHostView has already been inflated and instantiated
1044 launcherInfo.hostView = hostView;
1045 }
Romain Guycbb89e42009-06-08 15:52:54 -07001046
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001047 launcherInfo.hostView.setTag(launcherInfo);
Winson Chung3d503fb2011-07-13 17:25:49 -07001048 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001049 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001050
1051 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001052 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001053 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001054 }
Romain Guycbb89e42009-06-08 15:52:54 -07001055
Adam Cohended9f8d2010-11-03 13:25:16 -07001056 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1057 @Override
1058 public void onReceive(Context context, Intent intent) {
1059 final String action = intent.getAction();
1060 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1061 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001062 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001063 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001064
Winson Chungc100e8e2011-08-09 16:02:43 -07001065 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001066 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001067 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1068 mAppsCustomizeTabHost.reset();
1069 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001070 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001071 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1072 mUserPresent = true;
1073 updateRunning();
1074 }
1075 }
1076 };
1077
1078 @Override
1079 public void onAttachedToWindow() {
1080 super.onAttachedToWindow();
1081
1082 // Listen for broadcasts related to user-presence
1083 final IntentFilter filter = new IntentFilter();
1084 filter.addAction(Intent.ACTION_SCREEN_OFF);
1085 filter.addAction(Intent.ACTION_USER_PRESENT);
1086 registerReceiver(mReceiver, filter);
1087
Adam Cohend113e0c2010-11-11 10:48:05 -08001088 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001089 mVisible = true;
1090 }
1091
1092 @Override
1093 public void onDetachedFromWindow() {
1094 super.onDetachedFromWindow();
1095 mVisible = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001096 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001097
Adam Cohend113e0c2010-11-11 10:48:05 -08001098 if (mAttached) {
1099 unregisterReceiver(mReceiver);
1100 mAttached = false;
1101 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001102 updateRunning();
1103 }
1104
1105 public void onWindowVisibilityChanged(int visibility) {
1106 mVisible = visibility == View.VISIBLE;
1107 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001108 // The following code used to be in onResume, but it turns out onResume is called when
1109 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1110 // is a more appropriate event to handle
1111 if (mVisible) {
1112 mAppsCustomizeTabHost.onWindowVisible();
1113 if (!mWorkspaceLoading) {
1114 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001115 // We want to let Launcher draw itself at least once before we force it to build
1116 // layers on all the workspace pages, so that transitioning to Launcher from other
1117 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
1118 // a true draw so we wait until the second preDraw call to be safe
1119 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
1120 boolean mFirstTime = true;
1121 public boolean onPreDraw() {
1122 if (mFirstTime) {
1123 mFirstTime = false;
1124 } else {
1125 //workspace.post(mBuildLayersRunnable);
1126 observer.removeOnPreDrawListener(this);
1127 }
1128 return true;
1129 }
1130 });
1131 }
1132 clearTypedText();
1133 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001134 }
1135
1136 private void sendAdvanceMessage(long delay) {
1137 mHandler.removeMessages(ADVANCE_MSG);
1138 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1139 mHandler.sendMessageDelayed(msg, delay);
1140 mAutoAdvanceSentTime = System.currentTimeMillis();
1141 }
1142
1143 private void updateRunning() {
1144 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1145 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1146 mAutoAdvanceRunning = autoAdvanceRunning;
1147 if (autoAdvanceRunning) {
1148 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1149 sendAdvanceMessage(delay);
1150 } else {
1151 if (!mWidgetsToAdvance.isEmpty()) {
1152 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1153 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1154 }
1155 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001156 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001157 }
1158 }
1159 }
1160
1161 private final Handler mHandler = new Handler() {
1162 @Override
1163 public void handleMessage(Message msg) {
1164 if (msg.what == ADVANCE_MSG) {
1165 int i = 0;
1166 for (View key: mWidgetsToAdvance.keySet()) {
1167 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1168 final int delay = mAdvanceStagger * i;
1169 if (v instanceof Advanceable) {
1170 postDelayed(new Runnable() {
1171 public void run() {
1172 ((Advanceable) v).advance();
1173 }
1174 }, delay);
1175 }
1176 i++;
1177 }
1178 sendAdvanceMessage(mAdvanceInterval);
1179 }
1180 }
1181 };
1182
1183 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001184 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001185 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1186 if (v instanceof Advanceable) {
1187 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001188 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001189 updateRunning();
1190 }
1191 }
1192
1193 void removeWidgetToAutoAdvance(View hostView) {
1194 if (mWidgetsToAdvance.containsKey(hostView)) {
1195 mWidgetsToAdvance.remove(hostView);
1196 updateRunning();
1197 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001198 }
1199
Joe Onorato9c1289c2009-08-17 11:03:03 -04001200 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001201 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001202 launcherInfo.hostView = null;
1203 }
1204
Adam Cohended9f8d2010-11-03 13:25:16 -07001205 void showOutOfSpaceMessage() {
1206 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1207 }
1208
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001209 public LauncherAppWidgetHost getAppWidgetHost() {
1210 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001211 }
Romain Guycbb89e42009-06-08 15:52:54 -07001212
Winson Chunga9abd0e2010-10-27 17:18:37 -07001213 public LauncherModel getModel() {
1214 return mModel;
1215 }
1216
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001217 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001218 getWindow().closeAllPanels();
1219
Winson Chung87acb482011-08-23 17:28:05 -07001220 /**
1221 * We should remove this code when we remove all the dialog code.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001222 try {
1223 dismissDialog(DIALOG_CREATE_SHORTCUT);
1224 // Unlock the workspace if the dialog was showing
1225 } catch (Exception e) {
1226 // An exception is thrown if the dialog is not visible, which is fine
1227 }
1228
1229 try {
1230 dismissDialog(DIALOG_RENAME_FOLDER);
1231 // Unlock the workspace if the dialog was showing
1232 } catch (Exception e) {
1233 // An exception is thrown if the dialog is not visible, which is fine
1234 }
Winson Chung87acb482011-08-23 17:28:05 -07001235 */
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001236
1237 // Whatever we were doing is hereby canceled.
1238 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001239 }
1240
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001241 @Override
1242 protected void onNewIntent(Intent intent) {
1243 super.onNewIntent(intent);
1244
1245 // Close the menu
1246 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001247 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001248 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001249
Joe Onorato14f122b2009-11-19 14:06:36 -08001250 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1251 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001252
Adam Cohenac56cff2011-09-28 20:45:37 -07001253 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001254 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001255 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001256 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1257 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001258 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001259 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001260
1261 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001262 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001263 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001264
Joe Onorato3a8820b2009-11-10 15:06:42 -08001265 final View v = getWindow().peekDecorView();
1266 if (v != null && v.getWindowToken() != null) {
1267 InputMethodManager imm = (InputMethodManager)getSystemService(
1268 INPUT_METHOD_SERVICE);
1269 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001270 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001271
Michael Jurka35aa14d2011-07-07 17:01:08 -07001272 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001273 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001274 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001275 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001276 }
1277 }
1278
1279 @Override
1280 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1281 // Do not call super here
1282 mSavedInstanceState = savedInstanceState;
1283 }
1284
1285 @Override
1286 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001287 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001288 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001289
Michael Jurka883f55b2010-10-21 15:47:14 -07001290 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001291 // We close any open folder since it will not be re-opened, and we need to make sure
1292 // this state is reflected.
1293 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001294
Winson Chung3d503fb2011-07-13 17:25:49 -07001295 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1296 mWaitingForResult) {
1297 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1298 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1299 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1300 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001301 }
1302
1303 if (mFolderInfo != null && mWaitingForResult) {
1304 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1305 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1306 }
Michael Jurka946ad472010-07-09 18:05:18 -07001307
Winson Chung785d2eb2011-04-14 16:08:02 -07001308 // Save the current AppsCustomize tab
1309 if (mAppsCustomizeTabHost != null) {
1310 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1311 if (currentTabTag != null) {
1312 outState.putString("apps_customize_currentTab", currentTabTag);
1313 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001314 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1315 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001316 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001317 }
1318
1319 @Override
1320 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001321 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001322
Winson Chunge7a03942011-08-05 15:05:12 -07001323 // Remove all pending runnables
1324 mHandler.removeMessages(ADVANCE_MSG);
1325 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001326 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001327
Winson Chungcd2b0142011-06-08 16:02:26 -07001328 // Stop callbacks from LauncherModel
1329 LauncherApplication app = ((LauncherApplication) getApplication());
1330 mModel.stopLoader();
1331 app.setLauncher(null);
1332
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001333 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001334 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001335 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001336 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001337 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001338 mAppWidgetHost = null;
1339
1340 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001341
1342 TextKeyListener.getInstance().release();
1343
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001344
Winson Chung3d503fb2011-07-13 17:25:49 -07001345 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001346
1347 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001348 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001349
1350 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1351 mWorkspace.removeAllViews();
1352 mWorkspace = null;
1353 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001354
1355 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001356 }
1357
Adam Cohena9cf38f2011-05-02 15:36:58 -07001358 public DragController getDragController() {
1359 return mDragController;
1360 }
1361
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001362 @Override
1363 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001364 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001365 super.startActivityForResult(intent, requestCode);
1366 }
1367
Winson Chung70d72102011-08-12 11:24:35 -07001368 /**
1369 * Indicates that we want global search for this activity by setting the globalSearch
1370 * argument for {@link #startSearch} to true.
1371 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001372 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001373 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001374 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001375
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001376 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001377
Karl Rosaen138a0412009-04-23 19:00:21 -07001378 if (initialQuery == null) {
1379 // Use any text typed in the launcher as the initial query
1380 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001381 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001382 if (appSearchData == null) {
1383 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001384 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001385 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001386 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001387
Karl Rosaen138a0412009-04-23 19:00:21 -07001388 final SearchManager searchManager =
1389 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001390 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001391 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001392 }
1393
Winson Chung70d72102011-08-12 11:24:35 -07001394 @Override
1395 public boolean onCreateOptionsMenu(Menu menu) {
1396 if (isWorkspaceLocked()) {
1397 return false;
1398 }
1399
1400 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001401
1402 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1403 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1404 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001405 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1406 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1407 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001408 String helpUrl = getString(R.string.help_url);
1409 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001410 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1411 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1412
Winson Chung70d72102011-08-12 11:24:35 -07001413 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1414 .setIcon(android.R.drawable.ic_menu_gallery)
1415 .setAlphabeticShortcut('W');
1416 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1417 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001418 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001419 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001420 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1421 .setIcon(android.R.drawable.ic_menu_preferences)
1422 .setIntent(settings)
1423 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001424 if (!helpUrl.isEmpty()) {
1425 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1426 .setIcon(android.R.drawable.ic_menu_help)
1427 .setIntent(help)
1428 .setAlphabeticShortcut('H');
1429 }
Winson Chung70d72102011-08-12 11:24:35 -07001430 return true;
1431 }
1432
1433 @Override
1434 public boolean onPrepareOptionsMenu(Menu menu) {
1435 super.onPrepareOptionsMenu(menu);
1436
1437 if (mAppsCustomizeTabHost.isTransitioning()) {
1438 return false;
1439 }
1440 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1441 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1442
1443 return true;
1444 }
1445
1446 @Override
1447 public boolean onOptionsItemSelected(MenuItem item) {
1448 switch (item.getItemId()) {
1449 case MENU_WALLPAPER_SETTINGS:
1450 startWallpaper();
1451 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001452 }
1453
1454 return super.onOptionsItemSelected(item);
1455 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001456
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001457 @Override
1458 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001459 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001460 // Use a custom animation for launching search
1461 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001462 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001463 }
1464
Joe Onorato9c1289c2009-08-17 11:03:03 -04001465 public boolean isWorkspaceLocked() {
1466 return mWorkspaceLoading || mWaitingForResult;
1467 }
1468
Michael Jurka0280c3b2010-09-17 15:00:07 -07001469 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001470 mPendingAddInfo.container = ItemInfo.NO_ID;
1471 mPendingAddInfo.screen = -1;
1472 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1473 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
1474 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001475 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001476
Michael Jurkaaf442092010-06-10 17:01:57 -07001477 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001478 // TODO: catch bad widget exception when sent
1479 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001480 // TODO: Is this log message meaningful?
1481 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001482 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001483 }
1484
Adam Cohened66b2b2012-01-23 17:28:51 -08001485 void addAppWidgetImpl(final int appWidgetId, final PendingAddWidgetInfo info) {
1486 final AppWidgetProviderInfo appWidget = info.info;
1487 Runnable configurationActivity = null;
Bjorn Bringert7984c942009-12-09 15:38:25 +00001488 if (appWidget.configure != null) {
1489 // Launch over to configure widget, if needed
1490 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1491 intent.setComponent(appWidget.configure);
1492 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001493 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001494 if (info.mimeType != null && !info.mimeType.isEmpty()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001495 intent.putExtra(InstallWidgetReceiver.
1496 EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE, info.mimeType);
Winson Chung68846fd2010-10-29 11:00:27 -07001497
1498 final String mimeType = info.mimeType;
1499 final ClipData clipData = (ClipData) info.configurationData;
1500 final ClipDescription clipDesc = clipData.getDescription();
1501 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1502 if (clipDesc.getMimeType(i).equals(mimeType)) {
Dianne Hackborn0d5aad72011-01-17 15:28:58 -08001503 final ClipData.Item item = clipData.getItemAt(i);
Winson Chung68846fd2010-10-29 11:00:27 -07001504 final CharSequence stringData = item.getText();
1505 final Uri uriData = item.getUri();
1506 final Intent intentData = item.getIntent();
Adam Cohened66b2b2012-01-23 17:28:51 -08001507 final String key = InstallWidgetReceiver.
1508 EXTRA_APPWIDGET_CONFIGURATION_DATA;
Winson Chung68846fd2010-10-29 11:00:27 -07001509 if (uriData != null) {
1510 intent.putExtra(key, uriData);
1511 } else if (intentData != null) {
1512 intent.putExtra(key, intentData);
1513 } else if (stringData != null) {
1514 intent.putExtra(key, stringData);
1515 }
1516 break;
1517 }
1518 }
1519 }
Winson Chung55cef262010-10-28 14:14:18 -07001520 }
Romain Guy8e633c52010-03-04 12:51:36 -08001521 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
Adam Cohened66b2b2012-01-23 17:28:51 -08001522 mWidgetBeingConfigured = info;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001523 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001524 // Otherwise just add it
Adam Cohened66b2b2012-01-23 17:28:51 -08001525 completeAddAppWidget(appWidgetId, info.container, info.screen, info.boundWidget, appWidget);
Winson Chung557d6ed2011-07-08 15:34:52 -07001526 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001527 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001528 }
1529 }
Romain Guycbb89e42009-06-08 15:52:54 -07001530
Adam Cohenfbba09b2011-07-18 21:43:05 -07001531 /**
1532 * Process a shortcut drop.
1533 *
1534 * @param componentName The name of the component
1535 * @param screen The screen where it should be added
1536 * @param cell The cell it should be added to, optional
1537 * @param position The location on the screen where it was dropped, optional
1538 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001539 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1540 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001541 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001542 mPendingAddInfo.container = container;
1543 mPendingAddInfo.screen = screen;
1544 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001545
1546 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001547 mPendingAddInfo.cellX = cell[0];
1548 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001549 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001550
1551 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1552 createShortcutIntent.setComponent(componentName);
1553 processShortcut(createShortcutIntent);
1554 }
1555
Adam Cohenfbba09b2011-07-18 21:43:05 -07001556 /**
1557 * Process a widget drop.
1558 *
1559 * @param info The PendingAppWidgetInfo of the widget being added.
1560 * @param screen The screen where it should be added
1561 * @param cell The cell it should be added to, optional
1562 * @param position The location on the screen where it was dropped, optional
1563 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001564 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
1565 int[] cell, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001566 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001567 mPendingAddInfo.container = info.container = container;
1568 mPendingAddInfo.screen = info.screen = screen;
1569 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001570 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001571 mPendingAddInfo.cellX = cell[0];
1572 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001573 }
1574
Adam Cohened66b2b2012-01-23 17:28:51 -08001575 AppWidgetHostView hostView = info.boundWidget;
1576 int appWidgetId;
1577 if (hostView != null) {
1578 appWidgetId = hostView.getAppWidgetId();
1579 } else {
1580 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1581 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1582 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001583 addAppWidgetImpl(appWidgetId, info);
Adam Cohened66b2b2012-01-23 17:28:51 -08001584
Adam Cohenfbba09b2011-07-18 21:43:05 -07001585 }
1586
Joe Onoratodeb98af2010-02-19 14:59:39 -08001587 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001588 // Handle case where user selected "Applications"
1589 String applicationName = getResources().getString(R.string.group_applications);
1590 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001591
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001592 if (applicationName != null && applicationName.equals(shortcutName)) {
1593 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1594 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001595
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001596 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1597 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001598 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001599 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001600 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001601 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001602 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001603 }
1604
Winson Chung24ab2f12010-09-16 14:10:47 -07001605 void processWallpaper(Intent intent) {
1606 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1607 }
1608
Winson Chung3d503fb2011-07-13 17:25:49 -07001609 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1610 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001611 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001612 folderInfo.title = getText(R.string.folder_name);
1613
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001614 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001615 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1616 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001617 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001618
1619 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001620 FolderIcon newFolder =
1621 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1622 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1623 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001624 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001625 }
Romain Guycbb89e42009-06-08 15:52:54 -07001626
Joe Onorato9c1289c2009-08-17 11:03:03 -04001627 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001628 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001629 }
1630
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001631 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001632 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001633 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001634 Intent chooser = Intent.createChooser(pickWallpaper,
1635 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001636 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1637 // Removed in Eclair MR1
1638// WallpaperManager wm = (WallpaperManager)
1639// getSystemService(Context.WALLPAPER_SERVICE);
1640// WallpaperInfo wi = wm.getWallpaperInfo();
1641// if (wi != null && wi.getSettingsActivity() != null) {
1642// LabeledIntent li = new LabeledIntent(getPackageName(),
1643// R.string.configure_wallpaper, 0);
1644// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1645// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1646// }
Mike Clerona0618e42009-10-22 13:55:21 -07001647 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001648 }
1649
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001650 /**
1651 * Registers various content observers. The current implementation registers
1652 * only a favorites observer to keep track of the favorites applications.
1653 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001654 private void registerContentObservers() {
1655 ContentResolver resolver = getContentResolver();
1656 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1657 true, mWidgetObserver);
1658 }
1659
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001660 @Override
1661 public boolean dispatchKeyEvent(KeyEvent event) {
1662 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1663 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001664 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001665 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001666 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001667 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001668 dumpState();
1669 return true;
1670 }
1671 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001672 }
1673 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1674 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001675 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001676 return true;
1677 }
1678 }
1679
1680 return super.dispatchKeyEvent(event);
1681 }
1682
Joe Onorato88ec0992009-11-19 13:16:06 -08001683 @Override
1684 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001685 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001686 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001687 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001688 Folder openFolder = mWorkspace.getOpenFolder();
1689 if (openFolder.isEditingName()) {
1690 openFolder.dismissEditingName();
1691 } else {
1692 closeFolder();
1693 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001694 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001695 mWorkspace.exitWidgetResizeMode();
1696
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001697 // Back button is a no-op here, but give at least some feedback for the button press
1698 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001699 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001700 }
1701
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001702 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001703 * Re-listen when widgets are reset.
1704 */
1705 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001706 if (mAppWidgetHost != null) {
1707 mAppWidgetHost.startListening();
1708 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001709 }
1710
1711 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001712 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1713 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001714 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001715 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001716 if (mModel != null) {
1717 mModel.unbindWorkspaceItems();
1718 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001719 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001720
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001721 /**
1722 * Launches the intent referred by the clicked shortcut.
1723 *
1724 * @param v The view representing the clicked shortcut.
1725 */
1726 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001727 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1728 // view has detached (it's possible for this to happen if the view is removed mid touch).
1729 if (v.getWindowToken() == null) {
1730 return;
1731 }
1732
1733 if (mWorkspace.isSwitchingState()) {
1734 return;
1735 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001736
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001737 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001738 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001739 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001740 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001741 int[] pos = new int[2];
1742 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001743 intent.setSourceBounds(new Rect(pos[0], pos[1],
1744 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Michael Jurkaddd62e92011-02-16 17:49:14 -08001745 boolean success = startActivitySafely(intent, tag);
1746
1747 if (success && v instanceof BubbleTextView) {
1748 mWaitingForResume = (BubbleTextView) v;
1749 mWaitingForResume.setStayPressed(true);
1750 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001751 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001752 if (v instanceof FolderIcon) {
1753 FolderIcon fi = (FolderIcon) v;
1754 handleFolderClick(fi);
1755 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001756 } else if (v == mAllAppsButton) {
1757 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001758 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001759 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001760 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001761 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001762 }
1763 }
1764
Michael Jurka0e260592010-06-30 17:07:39 -07001765 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001766 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001767 // clicking anywhere on the workspace causes the customization drawer to slide down
1768 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001769 return false;
1770 }
1771
Michael Jurkaaf442092010-06-10 17:01:57 -07001772 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001773 * Event handler for the search button
1774 *
1775 * @param v The view that was clicked.
1776 */
1777 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001778 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1779
Amith Yamasania135ba82011-08-09 17:42:01 -07001780 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001781 }
1782
1783 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001784 * Event handler for the voice button
1785 *
1786 * @param v The view that was clicked.
1787 */
1788 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001789 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001790
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001791 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001792 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001793 startActivity(intent);
1794 }
1795
1796 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001797 * Event handler for the "grid" button that appears on the home screen, which
1798 * enters all apps mode.
1799 *
1800 * @param v The view that was clicked.
1801 */
1802 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001803 showAllApps(true);
1804 }
1805
1806 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001807 // Provide the same haptic feedback that the system offers for virtual keys.
1808 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001809 }
1810
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001811 public void onClickAppMarketButton(View v) {
1812 if (mAppMarketIntent != null) {
1813 startActivitySafely(mAppMarketIntent, "app market");
1814 }
1815 }
1816
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001817 void startApplicationDetailsActivity(ComponentName componentName) {
1818 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001819 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1820 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001821 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001822 startActivity(intent);
1823 }
1824
Patrick Dubroy5539af72010-09-07 15:22:01 -07001825 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1826 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1827 // System applications cannot be installed. For now, show a toast explaining that.
1828 // We may give them the option of disabling apps this way.
1829 int messageId = R.string.uninstall_system_app_text;
1830 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1831 } else {
1832 String packageName = appInfo.componentName.getPackageName();
1833 String className = appInfo.componentName.getClassName();
1834 Intent intent = new Intent(
1835 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001836 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1837 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001838 startActivity(intent);
1839 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001840 }
1841
Michael Jurkaddd62e92011-02-16 17:49:14 -08001842 boolean startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001843 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1844 try {
1845 startActivity(intent);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001846 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001847 } catch (ActivityNotFoundException e) {
1848 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001849 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001850 } catch (SecurityException e) {
1851 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001852 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001853 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001854 "or use the exported attribute for this activity. "
1855 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001856 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001857 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001858 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001859
Romain Guy8e633c52010-03-04 12:51:36 -08001860 void startActivityForResultSafely(Intent intent, int requestCode) {
1861 try {
1862 startActivityForResult(intent, requestCode);
1863 } catch (ActivityNotFoundException e) {
1864 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1865 } catch (SecurityException e) {
1866 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1867 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1868 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1869 "or use the exported attribute for this activity.", e);
1870 }
1871 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001872
Adam Cohena9cf38f2011-05-02 15:36:58 -07001873 private void handleFolderClick(FolderIcon folderIcon) {
1874 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07001875 Folder openFolder = mWorkspace.getFolderForTag(info);
1876
1877 // If the folder info reports that the associated folder is open, then verify that
1878 // it is actually opened. There have been a few instances where this gets out of sync.
1879 if (info.opened && openFolder == null) {
1880 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
1881 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
1882 info.opened = false;
1883 }
1884
Adam Cohena9cf38f2011-05-02 15:36:58 -07001885 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001886 // Close any open folder
1887 closeFolder();
1888 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07001889 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001890 } else {
1891 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001892 int folderScreen;
1893 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001894 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001895 // .. and close it
1896 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001897 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001898 // Close any folder open on the current screen
1899 closeFolder();
1900 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07001901 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001902 }
1903 }
1904 }
1905 }
1906
Adam Cohen2801caf2011-05-13 20:57:39 -07001907 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001908 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001909 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
1910 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
1911 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
1912
Adam Cohenc51934b2011-07-26 21:07:43 -07001913 FolderInfo info = (FolderInfo) fi.getTag();
1914 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1915 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07001916 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
1917 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07001918 }
1919
Adam Cohen2801caf2011-05-13 20:57:39 -07001920 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1921 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1922 oa.start();
1923 }
1924
1925 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001926 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001927 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1928 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1929 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1930
Adam Cohenc51934b2011-07-26 21:07:43 -07001931 FolderInfo info = (FolderInfo) fi.getTag();
1932 CellLayout cl = null;
1933 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1934 cl = (CellLayout) fi.getParent().getParent();
1935 }
1936
1937 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07001938 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1939 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07001940 oa.addListener(new AnimatorListenerAdapter() {
1941 @Override
1942 public void onAnimationEnd(Animator animation) {
1943 if (layout != null) {
1944 layout.clearFolderLeaveBehind();
1945 }
1946 }
1947 });
Adam Cohen2801caf2011-05-13 20:57:39 -07001948 oa.start();
1949 }
1950
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001951 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001952 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001953 * is animated relative to the specified View. If the View is null, no animation
1954 * is played.
1955 *
1956 * @param folderInfo The FolderInfo describing the folder to open.
1957 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001958 public void openFolder(FolderIcon folderIcon) {
1959 Folder folder = folderIcon.mFolder;
1960 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001961
Adam Cohen2801caf2011-05-13 20:57:39 -07001962 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001963 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001964
Adam Cohen4554ee12011-08-03 16:13:21 -07001965 // Just verify that the folder hasn't already been added to the DragLayer.
1966 // There was a one-off crash where the folder had a parent already.
1967 if (folder.getParent() == null) {
1968 mDragLayer.addView(folder);
1969 mDragController.addDropTarget((DropTarget) folder);
1970 } else {
1971 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
1972 folder.getParent() + ").");
1973 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001974 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07001975 }
1976
1977 public void closeFolder() {
1978 Folder folder = mWorkspace.getOpenFolder();
1979 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07001980 if (folder.isEditingName()) {
1981 folder.dismissEditingName();
1982 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001983 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07001984
1985 // Dismiss the folder cling
1986 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07001987 }
1988 }
1989
1990 void closeFolder(Folder folder) {
1991 folder.getInfo().opened = false;
1992
1993 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
1994 if (parent != null) {
1995 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
1996 shrinkAndFadeInFolderIcon(fi);
1997 }
1998 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001999 }
2000
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002001 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08002002 if (mState != State.WORKSPACE) {
2003 return false;
2004 }
2005
Joe Onorato9c1289c2009-08-17 11:03:03 -04002006 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002007 return false;
2008 }
2009
2010 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002011 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002012 }
2013
Michael Jurka0280c3b2010-09-17 15:00:07 -07002014 resetAddInfo();
2015 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002016 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002017 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002018 return true;
2019 }
2020
Winson Chung3d503fb2011-07-13 17:25:49 -07002021 // The hotseat touch handling does not go through Workspace, and we always allow long press
2022 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002023 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002024 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2025 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002026 if (itemUnderLongClick == null) {
2027 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07002028 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2029 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002030 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002032 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002033 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002034 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002035 }
2036 }
2037 }
2038 return true;
2039 }
2040
Winson Chung3d503fb2011-07-13 17:25:49 -07002041 boolean isHotseatLayout(View layout) {
2042 return mHotseat != null && layout != null &&
2043 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2044 }
2045 Hotseat getHotseat() {
2046 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002047 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002048 SearchDropTargetBar getSearchBar() {
2049 return mSearchDropTargetBar;
2050 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002051
Winson Chung3d503fb2011-07-13 17:25:49 -07002052 /**
2053 * Returns the CellLayout of the specified container at the specified screen.
2054 */
2055 CellLayout getCellLayout(long container, int screen) {
2056 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2057 if (mHotseat != null) {
2058 return mHotseat.getLayout();
2059 } else {
2060 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002061 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002062 } else {
2063 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002064 }
2065 }
2066
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002067 Workspace getWorkspace() {
2068 return mWorkspace;
2069 }
2070
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002071 @Override
2072 protected Dialog onCreateDialog(int id) {
2073 switch (id) {
2074 case DIALOG_CREATE_SHORTCUT:
2075 return new CreateShortcut().createDialog();
2076 case DIALOG_RENAME_FOLDER:
2077 return new RenameFolder().createDialog();
2078 }
2079
2080 return super.onCreateDialog(id);
2081 }
2082
2083 @Override
2084 protected void onPrepareDialog(int id, Dialog dialog) {
2085 switch (id) {
2086 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002087 break;
2088 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002089 if (mFolderInfo != null) {
2090 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2091 final CharSequence text = mFolderInfo.title;
2092 input.setText(text);
2093 input.setSelection(0, text.length());
2094 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002095 break;
2096 }
2097 }
2098
2099 void showRenameDialog(FolderInfo info) {
2100 mFolderInfo = info;
2101 mWaitingForResult = true;
2102 showDialog(DIALOG_RENAME_FOLDER);
2103 }
2104
Adam Cohenfbba09b2011-07-18 21:43:05 -07002105 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002106 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002107 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
2108 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002109 mWaitingForResult = true;
2110 showDialog(DIALOG_CREATE_SHORTCUT);
2111 }
2112
2113 private class RenameFolder {
2114 private EditText mInput;
2115
2116 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002117 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2118 mInput = (EditText) layout.findViewById(R.id.folder_name);
2119
2120 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2121 builder.setIcon(0);
2122 builder.setTitle(getString(R.string.rename_folder_title));
2123 builder.setCancelable(true);
2124 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2125 public void onCancel(DialogInterface dialog) {
2126 cleanup();
2127 }
2128 });
2129 builder.setNegativeButton(getString(R.string.cancel_action),
2130 new Dialog.OnClickListener() {
2131 public void onClick(DialogInterface dialog, int which) {
2132 cleanup();
2133 }
2134 }
2135 );
2136 builder.setPositiveButton(getString(R.string.rename_action),
2137 new Dialog.OnClickListener() {
2138 public void onClick(DialogInterface dialog, int which) {
2139 changeFolderName();
2140 }
2141 }
2142 );
2143 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002144
2145 final AlertDialog dialog = builder.create();
2146 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2147 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002148 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002149 mInput.requestFocus();
2150 InputMethodManager inputManager = (InputMethodManager)
2151 getSystemService(Context.INPUT_METHOD_SERVICE);
2152 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002153 }
2154 });
2155
2156 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002157 }
2158
2159 private void changeFolderName() {
2160 final String name = mInput.getText().toString();
2161 if (!TextUtils.isEmpty(name)) {
2162 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002163 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002164 mFolderInfo.title = name;
2165 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2166
Joe Onorato9c1289c2009-08-17 11:03:03 -04002167 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002168 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002169 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002170 } else {
2171 final FolderIcon folderIcon = (FolderIcon)
2172 mWorkspace.getViewForTag(mFolderInfo);
2173 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002174 // TODO: At some point we'll probably want some version of setting
2175 // the text for a folder icon.
2176 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002177 getWorkspace().requestLayout();
2178 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002179 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002180 mWorkspaceLoading = true;
2181 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002182 }
2183 }
2184 }
2185 cleanup();
2186 }
2187
2188 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002189 dismissDialog(DIALOG_RENAME_FOLDER);
2190 mWaitingForResult = false;
2191 mFolderInfo = null;
2192 }
2193 }
2194
Daniel Sandler843e8602010-06-07 14:59:01 -04002195 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2196 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002197 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002198 }
2199
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002200 // AllAppsView.Watcher
2201 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002202 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002203 mWorkspace.setVisibility(View.GONE);
2204 }
2205 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002206
2207 /**
2208 * Helper method for the cameraZoomIn/cameraZoomOut animations
2209 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002210 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002211 * @param scaleFactor The scale factor used for the zoom
2212 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002213 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002214 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002215 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002216 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002217
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002218 void updateWallpaperVisibility(boolean visible) {
2219 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2220 int curflags = getWindow().getAttributes().flags
2221 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2222 if (wpflags != curflags) {
2223 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2224 }
2225 }
2226
Michael Jurkabed61d22012-02-14 22:51:29 -08002227 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2228 if (v instanceof LauncherTransitionable) {
2229 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2230 }
2231 }
2232
2233 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2234 if (v instanceof LauncherTransitionable) {
2235 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2236 }
2237 }
2238
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002239 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002240 * Things to test when changing the following seven functions.
2241 * - Home from workspace
2242 * - from center screen
2243 * - from other screens
2244 * - Home from all apps
2245 * - from center screen
2246 * - from other screens
2247 * - Back from all apps
2248 * - from center screen
2249 * - from other screens
2250 * - Launch app from workspace and quit
2251 * - with back
2252 * - with home
2253 * - Launch app from all apps and quit
2254 * - with back
2255 * - with home
2256 * - Go to a screen that's not the default, then all
2257 * apps, and launch and app, and go back
2258 * - with back
2259 * -with home
2260 * - On workspace, long press power and go back
2261 * - with back
2262 * - with home
2263 * - On all apps, long press power and go back
2264 * - with back
2265 * - with home
2266 * - On workspace, power off
2267 * - On all apps, power off
2268 * - Launch an app and turn off the screen while in that app
2269 * - Go back with home key
2270 * - Go back with back key TODO: make this not go to workspace
2271 * - From all apps
2272 * - From workspace
2273 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2274 * - From all apps
2275 * - From the center workspace
2276 * - From another workspace
2277 */
2278
2279 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002280 * Zoom the camera out from the workspace to reveal 'toView'.
2281 * Assumes that the view to show is anchored at either the very top or very bottom
2282 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002283 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002284 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002285 if (mStateAnimation != null) {
2286 mStateAnimation.cancel();
2287 mStateAnimation = null;
2288 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002289 final Resources res = getResources();
Winson Chung7d7541e2011-09-16 20:14:36 -07002290 final Launcher instance = this;
Adam Cohenf16e5712011-01-13 13:31:45 -08002291
Winson Chungf0ea4d32011-06-06 14:27:16 -07002292 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2293 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2294 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002295 final View fromView = mWorkspace;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002296 final View toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002297 final int startDelay =
2298 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002299
Michael Jurkab3e22d92011-10-31 15:58:33 -07002300 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002301
Michael Jurkad74c9842011-07-10 12:44:21 -07002302 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002303 Animator workspaceAnim =
2304 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002305
2306 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002307 toView.setScaleX(scale);
2308 toView.setScaleY(scale);
2309 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2310 scaleAnim.
2311 scaleX(1f).scaleY(1f).
2312 setDuration(duration).
2313 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002314
Winson Chungf0ea4d32011-06-06 14:27:16 -07002315 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002316 toView.setAlpha(0f);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002317 final ObjectAnimator alphaAnim = ObjectAnimator
2318 .ofFloat(toView, "alpha", 0f, 1f)
2319 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002320 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Adam Cohenf16e5712011-01-13 13:31:45 -08002321
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002322 // toView should appear right at the end of the workspace shrink
2323 // animation
2324 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002325 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002326 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002327
2328 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002329 boolean animationCancelled = false;
2330
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002331 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002332 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002333 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002334 // Prepare the position
2335 toView.setTranslationX(0.0f);
2336 toView.setTranslationY(0.0f);
2337 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002338 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002339 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002340 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002341 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002342 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2343 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002344
2345 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2346 // Hide the workspace scrollbar
2347 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002348 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002349 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002350 if (!animationCancelled) {
2351 updateWallpaperVisibility(false);
2352 }
2353 }
2354
Adam Cohencff6af82011-09-13 14:51:53 -07002355 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002356 public void onAnimationCancel(Animator animation) {
2357 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002358 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002359 });
2360
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002361 if (workspaceAnim != null) {
2362 mStateAnimation.play(workspaceAnim);
2363 }
Michael Jurka1899a362011-11-03 13:50:45 -07002364
2365 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002366 final ViewTreeObserver observer;
2367
Michael Jurkabed61d22012-02-14 22:51:29 -08002368 dispatchOnLauncherTransitionStart(fromView, animated, false);
2369 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002370
2371 // If any of the objects being animated haven't been measured/laid out
2372 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002373 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002374 (mWorkspace.getMeasuredWidth() == 0) ||
2375 (toView.getMeasuredWidth() == 0)) {
2376 observer = mWorkspace.getViewTreeObserver();
2377 delayAnim = true;
2378 } else {
2379 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002380 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002381
2382 if (delayAnim) {
Michael Jurka49779a12012-01-16 04:10:08 -08002383 final AnimatorSet stateAnimation = mStateAnimation;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002384 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2385 public void onGlobalLayout() {
2386 mWorkspace.post(new Runnable() {
2387 public void run() {
Michael Jurka49779a12012-01-16 04:10:08 -08002388 // Check that mStateAnimation hasn't changed while
2389 // we waited for a layout pass
2390 if (mStateAnimation == stateAnimation) {
2391 // Need to update pivots for zoom if layout changed
2392 setPivotsForZoom(toView, scale);
2393 mStateAnimation.start();
2394 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002395 }
2396 });
2397 observer.removeGlobalOnLayoutListener(this);
2398 }
2399 };
2400 observer.addOnGlobalLayoutListener(delayedStart);
2401 } else {
2402 setPivotsForZoom(toView, scale);
Michael Jurka1899a362011-11-03 13:50:45 -07002403 mStateAnimation.start();
2404 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002405 } else {
2406 toView.setTranslationX(0.0f);
2407 toView.setTranslationY(0.0f);
2408 toView.setScaleX(1.0f);
2409 toView.setScaleY(1.0f);
2410 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002411 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002412
Michael Jurkabed61d22012-02-14 22:51:29 -08002413 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2414 // Hide the workspace scrollbar
2415 mWorkspace.hideScrollingIndicator(true);
2416 hideDockDivider();
Michael Jurkaabded662011-03-04 12:06:57 -08002417 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002418 dispatchOnLauncherTransitionStart(fromView, animated, false);
2419 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2420 dispatchOnLauncherTransitionStart(toView, animated, false);
2421 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002422 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002423 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002424 }
2425
2426 /**
2427 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002428 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002429 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002430 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002431 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2432 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002433
Michael Jurkab3e22d92011-10-31 15:58:33 -07002434 if (mStateAnimation != null) {
2435 mStateAnimation.cancel();
2436 mStateAnimation = null;
2437 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002438 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002439
Winson Chungf0ea4d32011-06-06 14:27:16 -07002440 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002441 final int fadeOutDuration =
2442 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002443 final float scaleFactor = (float)
2444 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2445 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002446 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002447 Animator workspaceAnim = null;
2448
2449 if (toState == State.WORKSPACE) {
2450 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2451 workspaceAnim = mWorkspace.getChangeStateAnimation(
2452 Workspace.State.NORMAL, animated, stagger);
2453 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2454 workspaceAnim = mWorkspace.getChangeStateAnimation(
2455 Workspace.State.SPRING_LOADED, animated);
2456 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002457
Michael Jurkab3e22d92011-10-31 15:58:33 -07002458 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002459 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002460 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002461 if (animated) {
Michael Jurka742574b2011-02-02 23:51:01 -08002462 final float oldScaleX = fromView.getScaleX();
2463 final float oldScaleY = fromView.getScaleY();
2464
Michael Jurka159b4cc2012-01-17 03:00:35 -08002465 final LauncherViewPropertyAnimator scaleAnim =
2466 new LauncherViewPropertyAnimator(fromView);
2467 scaleAnim.
2468 scaleX(scaleFactor).scaleY(scaleFactor).
2469 setDuration(duration).
2470 setInterpolator(new Workspace.ZoomInInterpolator());
2471
2472 final ObjectAnimator alphaAnim = ObjectAnimator
2473 .ofFloat(fromView, "alpha", 1f, 0f)
2474 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002475 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Michael Jurka159b4cc2012-01-17 03:00:35 -08002476
Michael Jurkabed61d22012-02-14 22:51:29 -08002477 mStateAnimation = new AnimatorSet();
2478
2479 dispatchOnLauncherTransitionStart(fromView, animated, true);
2480 dispatchOnLauncherTransitionStart(toView, animated, true);
2481
2482 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002483 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002484 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002485 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002486 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002487 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2488 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurka430e8a52011-08-08 15:52:14 -07002489 mWorkspace.hideScrollingIndicator(false);
Adam Cohened66b2b2012-01-23 17:28:51 -08002490 if (onCompleteRunnable != null) {
2491 onCompleteRunnable.run();
2492 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002493 }
2494 });
2495
Winson Chungf0ea4d32011-06-06 14:27:16 -07002496 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002497 if (workspaceAnim != null) {
2498 mStateAnimation.play(workspaceAnim);
2499 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002500 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002501 } else {
2502 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08002503 dispatchOnLauncherTransitionStart(fromView, animated, true);
2504 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2505 dispatchOnLauncherTransitionStart(toView, animated, true);
2506 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002507 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002508 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002509 }
2510
Michael Jurkae326f182011-11-21 14:05:46 -08002511 @Override
2512 public void onTrimMemory(int level) {
2513 super.onTrimMemory(level);
2514 if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
2515 mAppsCustomizeTabHost.onTrimMemory();
2516 }
2517 }
2518
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002519 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002520 showWorkspace(animated, null);
2521 }
2522
2523 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002524 if (mState != State.WORKSPACE) {
2525 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08002526 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002527
2528 // Show the search bar and hotseat
2529 mSearchDropTargetBar.showSearchBar(animated);
Michael Jurkab737ee62011-11-15 15:57:22 -08002530 // We only need to animate in the dock divider if we're going from spring loaded mode
2531 showDockDivider(animated && mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002532
2533 // Set focus to the AppsCustomize button
2534 if (mAllAppsButton != null) {
2535 mAllAppsButton.requestFocus();
2536 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002537 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002538
Michael Jurkab737ee62011-11-15 15:57:22 -08002539 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002540
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002541 // Change the state *after* we've called all the transition code
2542 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002543
Winson Chung5fb63472011-02-02 17:03:37 -08002544 // Resume the auto-advance of widgets
2545 mUserPresent = true;
2546 updateRunning();
2547
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002548 // send an accessibility event to announce the context change
2549 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002550 }
2551
Michael Jurkab3e22d92011-10-31 15:58:33 -07002552 void showAllApps(boolean animated) {
2553 if (mState != State.WORKSPACE) return;
2554
2555 showAppsCustomizeHelper(animated, false);
2556 mAppsCustomizeTabHost.requestFocus();
2557
2558 // Hide the search bar and hotseat
2559 mSearchDropTargetBar.hideSearchBar(animated);
2560
2561 // Change the state *after* we've called all the transition code
2562 mState = State.APPS_CUSTOMIZE;
2563
2564 // Pause the auto-advance of widgets until we are out of AllApps
2565 mUserPresent = false;
2566 updateRunning();
2567 closeFolder();
2568
2569 // Send an accessibility event to announce the context change
2570 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2571 }
2572
Adam Cohen7777d962011-08-18 18:58:38 -07002573 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002574 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohened66b2b2012-01-23 17:28:51 -08002575 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Michael Jurkab737ee62011-11-15 15:57:22 -08002576 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002577 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002578 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002579 }
Adam Cohen7777d962011-08-18 18:58:38 -07002580
Adam Cohened66b2b2012-01-23 17:28:51 -08002581 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
2582 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07002583 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2584
Winson Chunge7a03942011-08-05 15:05:12 -07002585 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002586 @Override
2587 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002588 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002589 // Before we show workspace, hide all apps again because
2590 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2591 // clean up our state transition functions
2592 mAppsCustomizeTabHost.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002593 mSearchDropTargetBar.showSearchBar(true);
Adam Cohened66b2b2012-01-23 17:28:51 -08002594 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07002595 } else {
2596 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002597 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002598 }
2599 }, (extendedDelay ?
2600 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2601 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2602 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002603
Michael Jurkad3ef3062010-11-23 16:23:58 -08002604 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002605 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002606 final boolean animated = true;
2607 final boolean springLoaded = true;
2608 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002609 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002610 }
2611 // Otherwise, we are not in spring loaded mode, so don't do anything.
2612 }
2613
Michael Jurkab737ee62011-11-15 15:57:22 -08002614 void hideDockDivider() {
2615 if (mQsbDivider != null && mDockDivider != null) {
2616 mQsbDivider.setVisibility(View.INVISIBLE);
2617 mDockDivider.setVisibility(View.INVISIBLE);
2618 }
2619 }
2620
2621 void showDockDivider(boolean animated) {
2622 if (mQsbDivider != null && mDockDivider != null) {
2623 mQsbDivider.setVisibility(View.VISIBLE);
2624 mDockDivider.setVisibility(View.VISIBLE);
2625 if (mDividerAnimator != null) {
2626 mDividerAnimator.cancel();
2627 mQsbDivider.setAlpha(1f);
2628 mDockDivider.setAlpha(1f);
2629 mDividerAnimator = null;
2630 }
2631 if (animated) {
2632 mDividerAnimator = new AnimatorSet();
2633 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2634 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2635 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2636 mDividerAnimator.start();
2637 }
2638 }
2639 }
2640
Michael Jurkab3e22d92011-10-31 15:58:33 -07002641 void lockAllApps() {
2642 // TODO
2643 }
2644
2645 void unlockAllApps() {
2646 // TODO
2647 }
2648
Adam Cohenfc53cd22011-07-20 15:45:11 -07002649 public boolean isAllAppsCustomizeOpen() {
2650 return mState == State.APPS_CUSTOMIZE;
2651 }
2652
Winson Chungf0ea4d32011-06-06 14:27:16 -07002653 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002654 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002655 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002656 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002657 if (!LauncherApplication.isScreenLarge()) {
2658 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002659 if (mHotseat.getAlpha() != 1f) {
2660 int duration = mSearchDropTargetBar.getTransitionInDuration();
2661 mHotseat.animate().alpha(1f).setDuration(duration);
2662 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002663 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002664 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002665 }
2666 }
2667 }
2668
2669 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002670 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002671 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002672 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002673 if (!LauncherApplication.isScreenLarge()) {
2674 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002675 if (mHotseat.getAlpha() != 0f) {
2676 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2677 mHotseat.animate().alpha(0f).setDuration(duration);
2678 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002679 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002680 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002681 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002682 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002683 }
2684
Patrick Dubroy5f445422011-02-18 14:35:21 -08002685 /**
2686 * Add an item from all apps or customize onto the given workspace screen.
2687 * If layout is null, add to the current screen.
2688 */
2689 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002690 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2691 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07002692 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002693 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002694
Winson Chungdff8ebb2011-09-08 17:25:31 -07002695 /** Maps the current orientation to an index for referencing orientation correct global icons */
2696 private int getCurrentOrientationIndexForGlobalIcons() {
2697 // default - 0, landscape - 1
2698 switch (getResources().getConfiguration().orientation) {
2699 case Configuration.ORIENTATION_LANDSCAPE:
2700 return 1;
2701 default:
2702 return 0;
2703 }
2704 }
2705
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002706 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002707 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002708 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002709 // Look for the toolbar icon specified in the activity meta-data
2710 Bundle metaData = packageManager.getActivityInfo(
2711 activityName, PackageManager.GET_META_DATA).metaData;
2712 if (metaData != null) {
2713 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2714 if (iconResId != 0) {
2715 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002716 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002717 }
2718 }
2719 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002720 // This can happen if the activity defines an invalid drawable
2721 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2722 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002723 } catch (Resources.NotFoundException nfe) {
2724 // This can happen if the activity defines an invalid drawable
2725 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2726 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002727 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002728 return null;
2729 }
2730
2731 // if successful in getting icon, return it; otherwise, set button to use default drawable
2732 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2733 int buttonId, ComponentName activityName, int fallbackDrawableId) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002734 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002735 Resources r = getResources();
2736 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2737 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002738
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002739 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002740 // If we were unable to find the icon via the meta-data, use a generic one
2741 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002742 toolbarIcon = r.getDrawable(fallbackDrawableId);
2743 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002744 if (button != null) {
2745 button.setCompoundDrawables(toolbarIcon, null, null, null);
2746 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002747 return null;
2748 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002749 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002750 if (button != null) {
2751 button.setCompoundDrawables(toolbarIcon, null, null, null);
2752 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002753 return toolbarIcon.getConstantState();
2754 }
2755 }
2756
2757 // if successful in getting icon, return it; otherwise, set button to use default drawable
2758 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2759 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2760 ImageView button = (ImageView) findViewById(buttonId);
2761 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2762
Michael Jurka19e0fc52011-07-22 18:00:21 -07002763 if (button != null) {
2764 // If we were unable to find the icon via the meta-data, use a
2765 // generic one
2766 if (toolbarIcon == null) {
2767 button.setImageResource(fallbackDrawableId);
2768 } else {
2769 button.setImageDrawable(toolbarIcon);
2770 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002771 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002772
2773 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2774
Michael Jurka0423dcf2010-10-05 14:56:18 -07002775 }
2776
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002777 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2778 TextView button = (TextView) findViewById(buttonId);
2779 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2780 }
2781
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002782 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002783 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002784 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002785 }
2786
Winson Chungbb185bd2011-11-21 12:31:42 -08002787 private void invalidatePressedFocusedStates(View container, View button) {
2788 if (container instanceof HolographicLinearLayout) {
2789 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2790 layout.invalidatePressedFocusedStates();
2791 } else if (button instanceof HolographicImageView) {
2792 HolographicImageView view = (HolographicImageView) button;
2793 view.invalidatePressedFocusedStates();
2794 }
2795 }
2796
Winson Chungc51db6a2011-10-05 11:44:49 -07002797 private boolean updateGlobalSearchIcon() {
2798 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002799 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2800 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002801 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002802 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002803
Winson Chung1cad91e2011-05-25 17:41:01 -07002804 final SearchManager searchManager =
2805 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2806 ComponentName activityName = searchManager.getGlobalSearchActivity();
2807 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002808 int coi = getCurrentOrientationIndexForGlobalIcons();
2809 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002810 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002811 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002812 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2813 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002814 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002815 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002816 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002817 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002818 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002819 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2820 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2821 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002822 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002823 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002824 }
2825 }
2826
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002827 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002828 final View searchButtonContainer = findViewById(R.id.search_button_container);
2829 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002830 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002831 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002832 }
2833
Winson Chungc51db6a2011-10-05 11:44:49 -07002834 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002835 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002836 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002837 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002838
Winson Chungc51db6a2011-10-05 11:44:49 -07002839 // We only show/update the voice search icon if the search icon is enabled as well
Winson Chung1cad91e2011-05-25 17:41:01 -07002840 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2841 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chungc51db6a2011-10-05 11:44:49 -07002842 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002843 int coi = getCurrentOrientationIndexForGlobalIcons();
2844 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002845 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002846 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002847 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002848 voiceButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002849 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002850 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002851 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002852 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002853 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002854 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002855 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002856 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002857 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002858
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002859 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002860 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
2861 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002862 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002863 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002864 }
2865
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002866 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002867 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002868 */
2869 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002870 final View marketButton = findViewById(R.id.market_button);
2871 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2872 // Find the app market activity by resolving an intent.
2873 // (If multiple app markets are installed, it will return the ResolverActivity.)
2874 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002875 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002876 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07002877 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07002878 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002879 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002880 marketButton.setVisibility(View.VISIBLE);
2881 } else {
2882 // We should hide and disable the view so that we don't try and restore the visibility
2883 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2884 marketButton.setVisibility(View.GONE);
2885 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002886 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002887 }
2888
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002889 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002890 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002891 }
2892
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002893 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002894 * Displays the shortcut creation dialog and launches, if necessary, the
2895 * appropriate activity.
2896 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002897 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002898 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2899 DialogInterface.OnShowListener {
2900
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002901 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002902
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002903 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002904 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002905
Winson Chung55b65502011-05-26 12:03:43 -07002906 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2907 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002908 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002909
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002910 AlertDialog dialog = builder.create();
2911 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002912 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002913 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002914
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002915 return dialog;
2916 }
2917
2918 public void onCancel(DialogInterface dialog) {
2919 mWaitingForResult = false;
2920 cleanup();
2921 }
2922
Romain Guycbb89e42009-06-08 15:52:54 -07002923 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002924 mWaitingForResult = false;
2925 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002926 }
2927
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002928 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002929 try {
2930 dismissDialog(DIALOG_CREATE_SHORTCUT);
2931 } catch (Exception e) {
2932 // An exception is thrown if the dialog is not visible, which is fine
2933 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002934 }
2935
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002936 /**
2937 * Handle the action clicked in the "Add to home" dialog.
2938 */
2939 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002940 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002941
Winson Chung55b65502011-05-26 12:03:43 -07002942 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2943 switch (item.actionTag) {
Winson Chung55b65502011-05-26 12:03:43 -07002944 case AddAdapter.ITEM_APPLICATION: {
2945 if (mAppsCustomizeTabHost != null) {
2946 mAppsCustomizeTabHost.selectAppsTab();
2947 }
2948 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002949 break;
2950 }
Winson Chung55b65502011-05-26 12:03:43 -07002951 case AddAdapter.ITEM_APPWIDGET: {
2952 if (mAppsCustomizeTabHost != null) {
2953 mAppsCustomizeTabHost.selectWidgetsTab();
2954 }
2955 showAllApps(true);
2956 break;
2957 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002958 case AddAdapter.ITEM_WALLPAPER: {
2959 startWallpaper();
2960 break;
2961 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002962 }
2963 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002964
2965 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002966 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002967 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002968 }
2969
2970 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07002971 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002972 */
2973 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2974 @Override
2975 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002976 closeSystemDialogs();
2977 }
2978 }
2979
2980 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002981 * Receives notifications whenever the appwidgets are reset.
2982 */
2983 private class AppWidgetResetObserver extends ContentObserver {
2984 public AppWidgetResetObserver() {
2985 super(new Handler());
2986 }
2987
2988 @Override
2989 public void onChange(boolean selfChange) {
2990 onAppWidgetReset();
2991 }
2992 }
2993
2994 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002995 * If the activity is currently paused, signal that we need to re-run the loader
2996 * in onResume.
2997 *
2998 * This needs to be called from incoming places where resources might have been loaded
2999 * while we are paused. That is becaues the Configuration might be wrong
3000 * when we're not running, and if it comes back to what it was when we
3001 * were paused, we are not restarted.
3002 *
3003 * Implementation of the method from LauncherModel.Callbacks.
3004 *
3005 * @return true if we are currently paused. The caller might be able to
3006 * skip some work in that case since we will come back again.
3007 */
3008 public boolean setLoadOnResume() {
3009 if (mPaused) {
3010 Log.i(TAG, "setLoadOnResume");
3011 mOnResumeNeedsLoad = true;
3012 return true;
3013 } else {
3014 return false;
3015 }
3016 }
3017
3018 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003019 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003020 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003021 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003022 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003023 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003024 } else {
3025 return SCREEN_COUNT / 2;
3026 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003027 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003028
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003029
Joe Onorato9c1289c2009-08-17 11:03:03 -04003030 /**
3031 * Refreshes the shortcuts shown on the workspace.
3032 *
3033 * Implementation of the method from LauncherModel.Callbacks.
3034 */
3035 public void startBinding() {
3036 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07003037
3038 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003039 int count = workspace.getChildCount();
3040 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003041 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08003042 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
3043 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003044 }
Michael Jurka05bf6442011-11-30 20:28:53 -08003045 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003046 if (mHotseat != null) {
3047 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003048 }
3049 }
3050
3051 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003052 * Bind the items start-end from the list.
3053 *
3054 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003055 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003056 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003057 setLoadOnResume();
3058
Joe Onorato9c1289c2009-08-17 11:03:03 -04003059 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003060 for (int i=start; i<end; i++) {
3061 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003062
3063 // Short circuit if we are loading dock items for a configuration which has no dock
3064 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3065 mHotseat == null) {
3066 continue;
3067 }
3068
Joe Onorato9c1289c2009-08-17 11:03:03 -04003069 switch (item.itemType) {
3070 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3071 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07003072 View shortcut = createShortcut((ShortcutInfo)item);
3073 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3074 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003075 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003076 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003077 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003078 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003079 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003080 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3081 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003082 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003083 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003084 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003085 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003086 }
3087
Joe Onorato9c1289c2009-08-17 11:03:03 -04003088 /**
3089 * Implementation of the method from LauncherModel.Callbacks.
3090 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003091 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003092 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003093 sFolders.clear();
3094 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003095 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003096
3097 /**
3098 * Add the views for a widget to the workspace.
3099 *
3100 * Implementation of the method from LauncherModel.Callbacks.
3101 */
3102 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003103 setLoadOnResume();
3104
Daniel Sandler843e8602010-06-07 14:59:01 -04003105 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3106 if (DEBUG_WIDGETS) {
3107 Log.d(TAG, "bindAppWidget: " + item);
3108 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003109 final Workspace workspace = mWorkspace;
3110
3111 final int appWidgetId = item.appWidgetId;
3112 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003113 if (DEBUG_WIDGETS) {
3114 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3115 }
3116
Joe Onorato9c1289c2009-08-17 11:03:03 -04003117 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3118
Joe Onorato9c1289c2009-08-17 11:03:03 -04003119 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
3120 item.hostView.setTag(item);
3121
Winson Chung3d503fb2011-07-13 17:25:49 -07003122 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003123 item.cellY, item.spanX, item.spanY, false);
3124
Adam Cohended9f8d2010-11-03 13:25:16 -07003125 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3126
Joe Onorato9c1289c2009-08-17 11:03:03 -04003127 workspace.requestLayout();
3128
Daniel Sandler843e8602010-06-07 14:59:01 -04003129 if (DEBUG_WIDGETS) {
3130 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3131 + (SystemClock.uptimeMillis()-start) + "ms");
3132 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003133 }
3134
3135 /**
3136 * Callback saying that there aren't any more items to bind.
3137 *
3138 * Implementation of the method from LauncherModel.Callbacks.
3139 */
3140 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003141 setLoadOnResume();
3142
Joe Onorato9c1289c2009-08-17 11:03:03 -04003143 if (mSavedState != null) {
3144 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003145 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003146 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003147 mSavedState = null;
3148 }
3149
3150 if (mSavedInstanceState != null) {
3151 super.onRestoreInstanceState(mSavedInstanceState);
3152 mSavedInstanceState = null;
3153 }
3154
Joe Onorato9c1289c2009-08-17 11:03:03 -04003155 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003156
3157 // If we received the result of any pending adds while the loader was running (e.g. the
3158 // widget configuration forced an orientation change), process them now.
3159 for (int i = 0; i < sPendingAddList.size(); i++) {
3160 completeAdd(sPendingAddList.get(i));
3161 }
3162 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003163
Winson Chungc51db6a2011-10-05 11:44:49 -07003164 // Update the market app icon as necessary (the other icons will be managed in response to
3165 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003166 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003167
3168 mWorkspace.post(mBuildLayersRunnable);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003169 }
3170
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003171 @Override
3172 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003173 boolean searchVisible = updateGlobalSearchIcon();
3174 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3175 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003176 }
3177
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003178 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003179 * Add the icons for all apps.
3180 *
3181 * Implementation of the method from LauncherModel.Callbacks.
3182 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003183 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3184 // Remove the progress bar entirely; we could also make it GONE
3185 // but better to remove it since we know it's not going to be used
3186 View progressBar = mAppsCustomizeTabHost.
3187 findViewById(R.id.apps_customize_progress_bar);
3188 if (progressBar != null) {
3189 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003190 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003191 // We just post the call to setApps so the user sees the progress bar
3192 // disappear-- otherwise, it just looks like the progress bar froze
3193 // which doesn't look great
3194 mAppsCustomizeTabHost.post(new Runnable() {
3195 public void run() {
3196 if (mAppsCustomizeContent != null) {
3197 mAppsCustomizeContent.setApps(apps);
3198 }
3199 }
3200 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003201 }
3202
3203 /**
3204 * A package was installed.
3205 *
3206 * Implementation of the method from LauncherModel.Callbacks.
3207 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003208 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003209 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003210 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003211
Winson Chung785d2eb2011-04-14 16:08:02 -07003212 if (mAppsCustomizeContent != null) {
3213 mAppsCustomizeContent.addApps(apps);
3214 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003215 }
3216
3217 /**
3218 * A package was updated.
3219 *
3220 * Implementation of the method from LauncherModel.Callbacks.
3221 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003222 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003223 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003224 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003225 if (mWorkspace != null) {
3226 mWorkspace.updateShortcuts(apps);
3227 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003228
Winson Chung785d2eb2011-04-14 16:08:02 -07003229 if (mAppsCustomizeContent != null) {
3230 mAppsCustomizeContent.updateApps(apps);
3231 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003232 }
3233
3234 /**
3235 * A package was uninstalled.
3236 *
3237 * Implementation of the method from LauncherModel.Callbacks.
3238 */
Joe Onorato36115782010-06-17 13:28:48 -04003239 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003240 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003241 if (permanent) {
3242 mWorkspace.removeItems(apps);
3243 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003244
Winson Chung785d2eb2011-04-14 16:08:02 -07003245 if (mAppsCustomizeContent != null) {
3246 mAppsCustomizeContent.removeApps(apps);
3247 }
Winson Chunga1820962011-10-03 16:31:06 -07003248
3249 // Notify the drag controller
3250 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003251 }
Joe Onoratobe386092009-11-17 17:32:16 -08003252
3253 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003254 * A number of packages were updated.
3255 */
3256 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003257 if (mAppsCustomizeContent != null) {
3258 mAppsCustomizeContent.onPackagesUpdated();
3259 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003260 }
3261
Winson Chung400438b2011-01-16 17:53:48 -08003262 private int mapConfigurationOriActivityInfoOri(int configOri) {
3263 final Display d = getWindowManager().getDefaultDisplay();
3264 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3265 switch (d.getRotation()) {
3266 case Surface.ROTATION_0:
3267 case Surface.ROTATION_180:
3268 // We are currently in the same basic orientation as the natural orientation
3269 naturalOri = configOri;
3270 break;
3271 case Surface.ROTATION_90:
3272 case Surface.ROTATION_270:
3273 // We are currently in the other basic orientation to the natural orientation
3274 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3275 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3276 break;
3277 }
3278
3279 int[] oriMap = {
3280 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3281 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3282 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3283 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3284 };
3285 // Since the map starts at portrait, we need to offset if this device's natural orientation
3286 // is landscape.
3287 int indexOffset = 0;
3288 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3289 indexOffset = 1;
3290 }
3291 return oriMap[(d.getRotation() + indexOffset) % 4];
3292 }
Adam Cohen446e9402011-09-15 18:21:21 -07003293
3294 public void lockScreenOrientationOnLargeUI() {
3295 if (LauncherApplication.isScreenLarge()) {
3296 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3297 .getConfiguration().orientation));
3298 }
Winson Chung400438b2011-01-16 17:53:48 -08003299 }
Adam Cohen446e9402011-09-15 18:21:21 -07003300 public void unlockScreenOrientationOnLargeUI() {
3301 if (LauncherApplication.isScreenLarge()) {
3302 mHandler.postDelayed(new Runnable() {
3303 public void run() {
3304 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3305 }
3306 }, mRestoreScreenOrientationDelay);
3307 }
Winson Chung400438b2011-01-16 17:53:48 -08003308 }
3309
Winson Chung82f55532011-08-09 14:14:23 -07003310 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003311 private static final String PREFS_KEY = "com.android.launcher2.prefs";
3312 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003313 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003314 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003315
Winson Chung7d7541e2011-09-16 20:14:36 -07003316 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003317 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003318 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3319 Cling cling = (Cling) findViewById(clingId);
3320 if (cling != null) {
3321 cling.init(this, positionData);
3322 cling.setVisibility(View.VISIBLE);
3323 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3324 if (animate) {
3325 cling.buildLayer();
3326 cling.setAlpha(0f);
3327 cling.animate()
3328 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003329 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003330 .setDuration(SHOW_CLING_DURATION)
3331 .setStartDelay(delay)
3332 .start();
3333 } else {
3334 cling.setAlpha(1f);
3335 }
3336 }
3337 return cling;
3338 }
3339 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003340 if (cling != null) {
3341 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003342 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003343 anim.addListener(new AnimatorListenerAdapter() {
3344 public void onAnimationEnd(Animator animation) {
3345 cling.setVisibility(View.GONE);
3346 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08003347 // We should update the shared preferences on a background thread
3348 new Thread("dismissClingThread") {
3349 public void run() {
3350 SharedPreferences.Editor editor = mSharedPrefs.edit();
3351 editor.putBoolean(flag, true);
3352 editor.commit();
3353 }
3354 }.start();
Winson Chung82f55532011-08-09 14:14:23 -07003355 };
3356 });
3357 anim.start();
3358 }
3359 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003360 private void removeCling(int id) {
3361 final View cling = findViewById(id);
3362 if (cling != null) {
3363 final ViewGroup parent = (ViewGroup) cling.getParent();
3364 parent.post(new Runnable() {
3365 @Override
3366 public void run() {
3367 parent.removeView(cling);
3368 }
3369 });
3370 }
3371 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003372 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003373 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003374 if (isClingsEnabled() &&
3375 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003376 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003377 } else {
3378 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003379 }
3380 }
3381 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003382 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003383 if (isClingsEnabled() &&
3384 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003385 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003386 } else {
3387 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003388 }
3389 }
3390 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003391 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08003392 if (isClingsEnabled() &&
3393 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
3394 return initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003395 } else {
3396 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08003397 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07003398 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003399 }
3400 public boolean isFolderClingVisible() {
3401 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003402 if (cling != null) {
3403 return cling.getVisibility() == View.VISIBLE;
3404 }
3405 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003406 }
Winson Chung82f55532011-08-09 14:14:23 -07003407 public void dismissWorkspaceCling(View v) {
3408 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003409 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003410 }
3411 public void dismissAllAppsCling(View v) {
3412 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003413 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3414 }
3415 public void dismissFolderCling(View v) {
3416 Cling cling = (Cling) findViewById(R.id.folder_cling);
3417 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003418 }
3419
Winson Chung80baf5a2010-08-09 16:03:15 -07003420 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003421 * Prints out out state for debugging.
3422 */
3423 public void dumpState() {
3424 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003425 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003426 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3427 Log.d(TAG, "mRestoring=" + mRestoring);
3428 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3429 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003430 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003431 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003432
Winson Chung785d2eb2011-04-14 16:08:02 -07003433 if (mAppsCustomizeContent != null) {
3434 mAppsCustomizeContent.dumpState();
3435 }
Joe Onoratobe386092009-11-17 17:32:16 -08003436 Log.d(TAG, "END launcher2 dump state");
3437 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003438
3439 @Override
3440 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3441 super.dump(prefix, fd, writer, args);
3442 writer.println(" ");
3443 writer.println("Debug logs: ");
3444 for (int i = 0; i < sDumpLogs.size(); i++) {
3445 writer.println(" " + sDumpLogs.get(i));
3446 }
3447 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003448}
Michael Jurka2763be32011-02-24 11:19:57 -08003449
Michael Jurkaabded662011-03-04 12:06:57 -08003450interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003451 View getContent();
Michael Jurkabed61d22012-02-14 22:51:29 -08003452 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
3453 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003454}