blob: 147500125a2caa219ca998b7e2f9e7c94766e2c8 [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;
Sunny Goyalffe83f12014-08-14 17:39:34 -0700102import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100103import com.android.launcher3.compat.LauncherActivityInfoCompat;
104import com.android.launcher3.compat.LauncherAppsCompat;
Sunny Goyale755d462014-07-22 13:48:29 -0700105import com.android.launcher3.compat.PackageInstallerCompat;
106import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
Kenny Guyed131872014-04-30 03:02:21 +0100107import com.android.launcher3.compat.UserHandleCompat;
108import com.android.launcher3.compat.UserManagerCompat;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700109
Adam Cohenc0dcf592011-06-01 15:30:43 -0700110import java.io.DataInputStream;
111import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700112import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700113import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700115import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700116import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700117import java.io.PrintWriter;
Adam Cohen0b395352014-06-09 22:54:36 +0000118import java.lang.reflect.Field;
119import java.lang.reflect.InvocationTargetException;
120import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700121import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700122import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700123import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700124import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700125import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700126import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000127import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700128
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 Sandler6053b8002013-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;
Romain Guycbb89e42009-06-08 15:52:54 -0700258
Sunny Goyalffe83f12014-08-14 17:39:34 -0700259 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700260 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700261
Michael Jurkac9d95c52011-08-29 14:03:34 -0700262 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700263 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800264 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700265
Michael Jurka0280c3b2010-09-17 15:00:07 -0700266 private int[] mTmpAddItemCellCoordinates = new int[2];
267
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800268 private FolderInfo mFolderInfo;
269
Winson Chung3d503fb2011-07-13 17:25:49 -0700270 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800271 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700272
Michael Jurka838a4ca2011-02-07 13:33:06 -0800273 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700274
Winson Chungc51db6a2011-10-05 11:44:49 -0700275 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700276 private AppsCustomizeTabHost mAppsCustomizeTabHost;
277 private AppsCustomizePagedView mAppsCustomizeContent;
278 private boolean mAutoAdvanceRunning = false;
Adam Cohen24ce0b32014-01-14 16:18:14 -0800279 private View mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800280
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800281 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700282 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
283 // scroll issues (because the workspace may not have been measured yet) and extra work.
284 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
285 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800286
287 private SpannableStringBuilder mDefaultKeySsb = null;
288
Joe Onorato9c1289c2009-08-17 11:03:03 -0400289 private boolean mWorkspaceLoading = true;
290
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800291 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800292 private boolean mRestoring;
293 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700294 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800295
Michael Jurka1e2f4652013-07-08 18:03:46 -0700296 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700297 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
298
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800299 private Bundle mSavedInstanceState;
300
Joe Onorato9c1289c2009-08-17 11:03:03 -0400301 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800302 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800303 private boolean mUserPresent = true;
304 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700305 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800306 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400307
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700308 private static LocaleConfiguration sLocaleConfiguration = null;
309
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700310 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700311
Adam Cohen61f560d2013-09-30 15:58:20 -0700312 private View.OnTouchListener mHapticFeedbackTouchListener;
313
Adam Cohended9f8d2010-11-03 13:25:16 -0700314 // Related to the auto-advancing of widgets
315 private final int ADVANCE_MSG = 1;
316 private final int mAdvanceInterval = 20000;
317 private final int mAdvanceStagger = 250;
318 private long mAutoAdvanceSentTime;
319 private long mAutoAdvanceTimeLeft = -1;
320 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
321 new HashMap<View, AppWidgetProviderInfo>();
322
Winson Chung400438b2011-01-16 17:53:48 -0800323 // Determines how long to wait after a rotation before restoring the screen orientation to
324 // match the sensor state.
325 private final int mRestoreScreenOrientationDelay = 500;
326
Michael Jurka4ef207b2010-11-29 17:05:45 -0800327 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700328 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
329 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
Winson Chungd64a6662013-09-30 11:06:59 -0700330
Craig Mautner360310b2012-10-26 15:13:08 -0700331 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700332
Adam Cohen1462de32012-07-24 22:34:36 -0700333 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700334 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700335
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700336 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700337 static Date sDateStamp = new Date();
338 static DateFormat sDateFormat =
339 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
340 static long sRunStart = System.currentTimeMillis();
341 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700342
Winson Chung46353de2012-02-16 14:05:10 -0800343 // We only want to get the SharedPreferences once since it does an FS stat each time we get
344 // it from the context.
345 private SharedPreferences mSharedPrefs;
346
Adam Cohene25af792013-06-06 23:08:25 -0700347 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
348
Winson Chungf0c6ae02012-03-21 16:10:31 -0700349 // Holds the page that we need to animate to, and the icon views that we need to animate up
350 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700351 private ImageView mFolderIconImageView;
352 private Bitmap mFolderIconBitmap;
353 private Canvas mFolderIconCanvas;
354 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700355
Michael Jurkaddd62e92011-02-16 17:49:14 -0800356 private BubbleTextView mWaitingForResume;
357
Michael Jurkac1f5d262011-09-30 19:32:27 -0700358 private Runnable mBuildLayersRunnable = new Runnable() {
359 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700360 if (mWorkspace != null) {
361 mWorkspace.buildPageHardwareLayers();
362 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700363 }
364 };
365
Adam Cohendb364c32014-05-20 14:23:40 -0700366 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800367
Michael Jurka7267fa52013-09-26 15:29:57 -0700368 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800369
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800370 private static class PendingAddArguments {
371 int requestCode;
372 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700373 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700374 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800375 int cellX;
376 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700377 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800378 }
379
Daniel Sandlerff02d492013-08-05 02:12:05 -0400380 private Stats mStats;
381
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700382 FocusIndicatorView mFocusHandler;
383
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800384 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800385 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700386 }
387
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800388 @Override
389 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700390 if (DEBUG_STRICT_MODE) {
391 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
392 .detectDiskReads()
393 .detectDiskWrites()
394 .detectNetwork() // or .detectAll() for all detectable problems
395 .penaltyLog()
396 .build());
397 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
398 .detectLeakedSqlLiteObjects()
399 .detectLeakedClosableObjects()
400 .penaltyLog()
401 .penaltyDeath()
402 .build());
403 }
404
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800405 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400406
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400407 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400408 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700409 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700410 // Determine the dynamic grid properties
411 Point smallestSize = new Point();
412 Point largestSize = new Point();
413 Point realSize = new Point();
414 Display display = getWindowManager().getDefaultDisplay();
415 display.getCurrentSizeRange(smallestSize, largestSize);
416 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700417 DisplayMetrics dm = new DisplayMetrics();
418 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700419
Winson Chung5f8afe62013-08-12 16:19:28 -0700420 // Lazy-initialize the dynamic grid
421 DeviceProfile grid = app.initDynamicGrid(this,
422 Math.min(smallestSize.x, smallestSize.y),
423 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700424 realSize.x, realSize.y,
425 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700426
427 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400428 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700429 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700430 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800431 mModel = app.setLauncher(this);
432 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700433 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400434 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800435 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700436
Daniel Sandlerff02d492013-08-05 02:12:05 -0400437 mStats = new Stats(this);
438
Sunny Goyalffe83f12014-08-14 17:39:34 -0700439 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700440
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700441 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
442 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700443
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700444 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
445 // this also ensures that any synchronous binding below doesn't re-trigger another
446 // LauncherModel load.
447 mPaused = false;
448
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800449 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200450 android.os.Debug.startMethodTracing(
451 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800452 }
453
454 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800455 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700456
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800457 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100458 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800459
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800460 registerContentObservers();
461
Joe Onorato7c312c12009-08-13 21:36:53 -0700462 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700463
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800464 mSavedState = savedInstanceState;
465 restoreState(mSavedState);
466
467 if (PROFILE_STARTUP) {
468 android.os.Debug.stopMethodTracing();
469 }
470
471 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700472 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700473 // If the user leaves launcher, then we should just load items asynchronously when
474 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500475 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700476 } else {
477 // We only load the page synchronously if the user rotates (or triggers a
478 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800479 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700480 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800481 }
482
483 // For handling default keys
484 mDefaultKeySsb = new SpannableStringBuilder();
485 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800486
487 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
488 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800489
Adam Cohenf9426d52012-06-04 17:26:21 -0700490 updateGlobalIcons();
491
492 // On large interfaces, we want the screen to auto-rotate based on the current orientation
493 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700494
Adam Cohen432609a2014-03-13 17:03:22 -0700495 if (shouldShowIntroScreen()) {
496 showIntroScreen();
497 } else {
498 showFirstRunActivity();
499 }
500
Winson Chunge43a1e72014-01-15 10:33:02 -0800501 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
502 // on the device, then we always show the first run cling experience (or if there is no
503 // launcher2). Otherwise, we prompt the user upon started for migration
Sunny Goyal424418b2014-08-22 16:09:37 -0700504 LauncherClings launcherClings = new LauncherClings(this);
505 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
Winson Chunge43a1e72014-01-15 10:33:02 -0800506 if (mModel.canMigrateFromOldLauncherDb(this)) {
Sunny Goyal424418b2014-08-22 16:09:37 -0700507 launcherClings.showMigrationCling();
Winson Chunge43a1e72014-01-15 10:33:02 -0800508 } else {
Sunny Goyal424418b2014-08-22 16:09:37 -0700509 launcherClings.showLongPressCling(true);
Winson Chunge43a1e72014-01-15 10:33:02 -0800510 }
Winson Chunga6945242014-01-08 14:04:34 -0800511 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700512 }
513
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700514 @Override
515 public void onLauncherProviderChange() { }
516
Winson Chung98ca0f72013-07-29 12:58:51 -0700517 /** To be overriden by subclasses to hint to Launcher that we have custom content */
518 protected boolean hasCustomContentToLeft() {
519 return false;
520 }
521
Dave Hawkeya8881582013-09-17 15:55:33 -0600522 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500523 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600524 * {@link #addToCustomContentPage}. This will only be invoked if
525 * {@link #hasCustomContentToLeft()} is {@code true}.
526 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500527 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600528 }
529
530 /**
531 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
532 * ensure the custom content page is added or removed if necessary.
533 */
534 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600535 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600536 // Not bound yet, wait for bindScreens to be called.
537 return;
538 }
539
540 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
541 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500542 mWorkspace.createCustomContentContainer();
543 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600544 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
545 mWorkspace.removeCustomContentPage();
546 }
547 }
548
Adam Cohenf9426d52012-06-04 17:26:21 -0700549 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700550 boolean searchVisible = false;
551 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800552 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700553 int coi = getCurrentOrientationIndexForGlobalIcons();
Adam Cohena00673c2014-08-14 12:57:28 -0700554 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700555 searchVisible = updateGlobalSearchIcon();
556 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700557 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700558 if (sGlobalSearchIcon[coi] != null) {
559 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700560 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700561 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700562 if (sVoiceSearchIcon[coi] != null) {
563 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700564 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700565 }
Winson Chungadf0c182012-08-23 14:59:07 -0700566 if (mSearchDropTargetBar != null) {
567 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
568 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800569 }
Romain Guycbb89e42009-06-08 15:52:54 -0700570
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800571 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700572 if (sLocaleConfiguration == null) {
573 new AsyncTask<Void, Void, LocaleConfiguration>() {
574 @Override
575 protected LocaleConfiguration doInBackground(Void... unused) {
576 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
577 readConfiguration(Launcher.this, localeConfiguration);
578 return localeConfiguration;
579 }
580
581 @Override
582 protected void onPostExecute(LocaleConfiguration result) {
583 sLocaleConfiguration = result;
584 checkForLocaleChange(); // recursive, but now with a locale configuration
585 }
586 }.execute();
587 return;
588 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700589
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800590 final Configuration configuration = getResources().getConfiguration();
591
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700592 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800593 final String locale = configuration.locale.toString();
594
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700595 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800596 final int mcc = configuration.mcc;
597
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700598 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800599 final int mnc = configuration.mnc;
600
Romain Guy84f296c2009-11-04 15:00:44 -0800601 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800602
Romain Guy84f296c2009-11-04 15:00:44 -0800603 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700604 sLocaleConfiguration.locale = locale;
605 sLocaleConfiguration.mcc = mcc;
606 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700607
Joe Onorato0589f0f2010-02-08 13:44:00 -0800608 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700609
610 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100611 new AsyncTask<Void, Void, Void>() {
612 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700613 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100614 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700615 }
Michael Jurka43467462013-11-14 12:03:58 +0100616 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700617 }
618 }
619
620 private static class LocaleConfiguration {
621 public String locale;
622 public int mcc = -1;
623 public int mnc = -1;
624 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700625
Romain Guy98d01652009-06-30 16:21:04 -0700626 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
627 DataInputStream in = null;
628 try {
629 in = new DataInputStream(context.openFileInput(PREFERENCES));
630 configuration.locale = in.readUTF();
631 configuration.mcc = in.readInt();
632 configuration.mnc = in.readInt();
633 } catch (FileNotFoundException e) {
634 // Ignore
635 } catch (IOException e) {
636 // Ignore
637 } finally {
638 if (in != null) {
639 try {
640 in.close();
641 } catch (IOException e) {
642 // Ignore
643 }
644 }
645 }
646 }
647
648 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
649 DataOutputStream out = null;
650 try {
651 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
652 out.writeUTF(configuration.locale);
653 out.writeInt(configuration.mcc);
654 out.writeInt(configuration.mnc);
655 out.flush();
656 } catch (FileNotFoundException e) {
657 // Ignore
658 } catch (IOException e) {
659 //noinspection ResultOfMethodCallIgnored
660 context.getFileStreamPath(PREFERENCES).delete();
661 } finally {
662 if (out != null) {
663 try {
664 out.close();
665 } catch (IOException e) {
666 // Ignore
667 }
668 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800669 }
670 }
671
Anton Hanssona2f665f2013-09-26 12:18:32 +0100672 public Stats getStats() {
673 return mStats;
674 }
675
Bjorn Bringertc459e522013-06-07 19:36:01 +0100676 public LayoutInflater getInflater() {
677 return mInflater;
678 }
679
Winson Chung36a62fe2012-05-06 18:04:42 -0700680 boolean isDraggingEnabled() {
681 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
682 // that is subsequently removed from the workspace in startBinding().
683 return !mModel.isLoadingWorkspace();
684 }
685
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800686 static int getScreen() {
687 synchronized (sLock) {
688 return sScreen;
689 }
690 }
691
692 static void setScreen(int screen) {
693 synchronized (sLock) {
694 sScreen = screen;
695 }
696 }
697
Winson Chung557d6ed2011-07-08 15:34:52 -0700698 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000699 * Copied from View -- the View version of the method isn't called
700 * anywhere else in our process and only exists for API level 17+,
701 * so it's ok to keep our own version with no API requirement.
702 */
703 public static int generateViewId() {
704 for (;;) {
705 final int result = sNextGeneratedId.get();
706 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
707 int newValue = result + 1;
708 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
709 if (sNextGeneratedId.compareAndSet(result, newValue)) {
710 return result;
711 }
712 }
713 }
714
715 public int getViewIdForItem(ItemInfo info) {
716 // This cast is safe given the > 2B range for int.
717 int itemId = (int) info.id;
718 if (mItemIdToViewId.containsKey(itemId)) {
719 return mItemIdToViewId.get(itemId);
720 }
721 int viewId = generateViewId();
722 mItemIdToViewId.put(itemId, viewId);
723 return viewId;
724 }
725
726 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700727 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
728 * a configuration step, this allows the proper animations to run after other transitions.
729 */
Adam Cohendb364c32014-05-20 14:23:40 -0700730 private long completeAdd(PendingAddArguments args) {
731
732 long screenId = ensurePendingDropLayoutExists(args.screenId);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800733 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800734 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700735 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700736 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700737 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800738 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700739 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700740 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700741 case REQUEST_RECONFIGURE_APPWIDGET:
742 completeRestoreAppWidget(args.appWidgetId);
743 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800744 }
Michael Jurka27614d22012-04-02 06:40:22 -0700745 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
746 // if you turned the screen off and then back while in All Apps, Launcher would not
747 // return to the workspace. Clearing mAddInfo.container here fixes this issue
748 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700749 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800750 }
751
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800752 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700753 protected void onActivityResult(
754 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700755 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700756 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700757 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800758 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700759
Adam Cohenad4e15c2013-10-17 16:21:35 -0700760 Runnable exitSpringLoaded = new Runnable() {
761 @Override
762 public void run() {
763 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
764 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
765 }
766 };
767
Michael Jurka8b805b12012-04-18 14:23:14 -0700768 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700769 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700770 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
771 if (resultCode == RESULT_CANCELED) {
772 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700773 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700774 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700775 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700776 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
777 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700778 }
779 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200780 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
781 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
782 mWorkspace.exitOverviewMode(false);
783 }
784 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700785 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200786
Adam Cohened66b2b2012-01-23 17:28:51 -0800787 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
788 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700789
Adam Cohendb364c32014-05-20 14:23:40 -0700790 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800791 // We have special handling for widgets
792 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800793 final int appWidgetId;
794 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
795 : -1;
796 if (widgetId < 0) {
797 appWidgetId = pendingAddWidgetId;
798 } else {
799 appWidgetId = widgetId;
800 }
801
Adam Cohenad4e15c2013-10-17 16:21:35 -0700802 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800803 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700804 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
805 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700806 result = RESULT_CANCELED;
807 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700808 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700809 @Override
810 public void run() {
811 exitSpringLoadedDragModeDelayed(false, 0, null);
812 }
813 };
Adam Cohendb364c32014-05-20 14:23:40 -0700814 if (workspaceLocked) {
815 // No need to remove the empty screen if we're mid-binding, as the
816 // the bind will not add the empty screen.
817 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
818 } else {
819 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
820 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
821 }
Winson Chung5aaab772012-04-27 15:24:02 -0700822 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700823 if (!workspaceLocked) {
824 mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
825 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
826
827 dropLayout.setDropPending(true);
828 final Runnable onComplete = new Runnable() {
829 @Override
830 public void run() {
831 completeTwoStageWidgetDrop(resultCode, appWidgetId);
832 dropLayout.setDropPending(false);
833 }
834 };
835 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
836 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
837 } else {
838 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
839 mPendingAddInfo);
840 sPendingAddItem = args;
841 }
Winson Chung5aaab772012-04-27 15:24:02 -0700842 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800843 return;
844 }
845
Sunny Goyalff572272014-07-23 13:58:07 -0700846 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
847 if (resultCode == RESULT_OK) {
848 // Update the widget view.
849 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
850 pendingAddWidgetId, mPendingAddInfo);
851 if (workspaceLocked) {
852 sPendingAddItem = args;
853 } else {
854 completeAdd(args);
855 }
856 }
857 // Leave the widget in the pending state if the user canceled the configure.
858 return;
859 }
860
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800861 // The pattern used here is that a user PICKs a specific application,
862 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700863
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800864 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
865 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700866 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700867 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
868 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800869 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700870 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800871 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700872 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700873 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
874 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800875 }
Adam Cohen00074722013-10-11 17:46:09 -0700876 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700877 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700878 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800879 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800880 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800881 }
882
Adam Cohendb364c32014-05-20 14:23:40 -0700883 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
884 appWidgetId, ItemInfo info) {
885 PendingAddArguments args = new PendingAddArguments();
886 args.requestCode = requestCode;
887 args.intent = data;
888 args.container = info.container;
889 args.screenId = info.screenId;
890 args.cellX = info.cellX;
891 args.cellY = info.cellY;
892 args.appWidgetId = appWidgetId;
893 return args;
894 }
895
896 /**
897 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
898 *
899 * @param screenId the screen id to check
900 * @return the new screen, or screenId if it exists
901 */
902 private long ensurePendingDropLayoutExists(long screenId) {
903 CellLayout dropLayout =
904 (CellLayout) mWorkspace.getScreenWithId(screenId);
905 if (dropLayout == null) {
906 // it's possible that the add screen was removed because it was
907 // empty and a re-bind occurred
908 mWorkspace.addExtraEmptyScreen();
909 return mWorkspace.commitExtraEmptyScreen();
910 } else {
911 return screenId;
912 }
913 }
914
Adam Cohened66b2b2012-01-23 17:28:51 -0800915 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700916 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700917 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800918 Runnable onCompleteRunnable = null;
919 int animationType = 0;
920
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700921 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800922 if (resultCode == RESULT_OK) {
923 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
924 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700925 mPendingAddWidgetInfo);
926 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800927 onCompleteRunnable = new Runnable() {
928 @Override
929 public void run() {
930 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700931 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700932 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
933 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800934 }
935 };
936 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800937 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800938 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800939 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700940 if (mDragLayer.getAnimatedView() != null) {
941 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
942 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
943 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700944 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700945 // The animated view may be null in the case of a rotation during widget configuration
946 onCompleteRunnable.run();
947 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800948 }
949
950 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700951 protected void onStop() {
952 super.onStop();
953 FirstFrameAnimatorHelper.setIsVisible(false);
954 }
955
956 @Override
957 protected void onStart() {
958 super.onStart();
959 FirstFrameAnimatorHelper.setIsVisible(true);
960 }
961
962 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800963 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200964 long startTime = 0;
965 if (DEBUG_RESUME_TIME) {
966 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400967 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200968 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800969 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700970
Winson Chung4a2afa32012-07-19 14:53:05 -0700971 // Restore the previous launcher state
972 if (mOnResumeState == State.WORKSPACE) {
973 showWorkspace(false);
974 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c62013-11-06 15:49:51 -0800975 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700976 }
977 mOnResumeState = State.NONE;
978
Craig Mautner360310b2012-10-26 15:13:08 -0700979 // Background was set to gradient in onPause(), restore to black if in all apps.
980 setWorkspaceBackground(mState == State.WORKSPACE);
981
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800982 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700983 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700984 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500985 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400986 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700987 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800988 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700989 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200990 // We might have postponed some bind calls until onResume (see waitUntilResume) --
991 // execute them here
992 long startTimeCallbacks = 0;
993 if (DEBUG_RESUME_TIME) {
994 startTimeCallbacks = System.currentTimeMillis();
995 }
996
997 if (mAppsCustomizeContent != null) {
998 mAppsCustomizeContent.setBulkBind(true);
999 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001000 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1001 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001002 }
1003 if (mAppsCustomizeContent != null) {
1004 mAppsCustomizeContent.setBulkBind(false);
1005 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001006 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001007 if (DEBUG_RESUME_TIME) {
1008 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1009 (System.currentTimeMillis() - startTimeCallbacks));
1010 }
Michael Jurka447bf842013-05-15 14:52:15 +02001011 }
Michael Jurka54554252013-08-01 12:52:23 +02001012 if (mOnResumeCallbacks.size() > 0) {
1013 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1014 mOnResumeCallbacks.get(i).run();
1015 }
1016 mOnResumeCallbacks.clear();
1017 }
Winson Chunge4e50662012-01-23 14:45:13 -08001018
1019 // Reset the pressed state of icons that were locked in the press state while activities
1020 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001021 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001022 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001023 mWaitingForResume.setStayPressed(false);
1024 }
Winson Chung82963d52013-10-09 11:20:57 -07001025
Adam Cohen06dff352012-06-01 17:17:08 -07001026 // It is possible that widgets can receive updates while launcher is not in the foreground.
1027 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1028 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1029 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001030 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001031
Winson Chung780fe592013-09-26 14:48:44 -07001032 // Process any items that were added while Launcher was away.
1033 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1034
Winson Chung5841efa2013-09-30 18:06:44 -07001035 // Update the voice search button proxy
1036 updateVoiceButtonProxyVisible(false);
1037
Adam Cohenf9426d52012-06-04 17:26:21 -07001038 // Again, as with the above scenario, it's possible that one or more of the global icons
1039 // were updated in the wrong orientation.
1040 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001041 if (DEBUG_RESUME_TIME) {
1042 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1043 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001044
1045 if (mWorkspace.getCustomContentCallbacks() != null) {
1046 // If we are resuming and the custom content is the current page, we call onShow().
1047 // It is also poassible that onShow will instead be called slightly after first layout
1048 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1049 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001050 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001051 }
1052 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001053 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001054 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001055
1056 PackageInstallerCompat.getInstance(this).onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001057 }
1058
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001059 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001060 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001061 // Ensure that items added to Launcher are queued until Launcher returns
1062 InstallShortcutReceiver.enableInstallQueue();
Sunny Goyale755d462014-07-22 13:48:29 -07001063 PackageInstallerCompat.getInstance(this).onPause();
Winson Chung997a9232013-07-24 15:33:46 -07001064
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001065 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001066 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001067 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001068 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001069
1070 // We call onHide() aggressively. The custom content callbacks should be able to
1071 // debounce excess onHide calls.
1072 if (mWorkspace.getCustomContentCallbacks() != null) {
1073 mWorkspace.getCustomContentCallbacks().onHide();
1074 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001075 }
Romain Guycbb89e42009-06-08 15:52:54 -07001076
Adam Cohenbffe7452013-07-22 18:21:45 -07001077 QSBScroller mQsbScroller = new QSBScroller() {
1078 int scrollY = 0;
1079
1080 @Override
1081 public void setScrollY(int scroll) {
1082 scrollY = scroll;
1083
1084 if (mWorkspace.isOnOrMovingToCustomContent()) {
1085 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001086 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001087 }
1088 }
1089 };
1090
1091 public void resetQSBScroll() {
1092 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001093 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001094 }
1095
1096 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001097 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1098 // by a onResume or by scrolling otherwise.
1099 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001100
1101 // Custom content is completely hidden
1102 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001103
1104 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1105 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001106
1107 // Indicates whether the user is allowed to scroll away from the custom content.
1108 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001109 }
1110
Jorim Jaggid017f882014-01-14 17:08:48 -08001111 protected boolean hasSettings() {
1112 return false;
1113 }
1114
Adam Cohenbffe7452013-07-22 18:21:45 -07001115 public interface QSBScroller {
1116 public void setScrollY(int scrollY);
1117 }
1118
Winson Chung98ca0f72013-07-29 12:58:51 -07001119 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001120 CustomContentCallbacks callbacks, String description) {
1121 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001122 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001123 }
1124
Adam Cohenedb40762013-07-18 16:45:45 -07001125 // The custom content needs to offset its content to account for the QSB
1126 public int getTopOffsetForCustomContent() {
1127 return mWorkspace.getPaddingTop();
1128 }
1129
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001130 @Override
1131 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001132 // Flag the loader to stop early before switching
1133 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001134 if (mAppsCustomizeContent != null) {
1135 mAppsCustomizeContent.surrender();
1136 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001137 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001138 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001139
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001140 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001141 @Override
1142 public void onWindowFocusChanged(boolean hasFocus) {
1143 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001144 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001145 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001146
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001147 private boolean acceptFilter() {
1148 final InputMethodManager inputManager = (InputMethodManager)
1149 getSystemService(Context.INPUT_METHOD_SERVICE);
1150 return !inputManager.isFullscreenMode();
1151 }
1152
1153 @Override
1154 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001155 final int uniChar = event.getUnicodeChar();
1156 final boolean handled = super.onKeyDown(keyCode, event);
1157 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1158 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001159 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1160 keyCode, event);
1161 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001162 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001163 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001164 // showSearchDialog()
1165 // If there are multiple keystrokes before the search dialog takes focus,
1166 // onSearchRequested() will be called for every keystroke,
1167 // but it is idempotent, so it's fine.
1168 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001169 }
1170 }
1171
Joe Onorato8a9625e2010-01-28 15:55:35 -08001172 // Eat the long press event so the keyboard doesn't come up.
1173 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1174 return true;
1175 }
1176
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001177 return handled;
1178 }
1179
Karl Rosaen138a0412009-04-23 19:00:21 -07001180 private String getTypedText() {
1181 return mDefaultKeySsb.toString();
1182 }
1183
1184 private void clearTypedText() {
1185 mDefaultKeySsb.clear();
1186 mDefaultKeySsb.clearSpans();
1187 Selection.setSelection(mDefaultKeySsb, 0);
1188 }
1189
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001190 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001191 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1192 * State
1193 */
1194 private static State intToState(int stateOrdinal) {
1195 State state = State.WORKSPACE;
1196 final State[] stateValues = State.values();
1197 for (int i = 0; i < stateValues.length; i++) {
1198 if (stateValues[i].ordinal() == stateOrdinal) {
1199 state = stateValues[i];
1200 break;
1201 }
1202 }
1203 return state;
1204 }
1205
1206 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001207 * Restores the previous state, if it exists.
1208 *
1209 * @param savedState The previous state.
1210 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001211 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001212 private void restoreState(Bundle savedState) {
1213 if (savedState == null) {
1214 return;
1215 }
1216
Michael Jurka883f55b2010-10-21 15:47:14 -07001217 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001218 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001219 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001220 }
1221
Adam Cohen21cd0022013-10-09 18:57:02 -07001222 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1223 PagedView.INVALID_RESTORE_PAGE);
1224 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001225 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001226 }
1227
Winson Chung3d503fb2011-07-13 17:25:49 -07001228 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001229 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001230
Winson Chung3d503fb2011-07-13 17:25:49 -07001231 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1232 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001233 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001234 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1235 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001236 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1237 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1238 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001239 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001240 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001241 mRestoring = true;
1242 }
1243
1244 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1245 if (renameFolder) {
1246 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001247 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001248 mRestoring = true;
1249 }
Winson Chunga12a2502010-12-20 14:41:35 -08001250
Winson Chung785d2eb2011-04-14 16:08:02 -07001251 // Restore the AppsCustomize tab
1252 if (mAppsCustomizeTabHost != null) {
1253 String curTab = savedState.getString("apps_customize_currentTab");
1254 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001255 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001256 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001257 mAppsCustomizeContent.loadAssociatedPages(
1258 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001259 }
1260
Winson Chung5afbf7b2011-07-25 11:53:08 -07001261 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1262 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001263 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001264 mItemIdToViewId = (HashMap<Integer, Integer>)
1265 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001266 }
1267
1268 /**
1269 * Finds all the views we need and configure them properly.
1270 */
1271 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001272 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001273
Craig Mautner360310b2012-10-26 15:13:08 -07001274 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001275 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001276 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1277 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001278 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001279 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001280
John Spurlock77e1f472013-09-11 10:09:51 -04001281 mLauncherView.setSystemUiVisibility(
1282 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001283 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001284
Winson Chung4c98d922011-05-31 16:50:48 -07001285 // Setup the drag layer
1286 mDragLayer.setup(this, dragController);
1287
Winson Chung3d503fb2011-07-13 17:25:49 -07001288 // Setup the hotseat
1289 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1290 if (mHotseat != null) {
1291 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001292 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001293 }
1294
Jorim Jaggid017f882014-01-14 17:08:48 -08001295 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001296 View widgetButton = findViewById(R.id.widget_button);
1297 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001298 @Override
1299 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001300 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001301 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001302 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001303 }
1304 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001305 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1306
1307 View wallpaperButton = findViewById(R.id.wallpaper_button);
1308 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001309 @Override
1310 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001311 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001312 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001313 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001314 }
1315 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001316 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1317
1318 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001319 if (hasSettings()) {
1320 settingsButton.setOnClickListener(new OnClickListener() {
1321 @Override
1322 public void onClick(View arg0) {
1323 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001324 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001325 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001326 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001327 });
1328 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1329 } else {
1330 settingsButton.setVisibility(View.GONE);
1331 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1332 lp.gravity = Gravity.END | Gravity.TOP;
1333 widgetButton.requestLayout();
1334 }
1335
Adam Cohendbdff6b2013-09-18 19:09:15 -07001336 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001337
Winson Chung4c98d922011-05-31 16:50:48 -07001338 // Setup the workspace
1339 mWorkspace.setHapticFeedbackEnabled(false);
1340 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001341 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001342 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001343
Winson Chungf0ea4d32011-06-06 14:27:16 -07001344 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001345 mSearchDropTargetBar = (SearchDropTargetBar)
1346 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001347
Winson Chungf0ea4d32011-06-06 14:27:16 -07001348 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001349 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001350 mAppsCustomizeContent = (AppsCustomizePagedView)
1351 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1352 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001353
Winson Chung3d503fb2011-07-13 17:25:49 -07001354 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001355 dragController.setDragScoller(mWorkspace);
1356 dragController.setScrollView(mDragLayer);
1357 dragController.setMoveTarget(mWorkspace);
1358 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001359 if (mSearchDropTargetBar != null) {
1360 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001361 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001362
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001363 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001364 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001365 mWeightWatcher = new WeightWatcher(this);
1366 mWeightWatcher.setAlpha(0.5f);
1367 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001368 new FrameLayout.LayoutParams(
1369 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001370 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001371 Gravity.BOTTOM)
1372 );
Adam Cohen39a06042013-07-19 14:30:12 -07001373
1374 boolean show = shouldShowWeightWatcher();
1375 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001376 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001377 }
1378
1379 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001380 * Sets the all apps button. This method is called from {@link Hotseat}.
1381 */
1382 public void setAllAppsButton(View allAppsButton) {
1383 mAllAppsButton = allAppsButton;
1384 }
1385
1386 public View getAllAppsButton() {
1387 return mAllAppsButton;
1388 }
1389
1390 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001391 * Creates a view representing a shortcut.
1392 *
1393 * @param info The data structure describing the shortcut.
1394 *
1395 * @return A View inflated from R.layout.application.
1396 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001397 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001398 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001399 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001400 }
1401
1402 /**
1403 * Creates a view representing a shortcut inflated from the specified resource.
1404 *
1405 * @param layoutResId The id of the XML layout used to create the shortcut.
1406 * @param parent The group the shortcut belongs to.
1407 * @param info The data structure describing the shortcut.
1408 *
1409 * @return A View inflated from layoutResId.
1410 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001411 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001412 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001413 favorite.applyFromShortcutInfo(info, mIconCache, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001415 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001416 return favorite;
1417 }
1418
1419 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001420 * Add a shortcut to the workspace.
1421 *
1422 * @param data The intent describing the shortcut.
1423 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001424 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001425 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001426 int cellY) {
1427 int[] cellXY = mTmpAddItemCellCoordinates;
1428 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001429 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001430
Michael Jurkad3ef3062010-11-23 16:23:58 -08001431 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001432
Adam Cohen558baaf2011-08-15 15:22:57 -07001433 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001434 if (info == null) {
1435 return;
1436 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001437 final View view = createShortcut(info);
1438
Adam Cohenfbba09b2011-07-18 21:43:05 -07001439 // First we check if we already know the exact location where we want to add this item.
1440 if (cellX >= 0 && cellY >= 0) {
1441 cellXY[0] = cellX;
1442 cellXY[1] = cellY;
1443 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001444
1445 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001446 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001447 true, null,null)) {
1448 return;
1449 }
1450 DragObject dragObject = new DragObject();
1451 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001452 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1453 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001454 return;
1455 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001456 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001457 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001458 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001459 foundCellSpan = (result != null);
1460 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001461 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001462 }
1463
1464 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001465 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001466 return;
1467 }
1468
Adam Cohendcd297f2013-06-18 13:13:40 -07001469 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001470
1471 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001472 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001473 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001474 }
1475 }
1476
Adam Cohen2f093b62012-04-30 18:59:53 -07001477 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1478 int minHeight) {
1479 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001480 // We want to account for the extra amount of padding that we are adding to the widget
1481 // to ensure that it gets the full amount of space that it has requested
1482 int requiredWidth = minWidth + padding.left + padding.right;
1483 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001484 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001485 }
1486
Adam Cohen2f093b62012-04-30 18:59:53 -07001487 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1488 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001489 }
1490
Adam Cohen2f093b62012-04-30 18:59:53 -07001491 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1492 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001493 }
1494
Adam Cohen2f093b62012-04-30 18:59:53 -07001495 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1496 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001497 }
1498
Adam Cohen2f093b62012-04-30 18:59:53 -07001499 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1500 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001501 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001502 }
1503
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001504 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001505 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001506 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001507 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001508 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001509 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001510 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001511 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1512 if (appWidgetInfo == null) {
1513 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1514 }
Romain Guycbb89e42009-06-08 15:52:54 -07001515
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001516 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001517 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001518
Adam Cohen2f093b62012-04-30 18:59:53 -07001519 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1520 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001521
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001522 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001523 // We have saved the position to which the widget was dragged-- this really only matters
1524 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001525 int[] cellXY = mTmpAddItemCellCoordinates;
1526 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001527 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001528 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001529 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1530 cellXY[0] = mPendingAddInfo.cellX;
1531 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001532 spanXY[0] = mPendingAddInfo.spanX;
1533 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001534 foundCellSpan = true;
1535 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001536 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001537 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001538 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1539 spanXY[1], cellXY, finalSpan);
1540 spanXY[0] = finalSpan[0];
1541 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001542 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001543 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001544 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001545 }
1546
Michael Jurka0280c3b2010-09-17 15:00:07 -07001547 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001548 if (appWidgetId != -1) {
1549 // Deleting an app widget ID is a void call but writes to disk before returning
1550 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001551 new AsyncTask<Void, Void, Void>() {
1552 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001553 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001554 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001555 }
Michael Jurka43467462013-11-14 12:03:58 +01001556 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001557 }
Winson Chung93eef082012-03-23 15:59:27 -07001558 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001559 return;
1560 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001561
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001562 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001563 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1564 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001565 launcherInfo.spanX = spanXY[0];
1566 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001567 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1568 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001569 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001570
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001571 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001572 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001573
1574 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001575 if (hostView == null) {
1576 // Perform actual inflation because we're live
1577 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1578 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1579 } else {
1580 // The AppWidgetHostView has already been inflated and instantiated
1581 launcherInfo.hostView = hostView;
1582 }
Romain Guycbb89e42009-06-08 15:52:54 -07001583
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001584 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001585 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001586 launcherInfo.notifyWidgetSizeChanged(this);
1587
Adam Cohendcd297f2013-06-18 13:13:40 -07001588 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001589 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001590
1591 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001592 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001593 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001594 }
Romain Guycbb89e42009-06-08 15:52:54 -07001595
Adam Cohended9f8d2010-11-03 13:25:16 -07001596 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1597 @Override
1598 public void onReceive(Context context, Intent intent) {
1599 final String action = intent.getAction();
1600 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1601 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001602 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001603 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001604
Winson Chungc100e8e2011-08-09 16:02:43 -07001605 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001606 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001607 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001608 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001609 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001610 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1611 mUserPresent = true;
1612 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001613 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1614 mModel.resetLoadedState(false, true);
1615 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1616 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1617 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1618 mModel.resetLoadedState(false, true);
1619 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1620 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1621 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001622 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1623 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1624 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001625 }
1626 }
1627 };
1628
1629 @Override
1630 public void onAttachedToWindow() {
1631 super.onAttachedToWindow();
1632
1633 // Listen for broadcasts related to user-presence
1634 final IntentFilter filter = new IntentFilter();
1635 filter.addAction(Intent.ACTION_SCREEN_OFF);
1636 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001637 // For handling managed profiles
1638 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1639 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001640 if (ENABLE_DEBUG_INTENTS) {
1641 filter.addAction(DebugIntents.DELETE_DATABASE);
1642 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1643 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001644 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001645 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001646 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001647 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001648 mVisible = true;
1649 }
1650
Adam Cohen0b395352014-06-09 22:54:36 +00001651 /**
1652 * Sets up transparent navigation and status bars in LMP.
1653 * This method is a no-op for other platform versions.
1654 */
1655 @TargetApi(19)
1656 private void setupTransparentSystemBarsForLmp() {
1657 // TODO(sansid): use the APIs directly when compiling against L sdk.
1658 // Currently we use reflection to access the flags and the API to set the transparency
1659 // on the System bars.
1660 if (Utilities.isLmp()) {
1661 try {
1662 getWindow().getAttributes().systemUiVisibility |=
1663 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1664 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1665 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1666 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1667 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1668 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1669 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1670 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1671
1672 Method setStatusBarColorMethod =
1673 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1674 Method setNavigationBarColorMethod =
1675 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1676 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1677 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1678 } catch (NoSuchFieldException e) {
1679 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1680 } catch (NoSuchMethodException ex) {
1681 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1682 } catch (IllegalAccessException e) {
1683 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1684 } catch (IllegalArgumentException e) {
1685 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1686 } catch (InvocationTargetException e) {
1687 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1688 } finally {}
1689 }
1690 }
1691
Adam Cohended9f8d2010-11-03 13:25:16 -07001692 @Override
1693 public void onDetachedFromWindow() {
1694 super.onDetachedFromWindow();
1695 mVisible = false;
1696
Adam Cohend113e0c2010-11-11 10:48:05 -08001697 if (mAttached) {
1698 unregisterReceiver(mReceiver);
1699 mAttached = false;
1700 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001701 updateRunning();
1702 }
1703
1704 public void onWindowVisibilityChanged(int visibility) {
1705 mVisible = visibility == View.VISIBLE;
1706 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001707 // The following code used to be in onResume, but it turns out onResume is called when
1708 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1709 // is a more appropriate event to handle
1710 if (mVisible) {
1711 mAppsCustomizeTabHost.onWindowVisible();
1712 if (!mWorkspaceLoading) {
1713 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001714 // We want to let Launcher draw itself at least once before we force it to build
1715 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001716 // apps is nice and speedy.
1717 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001718 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001719 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001720 if (mStarted) return;
1721 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001722 // We delay the layer building a bit in order to give
1723 // other message processing a time to run. In particular
1724 // this avoids a delay in hiding the IME if it was
1725 // currently shown, because doing that may involve
1726 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001727 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001728 final ViewTreeObserver.OnDrawListener listener = this;
1729 mWorkspace.post(new Runnable() {
1730 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001731 if (mWorkspace != null &&
1732 mWorkspace.getViewTreeObserver() != null) {
1733 mWorkspace.getViewTreeObserver().
1734 removeOnDrawListener(listener);
1735 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001736 }
1737 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001738 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001739 }
1740 });
1741 }
1742 clearTypedText();
1743 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001744 }
1745
1746 private void sendAdvanceMessage(long delay) {
1747 mHandler.removeMessages(ADVANCE_MSG);
1748 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1749 mHandler.sendMessageDelayed(msg, delay);
1750 mAutoAdvanceSentTime = System.currentTimeMillis();
1751 }
1752
1753 private void updateRunning() {
1754 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1755 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1756 mAutoAdvanceRunning = autoAdvanceRunning;
1757 if (autoAdvanceRunning) {
1758 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1759 sendAdvanceMessage(delay);
1760 } else {
1761 if (!mWidgetsToAdvance.isEmpty()) {
1762 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1763 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1764 }
1765 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001766 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001767 }
1768 }
1769 }
1770
1771 private final Handler mHandler = new Handler() {
1772 @Override
1773 public void handleMessage(Message msg) {
1774 if (msg.what == ADVANCE_MSG) {
1775 int i = 0;
1776 for (View key: mWidgetsToAdvance.keySet()) {
1777 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1778 final int delay = mAdvanceStagger * i;
1779 if (v instanceof Advanceable) {
1780 postDelayed(new Runnable() {
1781 public void run() {
1782 ((Advanceable) v).advance();
1783 }
1784 }, delay);
1785 }
1786 i++;
1787 }
1788 sendAdvanceMessage(mAdvanceInterval);
1789 }
1790 }
1791 };
1792
1793 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001794 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001795 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1796 if (v instanceof Advanceable) {
1797 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001798 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001799 updateRunning();
1800 }
1801 }
1802
1803 void removeWidgetToAutoAdvance(View hostView) {
1804 if (mWidgetsToAdvance.containsKey(hostView)) {
1805 mWidgetsToAdvance.remove(hostView);
1806 updateRunning();
1807 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001808 }
1809
Joe Onorato9c1289c2009-08-17 11:03:03 -04001810 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001811 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001812 launcherInfo.hostView = null;
1813 }
1814
Winson Chung93eef082012-03-23 15:59:27 -07001815 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1816 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1817 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001818 }
1819
Winson Chunga6945242014-01-08 14:04:34 -08001820 public DragLayer getDragLayer() {
1821 return mDragLayer;
1822 }
1823
1824 public Workspace getWorkspace() {
1825 return mWorkspace;
1826 }
1827
1828 public Hotseat getHotseat() {
1829 return mHotseat;
1830 }
1831
Jorim Jaggid017f882014-01-14 17:08:48 -08001832 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001833 return mOverviewPanel;
1834 }
1835
1836 public SearchDropTargetBar getSearchBar() {
1837 return mSearchDropTargetBar;
1838 }
1839
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001840 public LauncherAppWidgetHost getAppWidgetHost() {
1841 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001842 }
Romain Guycbb89e42009-06-08 15:52:54 -07001843
Winson Chunga9abd0e2010-10-27 17:18:37 -07001844 public LauncherModel getModel() {
1845 return mModel;
1846 }
1847
Winson Chunga6945242014-01-08 14:04:34 -08001848 protected SharedPreferences getSharedPrefs() {
1849 return mSharedPrefs;
1850 }
1851
Bjorn Bringertc459e522013-06-07 19:36:01 +01001852 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001853 getWindow().closeAllPanels();
1854
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001855 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001856 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001857 }
1858
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001859 @Override
1860 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001861 long startTime = 0;
1862 if (DEBUG_RESUME_TIME) {
1863 startTime = System.currentTimeMillis();
1864 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001865 super.onNewIntent(intent);
1866
1867 // Close the menu
1868 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001869 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001870 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001871
Adam Cohened307df2013-10-02 09:37:31 -07001872 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1873 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1874 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001875
Adam Cohen6fecd412013-10-02 17:41:50 -07001876 if (mWorkspace == null) {
1877 // Can be cases where mWorkspace is null, this prevents a NPE
1878 return;
1879 }
1880 Folder openFolder = mWorkspace.getOpenFolder();
1881 // In all these cases, only animate if we're already on home
1882 mWorkspace.exitWidgetResizeMode();
1883 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001884 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001885 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001886 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001887
Adam Cohen6fecd412013-10-02 17:41:50 -07001888 closeFolder();
1889 exitSpringLoadedDragMode();
1890
1891 // If we are already on home, then just animate back to the workspace,
1892 // otherwise, just wait until onResume to set the state back to Workspace
1893 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001894 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001895 } else {
1896 mOnResumeState = State.WORKSPACE;
1897 }
1898
1899 final View v = getWindow().peekDecorView();
1900 if (v != null && v.getWindowToken() != null) {
1901 InputMethodManager imm = (InputMethodManager)getSystemService(
1902 INPUT_METHOD_SERVICE);
1903 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1904 }
1905
1906 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001907 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001908 mAppsCustomizeTabHost.reset();
1909 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001910
1911 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001912 }
Adam Cohened307df2013-10-02 09:37:31 -07001913
Michael Jurka447bf842013-05-15 14:52:15 +02001914 if (DEBUG_RESUME_TIME) {
1915 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1916 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001917 }
1918
Adam Coppa120b8e2013-11-12 16:26:04 +00001919 /**
1920 * Override point for subclasses to prevent movement to the default screen when the home
1921 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1922 */
1923 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1924 return true;
1925 }
1926
1927 /**
1928 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1929 */
1930 protected void onHomeIntent() {
1931 // Do nothing
1932 }
1933
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001934 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001935 public void onRestoreInstanceState(Bundle state) {
1936 super.onRestoreInstanceState(state);
1937 for (int page: mSynchronouslyBoundPages) {
1938 mWorkspace.restoreInstanceStateForChild(page);
1939 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001940 }
1941
1942 @Override
1943 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001944 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001945 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1946 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001947 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001948 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001949
Michael Jurka883f55b2010-10-21 15:47:14 -07001950 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001951 // We close any open folder since it will not be re-opened, and we need to make sure
1952 // this state is reflected.
1953 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001954
Adam Cohendcd297f2013-06-18 13:13:40 -07001955 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001956 mWaitingForResult) {
1957 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001958 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001959 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1960 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001961 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1962 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1963 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001964 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001965 }
1966
1967 if (mFolderInfo != null && mWaitingForResult) {
1968 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1969 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1970 }
Michael Jurka946ad472010-07-09 18:05:18 -07001971
Winson Chung785d2eb2011-04-14 16:08:02 -07001972 // Save the current AppsCustomize tab
1973 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c62013-11-06 15:49:51 -08001974 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1975 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001976 if (currentTabTag != null) {
1977 outState.putString("apps_customize_currentTab", currentTabTag);
1978 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001979 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1980 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001981 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001982 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001983 }
1984
1985 @Override
1986 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001987 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001988
Winson Chunge7a03942011-08-05 15:05:12 -07001989 // Remove all pending runnables
1990 mHandler.removeMessages(ADVANCE_MSG);
1991 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001992 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001993
Winson Chungcd2b0142011-06-08 16:02:26 -07001994 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001995 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001996 mModel.stopLoader();
1997 app.setLauncher(null);
1998
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001999 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002000 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002001 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002002 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002003 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002004 mAppWidgetHost = null;
2005
2006 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002007
2008 TextKeyListener.getInstance().release();
2009
Winson Chung81b52252012-08-27 15:34:29 -07002010 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2011 // to prevent leaking Launcher activities on orientation change.
2012 if (mModel != null) {
2013 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2014 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002015
2016 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002017 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002018
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002019 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002020 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002021 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002022 mWorkspace = null;
2023 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002024
Sunny Goyale755d462014-07-22 13:48:29 -07002025 PackageInstallerCompat.getInstance(this).onStop();
Michael Jurka2ecf9952012-06-18 12:52:28 -07002026 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002027 }
2028
Adam Cohena9cf38f2011-05-02 15:36:58 -07002029 public DragController getDragController() {
2030 return mDragController;
2031 }
2032
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002033 @Override
2034 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002035 if (requestCode >= 0) {
2036 setWaitingForResult(true);
2037 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002038 super.startActivityForResult(intent, requestCode);
2039 }
2040
Winson Chung70d72102011-08-12 11:24:35 -07002041 /**
2042 * Indicates that we want global search for this activity by setting the globalSearch
2043 * argument for {@link #startSearch} to true.
2044 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002045 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002046 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002047 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002048
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002049 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002050
Karl Rosaen138a0412009-04-23 19:00:21 -07002051 if (initialQuery == null) {
2052 // Use any text typed in the launcher as the initial query
2053 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002054 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002055 if (appSearchData == null) {
2056 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002057 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002058 }
Winson Chungadf0c182012-08-23 14:59:07 -07002059 Rect sourceBounds = new Rect();
2060 if (mSearchDropTargetBar != null) {
2061 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2062 }
Romain Guycbb89e42009-06-08 15:52:54 -07002063
Bjorn Bringertc459e522013-06-07 19:36:01 +01002064 startSearch(initialQuery, selectInitialQuery,
2065 appSearchData, sourceBounds);
2066 }
2067
2068 public void startSearch(String initialQuery,
2069 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002070 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002071 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07002072 }
2073
2074 /**
2075 * Starts the global search activity. This code is a copied from SearchManager
2076 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002077 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002078 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002079 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002080 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2081 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2082 if (globalSearchActivity == null) {
2083 Log.w(TAG, "No global search activity found.");
2084 return;
2085 }
2086 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2087 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2088 intent.setComponent(globalSearchActivity);
2089 // Make sure that we have a Bundle to put source in
2090 if (appSearchData == null) {
2091 appSearchData = new Bundle();
2092 } else {
2093 appSearchData = new Bundle(appSearchData);
2094 }
2095 // Set source to package name of app that starts global search, if not set already.
2096 if (!appSearchData.containsKey("source")) {
2097 appSearchData.putString("source", getPackageName());
2098 }
2099 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2100 if (!TextUtils.isEmpty(initialQuery)) {
2101 intent.putExtra(SearchManager.QUERY, initialQuery);
2102 }
2103 if (selectInitialQuery) {
2104 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2105 }
2106 intent.setSourceBounds(sourceBounds);
2107 try {
2108 startActivity(intent);
2109 } catch (ActivityNotFoundException ex) {
2110 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2111 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002112 }
2113
Yura4f93ec62014-02-04 14:15:21 +00002114 public boolean isOnCustomContent() {
2115 return mWorkspace.isOnOrMovingToCustomContent();
2116 }
2117
Winson Chung70d72102011-08-12 11:24:35 -07002118 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002119 public boolean onPrepareOptionsMenu(Menu menu) {
2120 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002121 if (!isOnCustomContent()) {
2122 // Close any open folders
2123 closeFolder();
2124 // Stop resizing any widgets
2125 mWorkspace.exitWidgetResizeMode();
2126 if (!mWorkspace.isInOverviewMode()) {
2127 // Show the overview mode
2128 showOverviewMode(true);
2129 } else {
2130 showWorkspace(true);
2131 }
Winson Chunge0298742014-01-17 12:03:00 -08002132 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002133 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002134 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002135
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002136 @Override
2137 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002138 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002139 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002140 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002141 }
2142
Joe Onorato9c1289c2009-08-17 11:03:03 -04002143 public boolean isWorkspaceLocked() {
2144 return mWorkspaceLoading || mWaitingForResult;
2145 }
2146
Adam Cohen517a7f52014-03-01 12:12:59 -08002147 public boolean isWorkspaceLoading() {
2148 return mWorkspaceLoading;
2149 }
2150
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002151 private void setWorkspaceLoading(boolean value) {
2152 boolean isLocked = isWorkspaceLocked();
2153 mWorkspaceLoading = value;
2154 if (isLocked != isWorkspaceLocked()) {
2155 onWorkspaceLockedChanged();
2156 }
2157 }
2158
2159 private void setWaitingForResult(boolean value) {
2160 boolean isLocked = isWorkspaceLocked();
2161 mWaitingForResult = value;
2162 if (isLocked != isWorkspaceLocked()) {
2163 onWorkspaceLockedChanged();
2164 }
2165 }
2166
2167 protected void onWorkspaceLockedChanged() { }
2168
Michael Jurka0280c3b2010-09-17 15:00:07 -07002169 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002170 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002171 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002172 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2173 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002174 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002175 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002176 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002177
Adam Cohenad4e15c2013-10-17 16:21:35 -07002178 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2179 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2180 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2181 }
2182
2183 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2184 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2185 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002186 if (appWidgetInfo.configure != null) {
2187 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002188 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002189
Bjorn Bringert7984c942009-12-09 15:38:25 +00002190 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002191 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2192 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2193
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002194 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002195 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002196 Runnable onComplete = new Runnable() {
2197 @Override
2198 public void run() {
2199 // Exit spring loaded mode if necessary after adding the widget
2200 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2201 null);
2202 }
2203 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002204 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002205 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002206 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002207 }
2208 }
Romain Guycbb89e42009-06-08 15:52:54 -07002209
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002210 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002211 // Close any folders that may be open.
2212 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002213 mWorkspace.moveToCustomContentScreen(animate);
2214 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002215 /**
2216 * Process a shortcut drop.
2217 *
2218 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002219 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002220 * @param cell The cell it should be added to, optional
2221 * @param position The location on the screen where it was dropped, optional
2222 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002223 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002224 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002225 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002226 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002227 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002228 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002229
2230 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002231 mPendingAddInfo.cellX = cell[0];
2232 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002233 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002234
2235 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2236 createShortcutIntent.setComponent(componentName);
2237 processShortcut(createShortcutIntent);
2238 }
2239
Adam Cohenfbba09b2011-07-18 21:43:05 -07002240 /**
2241 * Process a widget drop.
2242 *
2243 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002244 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002245 * @param cell The cell it should be added to, optional
2246 * @param position The location on the screen where it was dropped, optional
2247 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002248 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002249 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002250 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002251 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002252 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002253 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002254 mPendingAddInfo.minSpanX = info.minSpanX;
2255 mPendingAddInfo.minSpanY = info.minSpanY;
2256
Adam Cohenfbba09b2011-07-18 21:43:05 -07002257 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002258 mPendingAddInfo.cellX = cell[0];
2259 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002260 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002261 if (span != null) {
2262 mPendingAddInfo.spanX = span[0];
2263 mPendingAddInfo.spanY = span[1];
2264 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002265
Adam Cohened66b2b2012-01-23 17:28:51 -08002266 AppWidgetHostView hostView = info.boundWidget;
2267 int appWidgetId;
2268 if (hostView != null) {
2269 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002270 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002271 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002272 // In this case, we either need to start an activity to get permission to bind
2273 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002274 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002275 Bundle options = info.bindOptions;
2276
Sunny Goyalffe83f12014-08-14 17:39:34 -07002277 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2278 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002279 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002280 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002281 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002282 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002283 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2284 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2285 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002286 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2287 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002288 // TODO: we need to make sure that this accounts for the options bundle.
2289 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002290 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2291 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002292 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002293 }
2294
Joe Onoratodeb98af2010-02-19 14:59:39 -08002295 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002296 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002297 }
2298
Winson Chung24ab2f12010-09-16 14:10:47 -07002299 void processWallpaper(Intent intent) {
2300 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2301 }
2302
Adam Cohendcd297f2013-06-18 13:13:40 -07002303 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002304 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002305 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002306 folderInfo.title = getText(R.string.folder_name);
2307
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002308 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002309 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002310 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002311 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002312
2313 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002314 FolderIcon newFolder =
2315 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002316 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002317 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002318 // Force measure the new folder icon
2319 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2320 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002321 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002322 }
Romain Guycbb89e42009-06-08 15:52:54 -07002323
Joe Onorato9c1289c2009-08-17 11:03:03 -04002324 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002325 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002326 }
2327
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002328 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002329 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002330 }
2331
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002332 /**
2333 * Registers various content observers. The current implementation registers
2334 * only a favorites observer to keep track of the favorites applications.
2335 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002336 private void registerContentObservers() {
2337 ContentResolver resolver = getContentResolver();
2338 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2339 true, mWidgetObserver);
2340 }
2341
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002342 @Override
2343 public boolean dispatchKeyEvent(KeyEvent event) {
2344 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2345 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002346 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002347 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002348 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002349 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002350 dumpState();
2351 return true;
2352 }
2353 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002354 }
2355 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2356 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002357 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002358 return true;
2359 }
2360 }
2361
2362 return super.dispatchKeyEvent(event);
2363 }
2364
Joe Onorato88ec0992009-11-19 13:16:06 -08002365 @Override
2366 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002367 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002368 if (mAppsCustomizeContent.getContentType() ==
2369 AppsCustomizePagedView.ContentType.Applications) {
2370 showWorkspace(true);
2371 } else {
2372 showOverviewMode(true);
2373 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002374 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002375 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002376 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002377 Folder openFolder = mWorkspace.getOpenFolder();
2378 if (openFolder.isEditingName()) {
2379 openFolder.dismissEditingName();
2380 } else {
2381 closeFolder();
2382 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002383 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002384 mWorkspace.exitWidgetResizeMode();
2385
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002386 // Back button is a no-op here, but give at least some feedback for the button press
2387 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002388 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002389 }
2390
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002391 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002392 * Re-listen when widgets are reset.
2393 */
2394 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002395 if (mAppWidgetHost != null) {
2396 mAppWidgetHost.startListening();
2397 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002398 }
2399
2400 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002401 * Launches the intent referred by the clicked shortcut.
2402 *
2403 * @param v The view representing the clicked shortcut.
2404 */
2405 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002406 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2407 // view has detached (it's possible for this to happen if the view is removed mid touch).
2408 if (v.getWindowToken() == null) {
2409 return;
2410 }
2411
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002412 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002413 return;
2414 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002415
Adam Cohen1697b792013-09-17 19:08:21 -07002416 if (v instanceof Workspace) {
2417 if (mWorkspace.isInOverviewMode()) {
2418 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002419 }
2420 return;
2421 }
2422
2423 if (v instanceof CellLayout) {
2424 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002425 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002426 }
2427 }
2428
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002429 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002430 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002431 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002432 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002433 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002434 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002435 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002436 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002437 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002438 } else if (tag instanceof AppInfo) {
2439 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002440 } else if (tag instanceof LauncherAppWidgetInfo) {
2441 if (v instanceof PendingAppWidgetHostView) {
2442 onClickPendingWidget((PendingAppWidgetHostView) v);
2443 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002444 }
2445 }
2446
Sunny Goyal508da152014-08-14 10:53:27 -07002447 public void onClickPagedViewIcon(View v) {
2448 startAppShortcutOrInfoActivity(v);
2449 }
2450
Michael Jurka0e260592010-06-30 17:07:39 -07002451 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002452 return false;
2453 }
2454
Michael Jurkaaf442092010-06-10 17:01:57 -07002455 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002456 * Event handler for the app widget view which has not fully restored.
2457 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002458 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
2459 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002460 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002461 int widgetId = info.appWidgetId;
2462 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2463 if (appWidgetInfo != null) {
2464 mPendingAddWidgetInfo = appWidgetInfo;
2465 mPendingAddInfo.copyFrom(info);
2466 mPendingAddWidgetId = widgetId;
2467
Sunny Goyalffe83f12014-08-14 17:39:34 -07002468 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2469 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002470 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002471 } else if (info.installProgress < 0) {
2472 // The install has not been queued
2473 final String packageName = info.providerName.getPackageName();
2474 showBrokenAppInstallDialog(packageName,
2475 new DialogInterface.OnClickListener() {
2476 public void onClick(DialogInterface dialog, int id) {
2477 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2478 }
2479 });
2480 } else {
2481 // Download has started.
2482 final String packageName = info.providerName.getPackageName();
2483 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002484 }
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
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002542 private void showBrokenAppInstallDialog(final String packageName,
2543 DialogInterface.OnClickListener onSearchClickListener) {
2544 new AlertDialog.Builder(this)
2545 .setTitle(R.string.abandoned_promises_title)
2546 .setMessage(R.string.abandoned_promise_explanation)
2547 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2548 .setNeutralButton(R.string.abandoned_clean_this,
2549 new DialogInterface.OnClickListener() {
2550 public void onClick(DialogInterface dialog, int id) {
2551 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2552 mWorkspace.removeAbandonedPromise(packageName, user);
2553 }
2554 })
2555 .create().show();
2556 return;
2557 }
2558
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002559 /**
2560 * Event handler for an app shortcut click.
2561 *
2562 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2563 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002564 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002565 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2566 Object tag = v.getTag();
2567 if (!(tag instanceof ShortcutInfo)) {
2568 throw new IllegalArgumentException("Input must be a Shortcut");
2569 }
2570
2571 // Open shortcut
2572 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2573 final Intent intent = shortcut.intent;
2574
2575 // Check for special shortcuts
2576 if (intent.getComponent() != null) {
2577 final String shortcutClass = intent.getComponent().getClassName();
2578
2579 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2580 MemoryDumpActivity.startDump(this);
2581 return;
2582 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2583 toggleShowWeightWatcher();
2584 return;
2585 }
2586 }
2587
Chris Wren40c5ed32014-06-24 18:24:23 -04002588 // Check for abandoned promise
2589 if (shortcut.isAbandoned() && v instanceof BubbleTextView) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002590 showBrokenAppInstallDialog(
2591 shortcut.getRestoredIntent().getComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002592 new DialogInterface.OnClickListener() {
2593 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002594 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002595 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002596 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002597 return;
2598 }
2599
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002600 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002601 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002602 }
2603
Sunny Goyal508da152014-08-14 10:53:27 -07002604 private void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002605 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002606 final ShortcutInfo shortcut;
2607 final Intent intent;
2608 if (tag instanceof ShortcutInfo) {
2609 shortcut = (ShortcutInfo) tag;
2610 intent = shortcut.intent;
2611 int[] pos = new int[2];
2612 v.getLocationOnScreen(pos);
2613 intent.setSourceBounds(new Rect(pos[0], pos[1],
2614 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002615
Sunny Goyal508da152014-08-14 10:53:27 -07002616 } else if (tag instanceof AppInfo) {
2617 shortcut = null;
2618 intent = ((AppInfo) tag).intent;
2619 } else {
2620 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2621 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002622
2623 boolean success = startActivitySafely(v, intent, tag);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002624 mStats.recordLaunch(intent, shortcut);
2625
2626 if (success && v instanceof BubbleTextView) {
2627 mWaitingForResume = (BubbleTextView) v;
2628 mWaitingForResume.setStayPressed(true);
2629 }
2630 }
2631
2632 /**
2633 * Event handler for a folder icon click.
2634 *
2635 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2636 */
2637 protected void onClickFolderIcon(View v) {
2638 if (LOGD) Log.d(TAG, "onClickFolder");
2639 if (!(v instanceof FolderIcon)){
2640 throw new IllegalArgumentException("Input must be a FolderIcon");
2641 }
2642
2643 FolderIcon folderIcon = (FolderIcon) v;
2644 final FolderInfo info = folderIcon.getFolderInfo();
2645 Folder openFolder = mWorkspace.getFolderForTag(info);
2646
2647 // If the folder info reports that the associated folder is open, then verify that
2648 // it is actually opened. There have been a few instances where this gets out of sync.
2649 if (info.opened && openFolder == null) {
2650 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2651 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2652 info.opened = false;
2653 }
2654
2655 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2656 // Close any open folder
2657 closeFolder();
2658 // Open the requested folder
2659 openFolder(folderIcon);
2660 } else {
2661 // Find the open folder...
2662 int folderScreen;
2663 if (openFolder != null) {
2664 folderScreen = mWorkspace.getPageForView(openFolder);
2665 // .. and close it
2666 closeFolder(openFolder);
2667 if (folderScreen != mWorkspace.getCurrentPage()) {
2668 // Close any folder open on the current screen
2669 closeFolder();
2670 // Pull the folder onto this screen
2671 openFolder(folderIcon);
2672 }
2673 }
2674 }
Michael Jurka5130e402011-10-13 04:55:35 -07002675 }
2676
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002677 /**
2678 * Event handler for the (Add) Widgets button that appears after a long press
2679 * on the home screen.
2680 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002681 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002682 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002683 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2684 }
2685
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002686 /**
2687 * Event handler for the wallpaper picker button that appears after a long press
2688 * on the home screen.
2689 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002690 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002691 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2692 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2693 pickWallpaper.setComponent(getWallpaperPickerComponent());
2694 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2695 }
2696
2697 /**
2698 * Event handler for a click on the settings button that appears after a long press
2699 * on the home screen.
2700 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002701 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002702 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2703 }
2704
Michael Jurka5130e402011-10-13 04:55:35 -07002705 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002706 // Provide the same haptic feedback that the system offers for virtual keys.
2707 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002708 }
2709
Adam Cohen61f560d2013-09-30 15:58:20 -07002710 public void performHapticFeedbackOnTouchDown(View v) {
2711 // Provide the same haptic feedback that the system offers for virtual keys.
2712 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2713 }
2714
2715 public View.OnTouchListener getHapticFeedbackTouchListener() {
2716 if (mHapticFeedbackTouchListener == null) {
2717 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2718 @Override
2719 public boolean onTouch(View v, MotionEvent event) {
2720 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2721 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2722 }
2723 return false;
2724 }
2725 };
2726 }
2727 return mHapticFeedbackTouchListener;
2728 }
2729
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002730 public void onDragStarted(View view) {}
2731
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002732 /**
2733 * Called when the user stops interacting with the launcher.
2734 * This implies that the user is now on the homescreen and is not doing housekeeping.
2735 */
2736 protected void onInteractionEnd() {}
2737
2738 /**
2739 * Called when the user starts interacting with the launcher.
2740 * The possible interactions are:
2741 * - open all apps
2742 * - reorder an app shortcut, or a widget
2743 * - open the overview mode.
2744 * This is a good time to stop doing things that only make sense
2745 * when the user is on the homescreen and not doing housekeeping.
2746 */
2747 protected void onInteractionBegin() {}
2748
Kenny Guyf07af7b2014-07-31 11:39:16 +01002749 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002750 String packageName = componentName.getPackageName();
Kenny Guyf07af7b2014-07-31 11:39:16 +01002751 try {
2752 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2753 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2754 launcherApps.showAppDetailsForProfile(componentName, user);
2755 } catch (SecurityException e) {
2756 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2757 Log.e(TAG, "Launcher does not have permission to launch settings");
2758 } catch (ActivityNotFoundException e) {
2759 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2760 Log.e(TAG, "Unable to launch settings");
2761 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002762 }
2763
Michael Jurka1e2f4652013-07-08 18:03:46 -07002764 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002765 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2766 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002767 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002768 // System applications cannot be installed. For now, show a toast explaining that.
2769 // We may give them the option of disabling apps this way.
2770 int messageId = R.string.uninstall_system_app_text;
2771 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002772 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002773 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002774 String packageName = componentName.getPackageName();
2775 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002776 Intent intent = new Intent(
2777 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002778 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2779 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002780 if (user != null) {
2781 user.addToIntent(intent, Intent.EXTRA_USER);
2782 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002783 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002784 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002785 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002786 }
2787
Michael Jurka86a720e2012-05-09 11:23:23 -07002788 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002789 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002790 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002791 // Only launch using the new animation if the shortcut has not opted out (this is a
2792 // private contract between launcher and may be ignored in the future).
2793 boolean useLaunchAnimation = (v != null) &&
2794 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002795 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2796 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002797
Kenny Guy1317e2d2014-05-08 18:52:50 +01002798 UserHandleCompat user = null;
2799 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2800 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2801 user = userManager.getUserForSerialNumber(serialNumber);
2802 }
2803
2804 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002805 if (useLaunchAnimation) {
Adam Cohen4da294d2014-07-28 10:56:19 -07002806 ActivityOptions opts = Utilities.isLmp() ?
2807 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) :
2808 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Adam Cohen6ea3b112014-06-11 11:38:49 -07002809 optsBundle = opts.toBundle();
2810 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002811
2812 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2813 // Could be launching some bookkeeping activity
2814 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002815 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002816 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002817 launcherApps.startActivityForProfile(intent.getComponent(), user,
2818 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002819 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002820 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002821 } catch (SecurityException e) {
2822 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002823 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002824 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002825 "or use the exported attribute for this activity. "
2826 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002827 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002828 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002829 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002830
Michael Jurka86a720e2012-05-09 11:23:23 -07002831 boolean startActivitySafely(View v, Intent intent, Object tag) {
2832 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002833 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2834 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2835 return false;
2836 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002837 try {
2838 success = startActivity(v, intent, tag);
2839 } catch (ActivityNotFoundException e) {
2840 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2841 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2842 }
2843 return success;
2844 }
2845
Adam Cohen268c4752012-06-06 17:47:33 -07002846 /**
2847 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2848 * in the DragLayer in the exact absolute location of the original FolderIcon.
2849 */
2850 private void copyFolderIconToImage(FolderIcon fi) {
2851 final int width = fi.getMeasuredWidth();
2852 final int height = fi.getMeasuredHeight();
2853
2854 // Lazy load ImageView, Bitmap and Canvas
2855 if (mFolderIconImageView == null) {
2856 mFolderIconImageView = new ImageView(this);
2857 }
2858 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2859 mFolderIconBitmap.getHeight() != height) {
2860 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2861 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2862 }
2863
2864 DragLayer.LayoutParams lp;
2865 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2866 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2867 } else {
2868 lp = new DragLayer.LayoutParams(width, height);
2869 }
2870
Adam Cohen307fe232012-08-16 17:55:58 -07002871 // The layout from which the folder is being opened may be scaled, adjust the starting
2872 // view size by this scale factor.
2873 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002874 lp.customPosition = true;
2875 lp.x = mRectForFolderAnimation.left;
2876 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002877 lp.width = (int) (scale * width);
2878 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002879
2880 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2881 fi.draw(mFolderIconCanvas);
2882 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002883 if (fi.getFolder() != null) {
2884 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2885 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002886 }
Adam Cohen268c4752012-06-06 17:47:33 -07002887 // Just in case this image view is still in the drag layer from a previous animation,
2888 // we remove it and re-add it.
2889 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2890 mDragLayer.removeView(mFolderIconImageView);
2891 }
2892 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002893 if (fi.getFolder() != null) {
2894 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002895 }
Adam Cohen268c4752012-06-06 17:47:33 -07002896 }
2897
Adam Cohen2801caf2011-05-13 20:57:39 -07002898 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002899 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002900 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2901 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2902 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2903
Adam Cohenc51934b2011-07-26 21:07:43 -07002904 FolderInfo info = (FolderInfo) fi.getTag();
2905 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2906 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002907 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2908 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002909 }
2910
Adam Cohen268c4752012-06-06 17:47:33 -07002911 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2912 copyFolderIconToImage(fi);
2913 fi.setVisibility(View.INVISIBLE);
2914
Michael Jurka2ecf9952012-06-18 12:52:28 -07002915 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002916 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002917 if (Utilities.isLmp()) {
2918 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
2919 }
2920 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07002921 oa.start();
2922 }
2923
Adam Cohen268c4752012-06-06 17:47:33 -07002924 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002925 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002926 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2927 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2928 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2929
Adam Cohen268c4752012-06-06 17:47:33 -07002930 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002931
Adam Cohen268c4752012-06-06 17:47:33 -07002932 // We remove and re-draw the FolderIcon in-case it has changed
2933 mDragLayer.removeView(mFolderIconImageView);
2934 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002935 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002936 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002937 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002938 oa.addListener(new AnimatorListenerAdapter() {
2939 @Override
2940 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002941 if (cl != null) {
2942 cl.clearFolderLeaveBehind();
2943 // Remove the ImageView copy of the FolderIcon and make the original visible.
2944 mDragLayer.removeView(mFolderIconImageView);
2945 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002946 }
2947 }
2948 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002949 oa.start();
2950 }
2951
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002952 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002953 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002954 * is animated relative to the specified View. If the View is null, no animation
2955 * is played.
2956 *
2957 * @param folderInfo The FolderInfo describing the folder to open.
2958 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002959 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002960 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002961 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002962
Adam Cohena9cf38f2011-05-02 15:36:58 -07002963 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002964
Adam Cohen4554ee12011-08-03 16:13:21 -07002965 // Just verify that the folder hasn't already been added to the DragLayer.
2966 // There was a one-off crash where the folder had a parent already.
2967 if (folder.getParent() == null) {
2968 mDragLayer.addView(folder);
2969 mDragController.addDropTarget((DropTarget) folder);
2970 } else {
2971 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2972 folder.getParent() + ").");
2973 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002974 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002975 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002976
2977 // Notify the accessibility manager that this folder "window" has appeared and occluded
2978 // the workspace items
2979 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2980 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002981 }
2982
2983 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002984 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002985 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002986 if (folder.isEditingName()) {
2987 folder.dismissEditingName();
2988 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002989 closeFolder(folder);
2990 }
2991 }
2992
2993 void closeFolder(Folder folder) {
2994 folder.getInfo().opened = false;
2995
2996 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2997 if (parent != null) {
2998 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2999 shrinkAndFadeInFolderIcon(fi);
3000 }
3001 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003002
3003 // Notify the accessibility manager that this folder "window" has disappeard and no
3004 // longer occludeds the workspace items
3005 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003006 }
3007
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003008 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003009 if (!isDraggingEnabled()) return false;
3010 if (isWorkspaceLocked()) return false;
3011 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003012
Adam Cohen1697b792013-09-17 19:08:21 -07003013 if (v instanceof Workspace) {
3014 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07003015 if (mWorkspace.enterOverviewMode()) {
3016 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3017 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3018 return true;
3019 } else {
3020 return false;
3021 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003022 } else {
3023 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003024 }
Adam Cohen1697b792013-09-17 19:08:21 -07003025 }
3026
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003027 CellLayout.CellInfo longClickCellInfo = null;
3028 View itemUnderLongClick = null;
3029 if (v.getTag() instanceof ItemInfo) {
3030 ItemInfo info = (ItemInfo) v.getTag();
3031 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3032 itemUnderLongClick = longClickCellInfo.cell;
3033 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003034 }
3035
Winson Chung3d503fb2011-07-13 17:25:49 -07003036 // The hotseat touch handling does not go through Workspace, and we always allow long press
3037 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003038 final boolean inHotseat = isHotseatLayout(v);
3039 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07003040 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003041 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003042 // User long pressed on empty space
3043 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3044 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003045 if (mWorkspace.isInOverviewMode()) {
3046 mWorkspace.startReordering(v);
3047 } else {
3048 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07003049 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003050 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003051 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3052 mHotseat.getOrderInHotseat(
3053 longClickCellInfo.cellX,
3054 longClickCellInfo.cellY));
3055 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003056 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003057 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003058 }
3059 }
3060 }
3061 return true;
3062 }
3063
Winson Chung3d503fb2011-07-13 17:25:49 -07003064 boolean isHotseatLayout(View layout) {
3065 return mHotseat != null && layout != null &&
3066 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3067 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003068
Winson Chung3d503fb2011-07-13 17:25:49 -07003069 /**
3070 * Returns the CellLayout of the specified container at the specified screen.
3071 */
Adam Cohendcd297f2013-06-18 13:13:40 -07003072 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003073 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3074 if (mHotseat != null) {
3075 return mHotseat.getLayout();
3076 } else {
3077 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003078 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003079 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07003080 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003081 }
3082 }
3083
Daniel Sandler843e8602010-06-07 14:59:01 -04003084 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003085 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003086 }
3087
Craig Mautner360310b2012-10-26 15:13:08 -07003088 private void setWorkspaceBackground(boolean workspace) {
3089 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003090 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003091 }
3092
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003093 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003094 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3095 int curflags = getWindow().getAttributes().flags
3096 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3097 if (wpflags != curflags) {
3098 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3099 }
Craig Mautner360310b2012-10-26 15:13:08 -07003100 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003101 }
3102
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003103 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3104 if (v instanceof LauncherTransitionable) {
3105 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3106 }
3107 }
3108
Michael Jurkabed61d22012-02-14 22:51:29 -08003109 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3110 if (v instanceof LauncherTransitionable) {
3111 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3112 }
Winson Chung70442722012-02-10 15:43:22 -08003113
3114 // Update the workspace transition step as well
3115 dispatchOnLauncherTransitionStep(v, 0f);
3116 }
3117
3118 private void dispatchOnLauncherTransitionStep(View v, float t) {
3119 if (v instanceof LauncherTransitionable) {
3120 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3121 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003122 }
3123
3124 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3125 if (v instanceof LauncherTransitionable) {
3126 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3127 }
Winson Chung70442722012-02-10 15:43:22 -08003128
3129 // Update the workspace transition step as well
3130 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003131 }
3132
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003133 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003134 * Things to test when changing the following seven functions.
3135 * - Home from workspace
3136 * - from center screen
3137 * - from other screens
3138 * - Home from all apps
3139 * - from center screen
3140 * - from other screens
3141 * - Back from all apps
3142 * - from center screen
3143 * - from other screens
3144 * - Launch app from workspace and quit
3145 * - with back
3146 * - with home
3147 * - Launch app from all apps and quit
3148 * - with back
3149 * - with home
3150 * - Go to a screen that's not the default, then all
3151 * apps, and launch and app, and go back
3152 * - with back
3153 * -with home
3154 * - On workspace, long press power and go back
3155 * - with back
3156 * - with home
3157 * - On all apps, long press power and go back
3158 * - with back
3159 * - with home
3160 * - On workspace, power off
3161 * - On all apps, power off
3162 * - Launch an app and turn off the screen while in that app
3163 * - Go back with home key
3164 * - Go back with back key TODO: make this not go to workspace
3165 * - From all apps
3166 * - From workspace
3167 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3168 * - From all apps
3169 * - From the center workspace
3170 * - From another workspace
3171 */
3172
3173 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003174 * Zoom the camera out from the workspace to reveal 'toView'.
3175 * Assumes that the view to show is anchored at either the very top or very bottom
3176 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003177 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003178 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003179 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3180 showAppsCustomizeHelper(animated, springLoaded, contentType);
3181 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003182
Winson Chungc58497e2013-09-03 17:48:37 -07003183 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3184 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003185 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003186 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003187 mStateAnimation.cancel();
3188 mStateAnimation = null;
3189 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003190
3191 boolean material = Utilities.isLmp();
3192
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003193 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003194
Winson Chungf0ea4d32011-06-06 14:27:16 -07003195 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3196 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003197 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003198 final int itemsAlphaStagger =
3199 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003200
Winson Chungf0ea4d32011-06-06 14:27:16 -07003201 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003202 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003203 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07003204
Adam Cohen6c5891a2014-07-09 23:53:15 -07003205 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3206 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003207 Animator workspaceAnim =
Adam Cohen6c5891a2014-07-09 23:53:15 -07003208 mWorkspace.getChangeStateAnimation(workspaceState, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003209 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003210 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3211 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003212 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3213 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003214
3215 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003216 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen61033d32010-11-15 18:29:44 -08003217
Adam Cohen9bfdb762014-07-21 17:44:06 -07003218 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3219 toView.findViewById(R.id.apps_customize_pane_content);
Adam Cohenf16e5712011-01-13 13:31:45 -08003220
Adam Cohen9bfdb762014-07-21 17:44:06 -07003221 final View page = content.getPageAt(content.getCurrentPage());
3222 final View revealView = toView.findViewById(R.id.fake_page);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003223
Adam Cohen63f1ec02014-08-12 09:23:13 -07003224 final float initialPanelAlpha = 1f;
3225
3226 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3227 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003228 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3229 } else {
3230 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3231 }
3232
Adam Cohen9bfdb762014-07-21 17:44:06 -07003233 // Hide the real page background, and swap in the fake one
3234 revealView.setVisibility(View.VISIBLE);
3235 content.setPageBackgroundsVisible(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003236
Adam Cohen9bfdb762014-07-21 17:44:06 -07003237 int width = revealView.getMeasuredWidth();
3238 int height = revealView.getMeasuredHeight();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003239
Adam Cohen9bfdb762014-07-21 17:44:06 -07003240 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003241 revealView.setTranslationY(0);
Adam Cohen94afab42014-08-24 16:10:54 -07003242 revealView.setTranslationX(0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003243
Adam Cohen63f1ec02014-08-12 09:23:13 -07003244 // Get the y delta between the center of the page and the center of the all apps button
3245 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3246 getAllAppsButton(), null);
3247 float yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
Adam Cohen94afab42014-08-24 16:10:54 -07003248 float xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
Adam Cohen63f1ec02014-08-12 09:23:13 -07003249
3250 float initAlpha = isWidgetTray ? 0.3f : 1f;
Adam Cohen9bfdb762014-07-21 17:44:06 -07003251 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003252 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
Adam Cohen94afab42014-08-24 16:10:54 -07003253 PropertyValuesHolder panelDriftY =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003254 PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
Adam Cohen94afab42014-08-24 16:10:54 -07003255 PropertyValuesHolder panelDriftX =
3256 PropertyValuesHolder.ofFloat("translationX", xDrift, 0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003257
Adam Cohen9bfdb762014-07-21 17:44:06 -07003258 ObjectAnimator panelAlphaAndDrift =
Adam Cohen94afab42014-08-24 16:10:54 -07003259 LauncherAnimUtils.ofPropertyValuesHolder(revealView, panelAlpha, panelDriftY, panelDriftX);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003260 panelAlphaAndDrift.setDuration(revealDuration);
3261 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003262
Adam Cohen9bfdb762014-07-21 17:44:06 -07003263 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003264
Adam Cohen4e243a22014-08-10 18:30:55 -07003265 if (page != null) {
3266 page.setVisibility(View.VISIBLE);
3267 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003268
Adam Cohen63f1ec02014-08-12 09:23:13 -07003269 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", yDrift, 0);
Adam Cohen4e243a22014-08-10 18:30:55 -07003270 pageDrift.setDuration(revealDuration);
3271 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003272 pageDrift.setStartDelay(itemsAlphaStagger);
Adam Cohen4e243a22014-08-10 18:30:55 -07003273 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003274
Adam Cohen63f1ec02014-08-12 09:23:13 -07003275 page.setAlpha(0f);
3276 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 0f, 1f);
Adam Cohen4e243a22014-08-10 18:30:55 -07003277 itemsAlpha.setDuration(revealDuration);
3278 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3279 itemsAlpha.setStartDelay(itemsAlphaStagger);
3280 mStateAnimation.play(itemsAlpha);
3281 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003282
Adam Cohen4e243a22014-08-10 18:30:55 -07003283 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3284 pageIndicators.setAlpha(0.01f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003285 ObjectAnimator indicatorsAlpha =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003286 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003287 indicatorsAlpha.setDuration(revealDuration);
3288 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003289
Adam Cohen9bfdb762014-07-21 17:44:06 -07003290 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003291 final View allApps = getAllAppsButton();
3292 int allAppsButtonSize = LauncherAppState.getInstance().
3293 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3294 float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003295 Animator reveal = LauncherAnimUtils.createCircularReveal(revealView, width / 2,
Adam Cohen63f1ec02014-08-12 09:23:13 -07003296 height / 2, startRadius, revealRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003297 reveal.setDuration(revealDuration);
3298 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003299
3300 reveal.addListener(new AnimatorListenerAdapter() {
3301 public void onAnimationStart(Animator animation) {
3302 if (!isWidgetTray) {
3303 allApps.setVisibility(View.INVISIBLE);
3304 }
3305 }
3306 public void onAnimationEnd(Animator animation) {
3307 if (!isWidgetTray) {
3308 allApps.setVisibility(View.VISIBLE);
3309 }
3310 }
3311 });
3312
Adam Cohen6c5891a2014-07-09 23:53:15 -07003313 mStateAnimation.play(reveal);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003314 }
Michael Jurka1899a362011-11-03 13:50:45 -07003315
Adam Cohen9bfdb762014-07-21 17:44:06 -07003316 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3317 @Override
3318 public void onAnimationEnd(Animator animation) {
3319 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3320 dispatchOnLauncherTransitionEnd(toView, animated, false);
3321
3322 revealView.setVisibility(View.INVISIBLE);
3323 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003324 if (page != null) {
3325 page.setLayerType(View.LAYER_TYPE_NONE, null);
3326 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003327 content.setPageBackgroundsVisible(true);
3328
3329 // Hide the search bar
3330 if (mSearchDropTargetBar != null) {
3331 mSearchDropTargetBar.hideSearchBar(false);
3332 }
3333 }
3334
3335 @Override
3336 public void onAnimationStart(Animator animation) {
3337 // Prepare the position
3338 toView.bringToFront();
3339 toView.setVisibility(View.VISIBLE);
3340 }
3341 });
3342
Michael Jurka1899a362011-11-03 13:50:45 -07003343 boolean delayAnim = false;
Adam Cohen6c5891a2014-07-09 23:53:15 -07003344 if (workspaceAnim != null) {
3345 mStateAnimation.play(workspaceAnim);
3346 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003347 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3348 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003349
3350 // If any of the objects being animated haven't been measured/laid out
3351 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003352 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003353 (mWorkspace.getMeasuredWidth() == 0) ||
3354 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003355 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003356 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003357
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003358 final AnimatorSet stateAnimation = mStateAnimation;
3359 final Runnable startAnimRunnable = new Runnable() {
3360 public void run() {
3361 // Check that mStateAnimation hasn't changed while
3362 // we waited for a layout/draw pass
3363 if (mStateAnimation != stateAnimation)
3364 return;
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003365 dispatchOnLauncherTransitionStart(fromView, animated, false);
3366 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003367 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003368 }
3369 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003370 if (delayAnim) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003371 toView.bringToFront();
3372 toView.setVisibility(View.VISIBLE);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003373 final ViewTreeObserver observer = toView.getViewTreeObserver();
3374 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3375 public void onGlobalLayout() {
3376 startAnimRunnable.run();
3377 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3378 }
3379 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003380 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003381 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003382 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003383 } else {
3384 toView.setTranslationX(0.0f);
3385 toView.setTranslationY(0.0f);
3386 toView.setScaleX(1.0f);
3387 toView.setScaleY(1.0f);
3388 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003389 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003390
Daniel Sandlere4f98912013-06-25 15:13:26 -04003391 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003392 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003393 if (mSearchDropTargetBar != null) {
3394 mSearchDropTargetBar.hideSearchBar(false);
3395 }
Michael Jurkaabded662011-03-04 12:06:57 -08003396 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003397 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003398 dispatchOnLauncherTransitionStart(fromView, animated, false);
3399 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003400 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003401 dispatchOnLauncherTransitionStart(toView, animated, false);
3402 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003403 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003404 }
3405
3406 /**
3407 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003408 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003409 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003410 */
Adam Cohened307df2013-10-02 09:37:31 -07003411 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003412 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003413
Michael Jurkab3e22d92011-10-31 15:58:33 -07003414 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003415 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003416 mStateAnimation.cancel();
3417 mStateAnimation = null;
3418 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003419
3420 boolean material = Utilities.isLmp();
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003421 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003422
Winson Chungf0ea4d32011-06-06 14:27:16 -07003423 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003424 final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003425 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003426 final int itemsAlphaStagger =
3427 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003428
Winson Chungf0ea4d32011-06-06 14:27:16 -07003429 final float scaleFactor = (float)
3430 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3431 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003432 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003433 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003434 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003435 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohen63f1ec02014-08-12 09:23:13 -07003436 toState, animated);
Adam Cohened307df2013-10-02 09:37:31 -07003437 } else if (toState == Workspace.State.SPRING_LOADED ||
3438 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003439 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003440 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003441 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003442
Winson Chung4afe9b32011-07-27 17:46:20 -07003443 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003444 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003445 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka159b4cc2012-01-17 03:00:35 -08003446
Adam Cohen9bfdb762014-07-21 17:44:06 -07003447 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3448 fromView.findViewById(R.id.apps_customize_pane_content);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003449
Adam Cohen9bfdb762014-07-21 17:44:06 -07003450 final View page = content.getPageAt(content.getNextPage());
3451 final View revealView = fromView.findViewById(R.id.fake_page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003452
Adam Cohen4e243a22014-08-10 18:30:55 -07003453 AppsCustomizePagedView.ContentType contentType = content.getContentType();
Adam Cohen63f1ec02014-08-12 09:23:13 -07003454 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3455
3456 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003457 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3458 } else {
3459 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3460 }
3461
Adam Cohen9bfdb762014-07-21 17:44:06 -07003462 int width = revealView.getMeasuredWidth();
3463 int height = revealView.getMeasuredHeight();
3464 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003465
Adam Cohen9bfdb762014-07-21 17:44:06 -07003466 // Hide the real page background, and swap in the fake one
3467 revealView.setVisibility(View.VISIBLE);
3468 content.setPageBackgroundsVisible(false);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003469
Adam Cohen63f1ec02014-08-12 09:23:13 -07003470 final View allAppsButton = getAllAppsButton();
3471 revealView.setTranslationY(0);
3472 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3473 allAppsButton, null);
3474 float yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
Adam Cohen94afab42014-08-24 16:10:54 -07003475 float xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
Adam Cohen6c5891a2014-07-09 23:53:15 -07003476
Adam Cohen9bfdb762014-07-21 17:44:06 -07003477 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003478
Adam Cohen63f1ec02014-08-12 09:23:13 -07003479 // The vertical motion of the apps panel should be delayed by one frame
3480 // from the conceal animation in order to give the right feel. We correpsondingly
3481 // shorten the duration so that the slide and conceal end at the same time.
Adam Cohen94afab42014-08-24 16:10:54 -07003482 ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY", 0, yDrift);
3483 panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3484 panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3485 panelDriftY.setInterpolator(new LogDecelerateInterpolator(100, 0));
3486 mStateAnimation.play(panelDriftY);
3487
3488 ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX", 0, xDrift);
3489 panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3490 panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3491 panelDriftX.setInterpolator(new LogDecelerateInterpolator(100, 0));
3492 mStateAnimation.play(panelDriftX);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003493
Adam Cohen63f1ec02014-08-12 09:23:13 -07003494 if (isWidgetTray) {
3495 ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", 1f, 0.4f);
3496 panelAlpha.setDuration(revealDuration);
3497 panelAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0));
3498 mStateAnimation.play(panelAlpha);
3499 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003500
Adam Cohen4e243a22014-08-10 18:30:55 -07003501 if (page != null) {
3502 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003503
Adam Cohen63f1ec02014-08-12 09:23:13 -07003504 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
3505 0, yDrift);
3506 pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
Adam Cohen4e243a22014-08-10 18:30:55 -07003507 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003508 pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
Adam Cohen4e243a22014-08-10 18:30:55 -07003509 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003510
Adam Cohen4e243a22014-08-10 18:30:55 -07003511 page.setAlpha(1f);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003512 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
3513 itemsAlpha.setDuration(100);
Adam Cohen4e243a22014-08-10 18:30:55 -07003514 itemsAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0));
3515 mStateAnimation.play(itemsAlpha);
3516 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003517
Adam Cohen9bfdb762014-07-21 17:44:06 -07003518 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
Adam Cohen4e243a22014-08-10 18:30:55 -07003519 pageIndicators.setAlpha(1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003520 ObjectAnimator indicatorsAlpha =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003521 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003522 indicatorsAlpha.setDuration(revealDuration);
3523 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3524 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003525
Adam Cohen9bfdb762014-07-21 17:44:06 -07003526 width = revealView.getMeasuredWidth();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003527
Adam Cohen9bfdb762014-07-21 17:44:06 -07003528 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003529 if (!isWidgetTray) {
3530 allAppsButton.setVisibility(View.INVISIBLE);
3531 }
3532 int allAppsButtonSize = LauncherAppState.getInstance().
3533 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3534 float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Nilesh Agrawal300c1502014-07-22 13:20:54 -07003535 Animator reveal =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003536 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3537 height / 2, revealRadius, finalRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003538 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3539 reveal.setDuration(revealDuration);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003540 reveal.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003541
3542 reveal.addListener(new AnimatorListenerAdapter() {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003543 public void onAnimationEnd(Animator animation) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003544 revealView.setVisibility(View.INVISIBLE);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003545 if (!isWidgetTray) {
3546 allAppsButton.setVisibility(View.VISIBLE);
3547 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003548 }
3549 });
3550
Adam Cohen6c5891a2014-07-09 23:53:15 -07003551 mStateAnimation.play(reveal);
3552 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003553
3554 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3555 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3556 mAppsCustomizeContent.stopScrolling();
3557
Adam Cohen6c5891a2014-07-09 23:53:15 -07003558 if (workspaceAnim != null) {
3559 mStateAnimation.play(workspaceAnim);
3560 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003561
3562 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003563 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003564 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003565 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003566 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3567 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003568 if (onCompleteRunnable != null) {
3569 onCompleteRunnable.run();
3570 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003571
3572 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003573 if (page != null) {
3574 page.setLayerType(View.LAYER_TYPE_NONE, null);
3575 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003576 content.setPageBackgroundsVisible(true);
Chet Haasebc2f0822012-10-26 17:59:53 -07003577 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003578 }
3579 });
3580
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003581 dispatchOnLauncherTransitionStart(fromView, animated, true);
3582 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003583 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003584 } else {
3585 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003586 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003587 dispatchOnLauncherTransitionStart(fromView, animated, true);
3588 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003589 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003590 dispatchOnLauncherTransitionStart(toView, animated, true);
3591 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003592 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003593 }
3594
Michael Jurkae326f182011-11-21 14:05:46 -08003595 @Override
3596 public void onTrimMemory(int level) {
3597 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003598 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003599 mAppsCustomizeTabHost.onTrimMemory();
3600 }
3601 }
3602
Adam Cohened307df2013-10-02 09:37:31 -07003603 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003604 showWorkspace(animated, null);
3605 }
3606
Adam Cohened307df2013-10-02 09:37:31 -07003607 protected void showWorkspace() {
3608 showWorkspace(true);
3609 }
3610
Adam Cohened66b2b2012-01-23 17:28:51 -08003611 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohene25c5d12014-06-18 10:34:58 -07003612 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
Winson Chung2d75f122013-09-23 16:53:31 -07003613 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003614 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003615 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003616
Winson Chungc7d2b602012-05-16 17:02:20 -07003617 // Show the search bar (only animate if we were showing the drop target bar in spring
3618 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003619 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003620 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003621 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003622
Michael Jurkab3e22d92011-10-31 15:58:33 -07003623 // Set focus to the AppsCustomize button
3624 if (mAllAppsButton != null) {
3625 mAllAppsButton.requestFocus();
3626 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003627 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003628
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003629 // Change the state *after* we've called all the transition code
3630 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003631
Winson Chung5fb63472011-02-02 17:03:37 -08003632 // Resume the auto-advance of widgets
3633 mUserPresent = true;
3634 updateRunning();
3635
alanv1d4fde62012-10-17 13:15:47 -07003636 // Send an accessibility event to announce the context change
3637 getWindow().getDecorView()
3638 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003639
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003640 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003641 }
3642
Adam Cohened307df2013-10-02 09:37:31 -07003643 void showOverviewMode(boolean animated) {
3644 mWorkspace.setVisibility(View.VISIBLE);
3645 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3646 mState = State.WORKSPACE;
3647 onWorkspaceShown(animated);
3648 }
3649
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003650 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003651 }
3652
Winson Chung82963d52013-10-09 11:20:57 -07003653 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3654 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003655 if (mState != State.WORKSPACE) return;
3656
Winson Chung82963d52013-10-09 11:20:57 -07003657 if (resetPageToZero) {
3658 mAppsCustomizeTabHost.reset();
3659 }
Winson Chungc58497e2013-09-03 17:48:37 -07003660 showAppsCustomizeHelper(animated, false, contentType);
Adam Cohendcc5e712014-06-23 15:38:55 -04003661 mAppsCustomizeTabHost.post(new Runnable() {
3662 @Override
3663 public void run() {
3664 // We post this in-case the all apps view isn't yet constructed.
3665 mAppsCustomizeTabHost.requestFocus();
3666 }
3667 });
Michael Jurkab3e22d92011-10-31 15:58:33 -07003668
Michael Jurkab3e22d92011-10-31 15:58:33 -07003669 // Change the state *after* we've called all the transition code
3670 mState = State.APPS_CUSTOMIZE;
3671
3672 // Pause the auto-advance of widgets until we are out of AllApps
3673 mUserPresent = false;
3674 updateRunning();
3675 closeFolder();
3676
3677 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003678 getWindow().getDecorView()
3679 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003680 }
3681
Adam Cohen7777d962011-08-18 18:58:38 -07003682 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003683 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003684 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003685 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003686 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003687 }
Adam Cohen7777d962011-08-18 18:58:38 -07003688
Adam Cohenad4e15c2013-10-17 16:21:35 -07003689 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003690 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003691 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3692
Winson Chunge7a03942011-08-05 15:05:12 -07003693 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003694 @Override
3695 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003696 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003697 // Before we show workspace, hide all apps again because
3698 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3699 // clean up our state transition functions
3700 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003701 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003702 } else {
3703 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003704 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003705 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003706 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003707 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003708
Michael Jurkad3ef3062010-11-23 16:23:58 -08003709 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003710 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003711 final boolean animated = true;
3712 final boolean springLoaded = true;
3713 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003714 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003715 }
3716 // Otherwise, we are not in spring loaded mode, so don't do anything.
3717 }
3718
Michael Jurkab3e22d92011-10-31 15:58:33 -07003719 void lockAllApps() {
3720 // TODO
3721 }
3722
3723 void unlockAllApps() {
3724 // TODO
3725 }
3726
Winson Chungf0ea4d32011-06-06 14:27:16 -07003727 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003728 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003729 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003730 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003731 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003732 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003733 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003734 int duration = 0;
3735 if (mSearchDropTargetBar != null) {
3736 duration = mSearchDropTargetBar.getTransitionInDuration();
3737 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003738 mHotseat.animate().alpha(1f).setDuration(duration);
3739 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003740 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003741 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003742 }
3743 }
3744 }
3745
3746 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003747 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003748 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003749 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003750 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003751 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003752 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003753 int duration = 0;
3754 if (mSearchDropTargetBar != null) {
3755 duration = mSearchDropTargetBar.getTransitionOutDuration();
3756 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003757 mHotseat.animate().alpha(0f).setDuration(duration);
3758 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003759 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003760 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003761 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003762 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003763 }
3764
Patrick Dubroy5f445422011-02-18 14:35:21 -08003765 /**
3766 * Add an item from all apps or customize onto the given workspace screen.
3767 * If layout is null, add to the current screen.
3768 */
3769 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003770 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003771 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003772 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003773 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003774
Winson Chungdff8ebb2011-09-08 17:25:31 -07003775 /** Maps the current orientation to an index for referencing orientation correct global icons */
3776 private int getCurrentOrientationIndexForGlobalIcons() {
3777 // default - 0, landscape - 1
3778 switch (getResources().getConfiguration().orientation) {
3779 case Configuration.ORIENTATION_LANDSCAPE:
3780 return 1;
3781 default:
3782 return 0;
3783 }
3784 }
3785
Michael Jurkaae65ee32012-04-30 11:45:54 -07003786 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003787 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003788 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003789 // Look for the toolbar icon specified in the activity meta-data
3790 Bundle metaData = packageManager.getActivityInfo(
3791 activityName, PackageManager.GET_META_DATA).metaData;
3792 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003793 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003794 if (iconResId != 0) {
3795 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003796 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003797 }
3798 }
3799 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003800 // This can happen if the activity defines an invalid drawable
3801 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3802 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003803 } catch (Resources.NotFoundException nfe) {
3804 // This can happen if the activity defines an invalid drawable
3805 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3806 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003807 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003808 return null;
3809 }
3810
3811 // if successful in getting icon, return it; otherwise, set button to use default drawable
3812 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003813 int buttonId, ComponentName activityName, int fallbackDrawableId,
3814 String toolbarResourceName) {
3815 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003816 Resources r = getResources();
3817 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3818 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003819
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003820 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003821 // If we were unable to find the icon via the meta-data, use a generic one
3822 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003823 toolbarIcon = r.getDrawable(fallbackDrawableId);
3824 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003825 if (button != null) {
3826 button.setCompoundDrawables(toolbarIcon, null, null, null);
3827 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003828 return null;
3829 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003830 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003831 if (button != null) {
3832 button.setCompoundDrawables(toolbarIcon, null, null, null);
3833 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003834 return toolbarIcon.getConstantState();
3835 }
3836 }
3837
3838 // if successful in getting icon, return it; otherwise, set button to use default drawable
3839 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003840 int buttonId, ComponentName activityName, int fallbackDrawableId,
3841 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003842 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003843 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003844
Michael Jurka19e0fc52011-07-22 18:00:21 -07003845 if (button != null) {
3846 // If we were unable to find the icon via the meta-data, use a
3847 // generic one
3848 if (toolbarIcon == null) {
3849 button.setImageResource(fallbackDrawableId);
3850 } else {
3851 button.setImageDrawable(toolbarIcon);
3852 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003853 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003854
3855 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3856
Michael Jurka0423dcf2010-10-05 14:56:18 -07003857 }
3858
Winson Chung1b884092012-06-08 17:13:02 -07003859 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003860 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003861 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003862 }
3863
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003864 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003865 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003866 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003867 }
3868
Winson Chungbb185bd2011-11-21 12:31:42 -08003869 private void invalidatePressedFocusedStates(View container, View button) {
3870 if (container instanceof HolographicLinearLayout) {
3871 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3872 layout.invalidatePressedFocusedStates();
3873 } else if (button instanceof HolographicImageView) {
3874 HolographicImageView view = (HolographicImageView) button;
3875 view.invalidatePressedFocusedStates();
3876 }
3877 }
3878
Cristina Stancu476493b2013-08-07 17:20:14 +01003879 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003880 if (mQsb == null) {
3881 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3882 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003883 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003884 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003885 }
3886
3887 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003888 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003889 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003890 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003891 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003892
Winson Chung1cad91e2011-05-25 17:41:01 -07003893 final SearchManager searchManager =
3894 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3895 ComponentName activityName = searchManager.getGlobalSearchActivity();
3896 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003897 int coi = getCurrentOrientationIndexForGlobalIcons();
3898 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003899 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3900 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3901 if (sGlobalSearchIcon[coi] == null) {
3902 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3903 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3904 TOOLBAR_ICON_METADATA_NAME);
3905 }
3906
Winson Chungc51db6a2011-10-05 11:44:49 -07003907 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3908 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003909 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003910 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003911 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003912 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003913 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3914 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003915 if (searchButton != null) searchButton.setVisibility(View.GONE);
3916 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003917 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003918 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003919 }
3920 }
3921
Cristina Stancu476493b2013-08-07 17:20:14 +01003922 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003923 final View searchButtonContainer = findViewById(R.id.search_button_container);
3924 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003925 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003926 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003927 }
3928
Cristina Stancu476493b2013-08-07 17:20:14 +01003929 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003930 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003931 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003932
Winson Chungc51db6a2011-10-05 11:44:49 -07003933 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003934 final SearchManager searchManager =
3935 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3936 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3937
3938 ComponentName activityName = null;
3939 if (globalSearchActivity != null) {
3940 // Check if the global search activity handles voice search
3941 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3942 intent.setPackage(globalSearchActivity.getPackageName());
3943 activityName = intent.resolveActivity(getPackageManager());
3944 }
3945
3946 if (activityName == null) {
3947 // Fallback: check if an activity other than the global search activity
3948 // resolves this
3949 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3950 activityName = intent.resolveActivity(getPackageManager());
3951 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003952 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003953 int coi = getCurrentOrientationIndexForGlobalIcons();
3954 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003955 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3956 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3957 if (sVoiceSearchIcon[coi] == null) {
3958 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3959 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3960 TOOLBAR_ICON_METADATA_NAME);
3961 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003962 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003963 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003964 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003965 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003966 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003967 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003968 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003969 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003970 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003971 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003972 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003973 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003974
Cristina Stancu476493b2013-08-07 17:20:14 +01003975 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003976 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3977 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003978 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003979 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003980 }
3981
Winson Chung5841efa2013-09-30 18:06:44 -07003982 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003983 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3984 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003985 boolean visible = !forceDisableVoiceButtonProxy &&
3986 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003987 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003988 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003989 }
3990 }
Winson Chung5841efa2013-09-30 18:06:44 -07003991
3992 /**
3993 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3994 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3995 */
3996 public void disableVoiceButtonProxy(boolean disabled) {
3997 updateVoiceButtonProxyVisible(disabled);
3998 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003999
Michael Jurkad7c28052012-04-27 15:43:36 -07004000 @Override
4001 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07004002 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07004003 final List<CharSequence> text = event.getText();
4004 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07004005 // Populate event with a fake title based on the current state.
4006 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07004007 text.add(mAppsCustomizeTabHost.getContentTag());
alanv1d4fde62012-10-17 13:15:47 -07004008 } else {
4009 text.add(getString(R.string.all_apps_home_button_label));
4010 }
Michael Jurkad7c28052012-04-27 15:43:36 -07004011 return result;
4012 }
4013
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004014 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07004015 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004016 */
4017 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4018 @Override
4019 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004020 closeSystemDialogs();
4021 }
4022 }
4023
4024 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08004025 * Receives notifications whenever the appwidgets are reset.
4026 */
4027 private class AppWidgetResetObserver extends ContentObserver {
4028 public AppWidgetResetObserver() {
4029 super(new Handler());
4030 }
4031
4032 @Override
4033 public void onChange(boolean selfChange) {
4034 onAppWidgetReset();
4035 }
4036 }
4037
4038 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07004039 * If the activity is currently paused, signal that we need to run the passed Runnable
4040 * in onResume.
4041 *
4042 * This needs to be called from incoming places where resources might have been loaded
4043 * while we are paused. That is becaues the Configuration might be wrong
4044 * when we're not running, and if it comes back to what it was when we
4045 * were paused, we are not restarted.
4046 *
4047 * Implementation of the method from LauncherModel.Callbacks.
4048 *
4049 * @return true if we are currently paused. The caller might be able to
4050 * skip some work in that case since we will come back again.
4051 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004052 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004053 if (mPaused) {
4054 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02004055 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07004056 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004057 }
4058 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07004059 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07004060 return true;
4061 } else {
4062 return false;
4063 }
4064 }
4065
Michael Jurkac402cd92013-05-20 15:49:32 +02004066 private boolean waitUntilResume(Runnable run) {
4067 return waitUntilResume(run, false);
4068 }
4069
Michael Jurka1e2f4652013-07-08 18:03:46 -07004070 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02004071 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07004072 }
4073
Michael Jurka7607c2f2013-04-03 14:33:19 -07004074 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004075 * If the activity is currently paused, signal that we need to re-run the loader
4076 * in onResume.
4077 *
4078 * This needs to be called from incoming places where resources might have been loaded
4079 * while we are paused. That is becaues the Configuration might be wrong
4080 * when we're not running, and if it comes back to what it was when we
4081 * were paused, we are not restarted.
4082 *
4083 * Implementation of the method from LauncherModel.Callbacks.
4084 *
4085 * @return true if we are currently paused. The caller might be able to
4086 * skip some work in that case since we will come back again.
4087 */
4088 public boolean setLoadOnResume() {
4089 if (mPaused) {
4090 Log.i(TAG, "setLoadOnResume");
4091 mOnResumeNeedsLoad = true;
4092 return true;
4093 } else {
4094 return false;
4095 }
4096 }
4097
4098 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004099 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004100 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04004101 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07004102 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07004103 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07004104 } else {
4105 return SCREEN_COUNT / 2;
4106 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004107 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07004108
Joe Onorato9c1289c2009-08-17 11:03:03 -04004109 /**
4110 * Refreshes the shortcuts shown on the workspace.
4111 *
4112 * Implementation of the method from LauncherModel.Callbacks.
4113 */
4114 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004115 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08004116
Michael Jurka7607c2f2013-04-03 14:33:19 -07004117 // If we're starting binding all over again, clear any bind calls we'd postponed in
4118 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4119 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07004120 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07004121
Winson Chungd64d1762013-08-20 14:37:16 -07004122 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07004123 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07004124 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07004125
Michael Jurka05bf644e2011-11-30 20:28:53 -08004126 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07004127 if (mHotseat != null) {
4128 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004129 }
4130 }
4131
Adam Cohendcd297f2013-06-18 13:13:40 -07004132 @Override
4133 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07004134 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07004135
Adam Cohen5084cba2013-09-03 12:01:16 -07004136 // If there are no screens, we need to have an empty screen
4137 if (orderedScreenIds.size() == 0) {
4138 mWorkspace.addExtraEmptyScreen();
4139 }
Winson Chung0e6a7132013-08-23 12:55:10 -07004140
4141 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06004142 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05004143 if (hasCustomContentToLeft()) {
4144 mWorkspace.createCustomContentContainer();
4145 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07004146 }
Winson Chung64359a52013-07-08 17:17:08 -07004147 }
4148
4149 @Override
4150 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08004151 // Log to disk
4152 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4153 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4154 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07004155 int count = orderedScreenIds.size();
4156 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07004157 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07004158 }
Adam Cohendcd297f2013-06-18 13:13:40 -07004159 }
4160
Adam Cohen39a06042013-07-19 14:30:12 -07004161 private boolean shouldShowWeightWatcher() {
4162 String spKey = LauncherAppState.getSharedPreferencesKey();
4163 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07004164 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07004165
4166 return show;
4167 }
4168
4169 private void toggleShowWeightWatcher() {
4170 String spKey = LauncherAppState.getSharedPreferencesKey();
4171 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4172 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4173
4174 show = !show;
4175
4176 SharedPreferences.Editor editor = sp.edit();
4177 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4178 editor.commit();
4179
4180 if (mWeightWatcher != null) {
4181 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4182 }
4183 }
4184
Winson Chungd64d1762013-08-20 14:37:16 -07004185 public void bindAppsAdded(final ArrayList<Long> newScreens,
4186 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07004187 final ArrayList<ItemInfo> addAnimated,
4188 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004189 Runnable r = new Runnable() {
4190 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07004191 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07004192 }
4193 };
4194 if (waitUntilResume(r)) {
4195 return;
4196 }
4197
Winson Chungd64d1762013-08-20 14:37:16 -07004198 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08004199 if (newScreens != null) {
4200 bindAddScreens(newScreens);
4201 }
Winson Chungd64d1762013-08-20 14:37:16 -07004202
4203 // We add the items without animation on non-visible pages, and with
4204 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08004205 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004206 bindItems(addNotAnimated, 0,
4207 addNotAnimated.size(), false);
4208 }
Adam Cohen76a47a12014-02-05 11:47:43 -08004209 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004210 bindItems(addAnimated, 0,
4211 addAnimated.size(), true);
4212 }
Winson Chungc58497e2013-09-03 17:48:37 -07004213
Winson Chung87412982013-10-03 18:34:14 -07004214 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004215 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004216
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004217 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004218 addedApps != null && mAppsCustomizeContent != null) {
4219 mAppsCustomizeContent.addApps(addedApps);
4220 }
Winson Chungd64d1762013-08-20 14:37:16 -07004221 }
4222
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004223 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004224 * Bind the items start-end from the list.
4225 *
4226 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004227 */
Winson Chung64359a52013-07-08 17:17:08 -07004228 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4229 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004230 Runnable r = new Runnable() {
4231 public void run() {
4232 bindItems(shortcuts, start, end, forceAnimateIcons);
4233 }
4234 };
4235 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004236 return;
4237 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004238
Winson Chungf0c6ae02012-03-21 16:10:31 -07004239 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004240 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4241 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004242 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004243 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004244 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004245 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004246 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004247
4248 // Short circuit if we are loading dock items for a configuration which has no dock
4249 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4250 mHotseat == null) {
4251 continue;
4252 }
4253
Joe Onorato9c1289c2009-08-17 11:03:03 -04004254 switch (item.itemType) {
4255 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4256 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004257 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004258 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004259
Winson Chung64359a52013-07-08 17:17:08 -07004260 /*
4261 * TODO: FIX collision case
4262 */
Winson Chungce376632013-07-11 16:12:41 -07004263 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4264 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4265 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004266 View v = cl.getChildAt(item.cellX, item.cellY);
4267 Object tag = v.getTag();
4268 String desc = "Collision while binding workspace item: " + item
4269 + ". Collides with " + tag;
4270 if (LauncherAppState.isDogfoodBuild()) {
4271 throw (new RuntimeException(desc));
4272 } else {
4273 Log.d(TAG, desc);
4274 }
Winson Chungce376632013-07-11 16:12:41 -07004275 }
Winson Chung64359a52013-07-08 17:17:08 -07004276 }
4277
Adam Cohendcd297f2013-06-18 13:13:40 -07004278 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4279 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004280 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004281 // Animate all the applications up now
4282 shortcut.setAlpha(0f);
4283 shortcut.setScaleX(0f);
4284 shortcut.setScaleY(0f);
4285 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004286 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004287 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004288 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004289 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004290 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004291 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004292 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004293 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4294 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004295 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004296 default:
4297 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004298 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004299 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004300
Winson Chung997a9232013-07-24 15:33:46 -07004301 if (animateIcons) {
4302 // Animate to the correct page
4303 if (newShortcutsScreenId > -1) {
4304 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004305 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004306 final Runnable startBounceAnimRunnable = new Runnable() {
4307 public void run() {
4308 anim.playTogether(bounceAnims);
4309 anim.start();
4310 }
4311 };
Winson Chung997a9232013-07-24 15:33:46 -07004312 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004313 // We post the animation slightly delayed to prevent slowdowns
4314 // when we are loading right after we return to launcher.
4315 mWorkspace.postDelayed(new Runnable() {
4316 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004317 if (mWorkspace != null) {
4318 mWorkspace.snapToPage(newScreenIndex);
4319 mWorkspace.postDelayed(startBounceAnimRunnable,
4320 NEW_APPS_ANIMATION_DELAY);
4321 }
Winson Chung94d67682013-09-25 16:29:40 -07004322 }
4323 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004324 } else {
4325 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004326 }
4327 }
Winson Chung64359a52013-07-08 17:17:08 -07004328 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004329 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004330 }
4331
Joe Onorato9c1289c2009-08-17 11:03:03 -04004332 /**
4333 * Implementation of the method from LauncherModel.Callbacks.
4334 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004335 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004336 Runnable r = new Runnable() {
4337 public void run() {
4338 bindFolders(folders);
4339 }
4340 };
4341 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004342 return;
4343 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004344 sFolders.clear();
4345 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004346 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004347
4348 /**
4349 * Add the views for a widget to the workspace.
4350 *
4351 * Implementation of the method from LauncherModel.Callbacks.
4352 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004353 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004354 Runnable r = new Runnable() {
4355 public void run() {
4356 bindAppWidget(item);
4357 }
4358 };
4359 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004360 return;
4361 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004362
Daniel Sandler843e8602010-06-07 14:59:01 -04004363 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4364 if (DEBUG_WIDGETS) {
4365 Log.d(TAG, "bindAppWidget: " + item);
4366 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004367 final Workspace workspace = mWorkspace;
4368
Sunny Goyalff572272014-07-23 13:58:07 -07004369 AppWidgetProviderInfo appWidgetInfo;
4370 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4371 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4372
4373 appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
4374 if (appWidgetInfo == null) {
4375 if (DEBUG_WIDGETS) {
4376 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4377 + " belongs to component " + item.providerName
4378 + ", as the povider is null");
4379 }
4380 LauncherModel.deleteItemFromDatabase(this, item);
4381 return;
4382 }
4383 // Note: This assumes that the id remap broadcast is received before this step.
4384 // If that is not the case, the id remap will be ignored and user may see the
4385 // click to setup view.
4386 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4387 pendingInfo.spanX = item.spanX;
4388 pendingInfo.spanY = item.spanY;
4389 pendingInfo.minSpanX = item.minSpanX;
4390 pendingInfo.minSpanY = item.minSpanY;
4391 Bundle options =
4392 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4393
Sunny Goyalff572272014-07-23 13:58:07 -07004394 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
Sunny Goyalffe83f12014-08-14 17:39:34 -07004395 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4396 newWidgetId, appWidgetInfo, options);
Sunny Goyalff572272014-07-23 13:58:07 -07004397
4398 // TODO consider showing a permission dialog when the widget is clicked.
4399 if (!success) {
4400 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4401 if (DEBUG_WIDGETS) {
4402 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4403 + " belongs to component " + item.providerName
4404 + ", as the launcher is unable to bing a new widget id");
4405 }
4406 LauncherModel.deleteItemFromDatabase(this, item);
4407 return;
4408 }
4409
4410 item.appWidgetId = newWidgetId;
4411
4412 // If the widget has a configure activity, it is still needs to set it up, otherwise
4413 // the widget is ready to go.
4414 item.restoreStatus = (appWidgetInfo.configure == null)
4415 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4416 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4417
4418 LauncherModel.updateItemInDatabase(this, item);
4419 }
4420
Sunny Goyal651077b2014-06-30 14:15:31 -07004421 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4422 final int appWidgetId = item.appWidgetId;
4423 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4424 if (DEBUG_WIDGETS) {
4425 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4426 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004427
Sunny Goyal651077b2014-06-30 14:15:31 -07004428 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4429 } else {
4430 appWidgetInfo = null;
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004431 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item);
4432 view.updateIcon(mIconCache);
4433 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004434 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004435 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004436 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004437
Joe Onorato9c1289c2009-08-17 11:03:03 -04004438 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004439 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004440
Adam Cohendcd297f2013-06-18 13:13:40 -07004441 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004442 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004443 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4444
Joe Onorato9c1289c2009-08-17 11:03:03 -04004445 workspace.requestLayout();
4446
Daniel Sandler843e8602010-06-07 14:59:01 -04004447 if (DEBUG_WIDGETS) {
4448 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4449 + (SystemClock.uptimeMillis()-start) + "ms");
4450 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004451 }
4452
Sunny Goyalff572272014-07-23 13:58:07 -07004453 /**
4454 * Restores a pending widget.
4455 *
4456 * @param appWidgetId The app widget id
4457 * @param cellInfo The position on screen where to create the widget.
4458 */
4459 private void completeRestoreAppWidget(final int appWidgetId) {
4460 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4461 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4462 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4463 return;
4464 }
4465
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004466 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004467 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4468
4469 mWorkspace.reinflateWidgetsIfNecessary();
4470 LauncherModel.updateItemInDatabase(this, info);
4471 }
4472
Adam Cohen1462de32012-07-24 22:34:36 -07004473 public void onPageBoundSynchronously(int page) {
4474 mSynchronouslyBoundPages.add(page);
4475 }
4476
Joe Onorato9c1289c2009-08-17 11:03:03 -04004477 /**
4478 * Callback saying that there aren't any more items to bind.
4479 *
4480 * Implementation of the method from LauncherModel.Callbacks.
4481 */
Adam Cohene25af792013-06-06 23:08:25 -07004482 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004483 Runnable r = new Runnable() {
4484 public void run() {
4485 finishBindingItems(upgradePath);
4486 }
4487 };
4488 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004489 return;
4490 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004491 if (mSavedState != null) {
4492 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004493 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004494 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004495 mSavedState = null;
4496 }
4497
Adam Cohen1462de32012-07-24 22:34:36 -07004498 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004499
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004500 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004501 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004502
4503 // If we received the result of any pending adds while the loader was running (e.g. the
4504 // widget configuration forced an orientation change), process them now.
4505 if (sPendingAddItem != null) {
4506 final long screenId = completeAdd(sPendingAddItem);
4507
4508 // TODO: this moves the user to the page where the pending item was added. Ideally,
4509 // the screen would be guaranteed to exist after bind, and the page would be set through
4510 // the workspace restore process.
4511 mWorkspace.post(new Runnable() {
4512 @Override
4513 public void run() {
4514 mWorkspace.snapToScreenId(screenId);
4515 }
4516 });
4517 sPendingAddItem = null;
4518 }
4519
Adam Cohene25af792013-06-06 23:08:25 -07004520 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004521 mWorkspace.getUniqueComponents(true, null);
4522 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004523 }
Sunny Goyale755d462014-07-22 13:48:29 -07004524 PackageInstallerCompat.getInstance(this).onFinishBind();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004525 }
4526
Adam Cohen3ed316a2014-07-23 18:21:20 -07004527 private void sendLoadingCompleteBroadcastIfNecessary() {
4528 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4529 String permission =
4530 getResources().getString(R.string.receive_first_load_broadcast_permission);
4531 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4532 sendBroadcast(intent, permission);
4533 SharedPreferences.Editor editor = mSharedPrefs.edit();
4534 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4535 editor.apply();
4536 }
4537 }
4538
Winson Chunga0b7e862013-09-05 16:03:15 -07004539 public boolean isAllAppsButtonRank(int rank) {
4540 if (mHotseat != null) {
4541 return mHotseat.isAllAppsButtonRank(rank);
4542 }
4543 return false;
4544 }
4545
Winson Chunga2413752012-04-03 14:22:34 -07004546 private boolean canRunNewAppsAnimation() {
4547 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4548 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4549 }
4550
Winson Chungc9168342013-06-26 14:54:55 -07004551 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4552 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4553 PropertyValuesHolder.ofFloat("alpha", 1f),
4554 PropertyValuesHolder.ofFloat("scaleX", 1f),
4555 PropertyValuesHolder.ofFloat("scaleY", 1f));
4556 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4557 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4558 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4559 return bounceAnim;
4560 }
4561
Adam Cohen27772732013-11-11 14:00:56 +00004562 public boolean useVerticalBarLayout() {
4563 return LauncherAppState.getInstance().getDynamicGrid().
4564 getDeviceProfile().isVerticalBarLayout();
4565 }
4566
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004567 protected Rect getSearchBarBounds() {
4568 return LauncherAppState.getInstance().getDynamicGrid().
4569 getDeviceProfile().getSearchBarBounds();
4570 }
4571
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004572 @Override
4573 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004574 boolean searchVisible = updateGlobalSearchIcon();
4575 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004576 if (mSearchDropTargetBar != null) {
4577 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4578 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004579 }
4580
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004581 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004582 * Add the icons for all apps.
4583 *
4584 * Implementation of the method from LauncherModel.Callbacks.
4585 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004586 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004587 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004588 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4589 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4590 getHotseat().addAllAppsFolder(mIconCache, apps,
4591 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4592 }
4593 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004594 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004595 if (mAppsCustomizeContent != null) {
4596 mAppsCustomizeContent.onPackagesUpdated(
4597 LauncherModel.getSortedWidgetsAndShortcuts(this));
4598 }
Winson Chungc58497e2013-09-03 17:48:37 -07004599 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004600 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004601 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004602 mAppsCustomizeContent.onPackagesUpdated(
4603 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004604 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004605 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004606 }
4607
4608 /**
4609 * A package was updated.
4610 *
4611 * Implementation of the method from LauncherModel.Callbacks.
4612 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004613 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004614 Runnable r = new Runnable() {
4615 public void run() {
4616 bindAppsUpdated(apps);
4617 }
4618 };
4619 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004620 return;
4621 }
4622
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004623 if (mWorkspace != null) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004624 mWorkspace.updateShortcutsAndWidgets(apps);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004625 }
Winson Chungc58497e2013-09-03 17:48:37 -07004626
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004627 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004628 mAppsCustomizeContent != null) {
4629 mAppsCustomizeContent.updateApps(apps);
4630 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004631 }
4632
4633 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004634 * Update the state of a package, typically related to install state.
4635 *
4636 * Implementation of the method from LauncherModel.Callbacks.
4637 */
Sunny Goyale755d462014-07-22 13:48:29 -07004638 @Override
4639 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004640 if (mWorkspace != null) {
Sunny Goyale755d462014-07-22 13:48:29 -07004641 mWorkspace.updatePackageState(installInfo);
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004642 }
4643 }
4644
4645 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004646 * A package was uninstalled. We take both the super set of packageNames
4647 * in addition to specific applications to remove, the reason being that
4648 * this can be called when a package is updated as well. In that scenario,
4649 * we only remove specific components from the workspace, where as
4650 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004651 *
4652 * Implementation of the method from LauncherModel.Callbacks.
4653 */
Winson Chung83892cc2013-05-01 16:53:33 -07004654 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004655 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004656 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004657 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004658 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004659 }
Winson Chungd64d1762013-08-20 14:37:16 -07004660 };
4661 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004662 return;
4663 }
4664
Winson Chungdf95eb12013-10-16 14:57:07 -07004665 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004666 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004667 }
4668 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004669 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004670 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004671
Winson Chunga1820962011-10-03 16:31:06 -07004672 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004673 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004674
Winson Chungdf95eb12013-10-16 14:57:07 -07004675 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004676 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004677 mAppsCustomizeContent != null) {
4678 mAppsCustomizeContent.removeApps(appInfos);
4679 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004680 }
Joe Onoratobe386092009-11-17 17:32:16 -08004681
4682 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004683 * A number of packages were updated.
4684 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004685 private ArrayList<Object> mWidgetsAndShortcuts;
4686 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004687 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004688 bindPackagesUpdated(mWidgetsAndShortcuts);
4689 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004690 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004691 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004692 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4693 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4694 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004695 return;
4696 }
4697
Winson Chung64359a52013-07-08 17:17:08 -07004698 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004699 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004700 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004701 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004702 }
4703
Winson Chung400438b2011-01-16 17:53:48 -08004704 private int mapConfigurationOriActivityInfoOri(int configOri) {
4705 final Display d = getWindowManager().getDefaultDisplay();
4706 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4707 switch (d.getRotation()) {
4708 case Surface.ROTATION_0:
4709 case Surface.ROTATION_180:
4710 // We are currently in the same basic orientation as the natural orientation
4711 naturalOri = configOri;
4712 break;
4713 case Surface.ROTATION_90:
4714 case Surface.ROTATION_270:
4715 // We are currently in the other basic orientation to the natural orientation
4716 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4717 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4718 break;
4719 }
4720
4721 int[] oriMap = {
4722 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4723 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4724 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4725 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4726 };
4727 // Since the map starts at portrait, we need to offset if this device's natural orientation
4728 // is landscape.
4729 int indexOffset = 0;
4730 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4731 indexOffset = 1;
4732 }
4733 return oriMap[(d.getRotation() + indexOffset) % 4];
4734 }
Adam Cohen446e9402011-09-15 18:21:21 -07004735
Winson Chung4b919f82012-05-01 10:44:08 -07004736 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004737 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004738 getResources().getBoolean(R.bool.allow_rotation);
4739 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004740 }
Winson Chung4b919f82012-05-01 10:44:08 -07004741 public void lockScreenOrientation() {
4742 if (isRotationEnabled()) {
4743 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4744 .getConfiguration().orientation));
4745 }
4746 }
4747 public void unlockScreenOrientation(boolean immediate) {
4748 if (isRotationEnabled()) {
4749 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004750 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004751 } else {
4752 mHandler.postDelayed(new Runnable() {
4753 public void run() {
4754 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4755 }
4756 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004757 }
Winson Chung4b919f82012-05-01 10:44:08 -07004758 }
Winson Chung400438b2011-01-16 17:53:48 -08004759 }
4760
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004761 /**
4762 * Called when the SearchBar hint should be changed.
4763 *
4764 * @param hint the hint to be displayed in the search bar.
4765 */
4766 protected void onSearchBarHintChanged(String hint) {
Sunny Goyal424418b2014-08-22 16:09:37 -07004767
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004768 }
4769
Winson Chunge43a1e72014-01-15 10:33:02 -08004770 protected boolean isLauncherPreinstalled() {
4771 PackageManager pm = getPackageManager();
4772 try {
4773 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4774 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4775 return true;
4776 } else {
4777 return false;
4778 }
4779 } catch (NameNotFoundException e) {
4780 e.printStackTrace();
4781 return false;
4782 }
4783 }
4784
Adam Cohenea90f832014-05-21 15:03:34 -07004785 /**
4786 * This method indicates whether or not we should suggest default wallpaper dimensions
4787 * when our wallpaper cropper was not yet used to set a wallpaper.
4788 */
4789 protected boolean overrideWallpaperDimensions() {
4790 return true;
4791 }
4792
Adam Cohen5eed5d82014-05-19 13:12:13 -07004793 protected boolean shouldClingFocusHotseatApp() {
4794 return false;
4795 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004796 protected String getFirstRunClingSearchBarHint() {
4797 return "";
4798 }
4799 protected String getFirstRunCustomContentHint() {
4800 return "";
4801 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004802 protected int getFirstRunFocusedHotseatAppDrawableId() {
4803 return -1;
4804 }
4805 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4806 return null;
4807 }
4808 protected int getFirstRunFocusedHotseatAppRank() {
4809 return -1;
4810 }
4811 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4812 return "";
4813 }
4814 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4815 return "";
4816 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004817
Adam Cohen432609a2014-03-13 17:03:22 -07004818 /**
4819 * To be overridden by subclasses to indicate that there is an activity to launch
4820 * before showing the standard launcher experience.
4821 */
4822 protected boolean hasFirstRunActivity() {
4823 return false;
4824 }
4825
4826 /**
4827 * To be overridden by subclasses to launch any first run activity
4828 */
4829 protected Intent getFirstRunActivity() {
4830 return null;
4831 }
4832
Winson Chunga6945242014-01-08 14:04:34 -08004833 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004834 return !ActivityManager.isRunningInTestHarness() &&
4835 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004836 }
4837
Adam Cohen4a9423d2014-03-28 14:22:31 -07004838 protected boolean hasRunFirstRunActivity() {
4839 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4840 }
4841
Adam Cohen432609a2014-03-13 17:03:22 -07004842 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004843 if (shouldRunFirstRunActivity() &&
4844 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004845 Intent firstRunIntent = getFirstRunActivity();
4846 if (firstRunIntent != null) {
4847 startActivity(firstRunIntent);
4848 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004849 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004850 }
4851 }
Adam Cohen432609a2014-03-13 17:03:22 -07004852 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004853 }
4854
4855 private void markFirstRunActivityShown() {
4856 SharedPreferences.Editor editor = mSharedPrefs.edit();
4857 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4858 editor.apply();
4859 }
4860
Adam Cohen432609a2014-03-13 17:03:22 -07004861 /**
4862 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4863 * screen that must be displayed and dismissed.
4864 */
4865 protected boolean hasDismissableIntroScreen() {
4866 return false;
4867 }
4868
4869 /**
4870 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4871 */
4872 protected View getIntroScreen() {
4873 return null;
4874 }
4875
4876 /**
4877 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4878 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4879 */
4880 private boolean shouldShowIntroScreen() {
4881 return hasDismissableIntroScreen() &&
4882 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4883 }
4884
4885 protected void showIntroScreen() {
4886 View introScreen = getIntroScreen();
4887 changeWallpaperVisiblity(false);
4888 if (introScreen != null) {
4889 mDragLayer.showOverlayView(introScreen);
4890 }
4891 }
4892
4893 public void dismissIntroScreen() {
4894 markIntroScreenDismissed();
4895 if (showFirstRunActivity()) {
4896 // We delay hiding the intro view until the first run activity is showing. This
4897 // avoids a blip.
4898 mWorkspace.postDelayed(new Runnable() {
4899 @Override
4900 public void run() {
4901 mDragLayer.dismissOverlayView();
4902 }
4903 }, ACTIVITY_START_DELAY);
4904 } else {
4905 mDragLayer.dismissOverlayView();
4906 }
4907 changeWallpaperVisiblity(true);
4908 }
4909
4910 private void markIntroScreenDismissed() {
4911 SharedPreferences.Editor editor = mSharedPrefs.edit();
4912 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4913 editor.apply();
4914 }
4915
Winson Chunga6945242014-01-08 14:04:34 -08004916 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004917 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4918 if (mHotseat != null) mHotseat.setAlpha(1f);
4919 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4920 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004921 }
4922
4923 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004924 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4925 if (mHotseat != null) mHotseat.setAlpha(0f);
4926 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4927 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004928 }
4929
Mathew Inwood72fbec12013-11-19 15:45:07 +00004930 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004931 // Called from search suggestion, not supported in other profiles.
4932 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4933 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4934 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4935 myUser);
4936 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004937 return null;
4938 }
Kenny Guyed131872014-04-30 03:02:21 +01004939 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004940 }
4941
4942 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4943 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004944 // Called from search suggestion, not supported in other profiles.
4945 return createShortcutDragInfo(shortcutIntent, caption, icon,
4946 UserHandleCompat.myUserHandle());
4947 }
4948
4949 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4950 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01004951 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01004952 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01004953 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004954 }
4955
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004956 protected void moveWorkspaceToDefaultScreen() {
4957 mWorkspace.moveToDefaultScreen(false);
4958 }
4959
Mathew Inwood72fbec12013-11-19 15:45:07 +00004960 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4961 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004962 mWorkspace.onExternalDragStartedWithItem(dragView);
4963 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004964 }
4965
Anjali Koppalf5d29132014-02-28 13:33:27 -08004966 @Override
4967 public void onPageSwitch(View newPage, int newPageIndex) {
4968 }
4969
Winson Chung80baf5a2010-08-09 16:03:15 -07004970 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004971 * Prints out out state for debugging.
4972 */
4973 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004974 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004975 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004976 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4977 Log.d(TAG, "mRestoring=" + mRestoring);
4978 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4979 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004980 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004981 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004982
Winson Chung785d2eb2011-04-14 16:08:02 -07004983 if (mAppsCustomizeContent != null) {
4984 mAppsCustomizeContent.dumpState();
4985 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004986 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004987 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004988
4989 @Override
4990 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4991 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004992 synchronized (sDumpLogs) {
4993 writer.println(" ");
4994 writer.println("Debug logs: ");
4995 for (int i = 0; i < sDumpLogs.size(); i++) {
4996 writer.println(" " + sDumpLogs.get(i));
4997 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004998 }
4999 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005000
5001 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07005002 if (DEBUG_DUMP_LOG) {
5003 synchronized (sDumpLogs) {
5004 Log.d(TAG, "");
5005 Log.d(TAG, "*********************");
5006 Log.d(TAG, "Launcher debug logs: ");
5007 for (int i = 0; i < sDumpLogs.size(); i++) {
5008 Log.d(TAG, " " + sDumpLogs.get(i));
5009 }
5010 Log.d(TAG, "*********************");
5011 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07005012 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005013 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005014 }
5015
5016 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005017 addDumpLog(tag, log, null, debugLog);
5018 }
5019
5020 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07005021 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005022 if (e != null) {
5023 Log.d(tag, log, e);
5024 } else {
5025 Log.d(tag, log);
5026 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005027 }
Winson Chungede41292013-09-19 16:27:36 -07005028 if (DEBUG_DUMP_LOG) {
5029 sDateStamp.setTime(System.currentTimeMillis());
5030 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05005031 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5032 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07005033 }
Winson Chungede41292013-09-19 16:27:36 -07005034 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005035 }
5036
Winson Chungede41292013-09-19 16:27:36 -07005037 public void dumpLogsToLocalData() {
5038 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01005039 new AsyncTask<Void, Void, Void>() {
5040 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07005041 boolean success = false;
5042 sDateStamp.setTime(sRunStart);
5043 String FILENAME = sDateStamp.getMonth() + "-"
5044 + sDateStamp.getDay() + "_"
5045 + sDateStamp.getHours() + "-"
5046 + sDateStamp.getMinutes() + "_"
5047 + sDateStamp.getSeconds() + ".txt";
5048
5049 FileOutputStream fos = null;
5050 File outFile = null;
5051 try {
5052 outFile = new File(getFilesDir(), FILENAME);
5053 outFile.createNewFile();
5054 fos = new FileOutputStream(outFile);
5055 } catch (Exception e) {
5056 e.printStackTrace();
5057 }
5058 if (fos != null) {
5059 PrintWriter writer = new PrintWriter(fos);
5060
5061 writer.println(" ");
5062 writer.println("Debug logs: ");
5063 synchronized (sDumpLogs) {
5064 for (int i = 0; i < sDumpLogs.size(); i++) {
5065 writer.println(" " + sDumpLogs.get(i));
5066 }
5067 }
5068 writer.close();
5069 }
5070 try {
5071 if (fos != null) {
5072 fos.close();
5073 success = true;
5074 }
5075 } catch (IOException e) {
5076 e.printStackTrace();
5077 }
Michael Jurka43467462013-11-14 12:03:58 +01005078 return null;
Winson Chungede41292013-09-19 16:27:36 -07005079 }
Michael Jurka43467462013-11-14 12:03:58 +01005080 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07005081 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005082 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08005083}
Michael Jurka2763be32011-02-24 11:19:57 -08005084
Michael Jurkaabded662011-03-04 12:06:57 -08005085interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08005086 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07005087 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08005088 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08005089 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08005090 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08005091}
Dan Sandlerd5024042014-01-09 15:01:33 -05005092
5093interface DebugIntents {
5094 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5095 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00005096}