blob: b8571008bf01cc8459b9ae2912b1fb88b58877c6 [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
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
24import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070025import android.animation.ValueAnimator;
Adam Cohen0b395352014-06-09 22:54:36 +000026import android.annotation.TargetApi;
Michael Jurka946ad472010-07-09 18:05:18 -070027import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070028import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070029import android.app.ActivityOptions;
Chris Wren40c5ed32014-06-24 18:24:23 -040030import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080032import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070033import android.appwidget.AppWidgetManager;
34import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080036import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080037import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040038import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080039import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Context;
Chris Wren40c5ed32014-06-24 18:24:23 -040041import android.content.DialogInterface;
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;
Winson Chunge43a1e72014-01-15 10:33:02 -080046import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070048import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070052import android.graphics.Bitmap;
53import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070054import android.graphics.Color;
Winson Chung5f8afe62013-08-12 16:19:28 -070055import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070056import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070058import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040059import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070060import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080061import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020062import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080063import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070064import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070065import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040066import android.os.SystemClock;
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;
Sunny Goyal651077b2014-06-30 14:15:31 -070088import android.view.Window;
Adam Cohen96d30a12013-07-16 18:13:21 -070089import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080090import android.view.accessibility.AccessibilityEvent;
Adam Cohen9bfdb762014-07-21 17:44:06 -070091import android.view.animation.AccelerateInterpolator;
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;
Adam Cohen6c5891a2014-07-09 23:53:15 -070099
Sunny Goyal651077b2014-06-30 14:15:31 -0700100import com.android.launcher3.DropTarget.DragObject;
101import com.android.launcher3.PagedView.PageSwitchListener;
Kenny Guyed131872014-04-30 03:02:21 +0100102import com.android.launcher3.compat.LauncherActivityInfoCompat;
103import com.android.launcher3.compat.LauncherAppsCompat;
Sunny Goyale755d462014-07-22 13:48:29 -0700104import com.android.launcher3.compat.PackageInstallerCompat;
105import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
Kenny Guyed131872014-04-30 03:02:21 +0100106import com.android.launcher3.compat.UserHandleCompat;
107import com.android.launcher3.compat.UserManagerCompat;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700108
Adam Cohenc0dcf592011-06-01 15:30:43 -0700109import java.io.DataInputStream;
110import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700111import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700112import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700113import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700114import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700115import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700116import java.io.PrintWriter;
Adam Cohen0b395352014-06-09 22:54:36 +0000117import java.lang.reflect.Field;
118import java.lang.reflect.InvocationTargetException;
119import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700120import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700121import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700122import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700123import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700124import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700125import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000126import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700127
Winson Chunga6945242014-01-08 14:04:34 -0800128
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800129/**
130 * Default launcher application.
131 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100132public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700133 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700134 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800135 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700136 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137
Daniel Sandlerf061f822013-06-27 13:59:36 -0400138 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400139 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700140 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400141 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700142 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700143
Dan Sandlerd5024042014-01-09 15:01:33 -0500144 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
145
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700147 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700149 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700150 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151
Michael Jurka8b805b12012-04-18 14:23:14 -0700152 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700153 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700154
Mathew Inwood876a8462013-06-14 14:12:41 +0100155 /**
156 * IntentStarter uses request codes starting with this. This must be greater than all activity
157 * request codes used internally.
158 */
159 protected static final int REQUEST_LAST = 100;
160
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800161 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
162
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800163 static final int SCREEN_COUNT = 5;
164 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165
Romain Guy98d01652009-06-30 16:21:04 -0700166 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800167 // To turn on these properties, type
168 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
169 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
170 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800171 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172
Winson Chung2672ff92012-05-04 16:22:30 -0700173 // The Intent extra that defines whether to ignore the launch animation
174 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400175 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700176
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 // Type: int
178 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700179 // Type: int
180 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700182 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
183 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
185 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700186 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700188 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800189 // Type: boolean
190 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
191 // Type: long
192 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700193 // Type: int
194 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
195 // Type: int
196 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
197 // Type: parcelable
198 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000199 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800200 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000201 // Type: int[]
202 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800203
Adam Cohen432609a2014-03-13 17:03:22 -0700204 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800205 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
206
Adam Cohen3ed316a2014-07-23 18:21:20 -0700207 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
208 static final String ACTION_FIRST_LOAD_COMPLETE =
209 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
210
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100211 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700212 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100213 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700214 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100215 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700216
Adam Cohen39a06042013-07-19 14:30:12 -0700217 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700218 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700219
Winson Chunga6945242014-01-08 14:04:34 -0800220 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
221
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700222 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700223 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700224 private State mState = State.WORKSPACE;
225 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700226
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700227 private boolean mIsSafeModeEnabled;
228
Joe Onorato9c1289c2009-08-17 11:03:03 -0400229 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700230 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
231 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700232 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800233
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800234 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800235 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000237 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
238 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
239
Winson Chunga2413752012-04-03 14:22:34 -0700240 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700241 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
242 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700243 private static int NEW_APPS_ANIMATION_DELAY = 500;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700244 private static final int SINGLE_FRAME_DELAY = 16;
Winson Chunga2413752012-04-03 14:22:34 -0700245
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800246 private final BroadcastReceiver mCloseSystemDialogsReceiver
247 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800248 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
249
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800250 private LayoutInflater mInflater;
251
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800252 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700253 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800254 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800255 private DragLayer mDragLayer;
256 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700257 private View mWeightWatcher;
Winson Chunga6945242014-01-08 14:04:34 -0800258 private LauncherClings mLauncherClings;
Romain Guycbb89e42009-06-08 15:52:54 -0700259
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700260 private AppWidgetManager mAppWidgetManager;
261 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700262
Michael Jurkac9d95c52011-08-29 14:03:34 -0700263 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700264 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800265 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700266
Michael Jurka0280c3b2010-09-17 15:00:07 -0700267 private int[] mTmpAddItemCellCoordinates = new int[2];
268
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269 private FolderInfo mFolderInfo;
270
Winson Chung3d503fb2011-07-13 17:25:49 -0700271 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800272 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700273
Michael Jurka838a4ca2011-02-07 13:33:06 -0800274 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700275
Winson Chungc51db6a2011-10-05 11:44:49 -0700276 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700277 private AppsCustomizeTabHost mAppsCustomizeTabHost;
278 private AppsCustomizePagedView mAppsCustomizeContent;
279 private boolean mAutoAdvanceRunning = false;
Adam Cohen24ce0b32014-01-14 16:18:14 -0800280 private View mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800281
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800282 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700283 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
284 // scroll issues (because the workspace may not have been measured yet) and extra work.
285 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
286 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800287
288 private SpannableStringBuilder mDefaultKeySsb = null;
289
Joe Onorato9c1289c2009-08-17 11:03:03 -0400290 private boolean mWorkspaceLoading = true;
291
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800292 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800293 private boolean mRestoring;
294 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700295 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800296
Michael Jurka1e2f4652013-07-08 18:03:46 -0700297 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700298 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
299
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800300 private Bundle mSavedInstanceState;
301
Joe Onorato9c1289c2009-08-17 11:03:03 -0400302 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800303 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800304 private boolean mUserPresent = true;
305 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700306 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800307 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400308
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700309 private static LocaleConfiguration sLocaleConfiguration = null;
310
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700311 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700312
Adam Cohen61f560d2013-09-30 15:58:20 -0700313 private View.OnTouchListener mHapticFeedbackTouchListener;
314
Adam Cohended9f8d2010-11-03 13:25:16 -0700315 // Related to the auto-advancing of widgets
316 private final int ADVANCE_MSG = 1;
317 private final int mAdvanceInterval = 20000;
318 private final int mAdvanceStagger = 250;
319 private long mAutoAdvanceSentTime;
320 private long mAutoAdvanceTimeLeft = -1;
321 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
322 new HashMap<View, AppWidgetProviderInfo>();
323
Winson Chung400438b2011-01-16 17:53:48 -0800324 // Determines how long to wait after a rotation before restoring the screen orientation to
325 // match the sensor state.
326 private final int mRestoreScreenOrientationDelay = 500;
327
Michael Jurka4ef207b2010-11-29 17:05:45 -0800328 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700329 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
330 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
Winson Chungd64a6662013-09-30 11:06:59 -0700331
Craig Mautner360310b2012-10-26 15:13:08 -0700332 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700333
Adam Cohen1462de32012-07-24 22:34:36 -0700334 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700335 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700336
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700337 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700338 static Date sDateStamp = new Date();
339 static DateFormat sDateFormat =
340 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
341 static long sRunStart = System.currentTimeMillis();
342 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700343
Winson Chung46353de2012-02-16 14:05:10 -0800344 // We only want to get the SharedPreferences once since it does an FS stat each time we get
345 // it from the context.
346 private SharedPreferences mSharedPrefs;
347
Adam Cohene25af792013-06-06 23:08:25 -0700348 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
349
Winson Chungf0c6ae02012-03-21 16:10:31 -0700350 // Holds the page that we need to animate to, and the icon views that we need to animate up
351 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700352 private ImageView mFolderIconImageView;
353 private Bitmap mFolderIconBitmap;
354 private Canvas mFolderIconCanvas;
355 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700356
Michael Jurkaddd62e92011-02-16 17:49:14 -0800357 private BubbleTextView mWaitingForResume;
358
Michael Jurkac1f5d262011-09-30 19:32:27 -0700359 private Runnable mBuildLayersRunnable = new Runnable() {
360 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700361 if (mWorkspace != null) {
362 mWorkspace.buildPageHardwareLayers();
363 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700364 }
365 };
366
Adam Cohendb364c32014-05-20 14:23:40 -0700367 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800368
Michael Jurka7267fa52013-09-26 15:29:57 -0700369 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800370
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800371 private static class PendingAddArguments {
372 int requestCode;
373 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700374 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700375 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800376 int cellX;
377 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700378 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800379 }
380
Daniel Sandlerff02d492013-08-05 02:12:05 -0400381 private Stats mStats;
382
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700383 FocusIndicatorView mFocusHandler;
384
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800385 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800386 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700387 }
388
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800389 @Override
390 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700391 if (DEBUG_STRICT_MODE) {
392 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
393 .detectDiskReads()
394 .detectDiskWrites()
395 .detectNetwork() // or .detectAll() for all detectable problems
396 .penaltyLog()
397 .build());
398 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
399 .detectLeakedSqlLiteObjects()
400 .detectLeakedClosableObjects()
401 .penaltyLog()
402 .penaltyDeath()
403 .build());
404 }
405
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800406 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400407
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400408 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400409 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700410 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700411 // Determine the dynamic grid properties
412 Point smallestSize = new Point();
413 Point largestSize = new Point();
414 Point realSize = new Point();
415 Display display = getWindowManager().getDefaultDisplay();
416 display.getCurrentSizeRange(smallestSize, largestSize);
417 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700418 DisplayMetrics dm = new DisplayMetrics();
419 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700420
Winson Chung5f8afe62013-08-12 16:19:28 -0700421 // Lazy-initialize the dynamic grid
422 DeviceProfile grid = app.initDynamicGrid(this,
423 Math.min(smallestSize.x, smallestSize.y),
424 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700425 realSize.x, realSize.y,
426 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700427
428 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400429 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700430 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700431 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800432 mModel = app.setLauncher(this);
433 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700434 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400435 mDragController = new DragController(this);
Winson Chunga6945242014-01-08 14:04:34 -0800436 mLauncherClings = new LauncherClings(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800437 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700438
Daniel Sandlerff02d492013-08-05 02:12:05 -0400439 mStats = new Stats(this);
440
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700441 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700442
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700443 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
444 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700445
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700446 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
447 // this also ensures that any synchronous binding below doesn't re-trigger another
448 // LauncherModel load.
449 mPaused = false;
450
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800451 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200452 android.os.Debug.startMethodTracing(
453 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800454 }
455
456 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800457 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700458
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800459 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100460 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800461
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800462 registerContentObservers();
463
Joe Onorato7c312c12009-08-13 21:36:53 -0700464 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700465
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800466 mSavedState = savedInstanceState;
467 restoreState(mSavedState);
468
469 if (PROFILE_STARTUP) {
470 android.os.Debug.stopMethodTracing();
471 }
472
473 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700474 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700475 // If the user leaves launcher, then we should just load items asynchronously when
476 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500477 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700478 } else {
479 // We only load the page synchronously if the user rotates (or triggers a
480 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800481 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700482 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800483 }
484
485 // For handling default keys
486 mDefaultKeySsb = new SpannableStringBuilder();
487 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800488
489 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
490 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800491
Adam Cohenf9426d52012-06-04 17:26:21 -0700492 updateGlobalIcons();
493
494 // On large interfaces, we want the screen to auto-rotate based on the current orientation
495 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700496
Adam Cohen432609a2014-03-13 17:03:22 -0700497 if (shouldShowIntroScreen()) {
498 showIntroScreen();
499 } else {
500 showFirstRunActivity();
501 }
502
Winson Chunge43a1e72014-01-15 10:33:02 -0800503 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
504 // on the device, then we always show the first run cling experience (or if there is no
505 // launcher2). Otherwise, we prompt the user upon started for migration
Winson Chunge43a1e72014-01-15 10:33:02 -0800506 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
507 if (mModel.canMigrateFromOldLauncherDb(this)) {
508 mLauncherClings.showMigrationCling();
509 } else {
510 mLauncherClings.showFirstRunCling();
511 }
Winson Chunga6945242014-01-08 14:04:34 -0800512 } else {
Winson Chunge43a1e72014-01-15 10:33:02 -0800513 mLauncherClings.removeFirstRunAndMigrationClings();
Winson Chunga6945242014-01-08 14:04:34 -0800514 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700515 }
516
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700517 @Override
518 public void onLauncherProviderChange() { }
519
Winson Chung98ca0f72013-07-29 12:58:51 -0700520 /** To be overriden by subclasses to hint to Launcher that we have custom content */
521 protected boolean hasCustomContentToLeft() {
522 return false;
523 }
524
Dave Hawkeya8881582013-09-17 15:55:33 -0600525 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500526 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600527 * {@link #addToCustomContentPage}. This will only be invoked if
528 * {@link #hasCustomContentToLeft()} is {@code true}.
529 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500530 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600531 }
532
533 /**
534 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
535 * ensure the custom content page is added or removed if necessary.
536 */
537 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600538 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600539 // Not bound yet, wait for bindScreens to be called.
540 return;
541 }
542
543 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
544 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500545 mWorkspace.createCustomContentContainer();
546 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600547 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
548 mWorkspace.removeCustomContentPage();
549 }
550 }
551
Adam Cohenf9426d52012-06-04 17:26:21 -0700552 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700553 boolean searchVisible = false;
554 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800555 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700556 int coi = getCurrentOrientationIndexForGlobalIcons();
Adam Cohena00673c2014-08-14 12:57:28 -0700557 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700558 searchVisible = updateGlobalSearchIcon();
559 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700560 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700561 if (sGlobalSearchIcon[coi] != null) {
562 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700563 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700564 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700565 if (sVoiceSearchIcon[coi] != null) {
566 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700567 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700568 }
Winson Chungadf0c182012-08-23 14:59:07 -0700569 if (mSearchDropTargetBar != null) {
570 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
571 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800572 }
Romain Guycbb89e42009-06-08 15:52:54 -0700573
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800574 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700575 if (sLocaleConfiguration == null) {
576 new AsyncTask<Void, Void, LocaleConfiguration>() {
577 @Override
578 protected LocaleConfiguration doInBackground(Void... unused) {
579 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
580 readConfiguration(Launcher.this, localeConfiguration);
581 return localeConfiguration;
582 }
583
584 @Override
585 protected void onPostExecute(LocaleConfiguration result) {
586 sLocaleConfiguration = result;
587 checkForLocaleChange(); // recursive, but now with a locale configuration
588 }
589 }.execute();
590 return;
591 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700592
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800593 final Configuration configuration = getResources().getConfiguration();
594
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700595 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800596 final String locale = configuration.locale.toString();
597
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700598 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800599 final int mcc = configuration.mcc;
600
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700601 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800602 final int mnc = configuration.mnc;
603
Romain Guy84f296c2009-11-04 15:00:44 -0800604 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800605
Romain Guy84f296c2009-11-04 15:00:44 -0800606 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700607 sLocaleConfiguration.locale = locale;
608 sLocaleConfiguration.mcc = mcc;
609 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700610
Joe Onorato0589f0f2010-02-08 13:44:00 -0800611 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700612
613 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100614 new AsyncTask<Void, Void, Void>() {
615 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700616 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100617 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700618 }
Michael Jurka43467462013-11-14 12:03:58 +0100619 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700620 }
621 }
622
623 private static class LocaleConfiguration {
624 public String locale;
625 public int mcc = -1;
626 public int mnc = -1;
627 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700628
Romain Guy98d01652009-06-30 16:21:04 -0700629 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
630 DataInputStream in = null;
631 try {
632 in = new DataInputStream(context.openFileInput(PREFERENCES));
633 configuration.locale = in.readUTF();
634 configuration.mcc = in.readInt();
635 configuration.mnc = in.readInt();
636 } catch (FileNotFoundException e) {
637 // Ignore
638 } catch (IOException e) {
639 // Ignore
640 } finally {
641 if (in != null) {
642 try {
643 in.close();
644 } catch (IOException e) {
645 // Ignore
646 }
647 }
648 }
649 }
650
651 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
652 DataOutputStream out = null;
653 try {
654 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
655 out.writeUTF(configuration.locale);
656 out.writeInt(configuration.mcc);
657 out.writeInt(configuration.mnc);
658 out.flush();
659 } catch (FileNotFoundException e) {
660 // Ignore
661 } catch (IOException e) {
662 //noinspection ResultOfMethodCallIgnored
663 context.getFileStreamPath(PREFERENCES).delete();
664 } finally {
665 if (out != null) {
666 try {
667 out.close();
668 } catch (IOException e) {
669 // Ignore
670 }
671 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800672 }
673 }
674
Anton Hanssona2f665f2013-09-26 12:18:32 +0100675 public Stats getStats() {
676 return mStats;
677 }
678
Bjorn Bringertc459e522013-06-07 19:36:01 +0100679 public LayoutInflater getInflater() {
680 return mInflater;
681 }
682
Winson Chung36a62fe2012-05-06 18:04:42 -0700683 boolean isDraggingEnabled() {
684 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
685 // that is subsequently removed from the workspace in startBinding().
686 return !mModel.isLoadingWorkspace();
687 }
688
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800689 static int getScreen() {
690 synchronized (sLock) {
691 return sScreen;
692 }
693 }
694
695 static void setScreen(int screen) {
696 synchronized (sLock) {
697 sScreen = screen;
698 }
699 }
700
Winson Chung557d6ed2011-07-08 15:34:52 -0700701 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000702 * Copied from View -- the View version of the method isn't called
703 * anywhere else in our process and only exists for API level 17+,
704 * so it's ok to keep our own version with no API requirement.
705 */
706 public static int generateViewId() {
707 for (;;) {
708 final int result = sNextGeneratedId.get();
709 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
710 int newValue = result + 1;
711 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
712 if (sNextGeneratedId.compareAndSet(result, newValue)) {
713 return result;
714 }
715 }
716 }
717
718 public int getViewIdForItem(ItemInfo info) {
719 // This cast is safe given the > 2B range for int.
720 int itemId = (int) info.id;
721 if (mItemIdToViewId.containsKey(itemId)) {
722 return mItemIdToViewId.get(itemId);
723 }
724 int viewId = generateViewId();
725 mItemIdToViewId.put(itemId, viewId);
726 return viewId;
727 }
728
729 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700730 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
731 * a configuration step, this allows the proper animations to run after other transitions.
732 */
Adam Cohendb364c32014-05-20 14:23:40 -0700733 private long completeAdd(PendingAddArguments args) {
734
735 long screenId = ensurePendingDropLayoutExists(args.screenId);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800736 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800737 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700738 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700739 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700740 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800741 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700742 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700743 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700744 case REQUEST_RECONFIGURE_APPWIDGET:
745 completeRestoreAppWidget(args.appWidgetId);
746 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800747 }
Michael Jurka27614d22012-04-02 06:40:22 -0700748 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
749 // if you turned the screen off and then back while in All Apps, Launcher would not
750 // return to the workspace. Clearing mAddInfo.container here fixes this issue
751 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700752 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800753 }
754
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800755 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700756 protected void onActivityResult(
757 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700758 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700759 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700760 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800761 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700762
Adam Cohenad4e15c2013-10-17 16:21:35 -0700763 Runnable exitSpringLoaded = new Runnable() {
764 @Override
765 public void run() {
766 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
767 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
768 }
769 };
770
Michael Jurka8b805b12012-04-18 14:23:14 -0700771 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700772 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700773 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
774 if (resultCode == RESULT_CANCELED) {
775 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700776 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700777 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700778 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700779 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
780 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700781 }
782 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200783 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
784 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
785 mWorkspace.exitOverviewMode(false);
786 }
787 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700788 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200789
Adam Cohened66b2b2012-01-23 17:28:51 -0800790 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
791 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700792
Adam Cohendb364c32014-05-20 14:23:40 -0700793 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800794 // We have special handling for widgets
795 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800796 final int appWidgetId;
797 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
798 : -1;
799 if (widgetId < 0) {
800 appWidgetId = pendingAddWidgetId;
801 } else {
802 appWidgetId = widgetId;
803 }
804
Adam Cohenad4e15c2013-10-17 16:21:35 -0700805 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800806 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700807 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
808 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700809 result = RESULT_CANCELED;
810 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700811 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700812 @Override
813 public void run() {
814 exitSpringLoadedDragModeDelayed(false, 0, null);
815 }
816 };
Adam Cohendb364c32014-05-20 14:23:40 -0700817 if (workspaceLocked) {
818 // No need to remove the empty screen if we're mid-binding, as the
819 // the bind will not add the empty screen.
820 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
821 } else {
822 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
823 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
824 }
Winson Chung5aaab772012-04-27 15:24:02 -0700825 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700826 if (!workspaceLocked) {
827 mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
828 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
829
830 dropLayout.setDropPending(true);
831 final Runnable onComplete = new Runnable() {
832 @Override
833 public void run() {
834 completeTwoStageWidgetDrop(resultCode, appWidgetId);
835 dropLayout.setDropPending(false);
836 }
837 };
838 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
839 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
840 } else {
841 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
842 mPendingAddInfo);
843 sPendingAddItem = args;
844 }
Winson Chung5aaab772012-04-27 15:24:02 -0700845 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800846 return;
847 }
848
Sunny Goyalff572272014-07-23 13:58:07 -0700849 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
850 if (resultCode == RESULT_OK) {
851 // Update the widget view.
852 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
853 pendingAddWidgetId, mPendingAddInfo);
854 if (workspaceLocked) {
855 sPendingAddItem = args;
856 } else {
857 completeAdd(args);
858 }
859 }
860 // Leave the widget in the pending state if the user canceled the configure.
861 return;
862 }
863
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800864 // The pattern used here is that a user PICKs a specific application,
865 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700866
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800867 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
868 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700869 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700870 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
871 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800872 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700873 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800874 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700875 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700876 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
877 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800878 }
Adam Cohen00074722013-10-11 17:46:09 -0700879 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700880 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700881 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800882 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800883 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800884 }
885
Adam Cohendb364c32014-05-20 14:23:40 -0700886 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
887 appWidgetId, ItemInfo info) {
888 PendingAddArguments args = new PendingAddArguments();
889 args.requestCode = requestCode;
890 args.intent = data;
891 args.container = info.container;
892 args.screenId = info.screenId;
893 args.cellX = info.cellX;
894 args.cellY = info.cellY;
895 args.appWidgetId = appWidgetId;
896 return args;
897 }
898
899 /**
900 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
901 *
902 * @param screenId the screen id to check
903 * @return the new screen, or screenId if it exists
904 */
905 private long ensurePendingDropLayoutExists(long screenId) {
906 CellLayout dropLayout =
907 (CellLayout) mWorkspace.getScreenWithId(screenId);
908 if (dropLayout == null) {
909 // it's possible that the add screen was removed because it was
910 // empty and a re-bind occurred
911 mWorkspace.addExtraEmptyScreen();
912 return mWorkspace.commitExtraEmptyScreen();
913 } else {
914 return screenId;
915 }
916 }
917
Adam Cohened66b2b2012-01-23 17:28:51 -0800918 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700919 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700920 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800921 Runnable onCompleteRunnable = null;
922 int animationType = 0;
923
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700924 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800925 if (resultCode == RESULT_OK) {
926 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
927 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700928 mPendingAddWidgetInfo);
929 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800930 onCompleteRunnable = new Runnable() {
931 @Override
932 public void run() {
933 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700934 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700935 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
936 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800937 }
938 };
939 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800940 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800941 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800942 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700943 if (mDragLayer.getAnimatedView() != null) {
944 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
945 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
946 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700947 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700948 // The animated view may be null in the case of a rotation during widget configuration
949 onCompleteRunnable.run();
950 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800951 }
952
953 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700954 protected void onStop() {
955 super.onStop();
956 FirstFrameAnimatorHelper.setIsVisible(false);
957 }
958
959 @Override
960 protected void onStart() {
961 super.onStart();
962 FirstFrameAnimatorHelper.setIsVisible(true);
963 }
964
965 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800966 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200967 long startTime = 0;
968 if (DEBUG_RESUME_TIME) {
969 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400970 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200971 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800972 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700973
Winson Chung4a2afa32012-07-19 14:53:05 -0700974 // Restore the previous launcher state
975 if (mOnResumeState == State.WORKSPACE) {
976 showWorkspace(false);
977 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -0800978 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700979 }
980 mOnResumeState = State.NONE;
981
Craig Mautner360310b2012-10-26 15:13:08 -0700982 // Background was set to gradient in onPause(), restore to black if in all apps.
983 setWorkspaceBackground(mState == State.WORKSPACE);
984
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800985 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700986 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700987 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500988 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400989 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700990 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800991 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700992 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200993 // We might have postponed some bind calls until onResume (see waitUntilResume) --
994 // execute them here
995 long startTimeCallbacks = 0;
996 if (DEBUG_RESUME_TIME) {
997 startTimeCallbacks = System.currentTimeMillis();
998 }
999
1000 if (mAppsCustomizeContent != null) {
1001 mAppsCustomizeContent.setBulkBind(true);
1002 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001003 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1004 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001005 }
1006 if (mAppsCustomizeContent != null) {
1007 mAppsCustomizeContent.setBulkBind(false);
1008 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001009 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001010 if (DEBUG_RESUME_TIME) {
1011 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1012 (System.currentTimeMillis() - startTimeCallbacks));
1013 }
Michael Jurka447bf842013-05-15 14:52:15 +02001014 }
Michael Jurka54554252013-08-01 12:52:23 +02001015 if (mOnResumeCallbacks.size() > 0) {
1016 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1017 mOnResumeCallbacks.get(i).run();
1018 }
1019 mOnResumeCallbacks.clear();
1020 }
Winson Chunge4e50662012-01-23 14:45:13 -08001021
1022 // Reset the pressed state of icons that were locked in the press state while activities
1023 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001024 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001025 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001026 mWaitingForResume.setStayPressed(false);
1027 }
Winson Chung82963d52013-10-09 11:20:57 -07001028
Adam Cohen06dff352012-06-01 17:17:08 -07001029 // It is possible that widgets can receive updates while launcher is not in the foreground.
1030 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1031 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1032 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001033 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001034
Winson Chung780fe592013-09-26 14:48:44 -07001035 // Process any items that were added while Launcher was away.
1036 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1037
Winson Chung5841efa2013-09-30 18:06:44 -07001038 // Update the voice search button proxy
1039 updateVoiceButtonProxyVisible(false);
1040
Adam Cohenf9426d52012-06-04 17:26:21 -07001041 // Again, as with the above scenario, it's possible that one or more of the global icons
1042 // were updated in the wrong orientation.
1043 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001044 if (DEBUG_RESUME_TIME) {
1045 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1046 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001047
1048 if (mWorkspace.getCustomContentCallbacks() != null) {
1049 // If we are resuming and the custom content is the current page, we call onShow().
1050 // It is also poassible that onShow will instead be called slightly after first layout
1051 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1052 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001053 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001054 }
1055 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001056 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001057 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001058
1059 PackageInstallerCompat.getInstance(this).onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001060 }
1061
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001062 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001063 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001064 // Ensure that items added to Launcher are queued until Launcher returns
1065 InstallShortcutReceiver.enableInstallQueue();
Sunny Goyale755d462014-07-22 13:48:29 -07001066 PackageInstallerCompat.getInstance(this).onPause();
Winson Chung997a9232013-07-24 15:33:46 -07001067
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001068 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001069 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001070 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001071 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001072
1073 // We call onHide() aggressively. The custom content callbacks should be able to
1074 // debounce excess onHide calls.
1075 if (mWorkspace.getCustomContentCallbacks() != null) {
1076 mWorkspace.getCustomContentCallbacks().onHide();
1077 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001078 }
Romain Guycbb89e42009-06-08 15:52:54 -07001079
Adam Cohenbffe7452013-07-22 18:21:45 -07001080 QSBScroller mQsbScroller = new QSBScroller() {
1081 int scrollY = 0;
1082
1083 @Override
1084 public void setScrollY(int scroll) {
1085 scrollY = scroll;
1086
1087 if (mWorkspace.isOnOrMovingToCustomContent()) {
1088 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001089 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001090 }
1091 }
1092 };
1093
1094 public void resetQSBScroll() {
1095 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001096 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001097 }
1098
1099 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001100 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1101 // by a onResume or by scrolling otherwise.
1102 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001103
1104 // Custom content is completely hidden
1105 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001106
1107 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1108 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001109
1110 // Indicates whether the user is allowed to scroll away from the custom content.
1111 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001112 }
1113
Jorim Jaggid017f882014-01-14 17:08:48 -08001114 protected boolean hasSettings() {
1115 return false;
1116 }
1117
Adam Cohenbffe7452013-07-22 18:21:45 -07001118 public interface QSBScroller {
1119 public void setScrollY(int scrollY);
1120 }
1121
Winson Chung98ca0f72013-07-29 12:58:51 -07001122 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001123 CustomContentCallbacks callbacks, String description) {
1124 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001125 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001126 }
1127
Adam Cohenedb40762013-07-18 16:45:45 -07001128 // The custom content needs to offset its content to account for the QSB
1129 public int getTopOffsetForCustomContent() {
1130 return mWorkspace.getPaddingTop();
1131 }
1132
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001133 @Override
1134 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001135 // Flag the loader to stop early before switching
1136 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001137 if (mAppsCustomizeContent != null) {
1138 mAppsCustomizeContent.surrender();
1139 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001140 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001141 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001142
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001143 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001144 @Override
1145 public void onWindowFocusChanged(boolean hasFocus) {
1146 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001147 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001148 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001149
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001150 private boolean acceptFilter() {
1151 final InputMethodManager inputManager = (InputMethodManager)
1152 getSystemService(Context.INPUT_METHOD_SERVICE);
1153 return !inputManager.isFullscreenMode();
1154 }
1155
1156 @Override
1157 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001158 final int uniChar = event.getUnicodeChar();
1159 final boolean handled = super.onKeyDown(keyCode, event);
1160 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1161 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001162 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1163 keyCode, event);
1164 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001165 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001166 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001167 // showSearchDialog()
1168 // If there are multiple keystrokes before the search dialog takes focus,
1169 // onSearchRequested() will be called for every keystroke,
1170 // but it is idempotent, so it's fine.
1171 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001172 }
1173 }
1174
Joe Onorato8a9625e2010-01-28 15:55:35 -08001175 // Eat the long press event so the keyboard doesn't come up.
1176 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1177 return true;
1178 }
1179
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001180 return handled;
1181 }
1182
Karl Rosaen138a0412009-04-23 19:00:21 -07001183 private String getTypedText() {
1184 return mDefaultKeySsb.toString();
1185 }
1186
1187 private void clearTypedText() {
1188 mDefaultKeySsb.clear();
1189 mDefaultKeySsb.clearSpans();
1190 Selection.setSelection(mDefaultKeySsb, 0);
1191 }
1192
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001193 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001194 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1195 * State
1196 */
1197 private static State intToState(int stateOrdinal) {
1198 State state = State.WORKSPACE;
1199 final State[] stateValues = State.values();
1200 for (int i = 0; i < stateValues.length; i++) {
1201 if (stateValues[i].ordinal() == stateOrdinal) {
1202 state = stateValues[i];
1203 break;
1204 }
1205 }
1206 return state;
1207 }
1208
1209 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001210 * Restores the previous state, if it exists.
1211 *
1212 * @param savedState The previous state.
1213 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001214 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001215 private void restoreState(Bundle savedState) {
1216 if (savedState == null) {
1217 return;
1218 }
1219
Michael Jurka883f55b2010-10-21 15:47:14 -07001220 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001221 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001222 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001223 }
1224
Adam Cohen21cd0022013-10-09 18:57:02 -07001225 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1226 PagedView.INVALID_RESTORE_PAGE);
1227 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001228 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229 }
1230
Winson Chung3d503fb2011-07-13 17:25:49 -07001231 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001232 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001233
Winson Chung3d503fb2011-07-13 17:25:49 -07001234 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1235 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001236 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001237 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1238 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001239 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1240 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1241 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001242 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001243 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001244 mRestoring = true;
1245 }
1246
1247 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1248 if (renameFolder) {
1249 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001250 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001251 mRestoring = true;
1252 }
Winson Chunga12a2502010-12-20 14:41:35 -08001253
Winson Chung785d2eb2011-04-14 16:08:02 -07001254 // Restore the AppsCustomize tab
1255 if (mAppsCustomizeTabHost != null) {
1256 String curTab = savedState.getString("apps_customize_currentTab");
1257 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001258 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001259 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001260 mAppsCustomizeContent.loadAssociatedPages(
1261 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001262 }
1263
Winson Chung5afbf7b2011-07-25 11:53:08 -07001264 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1265 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001266 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001267 mItemIdToViewId = (HashMap<Integer, Integer>)
1268 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001269 }
1270
1271 /**
1272 * Finds all the views we need and configure them properly.
1273 */
1274 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001275 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001276
Craig Mautner360310b2012-10-26 15:13:08 -07001277 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001278 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001279 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1280 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001281 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001282 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001283
John Spurlock77e1f472013-09-11 10:09:51 -04001284 mLauncherView.setSystemUiVisibility(
1285 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001286 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001287
Winson Chung4c98d922011-05-31 16:50:48 -07001288 // Setup the drag layer
1289 mDragLayer.setup(this, dragController);
1290
Winson Chung3d503fb2011-07-13 17:25:49 -07001291 // Setup the hotseat
1292 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1293 if (mHotseat != null) {
1294 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001295 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001296 }
1297
Jorim Jaggid017f882014-01-14 17:08:48 -08001298 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001299 View widgetButton = findViewById(R.id.widget_button);
1300 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001301 @Override
1302 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001303 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001304 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001305 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001306 }
1307 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001308 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1309
1310 View wallpaperButton = findViewById(R.id.wallpaper_button);
1311 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001312 @Override
1313 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001314 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001315 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001316 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001317 }
1318 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001319 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1320
1321 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001322 if (hasSettings()) {
1323 settingsButton.setOnClickListener(new OnClickListener() {
1324 @Override
1325 public void onClick(View arg0) {
1326 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001327 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001328 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001329 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001330 });
1331 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1332 } else {
1333 settingsButton.setVisibility(View.GONE);
1334 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1335 lp.gravity = Gravity.END | Gravity.TOP;
1336 widgetButton.requestLayout();
1337 }
1338
Adam Cohendbdff6b2013-09-18 19:09:15 -07001339 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001340
Winson Chung4c98d922011-05-31 16:50:48 -07001341 // Setup the workspace
1342 mWorkspace.setHapticFeedbackEnabled(false);
1343 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001344 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001345 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001346
Winson Chungf0ea4d32011-06-06 14:27:16 -07001347 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001348 mSearchDropTargetBar = (SearchDropTargetBar)
1349 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001350
Winson Chungf0ea4d32011-06-06 14:27:16 -07001351 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001352 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001353 mAppsCustomizeContent = (AppsCustomizePagedView)
1354 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1355 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001356
Winson Chung3d503fb2011-07-13 17:25:49 -07001357 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001358 dragController.setDragScoller(mWorkspace);
1359 dragController.setScrollView(mDragLayer);
1360 dragController.setMoveTarget(mWorkspace);
1361 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001362 if (mSearchDropTargetBar != null) {
1363 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001364 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001365
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001366 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001367 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001368 mWeightWatcher = new WeightWatcher(this);
1369 mWeightWatcher.setAlpha(0.5f);
1370 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001371 new FrameLayout.LayoutParams(
1372 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001373 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001374 Gravity.BOTTOM)
1375 );
Adam Cohen39a06042013-07-19 14:30:12 -07001376
1377 boolean show = shouldShowWeightWatcher();
1378 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001379 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001380 }
1381
1382 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001383 * Sets the all apps button. This method is called from {@link Hotseat}.
1384 */
1385 public void setAllAppsButton(View allAppsButton) {
1386 mAllAppsButton = allAppsButton;
1387 }
1388
1389 public View getAllAppsButton() {
1390 return mAllAppsButton;
1391 }
1392
1393 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001394 * Creates a view representing a shortcut.
1395 *
1396 * @param info The data structure describing the shortcut.
1397 *
1398 * @return A View inflated from R.layout.application.
1399 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001400 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001401 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001402 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001403 }
1404
1405 /**
1406 * Creates a view representing a shortcut inflated from the specified resource.
1407 *
1408 * @param layoutResId The id of the XML layout used to create the shortcut.
1409 * @param parent The group the shortcut belongs to.
1410 * @param info The data structure describing the shortcut.
1411 *
1412 * @return A View inflated from layoutResId.
1413 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001414 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001415 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001416 favorite.applyFromShortcutInfo(info, mIconCache, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001417 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001418 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001419 return favorite;
1420 }
1421
1422 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001423 * Add a shortcut to the workspace.
1424 *
1425 * @param data The intent describing the shortcut.
1426 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001427 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001428 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001429 int cellY) {
1430 int[] cellXY = mTmpAddItemCellCoordinates;
1431 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001432 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001433
Michael Jurkad3ef3062010-11-23 16:23:58 -08001434 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001435
Adam Cohen558baaf2011-08-15 15:22:57 -07001436 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001437 if (info == null) {
1438 return;
1439 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001440 final View view = createShortcut(info);
1441
Adam Cohenfbba09b2011-07-18 21:43:05 -07001442 // First we check if we already know the exact location where we want to add this item.
1443 if (cellX >= 0 && cellY >= 0) {
1444 cellXY[0] = cellX;
1445 cellXY[1] = cellY;
1446 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001447
1448 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001449 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001450 true, null,null)) {
1451 return;
1452 }
1453 DragObject dragObject = new DragObject();
1454 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001455 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1456 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001457 return;
1458 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001459 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001460 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001461 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001462 foundCellSpan = (result != null);
1463 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001464 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001465 }
1466
1467 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001468 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001469 return;
1470 }
1471
Adam Cohendcd297f2013-06-18 13:13:40 -07001472 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001473
1474 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001475 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001476 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001477 }
1478 }
1479
Adam Cohen2f093b62012-04-30 18:59:53 -07001480 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1481 int minHeight) {
1482 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001483 // We want to account for the extra amount of padding that we are adding to the widget
1484 // to ensure that it gets the full amount of space that it has requested
1485 int requiredWidth = minWidth + padding.left + padding.right;
1486 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001487 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001488 }
1489
Adam Cohen2f093b62012-04-30 18:59:53 -07001490 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1491 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001492 }
1493
Adam Cohen2f093b62012-04-30 18:59:53 -07001494 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1495 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001496 }
1497
Adam Cohen2f093b62012-04-30 18:59:53 -07001498 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1499 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001500 }
1501
Adam Cohen2f093b62012-04-30 18:59:53 -07001502 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1503 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001504 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001505 }
1506
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001507 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001508 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001509 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001510 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001511 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001512 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001513 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001514 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1515 if (appWidgetInfo == null) {
1516 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1517 }
Romain Guycbb89e42009-06-08 15:52:54 -07001518
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001519 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001520 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001521
Adam Cohen2f093b62012-04-30 18:59:53 -07001522 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1523 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001524
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001525 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001526 // We have saved the position to which the widget was dragged-- this really only matters
1527 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001528 int[] cellXY = mTmpAddItemCellCoordinates;
1529 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001530 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001531 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001532 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1533 cellXY[0] = mPendingAddInfo.cellX;
1534 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001535 spanXY[0] = mPendingAddInfo.spanX;
1536 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001537 foundCellSpan = true;
1538 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001539 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001540 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001541 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1542 spanXY[1], cellXY, finalSpan);
1543 spanXY[0] = finalSpan[0];
1544 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001545 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001546 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001547 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001548 }
1549
Michael Jurka0280c3b2010-09-17 15:00:07 -07001550 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001551 if (appWidgetId != -1) {
1552 // Deleting an app widget ID is a void call but writes to disk before returning
1553 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001554 new AsyncTask<Void, Void, Void>() {
1555 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001556 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001557 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001558 }
Michael Jurka43467462013-11-14 12:03:58 +01001559 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001560 }
Winson Chung93eef082012-03-23 15:59:27 -07001561 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001562 return;
1563 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001564
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001565 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001566 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1567 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001568 launcherInfo.spanX = spanXY[0];
1569 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001570 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1571 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001572
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001573 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001574 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001575
1576 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001577 if (hostView == null) {
1578 // Perform actual inflation because we're live
1579 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1580 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1581 } else {
1582 // The AppWidgetHostView has already been inflated and instantiated
1583 launcherInfo.hostView = hostView;
1584 }
Romain Guycbb89e42009-06-08 15:52:54 -07001585
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001586 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001587 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001588 launcherInfo.notifyWidgetSizeChanged(this);
1589
Adam Cohendcd297f2013-06-18 13:13:40 -07001590 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001591 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001592
1593 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001594 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001595 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001596 }
Romain Guycbb89e42009-06-08 15:52:54 -07001597
Adam Cohended9f8d2010-11-03 13:25:16 -07001598 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1599 @Override
1600 public void onReceive(Context context, Intent intent) {
1601 final String action = intent.getAction();
1602 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1603 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001604 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001605 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001606
Winson Chungc100e8e2011-08-09 16:02:43 -07001607 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001608 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001609 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001610 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001611 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001612 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1613 mUserPresent = true;
1614 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001615 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1616 mModel.resetLoadedState(false, true);
1617 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1618 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1619 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1620 mModel.resetLoadedState(false, true);
1621 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1622 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1623 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001624 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1625 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1626 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001627 }
1628 }
1629 };
1630
1631 @Override
1632 public void onAttachedToWindow() {
1633 super.onAttachedToWindow();
1634
1635 // Listen for broadcasts related to user-presence
1636 final IntentFilter filter = new IntentFilter();
1637 filter.addAction(Intent.ACTION_SCREEN_OFF);
1638 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001639 // For handling managed profiles
1640 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1641 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001642 if (ENABLE_DEBUG_INTENTS) {
1643 filter.addAction(DebugIntents.DELETE_DATABASE);
1644 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1645 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001646 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001647 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001648 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001649 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001650 mVisible = true;
1651 }
1652
Adam Cohen0b395352014-06-09 22:54:36 +00001653 /**
1654 * Sets up transparent navigation and status bars in LMP.
1655 * This method is a no-op for other platform versions.
1656 */
1657 @TargetApi(19)
1658 private void setupTransparentSystemBarsForLmp() {
1659 // TODO(sansid): use the APIs directly when compiling against L sdk.
1660 // Currently we use reflection to access the flags and the API to set the transparency
1661 // on the System bars.
1662 if (Utilities.isLmp()) {
1663 try {
1664 getWindow().getAttributes().systemUiVisibility |=
1665 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1666 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1667 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1668 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1669 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1670 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1671 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1672 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1673
1674 Method setStatusBarColorMethod =
1675 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1676 Method setNavigationBarColorMethod =
1677 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1678 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1679 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1680 } catch (NoSuchFieldException e) {
1681 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1682 } catch (NoSuchMethodException ex) {
1683 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1684 } catch (IllegalAccessException e) {
1685 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1686 } catch (IllegalArgumentException e) {
1687 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1688 } catch (InvocationTargetException e) {
1689 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1690 } finally {}
1691 }
1692 }
1693
Adam Cohended9f8d2010-11-03 13:25:16 -07001694 @Override
1695 public void onDetachedFromWindow() {
1696 super.onDetachedFromWindow();
1697 mVisible = false;
1698
Adam Cohend113e0c2010-11-11 10:48:05 -08001699 if (mAttached) {
1700 unregisterReceiver(mReceiver);
1701 mAttached = false;
1702 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001703 updateRunning();
1704 }
1705
1706 public void onWindowVisibilityChanged(int visibility) {
1707 mVisible = visibility == View.VISIBLE;
1708 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001709 // The following code used to be in onResume, but it turns out onResume is called when
1710 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1711 // is a more appropriate event to handle
1712 if (mVisible) {
1713 mAppsCustomizeTabHost.onWindowVisible();
1714 if (!mWorkspaceLoading) {
1715 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001716 // We want to let Launcher draw itself at least once before we force it to build
1717 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001718 // apps is nice and speedy.
1719 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001720 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001721 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001722 if (mStarted) return;
1723 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001724 // We delay the layer building a bit in order to give
1725 // other message processing a time to run. In particular
1726 // this avoids a delay in hiding the IME if it was
1727 // currently shown, because doing that may involve
1728 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001729 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001730 final ViewTreeObserver.OnDrawListener listener = this;
1731 mWorkspace.post(new Runnable() {
1732 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001733 if (mWorkspace != null &&
1734 mWorkspace.getViewTreeObserver() != null) {
1735 mWorkspace.getViewTreeObserver().
1736 removeOnDrawListener(listener);
1737 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001738 }
1739 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001740 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001741 }
1742 });
1743 }
1744 clearTypedText();
1745 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001746 }
1747
1748 private void sendAdvanceMessage(long delay) {
1749 mHandler.removeMessages(ADVANCE_MSG);
1750 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1751 mHandler.sendMessageDelayed(msg, delay);
1752 mAutoAdvanceSentTime = System.currentTimeMillis();
1753 }
1754
1755 private void updateRunning() {
1756 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1757 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1758 mAutoAdvanceRunning = autoAdvanceRunning;
1759 if (autoAdvanceRunning) {
1760 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1761 sendAdvanceMessage(delay);
1762 } else {
1763 if (!mWidgetsToAdvance.isEmpty()) {
1764 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1765 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1766 }
1767 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001768 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001769 }
1770 }
1771 }
1772
1773 private final Handler mHandler = new Handler() {
1774 @Override
1775 public void handleMessage(Message msg) {
1776 if (msg.what == ADVANCE_MSG) {
1777 int i = 0;
1778 for (View key: mWidgetsToAdvance.keySet()) {
1779 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1780 final int delay = mAdvanceStagger * i;
1781 if (v instanceof Advanceable) {
1782 postDelayed(new Runnable() {
1783 public void run() {
1784 ((Advanceable) v).advance();
1785 }
1786 }, delay);
1787 }
1788 i++;
1789 }
1790 sendAdvanceMessage(mAdvanceInterval);
1791 }
1792 }
1793 };
1794
1795 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001796 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001797 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1798 if (v instanceof Advanceable) {
1799 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001800 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001801 updateRunning();
1802 }
1803 }
1804
1805 void removeWidgetToAutoAdvance(View hostView) {
1806 if (mWidgetsToAdvance.containsKey(hostView)) {
1807 mWidgetsToAdvance.remove(hostView);
1808 updateRunning();
1809 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001810 }
1811
Joe Onorato9c1289c2009-08-17 11:03:03 -04001812 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001813 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001814 launcherInfo.hostView = null;
1815 }
1816
Winson Chung93eef082012-03-23 15:59:27 -07001817 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1818 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1819 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001820 }
1821
Winson Chunga6945242014-01-08 14:04:34 -08001822 public DragLayer getDragLayer() {
1823 return mDragLayer;
1824 }
1825
1826 public Workspace getWorkspace() {
1827 return mWorkspace;
1828 }
1829
1830 public Hotseat getHotseat() {
1831 return mHotseat;
1832 }
1833
Jorim Jaggid017f882014-01-14 17:08:48 -08001834 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001835 return mOverviewPanel;
1836 }
1837
1838 public SearchDropTargetBar getSearchBar() {
1839 return mSearchDropTargetBar;
1840 }
1841
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001842 public LauncherAppWidgetHost getAppWidgetHost() {
1843 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001844 }
Romain Guycbb89e42009-06-08 15:52:54 -07001845
Winson Chunga9abd0e2010-10-27 17:18:37 -07001846 public LauncherModel getModel() {
1847 return mModel;
1848 }
1849
Winson Chunga6945242014-01-08 14:04:34 -08001850 public LauncherClings getLauncherClings() {
1851 return mLauncherClings;
1852 }
1853
1854 protected SharedPreferences getSharedPrefs() {
1855 return mSharedPrefs;
1856 }
1857
Bjorn Bringertc459e522013-06-07 19:36:01 +01001858 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001859 getWindow().closeAllPanels();
1860
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001861 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001862 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001863 }
1864
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001865 @Override
1866 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001867 long startTime = 0;
1868 if (DEBUG_RESUME_TIME) {
1869 startTime = System.currentTimeMillis();
1870 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001871 super.onNewIntent(intent);
1872
1873 // Close the menu
1874 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001875 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001876 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001877
Adam Cohened307df2013-10-02 09:37:31 -07001878 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1879 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1880 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001881
Adam Cohen6fecd412013-10-02 17:41:50 -07001882 if (mWorkspace == null) {
1883 // Can be cases where mWorkspace is null, this prevents a NPE
1884 return;
1885 }
1886 Folder openFolder = mWorkspace.getOpenFolder();
1887 // In all these cases, only animate if we're already on home
1888 mWorkspace.exitWidgetResizeMode();
1889 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001890 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001891 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001892 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001893
Adam Cohen6fecd412013-10-02 17:41:50 -07001894 closeFolder();
1895 exitSpringLoadedDragMode();
1896
1897 // If we are already on home, then just animate back to the workspace,
1898 // otherwise, just wait until onResume to set the state back to Workspace
1899 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001900 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001901 } else {
1902 mOnResumeState = State.WORKSPACE;
1903 }
1904
1905 final View v = getWindow().peekDecorView();
1906 if (v != null && v.getWindowToken() != null) {
1907 InputMethodManager imm = (InputMethodManager)getSystemService(
1908 INPUT_METHOD_SERVICE);
1909 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1910 }
1911
1912 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001913 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001914 mAppsCustomizeTabHost.reset();
1915 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001916
1917 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001918 }
Adam Cohened307df2013-10-02 09:37:31 -07001919
Michael Jurka447bf842013-05-15 14:52:15 +02001920 if (DEBUG_RESUME_TIME) {
1921 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1922 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001923 }
1924
Adam Coppa120b8e2013-11-12 16:26:04 +00001925 /**
1926 * Override point for subclasses to prevent movement to the default screen when the home
1927 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1928 */
1929 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1930 return true;
1931 }
1932
1933 /**
1934 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1935 */
1936 protected void onHomeIntent() {
1937 // Do nothing
1938 }
1939
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001940 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001941 public void onRestoreInstanceState(Bundle state) {
1942 super.onRestoreInstanceState(state);
1943 for (int page: mSynchronouslyBoundPages) {
1944 mWorkspace.restoreInstanceStateForChild(page);
1945 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001946 }
1947
1948 @Override
1949 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001950 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001951 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1952 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001953 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001954 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001955
Michael Jurka883f55b2010-10-21 15:47:14 -07001956 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001957 // We close any open folder since it will not be re-opened, and we need to make sure
1958 // this state is reflected.
1959 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001960
Adam Cohendcd297f2013-06-18 13:13:40 -07001961 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001962 mWaitingForResult) {
1963 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001964 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001965 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1966 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001967 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1968 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1969 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001970 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001971 }
1972
1973 if (mFolderInfo != null && mWaitingForResult) {
1974 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1975 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1976 }
Michael Jurka946ad472010-07-09 18:05:18 -07001977
Winson Chung785d2eb2011-04-14 16:08:02 -07001978 // Save the current AppsCustomize tab
1979 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08001980 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1981 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001982 if (currentTabTag != null) {
1983 outState.putString("apps_customize_currentTab", currentTabTag);
1984 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001985 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1986 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001987 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001988 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001989 }
1990
1991 @Override
1992 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001993 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001994
Winson Chunge7a03942011-08-05 15:05:12 -07001995 // Remove all pending runnables
1996 mHandler.removeMessages(ADVANCE_MSG);
1997 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001998 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001999
Winson Chungcd2b0142011-06-08 16:02:26 -07002000 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04002001 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07002002 mModel.stopLoader();
2003 app.setLauncher(null);
2004
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002005 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002006 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002007 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002008 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002009 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002010 mAppWidgetHost = null;
2011
2012 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002013
2014 TextKeyListener.getInstance().release();
2015
Winson Chung81b52252012-08-27 15:34:29 -07002016 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2017 // to prevent leaking Launcher activities on orientation change.
2018 if (mModel != null) {
2019 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2020 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002021
2022 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002023 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002024
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002025 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002026 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002027 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002028 mWorkspace = null;
2029 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002030
Sunny Goyale755d462014-07-22 13:48:29 -07002031 PackageInstallerCompat.getInstance(this).onStop();
Michael Jurka2ecf9952012-06-18 12:52:28 -07002032 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002033 }
2034
Adam Cohena9cf38f2011-05-02 15:36:58 -07002035 public DragController getDragController() {
2036 return mDragController;
2037 }
2038
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002039 @Override
2040 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002041 if (requestCode >= 0) {
2042 setWaitingForResult(true);
2043 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002044 super.startActivityForResult(intent, requestCode);
2045 }
2046
Winson Chung70d72102011-08-12 11:24:35 -07002047 /**
2048 * Indicates that we want global search for this activity by setting the globalSearch
2049 * argument for {@link #startSearch} to true.
2050 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002051 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002052 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002053 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002054
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002055 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002056
Karl Rosaen138a0412009-04-23 19:00:21 -07002057 if (initialQuery == null) {
2058 // Use any text typed in the launcher as the initial query
2059 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002060 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002061 if (appSearchData == null) {
2062 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002063 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002064 }
Winson Chungadf0c182012-08-23 14:59:07 -07002065 Rect sourceBounds = new Rect();
2066 if (mSearchDropTargetBar != null) {
2067 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2068 }
Romain Guycbb89e42009-06-08 15:52:54 -07002069
Bjorn Bringertc459e522013-06-07 19:36:01 +01002070 startSearch(initialQuery, selectInitialQuery,
2071 appSearchData, sourceBounds);
2072 }
2073
2074 public void startSearch(String initialQuery,
2075 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002076 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002077 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07002078 }
2079
2080 /**
2081 * Starts the global search activity. This code is a copied from SearchManager
2082 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002083 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002084 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002085 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002086 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2087 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2088 if (globalSearchActivity == null) {
2089 Log.w(TAG, "No global search activity found.");
2090 return;
2091 }
2092 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2093 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2094 intent.setComponent(globalSearchActivity);
2095 // Make sure that we have a Bundle to put source in
2096 if (appSearchData == null) {
2097 appSearchData = new Bundle();
2098 } else {
2099 appSearchData = new Bundle(appSearchData);
2100 }
2101 // Set source to package name of app that starts global search, if not set already.
2102 if (!appSearchData.containsKey("source")) {
2103 appSearchData.putString("source", getPackageName());
2104 }
2105 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2106 if (!TextUtils.isEmpty(initialQuery)) {
2107 intent.putExtra(SearchManager.QUERY, initialQuery);
2108 }
2109 if (selectInitialQuery) {
2110 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2111 }
2112 intent.setSourceBounds(sourceBounds);
2113 try {
2114 startActivity(intent);
2115 } catch (ActivityNotFoundException ex) {
2116 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2117 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002118 }
2119
Yura4f93ec62014-02-04 14:15:21 +00002120 public boolean isOnCustomContent() {
2121 return mWorkspace.isOnOrMovingToCustomContent();
2122 }
2123
Winson Chung70d72102011-08-12 11:24:35 -07002124 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002125 public boolean onPrepareOptionsMenu(Menu menu) {
2126 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002127 if (!isOnCustomContent()) {
2128 // Close any open folders
2129 closeFolder();
2130 // Stop resizing any widgets
2131 mWorkspace.exitWidgetResizeMode();
2132 if (!mWorkspace.isInOverviewMode()) {
2133 // Show the overview mode
2134 showOverviewMode(true);
2135 } else {
2136 showWorkspace(true);
2137 }
Winson Chunge0298742014-01-17 12:03:00 -08002138 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002139 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002140 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002141
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002142 @Override
2143 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002144 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002145 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002146 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002147 }
2148
Joe Onorato9c1289c2009-08-17 11:03:03 -04002149 public boolean isWorkspaceLocked() {
2150 return mWorkspaceLoading || mWaitingForResult;
2151 }
2152
Adam Cohen517a7f52014-03-01 12:12:59 -08002153 public boolean isWorkspaceLoading() {
2154 return mWorkspaceLoading;
2155 }
2156
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002157 private void setWorkspaceLoading(boolean value) {
2158 boolean isLocked = isWorkspaceLocked();
2159 mWorkspaceLoading = value;
2160 if (isLocked != isWorkspaceLocked()) {
2161 onWorkspaceLockedChanged();
2162 }
2163 }
2164
2165 private void setWaitingForResult(boolean value) {
2166 boolean isLocked = isWorkspaceLocked();
2167 mWaitingForResult = value;
2168 if (isLocked != isWorkspaceLocked()) {
2169 onWorkspaceLockedChanged();
2170 }
2171 }
2172
2173 protected void onWorkspaceLockedChanged() { }
2174
Michael Jurka0280c3b2010-09-17 15:00:07 -07002175 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002176 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002177 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002178 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2179 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002180 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002181 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002182 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002183
Adam Cohenad4e15c2013-10-17 16:21:35 -07002184 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2185 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2186 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2187 }
2188
2189 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2190 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2191 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002192 if (appWidgetInfo.configure != null) {
2193 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002194 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002195
Bjorn Bringert7984c942009-12-09 15:38:25 +00002196 // Launch over to configure widget, if needed
2197 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002198 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002199 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002200 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002201 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002202 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002203 Runnable onComplete = new Runnable() {
2204 @Override
2205 public void run() {
2206 // Exit spring loaded mode if necessary after adding the widget
2207 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2208 null);
2209 }
2210 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002211 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002212 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002213 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002214 }
2215 }
Romain Guycbb89e42009-06-08 15:52:54 -07002216
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002217 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002218 // Close any folders that may be open.
2219 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002220 mWorkspace.moveToCustomContentScreen(animate);
2221 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002222 /**
2223 * Process a shortcut drop.
2224 *
2225 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002226 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002227 * @param cell The cell it should be added to, optional
2228 * @param position The location on the screen where it was dropped, optional
2229 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002230 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002231 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002232 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002233 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002234 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002235 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002236
2237 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002238 mPendingAddInfo.cellX = cell[0];
2239 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002240 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002241
2242 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2243 createShortcutIntent.setComponent(componentName);
2244 processShortcut(createShortcutIntent);
2245 }
2246
Adam Cohenfbba09b2011-07-18 21:43:05 -07002247 /**
2248 * Process a widget drop.
2249 *
2250 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002251 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002252 * @param cell The cell it should be added to, optional
2253 * @param position The location on the screen where it was dropped, optional
2254 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002255 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002256 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002257 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002258 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002259 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002260 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002261 mPendingAddInfo.minSpanX = info.minSpanX;
2262 mPendingAddInfo.minSpanY = info.minSpanY;
2263
Adam Cohenfbba09b2011-07-18 21:43:05 -07002264 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002265 mPendingAddInfo.cellX = cell[0];
2266 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002267 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002268 if (span != null) {
2269 mPendingAddInfo.spanX = span[0];
2270 mPendingAddInfo.spanY = span[1];
2271 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002272
Adam Cohened66b2b2012-01-23 17:28:51 -08002273 AppWidgetHostView hostView = info.boundWidget;
2274 int appWidgetId;
2275 if (hostView != null) {
2276 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002277 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002278 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002279 // In this case, we either need to start an activity to get permission to bind
2280 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002281 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002282 Bundle options = info.bindOptions;
2283
2284 boolean success = false;
2285 if (options != null) {
2286 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2287 info.componentName, options);
2288 } else {
2289 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2290 info.componentName);
2291 }
2292 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002293 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002294 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002295 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002296 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2297 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2298 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002299 // TODO: we need to make sure that this accounts for the options bundle.
2300 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002301 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2302 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002303 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002304 }
2305
Joe Onoratodeb98af2010-02-19 14:59:39 -08002306 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002307 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002308 }
2309
Winson Chung24ab2f12010-09-16 14:10:47 -07002310 void processWallpaper(Intent intent) {
2311 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2312 }
2313
Adam Cohendcd297f2013-06-18 13:13:40 -07002314 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002315 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002316 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002317 folderInfo.title = getText(R.string.folder_name);
2318
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002319 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002320 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002321 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002322 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002323
2324 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002325 FolderIcon newFolder =
2326 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002327 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002328 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002329 // Force measure the new folder icon
2330 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2331 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002332 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002333 }
Romain Guycbb89e42009-06-08 15:52:54 -07002334
Joe Onorato9c1289c2009-08-17 11:03:03 -04002335 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002336 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002337 }
2338
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002339 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002340 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002341 }
2342
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002343 /**
2344 * Registers various content observers. The current implementation registers
2345 * only a favorites observer to keep track of the favorites applications.
2346 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002347 private void registerContentObservers() {
2348 ContentResolver resolver = getContentResolver();
2349 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2350 true, mWidgetObserver);
2351 }
2352
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002353 @Override
2354 public boolean dispatchKeyEvent(KeyEvent event) {
2355 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2356 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002357 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002358 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002359 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002360 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002361 dumpState();
2362 return true;
2363 }
2364 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002365 }
2366 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2367 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002368 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002369 return true;
2370 }
2371 }
2372
2373 return super.dispatchKeyEvent(event);
2374 }
2375
Joe Onorato88ec0992009-11-19 13:16:06 -08002376 @Override
2377 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002378 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002379 if (mAppsCustomizeContent.getContentType() ==
2380 AppsCustomizePagedView.ContentType.Applications) {
2381 showWorkspace(true);
2382 } else {
2383 showOverviewMode(true);
2384 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002385 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002386 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002387 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002388 Folder openFolder = mWorkspace.getOpenFolder();
2389 if (openFolder.isEditingName()) {
2390 openFolder.dismissEditingName();
2391 } else {
2392 closeFolder();
2393 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002394 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002395 mWorkspace.exitWidgetResizeMode();
2396
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002397 // Back button is a no-op here, but give at least some feedback for the button press
2398 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002399 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002400 }
2401
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002402 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002403 * Re-listen when widgets are reset.
2404 */
2405 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002406 if (mAppWidgetHost != null) {
2407 mAppWidgetHost.startListening();
2408 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002409 }
2410
2411 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002412 * Launches the intent referred by the clicked shortcut.
2413 *
2414 * @param v The view representing the clicked shortcut.
2415 */
2416 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002417 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2418 // view has detached (it's possible for this to happen if the view is removed mid touch).
2419 if (v.getWindowToken() == null) {
2420 return;
2421 }
2422
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002423 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002424 return;
2425 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002426
Adam Cohen1697b792013-09-17 19:08:21 -07002427 if (v instanceof Workspace) {
2428 if (mWorkspace.isInOverviewMode()) {
2429 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002430 }
2431 return;
2432 }
2433
2434 if (v instanceof CellLayout) {
2435 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002436 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002437 }
2438 }
2439
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002440 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002441 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002442 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002443 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002444 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002445 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002446 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002447 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002448 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002449 } else if (tag instanceof AppInfo) {
2450 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002451 } else if (tag instanceof LauncherAppWidgetInfo) {
2452 if (v instanceof PendingAppWidgetHostView) {
2453 onClickPendingWidget((PendingAppWidgetHostView) v);
2454 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002455 }
2456 }
2457
Sunny Goyal508da152014-08-14 10:53:27 -07002458 public void onClickPagedViewIcon(View v) {
2459 startAppShortcutOrInfoActivity(v);
2460 }
2461
Michael Jurka0e260592010-06-30 17:07:39 -07002462 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002463 return false;
2464 }
2465
Michael Jurkaaf442092010-06-10 17:01:57 -07002466 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002467 * Event handler for the app widget view which has not fully restored.
2468 */
2469 public void onClickPendingWidget(PendingAppWidgetHostView v) {
2470 if (v.isReadyForClickSetup()) {
2471 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
2472 int widgetId = info.appWidgetId;
2473 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2474 if (appWidgetInfo != null) {
2475 mPendingAddWidgetInfo = appWidgetInfo;
2476 mPendingAddInfo.copyFrom(info);
2477 mPendingAddWidgetId = widgetId;
2478
2479 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
2480 intent.setComponent(appWidgetInfo.configure);
2481 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, info.appWidgetId);
2482 Utilities.startActivityForResultSafely(this, intent, REQUEST_RECONFIGURE_APPWIDGET);
2483 }
2484 }
2485 }
2486
2487 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002488 * Event handler for the search button
2489 *
2490 * @param v The view that was clicked.
2491 */
2492 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002493 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2494
Amith Yamasania135ba82011-08-09 17:42:01 -07002495 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002496 }
2497
2498 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002499 * Event handler for the voice button
2500 *
2501 * @param v The view that was clicked.
2502 */
2503 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002504 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002505
Bjorn Bringertc459e522013-06-07 19:36:01 +01002506 startVoice();
2507 }
2508
2509 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002510 try {
2511 final SearchManager searchManager =
2512 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2513 ComponentName activityName = searchManager.getGlobalSearchActivity();
2514 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002515 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002516 if (activityName != null) {
2517 intent.setPackage(activityName.getPackageName());
2518 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002519 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002520 } catch (ActivityNotFoundException e) {
2521 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002522 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002523 startActivitySafely(null, intent, "onClickVoiceButton");
2524 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002525 }
2526
2527 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002528 * Event handler for the "grid" button that appears on the home screen, which
2529 * enters all apps mode.
2530 *
2531 * @param v The view that was clicked.
2532 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002533 protected void onClickAllAppsButton(View v) {
2534 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2535 if (isAllAppsVisible()) {
2536 showWorkspace(true);
2537 } else {
2538 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2539 }
2540 }
2541
2542 /**
2543 * Event handler for an app shortcut click.
2544 *
2545 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2546 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002547 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002548 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2549 Object tag = v.getTag();
2550 if (!(tag instanceof ShortcutInfo)) {
2551 throw new IllegalArgumentException("Input must be a Shortcut");
2552 }
2553
2554 // Open shortcut
2555 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2556 final Intent intent = shortcut.intent;
2557
2558 // Check for special shortcuts
2559 if (intent.getComponent() != null) {
2560 final String shortcutClass = intent.getComponent().getClassName();
2561
2562 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2563 MemoryDumpActivity.startDump(this);
2564 return;
2565 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2566 toggleShowWeightWatcher();
2567 return;
2568 }
2569 }
2570
Chris Wren40c5ed32014-06-24 18:24:23 -04002571 // Check for abandoned promise
2572 if (shortcut.isAbandoned() && v instanceof BubbleTextView) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002573 AlertDialog.Builder builder = new AlertDialog.Builder(this);
2574 builder.setTitle(R.string.abandoned_promises_title);
Chris Wren803a4be2014-07-01 16:52:49 -04002575 builder.setMessage(R.string.abandoned_promise_explanation);
Chris Wren40c5ed32014-06-24 18:24:23 -04002576 builder.setPositiveButton(R.string.abandoned_search,
2577 new DialogInterface.OnClickListener() {
2578 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002579 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002580 }
2581 }
2582 );
Chris Wren40c5ed32014-06-24 18:24:23 -04002583 builder.setNeutralButton(R.string.abandoned_clean_this,
2584 new DialogInterface.OnClickListener() {
2585 public void onClick(DialogInterface dialog, int id) {
2586 final BubbleTextView bubble = (BubbleTextView) v;
2587 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2588 mWorkspace.removeAbandonedPromise(bubble, user);
2589 }
2590 });
2591 builder.create().show();
2592 return;
2593 }
2594
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002595 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002596 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002597 }
2598
Sunny Goyal508da152014-08-14 10:53:27 -07002599 private void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002600 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002601 final ShortcutInfo shortcut;
2602 final Intent intent;
2603 if (tag instanceof ShortcutInfo) {
2604 shortcut = (ShortcutInfo) tag;
2605 intent = shortcut.intent;
2606 int[] pos = new int[2];
2607 v.getLocationOnScreen(pos);
2608 intent.setSourceBounds(new Rect(pos[0], pos[1],
2609 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002610
Sunny Goyal508da152014-08-14 10:53:27 -07002611 } else if (tag instanceof AppInfo) {
2612 shortcut = null;
2613 intent = ((AppInfo) tag).intent;
2614 } else {
2615 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2616 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002617
2618 boolean success = startActivitySafely(v, intent, tag);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002619 mStats.recordLaunch(intent, shortcut);
2620
2621 if (success && v instanceof BubbleTextView) {
2622 mWaitingForResume = (BubbleTextView) v;
2623 mWaitingForResume.setStayPressed(true);
2624 }
2625 }
2626
2627 /**
2628 * Event handler for a folder icon click.
2629 *
2630 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2631 */
2632 protected void onClickFolderIcon(View v) {
2633 if (LOGD) Log.d(TAG, "onClickFolder");
2634 if (!(v instanceof FolderIcon)){
2635 throw new IllegalArgumentException("Input must be a FolderIcon");
2636 }
2637
2638 FolderIcon folderIcon = (FolderIcon) v;
2639 final FolderInfo info = folderIcon.getFolderInfo();
2640 Folder openFolder = mWorkspace.getFolderForTag(info);
2641
2642 // If the folder info reports that the associated folder is open, then verify that
2643 // it is actually opened. There have been a few instances where this gets out of sync.
2644 if (info.opened && openFolder == null) {
2645 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2646 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2647 info.opened = false;
2648 }
2649
2650 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2651 // Close any open folder
2652 closeFolder();
2653 // Open the requested folder
2654 openFolder(folderIcon);
2655 } else {
2656 // Find the open folder...
2657 int folderScreen;
2658 if (openFolder != null) {
2659 folderScreen = mWorkspace.getPageForView(openFolder);
2660 // .. and close it
2661 closeFolder(openFolder);
2662 if (folderScreen != mWorkspace.getCurrentPage()) {
2663 // Close any folder open on the current screen
2664 closeFolder();
2665 // Pull the folder onto this screen
2666 openFolder(folderIcon);
2667 }
2668 }
2669 }
Michael Jurka5130e402011-10-13 04:55:35 -07002670 }
2671
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002672 /**
2673 * Event handler for the (Add) Widgets button that appears after a long press
2674 * on the home screen.
2675 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002676 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002677 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002678 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2679 }
2680
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002681 /**
2682 * Event handler for the wallpaper picker button that appears after a long press
2683 * on the home screen.
2684 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002685 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002686 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2687 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2688 pickWallpaper.setComponent(getWallpaperPickerComponent());
2689 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2690 }
2691
2692 /**
2693 * Event handler for a click on the settings button that appears after a long press
2694 * on the home screen.
2695 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002696 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002697 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2698 }
2699
Michael Jurka5130e402011-10-13 04:55:35 -07002700 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002701 // Provide the same haptic feedback that the system offers for virtual keys.
2702 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002703 }
2704
Adam Cohen61f560d2013-09-30 15:58:20 -07002705 public void performHapticFeedbackOnTouchDown(View v) {
2706 // Provide the same haptic feedback that the system offers for virtual keys.
2707 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2708 }
2709
2710 public View.OnTouchListener getHapticFeedbackTouchListener() {
2711 if (mHapticFeedbackTouchListener == null) {
2712 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2713 @Override
2714 public boolean onTouch(View v, MotionEvent event) {
2715 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2716 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2717 }
2718 return false;
2719 }
2720 };
2721 }
2722 return mHapticFeedbackTouchListener;
2723 }
2724
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002725 public void onDragStarted(View view) {}
2726
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002727 /**
2728 * Called when the user stops interacting with the launcher.
2729 * This implies that the user is now on the homescreen and is not doing housekeeping.
2730 */
2731 protected void onInteractionEnd() {}
2732
2733 /**
2734 * Called when the user starts interacting with the launcher.
2735 * The possible interactions are:
2736 * - open all apps
2737 * - reorder an app shortcut, or a widget
2738 * - open the overview mode.
2739 * This is a good time to stop doing things that only make sense
2740 * when the user is on the homescreen and not doing housekeeping.
2741 */
2742 protected void onInteractionBegin() {}
2743
Kenny Guyf07af7b2014-07-31 11:39:16 +01002744 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002745 String packageName = componentName.getPackageName();
Kenny Guyf07af7b2014-07-31 11:39:16 +01002746 try {
2747 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2748 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2749 launcherApps.showAppDetailsForProfile(componentName, user);
2750 } catch (SecurityException e) {
2751 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2752 Log.e(TAG, "Launcher does not have permission to launch settings");
2753 } catch (ActivityNotFoundException e) {
2754 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2755 Log.e(TAG, "Unable to launch settings");
2756 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002757 }
2758
Michael Jurka1e2f4652013-07-08 18:03:46 -07002759 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002760 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2761 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002762 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002763 // System applications cannot be installed. For now, show a toast explaining that.
2764 // We may give them the option of disabling apps this way.
2765 int messageId = R.string.uninstall_system_app_text;
2766 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002767 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002768 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002769 String packageName = componentName.getPackageName();
2770 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002771 Intent intent = new Intent(
2772 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002773 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2774 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002775 if (user != null) {
2776 user.addToIntent(intent, Intent.EXTRA_USER);
2777 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002778 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002779 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002780 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002781 }
2782
Michael Jurka86a720e2012-05-09 11:23:23 -07002783 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002784 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002785 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002786 // Only launch using the new animation if the shortcut has not opted out (this is a
2787 // private contract between launcher and may be ignored in the future).
2788 boolean useLaunchAnimation = (v != null) &&
2789 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002790 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2791 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002792
Kenny Guy1317e2d2014-05-08 18:52:50 +01002793 UserHandleCompat user = null;
2794 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2795 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2796 user = userManager.getUserForSerialNumber(serialNumber);
2797 }
2798
2799 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002800 if (useLaunchAnimation) {
Adam Cohen4da294d2014-07-28 10:56:19 -07002801 ActivityOptions opts = Utilities.isLmp() ?
2802 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) :
2803 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Adam Cohen6ea3b112014-06-11 11:38:49 -07002804 optsBundle = opts.toBundle();
2805 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002806
2807 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2808 // Could be launching some bookkeeping activity
2809 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002810 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002811 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002812 launcherApps.startActivityForProfile(intent.getComponent(), user,
2813 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002814 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002815 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002816 } catch (SecurityException e) {
2817 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002818 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002819 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002820 "or use the exported attribute for this activity. "
2821 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002822 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002823 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002824 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002825
Michael Jurka86a720e2012-05-09 11:23:23 -07002826 boolean startActivitySafely(View v, Intent intent, Object tag) {
2827 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002828 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2829 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2830 return false;
2831 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002832 try {
2833 success = startActivity(v, intent, tag);
2834 } catch (ActivityNotFoundException e) {
2835 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2836 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2837 }
2838 return success;
2839 }
2840
Adam Cohen268c4752012-06-06 17:47:33 -07002841 /**
2842 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2843 * in the DragLayer in the exact absolute location of the original FolderIcon.
2844 */
2845 private void copyFolderIconToImage(FolderIcon fi) {
2846 final int width = fi.getMeasuredWidth();
2847 final int height = fi.getMeasuredHeight();
2848
2849 // Lazy load ImageView, Bitmap and Canvas
2850 if (mFolderIconImageView == null) {
2851 mFolderIconImageView = new ImageView(this);
2852 }
2853 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2854 mFolderIconBitmap.getHeight() != height) {
2855 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2856 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2857 }
2858
2859 DragLayer.LayoutParams lp;
2860 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2861 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2862 } else {
2863 lp = new DragLayer.LayoutParams(width, height);
2864 }
2865
Adam Cohen307fe232012-08-16 17:55:58 -07002866 // The layout from which the folder is being opened may be scaled, adjust the starting
2867 // view size by this scale factor.
2868 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002869 lp.customPosition = true;
2870 lp.x = mRectForFolderAnimation.left;
2871 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002872 lp.width = (int) (scale * width);
2873 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002874
2875 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2876 fi.draw(mFolderIconCanvas);
2877 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002878 if (fi.getFolder() != null) {
2879 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2880 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002881 }
Adam Cohen268c4752012-06-06 17:47:33 -07002882 // Just in case this image view is still in the drag layer from a previous animation,
2883 // we remove it and re-add it.
2884 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2885 mDragLayer.removeView(mFolderIconImageView);
2886 }
2887 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002888 if (fi.getFolder() != null) {
2889 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002890 }
Adam Cohen268c4752012-06-06 17:47:33 -07002891 }
2892
Adam Cohen2801caf2011-05-13 20:57:39 -07002893 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002894 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002895 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2896 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2897 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2898
Adam Cohenc51934b2011-07-26 21:07:43 -07002899 FolderInfo info = (FolderInfo) fi.getTag();
2900 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2901 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002902 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2903 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002904 }
2905
Adam Cohen268c4752012-06-06 17:47:33 -07002906 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2907 copyFolderIconToImage(fi);
2908 fi.setVisibility(View.INVISIBLE);
2909
Michael Jurka2ecf9952012-06-18 12:52:28 -07002910 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002911 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002912 if (Utilities.isLmp()) {
2913 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
2914 }
2915 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07002916 oa.start();
2917 }
2918
Adam Cohen268c4752012-06-06 17:47:33 -07002919 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002920 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002921 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2922 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2923 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2924
Adam Cohen268c4752012-06-06 17:47:33 -07002925 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002926
Adam Cohen268c4752012-06-06 17:47:33 -07002927 // We remove and re-draw the FolderIcon in-case it has changed
2928 mDragLayer.removeView(mFolderIconImageView);
2929 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002930 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002931 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002932 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002933 oa.addListener(new AnimatorListenerAdapter() {
2934 @Override
2935 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002936 if (cl != null) {
2937 cl.clearFolderLeaveBehind();
2938 // Remove the ImageView copy of the FolderIcon and make the original visible.
2939 mDragLayer.removeView(mFolderIconImageView);
2940 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002941 }
2942 }
2943 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002944 oa.start();
2945 }
2946
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002947 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002948 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002949 * is animated relative to the specified View. If the View is null, no animation
2950 * is played.
2951 *
2952 * @param folderInfo The FolderInfo describing the folder to open.
2953 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002954 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002955 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002956 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002957
Adam Cohena9cf38f2011-05-02 15:36:58 -07002958 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002959
Adam Cohen4554ee12011-08-03 16:13:21 -07002960 // Just verify that the folder hasn't already been added to the DragLayer.
2961 // There was a one-off crash where the folder had a parent already.
2962 if (folder.getParent() == null) {
2963 mDragLayer.addView(folder);
2964 mDragController.addDropTarget((DropTarget) folder);
2965 } else {
2966 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2967 folder.getParent() + ").");
2968 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002969 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002970 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002971
2972 // Notify the accessibility manager that this folder "window" has appeared and occluded
2973 // the workspace items
2974 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2975 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002976 }
2977
2978 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002979 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002980 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002981 if (folder.isEditingName()) {
2982 folder.dismissEditingName();
2983 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002984 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002985
2986 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08002987 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002988 }
2989 }
2990
2991 void closeFolder(Folder folder) {
2992 folder.getInfo().opened = false;
2993
2994 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2995 if (parent != null) {
2996 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2997 shrinkAndFadeInFolderIcon(fi);
2998 }
2999 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003000
3001 // Notify the accessibility manager that this folder "window" has disappeard and no
3002 // longer occludeds the workspace items
3003 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003004 }
3005
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003006 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003007 if (!isDraggingEnabled()) return false;
3008 if (isWorkspaceLocked()) return false;
3009 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003010
Adam Cohen1697b792013-09-17 19:08:21 -07003011 if (v instanceof Workspace) {
3012 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07003013 if (mWorkspace.enterOverviewMode()) {
3014 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3015 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3016 return true;
3017 } else {
3018 return false;
3019 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003020 } else {
3021 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003022 }
Adam Cohen1697b792013-09-17 19:08:21 -07003023 }
3024
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003025 CellLayout.CellInfo longClickCellInfo = null;
3026 View itemUnderLongClick = null;
3027 if (v.getTag() instanceof ItemInfo) {
3028 ItemInfo info = (ItemInfo) v.getTag();
3029 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3030 itemUnderLongClick = longClickCellInfo.cell;
3031 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003032 }
3033
Winson Chung3d503fb2011-07-13 17:25:49 -07003034 // The hotseat touch handling does not go through Workspace, and we always allow long press
3035 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003036 final boolean inHotseat = isHotseatLayout(v);
3037 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07003038 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003039 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003040 // User long pressed on empty space
3041 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3042 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003043 if (mWorkspace.isInOverviewMode()) {
3044 mWorkspace.startReordering(v);
3045 } else {
3046 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07003047 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003048 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003049 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3050 mHotseat.getOrderInHotseat(
3051 longClickCellInfo.cellX,
3052 longClickCellInfo.cellY));
3053 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003054 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003055 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003056 }
3057 }
3058 }
3059 return true;
3060 }
3061
Winson Chung3d503fb2011-07-13 17:25:49 -07003062 boolean isHotseatLayout(View layout) {
3063 return mHotseat != null && layout != null &&
3064 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3065 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003066
Winson Chung3d503fb2011-07-13 17:25:49 -07003067 /**
3068 * Returns the CellLayout of the specified container at the specified screen.
3069 */
Adam Cohendcd297f2013-06-18 13:13:40 -07003070 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003071 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3072 if (mHotseat != null) {
3073 return mHotseat.getLayout();
3074 } else {
3075 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003076 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003077 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07003078 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003079 }
3080 }
3081
Daniel Sandler843e8602010-06-07 14:59:01 -04003082 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003083 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003084 }
3085
Craig Mautner360310b2012-10-26 15:13:08 -07003086 private void setWorkspaceBackground(boolean workspace) {
3087 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003088 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003089 }
3090
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003091 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003092 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3093 int curflags = getWindow().getAttributes().flags
3094 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3095 if (wpflags != curflags) {
3096 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3097 }
Craig Mautner360310b2012-10-26 15:13:08 -07003098 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003099 }
3100
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003101 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3102 if (v instanceof LauncherTransitionable) {
3103 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3104 }
3105 }
3106
Michael Jurkabed61d22012-02-14 22:51:29 -08003107 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3108 if (v instanceof LauncherTransitionable) {
3109 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3110 }
Winson Chung70442722012-02-10 15:43:22 -08003111
3112 // Update the workspace transition step as well
3113 dispatchOnLauncherTransitionStep(v, 0f);
3114 }
3115
3116 private void dispatchOnLauncherTransitionStep(View v, float t) {
3117 if (v instanceof LauncherTransitionable) {
3118 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3119 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003120 }
3121
3122 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3123 if (v instanceof LauncherTransitionable) {
3124 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3125 }
Winson Chung70442722012-02-10 15:43:22 -08003126
3127 // Update the workspace transition step as well
3128 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003129 }
3130
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003131 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003132 * Things to test when changing the following seven functions.
3133 * - Home from workspace
3134 * - from center screen
3135 * - from other screens
3136 * - Home from all apps
3137 * - from center screen
3138 * - from other screens
3139 * - Back from all apps
3140 * - from center screen
3141 * - from other screens
3142 * - Launch app from workspace and quit
3143 * - with back
3144 * - with home
3145 * - Launch app from all apps and quit
3146 * - with back
3147 * - with home
3148 * - Go to a screen that's not the default, then all
3149 * apps, and launch and app, and go back
3150 * - with back
3151 * -with home
3152 * - On workspace, long press power and go back
3153 * - with back
3154 * - with home
3155 * - On all apps, long press power and go back
3156 * - with back
3157 * - with home
3158 * - On workspace, power off
3159 * - On all apps, power off
3160 * - Launch an app and turn off the screen while in that app
3161 * - Go back with home key
3162 * - Go back with back key TODO: make this not go to workspace
3163 * - From all apps
3164 * - From workspace
3165 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3166 * - From all apps
3167 * - From the center workspace
3168 * - From another workspace
3169 */
3170
3171 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003172 * Zoom the camera out from the workspace to reveal 'toView'.
3173 * Assumes that the view to show is anchored at either the very top or very bottom
3174 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003175 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003176 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003177 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3178 showAppsCustomizeHelper(animated, springLoaded, contentType);
3179 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003180
Winson Chungc58497e2013-09-03 17:48:37 -07003181 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3182 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003183 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003184 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003185 mStateAnimation.cancel();
3186 mStateAnimation = null;
3187 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003188
3189 boolean material = Utilities.isLmp();
3190
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003191 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003192
Winson Chungf0ea4d32011-06-06 14:27:16 -07003193 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3194 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003195 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003196 final int itemsAlphaStagger =
3197 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003198
Winson Chungf0ea4d32011-06-06 14:27:16 -07003199 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003200 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003201 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07003202
Adam Cohen6c5891a2014-07-09 23:53:15 -07003203 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3204 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003205 Animator workspaceAnim =
Adam Cohen6c5891a2014-07-09 23:53:15 -07003206 mWorkspace.getChangeStateAnimation(workspaceState, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003207 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003208 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3209 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003210 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3211 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003212
3213 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003214 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen61033d32010-11-15 18:29:44 -08003215
Adam Cohen9bfdb762014-07-21 17:44:06 -07003216 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3217 toView.findViewById(R.id.apps_customize_pane_content);
Adam Cohenf16e5712011-01-13 13:31:45 -08003218
Adam Cohen9bfdb762014-07-21 17:44:06 -07003219 final View page = content.getPageAt(content.getCurrentPage());
3220 final View revealView = toView.findViewById(R.id.fake_page);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003221
Adam Cohen63f1ec02014-08-12 09:23:13 -07003222 final float initialPanelAlpha = 1f;
3223
3224 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3225 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003226 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3227 } else {
3228 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3229 }
3230
Adam Cohen9bfdb762014-07-21 17:44:06 -07003231 // Hide the real page background, and swap in the fake one
3232 revealView.setVisibility(View.VISIBLE);
3233 content.setPageBackgroundsVisible(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003234
Adam Cohen9bfdb762014-07-21 17:44:06 -07003235 int width = revealView.getMeasuredWidth();
3236 int height = revealView.getMeasuredHeight();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003237
Adam Cohen9bfdb762014-07-21 17:44:06 -07003238 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003239 revealView.setTranslationY(0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003240
Adam Cohen63f1ec02014-08-12 09:23:13 -07003241 // Get the y delta between the center of the page and the center of the all apps button
3242 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3243 getAllAppsButton(), null);
3244 float yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3245
3246 float initAlpha = isWidgetTray ? 0.3f : 1f;
Adam Cohen9bfdb762014-07-21 17:44:06 -07003247 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003248 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003249 PropertyValuesHolder panelDrift =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003250 PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003251
Adam Cohen9bfdb762014-07-21 17:44:06 -07003252 ObjectAnimator panelAlphaAndDrift =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003253 LauncherAnimUtils.ofPropertyValuesHolder(revealView, panelAlpha, panelDrift);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003254 panelAlphaAndDrift.setDuration(revealDuration);
3255 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003256
Adam Cohen9bfdb762014-07-21 17:44:06 -07003257 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003258
Adam Cohen4e243a22014-08-10 18:30:55 -07003259 if (page != null) {
3260 page.setVisibility(View.VISIBLE);
3261 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003262
Adam Cohen63f1ec02014-08-12 09:23:13 -07003263 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", yDrift, 0);
Adam Cohen4e243a22014-08-10 18:30:55 -07003264 pageDrift.setDuration(revealDuration);
3265 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003266 pageDrift.setStartDelay(itemsAlphaStagger);
Adam Cohen4e243a22014-08-10 18:30:55 -07003267 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003268
Adam Cohen63f1ec02014-08-12 09:23:13 -07003269 page.setAlpha(0f);
3270 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 0f, 1f);
Adam Cohen4e243a22014-08-10 18:30:55 -07003271 itemsAlpha.setDuration(revealDuration);
3272 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3273 itemsAlpha.setStartDelay(itemsAlphaStagger);
3274 mStateAnimation.play(itemsAlpha);
3275 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003276
Adam Cohen4e243a22014-08-10 18:30:55 -07003277 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3278 pageIndicators.setAlpha(0.01f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003279 ObjectAnimator indicatorsAlpha =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003280 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003281 indicatorsAlpha.setDuration(revealDuration);
3282 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003283
Adam Cohen9bfdb762014-07-21 17:44:06 -07003284 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003285 final View allApps = getAllAppsButton();
3286 int allAppsButtonSize = LauncherAppState.getInstance().
3287 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3288 float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003289 Animator reveal = LauncherAnimUtils.createCircularReveal(revealView, width / 2,
Adam Cohen63f1ec02014-08-12 09:23:13 -07003290 height / 2, startRadius, revealRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003291 reveal.setDuration(revealDuration);
3292 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003293
3294 reveal.addListener(new AnimatorListenerAdapter() {
3295 public void onAnimationStart(Animator animation) {
3296 if (!isWidgetTray) {
3297 allApps.setVisibility(View.INVISIBLE);
3298 }
3299 }
3300 public void onAnimationEnd(Animator animation) {
3301 if (!isWidgetTray) {
3302 allApps.setVisibility(View.VISIBLE);
3303 }
3304 }
3305 });
3306
Adam Cohen6c5891a2014-07-09 23:53:15 -07003307 mStateAnimation.play(reveal);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003308 }
Michael Jurka1899a362011-11-03 13:50:45 -07003309
Adam Cohen9bfdb762014-07-21 17:44:06 -07003310 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3311 @Override
3312 public void onAnimationEnd(Animator animation) {
3313 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3314 dispatchOnLauncherTransitionEnd(toView, animated, false);
3315
3316 revealView.setVisibility(View.INVISIBLE);
3317 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003318 if (page != null) {
3319 page.setLayerType(View.LAYER_TYPE_NONE, null);
3320 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003321 content.setPageBackgroundsVisible(true);
3322
3323 // Hide the search bar
3324 if (mSearchDropTargetBar != null) {
3325 mSearchDropTargetBar.hideSearchBar(false);
3326 }
3327 }
3328
3329 @Override
3330 public void onAnimationStart(Animator animation) {
3331 // Prepare the position
3332 toView.bringToFront();
3333 toView.setVisibility(View.VISIBLE);
3334 }
3335 });
3336
Michael Jurka1899a362011-11-03 13:50:45 -07003337 boolean delayAnim = false;
Adam Cohen6c5891a2014-07-09 23:53:15 -07003338 if (workspaceAnim != null) {
3339 mStateAnimation.play(workspaceAnim);
3340 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003341 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3342 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003343
3344 // If any of the objects being animated haven't been measured/laid out
3345 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003346 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003347 (mWorkspace.getMeasuredWidth() == 0) ||
3348 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003349 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003350 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003351
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003352 final AnimatorSet stateAnimation = mStateAnimation;
3353 final Runnable startAnimRunnable = new Runnable() {
3354 public void run() {
3355 // Check that mStateAnimation hasn't changed while
3356 // we waited for a layout/draw pass
3357 if (mStateAnimation != stateAnimation)
3358 return;
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003359 dispatchOnLauncherTransitionStart(fromView, animated, false);
3360 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003361 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003362 }
3363 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003364 if (delayAnim) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003365 toView.bringToFront();
3366 toView.setVisibility(View.VISIBLE);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003367 final ViewTreeObserver observer = toView.getViewTreeObserver();
3368 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3369 public void onGlobalLayout() {
3370 startAnimRunnable.run();
3371 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3372 }
3373 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003374 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003375 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003376 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003377 } else {
3378 toView.setTranslationX(0.0f);
3379 toView.setTranslationY(0.0f);
3380 toView.setScaleX(1.0f);
3381 toView.setScaleY(1.0f);
3382 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003383 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003384
Daniel Sandlere4f98912013-06-25 15:13:26 -04003385 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003386 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003387 if (mSearchDropTargetBar != null) {
3388 mSearchDropTargetBar.hideSearchBar(false);
3389 }
Michael Jurkaabded662011-03-04 12:06:57 -08003390 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003391 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003392 dispatchOnLauncherTransitionStart(fromView, animated, false);
3393 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003394 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003395 dispatchOnLauncherTransitionStart(toView, animated, false);
3396 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003397 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003398 }
3399
3400 /**
3401 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003402 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003403 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003404 */
Adam Cohened307df2013-10-02 09:37:31 -07003405 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003406 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003407
Michael Jurkab3e22d92011-10-31 15:58:33 -07003408 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003409 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003410 mStateAnimation.cancel();
3411 mStateAnimation = null;
3412 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003413
3414 boolean material = Utilities.isLmp();
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003415 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003416
Winson Chungf0ea4d32011-06-06 14:27:16 -07003417 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003418 final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003419 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003420 final int itemsAlphaStagger =
3421 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003422
Winson Chungf0ea4d32011-06-06 14:27:16 -07003423 final float scaleFactor = (float)
3424 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3425 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003426 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003427 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003428 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003429 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohen63f1ec02014-08-12 09:23:13 -07003430 toState, animated);
Adam Cohened307df2013-10-02 09:37:31 -07003431 } else if (toState == Workspace.State.SPRING_LOADED ||
3432 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003433 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003434 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003435 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003436
Winson Chung4afe9b32011-07-27 17:46:20 -07003437 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003438 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003439 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka159b4cc2012-01-17 03:00:35 -08003440
Adam Cohen9bfdb762014-07-21 17:44:06 -07003441 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3442 fromView.findViewById(R.id.apps_customize_pane_content);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003443
Adam Cohen9bfdb762014-07-21 17:44:06 -07003444 final View page = content.getPageAt(content.getNextPage());
3445 final View revealView = fromView.findViewById(R.id.fake_page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003446
Adam Cohen4e243a22014-08-10 18:30:55 -07003447 AppsCustomizePagedView.ContentType contentType = content.getContentType();
Adam Cohen63f1ec02014-08-12 09:23:13 -07003448 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3449
3450 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003451 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3452 } else {
3453 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3454 }
3455
Adam Cohen9bfdb762014-07-21 17:44:06 -07003456 int width = revealView.getMeasuredWidth();
3457 int height = revealView.getMeasuredHeight();
3458 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003459
Adam Cohen9bfdb762014-07-21 17:44:06 -07003460 // Hide the real page background, and swap in the fake one
3461 revealView.setVisibility(View.VISIBLE);
3462 content.setPageBackgroundsVisible(false);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003463
Adam Cohen63f1ec02014-08-12 09:23:13 -07003464 final View allAppsButton = getAllAppsButton();
3465 revealView.setTranslationY(0);
3466 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3467 allAppsButton, null);
3468 float yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
Adam Cohen6c5891a2014-07-09 23:53:15 -07003469
Adam Cohen9bfdb762014-07-21 17:44:06 -07003470 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003471
Adam Cohen63f1ec02014-08-12 09:23:13 -07003472 // The vertical motion of the apps panel should be delayed by one frame
3473 // from the conceal animation in order to give the right feel. We correpsondingly
3474 // shorten the duration so that the slide and conceal end at the same time.
3475 ObjectAnimator panelDrift = LauncherAnimUtils.ofFloat(revealView, "translationY", 0, yDrift);
3476 panelDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3477 panelDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3478 panelDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3479 mStateAnimation.play(panelDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003480
Adam Cohen63f1ec02014-08-12 09:23:13 -07003481 if (isWidgetTray) {
3482 ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", 1f, 0.4f);
3483 panelAlpha.setDuration(revealDuration);
3484 panelAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0));
3485 mStateAnimation.play(panelAlpha);
3486 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003487
Adam Cohen4e243a22014-08-10 18:30:55 -07003488 if (page != null) {
3489 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003490
Adam Cohen63f1ec02014-08-12 09:23:13 -07003491 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
3492 0, yDrift);
3493 pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
Adam Cohen4e243a22014-08-10 18:30:55 -07003494 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003495 pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
Adam Cohen4e243a22014-08-10 18:30:55 -07003496 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003497
Adam Cohen4e243a22014-08-10 18:30:55 -07003498 page.setAlpha(1f);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003499 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
3500 itemsAlpha.setDuration(100);
Adam Cohen4e243a22014-08-10 18:30:55 -07003501 itemsAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0));
3502 mStateAnimation.play(itemsAlpha);
3503 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003504
Adam Cohen9bfdb762014-07-21 17:44:06 -07003505 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
Adam Cohen4e243a22014-08-10 18:30:55 -07003506 pageIndicators.setAlpha(1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003507 ObjectAnimator indicatorsAlpha =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003508 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003509 indicatorsAlpha.setDuration(revealDuration);
3510 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3511 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003512
Adam Cohen9bfdb762014-07-21 17:44:06 -07003513 width = revealView.getMeasuredWidth();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003514
Adam Cohen9bfdb762014-07-21 17:44:06 -07003515 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003516 if (!isWidgetTray) {
3517 allAppsButton.setVisibility(View.INVISIBLE);
3518 }
3519 int allAppsButtonSize = LauncherAppState.getInstance().
3520 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3521 float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Nilesh Agrawal300c1502014-07-22 13:20:54 -07003522 Animator reveal =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003523 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3524 height / 2, revealRadius, finalRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003525 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3526 reveal.setDuration(revealDuration);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003527 reveal.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003528
3529 reveal.addListener(new AnimatorListenerAdapter() {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003530 public void onAnimationEnd(Animator animation) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003531 revealView.setVisibility(View.INVISIBLE);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003532 if (!isWidgetTray) {
3533 allAppsButton.setVisibility(View.VISIBLE);
3534 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003535 }
3536 });
3537
Adam Cohen6c5891a2014-07-09 23:53:15 -07003538 mStateAnimation.play(reveal);
3539 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003540
3541 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3542 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3543 mAppsCustomizeContent.stopScrolling();
3544
Adam Cohen6c5891a2014-07-09 23:53:15 -07003545 if (workspaceAnim != null) {
3546 mStateAnimation.play(workspaceAnim);
3547 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003548
3549 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003550 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003551 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003552 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003553 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3554 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003555 if (onCompleteRunnable != null) {
3556 onCompleteRunnable.run();
3557 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003558
3559 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003560 if (page != null) {
3561 page.setLayerType(View.LAYER_TYPE_NONE, null);
3562 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003563 content.setPageBackgroundsVisible(true);
Chet Haasebc2f0822012-10-26 17:59:53 -07003564 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003565 }
3566 });
3567
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003568 dispatchOnLauncherTransitionStart(fromView, animated, true);
3569 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003570 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003571 } else {
3572 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003573 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003574 dispatchOnLauncherTransitionStart(fromView, animated, true);
3575 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003576 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003577 dispatchOnLauncherTransitionStart(toView, animated, true);
3578 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003579 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003580 }
3581
Michael Jurkae326f182011-11-21 14:05:46 -08003582 @Override
3583 public void onTrimMemory(int level) {
3584 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003585 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003586 mAppsCustomizeTabHost.onTrimMemory();
3587 }
3588 }
3589
Adam Cohened307df2013-10-02 09:37:31 -07003590 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003591 showWorkspace(animated, null);
3592 }
3593
Adam Cohened307df2013-10-02 09:37:31 -07003594 protected void showWorkspace() {
3595 showWorkspace(true);
3596 }
3597
Adam Cohened66b2b2012-01-23 17:28:51 -08003598 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohene25c5d12014-06-18 10:34:58 -07003599 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
Winson Chung2d75f122013-09-23 16:53:31 -07003600 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003601 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003602 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003603
Winson Chungc7d2b602012-05-16 17:02:20 -07003604 // Show the search bar (only animate if we were showing the drop target bar in spring
3605 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003606 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003607 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003608 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003609
Michael Jurkab3e22d92011-10-31 15:58:33 -07003610 // Set focus to the AppsCustomize button
3611 if (mAllAppsButton != null) {
3612 mAllAppsButton.requestFocus();
3613 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003614 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003615
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003616 // Change the state *after* we've called all the transition code
3617 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003618
Winson Chung5fb63472011-02-02 17:03:37 -08003619 // Resume the auto-advance of widgets
3620 mUserPresent = true;
3621 updateRunning();
3622
alanv1d4fde62012-10-17 13:15:47 -07003623 // Send an accessibility event to announce the context change
3624 getWindow().getDecorView()
3625 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003626
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003627 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003628 }
3629
Adam Cohened307df2013-10-02 09:37:31 -07003630 void showOverviewMode(boolean animated) {
3631 mWorkspace.setVisibility(View.VISIBLE);
3632 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3633 mState = State.WORKSPACE;
3634 onWorkspaceShown(animated);
3635 }
3636
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003637 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003638 }
3639
Winson Chung82963d52013-10-09 11:20:57 -07003640 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3641 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003642 if (mState != State.WORKSPACE) return;
3643
Winson Chung82963d52013-10-09 11:20:57 -07003644 if (resetPageToZero) {
3645 mAppsCustomizeTabHost.reset();
3646 }
Winson Chungc58497e2013-09-03 17:48:37 -07003647 showAppsCustomizeHelper(animated, false, contentType);
Adam Cohendcc5e712014-06-23 15:38:55 -04003648 mAppsCustomizeTabHost.post(new Runnable() {
3649 @Override
3650 public void run() {
3651 // We post this in-case the all apps view isn't yet constructed.
3652 mAppsCustomizeTabHost.requestFocus();
3653 }
3654 });
Michael Jurkab3e22d92011-10-31 15:58:33 -07003655
Michael Jurkab3e22d92011-10-31 15:58:33 -07003656 // Change the state *after* we've called all the transition code
3657 mState = State.APPS_CUSTOMIZE;
3658
3659 // Pause the auto-advance of widgets until we are out of AllApps
3660 mUserPresent = false;
3661 updateRunning();
3662 closeFolder();
3663
3664 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003665 getWindow().getDecorView()
3666 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003667 }
3668
Adam Cohen7777d962011-08-18 18:58:38 -07003669 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003670 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003671 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003672 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003673 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003674 }
Adam Cohen7777d962011-08-18 18:58:38 -07003675
Adam Cohenad4e15c2013-10-17 16:21:35 -07003676 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003677 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003678 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3679
Winson Chunge7a03942011-08-05 15:05:12 -07003680 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003681 @Override
3682 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003683 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003684 // Before we show workspace, hide all apps again because
3685 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3686 // clean up our state transition functions
3687 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003688 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003689 } else {
3690 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003691 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003692 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003693 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003694 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003695
Michael Jurkad3ef3062010-11-23 16:23:58 -08003696 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003697 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003698 final boolean animated = true;
3699 final boolean springLoaded = true;
3700 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003701 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003702 }
3703 // Otherwise, we are not in spring loaded mode, so don't do anything.
3704 }
3705
Michael Jurkab3e22d92011-10-31 15:58:33 -07003706 void lockAllApps() {
3707 // TODO
3708 }
3709
3710 void unlockAllApps() {
3711 // TODO
3712 }
3713
Winson Chungf0ea4d32011-06-06 14:27:16 -07003714 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003715 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003716 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003717 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003718 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003719 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003720 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003721 int duration = 0;
3722 if (mSearchDropTargetBar != null) {
3723 duration = mSearchDropTargetBar.getTransitionInDuration();
3724 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003725 mHotseat.animate().alpha(1f).setDuration(duration);
3726 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003727 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003728 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003729 }
3730 }
3731 }
3732
3733 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003734 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003735 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003736 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003737 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003738 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003739 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003740 int duration = 0;
3741 if (mSearchDropTargetBar != null) {
3742 duration = mSearchDropTargetBar.getTransitionOutDuration();
3743 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003744 mHotseat.animate().alpha(0f).setDuration(duration);
3745 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003746 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003747 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003748 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003749 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003750 }
3751
Patrick Dubroy5f445422011-02-18 14:35:21 -08003752 /**
3753 * Add an item from all apps or customize onto the given workspace screen.
3754 * If layout is null, add to the current screen.
3755 */
3756 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003757 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003758 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003759 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003760 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003761
Winson Chungdff8ebb2011-09-08 17:25:31 -07003762 /** Maps the current orientation to an index for referencing orientation correct global icons */
3763 private int getCurrentOrientationIndexForGlobalIcons() {
3764 // default - 0, landscape - 1
3765 switch (getResources().getConfiguration().orientation) {
3766 case Configuration.ORIENTATION_LANDSCAPE:
3767 return 1;
3768 default:
3769 return 0;
3770 }
3771 }
3772
Michael Jurkaae65ee32012-04-30 11:45:54 -07003773 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003774 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003775 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003776 // Look for the toolbar icon specified in the activity meta-data
3777 Bundle metaData = packageManager.getActivityInfo(
3778 activityName, PackageManager.GET_META_DATA).metaData;
3779 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003780 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003781 if (iconResId != 0) {
3782 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003783 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003784 }
3785 }
3786 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003787 // This can happen if the activity defines an invalid drawable
3788 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3789 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003790 } catch (Resources.NotFoundException nfe) {
3791 // This can happen if the activity defines an invalid drawable
3792 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3793 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003794 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003795 return null;
3796 }
3797
3798 // if successful in getting icon, return it; otherwise, set button to use default drawable
3799 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003800 int buttonId, ComponentName activityName, int fallbackDrawableId,
3801 String toolbarResourceName) {
3802 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003803 Resources r = getResources();
3804 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3805 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003806
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003807 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003808 // If we were unable to find the icon via the meta-data, use a generic one
3809 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003810 toolbarIcon = r.getDrawable(fallbackDrawableId);
3811 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003812 if (button != null) {
3813 button.setCompoundDrawables(toolbarIcon, null, null, null);
3814 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003815 return null;
3816 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003817 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003818 if (button != null) {
3819 button.setCompoundDrawables(toolbarIcon, null, null, null);
3820 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003821 return toolbarIcon.getConstantState();
3822 }
3823 }
3824
3825 // if successful in getting icon, return it; otherwise, set button to use default drawable
3826 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003827 int buttonId, ComponentName activityName, int fallbackDrawableId,
3828 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003829 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003830 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003831
Michael Jurka19e0fc52011-07-22 18:00:21 -07003832 if (button != null) {
3833 // If we were unable to find the icon via the meta-data, use a
3834 // generic one
3835 if (toolbarIcon == null) {
3836 button.setImageResource(fallbackDrawableId);
3837 } else {
3838 button.setImageDrawable(toolbarIcon);
3839 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003840 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003841
3842 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3843
Michael Jurka0423dcf2010-10-05 14:56:18 -07003844 }
3845
Winson Chung1b884092012-06-08 17:13:02 -07003846 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003847 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003848 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003849 }
3850
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003851 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003852 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003853 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003854 }
3855
Winson Chungbb185bd2011-11-21 12:31:42 -08003856 private void invalidatePressedFocusedStates(View container, View button) {
3857 if (container instanceof HolographicLinearLayout) {
3858 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3859 layout.invalidatePressedFocusedStates();
3860 } else if (button instanceof HolographicImageView) {
3861 HolographicImageView view = (HolographicImageView) button;
3862 view.invalidatePressedFocusedStates();
3863 }
3864 }
3865
Cristina Stancu476493b2013-08-07 17:20:14 +01003866 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003867 if (mQsb == null) {
3868 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3869 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003870 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003871 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003872 }
3873
3874 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003875 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003876 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003877 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003878 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003879
Winson Chung1cad91e2011-05-25 17:41:01 -07003880 final SearchManager searchManager =
3881 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3882 ComponentName activityName = searchManager.getGlobalSearchActivity();
3883 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003884 int coi = getCurrentOrientationIndexForGlobalIcons();
3885 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003886 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3887 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3888 if (sGlobalSearchIcon[coi] == null) {
3889 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3890 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3891 TOOLBAR_ICON_METADATA_NAME);
3892 }
3893
Winson Chungc51db6a2011-10-05 11:44:49 -07003894 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3895 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003896 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003897 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003898 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003899 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003900 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3901 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003902 if (searchButton != null) searchButton.setVisibility(View.GONE);
3903 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003904 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003905 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003906 }
3907 }
3908
Cristina Stancu476493b2013-08-07 17:20:14 +01003909 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003910 final View searchButtonContainer = findViewById(R.id.search_button_container);
3911 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003912 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003913 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003914 }
3915
Cristina Stancu476493b2013-08-07 17:20:14 +01003916 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003917 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003918 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003919
Winson Chungc51db6a2011-10-05 11:44:49 -07003920 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003921 final SearchManager searchManager =
3922 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3923 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3924
3925 ComponentName activityName = null;
3926 if (globalSearchActivity != null) {
3927 // Check if the global search activity handles voice search
3928 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3929 intent.setPackage(globalSearchActivity.getPackageName());
3930 activityName = intent.resolveActivity(getPackageManager());
3931 }
3932
3933 if (activityName == null) {
3934 // Fallback: check if an activity other than the global search activity
3935 // resolves this
3936 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3937 activityName = intent.resolveActivity(getPackageManager());
3938 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003939 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003940 int coi = getCurrentOrientationIndexForGlobalIcons();
3941 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003942 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3943 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3944 if (sVoiceSearchIcon[coi] == null) {
3945 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3946 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3947 TOOLBAR_ICON_METADATA_NAME);
3948 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003949 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003950 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003951 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003952 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003953 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003954 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003955 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003956 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003957 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003958 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003959 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003960 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003961
Cristina Stancu476493b2013-08-07 17:20:14 +01003962 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003963 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3964 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003965 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003966 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003967 }
3968
Winson Chung5841efa2013-09-30 18:06:44 -07003969 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003970 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3971 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003972 boolean visible = !forceDisableVoiceButtonProxy &&
3973 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003974 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003975 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003976 }
3977 }
Winson Chung5841efa2013-09-30 18:06:44 -07003978
3979 /**
3980 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3981 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3982 */
3983 public void disableVoiceButtonProxy(boolean disabled) {
3984 updateVoiceButtonProxyVisible(disabled);
3985 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003986
Michael Jurkad7c28052012-04-27 15:43:36 -07003987 @Override
3988 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003989 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003990 final List<CharSequence> text = event.getText();
3991 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003992 // Populate event with a fake title based on the current state.
3993 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003994 text.add(mAppsCustomizeTabHost.getContentTag());
alanv1d4fde62012-10-17 13:15:47 -07003995 } else {
3996 text.add(getString(R.string.all_apps_home_button_label));
3997 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003998 return result;
3999 }
4000
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004001 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07004002 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004003 */
4004 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4005 @Override
4006 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004007 closeSystemDialogs();
4008 }
4009 }
4010
4011 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08004012 * Receives notifications whenever the appwidgets are reset.
4013 */
4014 private class AppWidgetResetObserver extends ContentObserver {
4015 public AppWidgetResetObserver() {
4016 super(new Handler());
4017 }
4018
4019 @Override
4020 public void onChange(boolean selfChange) {
4021 onAppWidgetReset();
4022 }
4023 }
4024
4025 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07004026 * If the activity is currently paused, signal that we need to run the passed Runnable
4027 * in onResume.
4028 *
4029 * This needs to be called from incoming places where resources might have been loaded
4030 * while we are paused. That is becaues the Configuration might be wrong
4031 * when we're not running, and if it comes back to what it was when we
4032 * were paused, we are not restarted.
4033 *
4034 * Implementation of the method from LauncherModel.Callbacks.
4035 *
4036 * @return true if we are currently paused. The caller might be able to
4037 * skip some work in that case since we will come back again.
4038 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004039 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004040 if (mPaused) {
4041 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02004042 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07004043 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004044 }
4045 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07004046 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07004047 return true;
4048 } else {
4049 return false;
4050 }
4051 }
4052
Michael Jurkac402cd92013-05-20 15:49:32 +02004053 private boolean waitUntilResume(Runnable run) {
4054 return waitUntilResume(run, false);
4055 }
4056
Michael Jurka1e2f4652013-07-08 18:03:46 -07004057 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02004058 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07004059 }
4060
Michael Jurka7607c2f2013-04-03 14:33:19 -07004061 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004062 * If the activity is currently paused, signal that we need to re-run the loader
4063 * in onResume.
4064 *
4065 * This needs to be called from incoming places where resources might have been loaded
4066 * while we are paused. That is becaues the Configuration might be wrong
4067 * when we're not running, and if it comes back to what it was when we
4068 * were paused, we are not restarted.
4069 *
4070 * Implementation of the method from LauncherModel.Callbacks.
4071 *
4072 * @return true if we are currently paused. The caller might be able to
4073 * skip some work in that case since we will come back again.
4074 */
4075 public boolean setLoadOnResume() {
4076 if (mPaused) {
4077 Log.i(TAG, "setLoadOnResume");
4078 mOnResumeNeedsLoad = true;
4079 return true;
4080 } else {
4081 return false;
4082 }
4083 }
4084
4085 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004086 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004087 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04004088 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07004089 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07004090 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07004091 } else {
4092 return SCREEN_COUNT / 2;
4093 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004094 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07004095
Joe Onorato9c1289c2009-08-17 11:03:03 -04004096 /**
4097 * Refreshes the shortcuts shown on the workspace.
4098 *
4099 * Implementation of the method from LauncherModel.Callbacks.
4100 */
4101 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004102 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08004103
Michael Jurka7607c2f2013-04-03 14:33:19 -07004104 // If we're starting binding all over again, clear any bind calls we'd postponed in
4105 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4106 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07004107 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07004108
Winson Chungd64d1762013-08-20 14:37:16 -07004109 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07004110 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07004111 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07004112
Michael Jurka05bf6442011-11-30 20:28:53 -08004113 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07004114 if (mHotseat != null) {
4115 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004116 }
4117 }
4118
Adam Cohendcd297f2013-06-18 13:13:40 -07004119 @Override
4120 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07004121 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07004122
Adam Cohen5084cba2013-09-03 12:01:16 -07004123 // If there are no screens, we need to have an empty screen
4124 if (orderedScreenIds.size() == 0) {
4125 mWorkspace.addExtraEmptyScreen();
4126 }
Winson Chung0e6a7132013-08-23 12:55:10 -07004127
4128 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06004129 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05004130 if (hasCustomContentToLeft()) {
4131 mWorkspace.createCustomContentContainer();
4132 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07004133 }
Winson Chung64359a52013-07-08 17:17:08 -07004134 }
4135
4136 @Override
4137 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08004138 // Log to disk
4139 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4140 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4141 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07004142 int count = orderedScreenIds.size();
4143 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07004144 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07004145 }
Adam Cohendcd297f2013-06-18 13:13:40 -07004146 }
4147
Adam Cohen39a06042013-07-19 14:30:12 -07004148 private boolean shouldShowWeightWatcher() {
4149 String spKey = LauncherAppState.getSharedPreferencesKey();
4150 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07004151 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07004152
4153 return show;
4154 }
4155
4156 private void toggleShowWeightWatcher() {
4157 String spKey = LauncherAppState.getSharedPreferencesKey();
4158 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4159 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4160
4161 show = !show;
4162
4163 SharedPreferences.Editor editor = sp.edit();
4164 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4165 editor.commit();
4166
4167 if (mWeightWatcher != null) {
4168 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4169 }
4170 }
4171
Winson Chungd64d1762013-08-20 14:37:16 -07004172 public void bindAppsAdded(final ArrayList<Long> newScreens,
4173 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07004174 final ArrayList<ItemInfo> addAnimated,
4175 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004176 Runnable r = new Runnable() {
4177 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07004178 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07004179 }
4180 };
4181 if (waitUntilResume(r)) {
4182 return;
4183 }
4184
Winson Chungd64d1762013-08-20 14:37:16 -07004185 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08004186 if (newScreens != null) {
4187 bindAddScreens(newScreens);
4188 }
Winson Chungd64d1762013-08-20 14:37:16 -07004189
4190 // We add the items without animation on non-visible pages, and with
4191 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08004192 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004193 bindItems(addNotAnimated, 0,
4194 addNotAnimated.size(), false);
4195 }
Adam Cohen76a47a12014-02-05 11:47:43 -08004196 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004197 bindItems(addAnimated, 0,
4198 addAnimated.size(), true);
4199 }
Winson Chungc58497e2013-09-03 17:48:37 -07004200
Winson Chung87412982013-10-03 18:34:14 -07004201 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004202 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004203
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004204 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004205 addedApps != null && mAppsCustomizeContent != null) {
4206 mAppsCustomizeContent.addApps(addedApps);
4207 }
Winson Chungd64d1762013-08-20 14:37:16 -07004208 }
4209
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004210 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004211 * Bind the items start-end from the list.
4212 *
4213 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004214 */
Winson Chung64359a52013-07-08 17:17:08 -07004215 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4216 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004217 Runnable r = new Runnable() {
4218 public void run() {
4219 bindItems(shortcuts, start, end, forceAnimateIcons);
4220 }
4221 };
4222 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004223 return;
4224 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004225
Winson Chungf0c6ae02012-03-21 16:10:31 -07004226 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004227 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4228 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004229 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004230 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004231 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004232 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004233 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004234
4235 // Short circuit if we are loading dock items for a configuration which has no dock
4236 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4237 mHotseat == null) {
4238 continue;
4239 }
4240
Joe Onorato9c1289c2009-08-17 11:03:03 -04004241 switch (item.itemType) {
4242 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4243 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004244 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004245 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004246
Winson Chung64359a52013-07-08 17:17:08 -07004247 /*
4248 * TODO: FIX collision case
4249 */
Winson Chungce376632013-07-11 16:12:41 -07004250 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4251 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4252 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004253 View v = cl.getChildAt(item.cellX, item.cellY);
4254 Object tag = v.getTag();
4255 String desc = "Collision while binding workspace item: " + item
4256 + ". Collides with " + tag;
4257 if (LauncherAppState.isDogfoodBuild()) {
4258 throw (new RuntimeException(desc));
4259 } else {
4260 Log.d(TAG, desc);
4261 }
Winson Chungce376632013-07-11 16:12:41 -07004262 }
Winson Chung64359a52013-07-08 17:17:08 -07004263 }
4264
Adam Cohendcd297f2013-06-18 13:13:40 -07004265 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4266 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004267 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004268 // Animate all the applications up now
4269 shortcut.setAlpha(0f);
4270 shortcut.setScaleX(0f);
4271 shortcut.setScaleY(0f);
4272 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004273 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004274 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004275 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004276 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004277 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004278 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004279 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004280 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4281 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004282 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004283 default:
4284 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004285 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004286 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004287
Winson Chung997a9232013-07-24 15:33:46 -07004288 if (animateIcons) {
4289 // Animate to the correct page
4290 if (newShortcutsScreenId > -1) {
4291 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004292 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004293 final Runnable startBounceAnimRunnable = new Runnable() {
4294 public void run() {
4295 anim.playTogether(bounceAnims);
4296 anim.start();
4297 }
4298 };
Winson Chung997a9232013-07-24 15:33:46 -07004299 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004300 // We post the animation slightly delayed to prevent slowdowns
4301 // when we are loading right after we return to launcher.
4302 mWorkspace.postDelayed(new Runnable() {
4303 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004304 if (mWorkspace != null) {
4305 mWorkspace.snapToPage(newScreenIndex);
4306 mWorkspace.postDelayed(startBounceAnimRunnable,
4307 NEW_APPS_ANIMATION_DELAY);
4308 }
Winson Chung94d67682013-09-25 16:29:40 -07004309 }
4310 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004311 } else {
4312 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004313 }
4314 }
Winson Chung64359a52013-07-08 17:17:08 -07004315 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004316 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004317 }
4318
Joe Onorato9c1289c2009-08-17 11:03:03 -04004319 /**
4320 * Implementation of the method from LauncherModel.Callbacks.
4321 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004322 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004323 Runnable r = new Runnable() {
4324 public void run() {
4325 bindFolders(folders);
4326 }
4327 };
4328 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004329 return;
4330 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004331 sFolders.clear();
4332 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004333 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004334
4335 /**
4336 * Add the views for a widget to the workspace.
4337 *
4338 * Implementation of the method from LauncherModel.Callbacks.
4339 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004340 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004341 Runnable r = new Runnable() {
4342 public void run() {
4343 bindAppWidget(item);
4344 }
4345 };
4346 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004347 return;
4348 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004349
Daniel Sandler843e8602010-06-07 14:59:01 -04004350 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4351 if (DEBUG_WIDGETS) {
4352 Log.d(TAG, "bindAppWidget: " + item);
4353 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004354 final Workspace workspace = mWorkspace;
4355
Sunny Goyalff572272014-07-23 13:58:07 -07004356 AppWidgetProviderInfo appWidgetInfo;
4357 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4358 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4359
4360 appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
4361 if (appWidgetInfo == null) {
4362 if (DEBUG_WIDGETS) {
4363 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4364 + " belongs to component " + item.providerName
4365 + ", as the povider is null");
4366 }
4367 LauncherModel.deleteItemFromDatabase(this, item);
4368 return;
4369 }
4370 // Note: This assumes that the id remap broadcast is received before this step.
4371 // If that is not the case, the id remap will be ignored and user may see the
4372 // click to setup view.
4373 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4374 pendingInfo.spanX = item.spanX;
4375 pendingInfo.spanY = item.spanY;
4376 pendingInfo.minSpanX = item.minSpanX;
4377 pendingInfo.minSpanY = item.minSpanY;
4378 Bundle options =
4379 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4380
4381 boolean success = false;
4382 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4383 if (options != null) {
4384 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId,
4385 appWidgetInfo.provider, options);
4386 } else {
4387 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId,
4388 appWidgetInfo.provider);
4389 }
4390
4391 // TODO consider showing a permission dialog when the widget is clicked.
4392 if (!success) {
4393 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4394 if (DEBUG_WIDGETS) {
4395 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4396 + " belongs to component " + item.providerName
4397 + ", as the launcher is unable to bing a new widget id");
4398 }
4399 LauncherModel.deleteItemFromDatabase(this, item);
4400 return;
4401 }
4402
4403 item.appWidgetId = newWidgetId;
4404
4405 // If the widget has a configure activity, it is still needs to set it up, otherwise
4406 // the widget is ready to go.
4407 item.restoreStatus = (appWidgetInfo.configure == null)
4408 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4409 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4410
4411 LauncherModel.updateItemInDatabase(this, item);
4412 }
4413
Sunny Goyal651077b2014-06-30 14:15:31 -07004414 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4415 final int appWidgetId = item.appWidgetId;
4416 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4417 if (DEBUG_WIDGETS) {
4418 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4419 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004420
Sunny Goyal651077b2014-06-30 14:15:31 -07004421 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4422 } else {
4423 appWidgetInfo = null;
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004424 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item);
4425 view.updateIcon(mIconCache);
4426 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004427 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004428 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004429 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004430
Joe Onorato9c1289c2009-08-17 11:03:03 -04004431 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004432 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004433
Adam Cohendcd297f2013-06-18 13:13:40 -07004434 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004435 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004436 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4437
Joe Onorato9c1289c2009-08-17 11:03:03 -04004438 workspace.requestLayout();
4439
Daniel Sandler843e8602010-06-07 14:59:01 -04004440 if (DEBUG_WIDGETS) {
4441 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4442 + (SystemClock.uptimeMillis()-start) + "ms");
4443 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004444 }
4445
Sunny Goyalff572272014-07-23 13:58:07 -07004446 /**
4447 * Restores a pending widget.
4448 *
4449 * @param appWidgetId The app widget id
4450 * @param cellInfo The position on screen where to create the widget.
4451 */
4452 private void completeRestoreAppWidget(final int appWidgetId) {
4453 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4454 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4455 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4456 return;
4457 }
4458
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004459 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004460 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4461
4462 mWorkspace.reinflateWidgetsIfNecessary();
4463 LauncherModel.updateItemInDatabase(this, info);
4464 }
4465
Adam Cohen1462de32012-07-24 22:34:36 -07004466 public void onPageBoundSynchronously(int page) {
4467 mSynchronouslyBoundPages.add(page);
4468 }
4469
Joe Onorato9c1289c2009-08-17 11:03:03 -04004470 /**
4471 * Callback saying that there aren't any more items to bind.
4472 *
4473 * Implementation of the method from LauncherModel.Callbacks.
4474 */
Adam Cohene25af792013-06-06 23:08:25 -07004475 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004476 Runnable r = new Runnable() {
4477 public void run() {
4478 finishBindingItems(upgradePath);
4479 }
4480 };
4481 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004482 return;
4483 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004484 if (mSavedState != null) {
4485 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004486 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004487 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004488 mSavedState = null;
4489 }
4490
Adam Cohen1462de32012-07-24 22:34:36 -07004491 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004492
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004493 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004494 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004495
4496 // If we received the result of any pending adds while the loader was running (e.g. the
4497 // widget configuration forced an orientation change), process them now.
4498 if (sPendingAddItem != null) {
4499 final long screenId = completeAdd(sPendingAddItem);
4500
4501 // TODO: this moves the user to the page where the pending item was added. Ideally,
4502 // the screen would be guaranteed to exist after bind, and the page would be set through
4503 // the workspace restore process.
4504 mWorkspace.post(new Runnable() {
4505 @Override
4506 public void run() {
4507 mWorkspace.snapToScreenId(screenId);
4508 }
4509 });
4510 sPendingAddItem = null;
4511 }
4512
Adam Cohene25af792013-06-06 23:08:25 -07004513 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004514 mWorkspace.getUniqueComponents(true, null);
4515 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004516 }
Sunny Goyale755d462014-07-22 13:48:29 -07004517 PackageInstallerCompat.getInstance(this).onFinishBind();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004518 }
4519
Adam Cohen3ed316a2014-07-23 18:21:20 -07004520 private void sendLoadingCompleteBroadcastIfNecessary() {
4521 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4522 String permission =
4523 getResources().getString(R.string.receive_first_load_broadcast_permission);
4524 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4525 sendBroadcast(intent, permission);
4526 SharedPreferences.Editor editor = mSharedPrefs.edit();
4527 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4528 editor.apply();
4529 }
4530 }
4531
Winson Chunga0b7e862013-09-05 16:03:15 -07004532 public boolean isAllAppsButtonRank(int rank) {
4533 if (mHotseat != null) {
4534 return mHotseat.isAllAppsButtonRank(rank);
4535 }
4536 return false;
4537 }
4538
Winson Chunga2413752012-04-03 14:22:34 -07004539 private boolean canRunNewAppsAnimation() {
4540 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4541 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4542 }
4543
Winson Chungc9168342013-06-26 14:54:55 -07004544 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4545 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4546 PropertyValuesHolder.ofFloat("alpha", 1f),
4547 PropertyValuesHolder.ofFloat("scaleX", 1f),
4548 PropertyValuesHolder.ofFloat("scaleY", 1f));
4549 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4550 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4551 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4552 return bounceAnim;
4553 }
4554
Adam Cohen27772732013-11-11 14:00:56 +00004555 public boolean useVerticalBarLayout() {
4556 return LauncherAppState.getInstance().getDynamicGrid().
4557 getDeviceProfile().isVerticalBarLayout();
4558 }
4559
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004560 protected Rect getSearchBarBounds() {
4561 return LauncherAppState.getInstance().getDynamicGrid().
4562 getDeviceProfile().getSearchBarBounds();
4563 }
4564
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004565 @Override
4566 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004567 boolean searchVisible = updateGlobalSearchIcon();
4568 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004569 if (mSearchDropTargetBar != null) {
4570 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4571 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004572 }
4573
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004574 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004575 * Add the icons for all apps.
4576 *
4577 * Implementation of the method from LauncherModel.Callbacks.
4578 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004579 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004580 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004581 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4582 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4583 getHotseat().addAllAppsFolder(mIconCache, apps,
4584 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4585 }
4586 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004587 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004588 if (mAppsCustomizeContent != null) {
4589 mAppsCustomizeContent.onPackagesUpdated(
4590 LauncherModel.getSortedWidgetsAndShortcuts(this));
4591 }
Winson Chungc58497e2013-09-03 17:48:37 -07004592 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004593 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004594 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004595 mAppsCustomizeContent.onPackagesUpdated(
4596 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004597 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004598 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004599 }
4600
4601 /**
4602 * A package was updated.
4603 *
4604 * Implementation of the method from LauncherModel.Callbacks.
4605 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004606 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004607 Runnable r = new Runnable() {
4608 public void run() {
4609 bindAppsUpdated(apps);
4610 }
4611 };
4612 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004613 return;
4614 }
4615
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004616 if (mWorkspace != null) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004617 mWorkspace.updateShortcutsAndWidgets(apps);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004618 }
Winson Chungc58497e2013-09-03 17:48:37 -07004619
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004620 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004621 mAppsCustomizeContent != null) {
4622 mAppsCustomizeContent.updateApps(apps);
4623 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004624 }
4625
4626 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004627 * Update the state of a package, typically related to install state.
4628 *
4629 * Implementation of the method from LauncherModel.Callbacks.
4630 */
Sunny Goyale755d462014-07-22 13:48:29 -07004631 @Override
4632 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004633 if (mWorkspace != null) {
Sunny Goyale755d462014-07-22 13:48:29 -07004634 mWorkspace.updatePackageState(installInfo);
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004635 }
4636 }
4637
4638 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004639 * A package was uninstalled. We take both the super set of packageNames
4640 * in addition to specific applications to remove, the reason being that
4641 * this can be called when a package is updated as well. In that scenario,
4642 * we only remove specific components from the workspace, where as
4643 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004644 *
4645 * Implementation of the method from LauncherModel.Callbacks.
4646 */
Winson Chung83892cc2013-05-01 16:53:33 -07004647 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004648 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004649 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004650 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004651 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004652 }
Winson Chungd64d1762013-08-20 14:37:16 -07004653 };
4654 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004655 return;
4656 }
4657
Winson Chungdf95eb12013-10-16 14:57:07 -07004658 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004659 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004660 }
4661 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004662 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004663 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004664
Winson Chunga1820962011-10-03 16:31:06 -07004665 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004666 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004667
Winson Chungdf95eb12013-10-16 14:57:07 -07004668 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004669 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004670 mAppsCustomizeContent != null) {
4671 mAppsCustomizeContent.removeApps(appInfos);
4672 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004673 }
Joe Onoratobe386092009-11-17 17:32:16 -08004674
4675 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004676 * A number of packages were updated.
4677 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004678 private ArrayList<Object> mWidgetsAndShortcuts;
4679 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004680 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004681 bindPackagesUpdated(mWidgetsAndShortcuts);
4682 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004683 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004684 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004685 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4686 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4687 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004688 return;
4689 }
4690
Winson Chung64359a52013-07-08 17:17:08 -07004691 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004692 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004693 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004694 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004695 }
4696
Winson Chung400438b2011-01-16 17:53:48 -08004697 private int mapConfigurationOriActivityInfoOri(int configOri) {
4698 final Display d = getWindowManager().getDefaultDisplay();
4699 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4700 switch (d.getRotation()) {
4701 case Surface.ROTATION_0:
4702 case Surface.ROTATION_180:
4703 // We are currently in the same basic orientation as the natural orientation
4704 naturalOri = configOri;
4705 break;
4706 case Surface.ROTATION_90:
4707 case Surface.ROTATION_270:
4708 // We are currently in the other basic orientation to the natural orientation
4709 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4710 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4711 break;
4712 }
4713
4714 int[] oriMap = {
4715 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4716 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4717 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4718 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4719 };
4720 // Since the map starts at portrait, we need to offset if this device's natural orientation
4721 // is landscape.
4722 int indexOffset = 0;
4723 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4724 indexOffset = 1;
4725 }
4726 return oriMap[(d.getRotation() + indexOffset) % 4];
4727 }
Adam Cohen446e9402011-09-15 18:21:21 -07004728
Winson Chung4b919f82012-05-01 10:44:08 -07004729 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004730 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004731 getResources().getBoolean(R.bool.allow_rotation);
4732 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004733 }
Winson Chung4b919f82012-05-01 10:44:08 -07004734 public void lockScreenOrientation() {
4735 if (isRotationEnabled()) {
4736 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4737 .getConfiguration().orientation));
4738 }
4739 }
4740 public void unlockScreenOrientation(boolean immediate) {
4741 if (isRotationEnabled()) {
4742 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004743 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004744 } else {
4745 mHandler.postDelayed(new Runnable() {
4746 public void run() {
4747 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4748 }
4749 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004750 }
Winson Chung4b919f82012-05-01 10:44:08 -07004751 }
Winson Chung400438b2011-01-16 17:53:48 -08004752 }
4753
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004754 /**
4755 * Called when the SearchBar hint should be changed.
4756 *
4757 * @param hint the hint to be displayed in the search bar.
4758 */
4759 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004760 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004761 }
4762
Winson Chunge43a1e72014-01-15 10:33:02 -08004763 protected boolean isLauncherPreinstalled() {
4764 PackageManager pm = getPackageManager();
4765 try {
4766 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4767 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4768 return true;
4769 } else {
4770 return false;
4771 }
4772 } catch (NameNotFoundException e) {
4773 e.printStackTrace();
4774 return false;
4775 }
4776 }
4777
Adam Cohenea90f832014-05-21 15:03:34 -07004778 /**
4779 * This method indicates whether or not we should suggest default wallpaper dimensions
4780 * when our wallpaper cropper was not yet used to set a wallpaper.
4781 */
4782 protected boolean overrideWallpaperDimensions() {
4783 return true;
4784 }
4785
Adam Cohen5eed5d82014-05-19 13:12:13 -07004786 protected boolean shouldClingFocusHotseatApp() {
4787 return false;
4788 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004789 protected String getFirstRunClingSearchBarHint() {
4790 return "";
4791 }
4792 protected String getFirstRunCustomContentHint() {
4793 return "";
4794 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004795 protected int getFirstRunFocusedHotseatAppDrawableId() {
4796 return -1;
4797 }
4798 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4799 return null;
4800 }
4801 protected int getFirstRunFocusedHotseatAppRank() {
4802 return -1;
4803 }
4804 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4805 return "";
4806 }
4807 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4808 return "";
4809 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004810
Winson Chungaf40f202013-09-18 18:26:31 -07004811 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004812 mLauncherClings.dismissFirstRunCling(v);
4813 }
4814 public void dismissMigrationClingCopyApps(View v) {
4815 mLauncherClings.dismissMigrationClingCopyApps(v);
4816 }
4817 public void dismissMigrationClingUseDefault(View v) {
4818 mLauncherClings.dismissMigrationClingUseDefault(v);
4819 }
4820 public void dismissMigrationWorkspaceCling(View v) {
4821 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004822 }
Winson Chung82f55532011-08-09 14:14:23 -07004823 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004824 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004825 }
4826 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004827 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004828 }
Adam Cohen6268f2d2014-05-16 16:42:35 -07004829 public void markFolderClingDismissedIfNecessary() {
4830 mLauncherClings.markFolderClingDismissedIfNecessary();
4831 }
Adam Cohen432609a2014-03-13 17:03:22 -07004832
4833 /**
4834 * To be overridden by subclasses to indicate that there is an activity to launch
4835 * before showing the standard launcher experience.
4836 */
4837 protected boolean hasFirstRunActivity() {
4838 return false;
4839 }
4840
4841 /**
4842 * To be overridden by subclasses to launch any first run activity
4843 */
4844 protected Intent getFirstRunActivity() {
4845 return null;
4846 }
4847
Winson Chunga6945242014-01-08 14:04:34 -08004848 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004849 return !ActivityManager.isRunningInTestHarness() &&
4850 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004851 }
4852
Adam Cohen4a9423d2014-03-28 14:22:31 -07004853 protected boolean hasRunFirstRunActivity() {
4854 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4855 }
4856
Adam Cohen432609a2014-03-13 17:03:22 -07004857 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004858 if (shouldRunFirstRunActivity() &&
4859 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004860 Intent firstRunIntent = getFirstRunActivity();
4861 if (firstRunIntent != null) {
4862 startActivity(firstRunIntent);
4863 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004864 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004865 }
4866 }
Adam Cohen432609a2014-03-13 17:03:22 -07004867 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004868 }
4869
4870 private void markFirstRunActivityShown() {
4871 SharedPreferences.Editor editor = mSharedPrefs.edit();
4872 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4873 editor.apply();
4874 }
4875
Adam Cohen432609a2014-03-13 17:03:22 -07004876 /**
4877 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4878 * screen that must be displayed and dismissed.
4879 */
4880 protected boolean hasDismissableIntroScreen() {
4881 return false;
4882 }
4883
4884 /**
4885 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4886 */
4887 protected View getIntroScreen() {
4888 return null;
4889 }
4890
4891 /**
4892 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4893 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4894 */
4895 private boolean shouldShowIntroScreen() {
4896 return hasDismissableIntroScreen() &&
4897 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4898 }
4899
4900 protected void showIntroScreen() {
4901 View introScreen = getIntroScreen();
4902 changeWallpaperVisiblity(false);
4903 if (introScreen != null) {
4904 mDragLayer.showOverlayView(introScreen);
4905 }
4906 }
4907
4908 public void dismissIntroScreen() {
4909 markIntroScreenDismissed();
4910 if (showFirstRunActivity()) {
4911 // We delay hiding the intro view until the first run activity is showing. This
4912 // avoids a blip.
4913 mWorkspace.postDelayed(new Runnable() {
4914 @Override
4915 public void run() {
4916 mDragLayer.dismissOverlayView();
4917 }
4918 }, ACTIVITY_START_DELAY);
4919 } else {
4920 mDragLayer.dismissOverlayView();
4921 }
4922 changeWallpaperVisiblity(true);
4923 }
4924
4925 private void markIntroScreenDismissed() {
4926 SharedPreferences.Editor editor = mSharedPrefs.edit();
4927 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4928 editor.apply();
4929 }
4930
Winson Chunga6945242014-01-08 14:04:34 -08004931 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004932 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4933 if (mHotseat != null) mHotseat.setAlpha(1f);
4934 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4935 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004936 }
4937
4938 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004939 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4940 if (mHotseat != null) mHotseat.setAlpha(0f);
4941 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4942 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004943 }
4944
Mathew Inwood72fbec12013-11-19 15:45:07 +00004945 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004946 // Called from search suggestion, not supported in other profiles.
4947 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4948 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4949 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4950 myUser);
4951 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004952 return null;
4953 }
Kenny Guyed131872014-04-30 03:02:21 +01004954 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004955 }
4956
4957 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4958 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004959 // Called from search suggestion, not supported in other profiles.
4960 return createShortcutDragInfo(shortcutIntent, caption, icon,
4961 UserHandleCompat.myUserHandle());
4962 }
4963
4964 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4965 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01004966 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01004967 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01004968 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004969 }
4970
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004971 protected void moveWorkspaceToDefaultScreen() {
4972 mWorkspace.moveToDefaultScreen(false);
4973 }
4974
Mathew Inwood72fbec12013-11-19 15:45:07 +00004975 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4976 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004977 mWorkspace.onExternalDragStartedWithItem(dragView);
4978 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004979 }
4980
Anjali Koppalf5d29132014-02-28 13:33:27 -08004981 @Override
4982 public void onPageSwitch(View newPage, int newPageIndex) {
4983 }
4984
Winson Chung80baf5a2010-08-09 16:03:15 -07004985 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004986 * Prints out out state for debugging.
4987 */
4988 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004989 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004990 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004991 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4992 Log.d(TAG, "mRestoring=" + mRestoring);
4993 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4994 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004995 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004996 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004997
Winson Chung785d2eb2011-04-14 16:08:02 -07004998 if (mAppsCustomizeContent != null) {
4999 mAppsCustomizeContent.dumpState();
5000 }
Daniel Sandler325dc232013-06-05 22:57:57 -04005001 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08005002 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005003
5004 @Override
5005 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5006 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07005007 synchronized (sDumpLogs) {
5008 writer.println(" ");
5009 writer.println("Debug logs: ");
5010 for (int i = 0; i < sDumpLogs.size(); i++) {
5011 writer.println(" " + sDumpLogs.get(i));
5012 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005013 }
5014 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005015
5016 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07005017 if (DEBUG_DUMP_LOG) {
5018 synchronized (sDumpLogs) {
5019 Log.d(TAG, "");
5020 Log.d(TAG, "*********************");
5021 Log.d(TAG, "Launcher debug logs: ");
5022 for (int i = 0; i < sDumpLogs.size(); i++) {
5023 Log.d(TAG, " " + sDumpLogs.get(i));
5024 }
5025 Log.d(TAG, "*********************");
5026 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07005027 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005028 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005029 }
5030
5031 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005032 addDumpLog(tag, log, null, debugLog);
5033 }
5034
5035 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07005036 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005037 if (e != null) {
5038 Log.d(tag, log, e);
5039 } else {
5040 Log.d(tag, log);
5041 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005042 }
Winson Chungede41292013-09-19 16:27:36 -07005043 if (DEBUG_DUMP_LOG) {
5044 sDateStamp.setTime(System.currentTimeMillis());
5045 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05005046 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5047 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07005048 }
Winson Chungede41292013-09-19 16:27:36 -07005049 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005050 }
5051
Winson Chungede41292013-09-19 16:27:36 -07005052 public void dumpLogsToLocalData() {
5053 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01005054 new AsyncTask<Void, Void, Void>() {
5055 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07005056 boolean success = false;
5057 sDateStamp.setTime(sRunStart);
5058 String FILENAME = sDateStamp.getMonth() + "-"
5059 + sDateStamp.getDay() + "_"
5060 + sDateStamp.getHours() + "-"
5061 + sDateStamp.getMinutes() + "_"
5062 + sDateStamp.getSeconds() + ".txt";
5063
5064 FileOutputStream fos = null;
5065 File outFile = null;
5066 try {
5067 outFile = new File(getFilesDir(), FILENAME);
5068 outFile.createNewFile();
5069 fos = new FileOutputStream(outFile);
5070 } catch (Exception e) {
5071 e.printStackTrace();
5072 }
5073 if (fos != null) {
5074 PrintWriter writer = new PrintWriter(fos);
5075
5076 writer.println(" ");
5077 writer.println("Debug logs: ");
5078 synchronized (sDumpLogs) {
5079 for (int i = 0; i < sDumpLogs.size(); i++) {
5080 writer.println(" " + sDumpLogs.get(i));
5081 }
5082 }
5083 writer.close();
5084 }
5085 try {
5086 if (fos != null) {
5087 fos.close();
5088 success = true;
5089 }
5090 } catch (IOException e) {
5091 e.printStackTrace();
5092 }
Michael Jurka43467462013-11-14 12:03:58 +01005093 return null;
Winson Chungede41292013-09-19 16:27:36 -07005094 }
Michael Jurka43467462013-11-14 12:03:58 +01005095 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07005096 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005097 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08005098}
Michael Jurka2763be32011-02-24 11:19:57 -08005099
Michael Jurkaabded662011-03-04 12:06:57 -08005100interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08005101 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07005102 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08005103 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08005104 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08005105 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08005106}
Dan Sandlerd5024042014-01-09 15:01:33 -05005107
5108interface DebugIntents {
5109 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5110 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00005111}