blob: 3bea9415245b2afa4b13e16605320a70fac45807 [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
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700134 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_PICK_APPLICATION = 6;
136 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700137 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700138 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
Michael Jurka8b805b12012-04-18 14:23:14 -0700140 private static final int REQUEST_BIND_APPWIDGET = 11;
141
Mathew Inwood876a8462013-06-14 14:12:41 +0100142 /**
143 * IntentStarter uses request codes starting with this. This must be greater than all activity
144 * request codes used internally.
145 */
146 protected static final int REQUEST_LAST = 100;
147
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
149
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800150 static final int SCREEN_COUNT = 5;
151 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800152
Romain Guy98d01652009-06-30 16:21:04 -0700153 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800154 // To turn on these properties, type
155 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
156 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
157 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800158 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800159
Winson Chung2672ff92012-05-04 16:22:30 -0700160 // The Intent extra that defines whether to ignore the launch animation
161 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400162 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700163
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164 // Type: int
165 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700166 // Type: int
167 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800168 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700169 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
170 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
172 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700173 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700175 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176 // Type: boolean
177 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
178 // Type: long
179 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700180 // Type: int
181 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
182 // Type: int
183 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
184 // Type: parcelable
185 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000186 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800187 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000188 // Type: int[]
189 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190
Adam Cohenb54a5982014-01-08 15:21:04 -0800191
192 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
193
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100194 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700195 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100196 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700197 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100198 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700199
Adam Cohen39a06042013-07-19 14:30:12 -0700200 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700201 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700202
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700203 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700204 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700205 private State mState = State.WORKSPACE;
206 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700207
Joe Onorato9c1289c2009-08-17 11:03:03 -0400208 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700209 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
210 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Winson Chungaf40f202013-09-18 18:26:31 -0700211 private static final int SHOW_CLING_DURATION = 250;
212 private static final int DISMISS_CLING_DURATION = 200;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800213
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800214 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800215 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800216
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000217 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
218 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
219
Winson Chunga2413752012-04-03 14:22:34 -0700220 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700221 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
222 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700223 private static int NEW_APPS_ANIMATION_DELAY = 500;
Winson Chunga2413752012-04-03 14:22:34 -0700224
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800225 private final BroadcastReceiver mCloseSystemDialogsReceiver
226 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800227 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
228
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800229 private LayoutInflater mInflater;
230
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800231 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700232 private View mLauncherView;
Michael Jurkab737ee62011-11-15 15:57:22 -0800233 private DragLayer mDragLayer;
234 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700235 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700236
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700237 private AppWidgetManager mAppWidgetManager;
238 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700239
Michael Jurkac9d95c52011-08-29 14:03:34 -0700240 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700241 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800242 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700243
Michael Jurka0280c3b2010-09-17 15:00:07 -0700244 private int[] mTmpAddItemCellCoordinates = new int[2];
245
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800246 private FolderInfo mFolderInfo;
247
Winson Chung3d503fb2011-07-13 17:25:49 -0700248 private Hotseat mHotseat;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700249 private View mOverviewPanel;
250
Michael Jurka838a4ca2011-02-07 13:33:06 -0800251 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700252
Winson Chungc51db6a2011-10-05 11:44:49 -0700253 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700254 private AppsCustomizeTabHost mAppsCustomizeTabHost;
255 private AppsCustomizePagedView mAppsCustomizeContent;
256 private boolean mAutoAdvanceRunning = false;
Cristina Stancu476493b2013-08-07 17:20:14 +0100257 private View mQsbBar;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800258
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800259 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700260 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
261 // scroll issues (because the workspace may not have been measured yet) and extra work.
262 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
263 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800264
265 private SpannableStringBuilder mDefaultKeySsb = null;
266
Joe Onorato9c1289c2009-08-17 11:03:03 -0400267 private boolean mWorkspaceLoading = true;
268
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800269 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270 private boolean mRestoring;
271 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700272 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800273
Michael Jurka1e2f4652013-07-08 18:03:46 -0700274 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700275 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
276
Winson Chung4a2afa32012-07-19 14:53:05 -0700277 // Keep track of whether the user has left launcher
278 private static boolean sPausedFromUserAction = false;
279
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800280 private Bundle mSavedInstanceState;
281
Joe Onorato9c1289c2009-08-17 11:03:03 -0400282 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800283 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800284 private boolean mUserPresent = true;
285 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700286 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800287 private boolean mAttached = false;
Winson Chungfa545132013-09-26 17:45:32 -0700288 private static final boolean DISABLE_CLINGS = false;
Winson Chunge6eabff2013-09-24 11:01:23 -0700289 private static final boolean DISABLE_CUSTOM_CLINGS = true;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400290
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700291 private static LocaleConfiguration sLocaleConfiguration = null;
292
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700293 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700294
Adam Cohen61f560d2013-09-30 15:58:20 -0700295 private View.OnTouchListener mHapticFeedbackTouchListener;
296
Adam Cohended9f8d2010-11-03 13:25:16 -0700297 // Related to the auto-advancing of widgets
298 private final int ADVANCE_MSG = 1;
299 private final int mAdvanceInterval = 20000;
300 private final int mAdvanceStagger = 250;
301 private long mAutoAdvanceSentTime;
302 private long mAutoAdvanceTimeLeft = -1;
303 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
304 new HashMap<View, AppWidgetProviderInfo>();
305
Winson Chung400438b2011-01-16 17:53:48 -0800306 // Determines how long to wait after a rotation before restoring the screen orientation to
307 // match the sensor state.
308 private final int mRestoreScreenOrientationDelay = 500;
309
Michael Jurka4ef207b2010-11-29 17:05:45 -0800310 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700311 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
312 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
313 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800314
Winson Chungd64a6662013-09-30 11:06:59 -0700315 private Intent mAppMarketIntent = null;
316 private static final boolean DISABLE_MARKET_BUTTON = true;
317
Craig Mautner360310b2012-10-26 15:13:08 -0700318 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700319
Adam Cohen1462de32012-07-24 22:34:36 -0700320 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700321 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700322
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700323 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700324 static Date sDateStamp = new Date();
325 static DateFormat sDateFormat =
326 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
327 static long sRunStart = System.currentTimeMillis();
328 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700329
Winson Chung46353de2012-02-16 14:05:10 -0800330 // We only want to get the SharedPreferences once since it does an FS stat each time we get
331 // it from the context.
332 private SharedPreferences mSharedPrefs;
333
Adam Cohene25af792013-06-06 23:08:25 -0700334 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
335
Winson Chungf0c6ae02012-03-21 16:10:31 -0700336 // Holds the page that we need to animate to, and the icon views that we need to animate up
337 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700338 private ImageView mFolderIconImageView;
339 private Bitmap mFolderIconBitmap;
340 private Canvas mFolderIconCanvas;
341 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700342
Michael Jurkaddd62e92011-02-16 17:49:14 -0800343 private BubbleTextView mWaitingForResume;
344
Michael Jurka22143132012-10-04 17:42:38 +0200345 private HideFromAccessibilityHelper mHideFromAccessibilityHelper
346 = new HideFromAccessibilityHelper();
347
Michael Jurkac1f5d262011-09-30 19:32:27 -0700348 private Runnable mBuildLayersRunnable = new Runnable() {
349 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700350 if (mWorkspace != null) {
351 mWorkspace.buildPageHardwareLayers();
352 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700353 }
354 };
355
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800356 private static ArrayList<PendingAddArguments> sPendingAddList
357 = new ArrayList<PendingAddArguments>();
358
Michael Jurka7267fa52013-09-26 15:29:57 -0700359 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800360
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800361 private static class PendingAddArguments {
362 int requestCode;
363 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700364 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700365 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800366 int cellX;
367 int cellY;
368 }
369
Daniel Sandlerff02d492013-08-05 02:12:05 -0400370 private Stats mStats;
371
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800372 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800373 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700374 }
375
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 @Override
377 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700378 if (DEBUG_STRICT_MODE) {
379 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
380 .detectDiskReads()
381 .detectDiskWrites()
382 .detectNetwork() // or .detectAll() for all detectable problems
383 .penaltyLog()
384 .build());
385 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
386 .detectLeakedSqlLiteObjects()
387 .detectLeakedClosableObjects()
388 .penaltyLog()
389 .penaltyDeath()
390 .build());
391 }
392
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800393 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400394
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400395 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400396 LauncherAppState app = LauncherAppState.getInstance();
Winson Chung5f8afe62013-08-12 16:19:28 -0700397
398 // Determine the dynamic grid properties
399 Point smallestSize = new Point();
400 Point largestSize = new Point();
401 Point realSize = new Point();
402 Display display = getWindowManager().getDefaultDisplay();
403 display.getCurrentSizeRange(smallestSize, largestSize);
404 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700405 DisplayMetrics dm = new DisplayMetrics();
406 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700407
Winson Chung5f8afe62013-08-12 16:19:28 -0700408 // Lazy-initialize the dynamic grid
409 DeviceProfile grid = app.initDynamicGrid(this,
410 Math.min(smallestSize.x, smallestSize.y),
411 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700412 realSize.x, realSize.y,
413 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700414
415 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400416 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700417 Context.MODE_PRIVATE);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800418 mModel = app.setLauncher(this);
419 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700420 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400421 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800422 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700423
Daniel Sandlerff02d492013-08-05 02:12:05 -0400424 mStats = new Stats(this);
425
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700426 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700427
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700428 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
429 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700430
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700431 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
432 // this also ensures that any synchronous binding below doesn't re-trigger another
433 // LauncherModel load.
434 mPaused = false;
435
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800436 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200437 android.os.Debug.startMethodTracing(
438 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800439 }
440
Adam Cohen53805212013-10-01 10:39:23 -0700441
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800442 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800443 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700444
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800445 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100446 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800447
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800448 registerContentObservers();
449
Joe Onorato7c312c12009-08-13 21:36:53 -0700450 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700451
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800452 mSavedState = savedInstanceState;
453 restoreState(mSavedState);
454
455 if (PROFILE_STARTUP) {
456 android.os.Debug.stopMethodTracing();
457 }
458
459 if (!mRestoring) {
Winson Chung6e1c0d32013-10-25 15:24:24 -0700460 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE || sPausedFromUserAction) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700461 // If the user leaves launcher, then we should just load items asynchronously when
462 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500463 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700464 } else {
465 // We only load the page synchronously if the user rotates (or triggers a
466 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800467 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700468 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800469 }
470
471 // For handling default keys
472 mDefaultKeySsb = new SpannableStringBuilder();
473 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800474
475 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
476 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800477
Adam Cohenf9426d52012-06-04 17:26:21 -0700478 updateGlobalIcons();
479
480 // On large interfaces, we want the screen to auto-rotate based on the current orientation
481 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700482
Adam Cohenb54a5982014-01-08 15:21:04 -0800483 showFirstRunActivity();
Winson Chungaf40f202013-09-18 18:26:31 -0700484 showFirstRunCling();
Adam Cohenf9426d52012-06-04 17:26:21 -0700485 }
486
Winson Chung4a2afa32012-07-19 14:53:05 -0700487 protected void onUserLeaveHint() {
488 super.onUserLeaveHint();
489 sPausedFromUserAction = true;
490 }
491
Winson Chung98ca0f72013-07-29 12:58:51 -0700492 /** To be overriden by subclasses to hint to Launcher that we have custom content */
493 protected boolean hasCustomContentToLeft() {
494 return false;
495 }
496
Dave Hawkeya8881582013-09-17 15:55:33 -0600497 /**
498 * To be overridden by subclasses to create the custom content and call
499 * {@link #addToCustomContentPage}. This will only be invoked if
500 * {@link #hasCustomContentToLeft()} is {@code true}.
501 */
502 protected void addCustomContentToLeft() {
503 }
504
505 /**
Adam Cohenb54a5982014-01-08 15:21:04 -0800506 * To be overridden by subclasses to indicate that there is an activity to launch
507 * before showing the standard launcher experience.
508 */
509 protected boolean hasFirstRunActivity() {
510 return false;
511 }
512
513 /**
514 * To be overridden by subclasses to launch any first run activity
515 */
516 protected Intent getFirstRunActivity() {
517 return null;
518 }
519
520 /**
Dave Hawkeya8881582013-09-17 15:55:33 -0600521 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
522 * ensure the custom content page is added or removed if necessary.
523 */
524 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600525 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600526 // Not bound yet, wait for bindScreens to be called.
527 return;
528 }
529
530 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
531 // Create the custom content page and call the subclass to populate it.
532 mWorkspace.createCustomContentPage();
533 addCustomContentToLeft();
534 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
535 mWorkspace.removeCustomContentPage();
536 }
537 }
538
Adam Cohenf9426d52012-06-04 17:26:21 -0700539 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700540 boolean searchVisible = false;
541 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800542 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700543 int coi = getCurrentOrientationIndexForGlobalIcons();
544 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
545 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700546 if (!DISABLE_MARKET_BUTTON) {
547 updateAppMarketIcon();
548 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700549 searchVisible = updateGlobalSearchIcon();
550 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700551 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700552 if (sGlobalSearchIcon[coi] != null) {
553 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700554 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700555 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700556 if (sVoiceSearchIcon[coi] != null) {
557 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700558 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700559 }
Winson Chungd64a6662013-09-30 11:06:59 -0700560 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700561 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800562 }
Winson Chungadf0c182012-08-23 14:59:07 -0700563 if (mSearchDropTargetBar != null) {
564 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
565 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800566 }
Romain Guycbb89e42009-06-08 15:52:54 -0700567
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800568 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700569 if (sLocaleConfiguration == null) {
570 new AsyncTask<Void, Void, LocaleConfiguration>() {
571 @Override
572 protected LocaleConfiguration doInBackground(Void... unused) {
573 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
574 readConfiguration(Launcher.this, localeConfiguration);
575 return localeConfiguration;
576 }
577
578 @Override
579 protected void onPostExecute(LocaleConfiguration result) {
580 sLocaleConfiguration = result;
581 checkForLocaleChange(); // recursive, but now with a locale configuration
582 }
583 }.execute();
584 return;
585 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700586
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800587 final Configuration configuration = getResources().getConfiguration();
588
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700589 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800590 final String locale = configuration.locale.toString();
591
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700592 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800593 final int mcc = configuration.mcc;
594
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700595 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800596 final int mnc = configuration.mnc;
597
Romain Guy84f296c2009-11-04 15:00:44 -0800598 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800599
Romain Guy84f296c2009-11-04 15:00:44 -0800600 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700601 sLocaleConfiguration.locale = locale;
602 sLocaleConfiguration.mcc = mcc;
603 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700604
Joe Onorato0589f0f2010-02-08 13:44:00 -0800605 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700606
607 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100608 new AsyncTask<Void, Void, Void>() {
609 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700610 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100611 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700612 }
Michael Jurka43467462013-11-14 12:03:58 +0100613 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700614 }
615 }
616
617 private static class LocaleConfiguration {
618 public String locale;
619 public int mcc = -1;
620 public int mnc = -1;
621 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700622
Romain Guy98d01652009-06-30 16:21:04 -0700623 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
624 DataInputStream in = null;
625 try {
626 in = new DataInputStream(context.openFileInput(PREFERENCES));
627 configuration.locale = in.readUTF();
628 configuration.mcc = in.readInt();
629 configuration.mnc = in.readInt();
630 } catch (FileNotFoundException e) {
631 // Ignore
632 } catch (IOException e) {
633 // Ignore
634 } finally {
635 if (in != null) {
636 try {
637 in.close();
638 } catch (IOException e) {
639 // Ignore
640 }
641 }
642 }
643 }
644
645 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
646 DataOutputStream out = null;
647 try {
648 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
649 out.writeUTF(configuration.locale);
650 out.writeInt(configuration.mcc);
651 out.writeInt(configuration.mnc);
652 out.flush();
653 } catch (FileNotFoundException e) {
654 // Ignore
655 } catch (IOException e) {
656 //noinspection ResultOfMethodCallIgnored
657 context.getFileStreamPath(PREFERENCES).delete();
658 } finally {
659 if (out != null) {
660 try {
661 out.close();
662 } catch (IOException e) {
663 // Ignore
664 }
665 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800666 }
667 }
668
Anton Hanssona2f665f2013-09-26 12:18:32 +0100669 public Stats getStats() {
670 return mStats;
671 }
672
Bjorn Bringertc459e522013-06-07 19:36:01 +0100673 public LayoutInflater getInflater() {
674 return mInflater;
675 }
676
Adam Cohen716b51e2011-06-30 12:09:54 -0700677 public DragLayer getDragLayer() {
678 return mDragLayer;
679 }
680
Winson Chung36a62fe2012-05-06 18:04:42 -0700681 boolean isDraggingEnabled() {
682 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
683 // that is subsequently removed from the workspace in startBinding().
684 return !mModel.isLoadingWorkspace();
685 }
686
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800687 static int getScreen() {
688 synchronized (sLock) {
689 return sScreen;
690 }
691 }
692
693 static void setScreen(int screen) {
694 synchronized (sLock) {
695 sScreen = screen;
696 }
697 }
698
Winson Chung557d6ed2011-07-08 15:34:52 -0700699 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000700 * Copied from View -- the View version of the method isn't called
701 * anywhere else in our process and only exists for API level 17+,
702 * so it's ok to keep our own version with no API requirement.
703 */
704 public static int generateViewId() {
705 for (;;) {
706 final int result = sNextGeneratedId.get();
707 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
708 int newValue = result + 1;
709 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
710 if (sNextGeneratedId.compareAndSet(result, newValue)) {
711 return result;
712 }
713 }
714 }
715
716 public int getViewIdForItem(ItemInfo info) {
717 // This cast is safe given the > 2B range for int.
718 int itemId = (int) info.id;
719 if (mItemIdToViewId.containsKey(itemId)) {
720 return mItemIdToViewId.get(itemId);
721 }
722 int viewId = generateViewId();
723 mItemIdToViewId.put(itemId, viewId);
724 return viewId;
725 }
726
727 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700728 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
729 * a configuration step, this allows the proper animations to run after other transitions.
730 */
731 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700732 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800733 switch (args.requestCode) {
734 case REQUEST_PICK_APPLICATION:
Adam Cohendcd297f2013-06-18 13:13:40 -0700735 completeAddApplication(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700736 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800737 break;
738 case REQUEST_PICK_SHORTCUT:
739 processShortcut(args.intent);
740 break;
741 case REQUEST_CREATE_SHORTCUT:
Adam Cohendcd297f2013-06-18 13:13:40 -0700742 completeAddShortcut(args.intent, args.container, args.screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700743 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700744 result = true;
745 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800746 case REQUEST_CREATE_APPWIDGET:
747 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -0700748 completeAddAppWidget(appWidgetId, args.container, args.screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700749 result = true;
750 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800751 }
Michael Jurka27614d22012-04-02 06:40:22 -0700752 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
753 // if you turned the screen off and then back while in All Apps, Launcher would not
754 // return to the workspace. Clearing mAddInfo.container here fixes this issue
755 resetAddInfo();
Winson Chungb8472bb2011-08-05 13:49:21 -0700756 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800757 }
758
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800759 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700760 protected void onActivityResult(
761 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700762 // Reset the startActivity waiting flag
763 mWaitingForResult = false;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800764 int pendingAddWidgetId = mPendingAddWidgetId;
765 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700766
Adam Cohenad4e15c2013-10-17 16:21:35 -0700767 Runnable exitSpringLoaded = new Runnable() {
768 @Override
769 public void run() {
770 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
771 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
772 }
773 };
774
Michael Jurka8b805b12012-04-18 14:23:14 -0700775 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700776 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700777 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
778 if (resultCode == RESULT_CANCELED) {
779 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700780 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
781 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700782 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700783 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
784 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700785 }
786 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200787 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
788 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
789 mWorkspace.exitOverviewMode(false);
790 }
791 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700792 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200793
Adam Cohened66b2b2012-01-23 17:28:51 -0800794 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
795 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700796
Adam Cohened66b2b2012-01-23 17:28:51 -0800797 // We have special handling for widgets
798 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800799 final int appWidgetId;
800 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
801 : -1;
802 if (widgetId < 0) {
803 appWidgetId = pendingAddWidgetId;
804 } else {
805 appWidgetId = widgetId;
806 }
807
Adam Cohenad4e15c2013-10-17 16:21:35 -0700808 final int result;
809 final Runnable onComplete;
Adam Cohenf0129b12013-11-04 17:57:36 -0800810 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Winson Chung5aaab772012-04-27 15:24:02 -0700811 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
812 "widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700813 result = RESULT_CANCELED;
814 completeTwoStageWidgetDrop(result, appWidgetId);
815 onComplete = new Runnable() {
816 @Override
817 public void run() {
818 exitSpringLoadedDragModeDelayed(false, 0, null);
819 }
820 };
Winson Chung5aaab772012-04-27 15:24:02 -0700821 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700822 result = resultCode;
Adam Cohen917e3882013-10-31 15:03:35 -0700823 final CellLayout dropLayout =
824 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
825 dropLayout.setDropPending(true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700826 onComplete = new Runnable() {
827 @Override
828 public void run() {
829 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohen917e3882013-10-31 15:03:35 -0700830 dropLayout.setDropPending(false);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700831 }
832 };
Winson Chung5aaab772012-04-27 15:24:02 -0700833 }
Adam Cohenad4e15c2013-10-17 16:21:35 -0700834 mWorkspace.removeExtraEmptyScreen(true, onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY,
835 false);
Adam Cohened66b2b2012-01-23 17:28:51 -0800836 return;
837 }
838
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800839 // The pattern used here is that a user PICKs a specific application,
840 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700841
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800842 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
843 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700844 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800845 final PendingAddArguments args = new PendingAddArguments();
846 args.requestCode = requestCode;
847 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700848 args.container = mPendingAddInfo.container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700849 args.screenId = mPendingAddInfo.screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -0700850 args.cellX = mPendingAddInfo.cellX;
851 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800852 if (isWorkspaceLocked()) {
853 sPendingAddList.add(args);
854 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700855 completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800856 }
Adam Cohenad4e15c2013-10-17 16:21:35 -0700857 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
858 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Adam Cohen00074722013-10-11 17:46:09 -0700859 } else if (resultCode == RESULT_CANCELED) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700860 mWorkspace.removeExtraEmptyScreen(true, exitSpringLoaded,
861 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800862 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800863 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800864 }
865
866 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700867 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700868 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800869 Runnable onCompleteRunnable = null;
870 int animationType = 0;
871
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700872 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800873 if (resultCode == RESULT_OK) {
874 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
875 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700876 mPendingAddWidgetInfo);
877 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800878 onCompleteRunnable = new Runnable() {
879 @Override
880 public void run() {
881 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700882 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700883 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
884 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800885 }
886 };
887 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800888 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800889 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800890 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700891 if (mDragLayer.getAnimatedView() != null) {
892 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
893 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
894 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700895 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700896 // The animated view may be null in the case of a rotation during widget configuration
897 onCompleteRunnable.run();
898 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800899 }
900
901 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700902 protected void onStop() {
903 super.onStop();
904 FirstFrameAnimatorHelper.setIsVisible(false);
905 }
906
907 @Override
908 protected void onStart() {
909 super.onStart();
910 FirstFrameAnimatorHelper.setIsVisible(true);
911 }
912
913 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800914 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200915 long startTime = 0;
916 if (DEBUG_RESUME_TIME) {
917 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400918 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200919 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800920 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700921
Winson Chung4a2afa32012-07-19 14:53:05 -0700922 // Restore the previous launcher state
923 if (mOnResumeState == State.WORKSPACE) {
924 showWorkspace(false);
925 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -0800926 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700927 }
928 mOnResumeState = State.NONE;
929
Craig Mautner360310b2012-10-26 15:13:08 -0700930 // Background was set to gradient in onPause(), restore to black if in all apps.
931 setWorkspaceBackground(mState == State.WORKSPACE);
932
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800933 mPaused = false;
Winson Chung4a2afa32012-07-19 14:53:05 -0700934 sPausedFromUserAction = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700935 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400936 mWorkspaceLoading = true;
Derek Prothro7aff3992013-12-10 14:00:37 -0500937 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400938 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700939 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800940 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700941 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200942 // We might have postponed some bind calls until onResume (see waitUntilResume) --
943 // execute them here
944 long startTimeCallbacks = 0;
945 if (DEBUG_RESUME_TIME) {
946 startTimeCallbacks = System.currentTimeMillis();
947 }
948
949 if (mAppsCustomizeContent != null) {
950 mAppsCustomizeContent.setBulkBind(true);
951 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700952 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
953 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200954 }
955 if (mAppsCustomizeContent != null) {
956 mAppsCustomizeContent.setBulkBind(false);
957 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700958 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200959 if (DEBUG_RESUME_TIME) {
960 Log.d(TAG, "Time spent processing callbacks in onResume: " +
961 (System.currentTimeMillis() - startTimeCallbacks));
962 }
Michael Jurka447bf842013-05-15 14:52:15 +0200963 }
Michael Jurka54554252013-08-01 12:52:23 +0200964 if (mOnResumeCallbacks.size() > 0) {
965 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
966 mOnResumeCallbacks.get(i).run();
967 }
968 mOnResumeCallbacks.clear();
969 }
Winson Chunge4e50662012-01-23 14:45:13 -0800970
971 // Reset the pressed state of icons that were locked in the press state while activities
972 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800973 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800974 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800975 mWaitingForResume.setStayPressed(false);
976 }
Winson Chunge4e50662012-01-23 14:45:13 -0800977 if (mAppsCustomizeContent != null) {
978 // Resets the previous all apps icon press state
979 mAppsCustomizeContent.resetDrawableState();
980 }
Winson Chung82963d52013-10-09 11:20:57 -0700981
Adam Cohen06dff352012-06-01 17:17:08 -0700982 // It is possible that widgets can receive updates while launcher is not in the foreground.
983 // Consequently, the widgets will be inflated in the orientation of the foreground activity
984 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
985 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -0700986 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -0700987
Winson Chung780fe592013-09-26 14:48:44 -0700988 // Process any items that were added while Launcher was away.
989 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
990
Winson Chung5841efa2013-09-30 18:06:44 -0700991 // Update the voice search button proxy
992 updateVoiceButtonProxyVisible(false);
993
Adam Cohenf9426d52012-06-04 17:26:21 -0700994 // Again, as with the above scenario, it's possible that one or more of the global icons
995 // were updated in the wrong orientation.
996 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +0200997 if (DEBUG_RESUME_TIME) {
998 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
999 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001000
1001 if (mWorkspace.getCustomContentCallbacks() != null) {
1002 // If we are resuming and the custom content is the current page, we call onShow().
1003 // It is also poassible that onShow will instead be called slightly after first layout
1004 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1005 if (mWorkspace.isOnOrMovingToCustomContent()) {
1006 mWorkspace.getCustomContentCallbacks().onShow();
1007 }
1008 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001009 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001010 mWorkspace.onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001011 }
1012
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001013 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001014 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001015 // Ensure that items added to Launcher are queued until Launcher returns
1016 InstallShortcutReceiver.enableInstallQueue();
1017
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001018 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001019 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001020 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001021 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001022
1023 // We call onHide() aggressively. The custom content callbacks should be able to
1024 // debounce excess onHide calls.
1025 if (mWorkspace.getCustomContentCallbacks() != null) {
1026 mWorkspace.getCustomContentCallbacks().onHide();
1027 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001028 }
Romain Guycbb89e42009-06-08 15:52:54 -07001029
Adam Cohen66a01fd2013-06-11 12:48:00 -07001030 protected void onFinishBindingItems() {
Adam Cohen82398362013-09-29 12:57:34 -07001031 if (mWorkspace != null && hasCustomContentToLeft() && mWorkspace.hasCustomContent()) {
Dave Hawkeya8881582013-09-17 15:55:33 -06001032 addCustomContentToLeft();
1033 }
Adam Cohen66a01fd2013-06-11 12:48:00 -07001034 }
1035
Adam Cohenbffe7452013-07-22 18:21:45 -07001036 QSBScroller mQsbScroller = new QSBScroller() {
1037 int scrollY = 0;
1038
1039 @Override
1040 public void setScrollY(int scroll) {
1041 scrollY = scroll;
1042
1043 if (mWorkspace.isOnOrMovingToCustomContent()) {
1044 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001045 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001046 }
1047 }
1048 };
1049
1050 public void resetQSBScroll() {
1051 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001052 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001053 }
1054
1055 public interface CustomContentCallbacks {
1056 // Custom content is completely shown
1057 public void onShow();
1058
1059 // Custom content is completely hidden
1060 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001061
1062 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1063 public void onScrollProgressChanged(float progress);
Adam Cohenbffe7452013-07-22 18:21:45 -07001064 }
1065
Adam Cohen30bacb22013-08-29 14:25:25 -07001066 protected void startSettings() {
1067 }
1068
Adam Cohenbffe7452013-07-22 18:21:45 -07001069 public interface QSBScroller {
1070 public void setScrollY(int scrollY);
1071 }
1072
Winson Chung98ca0f72013-07-29 12:58:51 -07001073 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001074 CustomContentCallbacks callbacks, String description) {
1075 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001076 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001077 }
1078
Adam Cohenedb40762013-07-18 16:45:45 -07001079 // The custom content needs to offset its content to account for the QSB
1080 public int getTopOffsetForCustomContent() {
1081 return mWorkspace.getPaddingTop();
1082 }
1083
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001084 @Override
1085 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001086 // Flag the loader to stop early before switching
1087 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001088 if (mAppsCustomizeContent != null) {
1089 mAppsCustomizeContent.surrender();
1090 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001091 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001092 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001093
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001094 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001095 @Override
1096 public void onWindowFocusChanged(boolean hasFocus) {
1097 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001098 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001099 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001100
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001101 private boolean acceptFilter() {
1102 final InputMethodManager inputManager = (InputMethodManager)
1103 getSystemService(Context.INPUT_METHOD_SERVICE);
1104 return !inputManager.isFullscreenMode();
1105 }
1106
1107 @Override
1108 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001109 final int uniChar = event.getUnicodeChar();
1110 final boolean handled = super.onKeyDown(keyCode, event);
1111 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1112 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001113 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1114 keyCode, event);
1115 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001116 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001117 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001118 // showSearchDialog()
1119 // If there are multiple keystrokes before the search dialog takes focus,
1120 // onSearchRequested() will be called for every keystroke,
1121 // but it is idempotent, so it's fine.
1122 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001123 }
1124 }
1125
Joe Onorato8a9625e2010-01-28 15:55:35 -08001126 // Eat the long press event so the keyboard doesn't come up.
1127 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1128 return true;
1129 }
1130
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001131 return handled;
1132 }
1133
Karl Rosaen138a0412009-04-23 19:00:21 -07001134 private String getTypedText() {
1135 return mDefaultKeySsb.toString();
1136 }
1137
1138 private void clearTypedText() {
1139 mDefaultKeySsb.clear();
1140 mDefaultKeySsb.clearSpans();
1141 Selection.setSelection(mDefaultKeySsb, 0);
1142 }
1143
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001144 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001145 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1146 * State
1147 */
1148 private static State intToState(int stateOrdinal) {
1149 State state = State.WORKSPACE;
1150 final State[] stateValues = State.values();
1151 for (int i = 0; i < stateValues.length; i++) {
1152 if (stateValues[i].ordinal() == stateOrdinal) {
1153 state = stateValues[i];
1154 break;
1155 }
1156 }
1157 return state;
1158 }
1159
1160 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001161 * Restores the previous state, if it exists.
1162 *
1163 * @param savedState The previous state.
1164 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001165 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001166 private void restoreState(Bundle savedState) {
1167 if (savedState == null) {
1168 return;
1169 }
1170
Michael Jurka883f55b2010-10-21 15:47:14 -07001171 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001172 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001173 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001174 }
1175
Adam Cohen21cd0022013-10-09 18:57:02 -07001176 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1177 PagedView.INVALID_RESTORE_PAGE);
1178 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001179 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001180 }
1181
Winson Chung3d503fb2011-07-13 17:25:49 -07001182 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001183 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001184
Winson Chung3d503fb2011-07-13 17:25:49 -07001185 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1186 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001187 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001188 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1189 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001190 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1191 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1192 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001193 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Adam Cohen87a9f5b2012-05-29 16:16:51 -07001194 mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001195 mRestoring = true;
1196 }
1197
1198 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1199 if (renameFolder) {
1200 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001201 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001202 mRestoring = true;
1203 }
Winson Chunga12a2502010-12-20 14:41:35 -08001204
Winson Chung785d2eb2011-04-14 16:08:02 -07001205 // Restore the AppsCustomize tab
1206 if (mAppsCustomizeTabHost != null) {
1207 String curTab = savedState.getString("apps_customize_currentTab");
1208 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001209 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001210 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001211 mAppsCustomizeContent.loadAssociatedPages(
1212 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001213 }
1214
Winson Chung5afbf7b2011-07-25 11:53:08 -07001215 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1216 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001217 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001218 mItemIdToViewId = (HashMap<Integer, Integer>)
1219 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001220 }
1221
1222 /**
1223 * Finds all the views we need and configure them properly.
1224 */
1225 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001226 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001227
Craig Mautner360310b2012-10-26 15:13:08 -07001228 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001229 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1230 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Craig Mautner360310b2012-10-26 15:13:08 -07001231
John Spurlock77e1f472013-09-11 10:09:51 -04001232 mLauncherView.setSystemUiVisibility(
1233 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001234 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001235
Winson Chung4c98d922011-05-31 16:50:48 -07001236 // Setup the drag layer
1237 mDragLayer.setup(this, dragController);
1238
Winson Chung3d503fb2011-07-13 17:25:49 -07001239 // Setup the hotseat
1240 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1241 if (mHotseat != null) {
1242 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001243 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001244 }
1245
Adam Cohenf358a4b2013-07-23 16:47:31 -07001246 mOverviewPanel = findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001247 View widgetButton = findViewById(R.id.widget_button);
1248 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001249 @Override
1250 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001251 if (!mWorkspace.isSwitchingState()) {
1252 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
1253 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001254 }
1255 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001256 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1257
1258 View wallpaperButton = findViewById(R.id.wallpaper_button);
1259 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001260 @Override
1261 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001262 if (!mWorkspace.isSwitchingState()) {
1263 startWallpaper();
1264 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001265 }
1266 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001267 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1268
1269 View settingsButton = findViewById(R.id.settings_button);
1270 settingsButton.setOnClickListener(new OnClickListener() {
Adam Cohen30bacb22013-08-29 14:25:25 -07001271 @Override
1272 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001273 if (!mWorkspace.isSwitchingState()) {
1274 startSettings();
1275 }
Adam Cohen30bacb22013-08-29 14:25:25 -07001276 }
1277 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001278 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
Adam Cohendbdff6b2013-09-18 19:09:15 -07001279 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001280
Winson Chung4c98d922011-05-31 16:50:48 -07001281 // Setup the workspace
1282 mWorkspace.setHapticFeedbackEnabled(false);
1283 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001284 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001285 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001286
Winson Chungf0ea4d32011-06-06 14:27:16 -07001287 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -07001288 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001289
Winson Chungf0ea4d32011-06-06 14:27:16 -07001290 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001291 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001292 mAppsCustomizeContent = (AppsCustomizePagedView)
1293 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1294 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001295
Winson Chung3d503fb2011-07-13 17:25:49 -07001296 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001297 dragController.setDragScoller(mWorkspace);
1298 dragController.setScrollView(mDragLayer);
1299 dragController.setMoveTarget(mWorkspace);
1300 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001301 if (mSearchDropTargetBar != null) {
1302 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001303 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001304
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001305 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001306 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001307 mWeightWatcher = new WeightWatcher(this);
1308 mWeightWatcher.setAlpha(0.5f);
1309 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001310 new FrameLayout.LayoutParams(
1311 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001312 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001313 Gravity.BOTTOM)
1314 );
Adam Cohen39a06042013-07-19 14:30:12 -07001315
1316 boolean show = shouldShowWeightWatcher();
1317 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001318 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001319 }
1320
1321 /**
1322 * Creates a view representing a shortcut.
1323 *
1324 * @param info The data structure describing the shortcut.
1325 *
1326 * @return A View inflated from R.layout.application.
1327 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001328 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001329 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001330 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001331 }
1332
1333 /**
1334 * Creates a view representing a shortcut inflated from the specified resource.
1335 *
1336 * @param layoutResId The id of the XML layout used to create the shortcut.
1337 * @param parent The group the shortcut belongs to.
1338 * @param info The data structure describing the shortcut.
1339 *
1340 * @return A View inflated from layoutResId.
1341 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001342 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001343 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1344 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001345 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001346 return favorite;
1347 }
1348
1349 /**
1350 * Add an application shortcut to the workspace.
1351 *
1352 * @param data The intent describing the application.
1353 * @param cellInfo The position on screen where to create the shortcut.
1354 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001355 void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001356 final int[] cellXY = mTmpAddItemCellCoordinates;
Adam Cohendcd297f2013-06-18 13:13:40 -07001357 final CellLayout layout = getCellLayout(container, screenId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001358
Adam Cohenfbba09b2011-07-18 21:43:05 -07001359 // First we check if we already know the exact location where we want to add this item.
1360 if (cellX >= 0 && cellY >= 0) {
1361 cellXY[0] = cellX;
1362 cellXY[1] = cellY;
1363 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Winson Chung93eef082012-03-23 15:59:27 -07001364 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001365 return;
1366 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001367
Patrick Dubroy002cbf42011-03-03 16:36:21 -08001368 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001369
Romain Guy73b979d2009-06-09 12:57:21 -07001370 if (info != null) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07001371 info.setActivity(this, data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001372 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001373 info.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07001374 mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -07001375 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001376 } else {
1377 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001378 }
1379 }
Romain Guycbb89e42009-06-08 15:52:54 -07001380
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001381 /**
1382 * Add a shortcut to the workspace.
1383 *
1384 * @param data The intent describing the shortcut.
1385 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001386 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001387 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001388 int cellY) {
1389 int[] cellXY = mTmpAddItemCellCoordinates;
1390 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001391 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001392
Michael Jurkad3ef3062010-11-23 16:23:58 -08001393 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001394
Adam Cohen558baaf2011-08-15 15:22:57 -07001395 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001396 if (info == null) {
1397 return;
1398 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001399 final View view = createShortcut(info);
1400
Adam Cohenfbba09b2011-07-18 21:43:05 -07001401 // First we check if we already know the exact location where we want to add this item.
1402 if (cellX >= 0 && cellY >= 0) {
1403 cellXY[0] = cellX;
1404 cellXY[1] = cellY;
1405 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001406
1407 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001408 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001409 true, null,null)) {
1410 return;
1411 }
1412 DragObject dragObject = new DragObject();
1413 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001414 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1415 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001416 return;
1417 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001418 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001419 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001420 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001421 foundCellSpan = (result != null);
1422 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001423 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001424 }
1425
1426 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001427 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001428 return;
1429 }
1430
Adam Cohendcd297f2013-06-18 13:13:40 -07001431 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001432
1433 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001434 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001435 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001436 }
1437 }
1438
Adam Cohen2f093b62012-04-30 18:59:53 -07001439 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1440 int minHeight) {
1441 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001442 // We want to account for the extra amount of padding that we are adding to the widget
1443 // to ensure that it gets the full amount of space that it has requested
1444 int requiredWidth = minWidth + padding.left + padding.right;
1445 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001446 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001447 }
1448
Adam Cohen2f093b62012-04-30 18:59:53 -07001449 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1450 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001451 }
1452
Adam Cohen2f093b62012-04-30 18:59:53 -07001453 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1454 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001455 }
1456
Adam Cohen2f093b62012-04-30 18:59:53 -07001457 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1458 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001459 }
1460
Adam Cohen2f093b62012-04-30 18:59:53 -07001461 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1462 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001463 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001464 }
1465
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001466 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001467 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001468 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001469 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001470 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001471 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001472 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001473 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1474 if (appWidgetInfo == null) {
1475 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1476 }
Romain Guycbb89e42009-06-08 15:52:54 -07001477
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001478 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001479 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001480
Adam Cohen2f093b62012-04-30 18:59:53 -07001481 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1482 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001483
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001484 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001485 // We have saved the position to which the widget was dragged-- this really only matters
1486 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001487 int[] cellXY = mTmpAddItemCellCoordinates;
1488 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001489 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001490 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001491 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1492 cellXY[0] = mPendingAddInfo.cellX;
1493 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001494 spanXY[0] = mPendingAddInfo.spanX;
1495 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001496 foundCellSpan = true;
1497 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001498 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001499 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001500 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1501 spanXY[1], cellXY, finalSpan);
1502 spanXY[0] = finalSpan[0];
1503 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001504 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001505 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001506 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001507 }
1508
Michael Jurka0280c3b2010-09-17 15:00:07 -07001509 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001510 if (appWidgetId != -1) {
1511 // Deleting an app widget ID is a void call but writes to disk before returning
1512 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001513 new AsyncTask<Void, Void, Void>() {
1514 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001515 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001516 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001517 }
Michael Jurka43467462013-11-14 12:03:58 +01001518 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001519 }
Winson Chung93eef082012-03-23 15:59:27 -07001520 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001521 return;
1522 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001523
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001524 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001525 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1526 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001527 launcherInfo.spanX = spanXY[0];
1528 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001529 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1530 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001531
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001532 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001533 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001534
1535 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001536 if (hostView == null) {
1537 // Perform actual inflation because we're live
1538 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1539 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1540 } else {
1541 // The AppWidgetHostView has already been inflated and instantiated
1542 launcherInfo.hostView = hostView;
1543 }
Romain Guycbb89e42009-06-08 15:52:54 -07001544
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001545 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001546 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001547 launcherInfo.notifyWidgetSizeChanged(this);
1548
Adam Cohendcd297f2013-06-18 13:13:40 -07001549 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001550 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001551
1552 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001553 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001554 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001555 }
Romain Guycbb89e42009-06-08 15:52:54 -07001556
Adam Cohended9f8d2010-11-03 13:25:16 -07001557 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1558 @Override
1559 public void onReceive(Context context, Intent intent) {
1560 final String action = intent.getAction();
1561 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1562 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001563 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001564 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001565
Winson Chungc100e8e2011-08-09 16:02:43 -07001566 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001567 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001568 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001569 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001570 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001571 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1572 mUserPresent = true;
1573 updateRunning();
1574 }
1575 }
1576 };
1577
1578 @Override
1579 public void onAttachedToWindow() {
1580 super.onAttachedToWindow();
1581
1582 // Listen for broadcasts related to user-presence
1583 final IntentFilter filter = new IntentFilter();
1584 filter.addAction(Intent.ACTION_SCREEN_OFF);
1585 filter.addAction(Intent.ACTION_USER_PRESENT);
1586 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001587 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohend113e0c2010-11-11 10:48:05 -08001588 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001589 mVisible = true;
1590 }
1591
1592 @Override
1593 public void onDetachedFromWindow() {
1594 super.onDetachedFromWindow();
1595 mVisible = false;
1596
Adam Cohend113e0c2010-11-11 10:48:05 -08001597 if (mAttached) {
1598 unregisterReceiver(mReceiver);
1599 mAttached = false;
1600 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001601 updateRunning();
1602 }
1603
1604 public void onWindowVisibilityChanged(int visibility) {
1605 mVisible = visibility == View.VISIBLE;
1606 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001607 // The following code used to be in onResume, but it turns out onResume is called when
1608 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1609 // is a more appropriate event to handle
1610 if (mVisible) {
1611 mAppsCustomizeTabHost.onWindowVisible();
1612 if (!mWorkspaceLoading) {
1613 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001614 // We want to let Launcher draw itself at least once before we force it to build
1615 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001616 // apps is nice and speedy.
1617 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001618 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001619 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001620 if (mStarted) return;
1621 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001622 // We delay the layer building a bit in order to give
1623 // other message processing a time to run. In particular
1624 // this avoids a delay in hiding the IME if it was
1625 // currently shown, because doing that may involve
1626 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001627 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001628 final ViewTreeObserver.OnDrawListener listener = this;
1629 mWorkspace.post(new Runnable() {
1630 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001631 if (mWorkspace != null &&
1632 mWorkspace.getViewTreeObserver() != null) {
1633 mWorkspace.getViewTreeObserver().
1634 removeOnDrawListener(listener);
1635 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001636 }
1637 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001638 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001639 }
1640 });
1641 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001642 // When Launcher comes back to foreground, a different Activity might be responsible for
1643 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001644 if (!DISABLE_MARKET_BUTTON) {
1645 updateAppMarketIcon();
1646 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001647 clearTypedText();
1648 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001649 }
1650
1651 private void sendAdvanceMessage(long delay) {
1652 mHandler.removeMessages(ADVANCE_MSG);
1653 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1654 mHandler.sendMessageDelayed(msg, delay);
1655 mAutoAdvanceSentTime = System.currentTimeMillis();
1656 }
1657
1658 private void updateRunning() {
1659 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1660 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1661 mAutoAdvanceRunning = autoAdvanceRunning;
1662 if (autoAdvanceRunning) {
1663 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1664 sendAdvanceMessage(delay);
1665 } else {
1666 if (!mWidgetsToAdvance.isEmpty()) {
1667 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1668 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1669 }
1670 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001671 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001672 }
1673 }
1674 }
1675
1676 private final Handler mHandler = new Handler() {
1677 @Override
1678 public void handleMessage(Message msg) {
1679 if (msg.what == ADVANCE_MSG) {
1680 int i = 0;
1681 for (View key: mWidgetsToAdvance.keySet()) {
1682 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1683 final int delay = mAdvanceStagger * i;
1684 if (v instanceof Advanceable) {
1685 postDelayed(new Runnable() {
1686 public void run() {
1687 ((Advanceable) v).advance();
1688 }
1689 }, delay);
1690 }
1691 i++;
1692 }
1693 sendAdvanceMessage(mAdvanceInterval);
1694 }
1695 }
1696 };
1697
1698 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001699 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001700 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1701 if (v instanceof Advanceable) {
1702 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001703 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001704 updateRunning();
1705 }
1706 }
1707
1708 void removeWidgetToAutoAdvance(View hostView) {
1709 if (mWidgetsToAdvance.containsKey(hostView)) {
1710 mWidgetsToAdvance.remove(hostView);
1711 updateRunning();
1712 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001713 }
1714
Joe Onorato9c1289c2009-08-17 11:03:03 -04001715 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001716 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001717 launcherInfo.hostView = null;
1718 }
1719
Winson Chung93eef082012-03-23 15:59:27 -07001720 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1721 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1722 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001723 }
1724
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001725 public LauncherAppWidgetHost getAppWidgetHost() {
1726 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001727 }
Romain Guycbb89e42009-06-08 15:52:54 -07001728
Winson Chunga9abd0e2010-10-27 17:18:37 -07001729 public LauncherModel getModel() {
1730 return mModel;
1731 }
1732
Bjorn Bringertc459e522013-06-07 19:36:01 +01001733 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001734 getWindow().closeAllPanels();
1735
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001736 // Whatever we were doing is hereby canceled.
1737 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001738 }
1739
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001740 @Override
1741 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001742 long startTime = 0;
1743 if (DEBUG_RESUME_TIME) {
1744 startTime = System.currentTimeMillis();
1745 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001746 super.onNewIntent(intent);
1747
1748 // Close the menu
1749 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001750 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001751 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001752
Adam Cohened307df2013-10-02 09:37:31 -07001753 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1754 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1755 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001756
Adam Cohen6fecd412013-10-02 17:41:50 -07001757 if (mWorkspace == null) {
1758 // Can be cases where mWorkspace is null, this prevents a NPE
1759 return;
1760 }
1761 Folder openFolder = mWorkspace.getOpenFolder();
1762 // In all these cases, only animate if we're already on home
1763 mWorkspace.exitWidgetResizeMode();
1764 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001765 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001766 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001767 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001768
Adam Cohen6fecd412013-10-02 17:41:50 -07001769 closeFolder();
1770 exitSpringLoadedDragMode();
1771
1772 // If we are already on home, then just animate back to the workspace,
1773 // otherwise, just wait until onResume to set the state back to Workspace
1774 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001775 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001776 } else {
1777 mOnResumeState = State.WORKSPACE;
1778 }
1779
1780 final View v = getWindow().peekDecorView();
1781 if (v != null && v.getWindowToken() != null) {
1782 InputMethodManager imm = (InputMethodManager)getSystemService(
1783 INPUT_METHOD_SERVICE);
1784 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1785 }
1786
1787 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001788 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001789 mAppsCustomizeTabHost.reset();
1790 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001791
1792 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001793 }
Adam Cohened307df2013-10-02 09:37:31 -07001794
Michael Jurka447bf842013-05-15 14:52:15 +02001795 if (DEBUG_RESUME_TIME) {
1796 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1797 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001798 }
1799
Adam Coppa120b8e2013-11-12 16:26:04 +00001800 /**
1801 * Override point for subclasses to prevent movement to the default screen when the home
1802 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1803 */
1804 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1805 return true;
1806 }
1807
1808 /**
1809 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1810 */
1811 protected void onHomeIntent() {
1812 // Do nothing
1813 }
1814
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001815 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001816 public void onRestoreInstanceState(Bundle state) {
1817 super.onRestoreInstanceState(state);
1818 for (int page: mSynchronouslyBoundPages) {
1819 mWorkspace.restoreInstanceStateForChild(page);
1820 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001821 }
1822
1823 @Override
1824 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001825 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001826 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1827 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001828 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001829 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001830
Michael Jurka883f55b2010-10-21 15:47:14 -07001831 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001832 // We close any open folder since it will not be re-opened, and we need to make sure
1833 // this state is reflected.
1834 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001835
Adam Cohendcd297f2013-06-18 13:13:40 -07001836 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001837 mWaitingForResult) {
1838 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001839 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001840 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1841 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001842 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1843 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1844 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001845 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001846 }
1847
1848 if (mFolderInfo != null && mWaitingForResult) {
1849 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1850 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1851 }
Michael Jurka946ad472010-07-09 18:05:18 -07001852
Winson Chung785d2eb2011-04-14 16:08:02 -07001853 // Save the current AppsCustomize tab
1854 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08001855 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1856 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001857 if (currentTabTag != null) {
1858 outState.putString("apps_customize_currentTab", currentTabTag);
1859 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001860 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1861 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001862 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001863 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001864 }
1865
1866 @Override
1867 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001868 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001869
Winson Chunge7a03942011-08-05 15:05:12 -07001870 // Remove all pending runnables
1871 mHandler.removeMessages(ADVANCE_MSG);
1872 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001873 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001874
Winson Chungcd2b0142011-06-08 16:02:26 -07001875 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001876 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001877 mModel.stopLoader();
1878 app.setLauncher(null);
1879
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001880 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001881 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001882 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001883 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001884 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001885 mAppWidgetHost = null;
1886
1887 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001888
1889 TextKeyListener.getInstance().release();
1890
Winson Chung81b52252012-08-27 15:34:29 -07001891 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
1892 // to prevent leaking Launcher activities on orientation change.
1893 if (mModel != null) {
1894 mModel.unbindItemInfosAndClearQueuedBindRunnables();
1895 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001896
1897 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001898 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001899
Adam Cohenaccf3bf2012-04-30 16:07:43 -07001900 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001901 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08001902 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001903 mWorkspace = null;
1904 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001905
Michael Jurka2ecf9952012-06-18 12:52:28 -07001906 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001907 }
1908
Adam Cohena9cf38f2011-05-02 15:36:58 -07001909 public DragController getDragController() {
1910 return mDragController;
1911 }
1912
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001913 @Override
1914 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001915 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001916 super.startActivityForResult(intent, requestCode);
1917 }
1918
Winson Chung70d72102011-08-12 11:24:35 -07001919 /**
1920 * Indicates that we want global search for this activity by setting the globalSearch
1921 * argument for {@link #startSearch} to true.
1922 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001923 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001924 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001925 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001926
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001927 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001928
Karl Rosaen138a0412009-04-23 19:00:21 -07001929 if (initialQuery == null) {
1930 // Use any text typed in the launcher as the initial query
1931 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001932 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001933 if (appSearchData == null) {
1934 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01001935 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001936 }
Winson Chungadf0c182012-08-23 14:59:07 -07001937 Rect sourceBounds = new Rect();
1938 if (mSearchDropTargetBar != null) {
1939 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
1940 }
Romain Guycbb89e42009-06-08 15:52:54 -07001941
Bjorn Bringertc459e522013-06-07 19:36:01 +01001942 startSearch(initialQuery, selectInitialQuery,
1943 appSearchData, sourceBounds);
1944 }
1945
1946 public void startSearch(String initialQuery,
1947 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07001948 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01001949 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07001950 }
1951
1952 /**
1953 * Starts the global search activity. This code is a copied from SearchManager
1954 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01001955 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07001956 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001957 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07001958 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
1959 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
1960 if (globalSearchActivity == null) {
1961 Log.w(TAG, "No global search activity found.");
1962 return;
1963 }
1964 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1965 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1966 intent.setComponent(globalSearchActivity);
1967 // Make sure that we have a Bundle to put source in
1968 if (appSearchData == null) {
1969 appSearchData = new Bundle();
1970 } else {
1971 appSearchData = new Bundle(appSearchData);
1972 }
1973 // Set source to package name of app that starts global search, if not set already.
1974 if (!appSearchData.containsKey("source")) {
1975 appSearchData.putString("source", getPackageName());
1976 }
1977 intent.putExtra(SearchManager.APP_DATA, appSearchData);
1978 if (!TextUtils.isEmpty(initialQuery)) {
1979 intent.putExtra(SearchManager.QUERY, initialQuery);
1980 }
1981 if (selectInitialQuery) {
1982 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
1983 }
1984 intent.setSourceBounds(sourceBounds);
1985 try {
1986 startActivity(intent);
1987 } catch (ActivityNotFoundException ex) {
1988 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
1989 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001990 }
1991
Winson Chung70d72102011-08-12 11:24:35 -07001992 @Override
Winson Chung70d72102011-08-12 11:24:35 -07001993 public boolean onPrepareOptionsMenu(Menu menu) {
1994 super.onPrepareOptionsMenu(menu);
Dan Sandler14c6a3f2014-01-07 14:12:27 -05001995 showOverviewMode(true);
Michael Jurkab94f3f82013-09-11 18:08:54 +02001996 return false;
Winson Chung70d72102011-08-12 11:24:35 -07001997 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001998
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001999 @Override
2000 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002001 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002002 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002003 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002004 }
2005
Joe Onorato9c1289c2009-08-17 11:03:03 -04002006 public boolean isWorkspaceLocked() {
2007 return mWorkspaceLoading || mWaitingForResult;
2008 }
2009
Michael Jurka0280c3b2010-09-17 15:00:07 -07002010 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002011 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002012 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002013 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2014 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002015 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002016 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002017 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002018
Adam Cohenad4e15c2013-10-17 16:21:35 -07002019 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2020 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2021 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2022 }
2023
2024 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2025 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2026 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002027 if (appWidgetInfo.configure != null) {
2028 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002029 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002030
Bjorn Bringert7984c942009-12-09 15:38:25 +00002031 // Launch over to configure widget, if needed
2032 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002033 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002034 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002035 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002036 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002037 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002038 Runnable onComplete = new Runnable() {
2039 @Override
2040 public void run() {
2041 // Exit spring loaded mode if necessary after adding the widget
2042 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2043 null);
2044 }
2045 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002046 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002047 appWidgetInfo);
Adam Cohenad4e15c2013-10-17 16:21:35 -07002048 mWorkspace.removeExtraEmptyScreen(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002049 }
2050 }
Romain Guycbb89e42009-06-08 15:52:54 -07002051
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002052 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002053 // Close any folders that may be open.
2054 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002055 mWorkspace.moveToCustomContentScreen(animate);
2056 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002057 /**
2058 * Process a shortcut drop.
2059 *
2060 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002061 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002062 * @param cell The cell it should be added to, optional
2063 * @param position The location on the screen where it was dropped, optional
2064 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002065 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002066 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002067 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002068 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002069 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002070 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002071
2072 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002073 mPendingAddInfo.cellX = cell[0];
2074 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002075 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002076
2077 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2078 createShortcutIntent.setComponent(componentName);
2079 processShortcut(createShortcutIntent);
2080 }
2081
Adam Cohenfbba09b2011-07-18 21:43:05 -07002082 /**
2083 * Process a widget drop.
2084 *
2085 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002086 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002087 * @param cell The cell it should be added to, optional
2088 * @param position The location on the screen where it was dropped, optional
2089 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002090 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002091 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002092 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002093 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002094 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002095 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002096 mPendingAddInfo.minSpanX = info.minSpanX;
2097 mPendingAddInfo.minSpanY = info.minSpanY;
2098
Adam Cohenfbba09b2011-07-18 21:43:05 -07002099 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002100 mPendingAddInfo.cellX = cell[0];
2101 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002102 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002103 if (span != null) {
2104 mPendingAddInfo.spanX = span[0];
2105 mPendingAddInfo.spanY = span[1];
2106 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002107
Adam Cohened66b2b2012-01-23 17:28:51 -08002108 AppWidgetHostView hostView = info.boundWidget;
2109 int appWidgetId;
2110 if (hostView != null) {
2111 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002112 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002113 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002114 // In this case, we either need to start an activity to get permission to bind
2115 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002116 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002117 Bundle options = info.bindOptions;
2118
2119 boolean success = false;
2120 if (options != null) {
2121 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2122 info.componentName, options);
2123 } else {
2124 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2125 info.componentName);
2126 }
2127 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002128 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002129 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002130 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002131 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2132 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2133 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002134 // TODO: we need to make sure that this accounts for the options bundle.
2135 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002136 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2137 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002138 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002139 }
2140
Joe Onoratodeb98af2010-02-19 14:59:39 -08002141 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002142 // Handle case where user selected "Applications"
2143 String applicationName = getResources().getString(R.string.group_applications);
2144 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07002145
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002146 if (applicationName != null && applicationName.equals(shortcutName)) {
2147 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
2148 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07002149
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002150 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2151 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07002152 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002153 Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002154 } else {
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002155 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002156 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002157 }
2158
Winson Chung24ab2f12010-09-16 14:10:47 -07002159 void processWallpaper(Intent intent) {
2160 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2161 }
2162
Adam Cohendcd297f2013-06-18 13:13:40 -07002163 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002164 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002165 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002166 folderInfo.title = getText(R.string.folder_name);
2167
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002168 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002169 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002170 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002171 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002172
2173 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002174 FolderIcon newFolder =
2175 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002176 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002177 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002178 // Force measure the new folder icon
2179 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2180 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002181 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002182 }
Romain Guycbb89e42009-06-08 15:52:54 -07002183
Joe Onorato9c1289c2009-08-17 11:03:03 -04002184 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002185 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002186 }
2187
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002188 protected void startWallpaper() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002189 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002190 pickWallpaper.setComponent(getWallpaperPickerComponent());
Michael Jurka104c4562013-07-08 18:03:46 -07002191 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002192 }
2193
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002194 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002195 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002196 }
2197
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002198 /**
2199 * Registers various content observers. The current implementation registers
2200 * only a favorites observer to keep track of the favorites applications.
2201 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002202 private void registerContentObservers() {
2203 ContentResolver resolver = getContentResolver();
2204 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2205 true, mWidgetObserver);
2206 }
2207
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002208 @Override
2209 public boolean dispatchKeyEvent(KeyEvent event) {
2210 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2211 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002212 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002213 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002214 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002215 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002216 dumpState();
2217 return true;
2218 }
2219 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002220 }
2221 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2222 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002223 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002224 return true;
2225 }
2226 }
2227
2228 return super.dispatchKeyEvent(event);
2229 }
2230
Joe Onorato88ec0992009-11-19 13:16:06 -08002231 @Override
2232 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002233 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002234 if (mAppsCustomizeContent.getContentType() ==
2235 AppsCustomizePagedView.ContentType.Applications) {
2236 showWorkspace(true);
2237 } else {
2238 showOverviewMode(true);
2239 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002240 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002241 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002242 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002243 Folder openFolder = mWorkspace.getOpenFolder();
2244 if (openFolder.isEditingName()) {
2245 openFolder.dismissEditingName();
2246 } else {
2247 closeFolder();
2248 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002249 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002250 mWorkspace.exitWidgetResizeMode();
2251
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002252 // Back button is a no-op here, but give at least some feedback for the button press
2253 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002254 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002255 }
2256
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002257 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002258 * Re-listen when widgets are reset.
2259 */
2260 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002261 if (mAppWidgetHost != null) {
2262 mAppWidgetHost.startListening();
2263 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002264 }
2265
2266 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002267 * Launches the intent referred by the clicked shortcut.
2268 *
2269 * @param v The view representing the clicked shortcut.
2270 */
2271 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002272 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2273 // view has detached (it's possible for this to happen if the view is removed mid touch).
2274 if (v.getWindowToken() == null) {
2275 return;
2276 }
2277
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002278 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002279 return;
2280 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002281
Adam Cohen1697b792013-09-17 19:08:21 -07002282 if (v instanceof Workspace) {
2283 if (mWorkspace.isInOverviewMode()) {
2284 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002285 }
2286 return;
2287 }
2288
2289 if (v instanceof CellLayout) {
2290 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002291 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002292 }
2293 }
2294
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002295 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002296 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002297 // Open shortcut
Daniel Sandlerff02d492013-08-05 02:12:05 -04002298 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2299 final Intent intent = shortcut.intent;
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002300
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002301 // Check for special shortcuts
2302 if (intent.getComponent() != null) {
2303 final String shortcutClass = intent.getComponent().getClassName();
2304
2305 if (shortcutClass.equals(WidgetAdder.class.getName())) {
Winson Chung82963d52013-10-09 11:20:57 -07002306 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002307 return;
2308 } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2309 MemoryDumpActivity.startDump(this);
2310 return;
Adam Cohen39a06042013-07-19 14:30:12 -07002311 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2312 toggleShowWeightWatcher();
2313 return;
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002314 }
Adam Cohenb5fe60c2013-06-06 22:03:51 -07002315 }
Daniel Sandlerf8577a32013-06-26 14:04:59 -04002316
2317 // Start activities
Joe Onorato13724ea2009-12-02 21:16:35 -08002318 int[] pos = new int[2];
2319 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08002320 intent.setSourceBounds(new Rect(pos[0], pos[1],
2321 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -07002322
2323 boolean success = startActivitySafely(v, intent, tag);
Michael Jurkaddd62e92011-02-16 17:49:14 -08002324
Daniel Sandlerff02d492013-08-05 02:12:05 -04002325 mStats.recordLaunch(intent, shortcut);
2326
Michael Jurkaddd62e92011-02-16 17:49:14 -08002327 if (success && v instanceof BubbleTextView) {
2328 mWaitingForResume = (BubbleTextView) v;
2329 mWaitingForResume.setStayPressed(true);
2330 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002331 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002332 if (v instanceof FolderIcon) {
2333 FolderIcon fi = (FolderIcon) v;
2334 handleFolderClick(fi);
2335 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002336 } else if (v == mAllAppsButton) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002337 if (isAllAppsVisible()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002338 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07002339 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07002340 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07002341 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002342 }
2343 }
2344
Michael Jurka0e260592010-06-30 17:07:39 -07002345 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002346 return false;
2347 }
2348
Michael Jurkaaf442092010-06-10 17:01:57 -07002349 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002350 * Event handler for the search button
2351 *
2352 * @param v The view that was clicked.
2353 */
2354 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002355 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2356
Amith Yamasania135ba82011-08-09 17:42:01 -07002357 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002358 }
2359
2360 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002361 * Event handler for the voice button
2362 *
2363 * @param v The view that was clicked.
2364 */
2365 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002366 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002367
Bjorn Bringertc459e522013-06-07 19:36:01 +01002368 startVoice();
2369 }
2370
2371 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002372 try {
2373 final SearchManager searchManager =
2374 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2375 ComponentName activityName = searchManager.getGlobalSearchActivity();
2376 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002377 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002378 if (activityName != null) {
2379 intent.setPackage(activityName.getPackageName());
2380 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002381 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002382 } catch (ActivityNotFoundException e) {
2383 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002384 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002385 startActivitySafely(null, intent, "onClickVoiceButton");
2386 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002387 }
2388
2389 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002390 * Event handler for the "grid" button that appears on the home screen, which
2391 * enters all apps mode.
2392 *
2393 * @param v The view that was clicked.
2394 */
2395 public void onClickAllAppsButton(View v) {
Winson Chunge7e97e62013-12-02 17:02:50 -08002396 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
Michael Jurka5130e402011-10-13 04:55:35 -07002397 }
2398
2399 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002400 // Provide the same haptic feedback that the system offers for virtual keys.
2401 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002402 }
2403
Adam Cohen61f560d2013-09-30 15:58:20 -07002404 public void performHapticFeedbackOnTouchDown(View v) {
2405 // Provide the same haptic feedback that the system offers for virtual keys.
2406 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2407 }
2408
2409 public View.OnTouchListener getHapticFeedbackTouchListener() {
2410 if (mHapticFeedbackTouchListener == null) {
2411 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2412 @Override
2413 public boolean onTouch(View v, MotionEvent event) {
2414 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2415 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2416 }
2417 return false;
2418 }
2419 };
2420 }
2421 return mHapticFeedbackTouchListener;
2422 }
2423
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002424 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002425 if (!DISABLE_MARKET_BUTTON) {
2426 if (mAppMarketIntent != null) {
2427 startActivitySafely(v, mAppMarketIntent, "app market");
2428 } else {
2429 Log.e(TAG, "Invalid app market intent.");
2430 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002431 }
2432 }
2433
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002434 /**
2435 * Called when the user stops interacting with the launcher.
2436 * This implies that the user is now on the homescreen and is not doing housekeeping.
2437 */
2438 protected void onInteractionEnd() {}
2439
2440 /**
2441 * Called when the user starts interacting with the launcher.
2442 * The possible interactions are:
2443 * - open all apps
2444 * - reorder an app shortcut, or a widget
2445 * - open the overview mode.
2446 * This is a good time to stop doing things that only make sense
2447 * when the user is on the homescreen and not doing housekeeping.
2448 */
2449 protected void onInteractionBegin() {}
2450
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002451 void startApplicationDetailsActivity(ComponentName componentName) {
2452 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002453 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2454 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002455 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung3b1b36b2012-04-24 18:51:14 -07002456 startActivitySafely(null, intent, "startApplicationDetailsActivity");
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002457 }
2458
Michael Jurka1e2f4652013-07-08 18:03:46 -07002459 // returns true if the activity was started
2460 boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002461 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002462 // System applications cannot be installed. For now, show a toast explaining that.
2463 // We may give them the option of disabling apps this way.
2464 int messageId = R.string.uninstall_system_app_text;
2465 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002466 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002467 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002468 String packageName = componentName.getPackageName();
2469 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002470 Intent intent = new Intent(
2471 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002472 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2473 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07002474 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002475 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002476 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002477 }
2478
Michael Jurka86a720e2012-05-09 11:23:23 -07002479 boolean startActivity(View v, Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002480 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Winson Chungc7450e32012-04-17 17:34:08 -07002481
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002482 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002483 // Only launch using the new animation if the shortcut has not opted out (this is a
2484 // private contract between launcher and may be ignored in the future).
2485 boolean useLaunchAnimation = (v != null) &&
2486 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2487 if (useLaunchAnimation) {
Winson Chungc7450e32012-04-17 17:34:08 -07002488 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
2489 v.getMeasuredWidth(), v.getMeasuredHeight());
2490
2491 startActivity(intent, opts.toBundle());
2492 } else {
2493 startActivity(intent);
2494 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002495 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002496 } catch (SecurityException e) {
2497 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002498 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002499 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002500 "or use the exported attribute for this activity. "
2501 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002502 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002503 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002504 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002505
Michael Jurka86a720e2012-05-09 11:23:23 -07002506 boolean startActivitySafely(View v, Intent intent, Object tag) {
2507 boolean success = false;
2508 try {
2509 success = startActivity(v, intent, tag);
2510 } catch (ActivityNotFoundException e) {
2511 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2512 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2513 }
2514 return success;
2515 }
2516
Adam Cohena9cf38f2011-05-02 15:36:58 -07002517 private void handleFolderClick(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002518 final FolderInfo info = folderIcon.getFolderInfo();
Adam Cohen3c81a382011-08-31 22:25:51 -07002519 Folder openFolder = mWorkspace.getFolderForTag(info);
2520
2521 // If the folder info reports that the associated folder is open, then verify that
2522 // it is actually opened. There have been a few instances where this gets out of sync.
2523 if (info.opened && openFolder == null) {
2524 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
Adam Cohendcd297f2013-06-18 13:13:40 -07002525 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
Adam Cohen3c81a382011-08-31 22:25:51 -07002526 info.opened = false;
2527 }
2528
Adam Cohenfb91f302012-06-11 15:45:18 -07002529 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002530 // Close any open folder
2531 closeFolder();
2532 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07002533 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002534 } else {
2535 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002536 int folderScreen;
2537 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002538 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002539 // .. and close it
2540 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002541 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002542 // Close any folder open on the current screen
2543 closeFolder();
2544 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07002545 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002546 }
2547 }
2548 }
2549 }
2550
Adam Cohen268c4752012-06-06 17:47:33 -07002551 /**
2552 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2553 * in the DragLayer in the exact absolute location of the original FolderIcon.
2554 */
2555 private void copyFolderIconToImage(FolderIcon fi) {
2556 final int width = fi.getMeasuredWidth();
2557 final int height = fi.getMeasuredHeight();
2558
2559 // Lazy load ImageView, Bitmap and Canvas
2560 if (mFolderIconImageView == null) {
2561 mFolderIconImageView = new ImageView(this);
2562 }
2563 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2564 mFolderIconBitmap.getHeight() != height) {
2565 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2566 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2567 }
2568
2569 DragLayer.LayoutParams lp;
2570 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2571 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2572 } else {
2573 lp = new DragLayer.LayoutParams(width, height);
2574 }
2575
Adam Cohen307fe232012-08-16 17:55:58 -07002576 // The layout from which the folder is being opened may be scaled, adjust the starting
2577 // view size by this scale factor.
2578 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002579 lp.customPosition = true;
2580 lp.x = mRectForFolderAnimation.left;
2581 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002582 lp.width = (int) (scale * width);
2583 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002584
2585 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2586 fi.draw(mFolderIconCanvas);
2587 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002588 if (fi.getFolder() != null) {
2589 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2590 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002591 }
Adam Cohen268c4752012-06-06 17:47:33 -07002592 // Just in case this image view is still in the drag layer from a previous animation,
2593 // we remove it and re-add it.
2594 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2595 mDragLayer.removeView(mFolderIconImageView);
2596 }
2597 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002598 if (fi.getFolder() != null) {
2599 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002600 }
Adam Cohen268c4752012-06-06 17:47:33 -07002601 }
2602
Adam Cohen2801caf2011-05-13 20:57:39 -07002603 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002604 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002605 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2606 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2607 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2608
Adam Cohenc51934b2011-07-26 21:07:43 -07002609 FolderInfo info = (FolderInfo) fi.getTag();
2610 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2611 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002612 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2613 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002614 }
2615
Adam Cohen268c4752012-06-06 17:47:33 -07002616 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2617 copyFolderIconToImage(fi);
2618 fi.setVisibility(View.INVISIBLE);
2619
Michael Jurka2ecf9952012-06-18 12:52:28 -07002620 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002621 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002622 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2623 oa.start();
2624 }
2625
Adam Cohen268c4752012-06-06 17:47:33 -07002626 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002627 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002628 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2629 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2630 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2631
Adam Cohen268c4752012-06-06 17:47:33 -07002632 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002633
Adam Cohen268c4752012-06-06 17:47:33 -07002634 // We remove and re-draw the FolderIcon in-case it has changed
2635 mDragLayer.removeView(mFolderIconImageView);
2636 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002637 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002638 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002639 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002640 oa.addListener(new AnimatorListenerAdapter() {
2641 @Override
2642 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002643 if (cl != null) {
2644 cl.clearFolderLeaveBehind();
2645 // Remove the ImageView copy of the FolderIcon and make the original visible.
2646 mDragLayer.removeView(mFolderIconImageView);
2647 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002648 }
2649 }
2650 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002651 oa.start();
2652 }
2653
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002654 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002655 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002656 * is animated relative to the specified View. If the View is null, no animation
2657 * is played.
2658 *
2659 * @param folderInfo The FolderInfo describing the folder to open.
2660 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002661 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002662 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002663 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002664
Adam Cohena9cf38f2011-05-02 15:36:58 -07002665 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002666
Adam Cohen4554ee12011-08-03 16:13:21 -07002667 // Just verify that the folder hasn't already been added to the DragLayer.
2668 // There was a one-off crash where the folder had a parent already.
2669 if (folder.getParent() == null) {
2670 mDragLayer.addView(folder);
2671 mDragController.addDropTarget((DropTarget) folder);
2672 } else {
2673 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2674 folder.getParent() + ").");
2675 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002676 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002677 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002678
2679 // Notify the accessibility manager that this folder "window" has appeared and occluded
2680 // the workspace items
2681 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2682 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002683 }
2684
2685 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002686 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002687 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002688 if (folder.isEditingName()) {
2689 folder.dismissEditingName();
2690 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002691 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002692
2693 // Dismiss the folder cling
2694 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002695 }
2696 }
2697
2698 void closeFolder(Folder folder) {
2699 folder.getInfo().opened = false;
2700
2701 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2702 if (parent != null) {
2703 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2704 shrinkAndFadeInFolderIcon(fi);
2705 }
2706 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002707
2708 // Notify the accessibility manager that this folder "window" has disappeard and no
2709 // longer occludeds the workspace items
2710 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002711 }
2712
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002713 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07002714 if (!isDraggingEnabled()) return false;
2715 if (isWorkspaceLocked()) return false;
2716 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002717
Adam Cohen1697b792013-09-17 19:08:21 -07002718 if (v instanceof Workspace) {
2719 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07002720 if (mWorkspace.enterOverviewMode()) {
2721 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2722 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2723 return true;
2724 } else {
2725 return false;
2726 }
Adam Cohen1697b792013-09-17 19:08:21 -07002727 }
Adam Cohen1697b792013-09-17 19:08:21 -07002728 }
2729
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002730 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08002731 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002732 }
2733
Michael Jurka0280c3b2010-09-17 15:00:07 -07002734 resetAddInfo();
2735 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002736 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07002737 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002738 return true;
2739 }
2740
Winson Chung3d503fb2011-07-13 17:25:49 -07002741 // The hotseat touch handling does not go through Workspace, and we always allow long press
2742 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07002743 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07002744 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
2745 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002746 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07002747 // User long pressed on empty space
2748 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2749 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2750 // Disabling reordering until we sort out some issues.
2751 if (mWorkspace.isInOverviewMode()) {
2752 mWorkspace.startReordering(v);
2753 } else {
2754 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07002755 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002756 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002757 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002758 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07002759 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002760 }
2761 }
2762 }
2763 return true;
2764 }
2765
Winson Chung3d503fb2011-07-13 17:25:49 -07002766 boolean isHotseatLayout(View layout) {
2767 return mHotseat != null && layout != null &&
2768 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
2769 }
2770 Hotseat getHotseat() {
2771 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002772 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002773 View getOverviewPanel() {
2774 return mOverviewPanel;
2775 }
Adam Cohenebea84d2011-11-09 17:20:41 -08002776 SearchDropTargetBar getSearchBar() {
2777 return mSearchDropTargetBar;
2778 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002779
Winson Chung3d503fb2011-07-13 17:25:49 -07002780 /**
2781 * Returns the CellLayout of the specified container at the specified screen.
2782 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002783 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002784 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2785 if (mHotseat != null) {
2786 return mHotseat.getLayout();
2787 } else {
2788 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002789 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002790 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07002791 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08002792 }
2793 }
2794
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002795 Workspace getWorkspace() {
2796 return mWorkspace;
2797 }
2798
Daniel Sandler843e8602010-06-07 14:59:01 -04002799 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002800 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002801 }
2802
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002803 /**
2804 * Helper method for the cameraZoomIn/cameraZoomOut animations
2805 * @param view The view being animated
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002806 * @param scaleFactor The scale factor used for the zoom
2807 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002808 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002809 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002810 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002811 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002812
Craig Mautner360310b2012-10-26 15:13:08 -07002813 private void setWorkspaceBackground(boolean workspace) {
2814 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02002815 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07002816 }
2817
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002818 void updateWallpaperVisibility(boolean visible) {
2819 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2820 int curflags = getWindow().getAttributes().flags
2821 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2822 if (wpflags != curflags) {
2823 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2824 }
Craig Mautner360310b2012-10-26 15:13:08 -07002825 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002826 }
2827
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002828 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
2829 if (v instanceof LauncherTransitionable) {
2830 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
2831 }
2832 }
2833
Michael Jurkabed61d22012-02-14 22:51:29 -08002834 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2835 if (v instanceof LauncherTransitionable) {
2836 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2837 }
Winson Chung70442722012-02-10 15:43:22 -08002838
2839 // Update the workspace transition step as well
2840 dispatchOnLauncherTransitionStep(v, 0f);
2841 }
2842
2843 private void dispatchOnLauncherTransitionStep(View v, float t) {
2844 if (v instanceof LauncherTransitionable) {
2845 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
2846 }
Michael Jurkabed61d22012-02-14 22:51:29 -08002847 }
2848
2849 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2850 if (v instanceof LauncherTransitionable) {
2851 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2852 }
Winson Chung70442722012-02-10 15:43:22 -08002853
2854 // Update the workspace transition step as well
2855 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08002856 }
2857
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002858 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002859 * Things to test when changing the following seven functions.
2860 * - Home from workspace
2861 * - from center screen
2862 * - from other screens
2863 * - Home from all apps
2864 * - from center screen
2865 * - from other screens
2866 * - Back from all apps
2867 * - from center screen
2868 * - from other screens
2869 * - Launch app from workspace and quit
2870 * - with back
2871 * - with home
2872 * - Launch app from all apps and quit
2873 * - with back
2874 * - with home
2875 * - Go to a screen that's not the default, then all
2876 * apps, and launch and app, and go back
2877 * - with back
2878 * -with home
2879 * - On workspace, long press power and go back
2880 * - with back
2881 * - with home
2882 * - On all apps, long press power and go back
2883 * - with back
2884 * - with home
2885 * - On workspace, power off
2886 * - On all apps, power off
2887 * - Launch an app and turn off the screen while in that app
2888 * - Go back with home key
2889 * - Go back with back key TODO: make this not go to workspace
2890 * - From all apps
2891 * - From workspace
2892 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2893 * - From all apps
2894 * - From the center workspace
2895 * - From another workspace
2896 */
2897
2898 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002899 * Zoom the camera out from the workspace to reveal 'toView'.
2900 * Assumes that the view to show is anchored at either the very top or very bottom
2901 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002902 */
Michael Jurkabed61d22012-02-14 22:51:29 -08002903 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07002904 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
2905 showAppsCustomizeHelper(animated, springLoaded, contentType);
2906 }
2907 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
2908 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002909 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002910 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002911 mStateAnimation.cancel();
2912 mStateAnimation = null;
2913 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002914 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002915
Winson Chungf0ea4d32011-06-06 14:27:16 -07002916 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2917 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2918 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08002919 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002920 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002921 final int startDelay =
2922 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002923
Michael Jurkab3e22d92011-10-31 15:58:33 -07002924 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002925
Michael Jurkad74c9842011-07-10 12:44:21 -07002926 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002927 Animator workspaceAnim =
2928 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08002929 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08002930 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
2931 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07002932 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
2933 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002934
2935 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002936 toView.setScaleX(scale);
2937 toView.setScaleY(scale);
2938 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2939 scaleAnim.
2940 scaleX(1f).scaleY(1f).
2941 setDuration(duration).
2942 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002943
Winson Chungf0ea4d32011-06-06 14:27:16 -07002944 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002945 toView.setAlpha(0f);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01002946 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08002947 .ofFloat(toView, "alpha", 0f, 1f)
2948 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002949 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Winson Chung70442722012-02-10 15:43:22 -08002950 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
2951 @Override
2952 public void onAnimationUpdate(ValueAnimator animation) {
Michael Jurka059798a2012-09-04 09:20:16 -07002953 if (animation == null) {
2954 throw new RuntimeException("animation is null");
2955 }
Winson Chung70442722012-02-10 15:43:22 -08002956 float t = (Float) animation.getAnimatedValue();
2957 dispatchOnLauncherTransitionStep(fromView, t);
2958 dispatchOnLauncherTransitionStep(toView, t);
2959 }
2960 });
Adam Cohenf16e5712011-01-13 13:31:45 -08002961
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002962 // toView should appear right at the end of the workspace shrink
2963 // animation
Michael Jurka2ecf9952012-06-18 12:52:28 -07002964 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002965 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002966 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002967
2968 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002969 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002970 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002971 // Prepare the position
2972 toView.setTranslationX(0.0f);
2973 toView.setTranslationY(0.0f);
2974 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002975 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002976 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002977 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002978 public void onAnimationEnd(Animator animation) {
Michael Jurkabed61d22012-02-14 22:51:29 -08002979 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2980 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002981
Winson Chungc7d2b602012-05-16 17:02:20 -07002982 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07002983 if (mSearchDropTargetBar != null) {
2984 mSearchDropTargetBar.hideSearchBar(false);
2985 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002986 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002987 });
2988
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002989 if (workspaceAnim != null) {
2990 mStateAnimation.play(workspaceAnim);
2991 }
Michael Jurka1899a362011-11-03 13:50:45 -07002992
2993 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002994
Michael Jurkaa35e35a2012-04-26 15:04:28 -07002995 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
2996 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002997
2998 // If any of the objects being animated haven't been measured/laid out
2999 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003000 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003001 (mWorkspace.getMeasuredWidth() == 0) ||
3002 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003003 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003004 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003005
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003006 final AnimatorSet stateAnimation = mStateAnimation;
3007 final Runnable startAnimRunnable = new Runnable() {
3008 public void run() {
3009 // Check that mStateAnimation hasn't changed while
3010 // we waited for a layout/draw pass
3011 if (mStateAnimation != stateAnimation)
3012 return;
3013 setPivotsForZoom(toView, scale);
3014 dispatchOnLauncherTransitionStart(fromView, animated, false);
3015 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003016 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003017 }
3018 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003019 if (delayAnim) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003020 final ViewTreeObserver observer = toView.getViewTreeObserver();
3021 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3022 public void onGlobalLayout() {
3023 startAnimRunnable.run();
3024 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3025 }
3026 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003027 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003028 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003029 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003030 } else {
3031 toView.setTranslationX(0.0f);
3032 toView.setTranslationY(0.0f);
3033 toView.setScaleX(1.0f);
3034 toView.setScaleY(1.0f);
3035 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003036 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003037
Daniel Sandlere4f98912013-06-25 15:13:26 -04003038 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003039 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003040 if (mSearchDropTargetBar != null) {
3041 mSearchDropTargetBar.hideSearchBar(false);
3042 }
Michael Jurkaabded662011-03-04 12:06:57 -08003043 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003044 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003045 dispatchOnLauncherTransitionStart(fromView, animated, false);
3046 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003047 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003048 dispatchOnLauncherTransitionStart(toView, animated, false);
3049 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003050 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003051 }
3052
3053 /**
3054 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003055 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003056 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003057 */
Adam Cohened307df2013-10-02 09:37:31 -07003058 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003059 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003060
Michael Jurkab3e22d92011-10-31 15:58:33 -07003061 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003062 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003063 mStateAnimation.cancel();
3064 mStateAnimation = null;
3065 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003066 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003067
Winson Chungf0ea4d32011-06-06 14:27:16 -07003068 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08003069 final int fadeOutDuration =
3070 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003071 final float scaleFactor = (float)
3072 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3073 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003074 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003075 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003076 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003077 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
3078 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003079 toState, animated, stagger, -1);
3080 } else if (toState == Workspace.State.SPRING_LOADED ||
3081 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003082 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003083 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003084 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003085
Michael Jurkab3e22d92011-10-31 15:58:33 -07003086 setPivotsForZoom(fromView, scaleFactor);
Winson Chung4afe9b32011-07-27 17:46:20 -07003087 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003088 if (animated) {
Michael Jurka159b4cc2012-01-17 03:00:35 -08003089 final LauncherViewPropertyAnimator scaleAnim =
3090 new LauncherViewPropertyAnimator(fromView);
3091 scaleAnim.
3092 scaleX(scaleFactor).scaleY(scaleFactor).
3093 setDuration(duration).
3094 setInterpolator(new Workspace.ZoomInInterpolator());
3095
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003096 final ObjectAnimator alphaAnim = LauncherAnimUtils
Michael Jurka159b4cc2012-01-17 03:00:35 -08003097 .ofFloat(fromView, "alpha", 1f, 0f)
3098 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07003099 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Winson Chung70442722012-02-10 15:43:22 -08003100 alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
3101 @Override
3102 public void onAnimationUpdate(ValueAnimator animation) {
3103 float t = 1f - (Float) animation.getAnimatedValue();
3104 dispatchOnLauncherTransitionStep(fromView, t);
3105 dispatchOnLauncherTransitionStep(toView, t);
3106 }
3107 });
Michael Jurka159b4cc2012-01-17 03:00:35 -08003108
Michael Jurka2ecf9952012-06-18 12:52:28 -07003109 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurkabed61d22012-02-14 22:51:29 -08003110
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003111 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3112 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Adam Cohen4fe4c932013-10-28 16:02:34 -07003113 mAppsCustomizeContent.stopScrolling();
Michael Jurkabed61d22012-02-14 22:51:29 -08003114
3115 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003116 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003117 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003118 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003119 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3120 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003121 if (onCompleteRunnable != null) {
3122 onCompleteRunnable.run();
3123 }
Chet Haasebc2f0822012-10-26 17:59:53 -07003124 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003125 }
3126 });
3127
Winson Chungf0ea4d32011-06-06 14:27:16 -07003128 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003129 if (workspaceAnim != null) {
3130 mStateAnimation.play(workspaceAnim);
3131 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003132 dispatchOnLauncherTransitionStart(fromView, animated, true);
3133 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003134 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003135 } else {
3136 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003137 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003138 dispatchOnLauncherTransitionStart(fromView, animated, true);
3139 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003140 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003141 dispatchOnLauncherTransitionStart(toView, animated, true);
3142 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003143 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003144 }
3145
Michael Jurkae326f182011-11-21 14:05:46 -08003146 @Override
3147 public void onTrimMemory(int level) {
3148 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003149 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003150 mAppsCustomizeTabHost.onTrimMemory();
3151 }
3152 }
3153
Adam Cohened307df2013-10-02 09:37:31 -07003154 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003155 showWorkspace(animated, null);
3156 }
3157
Adam Cohened307df2013-10-02 09:37:31 -07003158 protected void showWorkspace() {
3159 showWorkspace(true);
3160 }
3161
Adam Cohened66b2b2012-01-23 17:28:51 -08003162 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohened307df2013-10-02 09:37:31 -07003163 if (mWorkspace.isInOverviewMode()) {
3164 mWorkspace.exitOverviewMode(animated);
3165 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003166 if (mState != State.WORKSPACE) {
Winson Chung2d75f122013-09-23 16:53:31 -07003167 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003168 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003169 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003170
Winson Chungc7d2b602012-05-16 17:02:20 -07003171 // Show the search bar (only animate if we were showing the drop target bar in spring
3172 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003173 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003174 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003175 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003176
Michael Jurkab3e22d92011-10-31 15:58:33 -07003177 // Set focus to the AppsCustomize button
3178 if (mAllAppsButton != null) {
3179 mAllAppsButton.requestFocus();
3180 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003181 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003182
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003183 // Change the state *after* we've called all the transition code
3184 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003185
Winson Chung5fb63472011-02-02 17:03:37 -08003186 // Resume the auto-advance of widgets
3187 mUserPresent = true;
3188 updateRunning();
3189
alanv1d4fde62012-10-17 13:15:47 -07003190 // Send an accessibility event to announce the context change
3191 getWindow().getDecorView()
3192 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003193
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003194 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003195 }
3196
Adam Cohened307df2013-10-02 09:37:31 -07003197 void showOverviewMode(boolean animated) {
3198 mWorkspace.setVisibility(View.VISIBLE);
3199 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3200 mState = State.WORKSPACE;
3201 onWorkspaceShown(animated);
3202 }
3203
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003204 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003205 }
3206
Winson Chung82963d52013-10-09 11:20:57 -07003207 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3208 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003209 if (mState != State.WORKSPACE) return;
3210
Winson Chung82963d52013-10-09 11:20:57 -07003211 if (resetPageToZero) {
3212 mAppsCustomizeTabHost.reset();
3213 }
Winson Chungc58497e2013-09-03 17:48:37 -07003214 showAppsCustomizeHelper(animated, false, contentType);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003215 mAppsCustomizeTabHost.requestFocus();
3216
Michael Jurkab3e22d92011-10-31 15:58:33 -07003217 // Change the state *after* we've called all the transition code
3218 mState = State.APPS_CUSTOMIZE;
3219
3220 // Pause the auto-advance of widgets until we are out of AllApps
3221 mUserPresent = false;
3222 updateRunning();
3223 closeFolder();
3224
3225 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003226 getWindow().getDecorView()
3227 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003228 }
3229
Adam Cohen7777d962011-08-18 18:58:38 -07003230 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003231 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003232 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003233 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003234 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003235 }
Adam Cohen7777d962011-08-18 18:58:38 -07003236
Adam Cohenad4e15c2013-10-17 16:21:35 -07003237 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003238 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003239 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3240
Winson Chunge7a03942011-08-05 15:05:12 -07003241 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003242 @Override
3243 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003244 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003245 // Before we show workspace, hide all apps again because
3246 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3247 // clean up our state transition functions
3248 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003249 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003250 } else {
3251 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003252 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003253 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003254 }, delay);
3255
Winson Chung557d6ed2011-07-08 15:34:52 -07003256 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003257
Michael Jurkad3ef3062010-11-23 16:23:58 -08003258 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003259 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003260 final boolean animated = true;
3261 final boolean springLoaded = true;
3262 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003263 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003264 }
3265 // Otherwise, we are not in spring loaded mode, so don't do anything.
3266 }
3267
Michael Jurkab3e22d92011-10-31 15:58:33 -07003268 void lockAllApps() {
3269 // TODO
3270 }
3271
3272 void unlockAllApps() {
3273 // TODO
3274 }
3275
Winson Chungf0ea4d32011-06-06 14:27:16 -07003276 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003277 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003278 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003279 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003280 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003281 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003282 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003283 int duration = 0;
3284 if (mSearchDropTargetBar != null) {
3285 duration = mSearchDropTargetBar.getTransitionInDuration();
3286 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003287 mHotseat.animate().alpha(1f).setDuration(duration);
3288 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003289 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003290 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003291 }
3292 }
3293 }
3294
3295 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003296 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003297 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003298 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003299 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003300 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003301 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003302 int duration = 0;
3303 if (mSearchDropTargetBar != null) {
3304 duration = mSearchDropTargetBar.getTransitionOutDuration();
3305 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003306 mHotseat.animate().alpha(0f).setDuration(duration);
3307 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003308 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003309 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003310 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003311 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003312 }
3313
Patrick Dubroy5f445422011-02-18 14:35:21 -08003314 /**
3315 * Add an item from all apps or customize onto the given workspace screen.
3316 * If layout is null, add to the current screen.
3317 */
3318 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003319 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003320 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003321 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003322 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003323
Winson Chungdff8ebb2011-09-08 17:25:31 -07003324 /** Maps the current orientation to an index for referencing orientation correct global icons */
3325 private int getCurrentOrientationIndexForGlobalIcons() {
3326 // default - 0, landscape - 1
3327 switch (getResources().getConfiguration().orientation) {
3328 case Configuration.ORIENTATION_LANDSCAPE:
3329 return 1;
3330 default:
3331 return 0;
3332 }
3333 }
3334
Michael Jurkaae65ee32012-04-30 11:45:54 -07003335 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003336 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003337 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003338 // Look for the toolbar icon specified in the activity meta-data
3339 Bundle metaData = packageManager.getActivityInfo(
3340 activityName, PackageManager.GET_META_DATA).metaData;
3341 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003342 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003343 if (iconResId != 0) {
3344 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003345 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003346 }
3347 }
3348 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003349 // This can happen if the activity defines an invalid drawable
3350 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3351 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003352 } catch (Resources.NotFoundException nfe) {
3353 // This can happen if the activity defines an invalid drawable
3354 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3355 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003356 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003357 return null;
3358 }
3359
3360 // if successful in getting icon, return it; otherwise, set button to use default drawable
3361 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003362 int buttonId, ComponentName activityName, int fallbackDrawableId,
3363 String toolbarResourceName) {
3364 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003365 Resources r = getResources();
3366 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3367 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003368
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003369 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003370 // If we were unable to find the icon via the meta-data, use a generic one
3371 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003372 toolbarIcon = r.getDrawable(fallbackDrawableId);
3373 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003374 if (button != null) {
3375 button.setCompoundDrawables(toolbarIcon, null, null, null);
3376 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003377 return null;
3378 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003379 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003380 if (button != null) {
3381 button.setCompoundDrawables(toolbarIcon, null, null, null);
3382 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003383 return toolbarIcon.getConstantState();
3384 }
3385 }
3386
3387 // if successful in getting icon, return it; otherwise, set button to use default drawable
3388 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003389 int buttonId, ComponentName activityName, int fallbackDrawableId,
3390 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003391 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003392 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003393
Michael Jurka19e0fc52011-07-22 18:00:21 -07003394 if (button != null) {
3395 // If we were unable to find the icon via the meta-data, use a
3396 // generic one
3397 if (toolbarIcon == null) {
3398 button.setImageResource(fallbackDrawableId);
3399 } else {
3400 button.setImageDrawable(toolbarIcon);
3401 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003402 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003403
3404 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3405
Michael Jurka0423dcf2010-10-05 14:56:18 -07003406 }
3407
Winson Chung1b884092012-06-08 17:13:02 -07003408 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003409 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003410 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003411 }
3412
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003413 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003414 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003415 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003416 }
3417
Winson Chungbb185bd2011-11-21 12:31:42 -08003418 private void invalidatePressedFocusedStates(View container, View button) {
3419 if (container instanceof HolographicLinearLayout) {
3420 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3421 layout.invalidatePressedFocusedStates();
3422 } else if (button instanceof HolographicImageView) {
3423 HolographicImageView view = (HolographicImageView) button;
3424 view.invalidatePressedFocusedStates();
3425 }
3426 }
3427
Cristina Stancu476493b2013-08-07 17:20:14 +01003428 public View getQsbBar() {
3429 if (mQsbBar == null) {
Winson Chung54e65132013-09-27 11:44:58 -07003430 mQsbBar = mInflater.inflate(R.layout.search_bar, mSearchDropTargetBar, false);
3431 mSearchDropTargetBar.addView(mQsbBar);
Cristina Stancu476493b2013-08-07 17:20:14 +01003432 }
3433 return mQsbBar;
3434 }
3435
3436 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003437 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003438 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003439 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003440 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003441
Winson Chung1cad91e2011-05-25 17:41:01 -07003442 final SearchManager searchManager =
3443 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3444 ComponentName activityName = searchManager.getGlobalSearchActivity();
3445 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003446 int coi = getCurrentOrientationIndexForGlobalIcons();
3447 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003448 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3449 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3450 if (sGlobalSearchIcon[coi] == null) {
3451 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3452 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3453 TOOLBAR_ICON_METADATA_NAME);
3454 }
3455
Winson Chungc51db6a2011-10-05 11:44:49 -07003456 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3457 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003458 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003459 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003460 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003461 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003462 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3463 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003464 if (searchButton != null) searchButton.setVisibility(View.GONE);
3465 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003466 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003467 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003468 }
3469 }
3470
Cristina Stancu476493b2013-08-07 17:20:14 +01003471 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003472 final View searchButtonContainer = findViewById(R.id.search_button_container);
3473 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003474 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003475 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003476 }
3477
Cristina Stancu476493b2013-08-07 17:20:14 +01003478 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003479 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003480 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003481
Winson Chungc51db6a2011-10-05 11:44:49 -07003482 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003483 final SearchManager searchManager =
3484 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3485 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3486
3487 ComponentName activityName = null;
3488 if (globalSearchActivity != null) {
3489 // Check if the global search activity handles voice search
3490 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3491 intent.setPackage(globalSearchActivity.getPackageName());
3492 activityName = intent.resolveActivity(getPackageManager());
3493 }
3494
3495 if (activityName == null) {
3496 // Fallback: check if an activity other than the global search activity
3497 // resolves this
3498 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3499 activityName = intent.resolveActivity(getPackageManager());
3500 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003501 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003502 int coi = getCurrentOrientationIndexForGlobalIcons();
3503 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003504 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3505 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3506 if (sVoiceSearchIcon[coi] == null) {
3507 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3508 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3509 TOOLBAR_ICON_METADATA_NAME);
3510 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003511 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003512 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003513 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003514 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003515 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003516 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003517 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003518 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003519 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003520 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003521 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003522 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003523
Cristina Stancu476493b2013-08-07 17:20:14 +01003524 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003525 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3526 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003527 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003528 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003529 }
3530
Winson Chung5841efa2013-09-30 18:06:44 -07003531 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003532 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3533 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003534 boolean visible = !forceDisableVoiceButtonProxy &&
3535 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003536 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003537 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003538 }
3539 }
Winson Chung5841efa2013-09-30 18:06:44 -07003540
3541 /**
3542 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3543 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3544 */
3545 public void disableVoiceButtonProxy(boolean disabled) {
3546 updateVoiceButtonProxyVisible(disabled);
3547 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003548 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003549 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003550 */
3551 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003552 if (!DISABLE_MARKET_BUTTON) {
3553 final View marketButton = findViewById(R.id.market_button);
3554 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3555 // Find the app market activity by resolving an intent.
3556 // (If multiple app markets are installed, it will return the ResolverActivity.)
3557 ComponentName activityName = intent.resolveActivity(getPackageManager());
3558 if (activityName != null) {
3559 int coi = getCurrentOrientationIndexForGlobalIcons();
3560 mAppMarketIntent = intent;
3561 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3562 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3563 TOOLBAR_ICON_METADATA_NAME);
3564 marketButton.setVisibility(View.VISIBLE);
3565 } else {
3566 // We should hide and disable the view so that we don't try and restore the visibility
3567 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3568 marketButton.setVisibility(View.GONE);
3569 marketButton.setEnabled(false);
3570 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003571 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003572 }
3573
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003574 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003575 if (!DISABLE_MARKET_BUTTON) {
3576 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3577 Resources r = getResources();
3578 Drawable marketIconDrawable = d.newDrawable(r);
3579 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3580 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3581 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07003582
Winson Chungd64a6662013-09-30 11:06:59 -07003583 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
3584 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003585 }
3586
Michael Jurkad7c28052012-04-27 15:43:36 -07003587 @Override
3588 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003589 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003590 final List<CharSequence> text = event.getText();
3591 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003592 // Populate event with a fake title based on the current state.
3593 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen4b378872013-10-04 18:58:04 -07003594 text.add(mAppsCustomizeTabHost.getCurrentTabView().getContentDescription());
alanv1d4fde62012-10-17 13:15:47 -07003595 } else {
3596 text.add(getString(R.string.all_apps_home_button_label));
3597 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003598 return result;
3599 }
3600
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003601 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003602 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003603 */
3604 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3605 @Override
3606 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003607 closeSystemDialogs();
3608 }
3609 }
3610
3611 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003612 * Receives notifications whenever the appwidgets are reset.
3613 */
3614 private class AppWidgetResetObserver extends ContentObserver {
3615 public AppWidgetResetObserver() {
3616 super(new Handler());
3617 }
3618
3619 @Override
3620 public void onChange(boolean selfChange) {
3621 onAppWidgetReset();
3622 }
3623 }
3624
3625 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07003626 * If the activity is currently paused, signal that we need to run the passed Runnable
3627 * in onResume.
3628 *
3629 * This needs to be called from incoming places where resources might have been loaded
3630 * while we are paused. That is becaues the Configuration might be wrong
3631 * when we're not running, and if it comes back to what it was when we
3632 * were paused, we are not restarted.
3633 *
3634 * Implementation of the method from LauncherModel.Callbacks.
3635 *
3636 * @return true if we are currently paused. The caller might be able to
3637 * skip some work in that case since we will come back again.
3638 */
Michael Jurkac402cd92013-05-20 15:49:32 +02003639 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003640 if (mPaused) {
3641 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02003642 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07003643 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02003644 }
3645 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07003646 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07003647 return true;
3648 } else {
3649 return false;
3650 }
3651 }
3652
Michael Jurkac402cd92013-05-20 15:49:32 +02003653 private boolean waitUntilResume(Runnable run) {
3654 return waitUntilResume(run, false);
3655 }
3656
Michael Jurka1e2f4652013-07-08 18:03:46 -07003657 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02003658 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07003659 }
3660
Michael Jurka7607c2f2013-04-03 14:33:19 -07003661 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003662 * If the activity is currently paused, signal that we need to re-run the loader
3663 * in onResume.
3664 *
3665 * This needs to be called from incoming places where resources might have been loaded
3666 * while we are paused. That is becaues the Configuration might be wrong
3667 * when we're not running, and if it comes back to what it was when we
3668 * were paused, we are not restarted.
3669 *
3670 * Implementation of the method from LauncherModel.Callbacks.
3671 *
3672 * @return true if we are currently paused. The caller might be able to
3673 * skip some work in that case since we will come back again.
3674 */
3675 public boolean setLoadOnResume() {
3676 if (mPaused) {
3677 Log.i(TAG, "setLoadOnResume");
3678 mOnResumeNeedsLoad = true;
3679 return true;
3680 } else {
3681 return false;
3682 }
3683 }
3684
3685 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003686 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003687 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003688 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003689 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003690 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003691 } else {
3692 return SCREEN_COUNT / 2;
3693 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003694 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003695
Joe Onorato9c1289c2009-08-17 11:03:03 -04003696 /**
3697 * Refreshes the shortcuts shown on the workspace.
3698 *
3699 * Implementation of the method from LauncherModel.Callbacks.
3700 */
3701 public void startBinding() {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003702 // If we're starting binding all over again, clear any bind calls we'd postponed in
3703 // the past (see waitUntilResume) -- we don't need them since we're starting binding
3704 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07003705 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07003706
Winson Chungd64d1762013-08-20 14:37:16 -07003707 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07003708 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07003709 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07003710
Michael Jurka05bf6442011-11-30 20:28:53 -08003711 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07003712 if (mHotseat != null) {
3713 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003714 }
3715 }
3716
Adam Cohendcd297f2013-06-18 13:13:40 -07003717 @Override
3718 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07003719 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07003720
Adam Cohen5084cba2013-09-03 12:01:16 -07003721 // If there are no screens, we need to have an empty screen
3722 if (orderedScreenIds.size() == 0) {
3723 mWorkspace.addExtraEmptyScreen();
3724 }
Winson Chung0e6a7132013-08-23 12:55:10 -07003725
3726 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06003727 // setCurrentPage() so ensure that all pages are added before calling this).
3728 // The actual content of the custom page will be added during onFinishBindingItems().
Winson Chung0e6a7132013-08-23 12:55:10 -07003729 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
3730 mWorkspace.createCustomContentPage();
3731 }
Winson Chung64359a52013-07-08 17:17:08 -07003732 }
3733
3734 @Override
3735 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08003736 // Log to disk
3737 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
3738 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
3739 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07003740 int count = orderedScreenIds.size();
3741 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07003742 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07003743 }
Adam Cohendcd297f2013-06-18 13:13:40 -07003744 }
3745
Adam Cohen39a06042013-07-19 14:30:12 -07003746 private boolean shouldShowWeightWatcher() {
3747 String spKey = LauncherAppState.getSharedPreferencesKey();
3748 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07003749 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07003750
3751 return show;
3752 }
3753
3754 private void toggleShowWeightWatcher() {
3755 String spKey = LauncherAppState.getSharedPreferencesKey();
3756 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
3757 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
3758
3759 show = !show;
3760
3761 SharedPreferences.Editor editor = sp.edit();
3762 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
3763 editor.commit();
3764
3765 if (mWeightWatcher != null) {
3766 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
3767 }
3768 }
3769
Winson Chungd64d1762013-08-20 14:37:16 -07003770 public void bindAppsAdded(final ArrayList<Long> newScreens,
3771 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07003772 final ArrayList<ItemInfo> addAnimated,
3773 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07003774 Runnable r = new Runnable() {
3775 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07003776 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07003777 }
3778 };
3779 if (waitUntilResume(r)) {
3780 return;
3781 }
3782
Winson Chungd64d1762013-08-20 14:37:16 -07003783 // Add the new screens
3784 bindAddScreens(newScreens);
3785
3786 // We add the items without animation on non-visible pages, and with
3787 // animations on the new page (which we will try and snap to).
3788 if (!addNotAnimated.isEmpty()) {
3789 bindItems(addNotAnimated, 0,
3790 addNotAnimated.size(), false);
3791 }
3792 if (!addAnimated.isEmpty()) {
3793 bindItems(addAnimated, 0,
3794 addAnimated.size(), true);
3795 }
Winson Chungc58497e2013-09-03 17:48:37 -07003796
Winson Chung87412982013-10-03 18:34:14 -07003797 // Remove the extra empty screen
Adam Cohenad4e15c2013-10-17 16:21:35 -07003798 mWorkspace.removeExtraEmptyScreen(false, null);
Winson Chung87412982013-10-03 18:34:14 -07003799
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003800 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07003801 addedApps != null && mAppsCustomizeContent != null) {
3802 mAppsCustomizeContent.addApps(addedApps);
3803 }
Winson Chungd64d1762013-08-20 14:37:16 -07003804 }
3805
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003806 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003807 * Bind the items start-end from the list.
3808 *
3809 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003810 */
Winson Chung64359a52013-07-08 17:17:08 -07003811 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
3812 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07003813 Runnable r = new Runnable() {
3814 public void run() {
3815 bindItems(shortcuts, start, end, forceAnimateIcons);
3816 }
3817 };
3818 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003819 return;
3820 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003821
Winson Chungf0c6ae02012-03-21 16:10:31 -07003822 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07003823 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
3824 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07003825 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07003826 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07003827 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003828 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003829 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07003830
3831 // Short circuit if we are loading dock items for a configuration which has no dock
3832 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
3833 mHotseat == null) {
3834 continue;
3835 }
3836
Joe Onorato9c1289c2009-08-17 11:03:03 -04003837 switch (item.itemType) {
3838 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3839 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07003840 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003841 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07003842
Winson Chung64359a52013-07-08 17:17:08 -07003843 /*
3844 * TODO: FIX collision case
3845 */
Winson Chungce376632013-07-11 16:12:41 -07003846 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
3847 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
3848 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
3849 throw new RuntimeException("OCCUPIED");
3850 }
Winson Chung64359a52013-07-08 17:17:08 -07003851 }
3852
Adam Cohendcd297f2013-06-18 13:13:40 -07003853 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
3854 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07003855 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07003856 // Animate all the applications up now
3857 shortcut.setAlpha(0f);
3858 shortcut.setScaleX(0f);
3859 shortcut.setScaleY(0f);
3860 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07003861 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07003862 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003863 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003864 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003865 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003866 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003867 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07003868 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
3869 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003870 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07003871 default:
3872 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04003873 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003874 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07003875
Winson Chung997a9232013-07-24 15:33:46 -07003876 if (animateIcons) {
3877 // Animate to the correct page
3878 if (newShortcutsScreenId > -1) {
3879 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07003880 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07003881 final Runnable startBounceAnimRunnable = new Runnable() {
3882 public void run() {
3883 anim.playTogether(bounceAnims);
3884 anim.start();
3885 }
3886 };
Winson Chung997a9232013-07-24 15:33:46 -07003887 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07003888 // We post the animation slightly delayed to prevent slowdowns
3889 // when we are loading right after we return to launcher.
3890 mWorkspace.postDelayed(new Runnable() {
3891 public void run() {
3892 mWorkspace.snapToPage(newScreenIndex);
Winson Chungb2323832013-10-03 15:22:09 -07003893 mWorkspace.postDelayed(startBounceAnimRunnable,
3894 NEW_APPS_ANIMATION_DELAY);
Winson Chung94d67682013-09-25 16:29:40 -07003895 }
3896 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07003897 } else {
3898 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07003899 }
3900 }
Winson Chung64359a52013-07-08 17:17:08 -07003901 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003902 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003903 }
3904
Joe Onorato9c1289c2009-08-17 11:03:03 -04003905 /**
3906 * Implementation of the method from LauncherModel.Callbacks.
3907 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003908 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07003909 Runnable r = new Runnable() {
3910 public void run() {
3911 bindFolders(folders);
3912 }
3913 };
3914 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003915 return;
3916 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003917 sFolders.clear();
3918 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003919 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003920
3921 /**
3922 * Add the views for a widget to the workspace.
3923 *
3924 * Implementation of the method from LauncherModel.Callbacks.
3925 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07003926 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07003927 Runnable r = new Runnable() {
3928 public void run() {
3929 bindAppWidget(item);
3930 }
3931 };
3932 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003933 return;
3934 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003935
Daniel Sandler843e8602010-06-07 14:59:01 -04003936 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3937 if (DEBUG_WIDGETS) {
3938 Log.d(TAG, "bindAppWidget: " + item);
3939 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003940 final Workspace workspace = mWorkspace;
3941
3942 final int appWidgetId = item.appWidgetId;
3943 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003944 if (DEBUG_WIDGETS) {
3945 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3946 }
3947
Joe Onorato9c1289c2009-08-17 11:03:03 -04003948 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3949
Joe Onorato9c1289c2009-08-17 11:03:03 -04003950 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07003951 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003952
Adam Cohendcd297f2013-06-18 13:13:40 -07003953 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003954 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07003955 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3956
Joe Onorato9c1289c2009-08-17 11:03:03 -04003957 workspace.requestLayout();
3958
Daniel Sandler843e8602010-06-07 14:59:01 -04003959 if (DEBUG_WIDGETS) {
3960 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3961 + (SystemClock.uptimeMillis()-start) + "ms");
3962 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003963 }
3964
Adam Cohen1462de32012-07-24 22:34:36 -07003965 public void onPageBoundSynchronously(int page) {
3966 mSynchronouslyBoundPages.add(page);
3967 }
3968
Joe Onorato9c1289c2009-08-17 11:03:03 -04003969 /**
3970 * Callback saying that there aren't any more items to bind.
3971 *
3972 * Implementation of the method from LauncherModel.Callbacks.
3973 */
Adam Cohene25af792013-06-06 23:08:25 -07003974 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07003975 Runnable r = new Runnable() {
3976 public void run() {
3977 finishBindingItems(upgradePath);
3978 }
3979 };
3980 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07003981 return;
3982 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003983 if (mSavedState != null) {
3984 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003985 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003986 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003987 mSavedState = null;
3988 }
3989
Adam Cohen1462de32012-07-24 22:34:36 -07003990 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003991
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003992 // If we received the result of any pending adds while the loader was running (e.g. the
3993 // widget configuration forced an orientation change), process them now.
3994 for (int i = 0; i < sPendingAddList.size(); i++) {
3995 completeAdd(sPendingAddList.get(i));
3996 }
3997 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003998
Winson Chungc51db6a2011-10-05 11:44:49 -07003999 // Update the market app icon as necessary (the other icons will be managed in response to
4000 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07004001 if (!DISABLE_MARKET_BUTTON) {
4002 updateAppMarketIcon();
4003 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07004004
Winson Chungf0c6ae02012-03-21 16:10:31 -07004005 mWorkspaceLoading = false;
Adam Cohene25af792013-06-06 23:08:25 -07004006 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004007 mWorkspace.getUniqueComponents(true, null);
4008 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004009 }
Adam Cohen99894d92013-06-14 11:22:59 -07004010
Adam Cohen66a01fd2013-06-11 12:48:00 -07004011 mWorkspace.post(new Runnable() {
4012 @Override
4013 public void run() {
4014 onFinishBindingItems();
4015 }
4016 });
Winson Chungf0c6ae02012-03-21 16:10:31 -07004017 }
4018
Winson Chunga0b7e862013-09-05 16:03:15 -07004019 public boolean isAllAppsButtonRank(int rank) {
4020 if (mHotseat != null) {
4021 return mHotseat.isAllAppsButtonRank(rank);
4022 }
4023 return false;
4024 }
4025
Winson Chunga2413752012-04-03 14:22:34 -07004026 private boolean canRunNewAppsAnimation() {
4027 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4028 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4029 }
4030
Winson Chungc9168342013-06-26 14:54:55 -07004031 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4032 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4033 PropertyValuesHolder.ofFloat("alpha", 1f),
4034 PropertyValuesHolder.ofFloat("scaleX", 1f),
4035 PropertyValuesHolder.ofFloat("scaleY", 1f));
4036 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4037 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4038 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4039 return bounceAnim;
4040 }
4041
Adam Cohen27772732013-11-11 14:00:56 +00004042 public boolean useVerticalBarLayout() {
4043 return LauncherAppState.getInstance().getDynamicGrid().
4044 getDeviceProfile().isVerticalBarLayout();
4045 }
4046
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004047 protected Rect getSearchBarBounds() {
4048 return LauncherAppState.getInstance().getDynamicGrid().
4049 getDeviceProfile().getSearchBarBounds();
4050 }
4051
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004052 @Override
4053 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004054 boolean searchVisible = updateGlobalSearchIcon();
4055 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004056 if (mSearchDropTargetBar != null) {
4057 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4058 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004059 }
4060
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004061 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004062 * Add the icons for all apps.
4063 *
4064 * Implementation of the method from LauncherModel.Callbacks.
4065 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004066 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004067 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004068 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4069 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4070 getHotseat().addAllAppsFolder(mIconCache, apps,
4071 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4072 }
4073 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004074 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004075 if (mAppsCustomizeContent != null) {
4076 mAppsCustomizeContent.onPackagesUpdated(
4077 LauncherModel.getSortedWidgetsAndShortcuts(this));
4078 }
Winson Chungc58497e2013-09-03 17:48:37 -07004079 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004080 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004081 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004082 mAppsCustomizeContent.onPackagesUpdated(
4083 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004084 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004085 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004086 }
4087
4088 /**
4089 * A package was updated.
4090 *
4091 * Implementation of the method from LauncherModel.Callbacks.
4092 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004093 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004094 Runnable r = new Runnable() {
4095 public void run() {
4096 bindAppsUpdated(apps);
4097 }
4098 };
4099 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004100 return;
4101 }
4102
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004103 if (mWorkspace != null) {
4104 mWorkspace.updateShortcuts(apps);
4105 }
Winson Chungc58497e2013-09-03 17:48:37 -07004106
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004107 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004108 mAppsCustomizeContent != null) {
4109 mAppsCustomizeContent.updateApps(apps);
4110 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004111 }
4112
4113 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004114 * A package was uninstalled. We take both the super set of packageNames
4115 * in addition to specific applications to remove, the reason being that
4116 * this can be called when a package is updated as well. In that scenario,
4117 * we only remove specific components from the workspace, where as
4118 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004119 *
4120 * Implementation of the method from LauncherModel.Callbacks.
4121 */
Winson Chung83892cc2013-05-01 16:53:33 -07004122 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Winson Chungdf95eb12013-10-16 14:57:07 -07004123 final ArrayList<AppInfo> appInfos) {
Winson Chungd64d1762013-08-20 14:37:16 -07004124 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004125 public void run() {
Winson Chungdf95eb12013-10-16 14:57:07 -07004126 bindComponentsRemoved(packageNames, appInfos);
Winson Chung83892cc2013-05-01 16:53:33 -07004127 }
Winson Chungd64d1762013-08-20 14:37:16 -07004128 };
4129 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004130 return;
4131 }
4132
Winson Chungdf95eb12013-10-16 14:57:07 -07004133 if (!packageNames.isEmpty()) {
Winson Chung83892cc2013-05-01 16:53:33 -07004134 mWorkspace.removeItemsByPackageName(packageNames);
Winson Chungdf95eb12013-10-16 14:57:07 -07004135 }
4136 if (!appInfos.isEmpty()) {
Winson Chung83892cc2013-05-01 16:53:33 -07004137 mWorkspace.removeItemsByApplicationInfo(appInfos);
Joe Onorato36115782010-06-17 13:28:48 -04004138 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004139
Winson Chunga1820962011-10-03 16:31:06 -07004140 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004141 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004142
Winson Chungdf95eb12013-10-16 14:57:07 -07004143 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004144 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004145 mAppsCustomizeContent != null) {
4146 mAppsCustomizeContent.removeApps(appInfos);
4147 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004148 }
Joe Onoratobe386092009-11-17 17:32:16 -08004149
4150 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004151 * A number of packages were updated.
4152 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004153 private ArrayList<Object> mWidgetsAndShortcuts;
4154 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004155 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004156 bindPackagesUpdated(mWidgetsAndShortcuts);
4157 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004158 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004159 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004160 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4161 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4162 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004163 return;
4164 }
4165
Winson Chung64359a52013-07-08 17:17:08 -07004166 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004167 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004168 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004169 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004170 }
4171
Winson Chung400438b2011-01-16 17:53:48 -08004172 private int mapConfigurationOriActivityInfoOri(int configOri) {
4173 final Display d = getWindowManager().getDefaultDisplay();
4174 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4175 switch (d.getRotation()) {
4176 case Surface.ROTATION_0:
4177 case Surface.ROTATION_180:
4178 // We are currently in the same basic orientation as the natural orientation
4179 naturalOri = configOri;
4180 break;
4181 case Surface.ROTATION_90:
4182 case Surface.ROTATION_270:
4183 // We are currently in the other basic orientation to the natural orientation
4184 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4185 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4186 break;
4187 }
4188
4189 int[] oriMap = {
4190 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4191 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4192 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4193 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4194 };
4195 // Since the map starts at portrait, we need to offset if this device's natural orientation
4196 // is landscape.
4197 int indexOffset = 0;
4198 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4199 indexOffset = 1;
4200 }
4201 return oriMap[(d.getRotation() + indexOffset) % 4];
4202 }
Adam Cohen446e9402011-09-15 18:21:21 -07004203
Winson Chung4b919f82012-05-01 10:44:08 -07004204 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004205 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004206 getResources().getBoolean(R.bool.allow_rotation);
4207 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004208 }
Winson Chung4b919f82012-05-01 10:44:08 -07004209 public void lockScreenOrientation() {
4210 if (isRotationEnabled()) {
4211 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4212 .getConfiguration().orientation));
4213 }
4214 }
4215 public void unlockScreenOrientation(boolean immediate) {
4216 if (isRotationEnabled()) {
4217 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004218 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004219 } else {
4220 mHandler.postDelayed(new Runnable() {
4221 public void run() {
4222 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4223 }
4224 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004225 }
Winson Chung4b919f82012-05-01 10:44:08 -07004226 }
Winson Chung400438b2011-01-16 17:53:48 -08004227 }
4228
Adam Cohenb54a5982014-01-08 15:21:04 -08004229 private boolean shouldRunFirstRunActivity() {
4230 return !ActivityManager.isRunningInTestHarness();
4231 }
4232
Winson Chung82f55532011-08-09 14:14:23 -07004233 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07004234 private boolean isClingsEnabled() {
Adam Cohen7564d982013-06-06 23:11:58 -07004235 if (DISABLE_CLINGS) {
4236 return false;
4237 }
4238
Winson Chung3a6e7f32013-10-09 15:50:52 -07004239 // For now, limit only to phones
4240 LauncherAppState app = LauncherAppState.getInstance();
4241 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
4242 if (grid.isTablet()) {
4243 return false;
4244 }
Winson Chung13dbfe12013-10-31 11:42:39 -07004245 if (grid.isLandscape) {
4246 return false;
4247 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004248
Brett Chabot2a9e2282011-08-23 15:03:13 -07004249 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07004250 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07004251
Casey Burkhardt0d9cbae2013-10-04 14:13:15 -07004252 // Disable clings for accessibility when explore by touch is enabled
4253 final AccessibilityManager a11yManager = (AccessibilityManager) getSystemService(
4254 ACCESSIBILITY_SERVICE);
4255 if (a11yManager.isTouchExplorationEnabled()) {
4256 return false;
4257 }
4258
Michael Jurkae233a8b2013-03-19 13:49:20 +01004259 // Restricted secondary users (child mode) will potentially have very few apps
4260 // seeded when they start up for the first time. Clings won't work well with that
Daniel Sandler325dc232013-06-05 22:57:57 -04004261// boolean supportsLimitedUsers =
4262// android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
4263// Account[] accounts = AccountManager.get(this).getAccounts();
4264// if (supportsLimitedUsers && accounts.length == 0) {
4265// UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
4266// Bundle restrictions = um.getUserRestrictions();
4267// if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
4268// return false;
4269// }
4270// }
Winson Chung7d7541e2011-09-16 20:14:36 -07004271 return true;
Winson Chung82f55532011-08-09 14:14:23 -07004272 }
Michael Jurka22143132012-10-04 17:42:38 +02004273
Winson Chungfa545132013-09-26 17:45:32 -07004274 private Cling initCling(int clingId, int scrimId, boolean animate,
Winson Chungaf40f202013-09-18 18:26:31 -07004275 boolean dimNavBarVisibilty) {
Winson Chungfa545132013-09-26 17:45:32 -07004276 Cling cling = (Cling) findViewById(clingId);
4277 View scrim = null;
4278 if (scrimId > 0) {
Sandeep Siddharthaa6125ef2013-09-26 20:30:40 -07004279 scrim = findViewById(R.id.cling_scrim);
Winson Chungfa545132013-09-26 17:45:32 -07004280 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004281 if (cling != null) {
Winson Chungfa545132013-09-26 17:45:32 -07004282 cling.init(this, scrim);
Winson Chungaf40f202013-09-18 18:26:31 -07004283 cling.show(animate, SHOW_CLING_DURATION);
4284
4285 if (dimNavBarVisibilty) {
4286 cling.setSystemUiVisibility(cling.getSystemUiVisibility() |
4287 View.SYSTEM_UI_FLAG_LOW_PROFILE);
Winson Chung7d7541e2011-09-16 20:14:36 -07004288 }
4289 }
4290 return cling;
4291 }
Michael Jurka22143132012-10-04 17:42:38 +02004292
Winson Chungaf40f202013-09-18 18:26:31 -07004293 private void dismissCling(final Cling cling, final Runnable postAnimationCb,
4294 final String flag, int duration, boolean restoreNavBarVisibilty) {
Winson Chung7819abd2012-11-29 14:29:38 -08004295 // To catch cases where siblings of top-level views are made invisible, just check whether
4296 // the cling is directly set to GONE before dismissing it.
4297 if (cling != null && cling.getVisibility() != View.GONE) {
Winson Chungaf40f202013-09-18 18:26:31 -07004298 final Runnable cleanUpClingCb = new Runnable() {
4299 public void run() {
Winson Chung82f55532011-08-09 14:14:23 -07004300 cling.cleanup();
Adam Cohenb54a5982014-01-08 15:21:04 -08004301 SharedPreferences.Editor editor = mSharedPrefs.edit();
4302 editor.putBoolean(flag, true);
4303 editor.apply();
Winson Chungaf40f202013-09-18 18:26:31 -07004304 if (postAnimationCb != null) {
4305 postAnimationCb.run();
4306 }
4307 }
4308 };
4309 if (duration <= 0) {
4310 cleanUpClingCb.run();
4311 } else {
4312 cling.hide(duration, cleanUpClingCb);
4313 }
Michael Jurka22143132012-10-04 17:42:38 +02004314 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chungaf40f202013-09-18 18:26:31 -07004315
4316 if (restoreNavBarVisibilty) {
4317 cling.setSystemUiVisibility(cling.getSystemUiVisibility() &
4318 ~View.SYSTEM_UI_FLAG_LOW_PROFILE);
4319 }
Winson Chung82f55532011-08-09 14:14:23 -07004320 }
4321 }
Michael Jurka22143132012-10-04 17:42:38 +02004322
Winson Chung9d9d74f2011-09-19 11:49:12 -07004323 private void removeCling(int id) {
4324 final View cling = findViewById(id);
4325 if (cling != null) {
4326 final ViewGroup parent = (ViewGroup) cling.getParent();
4327 parent.post(new Runnable() {
4328 @Override
4329 public void run() {
4330 parent.removeView(cling);
4331 }
4332 });
Michael Jurka22143132012-10-04 17:42:38 +02004333 mHideFromAccessibilityHelper.restoreImportantForAccessibility(mDragLayer);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004334 }
4335 }
Michael Jurka974c3862012-05-22 22:00:31 -07004336
4337 private boolean skipCustomClingIfNoAccounts() {
4338 Cling cling = (Cling) findViewById(R.id.workspace_cling);
4339 boolean customCling = cling.getDrawIdentifier().equals("workspace_custom");
4340 if (customCling) {
4341 AccountManager am = AccountManager.get(this);
Daniel Sandler325dc232013-06-05 22:57:57 -04004342 if (am == null) return false;
Michael Jurka974c3862012-05-22 22:00:31 -07004343 Account[] accounts = am.getAccountsByType("com.google");
4344 return accounts.length == 0;
4345 }
4346 return false;
4347 }
4348
Winson Chung82e5c982013-10-09 12:04:50 -07004349 public void updateCustomContentHintVisibility() {
4350 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4351 String ccHintStr = getFirstRunCustomContentHint();
4352
4353 if (mWorkspace.hasCustomContent()) {
4354 // Show the custom content hint if ccHintStr is not empty
4355 if (cling != null) {
4356 setCustomContentHintVisibility(cling, ccHintStr, true, true);
4357 }
4358 } else {
4359 // Hide the custom content hint
4360 if (cling != null) {
4361 setCustomContentHintVisibility(cling, ccHintStr, false, true);
4362 }
4363 }
4364 }
4365
4366 private void setCustomContentHintVisibility(Cling cling, String ccHintStr, boolean visible,
4367 boolean animate) {
4368 final TextView ccHint = (TextView) cling.findViewById(R.id.custom_content_hint);
4369 if (ccHint != null) {
4370 if (visible && !ccHintStr.isEmpty()) {
4371 ccHint.setText(ccHintStr);
4372 ccHint.setVisibility(View.VISIBLE);
4373 if (animate) {
4374 ccHint.setAlpha(0f);
4375 ccHint.animate().alpha(1f)
4376 .setDuration(SHOW_CLING_DURATION)
4377 .start();
4378 } else {
4379 ccHint.setAlpha(1f);
4380 }
4381 } else {
4382 if (animate) {
4383 ccHint.animate().alpha(0f)
4384 .setDuration(SHOW_CLING_DURATION)
4385 .setListener(new AnimatorListenerAdapter() {
4386 @Override
4387 public void onAnimationEnd(Animator animation) {
4388 ccHint.setVisibility(View.GONE);
4389 }
4390 })
4391 .start();
4392 } else {
4393 ccHint.setAlpha(0f);
4394 ccHint.setVisibility(View.GONE);
4395 }
4396 }
4397 }
4398 }
4399
Adam Cohenb54a5982014-01-08 15:21:04 -08004400 public void showFirstRunActivity() {
4401 if (shouldRunFirstRunActivity() && hasFirstRunActivity()
4402 && !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false)) {
4403 Intent firstRunIntent = getFirstRunActivity();
4404 if (firstRunIntent != null) {
4405 startActivity(firstRunIntent);
4406 markFirstRunActivityShown();
4407 }
4408 }
4409 }
4410
4411 private void markFirstRunActivityShown() {
4412 SharedPreferences.Editor editor = mSharedPrefs.edit();
4413 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4414 editor.apply();
4415 }
4416
Winson Chungaf40f202013-09-18 18:26:31 -07004417 public void showFirstRunCling() {
Winson Chung46353de2012-02-16 14:05:10 -08004418 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004419 !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) &&
Michael Jurka974c3862012-05-22 22:00:31 -07004420 !skipCustomClingIfNoAccounts() ) {
Adam Cohenb54a5982014-01-08 15:21:04 -08004421
4422
Michael Jurka45355c42012-10-08 13:21:35 +02004423 // If we're not using the default workspace layout, replace workspace cling
4424 // with a custom workspace cling (usually specified in an overlay)
4425 // For now, only do this on tablets
Winson Chunge6eabff2013-09-24 11:01:23 -07004426 if (!DISABLE_CUSTOM_CLINGS) {
4427 if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0 &&
4428 getResources().getBoolean(R.bool.config_useCustomClings)) {
4429 // Use a custom cling
4430 View cling = findViewById(R.id.workspace_cling);
4431 ViewGroup clingParent = (ViewGroup) cling.getParent();
4432 int clingIndex = clingParent.indexOfChild(cling);
4433 clingParent.removeViewAt(clingIndex);
4434 View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false);
4435 clingParent.addView(customCling, clingIndex);
4436 customCling.setId(R.id.workspace_cling);
4437 }
4438 }
4439 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4440 if (cling != null) {
4441 String sbHintStr = getFirstRunClingSearchBarHint();
4442 String ccHintStr = getFirstRunCustomContentHint();
4443 if (!sbHintStr.isEmpty()) {
4444 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4445 sbHint.setText(sbHintStr);
4446 sbHint.setVisibility(View.VISIBLE);
4447 }
Winson Chung82e5c982013-10-09 12:04:50 -07004448 setCustomContentHintVisibility(cling, ccHintStr, true, false);
Michael Jurka45355c42012-10-08 13:21:35 +02004449 }
Winson Chungfa545132013-09-26 17:45:32 -07004450 initCling(R.id.first_run_cling, 0, false, true);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004451 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004452 removeCling(R.id.first_run_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004453 }
4454 }
Winson Chungaf40f202013-09-18 18:26:31 -07004455
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004456 /**
4457 * Called when the SearchBar hint should be changed.
4458 *
4459 * @param hint the hint to be displayed in the search bar.
4460 */
4461 protected void onSearchBarHintChanged(String hint) {
4462 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4463 if (cling != null && cling.getVisibility() == View.VISIBLE && !hint.isEmpty()) {
4464 TextView sbHint = (TextView) cling.findViewById(R.id.search_bar_hint);
4465 sbHint.setText(hint);
4466 sbHint.setVisibility(View.VISIBLE);
4467 }
4468 }
4469
Winson Chunge6eabff2013-09-24 11:01:23 -07004470 protected String getFirstRunClingSearchBarHint() {
4471 return "";
4472 }
4473 protected String getFirstRunCustomContentHint() {
4474 return "";
4475 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004476 protected int getFirstRunFocusedHotseatAppDrawableId() {
4477 return -1;
4478 }
4479 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4480 return null;
4481 }
4482 protected int getFirstRunFocusedHotseatAppRank() {
4483 return -1;
4484 }
4485 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4486 return "";
4487 }
4488 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4489 return "";
4490 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004491
Winson Chungaf40f202013-09-18 18:26:31 -07004492 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004493 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004494 if (isClingsEnabled() &&
Winson Chungaf40f202013-09-18 18:26:31 -07004495 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chung3a6e7f32013-10-09 15:50:52 -07004496 Cling c = initCling(R.id.workspace_cling, 0, false, true);
4497
4498 // Set the focused hotseat app if there is one
4499 c.setFocusedHotseatApp(getFirstRunFocusedHotseatAppDrawableId(),
4500 getFirstRunFocusedHotseatAppRank(),
4501 getFirstRunFocusedHotseatAppComponentName(),
4502 getFirstRunFocusedHotseatAppBubbleTitle(),
4503 getFirstRunFocusedHotseatAppBubbleDescription());
Winson Chung9d9d74f2011-09-19 11:49:12 -07004504 } else {
Winson Chungaf40f202013-09-18 18:26:31 -07004505 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07004506 }
4507 }
4508 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07004509 // Enable the clings only if they have not been dismissed before
Winson Chung46353de2012-02-16 14:05:10 -08004510 if (isClingsEnabled() &&
4511 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chungfa545132013-09-26 17:45:32 -07004512 Cling cling = initCling(R.id.folder_cling, R.id.cling_scrim,
4513 true, true);
Winson Chungaf40f202013-09-18 18:26:31 -07004514 return cling;
Winson Chung9d9d74f2011-09-19 11:49:12 -07004515 } else {
4516 removeCling(R.id.folder_cling);
Winson Chung46353de2012-02-16 14:05:10 -08004517 return null;
Winson Chung7d7541e2011-09-16 20:14:36 -07004518 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004519 }
Michael Jurka104c4562013-07-08 18:03:46 -07004520 protected SharedPreferences getSharedPrefs() {
4521 return mSharedPrefs;
4522 }
Winson Chung7d7541e2011-09-16 20:14:36 -07004523 public boolean isFolderClingVisible() {
4524 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07004525 if (cling != null) {
4526 return cling.getVisibility() == View.VISIBLE;
4527 }
4528 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07004529 }
Winson Chungaf40f202013-09-18 18:26:31 -07004530 public void dismissFirstRunCling(View v) {
4531 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4532 Runnable cb = new Runnable() {
4533 public void run() {
4534 // Show the workspace cling next
4535 showFirstRunWorkspaceCling();
4536 }
4537 };
4538 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
4539 DISMISS_CLING_DURATION, false);
Winson Chung3a6e7f32013-10-09 15:50:52 -07004540
4541 // Fade out the search bar for the workspace cling coming up
4542 mSearchDropTargetBar.hideSearchBar(true);
Winson Chungaf40f202013-09-18 18:26:31 -07004543 }
Winson Chung82f55532011-08-09 14:14:23 -07004544 public void dismissWorkspaceCling(View v) {
4545 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004546 Runnable cb = null;
4547 if (v == null) {
4548 cb = new Runnable() {
4549 public void run() {
4550 mWorkspace.enterOverviewMode();
4551 }
4552 };
4553 }
4554 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
4555 DISMISS_CLING_DURATION, true);
Winson Chung3a6e7f32013-10-09 15:50:52 -07004556
4557 // Fade in the search bar
4558 mSearchDropTargetBar.showSearchBar(true);
Winson Chung7d7541e2011-09-16 20:14:36 -07004559 }
4560 public void dismissFolderCling(View v) {
4561 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chungaf40f202013-09-18 18:26:31 -07004562 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
4563 DISMISS_CLING_DURATION, true);
Winson Chung82f55532011-08-09 14:14:23 -07004564 }
4565
Mathew Inwood72fbec12013-11-19 15:45:07 +00004566 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
4567 ResolveInfo ri = getPackageManager().resolveActivity(appLaunchIntent, 0);
4568 if (ri == null) {
4569 return null;
4570 }
4571 return new AppInfo(getPackageManager(), ri, mIconCache, null);
4572 }
4573
4574 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4575 Bitmap icon) {
4576 return new ShortcutInfo(shortcutIntent, caption, icon);
4577 }
4578
4579 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4580 dragView.setTag(dragInfo);
4581 mWorkspace.onDragStartedWithItem(dragView);
4582 mWorkspace.beginDragShared(dragView, source);
4583 }
4584
Winson Chung80baf5a2010-08-09 16:03:15 -07004585 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004586 * Prints out out state for debugging.
4587 */
4588 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004589 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004590 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004591 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4592 Log.d(TAG, "mRestoring=" + mRestoring);
4593 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4594 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004595 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004596 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004597
Winson Chung785d2eb2011-04-14 16:08:02 -07004598 if (mAppsCustomizeContent != null) {
4599 mAppsCustomizeContent.dumpState();
4600 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004601 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004602 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004603
4604 @Override
4605 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4606 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004607 synchronized (sDumpLogs) {
4608 writer.println(" ");
4609 writer.println("Debug logs: ");
4610 for (int i = 0; i < sDumpLogs.size(); i++) {
4611 writer.println(" " + sDumpLogs.get(i));
4612 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004613 }
4614 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004615
4616 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07004617 if (DEBUG_DUMP_LOG) {
4618 synchronized (sDumpLogs) {
4619 Log.d(TAG, "");
4620 Log.d(TAG, "*********************");
4621 Log.d(TAG, "Launcher debug logs: ");
4622 for (int i = 0; i < sDumpLogs.size(); i++) {
4623 Log.d(TAG, " " + sDumpLogs.get(i));
4624 }
4625 Log.d(TAG, "*********************");
4626 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07004627 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004628 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004629 }
4630
4631 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004632 addDumpLog(tag, log, null, debugLog);
4633 }
4634
4635 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004636 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05004637 if (e != null) {
4638 Log.d(tag, log, e);
4639 } else {
4640 Log.d(tag, log);
4641 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004642 }
Winson Chungede41292013-09-19 16:27:36 -07004643 if (DEBUG_DUMP_LOG) {
4644 sDateStamp.setTime(System.currentTimeMillis());
4645 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05004646 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
4647 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07004648 }
Winson Chungede41292013-09-19 16:27:36 -07004649 }
Adam Cohen4caf2982013-08-20 18:54:31 -07004650 }
4651
Winson Chungede41292013-09-19 16:27:36 -07004652 public void dumpLogsToLocalData() {
4653 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01004654 new AsyncTask<Void, Void, Void>() {
4655 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07004656 boolean success = false;
4657 sDateStamp.setTime(sRunStart);
4658 String FILENAME = sDateStamp.getMonth() + "-"
4659 + sDateStamp.getDay() + "_"
4660 + sDateStamp.getHours() + "-"
4661 + sDateStamp.getMinutes() + "_"
4662 + sDateStamp.getSeconds() + ".txt";
4663
4664 FileOutputStream fos = null;
4665 File outFile = null;
4666 try {
4667 outFile = new File(getFilesDir(), FILENAME);
4668 outFile.createNewFile();
4669 fos = new FileOutputStream(outFile);
4670 } catch (Exception e) {
4671 e.printStackTrace();
4672 }
4673 if (fos != null) {
4674 PrintWriter writer = new PrintWriter(fos);
4675
4676 writer.println(" ");
4677 writer.println("Debug logs: ");
4678 synchronized (sDumpLogs) {
4679 for (int i = 0; i < sDumpLogs.size(); i++) {
4680 writer.println(" " + sDumpLogs.get(i));
4681 }
4682 }
4683 writer.close();
4684 }
4685 try {
4686 if (fos != null) {
4687 fos.close();
4688 success = true;
4689 }
4690 } catch (IOException e) {
4691 e.printStackTrace();
4692 }
Michael Jurka43467462013-11-14 12:03:58 +01004693 return null;
Winson Chungede41292013-09-19 16:27:36 -07004694 }
Michael Jurka43467462013-11-14 12:03:58 +01004695 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07004696 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07004697 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004698}
Michael Jurka2763be32011-02-24 11:19:57 -08004699
Michael Jurkaabded662011-03-04 12:06:57 -08004700interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08004701 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07004702 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08004703 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08004704 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08004705 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08004706}