blob: ceb31b001d5724a4ffca1054450346e88fea54ca [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;
Mathew Inwood72fbec12013-11-19 15:45:07 +000048import 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;
Casey Burkhardt0d9cbae2013-10-04 14:13:15 -070090import android.view.accessibility.AccessibilityManager;
Adam Cohencff6af82011-09-13 14:51:53 -070091import android.view.animation.AccelerateDecelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080092import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070094import android.widget.Advanceable;
95import android.widget.FrameLayout;
96import android.widget.ImageView;
97import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
Daniel Sandler325dc232013-06-05 22:57:57 -0400100import com.android.launcher3.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -0800101
Adam Cohenc0dcf592011-06-01 15:30:43 -0700102import java.io.DataInputStream;
103import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700104import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700105import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700106import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700107import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700108import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700109import java.io.PrintWriter;
Adam Cohen4caf2982013-08-20 18:54:31 -0700110import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700111import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700112import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700113import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700115import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000116import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800118/**
119 * Default launcher application.
120 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100121public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700122 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Winson Chungcd810732012-06-18 16:45:43 -0700123 View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800124 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700125 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800126
Daniel Sandlerf061f822013-06-27 13:59:36 -0400127 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400128 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700129 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400130 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700131 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700132
Dan Sandlerd5024042014-01-09 15:01:33 -0500133 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
134
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700139 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700140 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Michael Jurka8b805b12012-04-18 14:23:14 -0700142 private static final int REQUEST_BIND_APPWIDGET = 11;
143
Mathew Inwood876a8462013-06-14 14:12:41 +0100144 /**
145 * IntentStarter uses request codes starting with this. This must be greater than all activity
146 * request codes used internally.
147 */
148 protected static final int REQUEST_LAST = 100;
149
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
151
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800152 static final int SCREEN_COUNT = 5;
153 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Romain Guy98d01652009-06-30 16:21:04 -0700155 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800156 // To turn on these properties, type
157 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
158 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
159 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Winson Chung2672ff92012-05-04 16:22:30 -0700161 // The Intent extra that defines whether to ignore the launch animation
162 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400163 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700164
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: int
166 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700167 // Type: int
168 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700170 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
171 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
173 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700174 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700176 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 // Type: boolean
178 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
179 // Type: long
180 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700181 // Type: int
182 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
183 // Type: int
184 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
185 // Type: parcelable
186 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000187 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800188 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000189 // Type: int[]
190 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100192 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700193 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100194 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700195 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100196 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700197
Adam Cohen39a06042013-07-19 14:30:12 -0700198 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b8002013-08-15 15:44:26 -0700199 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700200
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700201 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700202 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700203 private State mState = State.WORKSPACE;
204 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700205
Joe Onorato9c1289c2009-08-17 11:03:03 -0400206 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700207 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
208 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Winson Chungaf40f202013-09-18 18:26:31 -0700209 private static final int SHOW_CLING_DURATION = 250;
210 private static final int DISMISS_CLING_DURATION = 200;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800211
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800213 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800214
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000215 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
216 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
217
Winson Chunga2413752012-04-03 14:22:34 -0700218 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700219 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
220 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700221 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700222
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800223 private final BroadcastReceiver mCloseSystemDialogsReceiver
224 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800225 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
226
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800227 private LayoutInflater mInflater;
228
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800229 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700230 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800231 private DragLayer mDragLayer;
232 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700233 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700234
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700235 private AppWidgetManager mAppWidgetManager;
236 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700237
Michael Jurkac9d95c52011-08-29 14:03:34 -0700238 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700239 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800240 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700241
Michael Jurka0280c3b2010-09-17 15:00:07 -0700242 private int[] mTmpAddItemCellCoordinates = new int[2];
243
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800244 private FolderInfo mFolderInfo;
245
Winson Chung3d503fb2011-07-13 17:25:49 -0700246 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700247 private View mOverviewPanel;
248
Michael Jurka838a4ca2011-02-07 13:33:06 -0800249 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700250
Winson Chungc51db6a2011-10-05 11:44:49 -0700251 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700252 private AppsCustomizeTabHost mAppsCustomizeTabHost;
253 private AppsCustomizePagedView mAppsCustomizeContent;
254 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100255 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800256
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800257 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700258 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
259 // scroll issues (because the workspace may not have been measured yet) and extra work.
260 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
261 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800262
263 private SpannableStringBuilder mDefaultKeySsb = null;
264
Joe Onorato9c1289c2009-08-17 11:03:03 -0400265 private boolean mWorkspaceLoading = true;
266
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800267 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800268 private boolean mRestoring;
269 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700270 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800271
Michael Jurka1e2f4652013-07-08 18:03:46 -0700272 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700273 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
274
Winson Chung4a2afa32012-07-19 14:53:05 -0700275 // Keep track of whether the user has left launcher
276 private static boolean sPausedFromUserAction = false;
277
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800278 private Bundle mSavedInstanceState;
279
Joe Onorato9c1289c2009-08-17 11:03:03 -0400280 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800281 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800282 private boolean mUserPresent = true;
283 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700284 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800285 private boolean mAttached = false;
Winson Chungfa545132013-09-26 17:45:32 -0700286 private static final boolean DISABLE_CLINGS = false;
Winson Chunge6eabff2013-09-24 11:01:23 -0700287 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400288
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700289 private static LocaleConfiguration sLocaleConfiguration = null;
290
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700291 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700292
Adam Cohen61f560d2013-09-30 15:58:20 -0700293 private View.OnTouchListener mHapticFeedbackTouchListener;
294
Adam Cohended9f8d2010-11-03 13:25:16 -0700295 // Related to the auto-advancing of widgets
296 private final int ADVANCE_MSG = 1;
297 private final int mAdvanceInterval = 20000;
298 private final int mAdvanceStagger = 250;
299 private long mAutoAdvanceSentTime;
300 private long mAutoAdvanceTimeLeft = -1;
301 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
302 new HashMap<View, AppWidgetProviderInfo>();
303
Winson Chung400438b2011-01-16 17:53:48 -0800304 // Determines how long to wait after a rotation before restoring the screen orientation to
305 // match the sensor state.
306 private final int mRestoreScreenOrientationDelay = 500;
307
Michael Jurka4ef207b2010-11-29 17:05:45 -0800308 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700309 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
310 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
311 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800312
Winson Chungd64a6662013-09-30 11:06:59 -0700313 private Intent mAppMarketIntent = null;
314 private static final boolean DISABLE_MARKET_BUTTON = true;
315
Craig Mautner360310b2012-10-26 15:13:08 -0700316 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700317
Adam Cohen1462de32012-07-24 22:34:36 -0700318 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700319 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700320
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700321 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700322 static Date sDateStamp = new Date();
323 static DateFormat sDateFormat =
324 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
325 static long sRunStart = System.currentTimeMillis();
326 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700327
Winson Chung46353de2012-02-16 14:05:10 -0800328 // We only want to get the SharedPreferences once since it does an FS stat each time we get
329 // it from the context.
330 private SharedPreferences mSharedPrefs;
331
Adam Cohene25af792013-06-06 23:08:25 -0700332 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
333
Winson Chungf0c6ae02012-03-21 16:10:31 -0700334 // Holds the page that we need to animate to, and the icon views that we need to animate up
335 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700336 private ImageView mFolderIconImageView;
337 private Bitmap mFolderIconBitmap;
338 private Canvas mFolderIconCanvas;
339 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700340
Michael Jurkaddd62e92011-02-16 17:49:14 -0800341 private BubbleTextView mWaitingForResume;
342
Michael Jurka22143132012-10-04 17:42:38 +0200343 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
344 = new HideFromAccessibilityHelper();
345
Michael Jurkac1f5d262011-09-30 19:32:27 -0700346 private Runnable mBuildLayersRunnable = new Runnable() {
347 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700348 if (mWorkspace != null) {
349 mWorkspace.buildPageHardwareLayers();
350 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700351 }
352 };
353
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800354 private static ArrayList<PendingAddArguments> sPendingAddList
355 = new ArrayList<PendingAddArguments>();
356
Michael Jurka7267fa52013-09-26 15:29:57 -0700357 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800358
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800359 private static class PendingAddArguments {
360 int requestCode;
361 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700362 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700363 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800364 int cellX;
365 int cellY;
366 }
367
Daniel Sandlerff02d492013-08-05 02:12:05 -0400368 private Stats mStats;
369
Michael Jurka0a457bf2012-11-19 14:05:05 -0800370 private static boolean isPropertyEnabled(String propertyName) {
371 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700372 }
373
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800374 @Override
375 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700376 if (DEBUG_STRICT_MODE) {
377 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
378 .detectDiskReads()
379 .detectDiskWrites()
380 .detectNetwork() // or .detectAll() for all detectable problems
381 .penaltyLog()
382 .build());
383 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
384 .detectLeakedSqlLiteObjects()
385 .detectLeakedClosableObjects()
386 .penaltyLog()
387 .penaltyDeath()
388 .build());
389 }
390
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800391 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400392
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400393 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400394 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700395
396 // Determine the dynamic grid properties
397 Point smallestSize = new Point();
398 Point largestSize = new Point();
399 Point realSize = new Point();
400 Display display = getWindowManager().getDefaultDisplay();
401 display.getCurrentSizeRange(smallestSize, largestSize);
402 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700403 DisplayMetrics dm = new DisplayMetrics();
404 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700405
Winson Chung5f8afe62013-08-12 16:19:28 -0700406 // Lazy-initialize the dynamic grid
407 DeviceProfile grid = app.initDynamicGrid(this,
408 Math.min(smallestSize.x, smallestSize.y),
409 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700410 realSize.x, realSize.y,
411 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700412
413 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400414 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700415 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800416 mModel = app.setLauncher(this);
417 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700418 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400419 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800420 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700421
Daniel Sandlerff02d492013-08-05 02:12:05 -0400422 mStats = new Stats(this);
423
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700424 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700425
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700426 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
427 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700428
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700429 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
430 // this also ensures that any synchronous binding below doesn't re-trigger another
431 // LauncherModel load.
432 mPaused = false;
433
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800434 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200435 android.os.Debug.startMethodTracing(
436 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800437 }
438
Adam Cohen53805212013-10-01 10:39:23 -0700439
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800440 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800441 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700442
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800443 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100444 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800445
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800446 registerContentObservers();
447
Joe Onorato7c312c12009-08-13 21:36:53 -0700448 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700449
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800450 mSavedState = savedInstanceState;
451 restoreState(mSavedState);
452
453 if (PROFILE_STARTUP) {
454 android.os.Debug.stopMethodTracing();
455 }
456
457 if (!mRestoring) {
Winson Chung6e1c0d32013-10-25 15:24:24 -0700458 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE || sPausedFromUserAction) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700459 // If the user leaves launcher, then we should just load items asynchronously when
460 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500461 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700462 } else {
463 // We only load the page synchronously if the user rotates (or triggers a
464 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800465 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700466 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800467 }
468
469 // For handling default keys
470 mDefaultKeySsb = new SpannableStringBuilder();
471 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800472
473 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
474 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800475
Adam Cohenf9426d52012-06-04 17:26:21 -0700476 updateGlobalIcons();
477
478 // On large interfaces, we want the screen to auto-rotate based on the current orientation
479 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700480
481 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700482 }
483
Winson Chung4a2afa32012-07-19 14:53:05 -0700484 protected void onUserLeaveHint() {
485 super.onUserLeaveHint();
486 sPausedFromUserAction = true;
487 }
488
Winson Chung98ca0f72013-07-29 12:58:51 -0700489 /** To be overriden by subclasses to hint to Launcher that we have custom content */
490 protected boolean hasCustomContentToLeft() {
491 return false;
492 }
493
Dave Hawkeya8881582013-09-17 15:55:33 -0600494 /**
495 * To be overridden by subclasses to create the custom content and call
496 * {@link #addToCustomContentPage}. This will only be invoked if
497 * {@link #hasCustomContentToLeft()} is {@code true}.
498 */
499 protected void addCustomContentToLeft() {
500 }
501
502 /**
503 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
504 * ensure the custom content page is added or removed if necessary.
505 */
506 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600507 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600508 // Not bound yet, wait for bindScreens to be called.
509 return;
510 }
511
512 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
513 // Create the custom content page and call the subclass to populate it.
514 mWorkspace.createCustomContentPage();
515 addCustomContentToLeft();
516 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
517 mWorkspace.removeCustomContentPage();
518 }
519 }
520
Adam Cohenf9426d52012-06-04 17:26:21 -0700521 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700522 boolean searchVisible = false;
523 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800524 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700525 int coi = getCurrentOrientationIndexForGlobalIcons();
526 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
527 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700528 if (!DISABLE_MARKET_BUTTON) {
529 updateAppMarketIcon();
530 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700531 searchVisible = updateGlobalSearchIcon();
532 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700533 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700534 if (sGlobalSearchIcon[coi] != null) {
535 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700536 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700537 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700538 if (sVoiceSearchIcon[coi] != null) {
539 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700540 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700541 }
Winson Chungd64a6662013-09-30 11:06:59 -0700542 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700543 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800544 }
Winson Chungadf0c182012-08-23 14:59:07 -0700545 if (mSearchDropTargetBar != null) {
546 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
547 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800548 }
Romain Guycbb89e42009-06-08 15:52:54 -0700549
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800550 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700551 if (sLocaleConfiguration == null) {
552 new AsyncTask<Void, Void, LocaleConfiguration>() {
553 @Override
554 protected LocaleConfiguration doInBackground(Void... unused) {
555 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
556 readConfiguration(Launcher.this, localeConfiguration);
557 return localeConfiguration;
558 }
559
560 @Override
561 protected void onPostExecute(LocaleConfiguration result) {
562 sLocaleConfiguration = result;
563 checkForLocaleChange(); // recursive, but now with a locale configuration
564 }
565 }.execute();
566 return;
567 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700568
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800569 final Configuration configuration = getResources().getConfiguration();
570
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700571 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800572 final String locale = configuration.locale.toString();
573
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700574 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800575 final int mcc = configuration.mcc;
576
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700577 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800578 final int mnc = configuration.mnc;
579
Romain Guy84f296c2009-11-04 15:00:44 -0800580 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800581
Romain Guy84f296c2009-11-04 15:00:44 -0800582 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700583 sLocaleConfiguration.locale = locale;
584 sLocaleConfiguration.mcc = mcc;
585 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700586
Joe Onorato0589f0f2010-02-08 13:44:00 -0800587 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700588
589 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100590 new AsyncTask<Void, Void, Void>() {
591 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700592 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100593 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700594 }
Michael Jurka43467462013-11-14 12:03:58 +0100595 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700596 }
597 }
598
599 private static class LocaleConfiguration {
600 public String locale;
601 public int mcc = -1;
602 public int mnc = -1;
603 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700604
Romain Guy98d01652009-06-30 16:21:04 -0700605 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
606 DataInputStream in = null;
607 try {
608 in = new DataInputStream(context.openFileInput(PREFERENCES));
609 configuration.locale = in.readUTF();
610 configuration.mcc = in.readInt();
611 configuration.mnc = in.readInt();
612 } catch (FileNotFoundException e) {
613 // Ignore
614 } catch (IOException e) {
615 // Ignore
616 } finally {
617 if (in != null) {
618 try {
619 in.close();
620 } catch (IOException e) {
621 // Ignore
622 }
623 }
624 }
625 }
626
627 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
628 DataOutputStream out = null;
629 try {
630 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
631 out.writeUTF(configuration.locale);
632 out.writeInt(configuration.mcc);
633 out.writeInt(configuration.mnc);
634 out.flush();
635 } catch (FileNotFoundException e) {
636 // Ignore
637 } catch (IOException e) {
638 //noinspection ResultOfMethodCallIgnored
639 context.getFileStreamPath(PREFERENCES).delete();
640 } finally {
641 if (out != null) {
642 try {
643 out.close();
644 } catch (IOException e) {
645 // Ignore
646 }
647 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800648 }
649 }
650
Anton Hanssona2f665f2013-09-26 12:18:32 +0100651 public Stats getStats() {
652 return mStats;
653 }
654
Bjorn Bringertc459e522013-06-07 19:36:01 +0100655 public LayoutInflater getInflater() {
656 return mInflater;
657 }
658
Adam Cohen716b51e2011-06-30 12:09:54 -0700659 public DragLayer getDragLayer() {
660 return mDragLayer;
661 }
662
Winson Chung36a62fe2012-05-06 18:04:42 -0700663 boolean isDraggingEnabled() {
664 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
665 // that is subsequently removed from the workspace in startBinding().
666 return !mModel.isLoadingWorkspace();
667 }
668
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800669 static int getScreen() {
670 synchronized (sLock) {
671 return sScreen;
672 }
673 }
674
675 static void setScreen(int screen) {
676 synchronized (sLock) {
677 sScreen = screen;
678 }
679 }
680
Winson Chung557d6ed2011-07-08 15:34:52 -0700681 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000682 * Copied from View -- the View version of the method isn't called
683 * anywhere else in our process and only exists for API level 17+,
684 * so it's ok to keep our own version with no API requirement.
685 */
686 public static int generateViewId() {
687 for (;;) {
688 final int result = sNextGeneratedId.get();
689 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
690 int newValue = result + 1;
691 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
692 if (sNextGeneratedId.compareAndSet(result, newValue)) {
693 return result;
694 }
695 }
696 }
697
698 public int getViewIdForItem(ItemInfo info) {
699 // This cast is safe given the > 2B range for int.
700 int itemId = (int) info.id;
701 if (mItemIdToViewId.containsKey(itemId)) {
702 return mItemIdToViewId.get(itemId);
703 }
704 int viewId = generateViewId();
705 mItemIdToViewId.put(itemId, viewId);
706 return viewId;
707 }
708
709 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700710 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
711 * a configuration step, this allows the proper animations to run after other transitions.
712 */
713 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700714 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800715 switch (args.requestCode) {
716 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700717 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700718 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800719 break;
720 case REQUEST_PICK_SHORTCUT:
721 processShortcut(args.intent);
722 break;
723 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700724 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700725 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700726 result = true;
727 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800728 case REQUEST_CREATE_APPWIDGET:
729 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700730 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700731 result = true;
732 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800733 }
Michael Jurka27614d22012-04-02 06:40:22 -0700734 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
735 // if you turned the screen off and then back while in All Apps, Launcher would not
736 // return to the workspace. Clearing mAddInfo.container here fixes this issue
737 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700738 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800739 }
740
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800741 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700742 protected void onActivityResult(
743 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700744 // Reset the startActivity waiting flag
745 mWaitingForResult = false;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800746 int pendingAddWidgetId = mPendingAddWidgetId;
747 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700748
Adam Cohenad4e15c2013-10-17 16:21:35 -0700749 Runnable exitSpringLoaded = new Runnable() {
750 @Override
751 public void run() {
752 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
753 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
754 }
755 };
756
Michael Jurka8b805b12012-04-18 14:23:14 -0700757 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700758 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700759 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
760 if (resultCode == RESULT_CANCELED) {
761 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700762 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
763 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700764 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700765 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
766 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700767 }
768 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200769 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
770 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
771 mWorkspace.exitOverviewMode(false);
772 }
773 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700774 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200775
Adam Cohened66b2b2012-01-23 17:28:51 -0800776 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
777 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700778
Adam Cohened66b2b2012-01-23 17:28:51 -0800779 // We have special handling for widgets
780 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800781 final int appWidgetId;
782 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
783 : -1;
784 if (widgetId < 0) {
785 appWidgetId = pendingAddWidgetId;
786 } else {
787 appWidgetId = widgetId;
788 }
789
Adam Cohenad4e15c2013-10-17 16:21:35 -0700790 final int result;
791 final Runnable onComplete;
Adam Cohenf0129b12013-11-04 17:57:36 -0800792 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Winson Chung5aaab772012-04-27 15:24:02 -0700793 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
794 "widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700795 result = RESULT_CANCELED;
796 completeTwoStageWidgetDrop(result, appWidgetId);
797 onComplete = new Runnable() {
798 @Override
799 public void run() {
800 exitSpringLoadedDragModeDelayed(false, 0, null);
801 }
802 };
Winson Chung5aaab772012-04-27 15:24:02 -0700803 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700804 result = resultCode;
Adam Cohen917e3882013-10-31 15:03:35 -0700805 final CellLayout dropLayout =
806 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
807 dropLayout.setDropPending(true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700808 onComplete = new Runnable() {
809 @Override
810 public void run() {
811 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohen917e3882013-10-31 15:03:35 -0700812 dropLayout.setDropPending(false);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700813 }
814 };
Winson Chung5aaab772012-04-27 15:24:02 -0700815 }
Adam Cohenad4e15c2013-10-17 16:21:35 -0700816 mWorkspace.removeExtraEmptyScreen(true, onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
817 false);
Adam Cohened66b2b2012-01-23 17:28:51 -0800818 return;
819 }
820
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800821 // The pattern used here is that a user PICKs a specific application,
822 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700823
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800824 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
825 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700826 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800827 final PendingAddArguments args = new PendingAddArguments();
828 args.requestCode = requestCode;
829 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700830 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700831 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700832 args.cellX = mPendingAddInfo.cellX;
833 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800834 if (isWorkspaceLocked()) {
835 sPendingAddList.add(args);
836 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700837 completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800838 }
Adam Cohenad4e15c2013-10-17 16:21:35 -0700839 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
840 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Adam Cohen00074722013-10-11 17:46:09 -0700841 } else if (resultCode == RESULT_CANCELED) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700842 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
843 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800844 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800845 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800846 }
847
848 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700849 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700850 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800851 Runnable onCompleteRunnable = null;
852 int animationType = 0;
853
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700854 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800855 if (resultCode == RESULT_OK) {
856 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
857 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700858 mPendingAddWidgetInfo);
859 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800860 onCompleteRunnable = new Runnable() {
861 @Override
862 public void run() {
863 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700864 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700865 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
866 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800867 }
868 };
869 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800870 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800871 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800872 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700873 if (mDragLayer.getAnimatedView() != null) {
874 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
875 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
876 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700877 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700878 // The animated view may be null in the case of a rotation during widget configuration
879 onCompleteRunnable.run();
880 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800881 }
882
883 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700884 protected void onStop() {
885 super.onStop();
886 FirstFrameAnimatorHelper.setIsVisible(false);
887 }
888
889 @Override
890 protected void onStart() {
891 super.onStart();
892 FirstFrameAnimatorHelper.setIsVisible(true);
893 }
894
895 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800896 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200897 long startTime = 0;
898 if (DEBUG_RESUME_TIME) {
899 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400900 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200901 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800902 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700903
Winson Chung4a2afa32012-07-19 14:53:05 -0700904 // Restore the previous launcher state
905 if (mOnResumeState == State.WORKSPACE) {
906 showWorkspace(false);
907 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c62013-11-06 15:49:51 -0800908 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700909 }
910 mOnResumeState = State.NONE;
911
Craig Mautner360310b2012-10-26 15:13:08 -0700912 // Background was set to gradient in onPause(), restore to black if in all apps.
913 setWorkspaceBackground(mState == State.WORKSPACE);
914
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800915 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700916 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700917 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400918 mWorkspaceLoading = true;
Derek Prothro7aff3992013-12-10 14:00:37 -0500919 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400920 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700921 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800922 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700923 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200924 // We might have postponed some bind calls until onResume (see waitUntilResume) --
925 // execute them here
926 long startTimeCallbacks = 0;
927 if (DEBUG_RESUME_TIME) {
928 startTimeCallbacks = System.currentTimeMillis();
929 }
930
931 if (mAppsCustomizeContent != null) {
932 mAppsCustomizeContent.setBulkBind(true);
933 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700934 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
935 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200936 }
937 if (mAppsCustomizeContent != null) {
938 mAppsCustomizeContent.setBulkBind(false);
939 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700940 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200941 if (DEBUG_RESUME_TIME) {
942 Log.d(TAG, "Time spent processing callbacks in onResume: " +
943 (System.currentTimeMillis() - startTimeCallbacks));
944 }
Michael Jurka447bf842013-05-15 14:52:15 +0200945 }
Michael Jurka54554252013-08-01 12:52:23 +0200946 if (mOnResumeCallbacks.size() > 0) {
947 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
948 mOnResumeCallbacks.get(i).run();
949 }
950 mOnResumeCallbacks.clear();
951 }
Winson Chunge4e50662012-01-23 14:45:13 -0800952
953 // Reset the pressed state of icons that were locked in the press state while activities
954 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800955 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800956 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800957 mWaitingForResume.setStayPressed(false);
958 }
Winson Chunge4e50662012-01-23 14:45:13 -0800959 if (mAppsCustomizeContent != null) {
960 // Resets the previous all apps icon press state
961 mAppsCustomizeContent.resetDrawableState();
962 }
Winson Chung82963d52013-10-09 11:20:57 -0700963
Adam Cohen06dff352012-06-01 17:17:08 -0700964 // It is possible that widgets can receive updates while launcher is not in the foreground.
965 // Consequently, the widgets will be inflated in the orientation of the foreground activity
966 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
967 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700968 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700969
Winson Chung780fe592013-09-26 14:48:44 -0700970 // Process any items that were added while Launcher was away.
971 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
972
Winson Chung5841efa2013-09-30 18:06:44 -0700973 // Update the voice search button proxy
974 updateVoiceButtonProxyVisible(false);
975
Adam Cohenf9426d52012-06-04 17:26:21 -0700976 // Again, as with the above scenario, it's possible that one or more of the global icons
977 // were updated in the wrong orientation.
978 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200979 if (DEBUG_RESUME_TIME) {
980 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
981 }
Adam Cohen6fecd412013-10-02 17:41:50 -0700982
983 if (mWorkspace.getCustomContentCallbacks() != null) {
984 // If we are resuming and the custom content is the current page, we call onShow().
985 // It is also poassible that onShow will instead be called slightly after first layout
986 // if PagedView#setRestorePage was set to the custom content page in onCreate().
987 if (mWorkspace.isOnOrMovingToCustomContent()) {
988 mWorkspace.getCustomContentCallbacks().onShow();
989 }
990 }
Adam Cohenedaaa302013-10-01 17:33:27 -0700991 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -0700992 mWorkspace.onResume();
Adam Cohen06dff352012-06-01 17:17:08 -0700993 }
994
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800995 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700996 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -0700997 // Ensure that items added to Launcher are queued until Launcher returns
998 InstallShortcutReceiver.enableInstallQueue();
999
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001000 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001001 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001002 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001003 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001004
1005 // We call onHide() aggressively. The custom content callbacks should be able to
1006 // debounce excess onHide calls.
1007 if (mWorkspace.getCustomContentCallbacks() != null) {
1008 mWorkspace.getCustomContentCallbacks().onHide();
1009 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001010 }
Romain Guycbb89e42009-06-08 15:52:54 -07001011
Adam Cohen66a01fd2013-06-11 12:48:00 -07001012 protected void onFinishBindingItems() {
Adam Cohen82398362013-09-29 12:57:34 -07001013 if (mWorkspace != null && hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
Dave Hawkeya8881582013-09-17 15:55:33 -06001014 addCustomContentToLeft();
1015 }
Adam Cohen66a01fd2013-06-11 12:48:00 -07001016 }
1017
Adam Cohenbffe7452013-07-22 18:21:45 -07001018 QSBScroller mQsbScroller = new QSBScroller() {
1019 int scrollY = 0;
1020
1021 @Override
1022 public void setScrollY(int scroll) {
1023 scrollY = scroll;
1024
1025 if (mWorkspace.isOnOrMovingToCustomContent()) {
1026 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001027 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001028 }
1029 }
1030 };
1031
1032 public void resetQSBScroll() {
1033 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001034 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001035 }
1036
1037 public interface CustomContentCallbacks {
1038 // Custom content is completely shown
1039 public void onShow();
1040
1041 // Custom content is completely hidden
1042 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001043
1044 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1045 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -07001046 }
1047
Adam Cohen30bacb22013-08-29 14:25:25 -07001048 protected void startSettings() {
1049 }
1050
Adam Cohenbffe7452013-07-22 18:21:45 -07001051 public interface QSBScroller {
1052 public void setScrollY(int scrollY);
1053 }
1054
Winson Chung98ca0f72013-07-29 12:58:51 -07001055 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001056 CustomContentCallbacks callbacks, String description) {
1057 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001058 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001059 }
1060
Adam Cohenedb40762013-07-18 16:45:45 -07001061 // The custom content needs to offset its content to account for the QSB
1062 public int getTopOffsetForCustomContent() {
1063 return mWorkspace.getPaddingTop();
1064 }
1065
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001066 @Override
1067 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001068 // Flag the loader to stop early before switching
1069 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001070 if (mAppsCustomizeContent != null) {
1071 mAppsCustomizeContent.surrender();
1072 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001073 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001074 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001075
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001076 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001077 @Override
1078 public void onWindowFocusChanged(boolean hasFocus) {
1079 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001080 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001081 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001082
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001083 private boolean acceptFilter() {
1084 final InputMethodManager inputManager = (InputMethodManager)
1085 getSystemService(Context.INPUT_METHOD_SERVICE);
1086 return !inputManager.isFullscreenMode();
1087 }
1088
1089 @Override
1090 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001091 final int uniChar = event.getUnicodeChar();
1092 final boolean handled = super.onKeyDown(keyCode, event);
1093 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1094 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001095 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1096 keyCode, event);
1097 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001098 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001099 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001100 // showSearchDialog()
1101 // If there are multiple keystrokes before the search dialog takes focus,
1102 // onSearchRequested() will be called for every keystroke,
1103 // but it is idempotent, so it's fine.
1104 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001105 }
1106 }
1107
Joe Onorato8a9625e2010-01-28 15:55:35 -08001108 // Eat the long press event so the keyboard doesn't come up.
1109 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1110 return true;
1111 }
1112
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001113 return handled;
1114 }
1115
Karl Rosaen138a0412009-04-23 19:00:21 -07001116 private String getTypedText() {
1117 return mDefaultKeySsb.toString();
1118 }
1119
1120 private void clearTypedText() {
1121 mDefaultKeySsb.clear();
1122 mDefaultKeySsb.clearSpans();
1123 Selection.setSelection(mDefaultKeySsb, 0);
1124 }
1125
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001126 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001127 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1128 * State
1129 */
1130 private static State intToState(int stateOrdinal) {
1131 State state = State.WORKSPACE;
1132 final State[] stateValues = State.values();
1133 for (int i = 0; i < stateValues.length; i++) {
1134 if (stateValues[i].ordinal() == stateOrdinal) {
1135 state = stateValues[i];
1136 break;
1137 }
1138 }
1139 return state;
1140 }
1141
1142 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001143 * Restores the previous state, if it exists.
1144 *
1145 * @param savedState The previous state.
1146 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001147 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001148 private void restoreState(Bundle savedState) {
1149 if (savedState == null) {
1150 return;
1151 }
1152
Michael Jurka883f55b2010-10-21 15:47:14 -07001153 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001154 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001155 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001156 }
1157
Adam Cohen21cd0022013-10-09 18:57:02 -07001158 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1159 PagedView.INVALID_RESTORE_PAGE);
1160 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001161 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001162 }
1163
Winson Chung3d503fb2011-07-13 17:25:49 -07001164 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001165 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001166
Winson Chung3d503fb2011-07-13 17:25:49 -07001167 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1168 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001169 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001170 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1171 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001172 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1173 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1174 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001175 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001176 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001177 mRestoring = true;
1178 }
1179
1180 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1181 if (renameFolder) {
1182 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001183 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001184 mRestoring = true;
1185 }
Winson Chunga12a2502010-12-20 14:41:35 -08001186
Winson Chung785d2eb2011-04-14 16:08:02 -07001187 // Restore the AppsCustomize tab
1188 if (mAppsCustomizeTabHost != null) {
1189 String curTab = savedState.getString("apps_customize_currentTab");
1190 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001191 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001192 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001193 mAppsCustomizeContent.loadAssociatedPages(
1194 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001195 }
1196
Winson Chung5afbf7b2011-07-25 11:53:08 -07001197 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1198 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001199 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001200 mItemIdToViewId = (HashMap<Integer, Integer>)
1201 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001202 }
1203
1204 /**
1205 * Finds all the views we need and configure them properly.
1206 */
1207 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001208 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001209
Craig Mautner360310b2012-10-26 15:13:08 -07001210 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001211 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1212 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001213
John Spurlock77e1f472013-09-11 10:09:51 -04001214 mLauncherView.setSystemUiVisibility(
1215 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001216 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001217
Winson Chung4c98d922011-05-31 16:50:48 -07001218 // Setup the drag layer
1219 mDragLayer.setup(this, dragController);
1220
Winson Chung3d503fb2011-07-13 17:25:49 -07001221 // Setup the hotseat
1222 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1223 if (mHotseat != null) {
1224 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001225 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001226 }
1227
Adam Cohenf358a4b2013-07-23 16:47:31 -07001228 mOverviewPanel = findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001229 View widgetButton = findViewById(R.id.widget_button);
1230 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001231 @Override
1232 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001233 if (!mWorkspace.isSwitchingState()) {
1234 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
1235 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001236 }
1237 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001238 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1239
1240 View wallpaperButton = findViewById(R.id.wallpaper_button);
1241 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001242 @Override
1243 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001244 if (!mWorkspace.isSwitchingState()) {
1245 startWallpaper();
1246 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001247 }
1248 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001249 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1250
1251 View settingsButton = findViewById(R.id.settings_button);
1252 settingsButton.setOnClickListener(new OnClickListener() {
Adam Cohen30bacb22013-08-29 14:25:25 -07001253 @Override
1254 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001255 if (!mWorkspace.isSwitchingState()) {
1256 startSettings();
1257 }
Adam Cohen30bacb22013-08-29 14:25:25 -07001258 }
1259 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001260 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
Adam Cohendbdff6b2013-09-18 19:09:15 -07001261 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001262
Winson Chung4c98d922011-05-31 16:50:48 -07001263 // Setup the workspace
1264 mWorkspace.setHapticFeedbackEnabled(false);
1265 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001266 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001267 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001268
Winson Chungf0ea4d32011-06-06 14:27:16 -07001269 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001270 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001271
Winson Chungf0ea4d32011-06-06 14:27:16 -07001272 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001273 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001274 mAppsCustomizeContent = (AppsCustomizePagedView)
1275 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1276 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001277
Winson Chung3d503fb2011-07-13 17:25:49 -07001278 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001279 dragController.setDragScoller(mWorkspace);
1280 dragController.setScrollView(mDragLayer);
1281 dragController.setMoveTarget(mWorkspace);
1282 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001283 if (mSearchDropTargetBar != null) {
1284 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001285 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001286
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001287 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001288 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001289 mWeightWatcher = new WeightWatcher(this);
1290 mWeightWatcher.setAlpha(0.5f);
1291 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001292 new FrameLayout.LayoutParams(
1293 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001294 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001295 Gravity.BOTTOM)
1296 );
Adam Cohen39a06042013-07-19 14:30:12 -07001297
1298 boolean show = shouldShowWeightWatcher();
1299 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001300 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001301 }
1302
1303 /**
1304 * Creates a view representing a shortcut.
1305 *
1306 * @param info The data structure describing the shortcut.
1307 *
1308 * @return A View inflated from R.layout.application.
1309 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001310 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001311 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001312 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001313 }
1314
1315 /**
1316 * Creates a view representing a shortcut inflated from the specified resource.
1317 *
1318 * @param layoutResId The id of the XML layout used to create the shortcut.
1319 * @param parent The group the shortcut belongs to.
1320 * @param info The data structure describing the shortcut.
1321 *
1322 * @return A View inflated from layoutResId.
1323 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001324 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001325 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1326 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001327 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001328 return favorite;
1329 }
1330
1331 /**
1332 * Add an application shortcut to the workspace.
1333 *
1334 * @param data The intent describing the application.
1335 * @param cellInfo The position on screen where to create the shortcut.
1336 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001337 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001338 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001339 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001340
Adam Cohenfbba09b2011-07-18 21:43:05 -07001341 // First we check if we already know the exact location where we want to add this item.
1342 if (cellX >= 0 && cellY >= 0) {
1343 cellXY[0] = cellX;
1344 cellXY[1] = cellY;
1345 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001346 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001347 return;
1348 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001349
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001350 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001351
Romain Guy73b979d2009-06-09 12:57:21 -07001352 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001353 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001354 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001355 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001356 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001357 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001358 } else {
1359 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001360 }
1361 }
Romain Guycbb89e42009-06-08 15:52:54 -07001362
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001363 /**
1364 * Add a shortcut to the workspace.
1365 *
1366 * @param data The intent describing the shortcut.
1367 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001368 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001369 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001370 int cellY) {
1371 int[] cellXY = mTmpAddItemCellCoordinates;
1372 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001373 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001374
Michael Jurkad3ef3062010-11-23 16:23:58 -08001375 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001376
Adam Cohen558baaf2011-08-15 15:22:57 -07001377 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001378 if (info == null) {
1379 return;
1380 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001381 final View view = createShortcut(info);
1382
Adam Cohenfbba09b2011-07-18 21:43:05 -07001383 // First we check if we already know the exact location where we want to add this item.
1384 if (cellX >= 0 && cellY >= 0) {
1385 cellXY[0] = cellX;
1386 cellXY[1] = cellY;
1387 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001388
1389 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001390 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001391 true, null,null)) {
1392 return;
1393 }
1394 DragObject dragObject = new DragObject();
1395 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001396 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1397 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001398 return;
1399 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001400 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001401 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001402 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001403 foundCellSpan = (result != null);
1404 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001405 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001406 }
1407
1408 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001409 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001410 return;
1411 }
1412
Adam Cohendcd297f2013-06-18 13:13:40 -07001413 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414
1415 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001416 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001417 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001418 }
1419 }
1420
Adam Cohen2f093b62012-04-30 18:59:53 -07001421 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1422 int minHeight) {
1423 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001424 // We want to account for the extra amount of padding that we are adding to the widget
1425 // to ensure that it gets the full amount of space that it has requested
1426 int requiredWidth = minWidth + padding.left + padding.right;
1427 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001428 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001429 }
1430
Adam Cohen2f093b62012-04-30 18:59:53 -07001431 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1432 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001433 }
1434
Adam Cohen2f093b62012-04-30 18:59:53 -07001435 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1436 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001437 }
1438
Adam Cohen2f093b62012-04-30 18:59:53 -07001439 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1440 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001441 }
1442
Adam Cohen2f093b62012-04-30 18:59:53 -07001443 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1444 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001445 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001446 }
1447
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001448 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001449 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001450 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001451 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001452 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001453 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001454 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001455 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1456 if (appWidgetInfo == null) {
1457 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1458 }
Romain Guycbb89e42009-06-08 15:52:54 -07001459
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001460 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001461 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001462
Adam Cohen2f093b62012-04-30 18:59:53 -07001463 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1464 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001465
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001466 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001467 // We have saved the position to which the widget was dragged-- this really only matters
1468 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001469 int[] cellXY = mTmpAddItemCellCoordinates;
1470 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001471 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001472 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001473 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1474 cellXY[0] = mPendingAddInfo.cellX;
1475 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001476 spanXY[0] = mPendingAddInfo.spanX;
1477 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001478 foundCellSpan = true;
1479 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001480 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001481 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001482 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1483 spanXY[1], cellXY, finalSpan);
1484 spanXY[0] = finalSpan[0];
1485 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001486 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001487 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001488 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001489 }
1490
Michael Jurka0280c3b2010-09-17 15:00:07 -07001491 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001492 if (appWidgetId != -1) {
1493 // Deleting an app widget ID is a void call but writes to disk before returning
1494 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001495 new AsyncTask<Void, Void, Void>() {
1496 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001497 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001498 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001499 }
Michael Jurka43467462013-11-14 12:03:58 +01001500 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001501 }
Winson Chung93eef082012-03-23 15:59:27 -07001502 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001503 return;
1504 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001505
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001506 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001507 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1508 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001509 launcherInfo.spanX = spanXY[0];
1510 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001511 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1512 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001513
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001514 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001515 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001516
1517 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001518 if (hostView == null) {
1519 // Perform actual inflation because we're live
1520 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1521 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1522 } else {
1523 // The AppWidgetHostView has already been inflated and instantiated
1524 launcherInfo.hostView = hostView;
1525 }
Romain Guycbb89e42009-06-08 15:52:54 -07001526
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001527 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001528 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001529 launcherInfo.notifyWidgetSizeChanged(this);
1530
Adam Cohendcd297f2013-06-18 13:13:40 -07001531 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001532 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001533
1534 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001535 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001536 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001537 }
Romain Guycbb89e42009-06-08 15:52:54 -07001538
Adam Cohended9f8d2010-11-03 13:25:16 -07001539 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1540 @Override
1541 public void onReceive(Context context, Intent intent) {
1542 final String action = intent.getAction();
1543 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1544 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001545 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001546 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001547
Winson Chungc100e8e2011-08-09 16:02:43 -07001548 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001549 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001550 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001551 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001552 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001553 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1554 mUserPresent = true;
1555 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001556 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1557 mModel.resetLoadedState(false, true);
1558 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1559 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1560 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1561 mModel.resetLoadedState(false, true);
1562 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1563 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1564 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Adam Cohended9f8d2010-11-03 13:25:16 -07001565 }
1566 }
1567 };
1568
1569 @Override
1570 public void onAttachedToWindow() {
1571 super.onAttachedToWindow();
1572
1573 // Listen for broadcasts related to user-presence
1574 final IntentFilter filter = new IntentFilter();
1575 filter.addAction(Intent.ACTION_SCREEN_OFF);
1576 filter.addAction(Intent.ACTION_USER_PRESENT);
Dan Sandlerd5024042014-01-09 15:01:33 -05001577 if (ENABLE_DEBUG_INTENTS) {
1578 filter.addAction(DebugIntents.DELETE_DATABASE);
1579 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1580 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001581 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001582 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001583 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001584 mVisible = true;
1585 }
1586
1587 @Override
1588 public void onDetachedFromWindow() {
1589 super.onDetachedFromWindow();
1590 mVisible = false;
1591
Adam Cohend113e0c2010-11-11 10:48:05 -08001592 if (mAttached) {
1593 unregisterReceiver(mReceiver);
1594 mAttached = false;
1595 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001596 updateRunning();
1597 }
1598
1599 public void onWindowVisibilityChanged(int visibility) {
1600 mVisible = visibility == View.VISIBLE;
1601 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001602 // The following code used to be in onResume, but it turns out onResume is called when
1603 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1604 // is a more appropriate event to handle
1605 if (mVisible) {
1606 mAppsCustomizeTabHost.onWindowVisible();
1607 if (!mWorkspaceLoading) {
1608 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001609 // We want to let Launcher draw itself at least once before we force it to build
1610 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001611 // apps is nice and speedy.
1612 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001613 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001614 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001615 if (mStarted) return;
1616 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001617 // We delay the layer building a bit in order to give
1618 // other message processing a time to run. In particular
1619 // this avoids a delay in hiding the IME if it was
1620 // currently shown, because doing that may involve
1621 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001622 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001623 final ViewTreeObserver.OnDrawListener listener = this;
1624 mWorkspace.post(new Runnable() {
1625 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001626 if (mWorkspace != null &&
1627 mWorkspace.getViewTreeObserver() != null) {
1628 mWorkspace.getViewTreeObserver().
1629 removeOnDrawListener(listener);
1630 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001631 }
1632 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001633 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001634 }
1635 });
1636 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001637 // When Launcher comes back to foreground, a different Activity might be responsible for
1638 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001639 if (!DISABLE_MARKET_BUTTON) {
1640 updateAppMarketIcon();
1641 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001642 clearTypedText();
1643 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001644 }
1645
1646 private void sendAdvanceMessage(long delay) {
1647 mHandler.removeMessages(ADVANCE_MSG);
1648 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1649 mHandler.sendMessageDelayed(msg, delay);
1650 mAutoAdvanceSentTime = System.currentTimeMillis();
1651 }
1652
1653 private void updateRunning() {
1654 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1655 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1656 mAutoAdvanceRunning = autoAdvanceRunning;
1657 if (autoAdvanceRunning) {
1658 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1659 sendAdvanceMessage(delay);
1660 } else {
1661 if (!mWidgetsToAdvance.isEmpty()) {
1662 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1663 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1664 }
1665 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001666 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001667 }
1668 }
1669 }
1670
1671 private final Handler mHandler = new Handler() {
1672 @Override
1673 public void handleMessage(Message msg) {
1674 if (msg.what == ADVANCE_MSG) {
1675 int i = 0;
1676 for (View key: mWidgetsToAdvance.keySet()) {
1677 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1678 final int delay = mAdvanceStagger * i;
1679 if (v instanceof Advanceable) {
1680 postDelayed(new Runnable() {
1681 public void run() {
1682 ((Advanceable) v).advance();
1683 }
1684 }, delay);
1685 }
1686 i++;
1687 }
1688 sendAdvanceMessage(mAdvanceInterval);
1689 }
1690 }
1691 };
1692
1693 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001694 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001695 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1696 if (v instanceof Advanceable) {
1697 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001698 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001699 updateRunning();
1700 }
1701 }
1702
1703 void removeWidgetToAutoAdvance(View hostView) {
1704 if (mWidgetsToAdvance.containsKey(hostView)) {
1705 mWidgetsToAdvance.remove(hostView);
1706 updateRunning();
1707 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001708 }
1709
Joe Onorato9c1289c2009-08-17 11:03:03 -04001710 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001711 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001712 launcherInfo.hostView = null;
1713 }
1714
Winson Chung93eef082012-03-23 15:59:27 -07001715 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1716 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1717 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001718 }
1719
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001720 public LauncherAppWidgetHost getAppWidgetHost() {
1721 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001722 }
Romain Guycbb89e42009-06-08 15:52:54 -07001723
Winson Chunga9abd0e2010-10-27 17:18:37 -07001724 public LauncherModel getModel() {
1725 return mModel;
1726 }
1727
Bjorn Bringertc459e522013-06-07 19:36:01 +01001728 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001729 getWindow().closeAllPanels();
1730
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001731 // Whatever we were doing is hereby canceled.
1732 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001733 }
1734
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001735 @Override
1736 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001737 long startTime = 0;
1738 if (DEBUG_RESUME_TIME) {
1739 startTime = System.currentTimeMillis();
1740 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001741 super.onNewIntent(intent);
1742
1743 // Close the menu
1744 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001745 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001746 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001747
Adam Cohened307df2013-10-02 09:37:31 -07001748 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1749 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1750 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001751
Adam Cohen6fecd412013-10-02 17:41:50 -07001752 if (mWorkspace == null) {
1753 // Can be cases where mWorkspace is null, this prevents a NPE
1754 return;
1755 }
1756 Folder openFolder = mWorkspace.getOpenFolder();
1757 // In all these cases, only animate if we're already on home
1758 mWorkspace.exitWidgetResizeMode();
1759 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001760 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001761 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001762 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001763
Adam Cohen6fecd412013-10-02 17:41:50 -07001764 closeFolder();
1765 exitSpringLoadedDragMode();
1766
1767 // If we are already on home, then just animate back to the workspace,
1768 // otherwise, just wait until onResume to set the state back to Workspace
1769 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001770 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001771 } else {
1772 mOnResumeState = State.WORKSPACE;
1773 }
1774
1775 final View v = getWindow().peekDecorView();
1776 if (v != null && v.getWindowToken() != null) {
1777 InputMethodManager imm = (InputMethodManager)getSystemService(
1778 INPUT_METHOD_SERVICE);
1779 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1780 }
1781
1782 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001783 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001784 mAppsCustomizeTabHost.reset();
1785 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001786
1787 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001788 }
Adam Cohened307df2013-10-02 09:37:31 -07001789
Michael Jurka447bf842013-05-15 14:52:15 +02001790 if (DEBUG_RESUME_TIME) {
1791 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1792 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001793 }
1794
Adam Coppa120b8e2013-11-12 16:26:04 +00001795 /**
1796 * Override point for subclasses to prevent movement to the default screen when the home
1797 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1798 */
1799 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1800 return true;
1801 }
1802
1803 /**
1804 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1805 */
1806 protected void onHomeIntent() {
1807 // Do nothing
1808 }
1809
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001810 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001811 public void onRestoreInstanceState(Bundle state) {
1812 super.onRestoreInstanceState(state);
1813 for (int page: mSynchronouslyBoundPages) {
1814 mWorkspace.restoreInstanceStateForChild(page);
1815 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001816 }
1817
1818 @Override
1819 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001820 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001821 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1822 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001823 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001824 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001825
Michael Jurka883f55b2010-10-21 15:47:14 -07001826 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001827 // We close any open folder since it will not be re-opened, and we need to make sure
1828 // this state is reflected.
1829 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001830
Adam Cohendcd297f2013-06-18 13:13:40 -07001831 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001832 mWaitingForResult) {
1833 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001834 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001835 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1836 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001837 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1838 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1839 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001840 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001841 }
1842
1843 if (mFolderInfo != null && mWaitingForResult) {
1844 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1845 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1846 }
Michael Jurka946ad472010-07-09 18:05:18 -07001847
Winson Chung785d2eb2011-04-14 16:08:02 -07001848 // Save the current AppsCustomize tab
1849 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c62013-11-06 15:49:51 -08001850 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1851 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001852 if (currentTabTag != null) {
1853 outState.putString("apps_customize_currentTab", currentTabTag);
1854 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001855 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1856 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001857 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001858 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001859 }
1860
1861 @Override
1862 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001863 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001864
Winson Chunge7a03942011-08-05 15:05:12 -07001865 // Remove all pending runnables
1866 mHandler.removeMessages(ADVANCE_MSG);
1867 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001868 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001869
Winson Chungcd2b0142011-06-08 16:02:26 -07001870 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001871 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001872 mModel.stopLoader();
1873 app.setLauncher(null);
1874
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001875 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001876 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001877 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001878 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001879 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001880 mAppWidgetHost = null;
1881
1882 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001883
1884 TextKeyListener.getInstance().release();
1885
Winson Chung81b52252012-08-27 15:34:29 -07001886 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1887 // to prevent leaking Launcher activities on orientation change.
1888 if (mModel != null) {
1889 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1890 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001891
1892 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001893 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001894
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001895 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001896 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08001897 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001898 mWorkspace = null;
1899 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001900
Michael Jurka2ecf9952012-06-18 12:52:28 -07001901 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001902 }
1903
Adam Cohena9cf38f2011-05-02 15:36:58 -07001904 public DragController getDragController() {
1905 return mDragController;
1906 }
1907
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001908 @Override
1909 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001910 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001911 super.startActivityForResult(intent, requestCode);
1912 }
1913
Winson Chung70d72102011-08-12 11:24:35 -07001914 /**
1915 * Indicates that we want global search for this activity by setting the globalSearch
1916 * argument for {@link #startSearch} to true.
1917 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001918 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001919 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001920 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001921
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001922 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001923
Karl Rosaen138a0412009-04-23 19:00:21 -07001924 if (initialQuery == null) {
1925 // Use any text typed in the launcher as the initial query
1926 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001927 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001928 if (appSearchData == null) {
1929 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001930 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001931 }
Winson Chungadf0c182012-08-23 14:59:07 -07001932 Rect sourceBounds = new Rect();
1933 if (mSearchDropTargetBar != null) {
1934 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1935 }
Romain Guycbb89e42009-06-08 15:52:54 -07001936
Bjorn Bringertc459e522013-06-07 19:36:01 +01001937 startSearch(initialQuery, selectInitialQuery,
1938 appSearchData, sourceBounds);
1939 }
1940
1941 public void startSearch(String initialQuery,
1942 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001943 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001944 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001945 }
1946
1947 /**
1948 * Starts the global search activity. This code is a copied from SearchManager
1949 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001950 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001951 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001952 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001953 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1954 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1955 if (globalSearchActivity == null) {
1956 Log.w(TAG, "No global search activity found.");
1957 return;
1958 }
1959 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1960 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1961 intent.setComponent(globalSearchActivity);
1962 // Make sure that we have a Bundle to put source in
1963 if (appSearchData == null) {
1964 appSearchData = new Bundle();
1965 } else {
1966 appSearchData = new Bundle(appSearchData);
1967 }
1968 // Set source to package name of app that starts global search, if not set already.
1969 if (!appSearchData.containsKey("source")) {
1970 appSearchData.putString("source", getPackageName());
1971 }
1972 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1973 if (!TextUtils.isEmpty(initialQuery)) {
1974 intent.putExtra(SearchManager.QUERY, initialQuery);
1975 }
1976 if (selectInitialQuery) {
1977 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1978 }
1979 intent.setSourceBounds(sourceBounds);
1980 try {
1981 startActivity(intent);
1982 } catch (ActivityNotFoundException ex) {
1983 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1984 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001985 }
1986
Winson Chung70d72102011-08-12 11:24:35 -07001987 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001988 public boolean onPrepareOptionsMenu(Menu menu) {
1989 super.onPrepareOptionsMenu(menu);
Dan Sandler14c6a3f2014-01-07 14:12:27 -05001990 showOverviewMode(true);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001991 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001992 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001993
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001994 @Override
1995 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001996 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001997 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07001998 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001999 }
2000
Joe Onorato9c1289c2009-08-17 11:03:03 -04002001 public boolean isWorkspaceLocked() {
2002 return mWorkspaceLoading || mWaitingForResult;
2003 }
2004
Michael Jurka0280c3b2010-09-17 15:00:07 -07002005 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002006 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002007 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002008 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2009 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002010 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002011 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002012 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002013
Adam Cohenad4e15c2013-10-17 16:21:35 -07002014 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2015 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2016 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2017 }
2018
2019 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2020 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2021 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002022 if (appWidgetInfo.configure != null) {
2023 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002024 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002025
Bjorn Bringert7984c942009-12-09 15:38:25 +00002026 // Launch over to configure widget, if needed
2027 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002028 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002029 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002030 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002032 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002033 Runnable onComplete = new Runnable() {
2034 @Override
2035 public void run() {
2036 // Exit spring loaded mode if necessary after adding the widget
2037 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2038 null);
2039 }
2040 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002041 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002042 appWidgetInfo);
Adam Cohenad4e15c2013-10-17 16:21:35 -07002043 mWorkspace.removeExtraEmptyScreen(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002044 }
2045 }
Romain Guycbb89e42009-06-08 15:52:54 -07002046
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002047 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002048 // Close any folders that may be open.
2049 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002050 mWorkspace.moveToCustomContentScreen(animate);
2051 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002052 /**
2053 * Process a shortcut drop.
2054 *
2055 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002056 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002057 * @param cell The cell it should be added to, optional
2058 * @param position The location on the screen where it was dropped, optional
2059 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002060 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002061 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002062 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002063 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002064 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002065 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002066
2067 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002068 mPendingAddInfo.cellX = cell[0];
2069 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002070 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002071
2072 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2073 createShortcutIntent.setComponent(componentName);
2074 processShortcut(createShortcutIntent);
2075 }
2076
Adam Cohenfbba09b2011-07-18 21:43:05 -07002077 /**
2078 * Process a widget drop.
2079 *
2080 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002081 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002082 * @param cell The cell it should be added to, optional
2083 * @param position The location on the screen where it was dropped, optional
2084 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002085 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002086 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002087 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002088 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002089 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002090 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002091 mPendingAddInfo.minSpanX = info.minSpanX;
2092 mPendingAddInfo.minSpanY = info.minSpanY;
2093
Adam Cohenfbba09b2011-07-18 21:43:05 -07002094 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002095 mPendingAddInfo.cellX = cell[0];
2096 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002097 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002098 if (span != null) {
2099 mPendingAddInfo.spanX = span[0];
2100 mPendingAddInfo.spanY = span[1];
2101 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002102
Adam Cohened66b2b2012-01-23 17:28:51 -08002103 AppWidgetHostView hostView = info.boundWidget;
2104 int appWidgetId;
2105 if (hostView != null) {
2106 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002107 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002108 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002109 // In this case, we either need to start an activity to get permission to bind
2110 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002111 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002112 Bundle options = info.bindOptions;
2113
2114 boolean success = false;
2115 if (options != null) {
2116 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2117 info.componentName, options);
2118 } else {
2119 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2120 info.componentName);
2121 }
2122 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002123 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002124 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002125 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002126 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2127 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2128 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002129 // TODO: we need to make sure that this accounts for the options bundle.
2130 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002131 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2132 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002133 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002134 }
2135
Joe Onoratodeb98af2010-02-19 14:59:39 -08002136 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002137 // Handle case where user selected "Applications"
2138 String applicationName = getResources().getString(R.string.group_applications);
2139 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002140
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002141 if (applicationName != null && applicationName.equals(shortcutName)) {
2142 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2143 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002144
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002145 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2146 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002147 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002148 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002149 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002150 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002151 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002152 }
2153
Winson Chung24ab2f12010-09-16 14:10:47 -07002154 void processWallpaper(Intent intent) {
2155 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2156 }
2157
Adam Cohendcd297f2013-06-18 13:13:40 -07002158 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002159 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002160 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002161 folderInfo.title = getText(R.string.folder_name);
2162
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002163 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002164 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002165 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002166 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002167
2168 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002169 FolderIcon newFolder =
2170 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002171 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002172 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002173 // Force measure the new folder icon
2174 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2175 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002176 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002177 }
Romain Guycbb89e42009-06-08 15:52:54 -07002178
Joe Onorato9c1289c2009-08-17 11:03:03 -04002179 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002180 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002181 }
2182
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002183 protected void startWallpaper() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002184 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002185 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002186 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002187 }
2188
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002189 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002190 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002191 }
2192
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002193 /**
2194 * Registers various content observers. The current implementation registers
2195 * only a favorites observer to keep track of the favorites applications.
2196 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002197 private void registerContentObservers() {
2198 ContentResolver resolver = getContentResolver();
2199 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2200 true, mWidgetObserver);
2201 }
2202
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002203 @Override
2204 public boolean dispatchKeyEvent(KeyEvent event) {
2205 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2206 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002207 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002208 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002209 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002210 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002211 dumpState();
2212 return true;
2213 }
2214 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002215 }
2216 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2217 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002218 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002219 return true;
2220 }
2221 }
2222
2223 return super.dispatchKeyEvent(event);
2224 }
2225
Joe Onorato88ec0992009-11-19 13:16:06 -08002226 @Override
2227 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002228 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002229 if (mAppsCustomizeContent.getContentType() ==
2230 AppsCustomizePagedView.ContentType.Applications) {
2231 showWorkspace(true);
2232 } else {
2233 showOverviewMode(true);
2234 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002235 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002236 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002237 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002238 Folder openFolder = mWorkspace.getOpenFolder();
2239 if (openFolder.isEditingName()) {
2240 openFolder.dismissEditingName();
2241 } else {
2242 closeFolder();
2243 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002244 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002245 mWorkspace.exitWidgetResizeMode();
2246
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002247 // Back button is a no-op here, but give at least some feedback for the button press
2248 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002249 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002250 }
2251
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002252 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002253 * Re-listen when widgets are reset.
2254 */
2255 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002256 if (mAppWidgetHost != null) {
2257 mAppWidgetHost.startListening();
2258 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002259 }
2260
2261 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002262 * Launches the intent referred by the clicked shortcut.
2263 *
2264 * @param v The view representing the clicked shortcut.
2265 */
2266 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002267 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2268 // view has detached (it's possible for this to happen if the view is removed mid touch).
2269 if (v.getWindowToken() == null) {
2270 return;
2271 }
2272
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002273 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002274 return;
2275 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002276
Adam Cohen1697b792013-09-17 19:08:21 -07002277 if (v instanceof Workspace) {
2278 if (mWorkspace.isInOverviewMode()) {
2279 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002280 }
2281 return;
2282 }
2283
2284 if (v instanceof CellLayout) {
2285 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002286 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002287 }
2288 }
2289
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002290 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002291 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002292 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002293 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2294 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002295
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002296 // Check for special shortcuts
2297 if (intent.getComponent() != null) {
2298 final String shortcutClass = intent.getComponent().getClassName();
2299
2300 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chung82963d52013-10-09 11:20:57 -07002301 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002302 return;
2303 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2304 MemoryDumpActivity.startDump(this);
2305 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002306 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2307 toggleShowWeightWatcher();
2308 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002309 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002310 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002311
2312 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002313 int[] pos = new int[2];
2314 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002315 intent.setSourceBounds(new Rect(pos[0], pos[1],
2316 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002317
2318 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002319
Daniel Sandlerff02d492013-08-05 02:12:05 -04002320 mStats.recordLaunch(intent, shortcut);
2321
Michael Jurkaddd62e92011-02-16 17:49:14 -08002322 if (success && v instanceof BubbleTextView) {
2323 mWaitingForResume = (BubbleTextView) v;
2324 mWaitingForResume.setStayPressed(true);
2325 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002326 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002327 if (v instanceof FolderIcon) {
2328 FolderIcon fi = (FolderIcon) v;
2329 handleFolderClick(fi);
2330 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002331 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002332 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002333 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002334 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002335 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002336 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002337 }
2338 }
2339
Michael Jurka0e260592010-06-30 17:07:39 -07002340 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002341 return false;
2342 }
2343
Michael Jurkaaf442092010-06-10 17:01:57 -07002344 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002345 * Event handler for the search button
2346 *
2347 * @param v The view that was clicked.
2348 */
2349 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002350 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2351
Amith Yamasania135ba82011-08-09 17:42:01 -07002352 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002353 }
2354
2355 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002356 * Event handler for the voice button
2357 *
2358 * @param v The view that was clicked.
2359 */
2360 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002361 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002362
Bjorn Bringertc459e522013-06-07 19:36:01 +01002363 startVoice();
2364 }
2365
2366 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002367 try {
2368 final SearchManager searchManager =
2369 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2370 ComponentName activityName = searchManager.getGlobalSearchActivity();
2371 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002372 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002373 if (activityName != null) {
2374 intent.setPackage(activityName.getPackageName());
2375 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002376 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002377 } catch (ActivityNotFoundException e) {
2378 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002379 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002380 startActivitySafely(null, intent, "onClickVoiceButton");
2381 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002382 }
2383
2384 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002385 * Event handler for the "grid" button that appears on the home screen, which
2386 * enters all apps mode.
2387 *
2388 * @param v The view that was clicked.
2389 */
2390 public void onClickAllAppsButton(View v) {
Winson Chunge7e97e62013-12-02 17:02:50 -08002391 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
Michael Jurka5130e402011-10-13 04:55:35 -07002392 }
2393
2394 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002395 // Provide the same haptic feedback that the system offers for virtual keys.
2396 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002397 }
2398
Adam Cohen61f560d2013-09-30 15:58:20 -07002399 public void performHapticFeedbackOnTouchDown(View v) {
2400 // Provide the same haptic feedback that the system offers for virtual keys.
2401 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2402 }
2403
2404 public View.OnTouchListener getHapticFeedbackTouchListener() {
2405 if (mHapticFeedbackTouchListener == null) {
2406 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2407 @Override
2408 public boolean onTouch(View v, MotionEvent event) {
2409 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2410 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2411 }
2412 return false;
2413 }
2414 };
2415 }
2416 return mHapticFeedbackTouchListener;
2417 }
2418
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002419 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002420 if (!DISABLE_MARKET_BUTTON) {
2421 if (mAppMarketIntent != null) {
2422 startActivitySafely(v, mAppMarketIntent, "app market");
2423 } else {
2424 Log.e(TAG, "Invalid app market intent.");
2425 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002426 }
2427 }
2428
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002429 /**
2430 * Called when the user stops interacting with the launcher.
2431 * This implies that the user is now on the homescreen and is not doing housekeeping.
2432 */
2433 protected void onInteractionEnd() {}
2434
2435 /**
2436 * Called when the user starts interacting with the launcher.
2437 * The possible interactions are:
2438 * - open all apps
2439 * - reorder an app shortcut, or a widget
2440 * - open the overview mode.
2441 * This is a good time to stop doing things that only make sense
2442 * when the user is on the homescreen and not doing housekeeping.
2443 */
2444 protected void onInteractionBegin() {}
2445
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002446 void startApplicationDetailsActivity(ComponentName componentName) {
2447 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002448 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2449 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002450 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002451 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002452 }
2453
Michael Jurka1e2f4652013-07-08 18:03:46 -07002454 // returns true if the activity was started
2455 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002456 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002457 // System applications cannot be installed. For now, show a toast explaining that.
2458 // We may give them the option of disabling apps this way.
2459 int messageId = R.string.uninstall_system_app_text;
2460 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002461 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002462 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002463 String packageName = componentName.getPackageName();
2464 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002465 Intent intent = new Intent(
2466 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002467 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2468 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002469 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002470 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002471 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002472 }
2473
Michael Jurka86a720e2012-05-09 11:23:23 -07002474 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002475 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002476
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002477 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002478 // Only launch using the new animation if the shortcut has not opted out (this is a
2479 // private contract between launcher and may be ignored in the future).
2480 boolean useLaunchAnimation = (v != null) &&
2481 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2482 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002483 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2484 v.getMeasuredWidth(), v.getMeasuredHeight());
2485
2486 startActivity(intent, opts.toBundle());
2487 } else {
2488 startActivity(intent);
2489 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002490 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002491 } catch (SecurityException e) {
2492 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002493 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002494 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002495 "or use the exported attribute for this activity. "
2496 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002497 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002498 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002499 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002500
Michael Jurka86a720e2012-05-09 11:23:23 -07002501 boolean startActivitySafely(View v, Intent intent, Object tag) {
2502 boolean success = false;
2503 try {
2504 success = startActivity(v, intent, tag);
2505 } catch (ActivityNotFoundException e) {
2506 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2507 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2508 }
2509 return success;
2510 }
2511
Adam Cohena9cf38f2011-05-02 15:36:58 -07002512 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002513 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002514 Folder openFolder = mWorkspace.getFolderForTag(info);
2515
2516 // If the folder info reports that the associated folder is open, then verify that
2517 // it is actually opened. There have been a few instances where this gets out of sync.
2518 if (info.opened && openFolder == null) {
2519 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002520 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002521 info.opened = false;
2522 }
2523
Adam Cohenfb91f302012-06-11 15:45:18 -07002524 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002525 // Close any open folder
2526 closeFolder();
2527 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002528 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002529 } else {
2530 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002531 int folderScreen;
2532 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002533 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002534 // .. and close it
2535 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002536 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002537 // Close any folder open on the current screen
2538 closeFolder();
2539 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002540 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002541 }
2542 }
2543 }
2544 }
2545
Adam Cohen268c4752012-06-06 17:47:33 -07002546 /**
2547 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2548 * in the DragLayer in the exact absolute location of the original FolderIcon.
2549 */
2550 private void copyFolderIconToImage(FolderIcon fi) {
2551 final int width = fi.getMeasuredWidth();
2552 final int height = fi.getMeasuredHeight();
2553
2554 // Lazy load ImageView, Bitmap and Canvas
2555 if (mFolderIconImageView == null) {
2556 mFolderIconImageView = new ImageView(this);
2557 }
2558 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2559 mFolderIconBitmap.getHeight() != height) {
2560 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2561 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2562 }
2563
2564 DragLayer.LayoutParams lp;
2565 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2566 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2567 } else {
2568 lp = new DragLayer.LayoutParams(width, height);
2569 }
2570
Adam Cohen307fe232012-08-16 17:55:58 -07002571 // The layout from which the folder is being opened may be scaled, adjust the starting
2572 // view size by this scale factor.
2573 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002574 lp.customPosition = true;
2575 lp.x = mRectForFolderAnimation.left;
2576 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002577 lp.width = (int) (scale * width);
2578 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002579
2580 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2581 fi.draw(mFolderIconCanvas);
2582 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002583 if (fi.getFolder() != null) {
2584 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2585 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002586 }
Adam Cohen268c4752012-06-06 17:47:33 -07002587 // Just in case this image view is still in the drag layer from a previous animation,
2588 // we remove it and re-add it.
2589 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2590 mDragLayer.removeView(mFolderIconImageView);
2591 }
2592 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002593 if (fi.getFolder() != null) {
2594 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002595 }
Adam Cohen268c4752012-06-06 17:47:33 -07002596 }
2597
Adam Cohen2801caf2011-05-13 20:57:39 -07002598 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002599 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002600 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2601 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2602 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2603
Adam Cohenc51934b2011-07-26 21:07:43 -07002604 FolderInfo info = (FolderInfo) fi.getTag();
2605 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2606 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002607 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2608 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002609 }
2610
Adam Cohen268c4752012-06-06 17:47:33 -07002611 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2612 copyFolderIconToImage(fi);
2613 fi.setVisibility(View.INVISIBLE);
2614
Michael Jurka2ecf9952012-06-18 12:52:28 -07002615 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002616 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002617 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2618 oa.start();
2619 }
2620
Adam Cohen268c4752012-06-06 17:47:33 -07002621 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002622 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002623 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2624 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2625 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2626
Adam Cohen268c4752012-06-06 17:47:33 -07002627 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002628
Adam Cohen268c4752012-06-06 17:47:33 -07002629 // We remove and re-draw the FolderIcon in-case it has changed
2630 mDragLayer.removeView(mFolderIconImageView);
2631 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002632 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002633 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002634 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002635 oa.addListener(new AnimatorListenerAdapter() {
2636 @Override
2637 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002638 if (cl != null) {
2639 cl.clearFolderLeaveBehind();
2640 // Remove the ImageView copy of the FolderIcon and make the original visible.
2641 mDragLayer.removeView(mFolderIconImageView);
2642 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002643 }
2644 }
2645 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002646 oa.start();
2647 }
2648
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002649 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002650 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002651 * is animated relative to the specified View. If the View is null, no animation
2652 * is played.
2653 *
2654 * @param folderInfo The FolderInfo describing the folder to open.
2655 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002656 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002657 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002658 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002659
Adam Cohena9cf38f2011-05-02 15:36:58 -07002660 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002661
Adam Cohen4554ee12011-08-03 16:13:21 -07002662 // Just verify that the folder hasn't already been added to the DragLayer.
2663 // There was a one-off crash where the folder had a parent already.
2664 if (folder.getParent() == null) {
2665 mDragLayer.addView(folder);
2666 mDragController.addDropTarget((DropTarget) folder);
2667 } else {
2668 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2669 folder.getParent() + ").");
2670 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002671 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002672 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002673
2674 // Notify the accessibility manager that this folder "window" has appeared and occluded
2675 // the workspace items
2676 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2677 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002678 }
2679
2680 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002681 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002682 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002683 if (folder.isEditingName()) {
2684 folder.dismissEditingName();
2685 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002686 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002687
2688 // Dismiss the folder cling
2689 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002690 }
2691 }
2692
2693 void closeFolder(Folder folder) {
2694 folder.getInfo().opened = false;
2695
2696 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2697 if (parent != null) {
2698 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2699 shrinkAndFadeInFolderIcon(fi);
2700 }
2701 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002702
2703 // Notify the accessibility manager that this folder "window" has disappeard and no
2704 // longer occludeds the workspace items
2705 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002706 }
2707
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002708 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002709 if (!isDraggingEnabled()) return false;
2710 if (isWorkspaceLocked()) return false;
2711 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002712
Adam Cohen1697b792013-09-17 19:08:21 -07002713 if (v instanceof Workspace) {
2714 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002715 if (mWorkspace.enterOverviewMode()) {
2716 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2717 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2718 return true;
2719 } else {
2720 return false;
2721 }
Adam Cohen1697b792013-09-17 19:08:21 -07002722 }
Adam Cohen1697b792013-09-17 19:08:21 -07002723 }
2724
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002725 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002726 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002727 }
2728
Michael Jurka0280c3b2010-09-17 15:00:07 -07002729 resetAddInfo();
2730 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002731 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002732 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002733 return true;
2734 }
2735
Winson Chung3d503fb2011-07-13 17:25:49 -07002736 // The hotseat touch handling does not go through Workspace, and we always allow long press
2737 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002738 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002739 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2740 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002741 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002742 // User long pressed on empty space
2743 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2744 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2745 // Disabling reordering until we sort out some issues.
2746 if (mWorkspace.isInOverviewMode()) {
2747 mWorkspace.startReordering(v);
2748 } else {
2749 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002750 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002751 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002752 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002753 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002754 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002755 }
2756 }
2757 }
2758 return true;
2759 }
2760
Winson Chung3d503fb2011-07-13 17:25:49 -07002761 boolean isHotseatLayout(View layout) {
2762 return mHotseat != null && layout != null &&
2763 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2764 }
2765 Hotseat getHotseat() {
2766 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002767 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002768 View getOverviewPanel() {
2769 return mOverviewPanel;
2770 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002771 SearchDropTargetBar getSearchBar() {
2772 return mSearchDropTargetBar;
2773 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002774
Winson Chung3d503fb2011-07-13 17:25:49 -07002775 /**
2776 * Returns the CellLayout of the specified container at the specified screen.
2777 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002778 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002779 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2780 if (mHotseat != null) {
2781 return mHotseat.getLayout();
2782 } else {
2783 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002784 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002785 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002786 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002787 }
2788 }
2789
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002790 Workspace getWorkspace() {
2791 return mWorkspace;
2792 }
2793
Daniel Sandler843e8602010-06-07 14:59:01 -04002794 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002795 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002796 }
2797
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002798 /**
2799 * Helper method for the cameraZoomIn/cameraZoomOut animations
2800 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002801 * @param scaleFactor The scale factor used for the zoom
2802 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002803 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002804 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002805 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002806 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002807
Craig Mautner360310b2012-10-26 15:13:08 -07002808 private void setWorkspaceBackground(boolean workspace) {
2809 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002810 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002811 }
2812
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002813 void updateWallpaperVisibility(boolean visible) {
2814 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2815 int curflags = getWindow().getAttributes().flags
2816 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2817 if (wpflags != curflags) {
2818 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2819 }
Craig Mautner360310b2012-10-26 15:13:08 -07002820 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002821 }
2822
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002823 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2824 if (v instanceof LauncherTransitionable) {
2825 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2826 }
2827 }
2828
Michael Jurkabed61d22012-02-14 22:51:29 -08002829 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2830 if (v instanceof LauncherTransitionable) {
2831 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2832 }
Winson Chung70442722012-02-10 15:43:22 -08002833
2834 // Update the workspace transition step as well
2835 dispatchOnLauncherTransitionStep(v, 0f);
2836 }
2837
2838 private void dispatchOnLauncherTransitionStep(View v, float t) {
2839 if (v instanceof LauncherTransitionable) {
2840 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2841 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002842 }
2843
2844 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2845 if (v instanceof LauncherTransitionable) {
2846 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2847 }
Winson Chung70442722012-02-10 15:43:22 -08002848
2849 // Update the workspace transition step as well
2850 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002851 }
2852
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002853 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002854 * Things to test when changing the following seven functions.
2855 * - Home from workspace
2856 * - from center screen
2857 * - from other screens
2858 * - Home from all apps
2859 * - from center screen
2860 * - from other screens
2861 * - Back from all apps
2862 * - from center screen
2863 * - from other screens
2864 * - Launch app from workspace and quit
2865 * - with back
2866 * - with home
2867 * - Launch app from all apps and quit
2868 * - with back
2869 * - with home
2870 * - Go to a screen that's not the default, then all
2871 * apps, and launch and app, and go back
2872 * - with back
2873 * -with home
2874 * - On workspace, long press power and go back
2875 * - with back
2876 * - with home
2877 * - On all apps, long press power and go back
2878 * - with back
2879 * - with home
2880 * - On workspace, power off
2881 * - On all apps, power off
2882 * - Launch an app and turn off the screen while in that app
2883 * - Go back with home key
2884 * - Go back with back key TODO: make this not go to workspace
2885 * - From all apps
2886 * - From workspace
2887 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2888 * - From all apps
2889 * - From the center workspace
2890 * - From another workspace
2891 */
2892
2893 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002894 * Zoom the camera out from the workspace to reveal 'toView'.
2895 * Assumes that the view to show is anchored at either the very top or very bottom
2896 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002897 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002898 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002899 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2900 showAppsCustomizeHelper(animated, springLoaded, contentType);
2901 }
2902 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2903 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002904 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002905 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002906 mStateAnimation.cancel();
2907 mStateAnimation = null;
2908 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002909 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002910
Winson Chungf0ea4d32011-06-06 14:27:16 -07002911 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2912 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2913 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002914 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002915 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002916 final int startDelay =
2917 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002918
Michael Jurkab3e22d92011-10-31 15:58:33 -07002919 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002920
Michael Jurkad74c9842011-07-10 12:44:21 -07002921 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002922 Animator workspaceAnim =
2923 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08002924 if (!AppsCustomizePagedView.DISABLE_ALL_APPS
2925 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
2926 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07002927 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2928 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002929
2930 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002931 toView.setScaleX(scale);
2932 toView.setScaleY(scale);
2933 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2934 scaleAnim.
2935 scaleX(1f).scaleY(1f).
2936 setDuration(duration).
2937 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002938
Winson Chungf0ea4d32011-06-06 14:27:16 -07002939 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002940 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002941 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002942 .ofFloat(toView, "alpha", 0f, 1f)
2943 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002944 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002945 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2946 @Override
2947 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002948 if (animation == null) {
2949 throw new RuntimeException("animation is null");
2950 }
Winson Chung70442722012-02-10 15:43:22 -08002951 float t = (Float) animation.getAnimatedValue();
2952 dispatchOnLauncherTransitionStep(fromView, t);
2953 dispatchOnLauncherTransitionStep(toView, t);
2954 }
2955 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002956
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002957 // toView should appear right at the end of the workspace shrink
2958 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002959 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002960 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002961 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002962
2963 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002964 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002965 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002966 // Prepare the position
2967 toView.setTranslationX(0.0f);
2968 toView.setTranslationY(0.0f);
2969 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002970 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002971 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002972 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002973 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002974 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2975 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002976
Winson Chungc7d2b602012-05-16 17:02:20 -07002977 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002978 if (mSearchDropTargetBar != null) {
2979 mSearchDropTargetBar.hideSearchBar(false);
2980 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002981 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002982 });
2983
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002984 if (workspaceAnim != null) {
2985 mStateAnimation.play(workspaceAnim);
2986 }
Michael Jurka1899a362011-11-03 13:50:45 -07002987
2988 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002989
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002990 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2991 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002992
2993 // If any of the objects being animated haven't been measured/laid out
2994 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08002995 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002996 (mWorkspace.getMeasuredWidth() == 0) ||
2997 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002998 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07002999 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003000
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003001 final AnimatorSet stateAnimation = mStateAnimation;
3002 final Runnable startAnimRunnable = new Runnable() {
3003 public void run() {
3004 // Check that mStateAnimation hasn't changed while
3005 // we waited for a layout/draw pass
3006 if (mStateAnimation != stateAnimation)
3007 return;
3008 setPivotsForZoom(toView, scale);
3009 dispatchOnLauncherTransitionStart(fromView, animated, false);
3010 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003011 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003012 }
3013 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003014 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003015 final ViewTreeObserver observer = toView.getViewTreeObserver();
3016 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3017 public void onGlobalLayout() {
3018 startAnimRunnable.run();
3019 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3020 }
3021 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003022 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003023 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003024 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003025 } else {
3026 toView.setTranslationX(0.0f);
3027 toView.setTranslationY(0.0f);
3028 toView.setScaleX(1.0f);
3029 toView.setScaleY(1.0f);
3030 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003031 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003032
Daniel Sandlere4f98912013-06-25 15:13:26 -04003033 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003034 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003035 if (mSearchDropTargetBar != null) {
3036 mSearchDropTargetBar.hideSearchBar(false);
3037 }
Michael Jurkaabded662011-03-04 12:06:57 -08003038 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003039 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003040 dispatchOnLauncherTransitionStart(fromView, animated, false);
3041 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003042 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003043 dispatchOnLauncherTransitionStart(toView, animated, false);
3044 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003045 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003046 }
3047
3048 /**
3049 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003050 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003051 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003052 */
Adam Cohened307df2013-10-02 09:37:31 -07003053 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003054 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003055
Michael Jurkab3e22d92011-10-31 15:58:33 -07003056 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003057 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003058 mStateAnimation.cancel();
3059 mStateAnimation = null;
3060 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003061 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003062
Winson Chungf0ea4d32011-06-06 14:27:16 -07003063 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08003064 final int fadeOutDuration =
3065 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003066 final float scaleFactor = (float)
3067 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3068 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003069 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003070 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003071 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003072 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
3073 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003074 toState, animated, stagger, -1);
3075 } else if (toState == Workspace.State.SPRING_LOADED ||
3076 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003077 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003078 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003079 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003080
Michael Jurkab3e22d92011-10-31 15:58:33 -07003081 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07003082 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003083 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08003084 final LauncherViewPropertyAnimator scaleAnim =
3085 new LauncherViewPropertyAnimator(fromView);
3086 scaleAnim.
3087 scaleX(scaleFactor).scaleY(scaleFactor).
3088 setDuration(duration).
3089 setInterpolator(new Workspace.ZoomInInterpolator());
3090
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003091 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003092 .ofFloat(fromView, "alpha", 1f, 0f)
3093 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07003094 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08003095 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3096 @Override
3097 public void onAnimationUpdate(ValueAnimator animation) {
3098 float t = 1f - (Float) animation.getAnimatedValue();
3099 dispatchOnLauncherTransitionStep(fromView, t);
3100 dispatchOnLauncherTransitionStep(toView, t);
3101 }
3102 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08003103
Michael Jurka2ecf9952012-06-18 12:52:28 -07003104 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08003105
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003106 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3107 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Adam Cohen4fe4c932013-10-28 16:02:34 -07003108 mAppsCustomizeContent.stopScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003109
3110 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003111 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003112 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003113 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003114 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3115 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003116 if (onCompleteRunnable != null) {
3117 onCompleteRunnable.run();
3118 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003119 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003120 }
3121 });
3122
Winson Chungf0ea4d32011-06-06 14:27:16 -07003123 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003124 if (workspaceAnim != null) {
3125 mStateAnimation.play(workspaceAnim);
3126 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003127 dispatchOnLauncherTransitionStart(fromView, animated, true);
3128 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003129 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003130 } else {
3131 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003132 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003133 dispatchOnLauncherTransitionStart(fromView, animated, true);
3134 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003135 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003136 dispatchOnLauncherTransitionStart(toView, animated, true);
3137 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003138 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003139 }
3140
Michael Jurkae326f182011-11-21 14:05:46 -08003141 @Override
3142 public void onTrimMemory(int level) {
3143 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003144 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003145 mAppsCustomizeTabHost.onTrimMemory();
3146 }
3147 }
3148
Adam Cohened307df2013-10-02 09:37:31 -07003149 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003150 showWorkspace(animated, null);
3151 }
3152
Adam Cohened307df2013-10-02 09:37:31 -07003153 protected void showWorkspace() {
3154 showWorkspace(true);
3155 }
3156
Adam Cohened66b2b2012-01-23 17:28:51 -08003157 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohened307df2013-10-02 09:37:31 -07003158 if (mWorkspace.isInOverviewMode()) {
3159 mWorkspace.exitOverviewMode(animated);
3160 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003161 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003162 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003163 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003164 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003165
Winson Chungc7d2b602012-05-16 17:02:20 -07003166 // Show the search bar (only animate if we were showing the drop target bar in spring
3167 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003168 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003169 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003170 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003171
Michael Jurkab3e22d92011-10-31 15:58:33 -07003172 // Set focus to the AppsCustomize button
3173 if (mAllAppsButton != null) {
3174 mAllAppsButton.requestFocus();
3175 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003176 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003177
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003178 // Change the state *after* we've called all the transition code
3179 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003180
Winson Chung5fb63472011-02-02 17:03:37 -08003181 // Resume the auto-advance of widgets
3182 mUserPresent = true;
3183 updateRunning();
3184
alanv1d4fde62012-10-17 13:15:47 -07003185 // Send an accessibility event to announce the context change
3186 getWindow().getDecorView()
3187 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003188
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003189 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003190 }
3191
Adam Cohened307df2013-10-02 09:37:31 -07003192 void showOverviewMode(boolean animated) {
3193 mWorkspace.setVisibility(View.VISIBLE);
3194 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3195 mState = State.WORKSPACE;
3196 onWorkspaceShown(animated);
3197 }
3198
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003199 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003200 }
3201
Winson Chung82963d52013-10-09 11:20:57 -07003202 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3203 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003204 if (mState != State.WORKSPACE) return;
3205
Winson Chung82963d52013-10-09 11:20:57 -07003206 if (resetPageToZero) {
3207 mAppsCustomizeTabHost.reset();
3208 }
Winson Chungc58497e2013-09-03 17:48:37 -07003209 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003210 mAppsCustomizeTabHost.requestFocus();
3211
Michael Jurkab3e22d92011-10-31 15:58:33 -07003212 // Change the state *after* we've called all the transition code
3213 mState = State.APPS_CUSTOMIZE;
3214
3215 // Pause the auto-advance of widgets until we are out of AllApps
3216 mUserPresent = false;
3217 updateRunning();
3218 closeFolder();
3219
3220 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003221 getWindow().getDecorView()
3222 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003223 }
3224
Adam Cohen7777d962011-08-18 18:58:38 -07003225 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003226 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003227 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003228 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003229 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003230 }
Adam Cohen7777d962011-08-18 18:58:38 -07003231
Adam Cohenad4e15c2013-10-17 16:21:35 -07003232 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003233 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003234 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3235
Winson Chunge7a03942011-08-05 15:05:12 -07003236 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003237 @Override
3238 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003239 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003240 // Before we show workspace, hide all apps again because
3241 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3242 // clean up our state transition functions
3243 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003244 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003245 } else {
3246 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003247 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003248 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003249 }, delay);
3250
Winson Chung557d6ed2011-07-08 15:34:52 -07003251 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003252
Michael Jurkad3ef3062010-11-23 16:23:58 -08003253 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003254 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003255 final boolean animated = true;
3256 final boolean springLoaded = true;
3257 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003258 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003259 }
3260 // Otherwise, we are not in spring loaded mode, so don't do anything.
3261 }
3262
Michael Jurkab3e22d92011-10-31 15:58:33 -07003263 void lockAllApps() {
3264 // TODO
3265 }
3266
3267 void unlockAllApps() {
3268 // TODO
3269 }
3270
Winson Chungf0ea4d32011-06-06 14:27:16 -07003271 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003272 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003273 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003274 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003275 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003276 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003277 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003278 int duration = 0;
3279 if (mSearchDropTargetBar != null) {
3280 duration = mSearchDropTargetBar.getTransitionInDuration();
3281 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003282 mHotseat.animate().alpha(1f).setDuration(duration);
3283 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003284 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003285 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003286 }
3287 }
3288 }
3289
3290 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003291 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003292 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003293 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003294 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003295 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003296 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003297 int duration = 0;
3298 if (mSearchDropTargetBar != null) {
3299 duration = mSearchDropTargetBar.getTransitionOutDuration();
3300 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003301 mHotseat.animate().alpha(0f).setDuration(duration);
3302 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003303 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003304 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003305 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003306 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003307 }
3308
Patrick Dubroy5f445422011-02-18 14:35:21 -08003309 /**
3310 * Add an item from all apps or customize onto the given workspace screen.
3311 * If layout is null, add to the current screen.
3312 */
3313 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003314 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003315 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003316 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003317 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003318
Winson Chungdff8ebb2011-09-08 17:25:31 -07003319 /** Maps the current orientation to an index for referencing orientation correct global icons */
3320 private int getCurrentOrientationIndexForGlobalIcons() {
3321 // default - 0, landscape - 1
3322 switch (getResources().getConfiguration().orientation) {
3323 case Configuration.ORIENTATION_LANDSCAPE:
3324 return 1;
3325 default:
3326 return 0;
3327 }
3328 }
3329
Michael Jurkaae65ee32012-04-30 11:45:54 -07003330 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003331 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003332 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003333 // Look for the toolbar icon specified in the activity meta-data
3334 Bundle metaData = packageManager.getActivityInfo(
3335 activityName, PackageManager.GET_META_DATA).metaData;
3336 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003337 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003338 if (iconResId != 0) {
3339 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003340 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003341 }
3342 }
3343 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003344 // This can happen if the activity defines an invalid drawable
3345 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3346 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003347 } catch (Resources.NotFoundException nfe) {
3348 // This can happen if the activity defines an invalid drawable
3349 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3350 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003351 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003352 return null;
3353 }
3354
3355 // if successful in getting icon, return it; otherwise, set button to use default drawable
3356 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003357 int buttonId, ComponentName activityName, int fallbackDrawableId,
3358 String toolbarResourceName) {
3359 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003360 Resources r = getResources();
3361 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3362 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003363
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003364 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003365 // If we were unable to find the icon via the meta-data, use a generic one
3366 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003367 toolbarIcon = r.getDrawable(fallbackDrawableId);
3368 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003369 if (button != null) {
3370 button.setCompoundDrawables(toolbarIcon, null, null, null);
3371 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003372 return null;
3373 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003374 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003375 if (button != null) {
3376 button.setCompoundDrawables(toolbarIcon, null, null, null);
3377 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003378 return toolbarIcon.getConstantState();
3379 }
3380 }
3381
3382 // if successful in getting icon, return it; otherwise, set button to use default drawable
3383 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003384 int buttonId, ComponentName activityName, int fallbackDrawableId,
3385 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003386 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003387 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003388
Michael Jurka19e0fc52011-07-22 18:00:21 -07003389 if (button != null) {
3390 // If we were unable to find the icon via the meta-data, use a
3391 // generic one
3392 if (toolbarIcon == null) {
3393 button.setImageResource(fallbackDrawableId);
3394 } else {
3395 button.setImageDrawable(toolbarIcon);
3396 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003397 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003398
3399 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3400
Michael Jurka0423dcf2010-10-05 14:56:18 -07003401 }
3402
Winson Chung1b884092012-06-08 17:13:02 -07003403 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003404 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003405 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003406 }
3407
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003408 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003409 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003410 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003411 }
3412
Winson Chungbb185bd2011-11-21 12:31:42 -08003413 private void invalidatePressedFocusedStates(View container, View button) {
3414 if (container instanceof HolographicLinearLayout) {
3415 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3416 layout.invalidatePressedFocusedStates();
3417 } else if (button instanceof HolographicImageView) {
3418 HolographicImageView view = (HolographicImageView) button;
3419 view.invalidatePressedFocusedStates();
3420 }
3421 }
3422
Cristina Stancu476493b2013-08-07 17:20:14 +01003423 public View getQsbBar() {
3424 if (mQsbBar == null) {
Winson Chung54e65132013-09-27 11:44:58 -07003425 mQsbBar = mInflater.inflate(R.layout.search_bar, mSearchDropTargetBar, false);
3426 mSearchDropTargetBar.addView(mQsbBar);
Cristina Stancu476493b2013-08-07 17:20:14 +01003427 }
3428 return mQsbBar;
3429 }
3430
3431 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003432 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003433 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003434 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003435 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003436
Winson Chung1cad91e2011-05-25 17:41:01 -07003437 final SearchManager searchManager =
3438 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3439 ComponentName activityName = searchManager.getGlobalSearchActivity();
3440 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003441 int coi = getCurrentOrientationIndexForGlobalIcons();
3442 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003443 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3444 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3445 if (sGlobalSearchIcon[coi] == null) {
3446 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3447 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3448 TOOLBAR_ICON_METADATA_NAME);
3449 }
3450
Winson Chungc51db6a2011-10-05 11:44:49 -07003451 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3452 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003453 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003454 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003455 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003456 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003457 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3458 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003459 if (searchButton != null) searchButton.setVisibility(View.GONE);
3460 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003461 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003462 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003463 }
3464 }
3465
Cristina Stancu476493b2013-08-07 17:20:14 +01003466 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003467 final View searchButtonContainer = findViewById(R.id.search_button_container);
3468 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003469 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003470 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003471 }
3472
Cristina Stancu476493b2013-08-07 17:20:14 +01003473 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003474 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003475 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003476
Winson Chungc51db6a2011-10-05 11:44:49 -07003477 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003478 final SearchManager searchManager =
3479 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3480 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3481
3482 ComponentName activityName = null;
3483 if (globalSearchActivity != null) {
3484 // Check if the global search activity handles voice search
3485 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3486 intent.setPackage(globalSearchActivity.getPackageName());
3487 activityName = intent.resolveActivity(getPackageManager());
3488 }
3489
3490 if (activityName == null) {
3491 // Fallback: check if an activity other than the global search activity
3492 // resolves this
3493 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3494 activityName = intent.resolveActivity(getPackageManager());
3495 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003496 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003497 int coi = getCurrentOrientationIndexForGlobalIcons();
3498 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003499 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3500 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3501 if (sVoiceSearchIcon[coi] == null) {
3502 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3503 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3504 TOOLBAR_ICON_METADATA_NAME);
3505 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003506 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003507 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003508 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003509 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003510 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003511 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003512 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003513 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003514 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003515 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003516 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003517 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003518
Cristina Stancu476493b2013-08-07 17:20:14 +01003519 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003520 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3521 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003522 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003523 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003524 }
3525
Winson Chung5841efa2013-09-30 18:06:44 -07003526 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003527 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3528 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003529 boolean visible = !forceDisableVoiceButtonProxy &&
3530 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003531 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003532 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003533 }
3534 }
Winson Chung5841efa2013-09-30 18:06:44 -07003535
3536 /**
3537 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3538 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3539 */
3540 public void disableVoiceButtonProxy(boolean disabled) {
3541 updateVoiceButtonProxyVisible(disabled);
3542 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003543 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003544 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003545 */
3546 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003547 if (!DISABLE_MARKET_BUTTON) {
3548 final View marketButton = findViewById(R.id.market_button);
3549 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3550 // Find the app market activity by resolving an intent.
3551 // (If multiple app markets are installed, it will return the ResolverActivity.)
3552 ComponentName activityName = intent.resolveActivity(getPackageManager());
3553 if (activityName != null) {
3554 int coi = getCurrentOrientationIndexForGlobalIcons();
3555 mAppMarketIntent = intent;
3556 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3557 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3558 TOOLBAR_ICON_METADATA_NAME);
3559 marketButton.setVisibility(View.VISIBLE);
3560 } else {
3561 // We should hide and disable the view so that we don't try and restore the visibility
3562 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3563 marketButton.setVisibility(View.GONE);
3564 marketButton.setEnabled(false);
3565 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003566 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003567 }
3568
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003569 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003570 if (!DISABLE_MARKET_BUTTON) {
3571 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3572 Resources r = getResources();
3573 Drawable marketIconDrawable = d.newDrawable(r);
3574 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3575 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3576 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003577
Winson Chungd64a6662013-09-30 11:06:59 -07003578 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3579 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003580 }
3581
Michael Jurkad7c28052012-04-27 15:43:36 -07003582 @Override
3583 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003584 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003585 final List<CharSequence> text = event.getText();
3586 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003587 // Populate event with a fake title based on the current state.
3588 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen4b378872013-10-04 18:58:04 -07003589 text.add(mAppsCustomizeTabHost.getCurrentTabView().getContentDescription());
alanv1d4fde62012-10-17 13:15:47 -07003590 } else {
3591 text.add(getString(R.string.all_apps_home_button_label));
3592 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003593 return result;
3594 }
3595
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003596 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003597 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003598 */
3599 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3600 @Override
3601 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003602 closeSystemDialogs();
3603 }
3604 }
3605
3606 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003607 * Receives notifications whenever the appwidgets are reset.
3608 */
3609 private class AppWidgetResetObserver extends ContentObserver {
3610 public AppWidgetResetObserver() {
3611 super(new Handler());
3612 }
3613
3614 @Override
3615 public void onChange(boolean selfChange) {
3616 onAppWidgetReset();
3617 }
3618 }
3619
3620 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003621 * If the activity is currently paused, signal that we need to run the passed Runnable
3622 * in onResume.
3623 *
3624 * This needs to be called from incoming places where resources might have been loaded
3625 * while we are paused. That is becaues the Configuration might be wrong
3626 * when we're not running, and if it comes back to what it was when we
3627 * were paused, we are not restarted.
3628 *
3629 * Implementation of the method from LauncherModel.Callbacks.
3630 *
3631 * @return true if we are currently paused. The caller might be able to
3632 * skip some work in that case since we will come back again.
3633 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003634 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003635 if (mPaused) {
3636 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003637 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003638 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003639 }
3640 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003641 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003642 return true;
3643 } else {
3644 return false;
3645 }
3646 }
3647
Michael Jurkac402cd92013-05-20 15:49:32 +02003648 private boolean waitUntilResume(Runnable run) {
3649 return waitUntilResume(run, false);
3650 }
3651
Michael Jurka1e2f4652013-07-08 18:03:46 -07003652 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003653 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003654 }
3655
Michael Jurka7607c2f2013-04-03 14:33:19 -07003656 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003657 * If the activity is currently paused, signal that we need to re-run the loader
3658 * in onResume.
3659 *
3660 * This needs to be called from incoming places where resources might have been loaded
3661 * while we are paused. That is becaues the Configuration might be wrong
3662 * when we're not running, and if it comes back to what it was when we
3663 * were paused, we are not restarted.
3664 *
3665 * Implementation of the method from LauncherModel.Callbacks.
3666 *
3667 * @return true if we are currently paused. The caller might be able to
3668 * skip some work in that case since we will come back again.
3669 */
3670 public boolean setLoadOnResume() {
3671 if (mPaused) {
3672 Log.i(TAG, "setLoadOnResume");
3673 mOnResumeNeedsLoad = true;
3674 return true;
3675 } else {
3676 return false;
3677 }
3678 }
3679
3680 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003681 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003682 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003683 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003684 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003685 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003686 } else {
3687 return SCREEN_COUNT / 2;
3688 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003689 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003690
Joe Onorato9c1289c2009-08-17 11:03:03 -04003691 /**
3692 * Refreshes the shortcuts shown on the workspace.
3693 *
3694 * Implementation of the method from LauncherModel.Callbacks.
3695 */
3696 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003697 // If we're starting binding all over again, clear any bind calls we'd postponed in
3698 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3699 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003700 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003701
Winson Chungd64d1762013-08-20 14:37:16 -07003702 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003703 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003704 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003705
Michael Jurka05bf644e2011-11-30 20:28:53 -08003706 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003707 if (mHotseat != null) {
3708 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003709 }
3710 }
3711
Adam Cohendcd297f2013-06-18 13:13:40 -07003712 @Override
3713 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003714 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003715
Adam Cohen5084cba2013-09-03 12:01:16 -07003716 // If there are no screens, we need to have an empty screen
3717 if (orderedScreenIds.size() == 0) {
3718 mWorkspace.addExtraEmptyScreen();
3719 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003720
3721 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003722 // setCurrentPage() so ensure that all pages are added before calling this).
3723 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003724 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3725 mWorkspace.createCustomContentPage();
3726 }
Winson Chung64359a52013-07-08 17:17:08 -07003727 }
3728
3729 @Override
3730 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08003731 // Log to disk
3732 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
3733 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
3734 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07003735 int count = orderedScreenIds.size();
3736 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003737 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003738 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003739 }
3740
Adam Cohen39a06042013-07-19 14:30:12 -07003741 private boolean shouldShowWeightWatcher() {
3742 String spKey = LauncherAppState.getSharedPreferencesKey();
3743 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07003744 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003745
3746 return show;
3747 }
3748
3749 private void toggleShowWeightWatcher() {
3750 String spKey = LauncherAppState.getSharedPreferencesKey();
3751 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3752 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3753
3754 show = !show;
3755
3756 SharedPreferences.Editor editor = sp.edit();
3757 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3758 editor.commit();
3759
3760 if (mWeightWatcher != null) {
3761 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3762 }
3763 }
3764
Winson Chungd64d1762013-08-20 14:37:16 -07003765 public void bindAppsAdded(final ArrayList<Long> newScreens,
3766 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003767 final ArrayList<ItemInfo> addAnimated,
3768 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003769 Runnable r = new Runnable() {
3770 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003771 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003772 }
3773 };
3774 if (waitUntilResume(r)) {
3775 return;
3776 }
3777
Winson Chungd64d1762013-08-20 14:37:16 -07003778 // Add the new screens
3779 bindAddScreens(newScreens);
3780
3781 // We add the items without animation on non-visible pages, and with
3782 // animations on the new page (which we will try and snap to).
3783 if (!addNotAnimated.isEmpty()) {
3784 bindItems(addNotAnimated, 0,
3785 addNotAnimated.size(), false);
3786 }
3787 if (!addAnimated.isEmpty()) {
3788 bindItems(addAnimated, 0,
3789 addAnimated.size(), true);
3790 }
Winson Chungc58497e2013-09-03 17:48:37 -07003791
Winson Chung87412982013-10-03 18:34:14 -07003792 // Remove the extra empty screen
Adam Cohenad4e15c2013-10-17 16:21:35 -07003793 mWorkspace.removeExtraEmptyScreen(false, null);
Winson Chung87412982013-10-03 18:34:14 -07003794
Winson Chungc58497e2013-09-03 17:48:37 -07003795 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
3796 addedApps != null && mAppsCustomizeContent != null) {
3797 mAppsCustomizeContent.addApps(addedApps);
3798 }
Winson Chungd64d1762013-08-20 14:37:16 -07003799 }
3800
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003801 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003802 * Bind the items start-end from the list.
3803 *
3804 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003805 */
Winson Chung64359a52013-07-08 17:17:08 -07003806 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3807 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003808 Runnable r = new Runnable() {
3809 public void run() {
3810 bindItems(shortcuts, start, end, forceAnimateIcons);
3811 }
3812 };
3813 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003814 return;
3815 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003816
Winson Chungf0c6ae02012-03-21 16:10:31 -07003817 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003818 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3819 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003820 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003821 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003822 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003823 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003824 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003825
3826 // Short circuit if we are loading dock items for a configuration which has no dock
3827 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3828 mHotseat == null) {
3829 continue;
3830 }
3831
Joe Onorato9c1289c2009-08-17 11:03:03 -04003832 switch (item.itemType) {
3833 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3834 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003835 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003836 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003837
Winson Chung64359a52013-07-08 17:17:08 -07003838 /*
3839 * TODO: FIX collision case
3840 */
Winson Chungce376632013-07-11 16:12:41 -07003841 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3842 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3843 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3844 throw new RuntimeException("OCCUPIED");
3845 }
Winson Chung64359a52013-07-08 17:17:08 -07003846 }
3847
Adam Cohendcd297f2013-06-18 13:13:40 -07003848 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3849 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003850 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003851 // Animate all the applications up now
3852 shortcut.setAlpha(0f);
3853 shortcut.setScaleX(0f);
3854 shortcut.setScaleY(0f);
3855 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003856 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003857 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003858 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003859 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003860 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003861 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003862 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003863 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3864 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003865 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003866 default:
3867 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003868 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003869 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003870
Winson Chung997a9232013-07-24 15:33:46 -07003871 if (animateIcons) {
3872 // Animate to the correct page
3873 if (newShortcutsScreenId > -1) {
3874 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003875 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003876 final Runnable startBounceAnimRunnable = new Runnable() {
3877 public void run() {
3878 anim.playTogether(bounceAnims);
3879 anim.start();
3880 }
3881 };
Winson Chung997a9232013-07-24 15:33:46 -07003882 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003883 // We post the animation slightly delayed to prevent slowdowns
3884 // when we are loading right after we return to launcher.
3885 mWorkspace.postDelayed(new Runnable() {
3886 public void run() {
3887 mWorkspace.snapToPage(newScreenIndex);
Winson Chungb2323832013-10-03 15:22:09 -07003888 mWorkspace.postDelayed(startBounceAnimRunnable,
3889 NEW_APPS_ANIMATION_DELAY);
Winson Chung94d67682013-09-25 16:29:40 -07003890 }
3891 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003892 } else {
3893 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003894 }
3895 }
Winson Chung64359a52013-07-08 17:17:08 -07003896 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003897 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003898 }
3899
Joe Onorato9c1289c2009-08-17 11:03:03 -04003900 /**
3901 * Implementation of the method from LauncherModel.Callbacks.
3902 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003903 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003904 Runnable r = new Runnable() {
3905 public void run() {
3906 bindFolders(folders);
3907 }
3908 };
3909 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003910 return;
3911 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003912 sFolders.clear();
3913 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003914 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003915
3916 /**
3917 * Add the views for a widget to the workspace.
3918 *
3919 * Implementation of the method from LauncherModel.Callbacks.
3920 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003921 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003922 Runnable r = new Runnable() {
3923 public void run() {
3924 bindAppWidget(item);
3925 }
3926 };
3927 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003928 return;
3929 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003930
Daniel Sandler843e8602010-06-07 14:59:01 -04003931 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3932 if (DEBUG_WIDGETS) {
3933 Log.d(TAG, "bindAppWidget: " + item);
3934 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003935 final Workspace workspace = mWorkspace;
3936
3937 final int appWidgetId = item.appWidgetId;
3938 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003939 if (DEBUG_WIDGETS) {
3940 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3941 }
3942
Joe Onorato9c1289c2009-08-17 11:03:03 -04003943 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3944
Joe Onorato9c1289c2009-08-17 11:03:03 -04003945 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003946 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003947
Adam Cohendcd297f2013-06-18 13:13:40 -07003948 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003949 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003950 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3951
Joe Onorato9c1289c2009-08-17 11:03:03 -04003952 workspace.requestLayout();
3953
Daniel Sandler843e8602010-06-07 14:59:01 -04003954 if (DEBUG_WIDGETS) {
3955 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3956 + (SystemClock.uptimeMillis()-start) + "ms");
3957 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003958 }
3959
Adam Cohen1462de32012-07-24 22:34:36 -07003960 public void onPageBoundSynchronously(int page) {
3961 mSynchronouslyBoundPages.add(page);
3962 }
3963
Joe Onorato9c1289c2009-08-17 11:03:03 -04003964 /**
3965 * Callback saying that there aren't any more items to bind.
3966 *
3967 * Implementation of the method from LauncherModel.Callbacks.
3968 */
Adam Cohene25af792013-06-06 23:08:25 -07003969 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003970 Runnable r = new Runnable() {
3971 public void run() {
3972 finishBindingItems(upgradePath);
3973 }
3974 };
3975 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003976 return;
3977 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003978 if (mSavedState != null) {
3979 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003980 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003981 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003982 mSavedState = null;
3983 }
3984
Adam Cohen1462de32012-07-24 22:34:36 -07003985 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003986
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003987 // If we received the result of any pending adds while the loader was running (e.g. the
3988 // widget configuration forced an orientation change), process them now.
3989 for (int i = 0; i < sPendingAddList.size(); i++) {
3990 completeAdd(sPendingAddList.get(i));
3991 }
3992 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003993
Winson Chungc51db6a2011-10-05 11:44:49 -07003994 // Update the market app icon as necessary (the other icons will be managed in response to
3995 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07003996 if (!DISABLE_MARKET_BUTTON) {
3997 updateAppMarketIcon();
3998 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07003999
Winson Chungf0c6ae02012-03-21 16:10:31 -07004000 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07004001 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004002 mWorkspace.getUniqueComponents(true, null);
4003 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004004 }
Adam Cohen99894d92013-06-14 11:22:59 -07004005
Adam Cohen66a01fd2013-06-11 12:48:00 -07004006 mWorkspace.post(new Runnable() {
4007 @Override
4008 public void run() {
4009 onFinishBindingItems();
4010 }
4011 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07004012 }
4013
Winson Chunga0b7e862013-09-05 16:03:15 -07004014 public boolean isAllAppsButtonRank(int rank) {
4015 if (mHotseat != null) {
4016 return mHotseat.isAllAppsButtonRank(rank);
4017 }
4018 return false;
4019 }
4020
Winson Chunga2413752012-04-03 14:22:34 -07004021 private boolean canRunNewAppsAnimation() {
4022 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4023 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4024 }
4025
Winson Chungc9168342013-06-26 14:54:55 -07004026 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4027 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4028 PropertyValuesHolder.ofFloat("alpha", 1f),
4029 PropertyValuesHolder.ofFloat("scaleX", 1f),
4030 PropertyValuesHolder.ofFloat("scaleY", 1f));
4031 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4032 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4033 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4034 return bounceAnim;
4035 }
4036
Adam Cohen27772732013-11-11 14:00:56 +00004037 public boolean useVerticalBarLayout() {
4038 return LauncherAppState.getInstance().getDynamicGrid().
4039 getDeviceProfile().isVerticalBarLayout();
4040 }
4041
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004042 protected Rect getSearchBarBounds() {
4043 return LauncherAppState.getInstance().getDynamicGrid().
4044 getDeviceProfile().getSearchBarBounds();
4045 }
4046
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004047 @Override
4048 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004049 boolean searchVisible = updateGlobalSearchIcon();
4050 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004051 if (mSearchDropTargetBar != null) {
4052 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4053 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004054 }
4055
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004056 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004057 * Add the icons for all apps.
4058 *
4059 * Implementation of the method from LauncherModel.Callbacks.
4060 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004061 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Winson Chungc58497e2013-09-03 17:48:37 -07004062 if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
4063 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4064 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4065 getHotseat().addAllAppsFolder(mIconCache, apps,
4066 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4067 }
4068 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004069 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004070 if (mAppsCustomizeContent != null) {
4071 mAppsCustomizeContent.onPackagesUpdated(
4072 LauncherModel.getSortedWidgetsAndShortcuts(this));
4073 }
Winson Chungc58497e2013-09-03 17:48:37 -07004074 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004075 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004076 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004077 mAppsCustomizeContent.onPackagesUpdated(
4078 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004079 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004080 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004081 }
4082
4083 /**
4084 * A package was updated.
4085 *
4086 * Implementation of the method from LauncherModel.Callbacks.
4087 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004088 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004089 Runnable r = new Runnable() {
4090 public void run() {
4091 bindAppsUpdated(apps);
4092 }
4093 };
4094 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004095 return;
4096 }
4097
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004098 if (mWorkspace != null) {
4099 mWorkspace.updateShortcuts(apps);
4100 }
Winson Chungc58497e2013-09-03 17:48:37 -07004101
4102 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
4103 mAppsCustomizeContent != null) {
4104 mAppsCustomizeContent.updateApps(apps);
4105 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004106 }
4107
4108 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004109 * A package was uninstalled. We take both the super set of packageNames
4110 * in addition to specific applications to remove, the reason being that
4111 * this can be called when a package is updated as well. In that scenario,
4112 * we only remove specific components from the workspace, where as
4113 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004114 *
4115 * Implementation of the method from LauncherModel.Callbacks.
4116 */
Winson Chung83892cc2013-05-01 16:53:33 -07004117 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Winson Chungdf95eb12013-10-16 14:57:07 -07004118 final ArrayList<AppInfo> appInfos) {
Winson Chungd64d1762013-08-20 14:37:16 -07004119 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004120 public void run() {
Winson Chungdf95eb12013-10-16 14:57:07 -07004121 bindComponentsRemoved(packageNames, appInfos);
Winson Chung83892cc2013-05-01 16:53:33 -07004122 }
Winson Chungd64d1762013-08-20 14:37:16 -07004123 };
4124 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004125 return;
4126 }
4127
Winson Chungdf95eb12013-10-16 14:57:07 -07004128 if (!packageNames.isEmpty()) {
Winson Chung83892cc2013-05-01 16:53:33 -07004129 mWorkspace.removeItemsByPackageName(packageNames);
Winson Chungdf95eb12013-10-16 14:57:07 -07004130 }
4131 if (!appInfos.isEmpty()) {
Winson Chung83892cc2013-05-01 16:53:33 -07004132 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04004133 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004134
Winson Chunga1820962011-10-03 16:31:06 -07004135 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004136 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004137
Winson Chungdf95eb12013-10-16 14:57:07 -07004138 // Update AllApps
Winson Chungc58497e2013-09-03 17:48:37 -07004139 if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
4140 mAppsCustomizeContent != null) {
4141 mAppsCustomizeContent.removeApps(appInfos);
4142 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004143 }
Joe Onoratobe386092009-11-17 17:32:16 -08004144
4145 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004146 * A number of packages were updated.
4147 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004148 private ArrayList<Object> mWidgetsAndShortcuts;
4149 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004150 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004151 bindPackagesUpdated(mWidgetsAndShortcuts);
4152 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004153 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004154 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004155 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4156 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4157 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004158 return;
4159 }
4160
Winson Chung64359a52013-07-08 17:17:08 -07004161 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004162 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004163 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004164 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004165 }
4166
Winson Chung400438b2011-01-16 17:53:48 -08004167 private int mapConfigurationOriActivityInfoOri(int configOri) {
4168 final Display d = getWindowManager().getDefaultDisplay();
4169 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4170 switch (d.getRotation()) {
4171 case Surface.ROTATION_0:
4172 case Surface.ROTATION_180:
4173 // We are currently in the same basic orientation as the natural orientation
4174 naturalOri = configOri;
4175 break;
4176 case Surface.ROTATION_90:
4177 case Surface.ROTATION_270:
4178 // We are currently in the other basic orientation to the natural orientation
4179 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4180 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4181 break;
4182 }
4183
4184 int[] oriMap = {
4185 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4186 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4187 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4188 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4189 };
4190 // Since the map starts at portrait, we need to offset if this device's natural orientation
4191 // is landscape.
4192 int indexOffset = 0;
4193 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4194 indexOffset = 1;
4195 }
4196 return oriMap[(d.getRotation() + indexOffset) % 4];
4197 }
Adam Cohen446e9402011-09-15 18:21:21 -07004198
Winson Chung4b919f82012-05-01 10:44:08 -07004199 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004200 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004201 getResources().getBoolean(R.bool.allow_rotation);
4202 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004203 }
Winson Chung4b919f82012-05-01 10:44:08 -07004204 public void lockScreenOrientation() {
4205 if (isRotationEnabled()) {
4206 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4207 .getConfiguration().orientation));
4208 }
4209 }
4210 public void unlockScreenOrientation(boolean immediate) {
4211 if (isRotationEnabled()) {
4212 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004213 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004214 } else {
4215 mHandler.postDelayed(new Runnable() {
4216 public void run() {
4217 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4218 }
4219 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004220 }
Winson Chung4b919f82012-05-01 10:44:08 -07004221 }
Winson Chung400438b2011-01-16 17:53:48 -08004222 }
4223
Winson Chung82f55532011-08-09 14:14:23 -07004224 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004225 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004226 if (DISABLE_CLINGS) {
4227 return false;
4228 }
4229
Winson Chung3a6e7f32013-10-09 15:50:52 -07004230 // For now, limit only to phones
4231 LauncherAppState app = LauncherAppState.getInstance();
4232 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
4233 if (grid.isTablet()) {
4234 return false;
4235 }
Winson Chung13dbfe12013-10-31 11:42:39 -07004236 if (grid.isLandscape) {
4237 return false;
4238 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004239
Brett Chabot2a9e2282011-08-23 15:03:13 -07004240 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004241 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004242
Casey Burkhardt0d9cbae2013-10-04 14:13:15 -07004243 // Disable clings for accessibility when explore by touch is enabled
4244 final AccessibilityManager a11yManager = (AccessibilityManager) getSystemService(
4245 ACCESSIBILITY_SERVICE);
4246 if (a11yManager.isTouchExplorationEnabled()) {
4247 return false;
4248 }
4249
Michael Jurkae233a8b2013-03-19 13:49:20 +01004250 // Restricted secondary users (child mode) will potentially have very few apps
4251 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004252// boolean supportsLimitedUsers =
4253// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4254// Account[] accounts = AccountManager.get(this).getAccounts();
4255// if (supportsLimitedUsers && accounts.length == 0) {
4256// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4257// Bundle restrictions = um.getUserRestrictions();
4258// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4259// return false;
4260// }
4261// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004262 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004263 }
Michael Jurka22143132012-10-04 17:42:38 +02004264
Winson Chungfa545132013-09-26 17:45:32 -07004265 private Cling initCling(int clingId, int scrimId, boolean animate,
Winson Chungaf40f202013-09-18 18:26:31 -07004266 boolean dimNavBarVisibilty) {
Winson Chungfa545132013-09-26 17:45:32 -07004267 Cling cling = (Cling) findViewById(clingId);
4268 View scrim = null;
4269 if (scrimId > 0) {
Sandeep Siddharthaa6125ef2013-09-26 20:30:40 -07004270 scrim = findViewById(R.id.cling_scrim);
Winson Chungfa545132013-09-26 17:45:32 -07004271 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004272 if (cling != null) {
Winson Chungfa545132013-09-26 17:45:32 -07004273 cling.init(this, scrim);
Winson Chungaf40f202013-09-18 18:26:31 -07004274 cling.show(animate, SHOW_CLING_DURATION);
4275
4276 if (dimNavBarVisibilty) {
4277 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4278 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004279 }
4280 }
4281 return cling;
4282 }
Michael Jurka22143132012-10-04 17:42:38 +02004283
Winson Chungaf40f202013-09-18 18:26:31 -07004284 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4285 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004286 // To catch cases where siblings of top-level views are made invisible, just check whether
4287 // the cling is directly set to GONE before dismissing it.
4288 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004289 final Runnable cleanUpClingCb = new Runnable() {
4290 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004291 cling.cleanup();
Winson Chung46353de2012-02-16 14:05:10 -08004292 // We should update the shared preferences on a background thread
Michael Jurka43467462013-11-14 12:03:58 +01004293 new AsyncTask<Void, Void, Void>() {
4294 public Void doInBackground(Void ... args) {
Winson Chung46353de2012-02-16 14:05:10 -08004295 SharedPreferences.Editor editor = mSharedPrefs.edit();
4296 editor.putBoolean(flag, true);
4297 editor.commit();
Michael Jurka43467462013-11-14 12:03:58 +01004298 return null;
Winson Chung46353de2012-02-16 14:05:10 -08004299 }
Michael Jurka43467462013-11-14 12:03:58 +01004300 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungaf40f202013-09-18 18:26:31 -07004301 if (postAnimationCb != null) {
4302 postAnimationCb.run();
4303 }
4304 }
4305 };
4306 if (duration <= 0) {
4307 cleanUpClingCb.run();
4308 } else {
4309 cling.hide(duration, cleanUpClingCb);
4310 }
Michael Jurka22143132012-10-04 17:42:38 +02004311 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004312
4313 if (restoreNavBarVisibilty) {
4314 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4315 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4316 }
Winson Chung82f55532011-08-09 14:14:23 -07004317 }
4318 }
Michael Jurka22143132012-10-04 17:42:38 +02004319
Winson Chung9d9d74f2011-09-19 11:49:12 -07004320 private void removeCling(int id) {
4321 final View cling = findViewById(id);
4322 if (cling != null) {
4323 final ViewGroup parent = (ViewGroup) cling.getParent();
4324 parent.post(new Runnable() {
4325 @Override
4326 public void run() {
4327 parent.removeView(cling);
4328 }
4329 });
Michael Jurka22143132012-10-04 17:42:38 +02004330 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004331 }
4332 }
Michael Jurka974c3862012-05-22 22:00:31 -07004333
4334 private boolean skipCustomClingIfNoAccounts() {
4335 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4336 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4337 if (customCling) {
4338 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004339 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004340 Account[] accounts = am.getAccountsByType("com.google");
4341 return accounts.length == 0;
4342 }
4343 return false;
4344 }
4345
Winson Chung82e5c982013-10-09 12:04:50 -07004346 public void updateCustomContentHintVisibility() {
4347 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4348 String ccHintStr = getFirstRunCustomContentHint();
4349
4350 if (mWorkspace.hasCustomContent()) {
4351 // Show the custom content hint if ccHintStr is not empty
4352 if (cling != null) {
4353 setCustomContentHintVisibility(cling, ccHintStr, true, true);
4354 }
4355 } else {
4356 // Hide the custom content hint
4357 if (cling != null) {
4358 setCustomContentHintVisibility(cling, ccHintStr, false, true);
4359 }
4360 }
4361 }
4362
4363 private void setCustomContentHintVisibility(Cling cling, String ccHintStr, boolean visible,
4364 boolean animate) {
4365 final TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4366 if (ccHint != null) {
4367 if (visible && !ccHintStr.isEmpty()) {
4368 ccHint.setText(ccHintStr);
4369 ccHint.setVisibility(View.VISIBLE);
4370 if (animate) {
4371 ccHint.setAlpha(0f);
4372 ccHint.animate().alpha(1f)
4373 .setDuration(SHOW_CLING_DURATION)
4374 .start();
4375 } else {
4376 ccHint.setAlpha(1f);
4377 }
4378 } else {
4379 if (animate) {
4380 ccHint.animate().alpha(0f)
4381 .setDuration(SHOW_CLING_DURATION)
4382 .setListener(new AnimatorListenerAdapter() {
4383 @Override
4384 public void onAnimationEnd(Animator animation) {
4385 ccHint.setVisibility(View.GONE);
4386 }
4387 })
4388 .start();
4389 } else {
4390 ccHint.setAlpha(0f);
4391 ccHint.setVisibility(View.GONE);
4392 }
4393 }
4394 }
4395 }
4396
Winson Chungaf40f202013-09-18 18:26:31 -07004397 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004398 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004399 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004400 !skipCustomClingIfNoAccounts() ) {
Michael Jurka45355c42012-10-08 13:21:35 +02004401 // If we're not using the default workspace layout, replace workspace cling
4402 // with a custom workspace cling (usually specified in an overlay)
4403 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004404 if (!DISABLE_CUSTOM_CLINGS) {
4405 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4406 getResources().getBoolean(R.bool.config_useCustomClings)) {
4407 // Use a custom cling
4408 View cling = findViewById(R.id.workspace_cling);
4409 ViewGroup clingParent = (ViewGroup) cling.getParent();
4410 int clingIndex = clingParent.indexOfChild(cling);
4411 clingParent.removeViewAt(clingIndex);
4412 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4413 clingParent.addView(customCling, clingIndex);
4414 customCling.setId(R.id.workspace_cling);
4415 }
4416 }
4417 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4418 if (cling != null) {
4419 String sbHintStr = getFirstRunClingSearchBarHint();
4420 String ccHintStr = getFirstRunCustomContentHint();
4421 if (!sbHintStr.isEmpty()) {
4422 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4423 sbHint.setText(sbHintStr);
4424 sbHint.setVisibility(View.VISIBLE);
4425 }
Winson Chung82e5c982013-10-09 12:04:50 -07004426 setCustomContentHintVisibility(cling, ccHintStr, true, false);
Michael Jurka45355c42012-10-08 13:21:35 +02004427 }
Winson Chungfa545132013-09-26 17:45:32 -07004428 initCling(R.id.first_run_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004429 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004430 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004431 }
4432 }
Winson Chungaf40f202013-09-18 18:26:31 -07004433
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004434 /**
4435 * Called when the SearchBar hint should be changed.
4436 *
4437 * @param hint the hint to be displayed in the search bar.
4438 */
4439 protected void onSearchBarHintChanged(String hint) {
4440 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4441 if (cling != null && cling.getVisibility() == View.VISIBLE && !hint.isEmpty()) {
4442 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4443 sbHint.setText(hint);
4444 sbHint.setVisibility(View.VISIBLE);
4445 }
4446 }
4447
Winson Chunge6eabff2013-09-24 11:01:23 -07004448 protected String getFirstRunClingSearchBarHint() {
4449 return "";
4450 }
4451 protected String getFirstRunCustomContentHint() {
4452 return "";
4453 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004454 protected int getFirstRunFocusedHotseatAppDrawableId() {
4455 return -1;
4456 }
4457 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4458 return null;
4459 }
4460 protected int getFirstRunFocusedHotseatAppRank() {
4461 return -1;
4462 }
4463 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4464 return "";
4465 }
4466 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4467 return "";
4468 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004469
Winson Chungaf40f202013-09-18 18:26:31 -07004470 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004471 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004472 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004473 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chung3a6e7f32013-10-09 15:50:52 -07004474 Cling c = initCling(R.id.workspace_cling, 0, false, true);
4475
4476 // Set the focused hotseat app if there is one
4477 c.setFocusedHotseatApp(getFirstRunFocusedHotseatAppDrawableId(),
4478 getFirstRunFocusedHotseatAppRank(),
4479 getFirstRunFocusedHotseatAppComponentName(),
4480 getFirstRunFocusedHotseatAppBubbleTitle(),
4481 getFirstRunFocusedHotseatAppBubbleDescription());
Winson Chung9d9d74f2011-09-19 11:49:12 -07004482 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004483 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004484 }
4485 }
4486 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004487 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004488 if (isClingsEnabled() &&
4489 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004490 Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim,
4491 true, true);
Winson Chungaf40f202013-09-18 18:26:31 -07004492 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004493 } else {
4494 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004495 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004496 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004497 }
Michael Jurka104c4562013-07-08 18:03:46 -07004498 protected SharedPreferences getSharedPrefs() {
4499 return mSharedPrefs;
4500 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004501 public boolean isFolderClingVisible() {
4502 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004503 if (cling != null) {
4504 return cling.getVisibility() == View.VISIBLE;
4505 }
4506 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004507 }
Winson Chungaf40f202013-09-18 18:26:31 -07004508 public void dismissFirstRunCling(View v) {
4509 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4510 Runnable cb = new Runnable() {
4511 public void run() {
4512 // Show the workspace cling next
4513 showFirstRunWorkspaceCling();
4514 }
4515 };
4516 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4517 DISMISS_CLING_DURATION, false);
Winson Chung3a6e7f32013-10-09 15:50:52 -07004518
4519 // Fade out the search bar for the workspace cling coming up
4520 mSearchDropTargetBar.hideSearchBar(true);
Winson Chungaf40f202013-09-18 18:26:31 -07004521 }
Winson Chung82f55532011-08-09 14:14:23 -07004522 public void dismissWorkspaceCling(View v) {
4523 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004524 Runnable cb = null;
4525 if (v == null) {
4526 cb = new Runnable() {
4527 public void run() {
4528 mWorkspace.enterOverviewMode();
4529 }
4530 };
4531 }
4532 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4533 DISMISS_CLING_DURATION, true);
Winson Chung3a6e7f32013-10-09 15:50:52 -07004534
4535 // Fade in the search bar
4536 mSearchDropTargetBar.showSearchBar(true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004537 }
4538 public void dismissFolderCling(View v) {
4539 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004540 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4541 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004542 }
4543
Mathew Inwood72fbec12013-11-19 15:45:07 +00004544 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
4545 ResolveInfo ri = getPackageManager().resolveActivity(appLaunchIntent, 0);
4546 if (ri == null) {
4547 return null;
4548 }
4549 return new AppInfo(getPackageManager(), ri, mIconCache, null);
4550 }
4551
4552 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4553 Bitmap icon) {
4554 return new ShortcutInfo(shortcutIntent, caption, icon);
4555 }
4556
4557 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4558 dragView.setTag(dragInfo);
4559 mWorkspace.onDragStartedWithItem(dragView);
4560 mWorkspace.beginDragShared(dragView, source);
4561 }
4562
Winson Chung80baf5a2010-08-09 16:03:15 -07004563 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004564 * Prints out out state for debugging.
4565 */
4566 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004567 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004568 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004569 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4570 Log.d(TAG, "mRestoring=" + mRestoring);
4571 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4572 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004573 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004574 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004575
Winson Chung785d2eb2011-04-14 16:08:02 -07004576 if (mAppsCustomizeContent != null) {
4577 mAppsCustomizeContent.dumpState();
4578 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004579 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004580 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004581
4582 @Override
4583 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4584 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004585 synchronized (sDumpLogs) {
4586 writer.println(" ");
4587 writer.println("Debug logs: ");
4588 for (int i = 0; i < sDumpLogs.size(); i++) {
4589 writer.println(" " + sDumpLogs.get(i));
4590 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004591 }
4592 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004593
4594 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004595 if (DEBUG_DUMP_LOG) {
4596 synchronized (sDumpLogs) {
4597 Log.d(TAG, "");
4598 Log.d(TAG, "*********************");
4599 Log.d(TAG, "Launcher debug logs: ");
4600 for (int i = 0; i < sDumpLogs.size(); i++) {
4601 Log.d(TAG, " " + sDumpLogs.get(i));
4602 }
4603 Log.d(TAG, "*********************");
4604 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004605 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004606 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004607 }
4608
4609 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004610 addDumpLog(tag, log, null, debugLog);
4611 }
4612
4613 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004614 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004615 if (e != null) {
4616 Log.d(tag, log, e);
4617 } else {
4618 Log.d(tag, log);
4619 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004620 }
Winson Chungede41292013-09-19 16:27:36 -07004621 if (DEBUG_DUMP_LOG) {
4622 sDateStamp.setTime(System.currentTimeMillis());
4623 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05004624 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
4625 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07004626 }
Winson Chungede41292013-09-19 16:27:36 -07004627 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004628 }
4629
Winson Chungede41292013-09-19 16:27:36 -07004630 public void dumpLogsToLocalData() {
4631 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01004632 new AsyncTask<Void, Void, Void>() {
4633 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07004634 boolean success = false;
4635 sDateStamp.setTime(sRunStart);
4636 String FILENAME = sDateStamp.getMonth() + "-"
4637 + sDateStamp.getDay() + "_"
4638 + sDateStamp.getHours() + "-"
4639 + sDateStamp.getMinutes() + "_"
4640 + sDateStamp.getSeconds() + ".txt";
4641
4642 FileOutputStream fos = null;
4643 File outFile = null;
4644 try {
4645 outFile = new File(getFilesDir(), FILENAME);
4646 outFile.createNewFile();
4647 fos = new FileOutputStream(outFile);
4648 } catch (Exception e) {
4649 e.printStackTrace();
4650 }
4651 if (fos != null) {
4652 PrintWriter writer = new PrintWriter(fos);
4653
4654 writer.println(" ");
4655 writer.println("Debug logs: ");
4656 synchronized (sDumpLogs) {
4657 for (int i = 0; i < sDumpLogs.size(); i++) {
4658 writer.println(" " + sDumpLogs.get(i));
4659 }
4660 }
4661 writer.close();
4662 }
4663 try {
4664 if (fos != null) {
4665 fos.close();
4666 success = true;
4667 }
4668 } catch (IOException e) {
4669 e.printStackTrace();
4670 }
Michael Jurka43467462013-11-14 12:03:58 +01004671 return null;
Winson Chungede41292013-09-19 16:27:36 -07004672 }
Michael Jurka43467462013-11-14 12:03:58 +01004673 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07004674 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004675 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004676}
Michael Jurka2763be32011-02-24 11:19:57 -08004677
Michael Jurkaabded662011-03-04 12:06:57 -08004678interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004679 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004680 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004681 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004682 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004683 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004684}
Dan Sandlerd5024042014-01-09 15:01:33 -05004685
4686interface DebugIntents {
4687 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
4688 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
4689}