blob: a11c487bc929cc7fd34c677581474af0399b5a7b [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
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Michael Jurka974c3862012-05-22 22:00:31 -070020import android.accounts.Account;
21import android.accounts.AccountManager;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080023import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070024import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070025import android.animation.ObjectAnimator;
26import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070027import android.animation.ValueAnimator;
Winson Chung70442722012-02-10 15:43:22 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070030import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070031import android.app.ActivityOptions;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
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;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070043import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070044import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070047import android.content.pm.PackageManager.NameNotFoundException;
Bjorn Bringert85f418d2013-09-06 12:50:05 +010048import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Winson Chung5f8afe62013-08-12 16:19:28 -070054import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070055import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070056import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040058import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070059import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020061import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080062import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070063import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070064import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070066import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080067import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.text.Selection;
69import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070070import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070072import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070074import android.view.Display;
75import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
77import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070080import android.view.MotionEvent;
81import android.view.Surface;
82import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070083import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080084import android.view.View.OnLongClickListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070085import android.view.ViewGroup;
86import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080087import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Adam Cohen96d30a12013-07-16 18:13:21 -070088import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080089import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070090import android.view.animation.AccelerateDecelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080091import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080092import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070093import android.widget.Advanceable;
94import android.widget.FrameLayout;
95import android.widget.ImageView;
96import android.widget.TextView;
97import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070098
Daniel Sandler325dc232013-06-05 22:57:57 -040099import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -0800100
Adam Cohenc0dcf592011-06-01 15:30:43 -0700101import java.io.DataInputStream;
102import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700103import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700104import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700105import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700106import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700107import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700108import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700109import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700110import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700111import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700112import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700113import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700114import java.util.List;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700115
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800116/**
117 * Default launcher application.
118 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100119public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700120 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700121 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800122 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700123 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800124
Daniel Sandlerf061f822013-06-27 13:59:36 -0400125 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400126 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700127 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400128 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700129 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700130
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700132 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133 private static final int REQUEST_PICK_APPLICATION = 6;
134 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700135 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700136 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137
Michael Jurka8b805b12012-04-18 14:23:14 -0700138 private static final int REQUEST_BIND_APPWIDGET = 11;
139
Mathew Inwood876a8462013-06-14 14:12:41 +0100140 /**
141 * IntentStarter uses request codes starting with this. This must be greater than all activity
142 * request codes used internally.
143 */
144 protected static final int REQUEST_LAST = 100;
145
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
147
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800148 static final int SCREEN_COUNT = 5;
149 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150
Romain Guy98d01652009-06-30 16:21:04 -0700151 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800152 // To turn on these properties, type
153 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
154 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
155 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156
Winson Chung2672ff92012-05-04 16:22:30 -0700157 // The Intent extra that defines whether to ignore the launch animation
158 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400159 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700160
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800161 // Type: int
162 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700163 // Type: int
164 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700166 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
167 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800168 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
169 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700172 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173 // Type: boolean
174 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
175 // Type: long
176 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700177 // Type: int
178 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
179 // Type: int
180 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
181 // Type: parcelable
182 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100184 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700185 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100186 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700187 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100188 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700189
Adam Cohen39a06042013-07-19 14:30:12 -0700190 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700191 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700192
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700193 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700194 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700195 private State mState = State.WORKSPACE;
196 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700197
Joe Onorato9c1289c2009-08-17 11:03:03 -0400198 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700199 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
200 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chungaf40f202013-09-18 18:26:31 -0700201 private static final int SHOW_CLING_DURATION = 250;
202 private static final int DISMISS_CLING_DURATION = 200;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800203
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800205 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800206
Winson Chunga2413752012-04-03 14:22:34 -0700207 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700208 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
209 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700210 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700211
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800212 private final BroadcastReceiver mCloseSystemDialogsReceiver
213 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800214 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
215
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800216 private LayoutInflater mInflater;
217
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700219 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800220 private DragLayer mDragLayer;
221 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700222 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700223
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700224 private AppWidgetManager mAppWidgetManager;
225 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700226
Michael Jurkac9d95c52011-08-29 14:03:34 -0700227 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700228 private AppWidgetProviderInfo mPendingAddWidgetInfo;
229
Michael Jurka0280c3b2010-09-17 15:00:07 -0700230 private int[] mTmpAddItemCellCoordinates = new int[2];
231
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800232 private FolderInfo mFolderInfo;
233
Winson Chung3d503fb2011-07-13 17:25:49 -0700234 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700235 private View mOverviewPanel;
236
Michael Jurka838a4ca2011-02-07 13:33:06 -0800237 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700238
Winson Chungc51db6a2011-10-05 11:44:49 -0700239 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700240 private AppsCustomizeTabHost mAppsCustomizeTabHost;
241 private AppsCustomizePagedView mAppsCustomizeContent;
242 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100243 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800244
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800245 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700246 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
247 // scroll issues (because the workspace may not have been measured yet) and extra work.
248 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
249 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800250
251 private SpannableStringBuilder mDefaultKeySsb = null;
252
Joe Onorato9c1289c2009-08-17 11:03:03 -0400253 private boolean mWorkspaceLoading = true;
254
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800255 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800256 private boolean mRestoring;
257 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700258 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800259
Michael Jurka1e2f4652013-07-08 18:03:46 -0700260 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700261 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
262
Winson Chung4a2afa32012-07-19 14:53:05 -0700263 // Keep track of whether the user has left launcher
264 private static boolean sPausedFromUserAction = false;
265
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800266 private Bundle mSavedInstanceState;
267
Joe Onorato9c1289c2009-08-17 11:03:03 -0400268 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800269 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800270 private boolean mUserPresent = true;
271 private boolean mVisible = false;
272 private boolean mAttached = false;
Winson Chungfa545132013-09-26 17:45:32 -0700273 private static final boolean DISABLE_CLINGS = false;
Winson Chunge6eabff2013-09-24 11:01:23 -0700274 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400275
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700276 private static LocaleConfiguration sLocaleConfiguration = null;
277
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700278 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700279
Adam Cohen61f560d2013-09-30 15:58:20 -0700280 private View.OnTouchListener mHapticFeedbackTouchListener;
281
Adam Cohended9f8d2010-11-03 13:25:16 -0700282 // Related to the auto-advancing of widgets
283 private final int ADVANCE_MSG = 1;
284 private final int mAdvanceInterval = 20000;
285 private final int mAdvanceStagger = 250;
286 private long mAutoAdvanceSentTime;
287 private long mAutoAdvanceTimeLeft = -1;
288 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
289 new HashMap<View, AppWidgetProviderInfo>();
290
Winson Chung400438b2011-01-16 17:53:48 -0800291 // Determines how long to wait after a rotation before restoring the screen orientation to
292 // match the sensor state.
293 private final int mRestoreScreenOrientationDelay = 500;
294
Michael Jurka4ef207b2010-11-29 17:05:45 -0800295 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700296 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
297 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
298 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800299
Winson Chungd64a6662013-09-30 11:06:59 -0700300 private Intent mAppMarketIntent = null;
301 private static final boolean DISABLE_MARKET_BUTTON = true;
302
Craig Mautner360310b2012-10-26 15:13:08 -0700303 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700304
Adam Cohen1462de32012-07-24 22:34:36 -0700305 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
306
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700307 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700308 static Date sDateStamp = new Date();
309 static DateFormat sDateFormat =
310 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
311 static long sRunStart = System.currentTimeMillis();
312 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700313
Winson Chung46353de2012-02-16 14:05:10 -0800314 // We only want to get the SharedPreferences once since it does an FS stat each time we get
315 // it from the context.
316 private SharedPreferences mSharedPrefs;
317
Adam Cohene25af792013-06-06 23:08:25 -0700318 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
319
Winson Chungf0c6ae02012-03-21 16:10:31 -0700320 // Holds the page that we need to animate to, and the icon views that we need to animate up
321 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700322 private ImageView mFolderIconImageView;
323 private Bitmap mFolderIconBitmap;
324 private Canvas mFolderIconCanvas;
325 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700326
Michael Jurkaddd62e92011-02-16 17:49:14 -0800327 private BubbleTextView mWaitingForResume;
328
Michael Jurka7267fa52013-09-26 15:29:57 -0700329 protected TransparentBars mTransparentBars;
330
Michael Jurka22143132012-10-04 17:42:38 +0200331 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
332 = new HideFromAccessibilityHelper();
333
Michael Jurkac1f5d262011-09-30 19:32:27 -0700334 private Runnable mBuildLayersRunnable = new Runnable() {
335 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700336 if (mWorkspace != null) {
337 mWorkspace.buildPageHardwareLayers();
338 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700339 }
340 };
341
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800342 private static ArrayList<PendingAddArguments> sPendingAddList
343 = new ArrayList<PendingAddArguments>();
344
Michael Jurka7267fa52013-09-26 15:29:57 -0700345 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800346
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800347 private static class PendingAddArguments {
348 int requestCode;
349 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700350 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700351 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800352 int cellX;
353 int cellY;
354 }
355
Daniel Sandlerff02d492013-08-05 02:12:05 -0400356 private Stats mStats;
357
Michael Jurka0a457bf2012-11-19 14:05:05 -0800358 private static boolean isPropertyEnabled(String propertyName) {
359 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700360 }
361
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800362 @Override
363 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700364 if (DEBUG_STRICT_MODE) {
365 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
366 .detectDiskReads()
367 .detectDiskWrites()
368 .detectNetwork() // or .detectAll() for all detectable problems
369 .penaltyLog()
370 .build());
371 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
372 .detectLeakedSqlLiteObjects()
373 .detectLeakedClosableObjects()
374 .penaltyLog()
375 .penaltyDeath()
376 .build());
377 }
378
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800379 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400380
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400381 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400382 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700383
384 // Determine the dynamic grid properties
385 Point smallestSize = new Point();
386 Point largestSize = new Point();
387 Point realSize = new Point();
388 Display display = getWindowManager().getDefaultDisplay();
389 display.getCurrentSizeRange(smallestSize, largestSize);
390 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700391 DisplayMetrics dm = new DisplayMetrics();
392 display.getMetrics(dm);
Winson Chung5f8afe62013-08-12 16:19:28 -0700393 // Lazy-initialize the dynamic grid
394 DeviceProfile grid = app.initDynamicGrid(this,
395 Math.min(smallestSize.x, smallestSize.y),
396 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700397 realSize.x, realSize.y,
398 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700399
400 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400401 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700402 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800403 mModel = app.setLauncher(this);
404 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400405 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800406 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700407
Daniel Sandlerff02d492013-08-05 02:12:05 -0400408 mStats = new Stats(this);
409
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700410 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700411
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700412 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
413 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700414
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700415 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
416 // this also ensures that any synchronous binding below doesn't re-trigger another
417 // LauncherModel load.
418 mPaused = false;
419
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800420 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200421 android.os.Debug.startMethodTracing(
422 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800423 }
424
Adam Cohen53805212013-10-01 10:39:23 -0700425
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800426 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800427 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700428
429 mTransparentBars = new TransparentBars(findViewById(R.id.launcher));
430 mTransparentBars.requestTransparentBars(true);
431
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800432 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100433 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800434
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800435 registerContentObservers();
436
Joe Onorato7c312c12009-08-13 21:36:53 -0700437 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700438
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800439 mSavedState = savedInstanceState;
440 restoreState(mSavedState);
441
Winson Chunga12a2502010-12-20 14:41:35 -0800442 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700443 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200444 mAppsCustomizeContent.onPackagesUpdated(
445 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chung785d2eb2011-04-14 16:08:02 -0700446 }
Winson Chunga12a2502010-12-20 14:41:35 -0800447
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800448 if (PROFILE_STARTUP) {
449 android.os.Debug.stopMethodTracing();
450 }
451
452 if (!mRestoring) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700453 if (sPausedFromUserAction) {
454 // If the user leaves launcher, then we should just load items asynchronously when
455 // they return.
456 mModel.startLoader(true, -1);
457 } else {
458 // We only load the page synchronously if the user rotates (or triggers a
459 // configuration change) while launcher is in the foreground
460 mModel.startLoader(true, mWorkspace.getCurrentPage());
461 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800462 }
463
464 // For handling default keys
465 mDefaultKeySsb = new SpannableStringBuilder();
466 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800467
468 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
469 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800470
Adam Cohenf9426d52012-06-04 17:26:21 -0700471 updateGlobalIcons();
472
473 // On large interfaces, we want the screen to auto-rotate based on the current orientation
474 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700475
476 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700477 }
478
Winson Chung4a2afa32012-07-19 14:53:05 -0700479 protected void onUserLeaveHint() {
480 super.onUserLeaveHint();
481 sPausedFromUserAction = true;
482 }
483
Winson Chung98ca0f72013-07-29 12:58:51 -0700484 /** To be overriden by subclasses to hint to Launcher that we have custom content */
485 protected boolean hasCustomContentToLeft() {
486 return false;
487 }
488
Dave Hawkeya8881582013-09-17 15:55:33 -0600489 /**
490 * To be overridden by subclasses to create the custom content and call
491 * {@link #addToCustomContentPage}. This will only be invoked if
492 * {@link #hasCustomContentToLeft()} is {@code true}.
493 */
494 protected void addCustomContentToLeft() {
495 }
496
497 /**
498 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
499 * ensure the custom content page is added or removed if necessary.
500 */
501 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600502 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600503 // Not bound yet, wait for bindScreens to be called.
504 return;
505 }
506
507 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
508 // Create the custom content page and call the subclass to populate it.
509 mWorkspace.createCustomContentPage();
510 addCustomContentToLeft();
511 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
512 mWorkspace.removeCustomContentPage();
513 }
514 }
515
Adam Cohenf9426d52012-06-04 17:26:21 -0700516 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700517 boolean searchVisible = false;
518 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800519 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700520 int coi = getCurrentOrientationIndexForGlobalIcons();
521 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
522 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700523 if (!DISABLE_MARKET_BUTTON) {
524 updateAppMarketIcon();
525 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700526 searchVisible = updateGlobalSearchIcon();
527 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700528 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700529 if (sGlobalSearchIcon[coi] != null) {
530 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700531 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700532 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700533 if (sVoiceSearchIcon[coi] != null) {
534 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700535 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700536 }
Winson Chungd64a6662013-09-30 11:06:59 -0700537 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700538 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800539 }
Winson Chungadf0c182012-08-23 14:59:07 -0700540 if (mSearchDropTargetBar != null) {
541 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
542 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800543 }
Romain Guycbb89e42009-06-08 15:52:54 -0700544
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800545 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700546 if (sLocaleConfiguration == null) {
547 new AsyncTask<Void, Void, LocaleConfiguration>() {
548 @Override
549 protected LocaleConfiguration doInBackground(Void... unused) {
550 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
551 readConfiguration(Launcher.this, localeConfiguration);
552 return localeConfiguration;
553 }
554
555 @Override
556 protected void onPostExecute(LocaleConfiguration result) {
557 sLocaleConfiguration = result;
558 checkForLocaleChange(); // recursive, but now with a locale configuration
559 }
560 }.execute();
561 return;
562 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700563
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564 final Configuration configuration = getResources().getConfiguration();
565
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700566 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800567 final String locale = configuration.locale.toString();
568
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700569 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800570 final int mcc = configuration.mcc;
571
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700572 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800573 final int mnc = configuration.mnc;
574
Romain Guy84f296c2009-11-04 15:00:44 -0800575 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800576
Romain Guy84f296c2009-11-04 15:00:44 -0800577 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700578 sLocaleConfiguration.locale = locale;
579 sLocaleConfiguration.mcc = mcc;
580 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700581
Joe Onorato0589f0f2010-02-08 13:44:00 -0800582 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700583
584 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
585 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700586 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700587 public void run() {
588 writeConfiguration(Launcher.this, localeConfiguration);
589 }
590 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700591 }
592 }
593
594 private static class LocaleConfiguration {
595 public String locale;
596 public int mcc = -1;
597 public int mnc = -1;
598 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700599
Romain Guy98d01652009-06-30 16:21:04 -0700600 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
601 DataInputStream in = null;
602 try {
603 in = new DataInputStream(context.openFileInput(PREFERENCES));
604 configuration.locale = in.readUTF();
605 configuration.mcc = in.readInt();
606 configuration.mnc = in.readInt();
607 } catch (FileNotFoundException e) {
608 // Ignore
609 } catch (IOException e) {
610 // Ignore
611 } finally {
612 if (in != null) {
613 try {
614 in.close();
615 } catch (IOException e) {
616 // Ignore
617 }
618 }
619 }
620 }
621
622 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
623 DataOutputStream out = null;
624 try {
625 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
626 out.writeUTF(configuration.locale);
627 out.writeInt(configuration.mcc);
628 out.writeInt(configuration.mnc);
629 out.flush();
630 } catch (FileNotFoundException e) {
631 // Ignore
632 } catch (IOException e) {
633 //noinspection ResultOfMethodCallIgnored
634 context.getFileStreamPath(PREFERENCES).delete();
635 } finally {
636 if (out != null) {
637 try {
638 out.close();
639 } catch (IOException e) {
640 // Ignore
641 }
642 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800643 }
644 }
645
Anton Hanssona2f665f2013-09-26 12:18:32 +0100646 public Stats getStats() {
647 return mStats;
648 }
649
Bjorn Bringertc459e522013-06-07 19:36:01 +0100650 public LayoutInflater getInflater() {
651 return mInflater;
652 }
653
Adam Cohen716b51e2011-06-30 12:09:54 -0700654 public DragLayer getDragLayer() {
655 return mDragLayer;
656 }
657
Winson Chung36a62fe2012-05-06 18:04:42 -0700658 boolean isDraggingEnabled() {
659 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
660 // that is subsequently removed from the workspace in startBinding().
661 return !mModel.isLoadingWorkspace();
662 }
663
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800664 static int getScreen() {
665 synchronized (sLock) {
666 return sScreen;
667 }
668 }
669
670 static void setScreen(int screen) {
671 synchronized (sLock) {
672 sScreen = screen;
673 }
674 }
675
Winson Chung557d6ed2011-07-08 15:34:52 -0700676 /**
677 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
678 * a configuration step, this allows the proper animations to run after other transitions.
679 */
680 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700681 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800682 switch (args.requestCode) {
683 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700684 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700685 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800686 break;
687 case REQUEST_PICK_SHORTCUT:
688 processShortcut(args.intent);
689 break;
690 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700691 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700692 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700693 result = true;
694 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800695 case REQUEST_CREATE_APPWIDGET:
696 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700697 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700698 result = true;
699 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800700 }
Michael Jurka27614d22012-04-02 06:40:22 -0700701 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
702 // if you turned the screen off and then back while in All Apps, Launcher would not
703 // return to the workspace. Clearing mAddInfo.container here fixes this issue
704 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700705 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800706 }
707
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800708 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700709 protected void onActivityResult(
710 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700711 // Reset the startActivity waiting flag
712 mWaitingForResult = false;
713
Michael Jurka8b805b12012-04-18 14:23:14 -0700714 if (requestCode == REQUEST_BIND_APPWIDGET) {
715 int appWidgetId = data != null ?
716 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
717 if (resultCode == RESULT_CANCELED) {
718 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
719 } else if (resultCode == RESULT_OK) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700720 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
Michael Jurka8b805b12012-04-18 14:23:14 -0700721 }
722 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200723 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
724 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
725 mWorkspace.exitOverviewMode(false);
726 }
727 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700728 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200729
Winson Chung557d6ed2011-07-08 15:34:52 -0700730 boolean delayExitSpringLoadedMode = false;
Adam Cohened66b2b2012-01-23 17:28:51 -0800731 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
732 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700733
Adam Cohened66b2b2012-01-23 17:28:51 -0800734 // We have special handling for widgets
735 if (isWidgetDrop) {
736 int appWidgetId = data != null ?
737 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
Winson Chung5aaab772012-04-27 15:24:02 -0700738 if (appWidgetId < 0) {
739 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
740 "widget configuration activity.");
741 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
742 } else {
743 completeTwoStageWidgetDrop(resultCode, appWidgetId);
744 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800745 return;
746 }
747
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800748 // The pattern used here is that a user PICKs a specific application,
749 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700750
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800751 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
752 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700753 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800754 final PendingAddArguments args = new PendingAddArguments();
755 args.requestCode = requestCode;
756 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700757 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700758 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700759 args.cellX = mPendingAddInfo.cellX;
760 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800761 if (isWorkspaceLocked()) {
762 sPendingAddList.add(args);
763 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700764 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800765 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800766 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800767 mDragLayer.clearAnimatedView();
Winson Chung557d6ed2011-07-08 15:34:52 -0700768 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Adam Cohened66b2b2012-01-23 17:28:51 -0800769 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode,
770 null);
771 }
772
773 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700774 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700775 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800776 Runnable onCompleteRunnable = null;
777 int animationType = 0;
778
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700779 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800780 if (resultCode == RESULT_OK) {
781 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
782 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700783 mPendingAddWidgetInfo);
784 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800785 onCompleteRunnable = new Runnable() {
786 @Override
787 public void run() {
788 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700789 mPendingAddInfo.screenId, layout, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800790 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
791 null);
792 }
793 };
794 } else if (resultCode == RESULT_CANCELED) {
795 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
796 onCompleteRunnable = new Runnable() {
797 @Override
798 public void run() {
799 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false,
800 null);
801 }
802 };
803 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700804 if (mDragLayer.getAnimatedView() != null) {
805 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
806 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
807 animationType, boundWidget, true);
808 } else {
809 // The animated view may be null in the case of a rotation during widget configuration
810 onCompleteRunnable.run();
811 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800812 }
813
814 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700815 protected void onStop() {
816 super.onStop();
817 FirstFrameAnimatorHelper.setIsVisible(false);
818 }
819
820 @Override
821 protected void onStart() {
822 super.onStart();
823 FirstFrameAnimatorHelper.setIsVisible(true);
824 }
825
826 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800827 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200828 long startTime = 0;
829 if (DEBUG_RESUME_TIME) {
830 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400831 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200832 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800833 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700834
Winson Chung4a2afa32012-07-19 14:53:05 -0700835 // Restore the previous launcher state
836 if (mOnResumeState == State.WORKSPACE) {
837 showWorkspace(false);
838 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chungc58497e2013-09-03 17:48:37 -0700839 showAllApps(false, AppsCustomizePagedView.ContentType.Applications);
Winson Chung4a2afa32012-07-19 14:53:05 -0700840 }
841 mOnResumeState = State.NONE;
842
Craig Mautner360310b2012-10-26 15:13:08 -0700843 // Background was set to gradient in onPause(), restore to black if in all apps.
844 setWorkspaceBackground(mState == State.WORKSPACE);
845
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800846 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700847 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700848 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400849 mWorkspaceLoading = true;
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700850 mModel.startLoader(true, -1);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400851 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700852 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800853 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700854 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200855 // We might have postponed some bind calls until onResume (see waitUntilResume) --
856 // execute them here
857 long startTimeCallbacks = 0;
858 if (DEBUG_RESUME_TIME) {
859 startTimeCallbacks = System.currentTimeMillis();
860 }
861
862 if (mAppsCustomizeContent != null) {
863 mAppsCustomizeContent.setBulkBind(true);
864 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700865 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
866 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200867 }
868 if (mAppsCustomizeContent != null) {
869 mAppsCustomizeContent.setBulkBind(false);
870 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700871 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200872 if (DEBUG_RESUME_TIME) {
873 Log.d(TAG, "Time spent processing callbacks in onResume: " +
874 (System.currentTimeMillis() - startTimeCallbacks));
875 }
Michael Jurka447bf842013-05-15 14:52:15 +0200876 }
Michael Jurka54554252013-08-01 12:52:23 +0200877 if (mOnResumeCallbacks.size() > 0) {
878 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
879 mOnResumeCallbacks.get(i).run();
880 }
881 mOnResumeCallbacks.clear();
882 }
Winson Chunge4e50662012-01-23 14:45:13 -0800883
884 // Reset the pressed state of icons that were locked in the press state while activities
885 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800886 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800887 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800888 mWaitingForResume.setStayPressed(false);
889 }
Winson Chunge4e50662012-01-23 14:45:13 -0800890 if (mAppsCustomizeContent != null) {
891 // Resets the previous all apps icon press state
892 mAppsCustomizeContent.resetDrawableState();
893 }
Winson Chung780fe592013-09-26 14:48:44 -0700894 // Reset AllApps to its initial state
895 if (mAppsCustomizeTabHost != null) {
896 mAppsCustomizeTabHost.reset();
897 }
Adam Cohen06dff352012-06-01 17:17:08 -0700898 // It is possible that widgets can receive updates while launcher is not in the foreground.
899 // Consequently, the widgets will be inflated in the orientation of the foreground activity
900 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
901 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700902 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700903
Winson Chung780fe592013-09-26 14:48:44 -0700904 // Process any items that were added while Launcher was away.
905 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
906
Winson Chung5841efa2013-09-30 18:06:44 -0700907 // Update the voice search button proxy
908 updateVoiceButtonProxyVisible(false);
909
Adam Cohenf9426d52012-06-04 17:26:21 -0700910 // Again, as with the above scenario, it's possible that one or more of the global icons
911 // were updated in the wrong orientation.
912 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200913 if (DEBUG_RESUME_TIME) {
914 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
915 }
Adam Cohen6fecd412013-10-02 17:41:50 -0700916
917 if (mWorkspace.getCustomContentCallbacks() != null) {
918 // If we are resuming and the custom content is the current page, we call onShow().
919 // It is also poassible that onShow will instead be called slightly after first layout
920 // if PagedView#setRestorePage was set to the custom content page in onCreate().
921 if (mWorkspace.isOnOrMovingToCustomContent()) {
922 mWorkspace.getCustomContentCallbacks().onShow();
923 }
924 }
Adam Cohenedaaa302013-10-01 17:33:27 -0700925 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -0700926 mWorkspace.onResume();
Adam Cohen06dff352012-06-01 17:17:08 -0700927 }
928
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800929 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700930 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700931 // Ensure that items added to Launcher are queued until Launcher returns
932 InstallShortcutReceiver.enableInstallQueue();
933
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700934 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700935 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800936 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -0700937 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -0700938
939 // We call onHide() aggressively. The custom content callbacks should be able to
940 // debounce excess onHide calls.
941 if (mWorkspace.getCustomContentCallbacks() != null) {
942 mWorkspace.getCustomContentCallbacks().onHide();
943 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700944 }
Romain Guycbb89e42009-06-08 15:52:54 -0700945
Adam Cohen66a01fd2013-06-11 12:48:00 -0700946 protected void onFinishBindingItems() {
Adam Cohen82398362013-09-29 12:57:34 -0700947 if (mWorkspace != null && hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600948 addCustomContentToLeft();
949 }
Adam Cohen66a01fd2013-06-11 12:48:00 -0700950 }
951
Adam Cohenbffe7452013-07-22 18:21:45 -0700952 QSBScroller mQsbScroller = new QSBScroller() {
953 int scrollY = 0;
954
955 @Override
956 public void setScrollY(int scroll) {
957 scrollY = scroll;
958
959 if (mWorkspace.isOnOrMovingToCustomContent()) {
960 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +0100961 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -0700962 }
963 }
964 };
965
966 public void resetQSBScroll() {
967 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +0100968 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -0700969 }
970
971 public interface CustomContentCallbacks {
972 // Custom content is completely shown
973 public void onShow();
974
975 // Custom content is completely hidden
976 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -0700977
978 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
979 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -0700980 }
981
Adam Cohen30bacb22013-08-29 14:25:25 -0700982 protected void startSettings() {
983 }
984
Adam Cohenbffe7452013-07-22 18:21:45 -0700985 public interface QSBScroller {
986 public void setScrollY(int scrollY);
987 }
988
Winson Chung98ca0f72013-07-29 12:58:51 -0700989 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -0700990 CustomContentCallbacks callbacks, String description) {
991 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -0700992 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -0700993 }
994
Adam Cohenedb40762013-07-18 16:45:45 -0700995 // The custom content needs to offset its content to account for the QSB
996 public int getTopOffsetForCustomContent() {
997 return mWorkspace.getPaddingTop();
998 }
999
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001000 @Override
1001 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001002 // Flag the loader to stop early before switching
1003 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001004 if (mAppsCustomizeContent != null) {
1005 mAppsCustomizeContent.surrender();
1006 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001007 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001008 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001009
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001010 // We can't hide the IME if it was forced open. So don't bother
1011 /*
1012 @Override
1013 public void onWindowFocusChanged(boolean hasFocus) {
1014 super.onWindowFocusChanged(hasFocus);
1015
1016 if (hasFocus) {
1017 final InputMethodManager inputManager = (InputMethodManager)
1018 getSystemService(Context.INPUT_METHOD_SERVICE);
1019 WindowManager.LayoutParams lp = getWindow().getAttributes();
1020 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
1021 android.os.Handler()) {
1022 protected void onReceiveResult(int resultCode, Bundle resultData) {
1023 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
1024 }
1025 });
1026 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
1027 }
1028 }
1029 */
1030
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001031 private boolean acceptFilter() {
1032 final InputMethodManager inputManager = (InputMethodManager)
1033 getSystemService(Context.INPUT_METHOD_SERVICE);
1034 return !inputManager.isFullscreenMode();
1035 }
1036
1037 @Override
1038 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001039 final int uniChar = event.getUnicodeChar();
1040 final boolean handled = super.onKeyDown(keyCode, event);
1041 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1042 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001043 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1044 keyCode, event);
1045 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001046 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001047 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001048 // showSearchDialog()
1049 // If there are multiple keystrokes before the search dialog takes focus,
1050 // onSearchRequested() will be called for every keystroke,
1051 // but it is idempotent, so it's fine.
1052 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001053 }
1054 }
1055
Joe Onorato8a9625e2010-01-28 15:55:35 -08001056 // Eat the long press event so the keyboard doesn't come up.
1057 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1058 return true;
1059 }
1060
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001061 return handled;
1062 }
1063
Karl Rosaen138a0412009-04-23 19:00:21 -07001064 private String getTypedText() {
1065 return mDefaultKeySsb.toString();
1066 }
1067
1068 private void clearTypedText() {
1069 mDefaultKeySsb.clear();
1070 mDefaultKeySsb.clearSpans();
1071 Selection.setSelection(mDefaultKeySsb, 0);
1072 }
1073
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001074 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001075 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1076 * State
1077 */
1078 private static State intToState(int stateOrdinal) {
1079 State state = State.WORKSPACE;
1080 final State[] stateValues = State.values();
1081 for (int i = 0; i < stateValues.length; i++) {
1082 if (stateValues[i].ordinal() == stateOrdinal) {
1083 state = stateValues[i];
1084 break;
1085 }
1086 }
1087 return state;
1088 }
1089
1090 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001091 * Restores the previous state, if it exists.
1092 *
1093 * @param savedState The previous state.
1094 */
1095 private void restoreState(Bundle savedState) {
1096 if (savedState == null) {
1097 return;
1098 }
1099
Michael Jurka883f55b2010-10-21 15:47:14 -07001100 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001101 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001102 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001103 }
1104
Winson Chungf0c6ae02012-03-21 16:10:31 -07001105 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001106 if (currentScreen > -1) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001107 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001108 }
1109
Winson Chung3d503fb2011-07-13 17:25:49 -07001110 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001111 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001112
Winson Chung3d503fb2011-07-13 17:25:49 -07001113 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1114 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001115 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001116 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1117 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001118 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1119 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1120 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001121 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001122 mRestoring = true;
1123 }
1124
1125 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1126 if (renameFolder) {
1127 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001128 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001129 mRestoring = true;
1130 }
Winson Chunga12a2502010-12-20 14:41:35 -08001131
Winson Chung785d2eb2011-04-14 16:08:02 -07001132 // Restore the AppsCustomize tab
1133 if (mAppsCustomizeTabHost != null) {
1134 String curTab = savedState.getString("apps_customize_currentTab");
1135 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001136 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001137 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001138 mAppsCustomizeContent.loadAssociatedPages(
1139 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001140 }
1141
Winson Chung5afbf7b2011-07-25 11:53:08 -07001142 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1143 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001144 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001145 }
1146
1147 /**
1148 * Finds all the views we need and configure them properly.
1149 */
1150 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001151 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001152
Craig Mautner360310b2012-10-26 15:13:08 -07001153 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001154 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1155 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001156
John Spurlock77e1f472013-09-11 10:09:51 -04001157 mLauncherView.setSystemUiVisibility(
1158 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001159 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001160
Winson Chung4c98d922011-05-31 16:50:48 -07001161 // Setup the drag layer
1162 mDragLayer.setup(this, dragController);
1163
Winson Chung3d503fb2011-07-13 17:25:49 -07001164 // Setup the hotseat
1165 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1166 if (mHotseat != null) {
1167 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001168 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001169 }
1170
Adam Cohenf358a4b2013-07-23 16:47:31 -07001171 mOverviewPanel = findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001172 View widgetButton = findViewById(R.id.widget_button);
1173 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001174 @Override
1175 public void onClick(View arg0) {
Winson Chungc58497e2013-09-03 17:48:37 -07001176 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001177 }
1178 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001179 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1180
1181 View wallpaperButton = findViewById(R.id.wallpaper_button);
1182 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001183 @Override
1184 public void onClick(View arg0) {
1185 startWallpaper();
1186 }
1187 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001188 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1189
1190 View settingsButton = findViewById(R.id.settings_button);
1191 settingsButton.setOnClickListener(new OnClickListener() {
Adam Cohen30bacb22013-08-29 14:25:25 -07001192 @Override
1193 public void onClick(View arg0) {
1194 startSettings();
1195 }
1196 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001197 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
Adam Cohendbdff6b2013-09-18 19:09:15 -07001198 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001199
Winson Chung4c98d922011-05-31 16:50:48 -07001200 // Setup the workspace
1201 mWorkspace.setHapticFeedbackEnabled(false);
1202 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001203 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001204 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001205
Winson Chungf0ea4d32011-06-06 14:27:16 -07001206 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001207 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001208
Winson Chungf0ea4d32011-06-06 14:27:16 -07001209 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001210 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001211 mAppsCustomizeContent = (AppsCustomizePagedView)
1212 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1213 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001214
Winson Chung3d503fb2011-07-13 17:25:49 -07001215 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001216 dragController.setDragScoller(mWorkspace);
1217 dragController.setScrollView(mDragLayer);
1218 dragController.setMoveTarget(mWorkspace);
1219 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001220 if (mSearchDropTargetBar != null) {
1221 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001222 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001223
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001224 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001225 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001226 mWeightWatcher = new WeightWatcher(this);
1227 mWeightWatcher.setAlpha(0.5f);
1228 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001229 new FrameLayout.LayoutParams(
1230 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001231 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001232 Gravity.BOTTOM)
1233 );
Adam Cohen39a06042013-07-19 14:30:12 -07001234
1235 boolean show = shouldShowWeightWatcher();
1236 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001237 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001238 }
1239
1240 /**
1241 * Creates a view representing a shortcut.
1242 *
1243 * @param info The data structure describing the shortcut.
1244 *
1245 * @return A View inflated from R.layout.application.
1246 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001247 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001248 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001249 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001250 }
1251
1252 /**
1253 * Creates a view representing a shortcut inflated from the specified resource.
1254 *
1255 * @param layoutResId The id of the XML layout used to create the shortcut.
1256 * @param parent The group the shortcut belongs to.
1257 * @param info The data structure describing the shortcut.
1258 *
1259 * @return A View inflated from layoutResId.
1260 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001261 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001262 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1263 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001264 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265 return favorite;
1266 }
1267
1268 /**
1269 * Add an application shortcut to the workspace.
1270 *
1271 * @param data The intent describing the application.
1272 * @param cellInfo The position on screen where to create the shortcut.
1273 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001274 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001275 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001276 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001277
Adam Cohenfbba09b2011-07-18 21:43:05 -07001278 // First we check if we already know the exact location where we want to add this item.
1279 if (cellX >= 0 && cellY >= 0) {
1280 cellXY[0] = cellX;
1281 cellXY[1] = cellY;
1282 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001283 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001284 return;
1285 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001286
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001287 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001288
Romain Guy73b979d2009-06-09 12:57:21 -07001289 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001290 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001291 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001292 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001293 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001294 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001295 } else {
1296 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001297 }
1298 }
Romain Guycbb89e42009-06-08 15:52:54 -07001299
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001300 /**
1301 * Add a shortcut to the workspace.
1302 *
1303 * @param data The intent describing the shortcut.
1304 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001305 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001306 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001307 int cellY) {
1308 int[] cellXY = mTmpAddItemCellCoordinates;
1309 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001310 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001311
Michael Jurkad3ef3062010-11-23 16:23:58 -08001312 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001313
Adam Cohen558baaf2011-08-15 15:22:57 -07001314 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001315 if (info == null) {
1316 return;
1317 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001318 final View view = createShortcut(info);
1319
Adam Cohenfbba09b2011-07-18 21:43:05 -07001320 // First we check if we already know the exact location where we want to add this item.
1321 if (cellX >= 0 && cellY >= 0) {
1322 cellXY[0] = cellX;
1323 cellXY[1] = cellY;
1324 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001325
1326 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001327 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001328 true, null,null)) {
1329 return;
1330 }
1331 DragObject dragObject = new DragObject();
1332 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001333 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1334 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001335 return;
1336 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001337 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001338 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001339 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001340 foundCellSpan = (result != null);
1341 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001342 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001343 }
1344
1345 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001346 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001347 return;
1348 }
1349
Adam Cohendcd297f2013-06-18 13:13:40 -07001350 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001351
1352 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001353 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001354 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001355 }
1356 }
1357
Adam Cohen2f093b62012-04-30 18:59:53 -07001358 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1359 int minHeight) {
1360 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001361 // We want to account for the extra amount of padding that we are adding to the widget
1362 // to ensure that it gets the full amount of space that it has requested
1363 int requiredWidth = minWidth + padding.left + padding.right;
1364 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001365 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001366 }
1367
Adam Cohen2f093b62012-04-30 18:59:53 -07001368 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1369 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001370 }
1371
Adam Cohen2f093b62012-04-30 18:59:53 -07001372 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1373 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001374 }
1375
Adam Cohen2f093b62012-04-30 18:59:53 -07001376 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1377 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001378 }
1379
Adam Cohen2f093b62012-04-30 18:59:53 -07001380 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1381 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001382 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001383 }
1384
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001385 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001386 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001387 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001388 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001389 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001390 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001391 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001392 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1393 if (appWidgetInfo == null) {
1394 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1395 }
Romain Guycbb89e42009-06-08 15:52:54 -07001396
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001397 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001398 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001399
Adam Cohen2f093b62012-04-30 18:59:53 -07001400 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1401 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001402
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001403 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001404 // We have saved the position to which the widget was dragged-- this really only matters
1405 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001406 int[] cellXY = mTmpAddItemCellCoordinates;
1407 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001408 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001409 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001410 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1411 cellXY[0] = mPendingAddInfo.cellX;
1412 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001413 spanXY[0] = mPendingAddInfo.spanX;
1414 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001415 foundCellSpan = true;
1416 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001417 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001418 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001419 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1420 spanXY[1], cellXY, finalSpan);
1421 spanXY[0] = finalSpan[0];
1422 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001423 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001424 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001425 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001426 }
1427
Michael Jurka0280c3b2010-09-17 15:00:07 -07001428 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001429 if (appWidgetId != -1) {
1430 // Deleting an app widget ID is a void call but writes to disk before returning
1431 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -08001432 new Thread("deleteAppWidgetId") {
1433 public void run() {
1434 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1435 }
1436 }.start();
1437 }
Winson Chung93eef082012-03-23 15:59:27 -07001438 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001439 return;
1440 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001441
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001442 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001443 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1444 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001445 launcherInfo.spanX = spanXY[0];
1446 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001447 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1448 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001449
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001450 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001451 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001452
1453 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001454 if (hostView == null) {
1455 // Perform actual inflation because we're live
1456 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1457 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1458 } else {
1459 // The AppWidgetHostView has already been inflated and instantiated
1460 launcherInfo.hostView = hostView;
1461 }
Romain Guycbb89e42009-06-08 15:52:54 -07001462
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001463 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001464 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001465 launcherInfo.notifyWidgetSizeChanged(this);
1466
Adam Cohendcd297f2013-06-18 13:13:40 -07001467 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001468 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001469
1470 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001471 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001472 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001473 }
Romain Guycbb89e42009-06-08 15:52:54 -07001474
Adam Cohended9f8d2010-11-03 13:25:16 -07001475 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1476 @Override
1477 public void onReceive(Context context, Intent intent) {
1478 final String action = intent.getAction();
1479 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1480 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001481 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001482 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001483
Winson Chungc100e8e2011-08-09 16:02:43 -07001484 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001485 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001486 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001487 showWorkspaceAndExitOverviewMode(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001488 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001489 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1490 mUserPresent = true;
1491 updateRunning();
1492 }
1493 }
1494 };
1495
1496 @Override
1497 public void onAttachedToWindow() {
1498 super.onAttachedToWindow();
1499
1500 // Listen for broadcasts related to user-presence
1501 final IntentFilter filter = new IntentFilter();
1502 filter.addAction(Intent.ACTION_SCREEN_OFF);
1503 filter.addAction(Intent.ACTION_USER_PRESENT);
1504 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001505 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001506 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001507 mVisible = true;
1508 }
1509
1510 @Override
1511 public void onDetachedFromWindow() {
1512 super.onDetachedFromWindow();
1513 mVisible = false;
1514
Adam Cohend113e0c2010-11-11 10:48:05 -08001515 if (mAttached) {
1516 unregisterReceiver(mReceiver);
1517 mAttached = false;
1518 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001519 updateRunning();
1520 }
1521
1522 public void onWindowVisibilityChanged(int visibility) {
1523 mVisible = visibility == View.VISIBLE;
1524 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001525 // The following code used to be in onResume, but it turns out onResume is called when
1526 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1527 // is a more appropriate event to handle
1528 if (mVisible) {
1529 mAppsCustomizeTabHost.onWindowVisible();
1530 if (!mWorkspaceLoading) {
1531 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001532 // We want to let Launcher draw itself at least once before we force it to build
1533 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001534 // apps is nice and speedy.
1535 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001536 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001537 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001538 if (mStarted) return;
1539 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001540 // We delay the layer building a bit in order to give
1541 // other message processing a time to run. In particular
1542 // this avoids a delay in hiding the IME if it was
1543 // currently shown, because doing that may involve
1544 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001545 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001546 final ViewTreeObserver.OnDrawListener listener = this;
1547 mWorkspace.post(new Runnable() {
1548 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001549 if (mWorkspace != null &&
1550 mWorkspace.getViewTreeObserver() != null) {
1551 mWorkspace.getViewTreeObserver().
1552 removeOnDrawListener(listener);
1553 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001554 }
1555 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001556 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001557 }
1558 });
1559 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001560 // When Launcher comes back to foreground, a different Activity might be responsible for
1561 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001562 if (!DISABLE_MARKET_BUTTON) {
1563 updateAppMarketIcon();
1564 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001565 clearTypedText();
1566 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001567 }
1568
1569 private void sendAdvanceMessage(long delay) {
1570 mHandler.removeMessages(ADVANCE_MSG);
1571 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1572 mHandler.sendMessageDelayed(msg, delay);
1573 mAutoAdvanceSentTime = System.currentTimeMillis();
1574 }
1575
1576 private void updateRunning() {
1577 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1578 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1579 mAutoAdvanceRunning = autoAdvanceRunning;
1580 if (autoAdvanceRunning) {
1581 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1582 sendAdvanceMessage(delay);
1583 } else {
1584 if (!mWidgetsToAdvance.isEmpty()) {
1585 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1586 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1587 }
1588 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001589 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001590 }
1591 }
1592 }
1593
1594 private final Handler mHandler = new Handler() {
1595 @Override
1596 public void handleMessage(Message msg) {
1597 if (msg.what == ADVANCE_MSG) {
1598 int i = 0;
1599 for (View key: mWidgetsToAdvance.keySet()) {
1600 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1601 final int delay = mAdvanceStagger * i;
1602 if (v instanceof Advanceable) {
1603 postDelayed(new Runnable() {
1604 public void run() {
1605 ((Advanceable) v).advance();
1606 }
1607 }, delay);
1608 }
1609 i++;
1610 }
1611 sendAdvanceMessage(mAdvanceInterval);
1612 }
1613 }
1614 };
1615
1616 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001617 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001618 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1619 if (v instanceof Advanceable) {
1620 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001621 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001622 updateRunning();
1623 }
1624 }
1625
1626 void removeWidgetToAutoAdvance(View hostView) {
1627 if (mWidgetsToAdvance.containsKey(hostView)) {
1628 mWidgetsToAdvance.remove(hostView);
1629 updateRunning();
1630 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001631 }
1632
Joe Onorato9c1289c2009-08-17 11:03:03 -04001633 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001634 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001635 launcherInfo.hostView = null;
1636 }
1637
Winson Chung93eef082012-03-23 15:59:27 -07001638 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1639 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1640 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001641 }
1642
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001643 public LauncherAppWidgetHost getAppWidgetHost() {
1644 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001645 }
Romain Guycbb89e42009-06-08 15:52:54 -07001646
Winson Chunga9abd0e2010-10-27 17:18:37 -07001647 public LauncherModel getModel() {
1648 return mModel;
1649 }
1650
Bjorn Bringertc459e522013-06-07 19:36:01 +01001651 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001652 getWindow().closeAllPanels();
1653
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001654 // Whatever we were doing is hereby canceled.
1655 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001656 }
1657
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001658 @Override
1659 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001660 long startTime = 0;
1661 if (DEBUG_RESUME_TIME) {
1662 startTime = System.currentTimeMillis();
1663 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001664 super.onNewIntent(intent);
1665
1666 // Close the menu
1667 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001668 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001669 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001670
Jamie Genniscb222e82012-10-23 15:44:26 -07001671 final boolean alreadyOnHome =
1672 ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
Joe Onorato14f122b2009-11-19 14:06:36 -08001673 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001674
Adam Cohen6fecd412013-10-02 17:41:50 -07001675 if (mWorkspace == null) {
1676 // Can be cases where mWorkspace is null, this prevents a NPE
1677 return;
1678 }
1679 Folder openFolder = mWorkspace.getOpenFolder();
1680 // In all these cases, only animate if we're already on home
1681 mWorkspace.exitWidgetResizeMode();
1682 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1683 openFolder == null) {
1684 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001685 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001686
Adam Cohen6fecd412013-10-02 17:41:50 -07001687 closeFolder();
1688 exitSpringLoadedDragMode();
1689
1690 // If we are already on home, then just animate back to the workspace,
1691 // otherwise, just wait until onResume to set the state back to Workspace
1692 if (alreadyOnHome) {
1693 showWorkspaceAndExitOverviewMode(true);
1694 } else {
1695 mOnResumeState = State.WORKSPACE;
1696 }
1697
1698 final View v = getWindow().peekDecorView();
1699 if (v != null && v.getWindowToken() != null) {
1700 InputMethodManager imm = (InputMethodManager)getSystemService(
1701 INPUT_METHOD_SERVICE);
1702 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1703 }
1704
1705 // Reset the apps customize page
1706 if (mAppsCustomizeTabHost != null) {
1707 mAppsCustomizeTabHost.reset();
1708 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001709 }
Michael Jurka447bf842013-05-15 14:52:15 +02001710 if (DEBUG_RESUME_TIME) {
1711 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1712 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001713 }
1714
Adam Cohen040a5d22013-09-16 17:09:33 -07001715 protected void showWorkspaceAndExitOverviewMode(boolean animate) {
1716 showWorkspace(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001717 if (mWorkspace.isInOverviewMode()) {
Adam Cohen040a5d22013-09-16 17:09:33 -07001718 mWorkspace.exitOverviewMode(animate);
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001719 }
1720 }
Adam Cohen040a5d22013-09-16 17:09:33 -07001721 protected void showWorkspaceAndExitOverviewMode() {
Allan Wojciechowskifdc43022013-10-02 11:13:17 -04001722 showWorkspaceAndExitOverviewMode(false);
Adam Cohen040a5d22013-09-16 17:09:33 -07001723 }
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001724
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001725 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001726 public void onRestoreInstanceState(Bundle state) {
1727 super.onRestoreInstanceState(state);
1728 for (int page: mSynchronouslyBoundPages) {
1729 mWorkspace.restoreInstanceStateForChild(page);
1730 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001731 }
1732
1733 @Override
1734 protected void onSaveInstanceState(Bundle outState) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001735 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001736 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001737
Michael Jurka883f55b2010-10-21 15:47:14 -07001738 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001739 // We close any open folder since it will not be re-opened, and we need to make sure
1740 // this state is reflected.
1741 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001742
Adam Cohendcd297f2013-06-18 13:13:40 -07001743 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001744 mWaitingForResult) {
1745 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001746 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001747 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1748 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001749 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1750 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1751 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001752 }
1753
1754 if (mFolderInfo != null && mWaitingForResult) {
1755 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1756 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1757 }
Michael Jurka946ad472010-07-09 18:05:18 -07001758
Winson Chung785d2eb2011-04-14 16:08:02 -07001759 // Save the current AppsCustomize tab
1760 if (mAppsCustomizeTabHost != null) {
1761 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1762 if (currentTabTag != null) {
1763 outState.putString("apps_customize_currentTab", currentTabTag);
1764 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001765 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1766 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001767 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001768 }
1769
1770 @Override
1771 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001772 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001773
Winson Chunge7a03942011-08-05 15:05:12 -07001774 // Remove all pending runnables
1775 mHandler.removeMessages(ADVANCE_MSG);
1776 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001777 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001778
Winson Chungcd2b0142011-06-08 16:02:26 -07001779 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001780 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001781 mModel.stopLoader();
1782 app.setLauncher(null);
1783
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001784 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001785 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001786 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001787 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001788 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001789 mAppWidgetHost = null;
1790
1791 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001792
1793 TextKeyListener.getInstance().release();
1794
Winson Chung81b52252012-08-27 15:34:29 -07001795 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1796 // to prevent leaking Launcher activities on orientation change.
1797 if (mModel != null) {
1798 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1799 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001800
1801 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001802 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001803
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001804 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001805 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1806 mWorkspace.removeAllViews();
1807 mWorkspace = null;
1808 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001809
Michael Jurka2ecf9952012-06-18 12:52:28 -07001810 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001811 }
1812
Adam Cohena9cf38f2011-05-02 15:36:58 -07001813 public DragController getDragController() {
1814 return mDragController;
1815 }
1816
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001817 @Override
1818 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001819 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001820 super.startActivityForResult(intent, requestCode);
1821 }
1822
Winson Chung70d72102011-08-12 11:24:35 -07001823 /**
1824 * Indicates that we want global search for this activity by setting the globalSearch
1825 * argument for {@link #startSearch} to true.
1826 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001827 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001828 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001829 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001830
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001831 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001832
Karl Rosaen138a0412009-04-23 19:00:21 -07001833 if (initialQuery == null) {
1834 // Use any text typed in the launcher as the initial query
1835 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001836 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001837 if (appSearchData == null) {
1838 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001839 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001840 }
Winson Chungadf0c182012-08-23 14:59:07 -07001841 Rect sourceBounds = new Rect();
1842 if (mSearchDropTargetBar != null) {
1843 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1844 }
Romain Guycbb89e42009-06-08 15:52:54 -07001845
Bjorn Bringertc459e522013-06-07 19:36:01 +01001846 startSearch(initialQuery, selectInitialQuery,
1847 appSearchData, sourceBounds);
1848 }
1849
1850 public void startSearch(String initialQuery,
1851 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001852 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001853 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001854 }
1855
1856 /**
1857 * Starts the global search activity. This code is a copied from SearchManager
1858 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001859 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001860 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001861 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001862 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1863 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1864 if (globalSearchActivity == null) {
1865 Log.w(TAG, "No global search activity found.");
1866 return;
1867 }
1868 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1869 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1870 intent.setComponent(globalSearchActivity);
1871 // Make sure that we have a Bundle to put source in
1872 if (appSearchData == null) {
1873 appSearchData = new Bundle();
1874 } else {
1875 appSearchData = new Bundle(appSearchData);
1876 }
1877 // Set source to package name of app that starts global search, if not set already.
1878 if (!appSearchData.containsKey("source")) {
1879 appSearchData.putString("source", getPackageName());
1880 }
1881 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1882 if (!TextUtils.isEmpty(initialQuery)) {
1883 intent.putExtra(SearchManager.QUERY, initialQuery);
1884 }
1885 if (selectInitialQuery) {
1886 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1887 }
1888 intent.setSourceBounds(sourceBounds);
1889 try {
1890 startActivity(intent);
1891 } catch (ActivityNotFoundException ex) {
1892 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1893 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001894 }
1895
Winson Chung70d72102011-08-12 11:24:35 -07001896 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001897 public boolean onPrepareOptionsMenu(Menu menu) {
1898 super.onPrepareOptionsMenu(menu);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001899 if (!mWorkspace.isInOverviewMode()) {
1900 mWorkspace.enterOverviewMode();
Winson Chung70d72102011-08-12 11:24:35 -07001901 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02001902 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001903 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001904
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001905 @Override
1906 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001907 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001908 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001909 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001910 }
1911
Joe Onorato9c1289c2009-08-17 11:03:03 -04001912 public boolean isWorkspaceLocked() {
1913 return mWorkspaceLoading || mWaitingForResult;
1914 }
1915
Michael Jurka0280c3b2010-09-17 15:00:07 -07001916 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001917 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001918 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001919 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1920 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08001921 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07001922 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001923 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001924
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001925 void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
1926 AppWidgetProviderInfo appWidgetInfo) {
1927 if (appWidgetInfo.configure != null) {
1928 mPendingAddWidgetInfo = appWidgetInfo;
Michael Jurkaaf442092010-06-10 17:01:57 -07001929
Bjorn Bringert7984c942009-12-09 15:38:25 +00001930 // Launch over to configure widget, if needed
1931 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001932 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00001933 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02001934 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001935 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001936 // Otherwise just add it
Adam Cohendcd297f2013-06-18 13:13:40 -07001937 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001938 appWidgetInfo);
Winson Chung557d6ed2011-07-08 15:34:52 -07001939 // Exit spring loaded mode if necessary after adding the widget
Adam Cohened66b2b2012-01-23 17:28:51 -08001940 exitSpringLoadedDragModeDelayed(true, false, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001941 }
1942 }
Romain Guycbb89e42009-06-08 15:52:54 -07001943
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001944 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07001945 // Close any folders that may be open.
1946 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01001947 mWorkspace.moveToCustomContentScreen(animate);
1948 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001949 /**
1950 * Process a shortcut drop.
1951 *
1952 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07001953 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001954 * @param cell The cell it should be added to, optional
1955 * @param position The location on the screen where it was dropped, optional
1956 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001957 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07001958 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001959 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001960 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001961 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001962 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001963
1964 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001965 mPendingAddInfo.cellX = cell[0];
1966 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001967 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001968
1969 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1970 createShortcutIntent.setComponent(componentName);
1971 processShortcut(createShortcutIntent);
1972 }
1973
Adam Cohenfbba09b2011-07-18 21:43:05 -07001974 /**
1975 * Process a widget drop.
1976 *
1977 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07001978 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07001979 * @param cell The cell it should be added to, optional
1980 * @param position The location on the screen where it was dropped, optional
1981 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001982 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08001983 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001984 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001985 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07001986 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07001987 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08001988 mPendingAddInfo.minSpanX = info.minSpanX;
1989 mPendingAddInfo.minSpanY = info.minSpanY;
1990
Adam Cohenfbba09b2011-07-18 21:43:05 -07001991 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001992 mPendingAddInfo.cellX = cell[0];
1993 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001994 }
Adam Cohend41fbf52012-02-16 23:53:59 -08001995 if (span != null) {
1996 mPendingAddInfo.spanX = span[0];
1997 mPendingAddInfo.spanY = span[1];
1998 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001999
Adam Cohened66b2b2012-01-23 17:28:51 -08002000 AppWidgetHostView hostView = info.boundWidget;
2001 int appWidgetId;
2002 if (hostView != null) {
2003 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002004 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002005 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002006 // In this case, we either need to start an activity to get permission to bind
2007 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002008 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002009 Bundle options = info.bindOptions;
2010
2011 boolean success = false;
2012 if (options != null) {
2013 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2014 info.componentName, options);
2015 } else {
2016 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2017 info.componentName);
2018 }
2019 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002020 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002021 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002022 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002023 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2024 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2025 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002026 // TODO: we need to make sure that this accounts for the options bundle.
2027 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002028 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2029 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002030 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002031 }
2032
Joe Onoratodeb98af2010-02-19 14:59:39 -08002033 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002034 // Handle case where user selected "Applications"
2035 String applicationName = getResources().getString(R.string.group_applications);
2036 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002037
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002038 if (applicationName != null && applicationName.equals(shortcutName)) {
2039 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2040 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002041
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002042 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2043 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002044 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002045 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002046 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002047 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002048 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002049 }
2050
Winson Chung24ab2f12010-09-16 14:10:47 -07002051 void processWallpaper(Intent intent) {
2052 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2053 }
2054
Adam Cohendcd297f2013-06-18 13:13:40 -07002055 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002056 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002057 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002058 folderInfo.title = getText(R.string.folder_name);
2059
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002060 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002061 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002062 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002063 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002064
2065 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002066 FolderIcon newFolder =
2067 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002068 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002069 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002070 // Force measure the new folder icon
2071 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2072 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002073 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002074 }
Romain Guycbb89e42009-06-08 15:52:54 -07002075
Joe Onorato9c1289c2009-08-17 11:03:03 -04002076 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002077 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002078 }
2079
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002080 protected void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002081 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002082 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002083 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002084 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002085 }
2086
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002087 protected ComponentName getWallpaperPickerComponent() {
2088 return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
2089 }
2090
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002091 /**
2092 * Registers various content observers. The current implementation registers
2093 * only a favorites observer to keep track of the favorites applications.
2094 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002095 private void registerContentObservers() {
2096 ContentResolver resolver = getContentResolver();
2097 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2098 true, mWidgetObserver);
2099 }
2100
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002101 @Override
2102 public boolean dispatchKeyEvent(KeyEvent event) {
2103 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2104 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002105 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002106 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002107 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002108 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002109 dumpState();
2110 return true;
2111 }
2112 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002113 }
2114 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2115 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002116 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002117 return true;
2118 }
2119 }
2120
2121 return super.dispatchKeyEvent(event);
2122 }
2123
Joe Onorato88ec0992009-11-19 13:16:06 -08002124 @Override
2125 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002126 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002127 showWorkspace(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002128 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002129 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002130 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002131 Folder openFolder = mWorkspace.getOpenFolder();
2132 if (openFolder.isEditingName()) {
2133 openFolder.dismissEditingName();
2134 } else {
2135 closeFolder();
2136 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002137 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002138 mWorkspace.exitWidgetResizeMode();
2139
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002140 // Back button is a no-op here, but give at least some feedback for the button press
2141 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002142 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002143 }
2144
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002145 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002146 * Re-listen when widgets are reset.
2147 */
2148 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002149 if (mAppWidgetHost != null) {
2150 mAppWidgetHost.startListening();
2151 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002152 }
2153
2154 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002155 * Launches the intent referred by the clicked shortcut.
2156 *
2157 * @param v The view representing the clicked shortcut.
2158 */
2159 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002160 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2161 // view has detached (it's possible for this to happen if the view is removed mid touch).
2162 if (v.getWindowToken() == null) {
2163 return;
2164 }
2165
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002166 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002167 return;
2168 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002169
Adam Cohen1697b792013-09-17 19:08:21 -07002170 if (v instanceof Workspace) {
2171 if (mWorkspace.isInOverviewMode()) {
2172 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002173 }
2174 return;
2175 }
2176
2177 if (v instanceof CellLayout) {
2178 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002179 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002180 }
2181 }
2182
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002183 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002184 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002185 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002186 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2187 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002188
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002189 // Check for special shortcuts
2190 if (intent.getComponent() != null) {
2191 final String shortcutClass = intent.getComponent().getClassName();
2192
2193 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chungc58497e2013-09-03 17:48:37 -07002194 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002195 return;
2196 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2197 MemoryDumpActivity.startDump(this);
2198 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002199 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2200 toggleShowWeightWatcher();
2201 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002202 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002203 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002204
2205 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002206 int[] pos = new int[2];
2207 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002208 intent.setSourceBounds(new Rect(pos[0], pos[1],
2209 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002210
2211 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002212
Daniel Sandlerff02d492013-08-05 02:12:05 -04002213 mStats.recordLaunch(intent, shortcut);
2214
Michael Jurkaddd62e92011-02-16 17:49:14 -08002215 if (success && v instanceof BubbleTextView) {
2216 mWaitingForResume = (BubbleTextView) v;
2217 mWaitingForResume.setStayPressed(true);
2218 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002219 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002220 if (v instanceof FolderIcon) {
2221 FolderIcon fi = (FolderIcon) v;
2222 handleFolderClick(fi);
2223 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002224 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002225 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002226 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002227 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002228 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002229 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002230 }
2231 }
2232
Michael Jurka0e260592010-06-30 17:07:39 -07002233 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002234 return false;
2235 }
2236
Michael Jurkaaf442092010-06-10 17:01:57 -07002237 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002238 * Event handler for the search button
2239 *
2240 * @param v The view that was clicked.
2241 */
2242 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002243 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2244
Amith Yamasania135ba82011-08-09 17:42:01 -07002245 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002246 }
2247
2248 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002249 * Event handler for the voice button
2250 *
2251 * @param v The view that was clicked.
2252 */
2253 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002254 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002255
Bjorn Bringertc459e522013-06-07 19:36:01 +01002256 startVoice();
2257 }
2258
2259 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002260 try {
2261 final SearchManager searchManager =
2262 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2263 ComponentName activityName = searchManager.getGlobalSearchActivity();
2264 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002265 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002266 if (activityName != null) {
2267 intent.setPackage(activityName.getPackageName());
2268 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002269 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002270 } catch (ActivityNotFoundException e) {
2271 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002272 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002273 startActivitySafely(null, intent, "onClickVoiceButton");
2274 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002275 }
2276
2277 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002278 * Event handler for the "grid" button that appears on the home screen, which
2279 * enters all apps mode.
2280 *
2281 * @param v The view that was clicked.
2282 */
2283 public void onClickAllAppsButton(View v) {
Winson Chungc58497e2013-09-03 17:48:37 -07002284 showAllApps(true, AppsCustomizePagedView.ContentType.Applications);
Michael Jurka5130e402011-10-13 04:55:35 -07002285 }
2286
2287 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002288 // Provide the same haptic feedback that the system offers for virtual keys.
2289 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002290 }
2291
Adam Cohen61f560d2013-09-30 15:58:20 -07002292 public void performHapticFeedbackOnTouchDown(View v) {
2293 // Provide the same haptic feedback that the system offers for virtual keys.
2294 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2295 }
2296
2297 public View.OnTouchListener getHapticFeedbackTouchListener() {
2298 if (mHapticFeedbackTouchListener == null) {
2299 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2300 @Override
2301 public boolean onTouch(View v, MotionEvent event) {
2302 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2303 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2304 }
2305 return false;
2306 }
2307 };
2308 }
2309 return mHapticFeedbackTouchListener;
2310 }
2311
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002312 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002313 if (!DISABLE_MARKET_BUTTON) {
2314 if (mAppMarketIntent != null) {
2315 startActivitySafely(v, mAppMarketIntent, "app market");
2316 } else {
2317 Log.e(TAG, "Invalid app market intent.");
2318 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002319 }
2320 }
2321
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002322 /**
2323 * Called when the user stops interacting with the launcher.
2324 * This implies that the user is now on the homescreen and is not doing housekeeping.
2325 */
2326 protected void onInteractionEnd() {}
2327
2328 /**
2329 * Called when the user starts interacting with the launcher.
2330 * The possible interactions are:
2331 * - open all apps
2332 * - reorder an app shortcut, or a widget
2333 * - open the overview mode.
2334 * This is a good time to stop doing things that only make sense
2335 * when the user is on the homescreen and not doing housekeeping.
2336 */
2337 protected void onInteractionBegin() {}
2338
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002339 void startApplicationDetailsActivity(ComponentName componentName) {
2340 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002341 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2342 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002343 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002344 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002345 }
2346
Michael Jurka1e2f4652013-07-08 18:03:46 -07002347 // returns true if the activity was started
2348 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002349 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002350 // System applications cannot be installed. For now, show a toast explaining that.
2351 // We may give them the option of disabling apps this way.
2352 int messageId = R.string.uninstall_system_app_text;
2353 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002354 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002355 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002356 String packageName = componentName.getPackageName();
2357 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002358 Intent intent = new Intent(
2359 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002360 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2361 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002362 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002363 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002364 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002365 }
2366
Michael Jurka86a720e2012-05-09 11:23:23 -07002367 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002368 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002369
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002370 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002371 // Only launch using the new animation if the shortcut has not opted out (this is a
2372 // private contract between launcher and may be ignored in the future).
2373 boolean useLaunchAnimation = (v != null) &&
2374 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2375 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002376 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2377 v.getMeasuredWidth(), v.getMeasuredHeight());
2378
2379 startActivity(intent, opts.toBundle());
2380 } else {
2381 startActivity(intent);
2382 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002383 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002384 } catch (SecurityException e) {
2385 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002386 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002387 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002388 "or use the exported attribute for this activity. "
2389 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002390 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002391 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002392 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002393
Michael Jurka86a720e2012-05-09 11:23:23 -07002394 boolean startActivitySafely(View v, Intent intent, Object tag) {
2395 boolean success = false;
2396 try {
2397 success = startActivity(v, intent, tag);
2398 } catch (ActivityNotFoundException e) {
2399 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2400 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2401 }
2402 return success;
2403 }
2404
Adam Cohena9cf38f2011-05-02 15:36:58 -07002405 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002406 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002407 Folder openFolder = mWorkspace.getFolderForTag(info);
2408
2409 // If the folder info reports that the associated folder is open, then verify that
2410 // it is actually opened. There have been a few instances where this gets out of sync.
2411 if (info.opened && openFolder == null) {
2412 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002413 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002414 info.opened = false;
2415 }
2416
Adam Cohenfb91f302012-06-11 15:45:18 -07002417 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002418 // Close any open folder
2419 closeFolder();
2420 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002421 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002422 } else {
2423 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002424 int folderScreen;
2425 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002426 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002427 // .. and close it
2428 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002429 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002430 // Close any folder open on the current screen
2431 closeFolder();
2432 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002433 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002434 }
2435 }
2436 }
2437 }
2438
Adam Cohen268c4752012-06-06 17:47:33 -07002439 /**
2440 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2441 * in the DragLayer in the exact absolute location of the original FolderIcon.
2442 */
2443 private void copyFolderIconToImage(FolderIcon fi) {
2444 final int width = fi.getMeasuredWidth();
2445 final int height = fi.getMeasuredHeight();
2446
2447 // Lazy load ImageView, Bitmap and Canvas
2448 if (mFolderIconImageView == null) {
2449 mFolderIconImageView = new ImageView(this);
2450 }
2451 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2452 mFolderIconBitmap.getHeight() != height) {
2453 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2454 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2455 }
2456
2457 DragLayer.LayoutParams lp;
2458 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2459 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2460 } else {
2461 lp = new DragLayer.LayoutParams(width, height);
2462 }
2463
Adam Cohen307fe232012-08-16 17:55:58 -07002464 // The layout from which the folder is being opened may be scaled, adjust the starting
2465 // view size by this scale factor.
2466 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002467 lp.customPosition = true;
2468 lp.x = mRectForFolderAnimation.left;
2469 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002470 lp.width = (int) (scale * width);
2471 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002472
2473 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2474 fi.draw(mFolderIconCanvas);
2475 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002476 if (fi.getFolder() != null) {
2477 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2478 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002479 }
Adam Cohen268c4752012-06-06 17:47:33 -07002480 // Just in case this image view is still in the drag layer from a previous animation,
2481 // we remove it and re-add it.
2482 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2483 mDragLayer.removeView(mFolderIconImageView);
2484 }
2485 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002486 if (fi.getFolder() != null) {
2487 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002488 }
Adam Cohen268c4752012-06-06 17:47:33 -07002489 }
2490
Adam Cohen2801caf2011-05-13 20:57:39 -07002491 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002492 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002493 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2494 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2495 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2496
Adam Cohenc51934b2011-07-26 21:07:43 -07002497 FolderInfo info = (FolderInfo) fi.getTag();
2498 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2499 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002500 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2501 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002502 }
2503
Adam Cohen268c4752012-06-06 17:47:33 -07002504 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2505 copyFolderIconToImage(fi);
2506 fi.setVisibility(View.INVISIBLE);
2507
Michael Jurka2ecf9952012-06-18 12:52:28 -07002508 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002509 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002510 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2511 oa.start();
2512 }
2513
Adam Cohen268c4752012-06-06 17:47:33 -07002514 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002515 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002516 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2517 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2518 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2519
Adam Cohen268c4752012-06-06 17:47:33 -07002520 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002521
Adam Cohen268c4752012-06-06 17:47:33 -07002522 // We remove and re-draw the FolderIcon in-case it has changed
2523 mDragLayer.removeView(mFolderIconImageView);
2524 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002525 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002526 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002527 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002528 oa.addListener(new AnimatorListenerAdapter() {
2529 @Override
2530 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002531 if (cl != null) {
2532 cl.clearFolderLeaveBehind();
2533 // Remove the ImageView copy of the FolderIcon and make the original visible.
2534 mDragLayer.removeView(mFolderIconImageView);
2535 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002536 }
2537 }
2538 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002539 oa.start();
2540 }
2541
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002542 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002543 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002544 * is animated relative to the specified View. If the View is null, no animation
2545 * is played.
2546 *
2547 * @param folderInfo The FolderInfo describing the folder to open.
2548 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002549 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002550 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002551 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002552
Adam Cohena9cf38f2011-05-02 15:36:58 -07002553 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002554
Adam Cohen4554ee12011-08-03 16:13:21 -07002555 // Just verify that the folder hasn't already been added to the DragLayer.
2556 // There was a one-off crash where the folder had a parent already.
2557 if (folder.getParent() == null) {
2558 mDragLayer.addView(folder);
2559 mDragController.addDropTarget((DropTarget) folder);
2560 } else {
2561 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2562 folder.getParent() + ").");
2563 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002564 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002565 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002566
2567 // Notify the accessibility manager that this folder "window" has appeared and occluded
2568 // the workspace items
2569 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2570 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002571 }
2572
2573 public void closeFolder() {
2574 Folder folder = mWorkspace.getOpenFolder();
2575 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002576 if (folder.isEditingName()) {
2577 folder.dismissEditingName();
2578 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002579 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002580
2581 // Dismiss the folder cling
2582 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002583 }
2584 }
2585
2586 void closeFolder(Folder folder) {
2587 folder.getInfo().opened = false;
2588
2589 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2590 if (parent != null) {
2591 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2592 shrinkAndFadeInFolderIcon(fi);
2593 }
2594 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002595
2596 // Notify the accessibility manager that this folder "window" has disappeard and no
2597 // longer occludeds the workspace items
2598 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002599 }
2600
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002601 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002602 if (!isDraggingEnabled()) return false;
2603 if (isWorkspaceLocked()) return false;
2604 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002605
Adam Cohen1697b792013-09-17 19:08:21 -07002606 if (v instanceof Workspace) {
2607 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002608 if (mWorkspace.enterOverviewMode()) {
2609 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2610 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2611 return true;
2612 } else {
2613 return false;
2614 }
Adam Cohen1697b792013-09-17 19:08:21 -07002615 }
Adam Cohen1697b792013-09-17 19:08:21 -07002616 }
2617
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002618 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002619 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002620 }
2621
Michael Jurka0280c3b2010-09-17 15:00:07 -07002622 resetAddInfo();
2623 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002624 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002625 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002626 return true;
2627 }
2628
Winson Chung3d503fb2011-07-13 17:25:49 -07002629 // The hotseat touch handling does not go through Workspace, and we always allow long press
2630 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002631 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002632 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2633 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002634 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002635 // User long pressed on empty space
2636 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2637 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2638 // Disabling reordering until we sort out some issues.
2639 if (mWorkspace.isInOverviewMode()) {
2640 mWorkspace.startReordering(v);
2641 } else {
2642 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002643 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002644 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002645 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002646 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002647 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002648 }
2649 }
2650 }
2651 return true;
2652 }
2653
Winson Chung3d503fb2011-07-13 17:25:49 -07002654 boolean isHotseatLayout(View layout) {
2655 return mHotseat != null && layout != null &&
2656 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2657 }
2658 Hotseat getHotseat() {
2659 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002660 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002661 View getOverviewPanel() {
2662 return mOverviewPanel;
2663 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002664 SearchDropTargetBar getSearchBar() {
2665 return mSearchDropTargetBar;
2666 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002667
Winson Chung3d503fb2011-07-13 17:25:49 -07002668 /**
2669 * Returns the CellLayout of the specified container at the specified screen.
2670 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002671 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002672 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2673 if (mHotseat != null) {
2674 return mHotseat.getLayout();
2675 } else {
2676 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002677 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002678 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002679 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002680 }
2681 }
2682
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002683 Workspace getWorkspace() {
2684 return mWorkspace;
2685 }
2686
Daniel Sandler843e8602010-06-07 14:59:01 -04002687 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002688 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002689 }
2690
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002691 /**
2692 * Helper method for the cameraZoomIn/cameraZoomOut animations
2693 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002694 * @param scaleFactor The scale factor used for the zoom
2695 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002696 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002697 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002698 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002699 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002700
Craig Mautner360310b2012-10-26 15:13:08 -07002701 private void setWorkspaceBackground(boolean workspace) {
2702 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002703 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002704 }
2705
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002706 void updateWallpaperVisibility(boolean visible) {
2707 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2708 int curflags = getWindow().getAttributes().flags
2709 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2710 if (wpflags != curflags) {
2711 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2712 }
Craig Mautner360310b2012-10-26 15:13:08 -07002713 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002714 }
2715
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002716 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2717 if (v instanceof LauncherTransitionable) {
2718 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2719 }
2720 }
2721
Michael Jurkabed61d22012-02-14 22:51:29 -08002722 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2723 if (v instanceof LauncherTransitionable) {
2724 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2725 }
Winson Chung70442722012-02-10 15:43:22 -08002726
2727 // Update the workspace transition step as well
2728 dispatchOnLauncherTransitionStep(v, 0f);
2729 }
2730
2731 private void dispatchOnLauncherTransitionStep(View v, float t) {
2732 if (v instanceof LauncherTransitionable) {
2733 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2734 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002735 }
2736
2737 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2738 if (v instanceof LauncherTransitionable) {
2739 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2740 }
Winson Chung70442722012-02-10 15:43:22 -08002741
2742 // Update the workspace transition step as well
2743 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002744 }
2745
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002746 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002747 * Things to test when changing the following seven functions.
2748 * - Home from workspace
2749 * - from center screen
2750 * - from other screens
2751 * - Home from all apps
2752 * - from center screen
2753 * - from other screens
2754 * - Back from all apps
2755 * - from center screen
2756 * - from other screens
2757 * - Launch app from workspace and quit
2758 * - with back
2759 * - with home
2760 * - Launch app from all apps and quit
2761 * - with back
2762 * - with home
2763 * - Go to a screen that's not the default, then all
2764 * apps, and launch and app, and go back
2765 * - with back
2766 * -with home
2767 * - On workspace, long press power and go back
2768 * - with back
2769 * - with home
2770 * - On all apps, long press power and go back
2771 * - with back
2772 * - with home
2773 * - On workspace, power off
2774 * - On all apps, power off
2775 * - Launch an app and turn off the screen while in that app
2776 * - Go back with home key
2777 * - Go back with back key TODO: make this not go to workspace
2778 * - From all apps
2779 * - From workspace
2780 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2781 * - From all apps
2782 * - From the center workspace
2783 * - From another workspace
2784 */
2785
2786 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002787 * Zoom the camera out from the workspace to reveal 'toView'.
2788 * Assumes that the view to show is anchored at either the very top or very bottom
2789 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002790 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002791 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002792 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2793 showAppsCustomizeHelper(animated, springLoaded, contentType);
2794 }
2795 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2796 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002797 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002798 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002799 mStateAnimation.cancel();
2800 mStateAnimation = null;
2801 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002802 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002803
Winson Chungf0ea4d32011-06-06 14:27:16 -07002804 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2805 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2806 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002807 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002808 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002809 final int startDelay =
2810 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002811
Michael Jurkab3e22d92011-10-31 15:58:33 -07002812 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002813
Michael Jurkad74c9842011-07-10 12:44:21 -07002814 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002815 Animator workspaceAnim =
2816 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Winson Chungc58497e2013-09-03 17:48:37 -07002817 if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
2818 // Set the content type for the all apps space
2819 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2820 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002821
2822 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002823 toView.setScaleX(scale);
2824 toView.setScaleY(scale);
2825 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2826 scaleAnim.
2827 scaleX(1f).scaleY(1f).
2828 setDuration(duration).
2829 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002830
Winson Chungf0ea4d32011-06-06 14:27:16 -07002831 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002832 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002833 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002834 .ofFloat(toView, "alpha", 0f, 1f)
2835 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002836 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002837 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2838 @Override
2839 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002840 if (animation == null) {
2841 throw new RuntimeException("animation is null");
2842 }
Winson Chung70442722012-02-10 15:43:22 -08002843 float t = (Float) animation.getAnimatedValue();
2844 dispatchOnLauncherTransitionStep(fromView, t);
2845 dispatchOnLauncherTransitionStep(toView, t);
2846 }
2847 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002848
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002849 // toView should appear right at the end of the workspace shrink
2850 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002851 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002852 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002853 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002854
2855 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002856 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002857 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002858 // Prepare the position
2859 toView.setTranslationX(0.0f);
2860 toView.setTranslationY(0.0f);
2861 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002862 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002863 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002864 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002865 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002866 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2867 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002868
Winson Chungc7d2b602012-05-16 17:02:20 -07002869 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002870 if (mSearchDropTargetBar != null) {
2871 mSearchDropTargetBar.hideSearchBar(false);
2872 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002873 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002874 });
2875
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002876 if (workspaceAnim != null) {
2877 mStateAnimation.play(workspaceAnim);
2878 }
Michael Jurka1899a362011-11-03 13:50:45 -07002879
2880 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002881
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002882 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2883 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002884
2885 // If any of the objects being animated haven't been measured/laid out
2886 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002887 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002888 (mWorkspace.getMeasuredWidth() == 0) ||
2889 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002890 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002891 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002892
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002893 final AnimatorSet stateAnimation = mStateAnimation;
2894 final Runnable startAnimRunnable = new Runnable() {
2895 public void run() {
2896 // Check that mStateAnimation hasn't changed while
2897 // we waited for a layout/draw pass
2898 if (mStateAnimation != stateAnimation)
2899 return;
2900 setPivotsForZoom(toView, scale);
2901 dispatchOnLauncherTransitionStart(fromView, animated, false);
2902 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002903 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002904 }
2905 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002906 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002907 final ViewTreeObserver observer = toView.getViewTreeObserver();
2908 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
2909 public void onGlobalLayout() {
2910 startAnimRunnable.run();
2911 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
2912 }
2913 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002914 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07002915 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07002916 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002917 } else {
2918 toView.setTranslationX(0.0f);
2919 toView.setTranslationY(0.0f);
2920 toView.setScaleX(1.0f);
2921 toView.setScaleY(1.0f);
2922 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002923 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002924
Daniel Sandlere4f98912013-06-25 15:13:26 -04002925 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07002926 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002927 if (mSearchDropTargetBar != null) {
2928 mSearchDropTargetBar.hideSearchBar(false);
2929 }
Michael Jurkaabded662011-03-04 12:06:57 -08002930 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002931 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002932 dispatchOnLauncherTransitionStart(fromView, animated, false);
2933 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002934 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08002935 dispatchOnLauncherTransitionStart(toView, animated, false);
2936 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002937 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002938 }
2939
2940 /**
2941 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002942 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002943 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002944 */
Adam Cohened66b2b2012-01-23 17:28:51 -08002945 private void hideAppsCustomizeHelper(State toState, final boolean animated,
2946 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002947
Michael Jurkab3e22d92011-10-31 15:58:33 -07002948 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002949 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002950 mStateAnimation.cancel();
2951 mStateAnimation = null;
2952 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002953 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002954
Winson Chungf0ea4d32011-06-06 14:27:16 -07002955 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002956 final int fadeOutDuration =
2957 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002958 final float scaleFactor = (float)
2959 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2960 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08002961 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002962 Animator workspaceAnim = null;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002963 if (toState == State.WORKSPACE) {
2964 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2965 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohenf358a4b2013-07-23 16:47:31 -07002966 Workspace.State.NORMAL, animated, stagger, -1);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002967 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2968 workspaceAnim = mWorkspace.getChangeStateAnimation(
2969 Workspace.State.SPRING_LOADED, animated);
2970 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002971
Michael Jurkab3e22d92011-10-31 15:58:33 -07002972 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07002973 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002974 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08002975 final LauncherViewPropertyAnimator scaleAnim =
2976 new LauncherViewPropertyAnimator(fromView);
2977 scaleAnim.
2978 scaleX(scaleFactor).scaleY(scaleFactor).
2979 setDuration(duration).
2980 setInterpolator(new Workspace.ZoomInInterpolator());
2981
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002982 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002983 .ofFloat(fromView, "alpha", 1f, 0f)
2984 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002985 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08002986 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2987 @Override
2988 public void onAnimationUpdate(ValueAnimator animation) {
2989 float t = 1f - (Float) animation.getAnimatedValue();
2990 dispatchOnLauncherTransitionStep(fromView, t);
2991 dispatchOnLauncherTransitionStep(toView, t);
2992 }
2993 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08002994
Michael Jurka2ecf9952012-06-18 12:52:28 -07002995 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08002996
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002997 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
2998 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Chet Haasebc2f0822012-10-26 17:59:53 -07002999 mAppsCustomizeContent.pauseScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003000
3001 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003002 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003003 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003004 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003005 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3006 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003007 if (onCompleteRunnable != null) {
3008 onCompleteRunnable.run();
3009 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003010 mAppsCustomizeContent.updateCurrentPageScroll();
3011 mAppsCustomizeContent.resumeScrolling();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003012 }
3013 });
3014
Winson Chungf0ea4d32011-06-06 14:27:16 -07003015 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003016 if (workspaceAnim != null) {
3017 mStateAnimation.play(workspaceAnim);
3018 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003019 dispatchOnLauncherTransitionStart(fromView, animated, true);
3020 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003021 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003022 } else {
3023 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003024 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003025 dispatchOnLauncherTransitionStart(fromView, animated, true);
3026 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003027 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003028 dispatchOnLauncherTransitionStart(toView, animated, true);
3029 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003030 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003031 }
3032
Michael Jurkae326f182011-11-21 14:05:46 -08003033 @Override
3034 public void onTrimMemory(int level) {
3035 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003036 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003037 mAppsCustomizeTabHost.onTrimMemory();
3038 }
3039 }
3040
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003041 void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003042 showWorkspace(animated, null);
3043 }
3044
3045 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003046 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003047 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003048 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003049 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003050
Winson Chungc7d2b602012-05-16 17:02:20 -07003051 // Show the search bar (only animate if we were showing the drop target bar in spring
3052 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003053 if (mSearchDropTargetBar != null) {
3054 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
3055 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003056
Michael Jurkab3e22d92011-10-31 15:58:33 -07003057 // Set focus to the AppsCustomize button
3058 if (mAllAppsButton != null) {
3059 mAllAppsButton.requestFocus();
3060 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003061 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003062
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003063 // Change the state *after* we've called all the transition code
3064 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003065
Winson Chung5fb63472011-02-02 17:03:37 -08003066 // Resume the auto-advance of widgets
3067 mUserPresent = true;
3068 updateRunning();
3069
alanv1d4fde62012-10-17 13:15:47 -07003070 // Send an accessibility event to announce the context change
3071 getWindow().getDecorView()
3072 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003073
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003074 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003075 }
3076
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003077 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003078 }
3079
Winson Chungc58497e2013-09-03 17:48:37 -07003080 void showAllApps(boolean animated,
3081 AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003082 if (mState != State.WORKSPACE) return;
3083
Winson Chungc58497e2013-09-03 17:48:37 -07003084 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003085 mAppsCustomizeTabHost.requestFocus();
3086
Michael Jurkab3e22d92011-10-31 15:58:33 -07003087 // Change the state *after* we've called all the transition code
3088 mState = State.APPS_CUSTOMIZE;
3089
3090 // Pause the auto-advance of widgets until we are out of AllApps
3091 mUserPresent = false;
3092 updateRunning();
3093 closeFolder();
3094
3095 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003096 getWindow().getDecorView()
3097 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003098 }
3099
Adam Cohen7777d962011-08-18 18:58:38 -07003100 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003101 if (isAllAppsVisible()) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003102 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003103 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003104 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003105 }
Adam Cohen7777d962011-08-18 18:58:38 -07003106
Adam Cohened66b2b2012-01-23 17:28:51 -08003107 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay,
3108 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003109 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3110
Winson Chunge7a03942011-08-05 15:05:12 -07003111 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003112 @Override
3113 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003114 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003115 // Before we show workspace, hide all apps again because
3116 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3117 // clean up our state transition functions
3118 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003119 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003120 } else {
3121 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003122 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003123 }
3124 }, (extendedDelay ?
3125 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
3126 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
3127 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003128
Michael Jurkad3ef3062010-11-23 16:23:58 -08003129 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003130 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003131 final boolean animated = true;
3132 final boolean springLoaded = true;
3133 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003134 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003135 }
3136 // Otherwise, we are not in spring loaded mode, so don't do anything.
3137 }
3138
Michael Jurkab3e22d92011-10-31 15:58:33 -07003139 void lockAllApps() {
3140 // TODO
3141 }
3142
3143 void unlockAllApps() {
3144 // TODO
3145 }
3146
Winson Chungf0ea4d32011-06-06 14:27:16 -07003147 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003148 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003149 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003150 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003151 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003152 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003153 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003154 int duration = 0;
3155 if (mSearchDropTargetBar != null) {
3156 duration = mSearchDropTargetBar.getTransitionInDuration();
3157 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003158 mHotseat.animate().alpha(1f).setDuration(duration);
3159 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003160 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003161 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003162 }
3163 }
3164 }
3165
3166 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003167 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003168 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003169 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003170 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003171 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003172 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003173 int duration = 0;
3174 if (mSearchDropTargetBar != null) {
3175 duration = mSearchDropTargetBar.getTransitionOutDuration();
3176 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003177 mHotseat.animate().alpha(0f).setDuration(duration);
3178 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003179 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003180 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003181 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003182 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003183 }
3184
Patrick Dubroy5f445422011-02-18 14:35:21 -08003185 /**
3186 * Add an item from all apps or customize onto the given workspace screen.
3187 * If layout is null, add to the current screen.
3188 */
3189 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003190 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003191 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003192 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003193 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003194
Winson Chungdff8ebb2011-09-08 17:25:31 -07003195 /** Maps the current orientation to an index for referencing orientation correct global icons */
3196 private int getCurrentOrientationIndexForGlobalIcons() {
3197 // default - 0, landscape - 1
3198 switch (getResources().getConfiguration().orientation) {
3199 case Configuration.ORIENTATION_LANDSCAPE:
3200 return 1;
3201 default:
3202 return 0;
3203 }
3204 }
3205
Michael Jurkaae65ee32012-04-30 11:45:54 -07003206 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003207 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003208 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003209 // Look for the toolbar icon specified in the activity meta-data
3210 Bundle metaData = packageManager.getActivityInfo(
3211 activityName, PackageManager.GET_META_DATA).metaData;
3212 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003213 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003214 if (iconResId != 0) {
3215 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003216 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003217 }
3218 }
3219 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003220 // This can happen if the activity defines an invalid drawable
3221 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3222 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003223 } catch (Resources.NotFoundException nfe) {
3224 // This can happen if the activity defines an invalid drawable
3225 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3226 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003227 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003228 return null;
3229 }
3230
3231 // if successful in getting icon, return it; otherwise, set button to use default drawable
3232 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003233 int buttonId, ComponentName activityName, int fallbackDrawableId,
3234 String toolbarResourceName) {
3235 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003236 Resources r = getResources();
3237 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3238 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003239
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003240 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003241 // If we were unable to find the icon via the meta-data, use a generic one
3242 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003243 toolbarIcon = r.getDrawable(fallbackDrawableId);
3244 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003245 if (button != null) {
3246 button.setCompoundDrawables(toolbarIcon, null, null, null);
3247 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003248 return null;
3249 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003250 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003251 if (button != null) {
3252 button.setCompoundDrawables(toolbarIcon, null, null, null);
3253 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003254 return toolbarIcon.getConstantState();
3255 }
3256 }
3257
3258 // if successful in getting icon, return it; otherwise, set button to use default drawable
3259 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003260 int buttonId, ComponentName activityName, int fallbackDrawableId,
3261 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003262 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003263 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003264
Michael Jurka19e0fc52011-07-22 18:00:21 -07003265 if (button != null) {
3266 // If we were unable to find the icon via the meta-data, use a
3267 // generic one
3268 if (toolbarIcon == null) {
3269 button.setImageResource(fallbackDrawableId);
3270 } else {
3271 button.setImageDrawable(toolbarIcon);
3272 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003273 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003274
3275 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3276
Michael Jurka0423dcf2010-10-05 14:56:18 -07003277 }
3278
Winson Chung1b884092012-06-08 17:13:02 -07003279 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003280 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003281 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003282 }
3283
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003284 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003285 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003286 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003287 }
3288
Winson Chungbb185bd2011-11-21 12:31:42 -08003289 private void invalidatePressedFocusedStates(View container, View button) {
3290 if (container instanceof HolographicLinearLayout) {
3291 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3292 layout.invalidatePressedFocusedStates();
3293 } else if (button instanceof HolographicImageView) {
3294 HolographicImageView view = (HolographicImageView) button;
3295 view.invalidatePressedFocusedStates();
3296 }
3297 }
3298
Cristina Stancu476493b2013-08-07 17:20:14 +01003299 public View getQsbBar() {
3300 if (mQsbBar == null) {
Winson Chung54e65132013-09-27 11:44:58 -07003301 mQsbBar = mInflater.inflate(R.layout.search_bar, mSearchDropTargetBar, false);
3302 mSearchDropTargetBar.addView(mQsbBar);
Cristina Stancu476493b2013-08-07 17:20:14 +01003303 }
3304 return mQsbBar;
3305 }
3306
3307 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003308 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003309 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003310 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003311 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003312
Winson Chung1cad91e2011-05-25 17:41:01 -07003313 final SearchManager searchManager =
3314 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3315 ComponentName activityName = searchManager.getGlobalSearchActivity();
3316 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003317 int coi = getCurrentOrientationIndexForGlobalIcons();
3318 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003319 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3320 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3321 if (sGlobalSearchIcon[coi] == null) {
3322 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3323 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3324 TOOLBAR_ICON_METADATA_NAME);
3325 }
3326
Winson Chungc51db6a2011-10-05 11:44:49 -07003327 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3328 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003329 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003330 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003331 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003332 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003333 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3334 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003335 if (searchButton != null) searchButton.setVisibility(View.GONE);
3336 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003337 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003338 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003339 }
3340 }
3341
Cristina Stancu476493b2013-08-07 17:20:14 +01003342 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003343 final View searchButtonContainer = findViewById(R.id.search_button_container);
3344 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003345 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003346 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003347 }
3348
Cristina Stancu476493b2013-08-07 17:20:14 +01003349 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003350 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003351 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003352
Winson Chungc51db6a2011-10-05 11:44:49 -07003353 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003354 final SearchManager searchManager =
3355 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3356 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3357
3358 ComponentName activityName = null;
3359 if (globalSearchActivity != null) {
3360 // Check if the global search activity handles voice search
3361 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3362 intent.setPackage(globalSearchActivity.getPackageName());
3363 activityName = intent.resolveActivity(getPackageManager());
3364 }
3365
3366 if (activityName == null) {
3367 // Fallback: check if an activity other than the global search activity
3368 // resolves this
3369 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3370 activityName = intent.resolveActivity(getPackageManager());
3371 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003372 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003373 int coi = getCurrentOrientationIndexForGlobalIcons();
3374 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003375 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3376 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3377 if (sVoiceSearchIcon[coi] == null) {
3378 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3379 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3380 TOOLBAR_ICON_METADATA_NAME);
3381 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003382 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003383 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003384 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003385 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003386 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003387 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003388 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003389 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003390 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003391 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003392 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003393 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003394
Cristina Stancu476493b2013-08-07 17:20:14 +01003395 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003396 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3397 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003398 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003399 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003400 }
3401
Winson Chung5841efa2013-09-30 18:06:44 -07003402 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003403 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3404 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003405 boolean visible = !forceDisableVoiceButtonProxy &&
3406 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003407 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003408 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003409 }
3410 }
Winson Chung5841efa2013-09-30 18:06:44 -07003411
3412 /**
3413 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3414 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3415 */
3416 public void disableVoiceButtonProxy(boolean disabled) {
3417 updateVoiceButtonProxyVisible(disabled);
3418 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003419 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003420 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003421 */
3422 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003423 if (!DISABLE_MARKET_BUTTON) {
3424 final View marketButton = findViewById(R.id.market_button);
3425 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3426 // Find the app market activity by resolving an intent.
3427 // (If multiple app markets are installed, it will return the ResolverActivity.)
3428 ComponentName activityName = intent.resolveActivity(getPackageManager());
3429 if (activityName != null) {
3430 int coi = getCurrentOrientationIndexForGlobalIcons();
3431 mAppMarketIntent = intent;
3432 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3433 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3434 TOOLBAR_ICON_METADATA_NAME);
3435 marketButton.setVisibility(View.VISIBLE);
3436 } else {
3437 // We should hide and disable the view so that we don't try and restore the visibility
3438 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3439 marketButton.setVisibility(View.GONE);
3440 marketButton.setEnabled(false);
3441 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003442 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003443 }
3444
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003445 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003446 if (!DISABLE_MARKET_BUTTON) {
3447 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3448 Resources r = getResources();
3449 Drawable marketIconDrawable = d.newDrawable(r);
3450 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3451 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3452 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003453
Winson Chungd64a6662013-09-30 11:06:59 -07003454 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3455 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003456 }
3457
Michael Jurkad7c28052012-04-27 15:43:36 -07003458 @Override
3459 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003460 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003461 final List<CharSequence> text = event.getText();
3462 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003463 // Populate event with a fake title based on the current state.
3464 if (mState == State.APPS_CUSTOMIZE) {
3465 text.add(getString(R.string.all_apps_button_label));
3466 } else {
3467 text.add(getString(R.string.all_apps_home_button_label));
3468 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003469 return result;
3470 }
3471
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003472 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003473 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003474 */
3475 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3476 @Override
3477 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003478 closeSystemDialogs();
3479 }
3480 }
3481
3482 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003483 * Receives notifications whenever the appwidgets are reset.
3484 */
3485 private class AppWidgetResetObserver extends ContentObserver {
3486 public AppWidgetResetObserver() {
3487 super(new Handler());
3488 }
3489
3490 @Override
3491 public void onChange(boolean selfChange) {
3492 onAppWidgetReset();
3493 }
3494 }
3495
3496 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003497 * If the activity is currently paused, signal that we need to run the passed Runnable
3498 * in onResume.
3499 *
3500 * This needs to be called from incoming places where resources might have been loaded
3501 * while we are paused. That is becaues the Configuration might be wrong
3502 * when we're not running, and if it comes back to what it was when we
3503 * were paused, we are not restarted.
3504 *
3505 * Implementation of the method from LauncherModel.Callbacks.
3506 *
3507 * @return true if we are currently paused. The caller might be able to
3508 * skip some work in that case since we will come back again.
3509 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003510 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003511 if (mPaused) {
3512 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003513 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003514 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003515 }
3516 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003517 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003518 return true;
3519 } else {
3520 return false;
3521 }
3522 }
3523
Michael Jurkac402cd92013-05-20 15:49:32 +02003524 private boolean waitUntilResume(Runnable run) {
3525 return waitUntilResume(run, false);
3526 }
3527
Michael Jurka1e2f4652013-07-08 18:03:46 -07003528 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003529 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003530 }
3531
Michael Jurka7607c2f2013-04-03 14:33:19 -07003532 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003533 * If the activity is currently paused, signal that we need to re-run the loader
3534 * in onResume.
3535 *
3536 * This needs to be called from incoming places where resources might have been loaded
3537 * while we are paused. That is becaues the Configuration might be wrong
3538 * when we're not running, and if it comes back to what it was when we
3539 * were paused, we are not restarted.
3540 *
3541 * Implementation of the method from LauncherModel.Callbacks.
3542 *
3543 * @return true if we are currently paused. The caller might be able to
3544 * skip some work in that case since we will come back again.
3545 */
3546 public boolean setLoadOnResume() {
3547 if (mPaused) {
3548 Log.i(TAG, "setLoadOnResume");
3549 mOnResumeNeedsLoad = true;
3550 return true;
3551 } else {
3552 return false;
3553 }
3554 }
3555
3556 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003557 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003558 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003559 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003560 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003561 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003562 } else {
3563 return SCREEN_COUNT / 2;
3564 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003565 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003566
Joe Onorato9c1289c2009-08-17 11:03:03 -04003567 /**
3568 * Refreshes the shortcuts shown on the workspace.
3569 *
3570 * Implementation of the method from LauncherModel.Callbacks.
3571 */
3572 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003573 // If we're starting binding all over again, clear any bind calls we'd postponed in
3574 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3575 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003576 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003577
Winson Chungd64d1762013-08-20 14:37:16 -07003578 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003579 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003580 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003581
Michael Jurka05bf6442011-11-30 20:28:53 -08003582 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003583 if (mHotseat != null) {
3584 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003585 }
3586 }
3587
Adam Cohendcd297f2013-06-18 13:13:40 -07003588 @Override
3589 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003590 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003591
Adam Cohen5084cba2013-09-03 12:01:16 -07003592 // If there are no screens, we need to have an empty screen
3593 if (orderedScreenIds.size() == 0) {
3594 mWorkspace.addExtraEmptyScreen();
3595 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003596
3597 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003598 // setCurrentPage() so ensure that all pages are added before calling this).
3599 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003600 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3601 mWorkspace.createCustomContentPage();
3602 }
Winson Chung64359a52013-07-08 17:17:08 -07003603 }
3604
3605 @Override
3606 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Adam Cohendcd297f2013-06-18 13:13:40 -07003607 int count = orderedScreenIds.size();
3608 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003609 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003610 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003611 }
3612
Adam Cohen39a06042013-07-19 14:30:12 -07003613 private boolean shouldShowWeightWatcher() {
3614 String spKey = LauncherAppState.getSharedPreferencesKey();
3615 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003616 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003617
3618 return show;
3619 }
3620
3621 private void toggleShowWeightWatcher() {
3622 String spKey = LauncherAppState.getSharedPreferencesKey();
3623 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3624 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3625
3626 show = !show;
3627
3628 SharedPreferences.Editor editor = sp.edit();
3629 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3630 editor.commit();
3631
3632 if (mWeightWatcher != null) {
3633 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3634 }
3635 }
3636
Winson Chungd64d1762013-08-20 14:37:16 -07003637 public void bindAppsAdded(final ArrayList<Long> newScreens,
3638 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003639 final ArrayList<ItemInfo> addAnimated,
3640 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003641 Runnable r = new Runnable() {
3642 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003643 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003644 }
3645 };
3646 if (waitUntilResume(r)) {
3647 return;
3648 }
3649
Winson Chungd64d1762013-08-20 14:37:16 -07003650 // Add the new screens
3651 bindAddScreens(newScreens);
3652
3653 // We add the items without animation on non-visible pages, and with
3654 // animations on the new page (which we will try and snap to).
3655 if (!addNotAnimated.isEmpty()) {
3656 bindItems(addNotAnimated, 0,
3657 addNotAnimated.size(), false);
3658 }
3659 if (!addAnimated.isEmpty()) {
3660 bindItems(addAnimated, 0,
3661 addAnimated.size(), true);
3662 }
Winson Chungc58497e2013-09-03 17:48:37 -07003663
Winson Chung87412982013-10-03 18:34:14 -07003664 // Remove the extra empty screen
3665 mWorkspace.removeExtraEmptyScreen();
3666
Winson Chungc58497e2013-09-03 17:48:37 -07003667 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3668 addedApps != null && mAppsCustomizeContent != null) {
3669 mAppsCustomizeContent.addApps(addedApps);
3670 }
Winson Chungd64d1762013-08-20 14:37:16 -07003671 }
3672
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003673 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003674 * Bind the items start-end from the list.
3675 *
3676 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003677 */
Winson Chung64359a52013-07-08 17:17:08 -07003678 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3679 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003680 Runnable r = new Runnable() {
3681 public void run() {
3682 bindItems(shortcuts, start, end, forceAnimateIcons);
3683 }
3684 };
3685 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003686 return;
3687 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003688
Winson Chungf0c6ae02012-03-21 16:10:31 -07003689 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003690 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3691 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003692 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003693 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003694 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003695 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003696 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003697
3698 // Short circuit if we are loading dock items for a configuration which has no dock
3699 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3700 mHotseat == null) {
3701 continue;
3702 }
3703
Joe Onorato9c1289c2009-08-17 11:03:03 -04003704 switch (item.itemType) {
3705 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3706 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003707 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003708 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003709
Winson Chung64359a52013-07-08 17:17:08 -07003710 /*
3711 * TODO: FIX collision case
3712 */
Winson Chungce376632013-07-11 16:12:41 -07003713 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3714 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3715 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3716 throw new RuntimeException("OCCUPIED");
3717 }
Winson Chung64359a52013-07-08 17:17:08 -07003718 }
3719
Adam Cohendcd297f2013-06-18 13:13:40 -07003720 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3721 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003722 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003723 // Animate all the applications up now
3724 shortcut.setAlpha(0f);
3725 shortcut.setScaleX(0f);
3726 shortcut.setScaleY(0f);
3727 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003728 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003729 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003730 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003731 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003732 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003733 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003734 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003735 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3736 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003737 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003738 default:
3739 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003740 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003741 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003742
Winson Chung997a9232013-07-24 15:33:46 -07003743 if (animateIcons) {
3744 // Animate to the correct page
3745 if (newShortcutsScreenId > -1) {
3746 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003747 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003748 final Runnable startBounceAnimRunnable = new Runnable() {
3749 public void run() {
3750 anim.playTogether(bounceAnims);
3751 anim.start();
3752 }
3753 };
Winson Chung997a9232013-07-24 15:33:46 -07003754 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003755 // We post the animation slightly delayed to prevent slowdowns
3756 // when we are loading right after we return to launcher.
3757 mWorkspace.postDelayed(new Runnable() {
3758 public void run() {
3759 mWorkspace.snapToPage(newScreenIndex);
Winson Chungb2323832013-10-03 15:22:09 -07003760 mWorkspace.postDelayed(startBounceAnimRunnable,
3761 NEW_APPS_ANIMATION_DELAY);
Winson Chung94d67682013-09-25 16:29:40 -07003762 }
3763 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003764 } else {
3765 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003766 }
3767 }
Winson Chung64359a52013-07-08 17:17:08 -07003768 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003769 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003770 }
3771
Joe Onorato9c1289c2009-08-17 11:03:03 -04003772 /**
3773 * Implementation of the method from LauncherModel.Callbacks.
3774 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003775 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003776 Runnable r = new Runnable() {
3777 public void run() {
3778 bindFolders(folders);
3779 }
3780 };
3781 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003782 return;
3783 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003784 sFolders.clear();
3785 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003786 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003787
3788 /**
3789 * Add the views for a widget to the workspace.
3790 *
3791 * Implementation of the method from LauncherModel.Callbacks.
3792 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003793 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003794 Runnable r = new Runnable() {
3795 public void run() {
3796 bindAppWidget(item);
3797 }
3798 };
3799 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003800 return;
3801 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003802
Daniel Sandler843e8602010-06-07 14:59:01 -04003803 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3804 if (DEBUG_WIDGETS) {
3805 Log.d(TAG, "bindAppWidget: " + item);
3806 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003807 final Workspace workspace = mWorkspace;
3808
3809 final int appWidgetId = item.appWidgetId;
3810 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003811 if (DEBUG_WIDGETS) {
3812 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3813 }
3814
Joe Onorato9c1289c2009-08-17 11:03:03 -04003815 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3816
Joe Onorato9c1289c2009-08-17 11:03:03 -04003817 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003818 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003819
Adam Cohendcd297f2013-06-18 13:13:40 -07003820 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003821 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003822 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3823
Joe Onorato9c1289c2009-08-17 11:03:03 -04003824 workspace.requestLayout();
3825
Daniel Sandler843e8602010-06-07 14:59:01 -04003826 if (DEBUG_WIDGETS) {
3827 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3828 + (SystemClock.uptimeMillis()-start) + "ms");
3829 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003830 }
3831
Adam Cohen1462de32012-07-24 22:34:36 -07003832 public void onPageBoundSynchronously(int page) {
3833 mSynchronouslyBoundPages.add(page);
3834 }
3835
Joe Onorato9c1289c2009-08-17 11:03:03 -04003836 /**
3837 * Callback saying that there aren't any more items to bind.
3838 *
3839 * Implementation of the method from LauncherModel.Callbacks.
3840 */
Adam Cohene25af792013-06-06 23:08:25 -07003841 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003842 Runnable r = new Runnable() {
3843 public void run() {
3844 finishBindingItems(upgradePath);
3845 }
3846 };
3847 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003848 return;
3849 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003850 if (mSavedState != null) {
3851 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003852 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003853 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003854 mSavedState = null;
3855 }
3856
Adam Cohen1462de32012-07-24 22:34:36 -07003857 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003858
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003859 // If we received the result of any pending adds while the loader was running (e.g. the
3860 // widget configuration forced an orientation change), process them now.
3861 for (int i = 0; i < sPendingAddList.size(); i++) {
3862 completeAdd(sPendingAddList.get(i));
3863 }
3864 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003865
Winson Chungc51db6a2011-10-05 11:44:49 -07003866 // Update the market app icon as necessary (the other icons will be managed in response to
3867 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07003868 if (!DISABLE_MARKET_BUTTON) {
3869 updateAppMarketIcon();
3870 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07003871
Winson Chungf0c6ae02012-03-21 16:10:31 -07003872 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07003873 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07003874 mWorkspace.getUniqueComponents(true, null);
3875 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07003876 }
Adam Cohen99894d92013-06-14 11:22:59 -07003877
Adam Cohen66a01fd2013-06-11 12:48:00 -07003878 mWorkspace.post(new Runnable() {
3879 @Override
3880 public void run() {
3881 onFinishBindingItems();
3882 }
3883 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07003884 }
3885
Winson Chunga0b7e862013-09-05 16:03:15 -07003886 public boolean isAllAppsButtonRank(int rank) {
3887 if (mHotseat != null) {
3888 return mHotseat.isAllAppsButtonRank(rank);
3889 }
3890 return false;
3891 }
3892
Winson Chunga2413752012-04-03 14:22:34 -07003893 private boolean canRunNewAppsAnimation() {
3894 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
3895 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
3896 }
3897
Winson Chungc9168342013-06-26 14:54:55 -07003898 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
3899 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
3900 PropertyValuesHolder.ofFloat("alpha", 1f),
3901 PropertyValuesHolder.ofFloat("scaleX", 1f),
3902 PropertyValuesHolder.ofFloat("scaleY", 1f));
3903 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
3904 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
3905 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
3906 return bounceAnim;
3907 }
3908
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003909 @Override
3910 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003911 boolean searchVisible = updateGlobalSearchIcon();
3912 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07003913 if (mSearchDropTargetBar != null) {
3914 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
3915 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003916 }
3917
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003918 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003919 * Add the icons for all apps.
3920 *
3921 * Implementation of the method from LauncherModel.Callbacks.
3922 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003923 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07003924 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
3925 if (mIntentsOnWorkspaceFromUpgradePath != null) {
3926 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
3927 getHotseat().addAllAppsFolder(mIconCache, apps,
3928 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
3929 }
3930 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07003931 }
Winson Chungc58497e2013-09-03 17:48:37 -07003932 } else {
3933 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3934 mAppsCustomizeContent != null) {
3935 mAppsCustomizeContent.setApps(apps);
3936 }
Winson Chung785d2eb2011-04-14 16:08:02 -07003937 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003938 }
3939
3940 /**
3941 * A package was updated.
3942 *
3943 * Implementation of the method from LauncherModel.Callbacks.
3944 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003945 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003946 Runnable r = new Runnable() {
3947 public void run() {
3948 bindAppsUpdated(apps);
3949 }
3950 };
3951 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003952 return;
3953 }
3954
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003955 if (mWorkspace != null) {
3956 mWorkspace.updateShortcuts(apps);
3957 }
Winson Chungc58497e2013-09-03 17:48:37 -07003958
3959 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3960 mAppsCustomizeContent != null) {
3961 mAppsCustomizeContent.updateApps(apps);
3962 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003963 }
3964
3965 /**
Winson Chung83892cc2013-05-01 16:53:33 -07003966 * A package was uninstalled. We take both the super set of packageNames
3967 * in addition to specific applications to remove, the reason being that
3968 * this can be called when a package is updated as well. In that scenario,
3969 * we only remove specific components from the workspace, where as
3970 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04003971 *
3972 * Implementation of the method from LauncherModel.Callbacks.
3973 */
Winson Chung83892cc2013-05-01 16:53:33 -07003974 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Michael Jurkaeadbfc52013-09-04 00:45:37 +02003975 final ArrayList<AppInfo> appInfos,
Winson Chung64359a52013-07-08 17:17:08 -07003976 final boolean packageRemoved) {
Winson Chungd64d1762013-08-20 14:37:16 -07003977 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07003978 public void run() {
Winson Chung64359a52013-07-08 17:17:08 -07003979 bindComponentsRemoved(packageNames, appInfos, packageRemoved);
Winson Chung83892cc2013-05-01 16:53:33 -07003980 }
Winson Chungd64d1762013-08-20 14:37:16 -07003981 };
3982 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07003983 return;
3984 }
3985
Winson Chung64359a52013-07-08 17:17:08 -07003986 if (packageRemoved) {
Winson Chung83892cc2013-05-01 16:53:33 -07003987 mWorkspace.removeItemsByPackageName(packageNames);
3988 } else {
3989 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04003990 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003991
Winson Chunga1820962011-10-03 16:31:06 -07003992 // Notify the drag controller
Winson Chung83892cc2013-05-01 16:53:33 -07003993 mDragController.onAppsRemoved(appInfos, this);
Winson Chungc58497e2013-09-03 17:48:37 -07003994
3995 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3996 mAppsCustomizeContent != null) {
3997 mAppsCustomizeContent.removeApps(appInfos);
3998 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003999 }
Joe Onoratobe386092009-11-17 17:32:16 -08004000
4001 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004002 * A number of packages were updated.
4003 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004004 private ArrayList<Object> mWidgetsAndShortcuts;
4005 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004006 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004007 bindPackagesUpdated(mWidgetsAndShortcuts);
4008 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004009 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004010 };
4011
4012 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4013 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4014 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004015 return;
4016 }
4017
Winson Chung64359a52013-07-08 17:17:08 -07004018 // Update the widgets pane
Winson Chungc58497e2013-09-03 17:48:37 -07004019 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
4020 mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004021 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004022 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004023 }
4024
Winson Chung400438b2011-01-16 17:53:48 -08004025 private int mapConfigurationOriActivityInfoOri(int configOri) {
4026 final Display d = getWindowManager().getDefaultDisplay();
4027 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4028 switch (d.getRotation()) {
4029 case Surface.ROTATION_0:
4030 case Surface.ROTATION_180:
4031 // We are currently in the same basic orientation as the natural orientation
4032 naturalOri = configOri;
4033 break;
4034 case Surface.ROTATION_90:
4035 case Surface.ROTATION_270:
4036 // We are currently in the other basic orientation to the natural orientation
4037 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4038 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4039 break;
4040 }
4041
4042 int[] oriMap = {
4043 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4044 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4045 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4046 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4047 };
4048 // Since the map starts at portrait, we need to offset if this device's natural orientation
4049 // is landscape.
4050 int indexOffset = 0;
4051 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4052 indexOffset = 1;
4053 }
4054 return oriMap[(d.getRotation() + indexOffset) % 4];
4055 }
Adam Cohen446e9402011-09-15 18:21:21 -07004056
Winson Chung4b919f82012-05-01 10:44:08 -07004057 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004058 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004059 getResources().getBoolean(R.bool.allow_rotation);
4060 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004061 }
Winson Chung4b919f82012-05-01 10:44:08 -07004062 public void lockScreenOrientation() {
4063 if (isRotationEnabled()) {
4064 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4065 .getConfiguration().orientation));
4066 }
4067 }
4068 public void unlockScreenOrientation(boolean immediate) {
4069 if (isRotationEnabled()) {
4070 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004071 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004072 } else {
4073 mHandler.postDelayed(new Runnable() {
4074 public void run() {
4075 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4076 }
4077 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004078 }
Winson Chung4b919f82012-05-01 10:44:08 -07004079 }
Winson Chung400438b2011-01-16 17:53:48 -08004080 }
4081
Winson Chung82f55532011-08-09 14:14:23 -07004082 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004083 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004084 if (DISABLE_CLINGS) {
4085 return false;
4086 }
4087
Brett Chabot2a9e2282011-08-23 15:03:13 -07004088 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004089 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004090
Michael Jurkae233a8b2013-03-19 13:49:20 +01004091 // Restricted secondary users (child mode) will potentially have very few apps
4092 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004093// boolean supportsLimitedUsers =
4094// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4095// Account[] accounts = AccountManager.get(this).getAccounts();
4096// if (supportsLimitedUsers && accounts.length == 0) {
4097// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4098// Bundle restrictions = um.getUserRestrictions();
4099// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4100// return false;
4101// }
4102// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004103 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004104 }
Michael Jurka22143132012-10-04 17:42:38 +02004105
Winson Chungfa545132013-09-26 17:45:32 -07004106 private Cling initCling(int clingId, int scrimId, boolean animate,
Winson Chungaf40f202013-09-18 18:26:31 -07004107 boolean dimNavBarVisibilty) {
Winson Chungfa545132013-09-26 17:45:32 -07004108 Cling cling = (Cling) findViewById(clingId);
4109 View scrim = null;
4110 if (scrimId > 0) {
Sandeep Siddharthaa6125ef2013-09-26 20:30:40 -07004111 scrim = findViewById(R.id.cling_scrim);
Winson Chungfa545132013-09-26 17:45:32 -07004112 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004113 if (cling != null) {
Winson Chungfa545132013-09-26 17:45:32 -07004114 cling.init(this, scrim);
Winson Chungaf40f202013-09-18 18:26:31 -07004115 cling.show(animate, SHOW_CLING_DURATION);
4116
4117 if (dimNavBarVisibilty) {
4118 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4119 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004120 }
4121 }
4122 return cling;
4123 }
Michael Jurka22143132012-10-04 17:42:38 +02004124
Winson Chungaf40f202013-09-18 18:26:31 -07004125 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4126 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004127 // To catch cases where siblings of top-level views are made invisible, just check whether
4128 // the cling is directly set to GONE before dismissing it.
4129 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004130 final Runnable cleanUpClingCb = new Runnable() {
4131 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004132 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004133 // We should update the shared preferences on a background thread
4134 new Thread("dismissClingThread") {
4135 public void run() {
4136 SharedPreferences.Editor editor = mSharedPrefs.edit();
4137 editor.putBoolean(flag, true);
4138 editor.commit();
4139 }
4140 }.start();
Winson Chungaf40f202013-09-18 18:26:31 -07004141 if (postAnimationCb != null) {
4142 postAnimationCb.run();
4143 }
4144 }
4145 };
4146 if (duration <= 0) {
4147 cleanUpClingCb.run();
4148 } else {
4149 cling.hide(duration, cleanUpClingCb);
4150 }
Michael Jurka22143132012-10-04 17:42:38 +02004151 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004152
4153 if (restoreNavBarVisibilty) {
4154 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4155 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4156 }
Winson Chung82f55532011-08-09 14:14:23 -07004157 }
4158 }
Michael Jurka22143132012-10-04 17:42:38 +02004159
Winson Chung9d9d74f2011-09-19 11:49:12 -07004160 private void removeCling(int id) {
4161 final View cling = findViewById(id);
4162 if (cling != null) {
4163 final ViewGroup parent = (ViewGroup) cling.getParent();
4164 parent.post(new Runnable() {
4165 @Override
4166 public void run() {
4167 parent.removeView(cling);
4168 }
4169 });
Michael Jurka22143132012-10-04 17:42:38 +02004170 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004171 }
4172 }
Michael Jurka974c3862012-05-22 22:00:31 -07004173
4174 private boolean skipCustomClingIfNoAccounts() {
4175 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4176 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4177 if (customCling) {
4178 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004179 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004180 Account[] accounts = am.getAccountsByType("com.google");
4181 return accounts.length == 0;
4182 }
4183 return false;
4184 }
4185
Winson Chungaf40f202013-09-18 18:26:31 -07004186 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004187 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004188 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004189 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004190 // If we're not using the default workspace layout, replace workspace cling
4191 // with a custom workspace cling (usually specified in an overlay)
4192 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004193 if (!DISABLE_CUSTOM_CLINGS) {
4194 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4195 getResources().getBoolean(R.bool.config_useCustomClings)) {
4196 // Use a custom cling
4197 View cling = findViewById(R.id.workspace_cling);
4198 ViewGroup clingParent = (ViewGroup) cling.getParent();
4199 int clingIndex = clingParent.indexOfChild(cling);
4200 clingParent.removeViewAt(clingIndex);
4201 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4202 clingParent.addView(customCling, clingIndex);
4203 customCling.setId(R.id.workspace_cling);
4204 }
4205 }
4206 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4207 if (cling != null) {
4208 String sbHintStr = getFirstRunClingSearchBarHint();
4209 String ccHintStr = getFirstRunCustomContentHint();
4210 if (!sbHintStr.isEmpty()) {
4211 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4212 sbHint.setText(sbHintStr);
4213 sbHint.setVisibility(View.VISIBLE);
4214 }
4215 if (!ccHintStr.isEmpty()) {
4216 TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4217 ccHint.setText(ccHintStr);
4218 ccHint.setVisibility(View.VISIBLE);
4219 }
Michael Jurka45355c42012-10-08 13:21:35 +02004220 }
Winson Chungfa545132013-09-26 17:45:32 -07004221 initCling(R.id.first_run_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004222 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004223 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004224 }
4225 }
Winson Chungaf40f202013-09-18 18:26:31 -07004226
Winson Chunge6eabff2013-09-24 11:01:23 -07004227 protected String getFirstRunClingSearchBarHint() {
4228 return "";
4229 }
4230 protected String getFirstRunCustomContentHint() {
4231 return "";
4232 }
4233
Winson Chungaf40f202013-09-18 18:26:31 -07004234 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004235 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004236 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004237 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004238 initCling(R.id.workspace_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004239 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004240 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004241 }
4242 }
4243 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004244 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004245 if (isClingsEnabled() &&
4246 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004247 Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim,
4248 true, true);
Winson Chungaf40f202013-09-18 18:26:31 -07004249 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004250 } else {
4251 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004252 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004253 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004254 }
Michael Jurka104c4562013-07-08 18:03:46 -07004255 protected SharedPreferences getSharedPrefs() {
4256 return mSharedPrefs;
4257 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004258 public boolean isFolderClingVisible() {
4259 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004260 if (cling != null) {
4261 return cling.getVisibility() == View.VISIBLE;
4262 }
4263 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004264 }
Winson Chungaf40f202013-09-18 18:26:31 -07004265 public void dismissFirstRunCling(View v) {
4266 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4267 Runnable cb = new Runnable() {
4268 public void run() {
4269 // Show the workspace cling next
4270 showFirstRunWorkspaceCling();
4271 }
4272 };
4273 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4274 DISMISS_CLING_DURATION, false);
4275 }
Winson Chung82f55532011-08-09 14:14:23 -07004276 public void dismissWorkspaceCling(View v) {
4277 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004278 Runnable cb = null;
4279 if (v == null) {
4280 cb = new Runnable() {
4281 public void run() {
4282 mWorkspace.enterOverviewMode();
4283 }
4284 };
4285 }
4286 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4287 DISMISS_CLING_DURATION, true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004288 }
4289 public void dismissFolderCling(View v) {
4290 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004291 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4292 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004293 }
4294
Winson Chung80baf5a2010-08-09 16:03:15 -07004295 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004296 * Prints out out state for debugging.
4297 */
4298 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004299 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004300 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004301 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4302 Log.d(TAG, "mRestoring=" + mRestoring);
4303 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4304 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004305 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004306 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004307
Winson Chung785d2eb2011-04-14 16:08:02 -07004308 if (mAppsCustomizeContent != null) {
4309 mAppsCustomizeContent.dumpState();
4310 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004311 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004312 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004313
4314 @Override
4315 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4316 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004317 synchronized (sDumpLogs) {
4318 writer.println(" ");
4319 writer.println("Debug logs: ");
4320 for (int i = 0; i < sDumpLogs.size(); i++) {
4321 writer.println(" " + sDumpLogs.get(i));
4322 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004323 }
4324 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004325
4326 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004327 if (DEBUG_DUMP_LOG) {
4328 synchronized (sDumpLogs) {
4329 Log.d(TAG, "");
4330 Log.d(TAG, "*********************");
4331 Log.d(TAG, "Launcher debug logs: ");
4332 for (int i = 0; i < sDumpLogs.size(); i++) {
4333 Log.d(TAG, " " + sDumpLogs.get(i));
4334 }
4335 Log.d(TAG, "*********************");
4336 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004337 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004338 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004339 }
4340
4341 public static void addDumpLog(String tag, String log, boolean debugLog) {
4342 if (debugLog) {
4343 Log.d(tag, log);
4344 }
Winson Chungede41292013-09-19 16:27:36 -07004345 if (DEBUG_DUMP_LOG) {
4346 sDateStamp.setTime(System.currentTimeMillis());
4347 synchronized (sDumpLogs) {
4348 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
Adam Cohen4caf2982013-08-20 18:54:31 -07004349 }
Winson Chungede41292013-09-19 16:27:36 -07004350 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004351 }
4352
Winson Chungede41292013-09-19 16:27:36 -07004353 public void dumpLogsToLocalData() {
4354 if (DEBUG_DUMP_LOG) {
4355 new Thread("DumpLogsToLocalData") {
4356 @Override
4357 public void run() {
4358 boolean success = false;
4359 sDateStamp.setTime(sRunStart);
4360 String FILENAME = sDateStamp.getMonth() + "-"
4361 + sDateStamp.getDay() + "_"
4362 + sDateStamp.getHours() + "-"
4363 + sDateStamp.getMinutes() + "_"
4364 + sDateStamp.getSeconds() + ".txt";
4365
4366 FileOutputStream fos = null;
4367 File outFile = null;
4368 try {
4369 outFile = new File(getFilesDir(), FILENAME);
4370 outFile.createNewFile();
4371 fos = new FileOutputStream(outFile);
4372 } catch (Exception e) {
4373 e.printStackTrace();
4374 }
4375 if (fos != null) {
4376 PrintWriter writer = new PrintWriter(fos);
4377
4378 writer.println(" ");
4379 writer.println("Debug logs: ");
4380 synchronized (sDumpLogs) {
4381 for (int i = 0; i < sDumpLogs.size(); i++) {
4382 writer.println(" " + sDumpLogs.get(i));
4383 }
4384 }
4385 writer.close();
4386 }
4387 try {
4388 if (fos != null) {
4389 fos.close();
4390 success = true;
4391 }
4392 } catch (IOException e) {
4393 e.printStackTrace();
4394 }
4395 }
4396 }.start();
Adam Cohen4caf2982013-08-20 18:54:31 -07004397 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004398 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004399}
Michael Jurka2763be32011-02-24 11:19:57 -08004400
Michael Jurkaabded662011-03-04 12:06:57 -08004401interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004402 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004403 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004404 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004405 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004406 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004407}