blob: 5d9ff1d55356e1dec335ab46821191cf16871138 [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
Winson Chunga6945242014-01-08 14:04:34 -0800129
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130/**
131 * Default launcher application.
132 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100133public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700134 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700135 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800136 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700137 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800138
Daniel Sandlerf061f822013-06-27 13:59:36 -0400139 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400140 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700141 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400142 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700143 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700144
Dan Sandlerd5024042014-01-09 15:01:33 -0500145 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
146
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700148 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700150 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700151 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800152
Michael Jurka8b805b12012-04-18 14:23:14 -0700153 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700154 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700155
Mathew Inwood876a8462013-06-14 14:12:41 +0100156 /**
157 * IntentStarter uses request codes starting with this. This must be greater than all activity
158 * request codes used internally.
159 */
160 protected static final int REQUEST_LAST = 100;
161
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
163
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800164 static final int SCREEN_COUNT = 5;
165 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166
Romain Guy98d01652009-06-30 16:21:04 -0700167 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800168 // To turn on these properties, type
169 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
170 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
171 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800172 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173
Winson Chung2672ff92012-05-04 16:22:30 -0700174 // The Intent extra that defines whether to ignore the launch animation
175 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400176 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700177
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800178 // Type: int
179 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700180 // Type: int
181 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700183 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
184 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
186 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700187 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700189 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190 // Type: boolean
191 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
192 // Type: long
193 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700194 // Type: int
195 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
196 // Type: int
197 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
198 // Type: parcelable
199 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000200 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800201 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000202 // Type: int[]
203 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204
Adam Cohen432609a2014-03-13 17:03:22 -0700205 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800206 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
207
Adam Cohen3ed316a2014-07-23 18:21:20 -0700208 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
209 static final String ACTION_FIRST_LOAD_COMPLETE =
210 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
211
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100212 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700213 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100214 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700215 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100216 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700217
Adam Cohen39a06042013-07-19 14:30:12 -0700218 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700219 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700220
Winson Chunga6945242014-01-08 14:04:34 -0800221 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
222
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700223 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700224 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700225 private State mState = State.WORKSPACE;
226 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700227
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700228 private boolean mIsSafeModeEnabled;
229
Joe Onorato9c1289c2009-08-17 11:03:03 -0400230 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700231 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
232 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700233 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800234
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800235 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800236 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800237
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000238 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
239 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
240
Winson Chunga2413752012-04-03 14:22:34 -0700241 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700242 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
243 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700244 private static int NEW_APPS_ANIMATION_DELAY = 500;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700245 private static final int SINGLE_FRAME_DELAY = 16;
Winson Chunga2413752012-04-03 14:22:34 -0700246
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800247 private final BroadcastReceiver mCloseSystemDialogsReceiver
248 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800249 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
250
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800251 private LayoutInflater mInflater;
252
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800253 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700254 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800255 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800256 private DragLayer mDragLayer;
257 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700258 private View mWeightWatcher;
Winson Chunga6945242014-01-08 14:04:34 -0800259 private LauncherClings mLauncherClings;
Romain Guycbb89e42009-06-08 15:52:54 -0700260
Sunny Goyalffe83f12014-08-14 17:39:34 -0700261 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700262 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700263
Michael Jurkac9d95c52011-08-29 14:03:34 -0700264 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700265 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800266 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700267
Michael Jurka0280c3b2010-09-17 15:00:07 -0700268 private int[] mTmpAddItemCellCoordinates = new int[2];
269
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270 private FolderInfo mFolderInfo;
271
Winson Chung3d503fb2011-07-13 17:25:49 -0700272 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800273 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700274
Michael Jurka838a4ca2011-02-07 13:33:06 -0800275 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700276
Winson Chungc51db6a2011-10-05 11:44:49 -0700277 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700278 private AppsCustomizeTabHost mAppsCustomizeTabHost;
279 private AppsCustomizePagedView mAppsCustomizeContent;
280 private boolean mAutoAdvanceRunning = false;
Adam Cohen24ce0b32014-01-14 16:18:14 -0800281 private View mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800282
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800283 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700284 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
285 // scroll issues (because the workspace may not have been measured yet) and extra work.
286 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
287 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800288
289 private SpannableStringBuilder mDefaultKeySsb = null;
290
Joe Onorato9c1289c2009-08-17 11:03:03 -0400291 private boolean mWorkspaceLoading = true;
292
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800293 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800294 private boolean mRestoring;
295 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700296 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800297
Michael Jurka1e2f4652013-07-08 18:03:46 -0700298 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700299 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
300
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800301 private Bundle mSavedInstanceState;
302
Joe Onorato9c1289c2009-08-17 11:03:03 -0400303 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800304 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800305 private boolean mUserPresent = true;
306 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700307 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800308 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400309
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700310 private static LocaleConfiguration sLocaleConfiguration = null;
311
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700312 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700313
Adam Cohen61f560d2013-09-30 15:58:20 -0700314 private View.OnTouchListener mHapticFeedbackTouchListener;
315
Adam Cohended9f8d2010-11-03 13:25:16 -0700316 // Related to the auto-advancing of widgets
317 private final int ADVANCE_MSG = 1;
318 private final int mAdvanceInterval = 20000;
319 private final int mAdvanceStagger = 250;
320 private long mAutoAdvanceSentTime;
321 private long mAutoAdvanceTimeLeft = -1;
322 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
323 new HashMap<View, AppWidgetProviderInfo>();
324
Winson Chung400438b2011-01-16 17:53:48 -0800325 // Determines how long to wait after a rotation before restoring the screen orientation to
326 // match the sensor state.
327 private final int mRestoreScreenOrientationDelay = 500;
328
Michael Jurka4ef207b2010-11-29 17:05:45 -0800329 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700330 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
331 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
Winson Chungd64a6662013-09-30 11:06:59 -0700332
Craig Mautner360310b2012-10-26 15:13:08 -0700333 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700334
Adam Cohen1462de32012-07-24 22:34:36 -0700335 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700336 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700337
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700338 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700339 static Date sDateStamp = new Date();
340 static DateFormat sDateFormat =
341 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
342 static long sRunStart = System.currentTimeMillis();
343 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700344
Winson Chung46353de2012-02-16 14:05:10 -0800345 // We only want to get the SharedPreferences once since it does an FS stat each time we get
346 // it from the context.
347 private SharedPreferences mSharedPrefs;
348
Adam Cohene25af792013-06-06 23:08:25 -0700349 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
350
Winson Chungf0c6ae02012-03-21 16:10:31 -0700351 // Holds the page that we need to animate to, and the icon views that we need to animate up
352 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700353 private ImageView mFolderIconImageView;
354 private Bitmap mFolderIconBitmap;
355 private Canvas mFolderIconCanvas;
356 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700357
Michael Jurkaddd62e92011-02-16 17:49:14 -0800358 private BubbleTextView mWaitingForResume;
359
Michael Jurkac1f5d262011-09-30 19:32:27 -0700360 private Runnable mBuildLayersRunnable = new Runnable() {
361 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700362 if (mWorkspace != null) {
363 mWorkspace.buildPageHardwareLayers();
364 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700365 }
366 };
367
Adam Cohendb364c32014-05-20 14:23:40 -0700368 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800369
Michael Jurka7267fa52013-09-26 15:29:57 -0700370 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800371
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800372 private static class PendingAddArguments {
373 int requestCode;
374 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700375 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700376 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800377 int cellX;
378 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700379 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800380 }
381
Daniel Sandlerff02d492013-08-05 02:12:05 -0400382 private Stats mStats;
383
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700384 FocusIndicatorView mFocusHandler;
385
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800386 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800387 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700388 }
389
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800390 @Override
391 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700392 if (DEBUG_STRICT_MODE) {
393 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
394 .detectDiskReads()
395 .detectDiskWrites()
396 .detectNetwork() // or .detectAll() for all detectable problems
397 .penaltyLog()
398 .build());
399 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
400 .detectLeakedSqlLiteObjects()
401 .detectLeakedClosableObjects()
402 .penaltyLog()
403 .penaltyDeath()
404 .build());
405 }
406
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800407 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400408
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400409 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400410 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700411 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700412 // Determine the dynamic grid properties
413 Point smallestSize = new Point();
414 Point largestSize = new Point();
415 Point realSize = new Point();
416 Display display = getWindowManager().getDefaultDisplay();
417 display.getCurrentSizeRange(smallestSize, largestSize);
418 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700419 DisplayMetrics dm = new DisplayMetrics();
420 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700421
Winson Chung5f8afe62013-08-12 16:19:28 -0700422 // Lazy-initialize the dynamic grid
423 DeviceProfile grid = app.initDynamicGrid(this,
424 Math.min(smallestSize.x, smallestSize.y),
425 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700426 realSize.x, realSize.y,
427 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700428
429 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400430 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700431 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700432 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800433 mModel = app.setLauncher(this);
434 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700435 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400436 mDragController = new DragController(this);
Winson Chunga6945242014-01-08 14:04:34 -0800437 mLauncherClings = new LauncherClings(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800438 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700439
Daniel Sandlerff02d492013-08-05 02:12:05 -0400440 mStats = new Stats(this);
441
Sunny Goyalffe83f12014-08-14 17:39:34 -0700442 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700443
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700444 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
445 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700446
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700447 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
448 // this also ensures that any synchronous binding below doesn't re-trigger another
449 // LauncherModel load.
450 mPaused = false;
451
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800452 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200453 android.os.Debug.startMethodTracing(
454 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800455 }
456
457 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800458 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700459
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100461 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800462
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800463 registerContentObservers();
464
Joe Onorato7c312c12009-08-13 21:36:53 -0700465 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700466
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800467 mSavedState = savedInstanceState;
468 restoreState(mSavedState);
469
470 if (PROFILE_STARTUP) {
471 android.os.Debug.stopMethodTracing();
472 }
473
474 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700475 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700476 // If the user leaves launcher, then we should just load items asynchronously when
477 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500478 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700479 } else {
480 // We only load the page synchronously if the user rotates (or triggers a
481 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800482 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700483 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800484 }
485
486 // For handling default keys
487 mDefaultKeySsb = new SpannableStringBuilder();
488 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800489
490 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
491 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800492
Adam Cohenf9426d52012-06-04 17:26:21 -0700493 updateGlobalIcons();
494
495 // On large interfaces, we want the screen to auto-rotate based on the current orientation
496 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700497
Adam Cohen432609a2014-03-13 17:03:22 -0700498 if (shouldShowIntroScreen()) {
499 showIntroScreen();
500 } else {
501 showFirstRunActivity();
502 }
503
Winson Chunge43a1e72014-01-15 10:33:02 -0800504 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
505 // on the device, then we always show the first run cling experience (or if there is no
506 // launcher2). Otherwise, we prompt the user upon started for migration
Winson Chunge43a1e72014-01-15 10:33:02 -0800507 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
508 if (mModel.canMigrateFromOldLauncherDb(this)) {
509 mLauncherClings.showMigrationCling();
510 } else {
511 mLauncherClings.showFirstRunCling();
512 }
Winson Chunga6945242014-01-08 14:04:34 -0800513 } else {
Winson Chunge43a1e72014-01-15 10:33:02 -0800514 mLauncherClings.removeFirstRunAndMigrationClings();
Winson Chunga6945242014-01-08 14:04:34 -0800515 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700516 }
517
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700518 @Override
519 public void onLauncherProviderChange() { }
520
Winson Chung98ca0f72013-07-29 12:58:51 -0700521 /** To be overriden by subclasses to hint to Launcher that we have custom content */
522 protected boolean hasCustomContentToLeft() {
523 return false;
524 }
525
Dave Hawkeya8881582013-09-17 15:55:33 -0600526 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500527 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600528 * {@link #addToCustomContentPage}. This will only be invoked if
529 * {@link #hasCustomContentToLeft()} is {@code true}.
530 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500531 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600532 }
533
534 /**
535 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
536 * ensure the custom content page is added or removed if necessary.
537 */
538 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600539 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600540 // Not bound yet, wait for bindScreens to be called.
541 return;
542 }
543
544 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
545 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500546 mWorkspace.createCustomContentContainer();
547 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600548 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
549 mWorkspace.removeCustomContentPage();
550 }
551 }
552
Adam Cohenf9426d52012-06-04 17:26:21 -0700553 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700554 boolean searchVisible = false;
555 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800556 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700557 int coi = getCurrentOrientationIndexForGlobalIcons();
Adam Cohena00673c2014-08-14 12:57:28 -0700558 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700559 searchVisible = updateGlobalSearchIcon();
560 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700561 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700562 if (sGlobalSearchIcon[coi] != null) {
563 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700564 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700565 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700566 if (sVoiceSearchIcon[coi] != null) {
567 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700568 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700569 }
Winson Chungadf0c182012-08-23 14:59:07 -0700570 if (mSearchDropTargetBar != null) {
571 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
572 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800573 }
Romain Guycbb89e42009-06-08 15:52:54 -0700574
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800575 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700576 if (sLocaleConfiguration == null) {
577 new AsyncTask<Void, Void, LocaleConfiguration>() {
578 @Override
579 protected LocaleConfiguration doInBackground(Void... unused) {
580 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
581 readConfiguration(Launcher.this, localeConfiguration);
582 return localeConfiguration;
583 }
584
585 @Override
586 protected void onPostExecute(LocaleConfiguration result) {
587 sLocaleConfiguration = result;
588 checkForLocaleChange(); // recursive, but now with a locale configuration
589 }
590 }.execute();
591 return;
592 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700593
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800594 final Configuration configuration = getResources().getConfiguration();
595
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700596 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800597 final String locale = configuration.locale.toString();
598
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700599 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800600 final int mcc = configuration.mcc;
601
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700602 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800603 final int mnc = configuration.mnc;
604
Romain Guy84f296c2009-11-04 15:00:44 -0800605 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800606
Romain Guy84f296c2009-11-04 15:00:44 -0800607 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700608 sLocaleConfiguration.locale = locale;
609 sLocaleConfiguration.mcc = mcc;
610 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700611
Joe Onorato0589f0f2010-02-08 13:44:00 -0800612 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700613
614 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100615 new AsyncTask<Void, Void, Void>() {
616 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700617 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100618 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700619 }
Michael Jurka43467462013-11-14 12:03:58 +0100620 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700621 }
622 }
623
624 private static class LocaleConfiguration {
625 public String locale;
626 public int mcc = -1;
627 public int mnc = -1;
628 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700629
Romain Guy98d01652009-06-30 16:21:04 -0700630 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
631 DataInputStream in = null;
632 try {
633 in = new DataInputStream(context.openFileInput(PREFERENCES));
634 configuration.locale = in.readUTF();
635 configuration.mcc = in.readInt();
636 configuration.mnc = in.readInt();
637 } catch (FileNotFoundException e) {
638 // Ignore
639 } catch (IOException e) {
640 // Ignore
641 } finally {
642 if (in != null) {
643 try {
644 in.close();
645 } catch (IOException e) {
646 // Ignore
647 }
648 }
649 }
650 }
651
652 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
653 DataOutputStream out = null;
654 try {
655 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
656 out.writeUTF(configuration.locale);
657 out.writeInt(configuration.mcc);
658 out.writeInt(configuration.mnc);
659 out.flush();
660 } catch (FileNotFoundException e) {
661 // Ignore
662 } catch (IOException e) {
663 //noinspection ResultOfMethodCallIgnored
664 context.getFileStreamPath(PREFERENCES).delete();
665 } finally {
666 if (out != null) {
667 try {
668 out.close();
669 } catch (IOException e) {
670 // Ignore
671 }
672 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 }
674 }
675
Anton Hanssona2f665f2013-09-26 12:18:32 +0100676 public Stats getStats() {
677 return mStats;
678 }
679
Bjorn Bringertc459e522013-06-07 19:36:01 +0100680 public LayoutInflater getInflater() {
681 return mInflater;
682 }
683
Winson Chung36a62fe2012-05-06 18:04:42 -0700684 boolean isDraggingEnabled() {
685 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
686 // that is subsequently removed from the workspace in startBinding().
687 return !mModel.isLoadingWorkspace();
688 }
689
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800690 static int getScreen() {
691 synchronized (sLock) {
692 return sScreen;
693 }
694 }
695
696 static void setScreen(int screen) {
697 synchronized (sLock) {
698 sScreen = screen;
699 }
700 }
701
Winson Chung557d6ed2011-07-08 15:34:52 -0700702 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000703 * Copied from View -- the View version of the method isn't called
704 * anywhere else in our process and only exists for API level 17+,
705 * so it's ok to keep our own version with no API requirement.
706 */
707 public static int generateViewId() {
708 for (;;) {
709 final int result = sNextGeneratedId.get();
710 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
711 int newValue = result + 1;
712 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
713 if (sNextGeneratedId.compareAndSet(result, newValue)) {
714 return result;
715 }
716 }
717 }
718
719 public int getViewIdForItem(ItemInfo info) {
720 // This cast is safe given the > 2B range for int.
721 int itemId = (int) info.id;
722 if (mItemIdToViewId.containsKey(itemId)) {
723 return mItemIdToViewId.get(itemId);
724 }
725 int viewId = generateViewId();
726 mItemIdToViewId.put(itemId, viewId);
727 return viewId;
728 }
729
730 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700731 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
732 * a configuration step, this allows the proper animations to run after other transitions.
733 */
Adam Cohendb364c32014-05-20 14:23:40 -0700734 private long completeAdd(PendingAddArguments args) {
735
736 long screenId = ensurePendingDropLayoutExists(args.screenId);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800737 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800738 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700739 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700740 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700741 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800742 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700743 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700744 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700745 case REQUEST_RECONFIGURE_APPWIDGET:
746 completeRestoreAppWidget(args.appWidgetId);
747 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800748 }
Michael Jurka27614d22012-04-02 06:40:22 -0700749 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
750 // if you turned the screen off and then back while in All Apps, Launcher would not
751 // return to the workspace. Clearing mAddInfo.container here fixes this issue
752 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700753 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800754 }
755
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800756 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700757 protected void onActivityResult(
758 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700759 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700760 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700761 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800762 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700763
Adam Cohenad4e15c2013-10-17 16:21:35 -0700764 Runnable exitSpringLoaded = new Runnable() {
765 @Override
766 public void run() {
767 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
768 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
769 }
770 };
771
Michael Jurka8b805b12012-04-18 14:23:14 -0700772 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700773 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700774 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
775 if (resultCode == RESULT_CANCELED) {
776 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700777 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700778 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700779 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700780 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
781 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700782 }
783 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200784 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
785 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
786 mWorkspace.exitOverviewMode(false);
787 }
788 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700789 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200790
Adam Cohened66b2b2012-01-23 17:28:51 -0800791 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
792 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700793
Adam Cohendb364c32014-05-20 14:23:40 -0700794 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800795 // We have special handling for widgets
796 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800797 final int appWidgetId;
798 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
799 : -1;
800 if (widgetId < 0) {
801 appWidgetId = pendingAddWidgetId;
802 } else {
803 appWidgetId = widgetId;
804 }
805
Adam Cohenad4e15c2013-10-17 16:21:35 -0700806 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800807 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700808 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
809 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700810 result = RESULT_CANCELED;
811 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700812 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700813 @Override
814 public void run() {
815 exitSpringLoadedDragModeDelayed(false, 0, null);
816 }
817 };
Adam Cohendb364c32014-05-20 14:23:40 -0700818 if (workspaceLocked) {
819 // No need to remove the empty screen if we're mid-binding, as the
820 // the bind will not add the empty screen.
821 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
822 } else {
823 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
824 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
825 }
Winson Chung5aaab772012-04-27 15:24:02 -0700826 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700827 if (!workspaceLocked) {
828 mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
829 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
830
831 dropLayout.setDropPending(true);
832 final Runnable onComplete = new Runnable() {
833 @Override
834 public void run() {
835 completeTwoStageWidgetDrop(resultCode, appWidgetId);
836 dropLayout.setDropPending(false);
837 }
838 };
839 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
840 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
841 } else {
842 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
843 mPendingAddInfo);
844 sPendingAddItem = args;
845 }
Winson Chung5aaab772012-04-27 15:24:02 -0700846 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800847 return;
848 }
849
Sunny Goyalff572272014-07-23 13:58:07 -0700850 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
851 if (resultCode == RESULT_OK) {
852 // Update the widget view.
853 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
854 pendingAddWidgetId, mPendingAddInfo);
855 if (workspaceLocked) {
856 sPendingAddItem = args;
857 } else {
858 completeAdd(args);
859 }
860 }
861 // Leave the widget in the pending state if the user canceled the configure.
862 return;
863 }
864
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800865 // The pattern used here is that a user PICKs a specific application,
866 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700867
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800868 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
869 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700870 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700871 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
872 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800873 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700874 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800875 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700876 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700877 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
878 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800879 }
Adam Cohen00074722013-10-11 17:46:09 -0700880 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700881 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700882 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800883 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800884 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800885 }
886
Adam Cohendb364c32014-05-20 14:23:40 -0700887 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
888 appWidgetId, ItemInfo info) {
889 PendingAddArguments args = new PendingAddArguments();
890 args.requestCode = requestCode;
891 args.intent = data;
892 args.container = info.container;
893 args.screenId = info.screenId;
894 args.cellX = info.cellX;
895 args.cellY = info.cellY;
896 args.appWidgetId = appWidgetId;
897 return args;
898 }
899
900 /**
901 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
902 *
903 * @param screenId the screen id to check
904 * @return the new screen, or screenId if it exists
905 */
906 private long ensurePendingDropLayoutExists(long screenId) {
907 CellLayout dropLayout =
908 (CellLayout) mWorkspace.getScreenWithId(screenId);
909 if (dropLayout == null) {
910 // it's possible that the add screen was removed because it was
911 // empty and a re-bind occurred
912 mWorkspace.addExtraEmptyScreen();
913 return mWorkspace.commitExtraEmptyScreen();
914 } else {
915 return screenId;
916 }
917 }
918
Adam Cohened66b2b2012-01-23 17:28:51 -0800919 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700920 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700921 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800922 Runnable onCompleteRunnable = null;
923 int animationType = 0;
924
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700925 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800926 if (resultCode == RESULT_OK) {
927 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
928 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700929 mPendingAddWidgetInfo);
930 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800931 onCompleteRunnable = new Runnable() {
932 @Override
933 public void run() {
934 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700935 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700936 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
937 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800938 }
939 };
940 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800941 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800942 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800943 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700944 if (mDragLayer.getAnimatedView() != null) {
945 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
946 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
947 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700948 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700949 // The animated view may be null in the case of a rotation during widget configuration
950 onCompleteRunnable.run();
951 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800952 }
953
954 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700955 protected void onStop() {
956 super.onStop();
957 FirstFrameAnimatorHelper.setIsVisible(false);
958 }
959
960 @Override
961 protected void onStart() {
962 super.onStart();
963 FirstFrameAnimatorHelper.setIsVisible(true);
964 }
965
966 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800967 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200968 long startTime = 0;
969 if (DEBUG_RESUME_TIME) {
970 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400971 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200972 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800973 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700974
Winson Chung4a2afa32012-07-19 14:53:05 -0700975 // Restore the previous launcher state
976 if (mOnResumeState == State.WORKSPACE) {
977 showWorkspace(false);
978 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -0800979 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700980 }
981 mOnResumeState = State.NONE;
982
Craig Mautner360310b2012-10-26 15:13:08 -0700983 // Background was set to gradient in onPause(), restore to black if in all apps.
984 setWorkspaceBackground(mState == State.WORKSPACE);
985
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800986 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700987 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700988 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500989 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400990 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700991 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800992 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700993 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200994 // We might have postponed some bind calls until onResume (see waitUntilResume) --
995 // execute them here
996 long startTimeCallbacks = 0;
997 if (DEBUG_RESUME_TIME) {
998 startTimeCallbacks = System.currentTimeMillis();
999 }
1000
1001 if (mAppsCustomizeContent != null) {
1002 mAppsCustomizeContent.setBulkBind(true);
1003 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001004 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1005 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001006 }
1007 if (mAppsCustomizeContent != null) {
1008 mAppsCustomizeContent.setBulkBind(false);
1009 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001010 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001011 if (DEBUG_RESUME_TIME) {
1012 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1013 (System.currentTimeMillis() - startTimeCallbacks));
1014 }
Michael Jurka447bf842013-05-15 14:52:15 +02001015 }
Michael Jurka54554252013-08-01 12:52:23 +02001016 if (mOnResumeCallbacks.size() > 0) {
1017 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1018 mOnResumeCallbacks.get(i).run();
1019 }
1020 mOnResumeCallbacks.clear();
1021 }
Winson Chunge4e50662012-01-23 14:45:13 -08001022
1023 // Reset the pressed state of icons that were locked in the press state while activities
1024 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001025 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001026 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001027 mWaitingForResume.setStayPressed(false);
1028 }
Winson Chung82963d52013-10-09 11:20:57 -07001029
Adam Cohen06dff352012-06-01 17:17:08 -07001030 // It is possible that widgets can receive updates while launcher is not in the foreground.
1031 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1032 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1033 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001034 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001035
Winson Chung780fe592013-09-26 14:48:44 -07001036 // Process any items that were added while Launcher was away.
1037 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1038
Winson Chung5841efa2013-09-30 18:06:44 -07001039 // Update the voice search button proxy
1040 updateVoiceButtonProxyVisible(false);
1041
Adam Cohenf9426d52012-06-04 17:26:21 -07001042 // Again, as with the above scenario, it's possible that one or more of the global icons
1043 // were updated in the wrong orientation.
1044 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001045 if (DEBUG_RESUME_TIME) {
1046 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1047 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001048
1049 if (mWorkspace.getCustomContentCallbacks() != null) {
1050 // If we are resuming and the custom content is the current page, we call onShow().
1051 // It is also poassible that onShow will instead be called slightly after first layout
1052 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1053 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001054 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001055 }
1056 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001057 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001058 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001059
1060 PackageInstallerCompat.getInstance(this).onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001061 }
1062
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001063 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001064 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001065 // Ensure that items added to Launcher are queued until Launcher returns
1066 InstallShortcutReceiver.enableInstallQueue();
Sunny Goyale755d462014-07-22 13:48:29 -07001067 PackageInstallerCompat.getInstance(this).onPause();
Winson Chung997a9232013-07-24 15:33:46 -07001068
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001069 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001070 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001071 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001072 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001073
1074 // We call onHide() aggressively. The custom content callbacks should be able to
1075 // debounce excess onHide calls.
1076 if (mWorkspace.getCustomContentCallbacks() != null) {
1077 mWorkspace.getCustomContentCallbacks().onHide();
1078 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001079 }
Romain Guycbb89e42009-06-08 15:52:54 -07001080
Adam Cohenbffe7452013-07-22 18:21:45 -07001081 QSBScroller mQsbScroller = new QSBScroller() {
1082 int scrollY = 0;
1083
1084 @Override
1085 public void setScrollY(int scroll) {
1086 scrollY = scroll;
1087
1088 if (mWorkspace.isOnOrMovingToCustomContent()) {
1089 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001090 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001091 }
1092 }
1093 };
1094
1095 public void resetQSBScroll() {
1096 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001097 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001098 }
1099
1100 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001101 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1102 // by a onResume or by scrolling otherwise.
1103 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001104
1105 // Custom content is completely hidden
1106 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001107
1108 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1109 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001110
1111 // Indicates whether the user is allowed to scroll away from the custom content.
1112 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001113 }
1114
Jorim Jaggid017f882014-01-14 17:08:48 -08001115 protected boolean hasSettings() {
1116 return false;
1117 }
1118
Adam Cohenbffe7452013-07-22 18:21:45 -07001119 public interface QSBScroller {
1120 public void setScrollY(int scrollY);
1121 }
1122
Winson Chung98ca0f72013-07-29 12:58:51 -07001123 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001124 CustomContentCallbacks callbacks, String description) {
1125 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001126 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001127 }
1128
Adam Cohenedb40762013-07-18 16:45:45 -07001129 // The custom content needs to offset its content to account for the QSB
1130 public int getTopOffsetForCustomContent() {
1131 return mWorkspace.getPaddingTop();
1132 }
1133
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001134 @Override
1135 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001136 // Flag the loader to stop early before switching
1137 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001138 if (mAppsCustomizeContent != null) {
1139 mAppsCustomizeContent.surrender();
1140 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001141 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001142 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001143
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001144 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001145 @Override
1146 public void onWindowFocusChanged(boolean hasFocus) {
1147 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001148 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001149 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001150
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001151 private boolean acceptFilter() {
1152 final InputMethodManager inputManager = (InputMethodManager)
1153 getSystemService(Context.INPUT_METHOD_SERVICE);
1154 return !inputManager.isFullscreenMode();
1155 }
1156
1157 @Override
1158 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001159 final int uniChar = event.getUnicodeChar();
1160 final boolean handled = super.onKeyDown(keyCode, event);
1161 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1162 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001163 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1164 keyCode, event);
1165 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001166 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001167 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001168 // showSearchDialog()
1169 // If there are multiple keystrokes before the search dialog takes focus,
1170 // onSearchRequested() will be called for every keystroke,
1171 // but it is idempotent, so it's fine.
1172 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001173 }
1174 }
1175
Joe Onorato8a9625e2010-01-28 15:55:35 -08001176 // Eat the long press event so the keyboard doesn't come up.
1177 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1178 return true;
1179 }
1180
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001181 return handled;
1182 }
1183
Karl Rosaen138a0412009-04-23 19:00:21 -07001184 private String getTypedText() {
1185 return mDefaultKeySsb.toString();
1186 }
1187
1188 private void clearTypedText() {
1189 mDefaultKeySsb.clear();
1190 mDefaultKeySsb.clearSpans();
1191 Selection.setSelection(mDefaultKeySsb, 0);
1192 }
1193
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001194 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001195 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1196 * State
1197 */
1198 private static State intToState(int stateOrdinal) {
1199 State state = State.WORKSPACE;
1200 final State[] stateValues = State.values();
1201 for (int i = 0; i < stateValues.length; i++) {
1202 if (stateValues[i].ordinal() == stateOrdinal) {
1203 state = stateValues[i];
1204 break;
1205 }
1206 }
1207 return state;
1208 }
1209
1210 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001211 * Restores the previous state, if it exists.
1212 *
1213 * @param savedState The previous state.
1214 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001215 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001216 private void restoreState(Bundle savedState) {
1217 if (savedState == null) {
1218 return;
1219 }
1220
Michael Jurka883f55b2010-10-21 15:47:14 -07001221 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001222 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001223 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001224 }
1225
Adam Cohen21cd0022013-10-09 18:57:02 -07001226 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1227 PagedView.INVALID_RESTORE_PAGE);
1228 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001229 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001230 }
1231
Winson Chung3d503fb2011-07-13 17:25:49 -07001232 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001233 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001234
Winson Chung3d503fb2011-07-13 17:25:49 -07001235 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1236 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001237 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001238 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1239 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001240 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1241 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1242 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001243 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001244 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001245 mRestoring = true;
1246 }
1247
1248 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1249 if (renameFolder) {
1250 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001251 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001252 mRestoring = true;
1253 }
Winson Chunga12a2502010-12-20 14:41:35 -08001254
Winson Chung785d2eb2011-04-14 16:08:02 -07001255 // Restore the AppsCustomize tab
1256 if (mAppsCustomizeTabHost != null) {
1257 String curTab = savedState.getString("apps_customize_currentTab");
1258 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001259 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001260 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001261 mAppsCustomizeContent.loadAssociatedPages(
1262 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001263 }
1264
Winson Chung5afbf7b2011-07-25 11:53:08 -07001265 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1266 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001267 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001268 mItemIdToViewId = (HashMap<Integer, Integer>)
1269 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001270 }
1271
1272 /**
1273 * Finds all the views we need and configure them properly.
1274 */
1275 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001276 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001277
Craig Mautner360310b2012-10-26 15:13:08 -07001278 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001279 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001280 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1281 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001282 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001283 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001284
John Spurlock77e1f472013-09-11 10:09:51 -04001285 mLauncherView.setSystemUiVisibility(
1286 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001287 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001288
Winson Chung4c98d922011-05-31 16:50:48 -07001289 // Setup the drag layer
1290 mDragLayer.setup(this, dragController);
1291
Winson Chung3d503fb2011-07-13 17:25:49 -07001292 // Setup the hotseat
1293 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1294 if (mHotseat != null) {
1295 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001296 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001297 }
1298
Jorim Jaggid017f882014-01-14 17:08:48 -08001299 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001300 View widgetButton = findViewById(R.id.widget_button);
1301 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001302 @Override
1303 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001304 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001305 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001306 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001307 }
1308 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001309 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1310
1311 View wallpaperButton = findViewById(R.id.wallpaper_button);
1312 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001313 @Override
1314 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001315 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001316 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001317 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001318 }
1319 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001320 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1321
1322 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001323 if (hasSettings()) {
1324 settingsButton.setOnClickListener(new OnClickListener() {
1325 @Override
1326 public void onClick(View arg0) {
1327 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001328 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001329 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001330 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001331 });
1332 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1333 } else {
1334 settingsButton.setVisibility(View.GONE);
1335 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1336 lp.gravity = Gravity.END | Gravity.TOP;
1337 widgetButton.requestLayout();
1338 }
1339
Adam Cohendbdff6b2013-09-18 19:09:15 -07001340 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001341
Winson Chung4c98d922011-05-31 16:50:48 -07001342 // Setup the workspace
1343 mWorkspace.setHapticFeedbackEnabled(false);
1344 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001345 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001346 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001347
Winson Chungf0ea4d32011-06-06 14:27:16 -07001348 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001349 mSearchDropTargetBar = (SearchDropTargetBar)
1350 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001351
Winson Chungf0ea4d32011-06-06 14:27:16 -07001352 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001353 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001354 mAppsCustomizeContent = (AppsCustomizePagedView)
1355 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1356 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001357
Winson Chung3d503fb2011-07-13 17:25:49 -07001358 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001359 dragController.setDragScoller(mWorkspace);
1360 dragController.setScrollView(mDragLayer);
1361 dragController.setMoveTarget(mWorkspace);
1362 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001363 if (mSearchDropTargetBar != null) {
1364 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001365 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001366
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001367 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001368 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001369 mWeightWatcher = new WeightWatcher(this);
1370 mWeightWatcher.setAlpha(0.5f);
1371 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001372 new FrameLayout.LayoutParams(
1373 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001374 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001375 Gravity.BOTTOM)
1376 );
Adam Cohen39a06042013-07-19 14:30:12 -07001377
1378 boolean show = shouldShowWeightWatcher();
1379 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001380 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001381 }
1382
1383 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001384 * Sets the all apps button. This method is called from {@link Hotseat}.
1385 */
1386 public void setAllAppsButton(View allAppsButton) {
1387 mAllAppsButton = allAppsButton;
1388 }
1389
1390 public View getAllAppsButton() {
1391 return mAllAppsButton;
1392 }
1393
1394 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001395 * Creates a view representing a shortcut.
1396 *
1397 * @param info The data structure describing the shortcut.
1398 *
1399 * @return A View inflated from R.layout.application.
1400 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001401 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001402 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001403 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001404 }
1405
1406 /**
1407 * Creates a view representing a shortcut inflated from the specified resource.
1408 *
1409 * @param layoutResId The id of the XML layout used to create the shortcut.
1410 * @param parent The group the shortcut belongs to.
1411 * @param info The data structure describing the shortcut.
1412 *
1413 * @return A View inflated from layoutResId.
1414 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001415 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001416 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001417 favorite.applyFromShortcutInfo(info, mIconCache, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001418 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001419 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001420 return favorite;
1421 }
1422
1423 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001424 * Add a shortcut to the workspace.
1425 *
1426 * @param data The intent describing the shortcut.
1427 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001428 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001429 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001430 int cellY) {
1431 int[] cellXY = mTmpAddItemCellCoordinates;
1432 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001433 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001434
Michael Jurkad3ef3062010-11-23 16:23:58 -08001435 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001436
Adam Cohen558baaf2011-08-15 15:22:57 -07001437 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001438 if (info == null) {
1439 return;
1440 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001441 final View view = createShortcut(info);
1442
Adam Cohenfbba09b2011-07-18 21:43:05 -07001443 // First we check if we already know the exact location where we want to add this item.
1444 if (cellX >= 0 && cellY >= 0) {
1445 cellXY[0] = cellX;
1446 cellXY[1] = cellY;
1447 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001448
1449 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001450 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001451 true, null,null)) {
1452 return;
1453 }
1454 DragObject dragObject = new DragObject();
1455 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001456 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1457 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001458 return;
1459 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001460 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001461 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001462 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001463 foundCellSpan = (result != null);
1464 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001465 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001466 }
1467
1468 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001469 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001470 return;
1471 }
1472
Adam Cohendcd297f2013-06-18 13:13:40 -07001473 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001474
1475 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001476 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001477 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001478 }
1479 }
1480
Adam Cohen2f093b62012-04-30 18:59:53 -07001481 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1482 int minHeight) {
1483 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001484 // We want to account for the extra amount of padding that we are adding to the widget
1485 // to ensure that it gets the full amount of space that it has requested
1486 int requiredWidth = minWidth + padding.left + padding.right;
1487 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001488 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001489 }
1490
Adam Cohen2f093b62012-04-30 18:59:53 -07001491 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1492 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001493 }
1494
Adam Cohen2f093b62012-04-30 18:59:53 -07001495 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1496 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001497 }
1498
Adam Cohen2f093b62012-04-30 18:59:53 -07001499 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1500 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001501 }
1502
Adam Cohen2f093b62012-04-30 18:59:53 -07001503 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1504 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001505 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001506 }
1507
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001508 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001509 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001510 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001511 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001512 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001513 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001514 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001515 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1516 if (appWidgetInfo == null) {
1517 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1518 }
Romain Guycbb89e42009-06-08 15:52:54 -07001519
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001520 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001521 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001522
Adam Cohen2f093b62012-04-30 18:59:53 -07001523 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1524 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001525
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001526 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001527 // We have saved the position to which the widget was dragged-- this really only matters
1528 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001529 int[] cellXY = mTmpAddItemCellCoordinates;
1530 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001531 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001532 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001533 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1534 cellXY[0] = mPendingAddInfo.cellX;
1535 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001536 spanXY[0] = mPendingAddInfo.spanX;
1537 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001538 foundCellSpan = true;
1539 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001540 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001541 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001542 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1543 spanXY[1], cellXY, finalSpan);
1544 spanXY[0] = finalSpan[0];
1545 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001546 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001547 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001548 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001549 }
1550
Michael Jurka0280c3b2010-09-17 15:00:07 -07001551 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001552 if (appWidgetId != -1) {
1553 // Deleting an app widget ID is a void call but writes to disk before returning
1554 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001555 new AsyncTask<Void, Void, Void>() {
1556 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001557 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001558 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001559 }
Michael Jurka43467462013-11-14 12:03:58 +01001560 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001561 }
Winson Chung93eef082012-03-23 15:59:27 -07001562 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001563 return;
1564 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001565
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001566 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001567 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1568 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001569 launcherInfo.spanX = spanXY[0];
1570 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001571 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1572 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001573 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001574
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001575 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001576 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001577
1578 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001579 if (hostView == null) {
1580 // Perform actual inflation because we're live
1581 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1582 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1583 } else {
1584 // The AppWidgetHostView has already been inflated and instantiated
1585 launcherInfo.hostView = hostView;
1586 }
Romain Guycbb89e42009-06-08 15:52:54 -07001587
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001588 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001589 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001590 launcherInfo.notifyWidgetSizeChanged(this);
1591
Adam Cohendcd297f2013-06-18 13:13:40 -07001592 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001593 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001594
1595 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001596 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001597 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001598 }
Romain Guycbb89e42009-06-08 15:52:54 -07001599
Adam Cohended9f8d2010-11-03 13:25:16 -07001600 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1601 @Override
1602 public void onReceive(Context context, Intent intent) {
1603 final String action = intent.getAction();
1604 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1605 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001606 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001607 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001608
Winson Chungc100e8e2011-08-09 16:02:43 -07001609 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001610 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001611 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001612 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001613 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001614 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1615 mUserPresent = true;
1616 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001617 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1618 mModel.resetLoadedState(false, true);
1619 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1620 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1621 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1622 mModel.resetLoadedState(false, true);
1623 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1624 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1625 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001626 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1627 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1628 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001629 }
1630 }
1631 };
1632
1633 @Override
1634 public void onAttachedToWindow() {
1635 super.onAttachedToWindow();
1636
1637 // Listen for broadcasts related to user-presence
1638 final IntentFilter filter = new IntentFilter();
1639 filter.addAction(Intent.ACTION_SCREEN_OFF);
1640 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001641 // For handling managed profiles
1642 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1643 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001644 if (ENABLE_DEBUG_INTENTS) {
1645 filter.addAction(DebugIntents.DELETE_DATABASE);
1646 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1647 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001648 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001649 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001650 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001651 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001652 mVisible = true;
1653 }
1654
Adam Cohen0b395352014-06-09 22:54:36 +00001655 /**
1656 * Sets up transparent navigation and status bars in LMP.
1657 * This method is a no-op for other platform versions.
1658 */
1659 @TargetApi(19)
1660 private void setupTransparentSystemBarsForLmp() {
1661 // TODO(sansid): use the APIs directly when compiling against L sdk.
1662 // Currently we use reflection to access the flags and the API to set the transparency
1663 // on the System bars.
1664 if (Utilities.isLmp()) {
1665 try {
1666 getWindow().getAttributes().systemUiVisibility |=
1667 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1668 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1669 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1670 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1671 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1672 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1673 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1674 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1675
1676 Method setStatusBarColorMethod =
1677 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1678 Method setNavigationBarColorMethod =
1679 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1680 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1681 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1682 } catch (NoSuchFieldException e) {
1683 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1684 } catch (NoSuchMethodException ex) {
1685 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1686 } catch (IllegalAccessException e) {
1687 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1688 } catch (IllegalArgumentException e) {
1689 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1690 } catch (InvocationTargetException e) {
1691 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1692 } finally {}
1693 }
1694 }
1695
Adam Cohended9f8d2010-11-03 13:25:16 -07001696 @Override
1697 public void onDetachedFromWindow() {
1698 super.onDetachedFromWindow();
1699 mVisible = false;
1700
Adam Cohend113e0c2010-11-11 10:48:05 -08001701 if (mAttached) {
1702 unregisterReceiver(mReceiver);
1703 mAttached = false;
1704 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001705 updateRunning();
1706 }
1707
1708 public void onWindowVisibilityChanged(int visibility) {
1709 mVisible = visibility == View.VISIBLE;
1710 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001711 // The following code used to be in onResume, but it turns out onResume is called when
1712 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1713 // is a more appropriate event to handle
1714 if (mVisible) {
1715 mAppsCustomizeTabHost.onWindowVisible();
1716 if (!mWorkspaceLoading) {
1717 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001718 // We want to let Launcher draw itself at least once before we force it to build
1719 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001720 // apps is nice and speedy.
1721 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001722 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001723 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001724 if (mStarted) return;
1725 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001726 // We delay the layer building a bit in order to give
1727 // other message processing a time to run. In particular
1728 // this avoids a delay in hiding the IME if it was
1729 // currently shown, because doing that may involve
1730 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001731 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001732 final ViewTreeObserver.OnDrawListener listener = this;
1733 mWorkspace.post(new Runnable() {
1734 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001735 if (mWorkspace != null &&
1736 mWorkspace.getViewTreeObserver() != null) {
1737 mWorkspace.getViewTreeObserver().
1738 removeOnDrawListener(listener);
1739 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001740 }
1741 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001742 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001743 }
1744 });
1745 }
1746 clearTypedText();
1747 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001748 }
1749
1750 private void sendAdvanceMessage(long delay) {
1751 mHandler.removeMessages(ADVANCE_MSG);
1752 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1753 mHandler.sendMessageDelayed(msg, delay);
1754 mAutoAdvanceSentTime = System.currentTimeMillis();
1755 }
1756
1757 private void updateRunning() {
1758 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1759 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1760 mAutoAdvanceRunning = autoAdvanceRunning;
1761 if (autoAdvanceRunning) {
1762 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1763 sendAdvanceMessage(delay);
1764 } else {
1765 if (!mWidgetsToAdvance.isEmpty()) {
1766 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1767 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1768 }
1769 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001770 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001771 }
1772 }
1773 }
1774
1775 private final Handler mHandler = new Handler() {
1776 @Override
1777 public void handleMessage(Message msg) {
1778 if (msg.what == ADVANCE_MSG) {
1779 int i = 0;
1780 for (View key: mWidgetsToAdvance.keySet()) {
1781 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1782 final int delay = mAdvanceStagger * i;
1783 if (v instanceof Advanceable) {
1784 postDelayed(new Runnable() {
1785 public void run() {
1786 ((Advanceable) v).advance();
1787 }
1788 }, delay);
1789 }
1790 i++;
1791 }
1792 sendAdvanceMessage(mAdvanceInterval);
1793 }
1794 }
1795 };
1796
1797 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001798 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001799 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1800 if (v instanceof Advanceable) {
1801 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001802 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001803 updateRunning();
1804 }
1805 }
1806
1807 void removeWidgetToAutoAdvance(View hostView) {
1808 if (mWidgetsToAdvance.containsKey(hostView)) {
1809 mWidgetsToAdvance.remove(hostView);
1810 updateRunning();
1811 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001812 }
1813
Joe Onorato9c1289c2009-08-17 11:03:03 -04001814 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001815 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001816 launcherInfo.hostView = null;
1817 }
1818
Winson Chung93eef082012-03-23 15:59:27 -07001819 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1820 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1821 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001822 }
1823
Winson Chunga6945242014-01-08 14:04:34 -08001824 public DragLayer getDragLayer() {
1825 return mDragLayer;
1826 }
1827
1828 public Workspace getWorkspace() {
1829 return mWorkspace;
1830 }
1831
1832 public Hotseat getHotseat() {
1833 return mHotseat;
1834 }
1835
Jorim Jaggid017f882014-01-14 17:08:48 -08001836 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001837 return mOverviewPanel;
1838 }
1839
1840 public SearchDropTargetBar getSearchBar() {
1841 return mSearchDropTargetBar;
1842 }
1843
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001844 public LauncherAppWidgetHost getAppWidgetHost() {
1845 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001846 }
Romain Guycbb89e42009-06-08 15:52:54 -07001847
Winson Chunga9abd0e2010-10-27 17:18:37 -07001848 public LauncherModel getModel() {
1849 return mModel;
1850 }
1851
Winson Chunga6945242014-01-08 14:04:34 -08001852 public LauncherClings getLauncherClings() {
1853 return mLauncherClings;
1854 }
1855
1856 protected SharedPreferences getSharedPrefs() {
1857 return mSharedPrefs;
1858 }
1859
Bjorn Bringertc459e522013-06-07 19:36:01 +01001860 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001861 getWindow().closeAllPanels();
1862
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001863 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001864 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001865 }
1866
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001867 @Override
1868 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001869 long startTime = 0;
1870 if (DEBUG_RESUME_TIME) {
1871 startTime = System.currentTimeMillis();
1872 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001873 super.onNewIntent(intent);
1874
1875 // Close the menu
1876 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001877 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001878 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001879
Adam Cohened307df2013-10-02 09:37:31 -07001880 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1881 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1882 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001883
Adam Cohen6fecd412013-10-02 17:41:50 -07001884 if (mWorkspace == null) {
1885 // Can be cases where mWorkspace is null, this prevents a NPE
1886 return;
1887 }
1888 Folder openFolder = mWorkspace.getOpenFolder();
1889 // In all these cases, only animate if we're already on home
1890 mWorkspace.exitWidgetResizeMode();
1891 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001892 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001893 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001894 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001895
Adam Cohen6fecd412013-10-02 17:41:50 -07001896 closeFolder();
1897 exitSpringLoadedDragMode();
1898
1899 // If we are already on home, then just animate back to the workspace,
1900 // otherwise, just wait until onResume to set the state back to Workspace
1901 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001902 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001903 } else {
1904 mOnResumeState = State.WORKSPACE;
1905 }
1906
1907 final View v = getWindow().peekDecorView();
1908 if (v != null && v.getWindowToken() != null) {
1909 InputMethodManager imm = (InputMethodManager)getSystemService(
1910 INPUT_METHOD_SERVICE);
1911 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1912 }
1913
1914 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001915 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001916 mAppsCustomizeTabHost.reset();
1917 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001918
1919 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001920 }
Adam Cohened307df2013-10-02 09:37:31 -07001921
Michael Jurka447bf842013-05-15 14:52:15 +02001922 if (DEBUG_RESUME_TIME) {
1923 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1924 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001925 }
1926
Adam Coppa120b8e2013-11-12 16:26:04 +00001927 /**
1928 * Override point for subclasses to prevent movement to the default screen when the home
1929 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1930 */
1931 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1932 return true;
1933 }
1934
1935 /**
1936 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1937 */
1938 protected void onHomeIntent() {
1939 // Do nothing
1940 }
1941
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001942 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001943 public void onRestoreInstanceState(Bundle state) {
1944 super.onRestoreInstanceState(state);
1945 for (int page: mSynchronouslyBoundPages) {
1946 mWorkspace.restoreInstanceStateForChild(page);
1947 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001948 }
1949
1950 @Override
1951 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001952 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001953 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1954 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001955 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001956 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001957
Michael Jurka883f55b2010-10-21 15:47:14 -07001958 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001959 // We close any open folder since it will not be re-opened, and we need to make sure
1960 // this state is reflected.
1961 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001962
Adam Cohendcd297f2013-06-18 13:13:40 -07001963 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001964 mWaitingForResult) {
1965 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001966 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001967 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1968 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001969 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1970 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1971 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001972 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001973 }
1974
1975 if (mFolderInfo != null && mWaitingForResult) {
1976 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1977 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1978 }
Michael Jurka946ad472010-07-09 18:05:18 -07001979
Winson Chung785d2eb2011-04-14 16:08:02 -07001980 // Save the current AppsCustomize tab
1981 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08001982 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1983 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001984 if (currentTabTag != null) {
1985 outState.putString("apps_customize_currentTab", currentTabTag);
1986 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001987 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1988 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001989 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001990 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001991 }
1992
1993 @Override
1994 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001995 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001996
Winson Chunge7a03942011-08-05 15:05:12 -07001997 // Remove all pending runnables
1998 mHandler.removeMessages(ADVANCE_MSG);
1999 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07002000 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002001
Winson Chungcd2b0142011-06-08 16:02:26 -07002002 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04002003 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07002004 mModel.stopLoader();
2005 app.setLauncher(null);
2006
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002007 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002008 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002009 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002010 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002011 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002012 mAppWidgetHost = null;
2013
2014 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002015
2016 TextKeyListener.getInstance().release();
2017
Winson Chung81b52252012-08-27 15:34:29 -07002018 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2019 // to prevent leaking Launcher activities on orientation change.
2020 if (mModel != null) {
2021 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2022 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002023
2024 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002025 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002026
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002027 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002028 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002029 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002030 mWorkspace = null;
2031 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002032
Sunny Goyale755d462014-07-22 13:48:29 -07002033 PackageInstallerCompat.getInstance(this).onStop();
Michael Jurka2ecf9952012-06-18 12:52:28 -07002034 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002035 }
2036
Adam Cohena9cf38f2011-05-02 15:36:58 -07002037 public DragController getDragController() {
2038 return mDragController;
2039 }
2040
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002041 @Override
2042 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002043 if (requestCode >= 0) {
2044 setWaitingForResult(true);
2045 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002046 super.startActivityForResult(intent, requestCode);
2047 }
2048
Winson Chung70d72102011-08-12 11:24:35 -07002049 /**
2050 * Indicates that we want global search for this activity by setting the globalSearch
2051 * argument for {@link #startSearch} to true.
2052 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002053 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002054 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002055 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002056
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002057 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002058
Karl Rosaen138a0412009-04-23 19:00:21 -07002059 if (initialQuery == null) {
2060 // Use any text typed in the launcher as the initial query
2061 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002062 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002063 if (appSearchData == null) {
2064 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002065 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002066 }
Winson Chungadf0c182012-08-23 14:59:07 -07002067 Rect sourceBounds = new Rect();
2068 if (mSearchDropTargetBar != null) {
2069 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2070 }
Romain Guycbb89e42009-06-08 15:52:54 -07002071
Bjorn Bringertc459e522013-06-07 19:36:01 +01002072 startSearch(initialQuery, selectInitialQuery,
2073 appSearchData, sourceBounds);
2074 }
2075
2076 public void startSearch(String initialQuery,
2077 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002078 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002079 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07002080 }
2081
2082 /**
2083 * Starts the global search activity. This code is a copied from SearchManager
2084 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002085 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002086 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002087 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002088 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2089 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2090 if (globalSearchActivity == null) {
2091 Log.w(TAG, "No global search activity found.");
2092 return;
2093 }
2094 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2095 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2096 intent.setComponent(globalSearchActivity);
2097 // Make sure that we have a Bundle to put source in
2098 if (appSearchData == null) {
2099 appSearchData = new Bundle();
2100 } else {
2101 appSearchData = new Bundle(appSearchData);
2102 }
2103 // Set source to package name of app that starts global search, if not set already.
2104 if (!appSearchData.containsKey("source")) {
2105 appSearchData.putString("source", getPackageName());
2106 }
2107 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2108 if (!TextUtils.isEmpty(initialQuery)) {
2109 intent.putExtra(SearchManager.QUERY, initialQuery);
2110 }
2111 if (selectInitialQuery) {
2112 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2113 }
2114 intent.setSourceBounds(sourceBounds);
2115 try {
2116 startActivity(intent);
2117 } catch (ActivityNotFoundException ex) {
2118 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2119 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002120 }
2121
Yura4f93ec62014-02-04 14:15:21 +00002122 public boolean isOnCustomContent() {
2123 return mWorkspace.isOnOrMovingToCustomContent();
2124 }
2125
Winson Chung70d72102011-08-12 11:24:35 -07002126 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002127 public boolean onPrepareOptionsMenu(Menu menu) {
2128 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002129 if (!isOnCustomContent()) {
2130 // Close any open folders
2131 closeFolder();
2132 // Stop resizing any widgets
2133 mWorkspace.exitWidgetResizeMode();
2134 if (!mWorkspace.isInOverviewMode()) {
2135 // Show the overview mode
2136 showOverviewMode(true);
2137 } else {
2138 showWorkspace(true);
2139 }
Winson Chunge0298742014-01-17 12:03:00 -08002140 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002141 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002142 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002143
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002144 @Override
2145 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002146 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002147 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002148 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002149 }
2150
Joe Onorato9c1289c2009-08-17 11:03:03 -04002151 public boolean isWorkspaceLocked() {
2152 return mWorkspaceLoading || mWaitingForResult;
2153 }
2154
Adam Cohen517a7f52014-03-01 12:12:59 -08002155 public boolean isWorkspaceLoading() {
2156 return mWorkspaceLoading;
2157 }
2158
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002159 private void setWorkspaceLoading(boolean value) {
2160 boolean isLocked = isWorkspaceLocked();
2161 mWorkspaceLoading = value;
2162 if (isLocked != isWorkspaceLocked()) {
2163 onWorkspaceLockedChanged();
2164 }
2165 }
2166
2167 private void setWaitingForResult(boolean value) {
2168 boolean isLocked = isWorkspaceLocked();
2169 mWaitingForResult = value;
2170 if (isLocked != isWorkspaceLocked()) {
2171 onWorkspaceLockedChanged();
2172 }
2173 }
2174
2175 protected void onWorkspaceLockedChanged() { }
2176
Michael Jurka0280c3b2010-09-17 15:00:07 -07002177 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002178 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002179 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002180 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2181 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002182 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002183 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002184 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002185
Adam Cohenad4e15c2013-10-17 16:21:35 -07002186 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2187 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2188 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2189 }
2190
2191 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2192 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2193 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002194 if (appWidgetInfo.configure != null) {
2195 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002196 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002197
Bjorn Bringert7984c942009-12-09 15:38:25 +00002198 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002199 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2200 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2201
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002202 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002203 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002204 Runnable onComplete = new Runnable() {
2205 @Override
2206 public void run() {
2207 // Exit spring loaded mode if necessary after adding the widget
2208 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2209 null);
2210 }
2211 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002212 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002213 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002214 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002215 }
2216 }
Romain Guycbb89e42009-06-08 15:52:54 -07002217
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002218 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002219 // Close any folders that may be open.
2220 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002221 mWorkspace.moveToCustomContentScreen(animate);
2222 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002223 /**
2224 * Process a shortcut drop.
2225 *
2226 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002227 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002228 * @param cell The cell it should be added to, optional
2229 * @param position The location on the screen where it was dropped, optional
2230 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002231 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002232 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002233 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002234 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002235 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002236 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002237
2238 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002239 mPendingAddInfo.cellX = cell[0];
2240 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002241 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002242
2243 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2244 createShortcutIntent.setComponent(componentName);
2245 processShortcut(createShortcutIntent);
2246 }
2247
Adam Cohenfbba09b2011-07-18 21:43:05 -07002248 /**
2249 * Process a widget drop.
2250 *
2251 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002252 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002253 * @param cell The cell it should be added to, optional
2254 * @param position The location on the screen where it was dropped, optional
2255 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002256 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002257 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002258 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002259 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002260 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002261 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002262 mPendingAddInfo.minSpanX = info.minSpanX;
2263 mPendingAddInfo.minSpanY = info.minSpanY;
2264
Adam Cohenfbba09b2011-07-18 21:43:05 -07002265 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002266 mPendingAddInfo.cellX = cell[0];
2267 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002268 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002269 if (span != null) {
2270 mPendingAddInfo.spanX = span[0];
2271 mPendingAddInfo.spanY = span[1];
2272 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002273
Adam Cohened66b2b2012-01-23 17:28:51 -08002274 AppWidgetHostView hostView = info.boundWidget;
2275 int appWidgetId;
2276 if (hostView != null) {
2277 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002278 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002279 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002280 // In this case, we either need to start an activity to get permission to bind
2281 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002282 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002283 Bundle options = info.bindOptions;
2284
Sunny Goyalffe83f12014-08-14 17:39:34 -07002285 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2286 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002287 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002288 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002289 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002290 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002291 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2292 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2293 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002294 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2295 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002296 // TODO: we need to make sure that this accounts for the options bundle.
2297 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002298 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2299 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002300 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002301 }
2302
Joe Onoratodeb98af2010-02-19 14:59:39 -08002303 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002304 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002305 }
2306
Winson Chung24ab2f12010-09-16 14:10:47 -07002307 void processWallpaper(Intent intent) {
2308 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2309 }
2310
Adam Cohendcd297f2013-06-18 13:13:40 -07002311 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002312 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002313 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002314 folderInfo.title = getText(R.string.folder_name);
2315
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002316 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002317 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002318 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002319 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002320
2321 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002322 FolderIcon newFolder =
2323 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002324 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002325 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002326 // Force measure the new folder icon
2327 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2328 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002329 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002330 }
Romain Guycbb89e42009-06-08 15:52:54 -07002331
Joe Onorato9c1289c2009-08-17 11:03:03 -04002332 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002333 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002334 }
2335
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002336 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002337 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002338 }
2339
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002340 /**
2341 * Registers various content observers. The current implementation registers
2342 * only a favorites observer to keep track of the favorites applications.
2343 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002344 private void registerContentObservers() {
2345 ContentResolver resolver = getContentResolver();
2346 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2347 true, mWidgetObserver);
2348 }
2349
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002350 @Override
2351 public boolean dispatchKeyEvent(KeyEvent event) {
2352 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2353 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002354 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002355 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002356 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002357 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002358 dumpState();
2359 return true;
2360 }
2361 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002362 }
2363 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2364 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002365 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002366 return true;
2367 }
2368 }
2369
2370 return super.dispatchKeyEvent(event);
2371 }
2372
Joe Onorato88ec0992009-11-19 13:16:06 -08002373 @Override
2374 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002375 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002376 if (mAppsCustomizeContent.getContentType() ==
2377 AppsCustomizePagedView.ContentType.Applications) {
2378 showWorkspace(true);
2379 } else {
2380 showOverviewMode(true);
2381 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002382 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002383 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002384 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002385 Folder openFolder = mWorkspace.getOpenFolder();
2386 if (openFolder.isEditingName()) {
2387 openFolder.dismissEditingName();
2388 } else {
2389 closeFolder();
2390 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002391 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002392 mWorkspace.exitWidgetResizeMode();
2393
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002394 // Back button is a no-op here, but give at least some feedback for the button press
2395 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002396 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002397 }
2398
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002399 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002400 * Re-listen when widgets are reset.
2401 */
2402 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002403 if (mAppWidgetHost != null) {
2404 mAppWidgetHost.startListening();
2405 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002406 }
2407
2408 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002409 * Launches the intent referred by the clicked shortcut.
2410 *
2411 * @param v The view representing the clicked shortcut.
2412 */
2413 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002414 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2415 // view has detached (it's possible for this to happen if the view is removed mid touch).
2416 if (v.getWindowToken() == null) {
2417 return;
2418 }
2419
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002420 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002421 return;
2422 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002423
Adam Cohen1697b792013-09-17 19:08:21 -07002424 if (v instanceof Workspace) {
2425 if (mWorkspace.isInOverviewMode()) {
2426 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002427 }
2428 return;
2429 }
2430
2431 if (v instanceof CellLayout) {
2432 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002433 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002434 }
2435 }
2436
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002437 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002438 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002439 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002440 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002441 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002442 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002443 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002444 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002445 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002446 } else if (tag instanceof AppInfo) {
2447 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002448 } else if (tag instanceof LauncherAppWidgetInfo) {
2449 if (v instanceof PendingAppWidgetHostView) {
2450 onClickPendingWidget((PendingAppWidgetHostView) v);
2451 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002452 }
2453 }
2454
Sunny Goyal508da152014-08-14 10:53:27 -07002455 public void onClickPagedViewIcon(View v) {
2456 startAppShortcutOrInfoActivity(v);
2457 }
2458
Michael Jurka0e260592010-06-30 17:07:39 -07002459 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002460 return false;
2461 }
2462
Michael Jurkaaf442092010-06-10 17:01:57 -07002463 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002464 * Event handler for the app widget view which has not fully restored.
2465 */
2466 public void onClickPendingWidget(PendingAppWidgetHostView v) {
2467 if (v.isReadyForClickSetup()) {
2468 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
2469 int widgetId = info.appWidgetId;
2470 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2471 if (appWidgetInfo != null) {
2472 mPendingAddWidgetInfo = appWidgetInfo;
2473 mPendingAddInfo.copyFrom(info);
2474 mPendingAddWidgetId = widgetId;
2475
Sunny Goyalffe83f12014-08-14 17:39:34 -07002476 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2477 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002478 }
2479 }
2480 }
2481
2482 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002483 * Event handler for the search button
2484 *
2485 * @param v The view that was clicked.
2486 */
2487 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002488 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2489
Amith Yamasania135ba82011-08-09 17:42:01 -07002490 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002491 }
2492
2493 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002494 * Event handler for the voice button
2495 *
2496 * @param v The view that was clicked.
2497 */
2498 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002499 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002500
Bjorn Bringertc459e522013-06-07 19:36:01 +01002501 startVoice();
2502 }
2503
2504 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002505 try {
2506 final SearchManager searchManager =
2507 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2508 ComponentName activityName = searchManager.getGlobalSearchActivity();
2509 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002510 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002511 if (activityName != null) {
2512 intent.setPackage(activityName.getPackageName());
2513 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002514 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002515 } catch (ActivityNotFoundException e) {
2516 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002517 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002518 startActivitySafely(null, intent, "onClickVoiceButton");
2519 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002520 }
2521
2522 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002523 * Event handler for the "grid" button that appears on the home screen, which
2524 * enters all apps mode.
2525 *
2526 * @param v The view that was clicked.
2527 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002528 protected void onClickAllAppsButton(View v) {
2529 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2530 if (isAllAppsVisible()) {
2531 showWorkspace(true);
2532 } else {
2533 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2534 }
2535 }
2536
2537 /**
2538 * Event handler for an app shortcut click.
2539 *
2540 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2541 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002542 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002543 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2544 Object tag = v.getTag();
2545 if (!(tag instanceof ShortcutInfo)) {
2546 throw new IllegalArgumentException("Input must be a Shortcut");
2547 }
2548
2549 // Open shortcut
2550 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2551 final Intent intent = shortcut.intent;
2552
2553 // Check for special shortcuts
2554 if (intent.getComponent() != null) {
2555 final String shortcutClass = intent.getComponent().getClassName();
2556
2557 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2558 MemoryDumpActivity.startDump(this);
2559 return;
2560 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2561 toggleShowWeightWatcher();
2562 return;
2563 }
2564 }
2565
Chris Wren40c5ed32014-06-24 18:24:23 -04002566 // Check for abandoned promise
2567 if (shortcut.isAbandoned() && v instanceof BubbleTextView) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002568 AlertDialog.Builder builder = new AlertDialog.Builder(this);
2569 builder.setTitle(R.string.abandoned_promises_title);
Chris Wren803a4be2014-07-01 16:52:49 -04002570 builder.setMessage(R.string.abandoned_promise_explanation);
Chris Wren40c5ed32014-06-24 18:24:23 -04002571 builder.setPositiveButton(R.string.abandoned_search,
2572 new DialogInterface.OnClickListener() {
2573 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002574 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002575 }
2576 }
2577 );
Chris Wren40c5ed32014-06-24 18:24:23 -04002578 builder.setNeutralButton(R.string.abandoned_clean_this,
2579 new DialogInterface.OnClickListener() {
2580 public void onClick(DialogInterface dialog, int id) {
2581 final BubbleTextView bubble = (BubbleTextView) v;
2582 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2583 mWorkspace.removeAbandonedPromise(bubble, user);
2584 }
2585 });
2586 builder.create().show();
2587 return;
2588 }
2589
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002590 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002591 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002592 }
2593
Sunny Goyal508da152014-08-14 10:53:27 -07002594 private void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002595 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002596 final ShortcutInfo shortcut;
2597 final Intent intent;
2598 if (tag instanceof ShortcutInfo) {
2599 shortcut = (ShortcutInfo) tag;
2600 intent = shortcut.intent;
2601 int[] pos = new int[2];
2602 v.getLocationOnScreen(pos);
2603 intent.setSourceBounds(new Rect(pos[0], pos[1],
2604 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002605
Sunny Goyal508da152014-08-14 10:53:27 -07002606 } else if (tag instanceof AppInfo) {
2607 shortcut = null;
2608 intent = ((AppInfo) tag).intent;
2609 } else {
2610 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2611 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002612
2613 boolean success = startActivitySafely(v, intent, tag);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002614 mStats.recordLaunch(intent, shortcut);
2615
2616 if (success && v instanceof BubbleTextView) {
2617 mWaitingForResume = (BubbleTextView) v;
2618 mWaitingForResume.setStayPressed(true);
2619 }
2620 }
2621
2622 /**
2623 * Event handler for a folder icon click.
2624 *
2625 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2626 */
2627 protected void onClickFolderIcon(View v) {
2628 if (LOGD) Log.d(TAG, "onClickFolder");
2629 if (!(v instanceof FolderIcon)){
2630 throw new IllegalArgumentException("Input must be a FolderIcon");
2631 }
2632
2633 FolderIcon folderIcon = (FolderIcon) v;
2634 final FolderInfo info = folderIcon.getFolderInfo();
2635 Folder openFolder = mWorkspace.getFolderForTag(info);
2636
2637 // If the folder info reports that the associated folder is open, then verify that
2638 // it is actually opened. There have been a few instances where this gets out of sync.
2639 if (info.opened && openFolder == null) {
2640 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2641 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2642 info.opened = false;
2643 }
2644
2645 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2646 // Close any open folder
2647 closeFolder();
2648 // Open the requested folder
2649 openFolder(folderIcon);
2650 } else {
2651 // Find the open folder...
2652 int folderScreen;
2653 if (openFolder != null) {
2654 folderScreen = mWorkspace.getPageForView(openFolder);
2655 // .. and close it
2656 closeFolder(openFolder);
2657 if (folderScreen != mWorkspace.getCurrentPage()) {
2658 // Close any folder open on the current screen
2659 closeFolder();
2660 // Pull the folder onto this screen
2661 openFolder(folderIcon);
2662 }
2663 }
2664 }
Michael Jurka5130e402011-10-13 04:55:35 -07002665 }
2666
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002667 /**
2668 * Event handler for the (Add) Widgets button that appears after a long press
2669 * on the home screen.
2670 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002671 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002672 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002673 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2674 }
2675
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002676 /**
2677 * Event handler for the wallpaper picker button that appears after a long press
2678 * on the home screen.
2679 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002680 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002681 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2682 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2683 pickWallpaper.setComponent(getWallpaperPickerComponent());
2684 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2685 }
2686
2687 /**
2688 * Event handler for a click on the settings button that appears after a long press
2689 * on the home screen.
2690 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002691 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002692 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2693 }
2694
Michael Jurka5130e402011-10-13 04:55:35 -07002695 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002696 // Provide the same haptic feedback that the system offers for virtual keys.
2697 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002698 }
2699
Adam Cohen61f560d2013-09-30 15:58:20 -07002700 public void performHapticFeedbackOnTouchDown(View v) {
2701 // Provide the same haptic feedback that the system offers for virtual keys.
2702 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2703 }
2704
2705 public View.OnTouchListener getHapticFeedbackTouchListener() {
2706 if (mHapticFeedbackTouchListener == null) {
2707 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2708 @Override
2709 public boolean onTouch(View v, MotionEvent event) {
2710 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2711 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2712 }
2713 return false;
2714 }
2715 };
2716 }
2717 return mHapticFeedbackTouchListener;
2718 }
2719
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002720 public void onDragStarted(View view) {}
2721
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002722 /**
2723 * Called when the user stops interacting with the launcher.
2724 * This implies that the user is now on the homescreen and is not doing housekeeping.
2725 */
2726 protected void onInteractionEnd() {}
2727
2728 /**
2729 * Called when the user starts interacting with the launcher.
2730 * The possible interactions are:
2731 * - open all apps
2732 * - reorder an app shortcut, or a widget
2733 * - open the overview mode.
2734 * This is a good time to stop doing things that only make sense
2735 * when the user is on the homescreen and not doing housekeeping.
2736 */
2737 protected void onInteractionBegin() {}
2738
Kenny Guyf07af7b2014-07-31 11:39:16 +01002739 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002740 String packageName = componentName.getPackageName();
Kenny Guyf07af7b2014-07-31 11:39:16 +01002741 try {
2742 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2743 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2744 launcherApps.showAppDetailsForProfile(componentName, user);
2745 } catch (SecurityException e) {
2746 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2747 Log.e(TAG, "Launcher does not have permission to launch settings");
2748 } catch (ActivityNotFoundException e) {
2749 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2750 Log.e(TAG, "Unable to launch settings");
2751 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002752 }
2753
Michael Jurka1e2f4652013-07-08 18:03:46 -07002754 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002755 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2756 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002757 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002758 // System applications cannot be installed. For now, show a toast explaining that.
2759 // We may give them the option of disabling apps this way.
2760 int messageId = R.string.uninstall_system_app_text;
2761 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002762 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002763 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002764 String packageName = componentName.getPackageName();
2765 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002766 Intent intent = new Intent(
2767 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002768 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2769 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002770 if (user != null) {
2771 user.addToIntent(intent, Intent.EXTRA_USER);
2772 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002773 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002774 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002775 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002776 }
2777
Michael Jurka86a720e2012-05-09 11:23:23 -07002778 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002779 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002780 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002781 // Only launch using the new animation if the shortcut has not opted out (this is a
2782 // private contract between launcher and may be ignored in the future).
2783 boolean useLaunchAnimation = (v != null) &&
2784 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002785 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2786 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002787
Kenny Guy1317e2d2014-05-08 18:52:50 +01002788 UserHandleCompat user = null;
2789 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2790 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2791 user = userManager.getUserForSerialNumber(serialNumber);
2792 }
2793
2794 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002795 if (useLaunchAnimation) {
Adam Cohen4da294d2014-07-28 10:56:19 -07002796 ActivityOptions opts = Utilities.isLmp() ?
2797 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) :
2798 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Adam Cohen6ea3b112014-06-11 11:38:49 -07002799 optsBundle = opts.toBundle();
2800 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002801
2802 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2803 // Could be launching some bookkeeping activity
2804 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002805 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002806 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002807 launcherApps.startActivityForProfile(intent.getComponent(), user,
2808 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002809 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002810 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002811 } catch (SecurityException e) {
2812 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002813 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002814 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002815 "or use the exported attribute for this activity. "
2816 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002817 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002818 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002819 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002820
Michael Jurka86a720e2012-05-09 11:23:23 -07002821 boolean startActivitySafely(View v, Intent intent, Object tag) {
2822 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002823 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2824 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2825 return false;
2826 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002827 try {
2828 success = startActivity(v, intent, tag);
2829 } catch (ActivityNotFoundException e) {
2830 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2831 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2832 }
2833 return success;
2834 }
2835
Adam Cohen268c4752012-06-06 17:47:33 -07002836 /**
2837 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2838 * in the DragLayer in the exact absolute location of the original FolderIcon.
2839 */
2840 private void copyFolderIconToImage(FolderIcon fi) {
2841 final int width = fi.getMeasuredWidth();
2842 final int height = fi.getMeasuredHeight();
2843
2844 // Lazy load ImageView, Bitmap and Canvas
2845 if (mFolderIconImageView == null) {
2846 mFolderIconImageView = new ImageView(this);
2847 }
2848 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2849 mFolderIconBitmap.getHeight() != height) {
2850 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2851 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2852 }
2853
2854 DragLayer.LayoutParams lp;
2855 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2856 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2857 } else {
2858 lp = new DragLayer.LayoutParams(width, height);
2859 }
2860
Adam Cohen307fe232012-08-16 17:55:58 -07002861 // The layout from which the folder is being opened may be scaled, adjust the starting
2862 // view size by this scale factor.
2863 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002864 lp.customPosition = true;
2865 lp.x = mRectForFolderAnimation.left;
2866 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002867 lp.width = (int) (scale * width);
2868 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002869
2870 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2871 fi.draw(mFolderIconCanvas);
2872 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002873 if (fi.getFolder() != null) {
2874 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2875 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002876 }
Adam Cohen268c4752012-06-06 17:47:33 -07002877 // Just in case this image view is still in the drag layer from a previous animation,
2878 // we remove it and re-add it.
2879 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2880 mDragLayer.removeView(mFolderIconImageView);
2881 }
2882 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002883 if (fi.getFolder() != null) {
2884 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002885 }
Adam Cohen268c4752012-06-06 17:47:33 -07002886 }
2887
Adam Cohen2801caf2011-05-13 20:57:39 -07002888 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002889 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002890 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2891 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2892 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2893
Adam Cohenc51934b2011-07-26 21:07:43 -07002894 FolderInfo info = (FolderInfo) fi.getTag();
2895 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2896 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002897 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2898 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002899 }
2900
Adam Cohen268c4752012-06-06 17:47:33 -07002901 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2902 copyFolderIconToImage(fi);
2903 fi.setVisibility(View.INVISIBLE);
2904
Michael Jurka2ecf9952012-06-18 12:52:28 -07002905 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002906 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002907 if (Utilities.isLmp()) {
2908 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
2909 }
2910 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07002911 oa.start();
2912 }
2913
Adam Cohen268c4752012-06-06 17:47:33 -07002914 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002915 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002916 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2917 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2918 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2919
Adam Cohen268c4752012-06-06 17:47:33 -07002920 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002921
Adam Cohen268c4752012-06-06 17:47:33 -07002922 // We remove and re-draw the FolderIcon in-case it has changed
2923 mDragLayer.removeView(mFolderIconImageView);
2924 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002925 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002926 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002927 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002928 oa.addListener(new AnimatorListenerAdapter() {
2929 @Override
2930 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002931 if (cl != null) {
2932 cl.clearFolderLeaveBehind();
2933 // Remove the ImageView copy of the FolderIcon and make the original visible.
2934 mDragLayer.removeView(mFolderIconImageView);
2935 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002936 }
2937 }
2938 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002939 oa.start();
2940 }
2941
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002942 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002943 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002944 * is animated relative to the specified View. If the View is null, no animation
2945 * is played.
2946 *
2947 * @param folderInfo The FolderInfo describing the folder to open.
2948 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002949 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002950 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002951 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002952
Adam Cohena9cf38f2011-05-02 15:36:58 -07002953 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002954
Adam Cohen4554ee12011-08-03 16:13:21 -07002955 // Just verify that the folder hasn't already been added to the DragLayer.
2956 // There was a one-off crash where the folder had a parent already.
2957 if (folder.getParent() == null) {
2958 mDragLayer.addView(folder);
2959 mDragController.addDropTarget((DropTarget) folder);
2960 } else {
2961 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2962 folder.getParent() + ").");
2963 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002964 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002965 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002966
2967 // Notify the accessibility manager that this folder "window" has appeared and occluded
2968 // the workspace items
2969 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2970 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002971 }
2972
2973 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002974 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002975 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002976 if (folder.isEditingName()) {
2977 folder.dismissEditingName();
2978 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002979 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07002980
2981 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08002982 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07002983 }
2984 }
2985
2986 void closeFolder(Folder folder) {
2987 folder.getInfo().opened = false;
2988
2989 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
2990 if (parent != null) {
2991 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
2992 shrinkAndFadeInFolderIcon(fi);
2993 }
2994 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07002995
2996 // Notify the accessibility manager that this folder "window" has disappeard and no
2997 // longer occludeds the workspace items
2998 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002999 }
3000
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003001 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003002 if (!isDraggingEnabled()) return false;
3003 if (isWorkspaceLocked()) return false;
3004 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003005
Adam Cohen1697b792013-09-17 19:08:21 -07003006 if (v instanceof Workspace) {
3007 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07003008 if (mWorkspace.enterOverviewMode()) {
3009 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3010 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3011 return true;
3012 } else {
3013 return false;
3014 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003015 } else {
3016 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003017 }
Adam Cohen1697b792013-09-17 19:08:21 -07003018 }
3019
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003020 CellLayout.CellInfo longClickCellInfo = null;
3021 View itemUnderLongClick = null;
3022 if (v.getTag() instanceof ItemInfo) {
3023 ItemInfo info = (ItemInfo) v.getTag();
3024 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3025 itemUnderLongClick = longClickCellInfo.cell;
3026 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003027 }
3028
Winson Chung3d503fb2011-07-13 17:25:49 -07003029 // The hotseat touch handling does not go through Workspace, and we always allow long press
3030 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003031 final boolean inHotseat = isHotseatLayout(v);
3032 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07003033 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003034 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003035 // User long pressed on empty space
3036 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3037 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003038 if (mWorkspace.isInOverviewMode()) {
3039 mWorkspace.startReordering(v);
3040 } else {
3041 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07003042 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003043 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003044 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3045 mHotseat.getOrderInHotseat(
3046 longClickCellInfo.cellX,
3047 longClickCellInfo.cellY));
3048 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003049 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003050 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003051 }
3052 }
3053 }
3054 return true;
3055 }
3056
Winson Chung3d503fb2011-07-13 17:25:49 -07003057 boolean isHotseatLayout(View layout) {
3058 return mHotseat != null && layout != null &&
3059 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3060 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003061
Winson Chung3d503fb2011-07-13 17:25:49 -07003062 /**
3063 * Returns the CellLayout of the specified container at the specified screen.
3064 */
Adam Cohendcd297f2013-06-18 13:13:40 -07003065 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003066 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3067 if (mHotseat != null) {
3068 return mHotseat.getLayout();
3069 } else {
3070 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003071 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003072 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07003073 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003074 }
3075 }
3076
Daniel Sandler843e8602010-06-07 14:59:01 -04003077 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003078 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003079 }
3080
Craig Mautner360310b2012-10-26 15:13:08 -07003081 private void setWorkspaceBackground(boolean workspace) {
3082 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003083 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003084 }
3085
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003086 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003087 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3088 int curflags = getWindow().getAttributes().flags
3089 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3090 if (wpflags != curflags) {
3091 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3092 }
Craig Mautner360310b2012-10-26 15:13:08 -07003093 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003094 }
3095
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003096 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3097 if (v instanceof LauncherTransitionable) {
3098 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3099 }
3100 }
3101
Michael Jurkabed61d22012-02-14 22:51:29 -08003102 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3103 if (v instanceof LauncherTransitionable) {
3104 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3105 }
Winson Chung70442722012-02-10 15:43:22 -08003106
3107 // Update the workspace transition step as well
3108 dispatchOnLauncherTransitionStep(v, 0f);
3109 }
3110
3111 private void dispatchOnLauncherTransitionStep(View v, float t) {
3112 if (v instanceof LauncherTransitionable) {
3113 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3114 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003115 }
3116
3117 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3118 if (v instanceof LauncherTransitionable) {
3119 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3120 }
Winson Chung70442722012-02-10 15:43:22 -08003121
3122 // Update the workspace transition step as well
3123 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003124 }
3125
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003126 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003127 * Things to test when changing the following seven functions.
3128 * - Home from workspace
3129 * - from center screen
3130 * - from other screens
3131 * - Home from all apps
3132 * - from center screen
3133 * - from other screens
3134 * - Back from all apps
3135 * - from center screen
3136 * - from other screens
3137 * - Launch app from workspace and quit
3138 * - with back
3139 * - with home
3140 * - Launch app from all apps and quit
3141 * - with back
3142 * - with home
3143 * - Go to a screen that's not the default, then all
3144 * apps, and launch and app, and go back
3145 * - with back
3146 * -with home
3147 * - On workspace, long press power and go back
3148 * - with back
3149 * - with home
3150 * - On all apps, long press power and go back
3151 * - with back
3152 * - with home
3153 * - On workspace, power off
3154 * - On all apps, power off
3155 * - Launch an app and turn off the screen while in that app
3156 * - Go back with home key
3157 * - Go back with back key TODO: make this not go to workspace
3158 * - From all apps
3159 * - From workspace
3160 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3161 * - From all apps
3162 * - From the center workspace
3163 * - From another workspace
3164 */
3165
3166 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003167 * Zoom the camera out from the workspace to reveal 'toView'.
3168 * Assumes that the view to show is anchored at either the very top or very bottom
3169 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003170 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003171 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003172 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3173 showAppsCustomizeHelper(animated, springLoaded, contentType);
3174 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003175
Winson Chungc58497e2013-09-03 17:48:37 -07003176 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3177 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003178 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003179 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003180 mStateAnimation.cancel();
3181 mStateAnimation = null;
3182 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003183
3184 boolean material = Utilities.isLmp();
3185
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003186 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003187
Winson Chungf0ea4d32011-06-06 14:27:16 -07003188 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3189 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003190 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003191 final int itemsAlphaStagger =
3192 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003193
Winson Chungf0ea4d32011-06-06 14:27:16 -07003194 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003195 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003196 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07003197
Adam Cohen6c5891a2014-07-09 23:53:15 -07003198 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3199 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003200 Animator workspaceAnim =
Adam Cohen6c5891a2014-07-09 23:53:15 -07003201 mWorkspace.getChangeStateAnimation(workspaceState, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003202 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003203 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3204 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003205 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3206 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003207
3208 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003209 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen61033d32010-11-15 18:29:44 -08003210
Adam Cohen9bfdb762014-07-21 17:44:06 -07003211 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3212 toView.findViewById(R.id.apps_customize_pane_content);
Adam Cohenf16e5712011-01-13 13:31:45 -08003213
Adam Cohen9bfdb762014-07-21 17:44:06 -07003214 final View page = content.getPageAt(content.getCurrentPage());
3215 final View revealView = toView.findViewById(R.id.fake_page);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003216
Adam Cohen63f1ec02014-08-12 09:23:13 -07003217 final float initialPanelAlpha = 1f;
3218
3219 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3220 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003221 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3222 } else {
3223 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3224 }
3225
Adam Cohen9bfdb762014-07-21 17:44:06 -07003226 // Hide the real page background, and swap in the fake one
3227 revealView.setVisibility(View.VISIBLE);
3228 content.setPageBackgroundsVisible(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003229
Adam Cohen9bfdb762014-07-21 17:44:06 -07003230 int width = revealView.getMeasuredWidth();
3231 int height = revealView.getMeasuredHeight();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003232
Adam Cohen9bfdb762014-07-21 17:44:06 -07003233 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003234 revealView.setTranslationY(0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003235
Adam Cohen63f1ec02014-08-12 09:23:13 -07003236 // Get the y delta between the center of the page and the center of the all apps button
3237 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3238 getAllAppsButton(), null);
3239 float yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3240
3241 float initAlpha = isWidgetTray ? 0.3f : 1f;
Adam Cohen9bfdb762014-07-21 17:44:06 -07003242 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003243 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003244 PropertyValuesHolder panelDrift =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003245 PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003246
Adam Cohen9bfdb762014-07-21 17:44:06 -07003247 ObjectAnimator panelAlphaAndDrift =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003248 LauncherAnimUtils.ofPropertyValuesHolder(revealView, panelAlpha, panelDrift);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003249 panelAlphaAndDrift.setDuration(revealDuration);
3250 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003251
Adam Cohen9bfdb762014-07-21 17:44:06 -07003252 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003253
Adam Cohen4e243a22014-08-10 18:30:55 -07003254 if (page != null) {
3255 page.setVisibility(View.VISIBLE);
3256 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003257
Adam Cohen63f1ec02014-08-12 09:23:13 -07003258 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", yDrift, 0);
Adam Cohen4e243a22014-08-10 18:30:55 -07003259 pageDrift.setDuration(revealDuration);
3260 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003261 pageDrift.setStartDelay(itemsAlphaStagger);
Adam Cohen4e243a22014-08-10 18:30:55 -07003262 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003263
Adam Cohen63f1ec02014-08-12 09:23:13 -07003264 page.setAlpha(0f);
3265 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 0f, 1f);
Adam Cohen4e243a22014-08-10 18:30:55 -07003266 itemsAlpha.setDuration(revealDuration);
3267 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3268 itemsAlpha.setStartDelay(itemsAlphaStagger);
3269 mStateAnimation.play(itemsAlpha);
3270 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003271
Adam Cohen4e243a22014-08-10 18:30:55 -07003272 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3273 pageIndicators.setAlpha(0.01f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003274 ObjectAnimator indicatorsAlpha =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003275 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003276 indicatorsAlpha.setDuration(revealDuration);
3277 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003278
Adam Cohen9bfdb762014-07-21 17:44:06 -07003279 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003280 final View allApps = getAllAppsButton();
3281 int allAppsButtonSize = LauncherAppState.getInstance().
3282 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3283 float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003284 Animator reveal = LauncherAnimUtils.createCircularReveal(revealView, width / 2,
Adam Cohen63f1ec02014-08-12 09:23:13 -07003285 height / 2, startRadius, revealRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003286 reveal.setDuration(revealDuration);
3287 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003288
3289 reveal.addListener(new AnimatorListenerAdapter() {
3290 public void onAnimationStart(Animator animation) {
3291 if (!isWidgetTray) {
3292 allApps.setVisibility(View.INVISIBLE);
3293 }
3294 }
3295 public void onAnimationEnd(Animator animation) {
3296 if (!isWidgetTray) {
3297 allApps.setVisibility(View.VISIBLE);
3298 }
3299 }
3300 });
3301
Adam Cohen6c5891a2014-07-09 23:53:15 -07003302 mStateAnimation.play(reveal);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003303 }
Michael Jurka1899a362011-11-03 13:50:45 -07003304
Adam Cohen9bfdb762014-07-21 17:44:06 -07003305 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3306 @Override
3307 public void onAnimationEnd(Animator animation) {
3308 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3309 dispatchOnLauncherTransitionEnd(toView, animated, false);
3310
3311 revealView.setVisibility(View.INVISIBLE);
3312 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003313 if (page != null) {
3314 page.setLayerType(View.LAYER_TYPE_NONE, null);
3315 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003316 content.setPageBackgroundsVisible(true);
3317
3318 // Hide the search bar
3319 if (mSearchDropTargetBar != null) {
3320 mSearchDropTargetBar.hideSearchBar(false);
3321 }
3322 }
3323
3324 @Override
3325 public void onAnimationStart(Animator animation) {
3326 // Prepare the position
3327 toView.bringToFront();
3328 toView.setVisibility(View.VISIBLE);
3329 }
3330 });
3331
Michael Jurka1899a362011-11-03 13:50:45 -07003332 boolean delayAnim = false;
Adam Cohen6c5891a2014-07-09 23:53:15 -07003333 if (workspaceAnim != null) {
3334 mStateAnimation.play(workspaceAnim);
3335 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003336 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3337 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003338
3339 // If any of the objects being animated haven't been measured/laid out
3340 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003341 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003342 (mWorkspace.getMeasuredWidth() == 0) ||
3343 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003344 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003345 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003346
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003347 final AnimatorSet stateAnimation = mStateAnimation;
3348 final Runnable startAnimRunnable = new Runnable() {
3349 public void run() {
3350 // Check that mStateAnimation hasn't changed while
3351 // we waited for a layout/draw pass
3352 if (mStateAnimation != stateAnimation)
3353 return;
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003354 dispatchOnLauncherTransitionStart(fromView, animated, false);
3355 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003356 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003357 }
3358 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003359 if (delayAnim) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003360 toView.bringToFront();
3361 toView.setVisibility(View.VISIBLE);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003362 final ViewTreeObserver observer = toView.getViewTreeObserver();
3363 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3364 public void onGlobalLayout() {
3365 startAnimRunnable.run();
3366 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3367 }
3368 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003369 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003370 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003371 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003372 } else {
3373 toView.setTranslationX(0.0f);
3374 toView.setTranslationY(0.0f);
3375 toView.setScaleX(1.0f);
3376 toView.setScaleY(1.0f);
3377 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003378 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003379
Daniel Sandlere4f98912013-06-25 15:13:26 -04003380 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003381 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003382 if (mSearchDropTargetBar != null) {
3383 mSearchDropTargetBar.hideSearchBar(false);
3384 }
Michael Jurkaabded662011-03-04 12:06:57 -08003385 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003386 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003387 dispatchOnLauncherTransitionStart(fromView, animated, false);
3388 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003389 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003390 dispatchOnLauncherTransitionStart(toView, animated, false);
3391 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003392 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003393 }
3394
3395 /**
3396 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003397 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003398 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003399 */
Adam Cohened307df2013-10-02 09:37:31 -07003400 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003401 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003402
Michael Jurkab3e22d92011-10-31 15:58:33 -07003403 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003404 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003405 mStateAnimation.cancel();
3406 mStateAnimation = null;
3407 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003408
3409 boolean material = Utilities.isLmp();
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003410 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003411
Winson Chungf0ea4d32011-06-06 14:27:16 -07003412 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003413 final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003414 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003415 final int itemsAlphaStagger =
3416 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003417
Winson Chungf0ea4d32011-06-06 14:27:16 -07003418 final float scaleFactor = (float)
3419 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3420 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003421 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003422 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003423 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003424 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohen63f1ec02014-08-12 09:23:13 -07003425 toState, animated);
Adam Cohened307df2013-10-02 09:37:31 -07003426 } else if (toState == Workspace.State.SPRING_LOADED ||
3427 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003428 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003429 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003430 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003431
Winson Chung4afe9b32011-07-27 17:46:20 -07003432 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003433 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003434 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka159b4cc2012-01-17 03:00:35 -08003435
Adam Cohen9bfdb762014-07-21 17:44:06 -07003436 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3437 fromView.findViewById(R.id.apps_customize_pane_content);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003438
Adam Cohen9bfdb762014-07-21 17:44:06 -07003439 final View page = content.getPageAt(content.getNextPage());
3440 final View revealView = fromView.findViewById(R.id.fake_page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003441
Adam Cohen4e243a22014-08-10 18:30:55 -07003442 AppsCustomizePagedView.ContentType contentType = content.getContentType();
Adam Cohen63f1ec02014-08-12 09:23:13 -07003443 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3444
3445 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003446 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3447 } else {
3448 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3449 }
3450
Adam Cohen9bfdb762014-07-21 17:44:06 -07003451 int width = revealView.getMeasuredWidth();
3452 int height = revealView.getMeasuredHeight();
3453 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003454
Adam Cohen9bfdb762014-07-21 17:44:06 -07003455 // Hide the real page background, and swap in the fake one
3456 revealView.setVisibility(View.VISIBLE);
3457 content.setPageBackgroundsVisible(false);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003458
Adam Cohen63f1ec02014-08-12 09:23:13 -07003459 final View allAppsButton = getAllAppsButton();
3460 revealView.setTranslationY(0);
3461 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3462 allAppsButton, null);
3463 float yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
Adam Cohen6c5891a2014-07-09 23:53:15 -07003464
Adam Cohen9bfdb762014-07-21 17:44:06 -07003465 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003466
Adam Cohen63f1ec02014-08-12 09:23:13 -07003467 // The vertical motion of the apps panel should be delayed by one frame
3468 // from the conceal animation in order to give the right feel. We correpsondingly
3469 // shorten the duration so that the slide and conceal end at the same time.
3470 ObjectAnimator panelDrift = LauncherAnimUtils.ofFloat(revealView, "translationY", 0, yDrift);
3471 panelDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3472 panelDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3473 panelDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3474 mStateAnimation.play(panelDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003475
Adam Cohen63f1ec02014-08-12 09:23:13 -07003476 if (isWidgetTray) {
3477 ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", 1f, 0.4f);
3478 panelAlpha.setDuration(revealDuration);
3479 panelAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0));
3480 mStateAnimation.play(panelAlpha);
3481 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003482
Adam Cohen4e243a22014-08-10 18:30:55 -07003483 if (page != null) {
3484 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003485
Adam Cohen63f1ec02014-08-12 09:23:13 -07003486 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
3487 0, yDrift);
3488 pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
Adam Cohen4e243a22014-08-10 18:30:55 -07003489 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003490 pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
Adam Cohen4e243a22014-08-10 18:30:55 -07003491 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003492
Adam Cohen4e243a22014-08-10 18:30:55 -07003493 page.setAlpha(1f);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003494 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
3495 itemsAlpha.setDuration(100);
Adam Cohen4e243a22014-08-10 18:30:55 -07003496 itemsAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0));
3497 mStateAnimation.play(itemsAlpha);
3498 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003499
Adam Cohen9bfdb762014-07-21 17:44:06 -07003500 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
Adam Cohen4e243a22014-08-10 18:30:55 -07003501 pageIndicators.setAlpha(1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003502 ObjectAnimator indicatorsAlpha =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003503 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003504 indicatorsAlpha.setDuration(revealDuration);
3505 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3506 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003507
Adam Cohen9bfdb762014-07-21 17:44:06 -07003508 width = revealView.getMeasuredWidth();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003509
Adam Cohen9bfdb762014-07-21 17:44:06 -07003510 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003511 if (!isWidgetTray) {
3512 allAppsButton.setVisibility(View.INVISIBLE);
3513 }
3514 int allAppsButtonSize = LauncherAppState.getInstance().
3515 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3516 float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Nilesh Agrawal300c1502014-07-22 13:20:54 -07003517 Animator reveal =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003518 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3519 height / 2, revealRadius, finalRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003520 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3521 reveal.setDuration(revealDuration);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003522 reveal.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003523
3524 reveal.addListener(new AnimatorListenerAdapter() {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003525 public void onAnimationEnd(Animator animation) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003526 revealView.setVisibility(View.INVISIBLE);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003527 if (!isWidgetTray) {
3528 allAppsButton.setVisibility(View.VISIBLE);
3529 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003530 }
3531 });
3532
Adam Cohen6c5891a2014-07-09 23:53:15 -07003533 mStateAnimation.play(reveal);
3534 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003535
3536 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3537 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3538 mAppsCustomizeContent.stopScrolling();
3539
Adam Cohen6c5891a2014-07-09 23:53:15 -07003540 if (workspaceAnim != null) {
3541 mStateAnimation.play(workspaceAnim);
3542 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003543
3544 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003545 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003546 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003547 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003548 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3549 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003550 if (onCompleteRunnable != null) {
3551 onCompleteRunnable.run();
3552 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003553
3554 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003555 if (page != null) {
3556 page.setLayerType(View.LAYER_TYPE_NONE, null);
3557 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003558 content.setPageBackgroundsVisible(true);
Chet Haasebc2f0822012-10-26 17:59:53 -07003559 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003560 }
3561 });
3562
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003563 dispatchOnLauncherTransitionStart(fromView, animated, true);
3564 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003565 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003566 } else {
3567 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003568 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003569 dispatchOnLauncherTransitionStart(fromView, animated, true);
3570 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003571 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003572 dispatchOnLauncherTransitionStart(toView, animated, true);
3573 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003574 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003575 }
3576
Michael Jurkae326f182011-11-21 14:05:46 -08003577 @Override
3578 public void onTrimMemory(int level) {
3579 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003580 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003581 mAppsCustomizeTabHost.onTrimMemory();
3582 }
3583 }
3584
Adam Cohened307df2013-10-02 09:37:31 -07003585 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003586 showWorkspace(animated, null);
3587 }
3588
Adam Cohened307df2013-10-02 09:37:31 -07003589 protected void showWorkspace() {
3590 showWorkspace(true);
3591 }
3592
Adam Cohened66b2b2012-01-23 17:28:51 -08003593 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohene25c5d12014-06-18 10:34:58 -07003594 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
Winson Chung2d75f122013-09-23 16:53:31 -07003595 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003596 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003597 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003598
Winson Chungc7d2b602012-05-16 17:02:20 -07003599 // Show the search bar (only animate if we were showing the drop target bar in spring
3600 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003601 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003602 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003603 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003604
Michael Jurkab3e22d92011-10-31 15:58:33 -07003605 // Set focus to the AppsCustomize button
3606 if (mAllAppsButton != null) {
3607 mAllAppsButton.requestFocus();
3608 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003609 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003610
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003611 // Change the state *after* we've called all the transition code
3612 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003613
Winson Chung5fb63472011-02-02 17:03:37 -08003614 // Resume the auto-advance of widgets
3615 mUserPresent = true;
3616 updateRunning();
3617
alanv1d4fde62012-10-17 13:15:47 -07003618 // Send an accessibility event to announce the context change
3619 getWindow().getDecorView()
3620 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003621
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003622 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003623 }
3624
Adam Cohened307df2013-10-02 09:37:31 -07003625 void showOverviewMode(boolean animated) {
3626 mWorkspace.setVisibility(View.VISIBLE);
3627 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3628 mState = State.WORKSPACE;
3629 onWorkspaceShown(animated);
3630 }
3631
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003632 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003633 }
3634
Winson Chung82963d52013-10-09 11:20:57 -07003635 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3636 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003637 if (mState != State.WORKSPACE) return;
3638
Winson Chung82963d52013-10-09 11:20:57 -07003639 if (resetPageToZero) {
3640 mAppsCustomizeTabHost.reset();
3641 }
Winson Chungc58497e2013-09-03 17:48:37 -07003642 showAppsCustomizeHelper(animated, false, contentType);
Adam Cohendcc5e712014-06-23 15:38:55 -04003643 mAppsCustomizeTabHost.post(new Runnable() {
3644 @Override
3645 public void run() {
3646 // We post this in-case the all apps view isn't yet constructed.
3647 mAppsCustomizeTabHost.requestFocus();
3648 }
3649 });
Michael Jurkab3e22d92011-10-31 15:58:33 -07003650
Michael Jurkab3e22d92011-10-31 15:58:33 -07003651 // Change the state *after* we've called all the transition code
3652 mState = State.APPS_CUSTOMIZE;
3653
3654 // Pause the auto-advance of widgets until we are out of AllApps
3655 mUserPresent = false;
3656 updateRunning();
3657 closeFolder();
3658
3659 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003660 getWindow().getDecorView()
3661 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003662 }
3663
Adam Cohen7777d962011-08-18 18:58:38 -07003664 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003665 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003666 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003667 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003668 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003669 }
Adam Cohen7777d962011-08-18 18:58:38 -07003670
Adam Cohenad4e15c2013-10-17 16:21:35 -07003671 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003672 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003673 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3674
Winson Chunge7a03942011-08-05 15:05:12 -07003675 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003676 @Override
3677 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003678 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003679 // Before we show workspace, hide all apps again because
3680 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3681 // clean up our state transition functions
3682 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003683 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003684 } else {
3685 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003686 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003687 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003688 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003689 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003690
Michael Jurkad3ef3062010-11-23 16:23:58 -08003691 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003692 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003693 final boolean animated = true;
3694 final boolean springLoaded = true;
3695 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003696 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003697 }
3698 // Otherwise, we are not in spring loaded mode, so don't do anything.
3699 }
3700
Michael Jurkab3e22d92011-10-31 15:58:33 -07003701 void lockAllApps() {
3702 // TODO
3703 }
3704
3705 void unlockAllApps() {
3706 // TODO
3707 }
3708
Winson Chungf0ea4d32011-06-06 14:27:16 -07003709 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003710 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003711 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003712 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003713 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003714 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003715 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003716 int duration = 0;
3717 if (mSearchDropTargetBar != null) {
3718 duration = mSearchDropTargetBar.getTransitionInDuration();
3719 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003720 mHotseat.animate().alpha(1f).setDuration(duration);
3721 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003722 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003723 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003724 }
3725 }
3726 }
3727
3728 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003729 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003730 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003731 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003732 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003733 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003734 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003735 int duration = 0;
3736 if (mSearchDropTargetBar != null) {
3737 duration = mSearchDropTargetBar.getTransitionOutDuration();
3738 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003739 mHotseat.animate().alpha(0f).setDuration(duration);
3740 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003741 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003742 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003743 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003744 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003745 }
3746
Patrick Dubroy5f445422011-02-18 14:35:21 -08003747 /**
3748 * Add an item from all apps or customize onto the given workspace screen.
3749 * If layout is null, add to the current screen.
3750 */
3751 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003752 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003753 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003754 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003755 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003756
Winson Chungdff8ebb2011-09-08 17:25:31 -07003757 /** Maps the current orientation to an index for referencing orientation correct global icons */
3758 private int getCurrentOrientationIndexForGlobalIcons() {
3759 // default - 0, landscape - 1
3760 switch (getResources().getConfiguration().orientation) {
3761 case Configuration.ORIENTATION_LANDSCAPE:
3762 return 1;
3763 default:
3764 return 0;
3765 }
3766 }
3767
Michael Jurkaae65ee32012-04-30 11:45:54 -07003768 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003769 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003770 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003771 // Look for the toolbar icon specified in the activity meta-data
3772 Bundle metaData = packageManager.getActivityInfo(
3773 activityName, PackageManager.GET_META_DATA).metaData;
3774 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003775 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003776 if (iconResId != 0) {
3777 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003778 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003779 }
3780 }
3781 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003782 // This can happen if the activity defines an invalid drawable
3783 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3784 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003785 } catch (Resources.NotFoundException nfe) {
3786 // This can happen if the activity defines an invalid drawable
3787 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3788 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003789 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003790 return null;
3791 }
3792
3793 // if successful in getting icon, return it; otherwise, set button to use default drawable
3794 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003795 int buttonId, ComponentName activityName, int fallbackDrawableId,
3796 String toolbarResourceName) {
3797 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003798 Resources r = getResources();
3799 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3800 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003801
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003802 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003803 // If we were unable to find the icon via the meta-data, use a generic one
3804 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003805 toolbarIcon = r.getDrawable(fallbackDrawableId);
3806 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003807 if (button != null) {
3808 button.setCompoundDrawables(toolbarIcon, null, null, null);
3809 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003810 return null;
3811 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003812 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003813 if (button != null) {
3814 button.setCompoundDrawables(toolbarIcon, null, null, null);
3815 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003816 return toolbarIcon.getConstantState();
3817 }
3818 }
3819
3820 // if successful in getting icon, return it; otherwise, set button to use default drawable
3821 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003822 int buttonId, ComponentName activityName, int fallbackDrawableId,
3823 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003824 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003825 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003826
Michael Jurka19e0fc52011-07-22 18:00:21 -07003827 if (button != null) {
3828 // If we were unable to find the icon via the meta-data, use a
3829 // generic one
3830 if (toolbarIcon == null) {
3831 button.setImageResource(fallbackDrawableId);
3832 } else {
3833 button.setImageDrawable(toolbarIcon);
3834 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003835 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003836
3837 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3838
Michael Jurka0423dcf2010-10-05 14:56:18 -07003839 }
3840
Winson Chung1b884092012-06-08 17:13:02 -07003841 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003842 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003843 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003844 }
3845
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003846 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003847 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003848 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003849 }
3850
Winson Chungbb185bd2011-11-21 12:31:42 -08003851 private void invalidatePressedFocusedStates(View container, View button) {
3852 if (container instanceof HolographicLinearLayout) {
3853 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3854 layout.invalidatePressedFocusedStates();
3855 } else if (button instanceof HolographicImageView) {
3856 HolographicImageView view = (HolographicImageView) button;
3857 view.invalidatePressedFocusedStates();
3858 }
3859 }
3860
Cristina Stancu476493b2013-08-07 17:20:14 +01003861 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003862 if (mQsb == null) {
3863 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3864 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003865 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003866 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003867 }
3868
3869 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003870 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003871 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003872 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003873 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003874
Winson Chung1cad91e2011-05-25 17:41:01 -07003875 final SearchManager searchManager =
3876 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3877 ComponentName activityName = searchManager.getGlobalSearchActivity();
3878 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003879 int coi = getCurrentOrientationIndexForGlobalIcons();
3880 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003881 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3882 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3883 if (sGlobalSearchIcon[coi] == null) {
3884 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3885 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3886 TOOLBAR_ICON_METADATA_NAME);
3887 }
3888
Winson Chungc51db6a2011-10-05 11:44:49 -07003889 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3890 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003891 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003892 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003893 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003894 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003895 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3896 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003897 if (searchButton != null) searchButton.setVisibility(View.GONE);
3898 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003899 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003900 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003901 }
3902 }
3903
Cristina Stancu476493b2013-08-07 17:20:14 +01003904 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003905 final View searchButtonContainer = findViewById(R.id.search_button_container);
3906 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003907 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003908 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003909 }
3910
Cristina Stancu476493b2013-08-07 17:20:14 +01003911 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003912 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003913 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003914
Winson Chungc51db6a2011-10-05 11:44:49 -07003915 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003916 final SearchManager searchManager =
3917 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3918 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3919
3920 ComponentName activityName = null;
3921 if (globalSearchActivity != null) {
3922 // Check if the global search activity handles voice search
3923 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3924 intent.setPackage(globalSearchActivity.getPackageName());
3925 activityName = intent.resolveActivity(getPackageManager());
3926 }
3927
3928 if (activityName == null) {
3929 // Fallback: check if an activity other than the global search activity
3930 // resolves this
3931 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3932 activityName = intent.resolveActivity(getPackageManager());
3933 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003934 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003935 int coi = getCurrentOrientationIndexForGlobalIcons();
3936 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003937 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3938 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3939 if (sVoiceSearchIcon[coi] == null) {
3940 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3941 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3942 TOOLBAR_ICON_METADATA_NAME);
3943 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003944 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003945 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003946 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003947 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003948 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003949 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003950 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003951 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003952 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003953 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003954 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003955 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003956
Cristina Stancu476493b2013-08-07 17:20:14 +01003957 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003958 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3959 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003960 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003961 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003962 }
3963
Winson Chung5841efa2013-09-30 18:06:44 -07003964 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003965 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3966 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003967 boolean visible = !forceDisableVoiceButtonProxy &&
3968 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003969 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003970 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003971 }
3972 }
Winson Chung5841efa2013-09-30 18:06:44 -07003973
3974 /**
3975 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3976 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3977 */
3978 public void disableVoiceButtonProxy(boolean disabled) {
3979 updateVoiceButtonProxyVisible(disabled);
3980 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003981
Michael Jurkad7c28052012-04-27 15:43:36 -07003982 @Override
3983 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003984 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003985 final List<CharSequence> text = event.getText();
3986 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003987 // Populate event with a fake title based on the current state.
3988 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003989 text.add(mAppsCustomizeTabHost.getContentTag());
alanv1d4fde62012-10-17 13:15:47 -07003990 } else {
3991 text.add(getString(R.string.all_apps_home_button_label));
3992 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003993 return result;
3994 }
3995
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003996 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003997 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003998 */
3999 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4000 @Override
4001 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004002 closeSystemDialogs();
4003 }
4004 }
4005
4006 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08004007 * Receives notifications whenever the appwidgets are reset.
4008 */
4009 private class AppWidgetResetObserver extends ContentObserver {
4010 public AppWidgetResetObserver() {
4011 super(new Handler());
4012 }
4013
4014 @Override
4015 public void onChange(boolean selfChange) {
4016 onAppWidgetReset();
4017 }
4018 }
4019
4020 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07004021 * If the activity is currently paused, signal that we need to run the passed Runnable
4022 * in onResume.
4023 *
4024 * This needs to be called from incoming places where resources might have been loaded
4025 * while we are paused. That is becaues the Configuration might be wrong
4026 * when we're not running, and if it comes back to what it was when we
4027 * were paused, we are not restarted.
4028 *
4029 * Implementation of the method from LauncherModel.Callbacks.
4030 *
4031 * @return true if we are currently paused. The caller might be able to
4032 * skip some work in that case since we will come back again.
4033 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004034 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004035 if (mPaused) {
4036 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02004037 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07004038 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004039 }
4040 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07004041 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07004042 return true;
4043 } else {
4044 return false;
4045 }
4046 }
4047
Michael Jurkac402cd92013-05-20 15:49:32 +02004048 private boolean waitUntilResume(Runnable run) {
4049 return waitUntilResume(run, false);
4050 }
4051
Michael Jurka1e2f4652013-07-08 18:03:46 -07004052 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02004053 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07004054 }
4055
Michael Jurka7607c2f2013-04-03 14:33:19 -07004056 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004057 * If the activity is currently paused, signal that we need to re-run the loader
4058 * in onResume.
4059 *
4060 * This needs to be called from incoming places where resources might have been loaded
4061 * while we are paused. That is becaues the Configuration might be wrong
4062 * when we're not running, and if it comes back to what it was when we
4063 * were paused, we are not restarted.
4064 *
4065 * Implementation of the method from LauncherModel.Callbacks.
4066 *
4067 * @return true if we are currently paused. The caller might be able to
4068 * skip some work in that case since we will come back again.
4069 */
4070 public boolean setLoadOnResume() {
4071 if (mPaused) {
4072 Log.i(TAG, "setLoadOnResume");
4073 mOnResumeNeedsLoad = true;
4074 return true;
4075 } else {
4076 return false;
4077 }
4078 }
4079
4080 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004081 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004082 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04004083 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07004084 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07004085 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07004086 } else {
4087 return SCREEN_COUNT / 2;
4088 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004089 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07004090
Joe Onorato9c1289c2009-08-17 11:03:03 -04004091 /**
4092 * Refreshes the shortcuts shown on the workspace.
4093 *
4094 * Implementation of the method from LauncherModel.Callbacks.
4095 */
4096 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004097 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08004098
Michael Jurka7607c2f2013-04-03 14:33:19 -07004099 // If we're starting binding all over again, clear any bind calls we'd postponed in
4100 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4101 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07004102 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07004103
Winson Chungd64d1762013-08-20 14:37:16 -07004104 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07004105 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07004106 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07004107
Michael Jurka05bf6442011-11-30 20:28:53 -08004108 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07004109 if (mHotseat != null) {
4110 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004111 }
4112 }
4113
Adam Cohendcd297f2013-06-18 13:13:40 -07004114 @Override
4115 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07004116 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07004117
Adam Cohen5084cba2013-09-03 12:01:16 -07004118 // If there are no screens, we need to have an empty screen
4119 if (orderedScreenIds.size() == 0) {
4120 mWorkspace.addExtraEmptyScreen();
4121 }
Winson Chung0e6a7132013-08-23 12:55:10 -07004122
4123 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06004124 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05004125 if (hasCustomContentToLeft()) {
4126 mWorkspace.createCustomContentContainer();
4127 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07004128 }
Winson Chung64359a52013-07-08 17:17:08 -07004129 }
4130
4131 @Override
4132 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08004133 // Log to disk
4134 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4135 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4136 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07004137 int count = orderedScreenIds.size();
4138 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07004139 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07004140 }
Adam Cohendcd297f2013-06-18 13:13:40 -07004141 }
4142
Adam Cohen39a06042013-07-19 14:30:12 -07004143 private boolean shouldShowWeightWatcher() {
4144 String spKey = LauncherAppState.getSharedPreferencesKey();
4145 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07004146 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07004147
4148 return show;
4149 }
4150
4151 private void toggleShowWeightWatcher() {
4152 String spKey = LauncherAppState.getSharedPreferencesKey();
4153 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4154 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4155
4156 show = !show;
4157
4158 SharedPreferences.Editor editor = sp.edit();
4159 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4160 editor.commit();
4161
4162 if (mWeightWatcher != null) {
4163 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4164 }
4165 }
4166
Winson Chungd64d1762013-08-20 14:37:16 -07004167 public void bindAppsAdded(final ArrayList<Long> newScreens,
4168 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07004169 final ArrayList<ItemInfo> addAnimated,
4170 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004171 Runnable r = new Runnable() {
4172 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07004173 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07004174 }
4175 };
4176 if (waitUntilResume(r)) {
4177 return;
4178 }
4179
Winson Chungd64d1762013-08-20 14:37:16 -07004180 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08004181 if (newScreens != null) {
4182 bindAddScreens(newScreens);
4183 }
Winson Chungd64d1762013-08-20 14:37:16 -07004184
4185 // We add the items without animation on non-visible pages, and with
4186 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08004187 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004188 bindItems(addNotAnimated, 0,
4189 addNotAnimated.size(), false);
4190 }
Adam Cohen76a47a12014-02-05 11:47:43 -08004191 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004192 bindItems(addAnimated, 0,
4193 addAnimated.size(), true);
4194 }
Winson Chungc58497e2013-09-03 17:48:37 -07004195
Winson Chung87412982013-10-03 18:34:14 -07004196 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004197 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004198
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004199 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004200 addedApps != null && mAppsCustomizeContent != null) {
4201 mAppsCustomizeContent.addApps(addedApps);
4202 }
Winson Chungd64d1762013-08-20 14:37:16 -07004203 }
4204
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004205 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004206 * Bind the items start-end from the list.
4207 *
4208 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004209 */
Winson Chung64359a52013-07-08 17:17:08 -07004210 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4211 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004212 Runnable r = new Runnable() {
4213 public void run() {
4214 bindItems(shortcuts, start, end, forceAnimateIcons);
4215 }
4216 };
4217 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004218 return;
4219 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004220
Winson Chungf0c6ae02012-03-21 16:10:31 -07004221 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004222 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4223 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004224 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004225 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004226 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004227 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004228 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004229
4230 // Short circuit if we are loading dock items for a configuration which has no dock
4231 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4232 mHotseat == null) {
4233 continue;
4234 }
4235
Joe Onorato9c1289c2009-08-17 11:03:03 -04004236 switch (item.itemType) {
4237 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4238 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004239 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004240 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004241
Winson Chung64359a52013-07-08 17:17:08 -07004242 /*
4243 * TODO: FIX collision case
4244 */
Winson Chungce376632013-07-11 16:12:41 -07004245 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4246 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4247 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004248 View v = cl.getChildAt(item.cellX, item.cellY);
4249 Object tag = v.getTag();
4250 String desc = "Collision while binding workspace item: " + item
4251 + ". Collides with " + tag;
4252 if (LauncherAppState.isDogfoodBuild()) {
4253 throw (new RuntimeException(desc));
4254 } else {
4255 Log.d(TAG, desc);
4256 }
Winson Chungce376632013-07-11 16:12:41 -07004257 }
Winson Chung64359a52013-07-08 17:17:08 -07004258 }
4259
Adam Cohendcd297f2013-06-18 13:13:40 -07004260 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4261 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004262 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004263 // Animate all the applications up now
4264 shortcut.setAlpha(0f);
4265 shortcut.setScaleX(0f);
4266 shortcut.setScaleY(0f);
4267 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004268 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004269 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004270 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004271 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004272 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004273 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004274 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004275 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4276 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004277 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004278 default:
4279 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004280 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004281 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004282
Winson Chung997a9232013-07-24 15:33:46 -07004283 if (animateIcons) {
4284 // Animate to the correct page
4285 if (newShortcutsScreenId > -1) {
4286 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004287 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004288 final Runnable startBounceAnimRunnable = new Runnable() {
4289 public void run() {
4290 anim.playTogether(bounceAnims);
4291 anim.start();
4292 }
4293 };
Winson Chung997a9232013-07-24 15:33:46 -07004294 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004295 // We post the animation slightly delayed to prevent slowdowns
4296 // when we are loading right after we return to launcher.
4297 mWorkspace.postDelayed(new Runnable() {
4298 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004299 if (mWorkspace != null) {
4300 mWorkspace.snapToPage(newScreenIndex);
4301 mWorkspace.postDelayed(startBounceAnimRunnable,
4302 NEW_APPS_ANIMATION_DELAY);
4303 }
Winson Chung94d67682013-09-25 16:29:40 -07004304 }
4305 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004306 } else {
4307 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004308 }
4309 }
Winson Chung64359a52013-07-08 17:17:08 -07004310 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004311 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004312 }
4313
Joe Onorato9c1289c2009-08-17 11:03:03 -04004314 /**
4315 * Implementation of the method from LauncherModel.Callbacks.
4316 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004317 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004318 Runnable r = new Runnable() {
4319 public void run() {
4320 bindFolders(folders);
4321 }
4322 };
4323 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004324 return;
4325 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004326 sFolders.clear();
4327 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004328 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004329
4330 /**
4331 * Add the views for a widget to the workspace.
4332 *
4333 * Implementation of the method from LauncherModel.Callbacks.
4334 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004335 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004336 Runnable r = new Runnable() {
4337 public void run() {
4338 bindAppWidget(item);
4339 }
4340 };
4341 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004342 return;
4343 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004344
Daniel Sandler843e8602010-06-07 14:59:01 -04004345 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4346 if (DEBUG_WIDGETS) {
4347 Log.d(TAG, "bindAppWidget: " + item);
4348 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004349 final Workspace workspace = mWorkspace;
4350
Sunny Goyalff572272014-07-23 13:58:07 -07004351 AppWidgetProviderInfo appWidgetInfo;
4352 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4353 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4354
4355 appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
4356 if (appWidgetInfo == null) {
4357 if (DEBUG_WIDGETS) {
4358 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4359 + " belongs to component " + item.providerName
4360 + ", as the povider is null");
4361 }
4362 LauncherModel.deleteItemFromDatabase(this, item);
4363 return;
4364 }
4365 // Note: This assumes that the id remap broadcast is received before this step.
4366 // If that is not the case, the id remap will be ignored and user may see the
4367 // click to setup view.
4368 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4369 pendingInfo.spanX = item.spanX;
4370 pendingInfo.spanY = item.spanY;
4371 pendingInfo.minSpanX = item.minSpanX;
4372 pendingInfo.minSpanY = item.minSpanY;
4373 Bundle options =
4374 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4375
Sunny Goyalff572272014-07-23 13:58:07 -07004376 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
Sunny Goyalffe83f12014-08-14 17:39:34 -07004377 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4378 newWidgetId, appWidgetInfo, options);
Sunny Goyalff572272014-07-23 13:58:07 -07004379
4380 // TODO consider showing a permission dialog when the widget is clicked.
4381 if (!success) {
4382 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4383 if (DEBUG_WIDGETS) {
4384 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4385 + " belongs to component " + item.providerName
4386 + ", as the launcher is unable to bing a new widget id");
4387 }
4388 LauncherModel.deleteItemFromDatabase(this, item);
4389 return;
4390 }
4391
4392 item.appWidgetId = newWidgetId;
4393
4394 // If the widget has a configure activity, it is still needs to set it up, otherwise
4395 // the widget is ready to go.
4396 item.restoreStatus = (appWidgetInfo.configure == null)
4397 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4398 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4399
4400 LauncherModel.updateItemInDatabase(this, item);
4401 }
4402
Sunny Goyal651077b2014-06-30 14:15:31 -07004403 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4404 final int appWidgetId = item.appWidgetId;
4405 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4406 if (DEBUG_WIDGETS) {
4407 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4408 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004409
Sunny Goyal651077b2014-06-30 14:15:31 -07004410 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4411 } else {
4412 appWidgetInfo = null;
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004413 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item);
4414 view.updateIcon(mIconCache);
4415 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004416 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004417 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004418 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004419
Joe Onorato9c1289c2009-08-17 11:03:03 -04004420 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004421 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004422
Adam Cohendcd297f2013-06-18 13:13:40 -07004423 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004424 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004425 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4426
Joe Onorato9c1289c2009-08-17 11:03:03 -04004427 workspace.requestLayout();
4428
Daniel Sandler843e8602010-06-07 14:59:01 -04004429 if (DEBUG_WIDGETS) {
4430 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4431 + (SystemClock.uptimeMillis()-start) + "ms");
4432 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004433 }
4434
Sunny Goyalff572272014-07-23 13:58:07 -07004435 /**
4436 * Restores a pending widget.
4437 *
4438 * @param appWidgetId The app widget id
4439 * @param cellInfo The position on screen where to create the widget.
4440 */
4441 private void completeRestoreAppWidget(final int appWidgetId) {
4442 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4443 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4444 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4445 return;
4446 }
4447
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004448 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004449 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4450
4451 mWorkspace.reinflateWidgetsIfNecessary();
4452 LauncherModel.updateItemInDatabase(this, info);
4453 }
4454
Adam Cohen1462de32012-07-24 22:34:36 -07004455 public void onPageBoundSynchronously(int page) {
4456 mSynchronouslyBoundPages.add(page);
4457 }
4458
Joe Onorato9c1289c2009-08-17 11:03:03 -04004459 /**
4460 * Callback saying that there aren't any more items to bind.
4461 *
4462 * Implementation of the method from LauncherModel.Callbacks.
4463 */
Adam Cohene25af792013-06-06 23:08:25 -07004464 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004465 Runnable r = new Runnable() {
4466 public void run() {
4467 finishBindingItems(upgradePath);
4468 }
4469 };
4470 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004471 return;
4472 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004473 if (mSavedState != null) {
4474 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004475 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004476 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004477 mSavedState = null;
4478 }
4479
Adam Cohen1462de32012-07-24 22:34:36 -07004480 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004481
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004482 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004483 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004484
4485 // If we received the result of any pending adds while the loader was running (e.g. the
4486 // widget configuration forced an orientation change), process them now.
4487 if (sPendingAddItem != null) {
4488 final long screenId = completeAdd(sPendingAddItem);
4489
4490 // TODO: this moves the user to the page where the pending item was added. Ideally,
4491 // the screen would be guaranteed to exist after bind, and the page would be set through
4492 // the workspace restore process.
4493 mWorkspace.post(new Runnable() {
4494 @Override
4495 public void run() {
4496 mWorkspace.snapToScreenId(screenId);
4497 }
4498 });
4499 sPendingAddItem = null;
4500 }
4501
Adam Cohene25af792013-06-06 23:08:25 -07004502 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004503 mWorkspace.getUniqueComponents(true, null);
4504 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004505 }
Sunny Goyale755d462014-07-22 13:48:29 -07004506 PackageInstallerCompat.getInstance(this).onFinishBind();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004507 }
4508
Adam Cohen3ed316a2014-07-23 18:21:20 -07004509 private void sendLoadingCompleteBroadcastIfNecessary() {
4510 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4511 String permission =
4512 getResources().getString(R.string.receive_first_load_broadcast_permission);
4513 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4514 sendBroadcast(intent, permission);
4515 SharedPreferences.Editor editor = mSharedPrefs.edit();
4516 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4517 editor.apply();
4518 }
4519 }
4520
Winson Chunga0b7e862013-09-05 16:03:15 -07004521 public boolean isAllAppsButtonRank(int rank) {
4522 if (mHotseat != null) {
4523 return mHotseat.isAllAppsButtonRank(rank);
4524 }
4525 return false;
4526 }
4527
Winson Chunga2413752012-04-03 14:22:34 -07004528 private boolean canRunNewAppsAnimation() {
4529 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4530 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4531 }
4532
Winson Chungc9168342013-06-26 14:54:55 -07004533 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4534 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4535 PropertyValuesHolder.ofFloat("alpha", 1f),
4536 PropertyValuesHolder.ofFloat("scaleX", 1f),
4537 PropertyValuesHolder.ofFloat("scaleY", 1f));
4538 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4539 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4540 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4541 return bounceAnim;
4542 }
4543
Adam Cohen27772732013-11-11 14:00:56 +00004544 public boolean useVerticalBarLayout() {
4545 return LauncherAppState.getInstance().getDynamicGrid().
4546 getDeviceProfile().isVerticalBarLayout();
4547 }
4548
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004549 protected Rect getSearchBarBounds() {
4550 return LauncherAppState.getInstance().getDynamicGrid().
4551 getDeviceProfile().getSearchBarBounds();
4552 }
4553
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004554 @Override
4555 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004556 boolean searchVisible = updateGlobalSearchIcon();
4557 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004558 if (mSearchDropTargetBar != null) {
4559 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4560 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004561 }
4562
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004563 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004564 * Add the icons for all apps.
4565 *
4566 * Implementation of the method from LauncherModel.Callbacks.
4567 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004568 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004569 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004570 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4571 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4572 getHotseat().addAllAppsFolder(mIconCache, apps,
4573 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4574 }
4575 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004576 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004577 if (mAppsCustomizeContent != null) {
4578 mAppsCustomizeContent.onPackagesUpdated(
4579 LauncherModel.getSortedWidgetsAndShortcuts(this));
4580 }
Winson Chungc58497e2013-09-03 17:48:37 -07004581 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004582 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004583 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004584 mAppsCustomizeContent.onPackagesUpdated(
4585 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004586 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004587 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004588 }
4589
4590 /**
4591 * A package was updated.
4592 *
4593 * Implementation of the method from LauncherModel.Callbacks.
4594 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004595 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004596 Runnable r = new Runnable() {
4597 public void run() {
4598 bindAppsUpdated(apps);
4599 }
4600 };
4601 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004602 return;
4603 }
4604
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004605 if (mWorkspace != null) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004606 mWorkspace.updateShortcutsAndWidgets(apps);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004607 }
Winson Chungc58497e2013-09-03 17:48:37 -07004608
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004609 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004610 mAppsCustomizeContent != null) {
4611 mAppsCustomizeContent.updateApps(apps);
4612 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004613 }
4614
4615 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004616 * Update the state of a package, typically related to install state.
4617 *
4618 * Implementation of the method from LauncherModel.Callbacks.
4619 */
Sunny Goyale755d462014-07-22 13:48:29 -07004620 @Override
4621 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004622 if (mWorkspace != null) {
Sunny Goyale755d462014-07-22 13:48:29 -07004623 mWorkspace.updatePackageState(installInfo);
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004624 }
4625 }
4626
4627 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004628 * A package was uninstalled. We take both the super set of packageNames
4629 * in addition to specific applications to remove, the reason being that
4630 * this can be called when a package is updated as well. In that scenario,
4631 * we only remove specific components from the workspace, where as
4632 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004633 *
4634 * Implementation of the method from LauncherModel.Callbacks.
4635 */
Winson Chung83892cc2013-05-01 16:53:33 -07004636 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004637 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004638 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004639 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004640 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004641 }
Winson Chungd64d1762013-08-20 14:37:16 -07004642 };
4643 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004644 return;
4645 }
4646
Winson Chungdf95eb12013-10-16 14:57:07 -07004647 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004648 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004649 }
4650 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004651 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004652 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004653
Winson Chunga1820962011-10-03 16:31:06 -07004654 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004655 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004656
Winson Chungdf95eb12013-10-16 14:57:07 -07004657 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004658 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004659 mAppsCustomizeContent != null) {
4660 mAppsCustomizeContent.removeApps(appInfos);
4661 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004662 }
Joe Onoratobe386092009-11-17 17:32:16 -08004663
4664 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004665 * A number of packages were updated.
4666 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004667 private ArrayList<Object> mWidgetsAndShortcuts;
4668 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004669 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004670 bindPackagesUpdated(mWidgetsAndShortcuts);
4671 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004672 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004673 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004674 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4675 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4676 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004677 return;
4678 }
4679
Winson Chung64359a52013-07-08 17:17:08 -07004680 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004681 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004682 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004683 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004684 }
4685
Winson Chung400438b2011-01-16 17:53:48 -08004686 private int mapConfigurationOriActivityInfoOri(int configOri) {
4687 final Display d = getWindowManager().getDefaultDisplay();
4688 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4689 switch (d.getRotation()) {
4690 case Surface.ROTATION_0:
4691 case Surface.ROTATION_180:
4692 // We are currently in the same basic orientation as the natural orientation
4693 naturalOri = configOri;
4694 break;
4695 case Surface.ROTATION_90:
4696 case Surface.ROTATION_270:
4697 // We are currently in the other basic orientation to the natural orientation
4698 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4699 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4700 break;
4701 }
4702
4703 int[] oriMap = {
4704 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4705 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4706 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4707 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4708 };
4709 // Since the map starts at portrait, we need to offset if this device's natural orientation
4710 // is landscape.
4711 int indexOffset = 0;
4712 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4713 indexOffset = 1;
4714 }
4715 return oriMap[(d.getRotation() + indexOffset) % 4];
4716 }
Adam Cohen446e9402011-09-15 18:21:21 -07004717
Winson Chung4b919f82012-05-01 10:44:08 -07004718 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004719 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004720 getResources().getBoolean(R.bool.allow_rotation);
4721 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004722 }
Winson Chung4b919f82012-05-01 10:44:08 -07004723 public void lockScreenOrientation() {
4724 if (isRotationEnabled()) {
4725 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4726 .getConfiguration().orientation));
4727 }
4728 }
4729 public void unlockScreenOrientation(boolean immediate) {
4730 if (isRotationEnabled()) {
4731 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004732 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004733 } else {
4734 mHandler.postDelayed(new Runnable() {
4735 public void run() {
4736 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4737 }
4738 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004739 }
Winson Chung4b919f82012-05-01 10:44:08 -07004740 }
Winson Chung400438b2011-01-16 17:53:48 -08004741 }
4742
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004743 /**
4744 * Called when the SearchBar hint should be changed.
4745 *
4746 * @param hint the hint to be displayed in the search bar.
4747 */
4748 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004749 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004750 }
4751
Winson Chunge43a1e72014-01-15 10:33:02 -08004752 protected boolean isLauncherPreinstalled() {
4753 PackageManager pm = getPackageManager();
4754 try {
4755 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4756 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4757 return true;
4758 } else {
4759 return false;
4760 }
4761 } catch (NameNotFoundException e) {
4762 e.printStackTrace();
4763 return false;
4764 }
4765 }
4766
Adam Cohenea90f832014-05-21 15:03:34 -07004767 /**
4768 * This method indicates whether or not we should suggest default wallpaper dimensions
4769 * when our wallpaper cropper was not yet used to set a wallpaper.
4770 */
4771 protected boolean overrideWallpaperDimensions() {
4772 return true;
4773 }
4774
Adam Cohen5eed5d82014-05-19 13:12:13 -07004775 protected boolean shouldClingFocusHotseatApp() {
4776 return false;
4777 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004778 protected String getFirstRunClingSearchBarHint() {
4779 return "";
4780 }
4781 protected String getFirstRunCustomContentHint() {
4782 return "";
4783 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004784 protected int getFirstRunFocusedHotseatAppDrawableId() {
4785 return -1;
4786 }
4787 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4788 return null;
4789 }
4790 protected int getFirstRunFocusedHotseatAppRank() {
4791 return -1;
4792 }
4793 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4794 return "";
4795 }
4796 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4797 return "";
4798 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004799
Winson Chungaf40f202013-09-18 18:26:31 -07004800 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004801 mLauncherClings.dismissFirstRunCling(v);
4802 }
4803 public void dismissMigrationClingCopyApps(View v) {
4804 mLauncherClings.dismissMigrationClingCopyApps(v);
4805 }
4806 public void dismissMigrationClingUseDefault(View v) {
4807 mLauncherClings.dismissMigrationClingUseDefault(v);
4808 }
4809 public void dismissMigrationWorkspaceCling(View v) {
4810 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004811 }
Winson Chung82f55532011-08-09 14:14:23 -07004812 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004813 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004814 }
4815 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004816 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004817 }
Adam Cohen6268f2d2014-05-16 16:42:35 -07004818 public void markFolderClingDismissedIfNecessary() {
4819 mLauncherClings.markFolderClingDismissedIfNecessary();
4820 }
Adam Cohen432609a2014-03-13 17:03:22 -07004821
4822 /**
4823 * To be overridden by subclasses to indicate that there is an activity to launch
4824 * before showing the standard launcher experience.
4825 */
4826 protected boolean hasFirstRunActivity() {
4827 return false;
4828 }
4829
4830 /**
4831 * To be overridden by subclasses to launch any first run activity
4832 */
4833 protected Intent getFirstRunActivity() {
4834 return null;
4835 }
4836
Winson Chunga6945242014-01-08 14:04:34 -08004837 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004838 return !ActivityManager.isRunningInTestHarness() &&
4839 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004840 }
4841
Adam Cohen4a9423d2014-03-28 14:22:31 -07004842 protected boolean hasRunFirstRunActivity() {
4843 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4844 }
4845
Adam Cohen432609a2014-03-13 17:03:22 -07004846 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004847 if (shouldRunFirstRunActivity() &&
4848 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004849 Intent firstRunIntent = getFirstRunActivity();
4850 if (firstRunIntent != null) {
4851 startActivity(firstRunIntent);
4852 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004853 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004854 }
4855 }
Adam Cohen432609a2014-03-13 17:03:22 -07004856 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004857 }
4858
4859 private void markFirstRunActivityShown() {
4860 SharedPreferences.Editor editor = mSharedPrefs.edit();
4861 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4862 editor.apply();
4863 }
4864
Adam Cohen432609a2014-03-13 17:03:22 -07004865 /**
4866 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4867 * screen that must be displayed and dismissed.
4868 */
4869 protected boolean hasDismissableIntroScreen() {
4870 return false;
4871 }
4872
4873 /**
4874 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4875 */
4876 protected View getIntroScreen() {
4877 return null;
4878 }
4879
4880 /**
4881 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4882 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4883 */
4884 private boolean shouldShowIntroScreen() {
4885 return hasDismissableIntroScreen() &&
4886 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4887 }
4888
4889 protected void showIntroScreen() {
4890 View introScreen = getIntroScreen();
4891 changeWallpaperVisiblity(false);
4892 if (introScreen != null) {
4893 mDragLayer.showOverlayView(introScreen);
4894 }
4895 }
4896
4897 public void dismissIntroScreen() {
4898 markIntroScreenDismissed();
4899 if (showFirstRunActivity()) {
4900 // We delay hiding the intro view until the first run activity is showing. This
4901 // avoids a blip.
4902 mWorkspace.postDelayed(new Runnable() {
4903 @Override
4904 public void run() {
4905 mDragLayer.dismissOverlayView();
4906 }
4907 }, ACTIVITY_START_DELAY);
4908 } else {
4909 mDragLayer.dismissOverlayView();
4910 }
4911 changeWallpaperVisiblity(true);
4912 }
4913
4914 private void markIntroScreenDismissed() {
4915 SharedPreferences.Editor editor = mSharedPrefs.edit();
4916 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4917 editor.apply();
4918 }
4919
Winson Chunga6945242014-01-08 14:04:34 -08004920 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004921 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4922 if (mHotseat != null) mHotseat.setAlpha(1f);
4923 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4924 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004925 }
4926
4927 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004928 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4929 if (mHotseat != null) mHotseat.setAlpha(0f);
4930 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4931 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004932 }
4933
Mathew Inwood72fbec12013-11-19 15:45:07 +00004934 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004935 // Called from search suggestion, not supported in other profiles.
4936 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4937 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4938 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4939 myUser);
4940 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004941 return null;
4942 }
Kenny Guyed131872014-04-30 03:02:21 +01004943 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004944 }
4945
4946 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4947 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004948 // Called from search suggestion, not supported in other profiles.
4949 return createShortcutDragInfo(shortcutIntent, caption, icon,
4950 UserHandleCompat.myUserHandle());
4951 }
4952
4953 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4954 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01004955 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01004956 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01004957 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004958 }
4959
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004960 protected void moveWorkspaceToDefaultScreen() {
4961 mWorkspace.moveToDefaultScreen(false);
4962 }
4963
Mathew Inwood72fbec12013-11-19 15:45:07 +00004964 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4965 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004966 mWorkspace.onExternalDragStartedWithItem(dragView);
4967 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004968 }
4969
Anjali Koppalf5d29132014-02-28 13:33:27 -08004970 @Override
4971 public void onPageSwitch(View newPage, int newPageIndex) {
4972 }
4973
Winson Chung80baf5a2010-08-09 16:03:15 -07004974 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004975 * Prints out out state for debugging.
4976 */
4977 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004978 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004979 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004980 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4981 Log.d(TAG, "mRestoring=" + mRestoring);
4982 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4983 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004984 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004985 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004986
Winson Chung785d2eb2011-04-14 16:08:02 -07004987 if (mAppsCustomizeContent != null) {
4988 mAppsCustomizeContent.dumpState();
4989 }
Daniel Sandler325dc232013-06-05 22:57:57 -04004990 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08004991 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07004992
4993 @Override
4994 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
4995 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07004996 synchronized (sDumpLogs) {
4997 writer.println(" ");
4998 writer.println("Debug logs: ");
4999 for (int i = 0; i < sDumpLogs.size(); i++) {
5000 writer.println(" " + sDumpLogs.get(i));
5001 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005002 }
5003 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005004
5005 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07005006 if (DEBUG_DUMP_LOG) {
5007 synchronized (sDumpLogs) {
5008 Log.d(TAG, "");
5009 Log.d(TAG, "*********************");
5010 Log.d(TAG, "Launcher debug logs: ");
5011 for (int i = 0; i < sDumpLogs.size(); i++) {
5012 Log.d(TAG, " " + sDumpLogs.get(i));
5013 }
5014 Log.d(TAG, "*********************");
5015 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07005016 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005017 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005018 }
5019
5020 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005021 addDumpLog(tag, log, null, debugLog);
5022 }
5023
5024 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07005025 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005026 if (e != null) {
5027 Log.d(tag, log, e);
5028 } else {
5029 Log.d(tag, log);
5030 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005031 }
Winson Chungede41292013-09-19 16:27:36 -07005032 if (DEBUG_DUMP_LOG) {
5033 sDateStamp.setTime(System.currentTimeMillis());
5034 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05005035 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5036 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07005037 }
Winson Chungede41292013-09-19 16:27:36 -07005038 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005039 }
5040
Winson Chungede41292013-09-19 16:27:36 -07005041 public void dumpLogsToLocalData() {
5042 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01005043 new AsyncTask<Void, Void, Void>() {
5044 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07005045 boolean success = false;
5046 sDateStamp.setTime(sRunStart);
5047 String FILENAME = sDateStamp.getMonth() + "-"
5048 + sDateStamp.getDay() + "_"
5049 + sDateStamp.getHours() + "-"
5050 + sDateStamp.getMinutes() + "_"
5051 + sDateStamp.getSeconds() + ".txt";
5052
5053 FileOutputStream fos = null;
5054 File outFile = null;
5055 try {
5056 outFile = new File(getFilesDir(), FILENAME);
5057 outFile.createNewFile();
5058 fos = new FileOutputStream(outFile);
5059 } catch (Exception e) {
5060 e.printStackTrace();
5061 }
5062 if (fos != null) {
5063 PrintWriter writer = new PrintWriter(fos);
5064
5065 writer.println(" ");
5066 writer.println("Debug logs: ");
5067 synchronized (sDumpLogs) {
5068 for (int i = 0; i < sDumpLogs.size(); i++) {
5069 writer.println(" " + sDumpLogs.get(i));
5070 }
5071 }
5072 writer.close();
5073 }
5074 try {
5075 if (fos != null) {
5076 fos.close();
5077 success = true;
5078 }
5079 } catch (IOException e) {
5080 e.printStackTrace();
5081 }
Michael Jurka43467462013-11-14 12:03:58 +01005082 return null;
Winson Chungede41292013-09-19 16:27:36 -07005083 }
Michael Jurka43467462013-11-14 12:03:58 +01005084 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07005085 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005086 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08005087}
Michael Jurka2763be32011-02-24 11:19:57 -08005088
Michael Jurkaabded662011-03-04 12:06:57 -08005089interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08005090 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07005091 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08005092 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08005093 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08005094 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08005095}
Dan Sandlerd5024042014-01-09 15:01:33 -05005096
5097interface DebugIntents {
5098 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5099 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00005100}