blob: c9d423c34e4c67a095bfa95996275ab0e3571489 [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;
Sunny Goyale755d462014-07-22 13:48:29 -070085import android.view.ViewAnimationUtils;
Adam Cohen96d30a12013-07-16 18:13:21 -070086import android.view.ViewGroup;
87import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080088import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Sunny Goyal651077b2014-06-30 14:15:31 -070089import android.view.Window;
Adam Cohen96d30a12013-07-16 18:13:21 -070090import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080091import android.view.accessibility.AccessibilityEvent;
Adam Cohen9bfdb762014-07-21 17:44:06 -070092import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080093import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080094import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070095import android.widget.Advanceable;
96import android.widget.FrameLayout;
97import android.widget.ImageView;
98import android.widget.TextView;
99import android.widget.Toast;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700100
Sunny Goyal651077b2014-06-30 14:15:31 -0700101import com.android.launcher3.DropTarget.DragObject;
102import com.android.launcher3.PagedView.PageSwitchListener;
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;
Winson Chunga2413752012-04-03 14:22:34 -0700245
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800246 private final BroadcastReceiver mCloseSystemDialogsReceiver
247 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800248 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
249
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800250 private LayoutInflater mInflater;
251
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800252 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700253 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800254 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800255 private DragLayer mDragLayer;
256 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700257 private View mWeightWatcher;
Winson Chunga6945242014-01-08 14:04:34 -0800258 private LauncherClings mLauncherClings;
Romain Guycbb89e42009-06-08 15:52:54 -0700259
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700260 private AppWidgetManager mAppWidgetManager;
261 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700262
Michael Jurkac9d95c52011-08-29 14:03:34 -0700263 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700264 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800265 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700266
Michael Jurka0280c3b2010-09-17 15:00:07 -0700267 private int[] mTmpAddItemCellCoordinates = new int[2];
268
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269 private FolderInfo mFolderInfo;
270
Winson Chung3d503fb2011-07-13 17:25:49 -0700271 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800272 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700273
Michael Jurka838a4ca2011-02-07 13:33:06 -0800274 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700275
Winson Chungc51db6a2011-10-05 11:44:49 -0700276 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700277 private AppsCustomizeTabHost mAppsCustomizeTabHost;
278 private AppsCustomizePagedView mAppsCustomizeContent;
279 private boolean mAutoAdvanceRunning = false;
Adam Cohen24ce0b32014-01-14 16:18:14 -0800280 private View mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800281
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800282 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700283 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
284 // scroll issues (because the workspace may not have been measured yet) and extra work.
285 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
286 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800287
288 private SpannableStringBuilder mDefaultKeySsb = null;
289
Joe Onorato9c1289c2009-08-17 11:03:03 -0400290 private boolean mWorkspaceLoading = true;
291
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800292 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800293 private boolean mRestoring;
294 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700295 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800296
Michael Jurka1e2f4652013-07-08 18:03:46 -0700297 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700298 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
299
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800300 private Bundle mSavedInstanceState;
301
Joe Onorato9c1289c2009-08-17 11:03:03 -0400302 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800303 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800304 private boolean mUserPresent = true;
305 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700306 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800307 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400308
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700309 private static LocaleConfiguration sLocaleConfiguration = null;
310
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700311 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700312
Adam Cohen61f560d2013-09-30 15:58:20 -0700313 private View.OnTouchListener mHapticFeedbackTouchListener;
314
Adam Cohended9f8d2010-11-03 13:25:16 -0700315 // Related to the auto-advancing of widgets
316 private final int ADVANCE_MSG = 1;
317 private final int mAdvanceInterval = 20000;
318 private final int mAdvanceStagger = 250;
319 private long mAutoAdvanceSentTime;
320 private long mAutoAdvanceTimeLeft = -1;
321 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
322 new HashMap<View, AppWidgetProviderInfo>();
323
Winson Chung400438b2011-01-16 17:53:48 -0800324 // Determines how long to wait after a rotation before restoring the screen orientation to
325 // match the sensor state.
326 private final int mRestoreScreenOrientationDelay = 500;
327
Michael Jurka4ef207b2010-11-29 17:05:45 -0800328 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700329 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
330 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
331 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800332
Winson Chungd64a6662013-09-30 11:06:59 -0700333 private Intent mAppMarketIntent = null;
334 private static final boolean DISABLE_MARKET_BUTTON = true;
335
Craig Mautner360310b2012-10-26 15:13:08 -0700336 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700337
Adam Cohen1462de32012-07-24 22:34:36 -0700338 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700339 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700340
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700341 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700342 static Date sDateStamp = new Date();
343 static DateFormat sDateFormat =
344 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
345 static long sRunStart = System.currentTimeMillis();
346 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700347
Winson Chung46353de2012-02-16 14:05:10 -0800348 // We only want to get the SharedPreferences once since it does an FS stat each time we get
349 // it from the context.
350 private SharedPreferences mSharedPrefs;
351
Adam Cohene25af792013-06-06 23:08:25 -0700352 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
353
Winson Chungf0c6ae02012-03-21 16:10:31 -0700354 // Holds the page that we need to animate to, and the icon views that we need to animate up
355 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700356 private ImageView mFolderIconImageView;
357 private Bitmap mFolderIconBitmap;
358 private Canvas mFolderIconCanvas;
359 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700360
Michael Jurkaddd62e92011-02-16 17:49:14 -0800361 private BubbleTextView mWaitingForResume;
362
Michael Jurkac1f5d262011-09-30 19:32:27 -0700363 private Runnable mBuildLayersRunnable = new Runnable() {
364 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700365 if (mWorkspace != null) {
366 mWorkspace.buildPageHardwareLayers();
367 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700368 }
369 };
370
Adam Cohendb364c32014-05-20 14:23:40 -0700371 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800372
Michael Jurka7267fa52013-09-26 15:29:57 -0700373 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800374
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800375 private static class PendingAddArguments {
376 int requestCode;
377 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700378 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700379 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800380 int cellX;
381 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700382 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800383 }
384
Daniel Sandlerff02d492013-08-05 02:12:05 -0400385 private Stats mStats;
386
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700387 FocusIndicatorView mFocusHandler;
388
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800389 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800390 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700391 }
392
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800393 @Override
394 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700395 if (DEBUG_STRICT_MODE) {
396 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
397 .detectDiskReads()
398 .detectDiskWrites()
399 .detectNetwork() // or .detectAll() for all detectable problems
400 .penaltyLog()
401 .build());
402 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
403 .detectLeakedSqlLiteObjects()
404 .detectLeakedClosableObjects()
405 .penaltyLog()
406 .penaltyDeath()
407 .build());
408 }
409
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800410 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400411
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400412 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400413 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700414 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700415 // Determine the dynamic grid properties
416 Point smallestSize = new Point();
417 Point largestSize = new Point();
418 Point realSize = new Point();
419 Display display = getWindowManager().getDefaultDisplay();
420 display.getCurrentSizeRange(smallestSize, largestSize);
421 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700422 DisplayMetrics dm = new DisplayMetrics();
423 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700424
Winson Chung5f8afe62013-08-12 16:19:28 -0700425 // Lazy-initialize the dynamic grid
426 DeviceProfile grid = app.initDynamicGrid(this,
427 Math.min(smallestSize.x, smallestSize.y),
428 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700429 realSize.x, realSize.y,
430 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700431
432 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400433 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700434 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700435 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800436 mModel = app.setLauncher(this);
437 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700438 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400439 mDragController = new DragController(this);
Winson Chunga6945242014-01-08 14:04:34 -0800440 mLauncherClings = new LauncherClings(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800441 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700442
Daniel Sandlerff02d492013-08-05 02:12:05 -0400443 mStats = new Stats(this);
444
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700445 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700446
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700447 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
448 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700449
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700450 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
451 // this also ensures that any synchronous binding below doesn't re-trigger another
452 // LauncherModel load.
453 mPaused = false;
454
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800455 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200456 android.os.Debug.startMethodTracing(
457 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800458 }
459
Adam Cohen53805212013-10-01 10:39:23 -0700460
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800461 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800462 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700463
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800464 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100465 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800466
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800467 registerContentObservers();
468
Joe Onorato7c312c12009-08-13 21:36:53 -0700469 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700470
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800471 mSavedState = savedInstanceState;
472 restoreState(mSavedState);
473
474 if (PROFILE_STARTUP) {
475 android.os.Debug.stopMethodTracing();
476 }
477
478 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700479 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700480 // If the user leaves launcher, then we should just load items asynchronously when
481 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500482 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700483 } else {
484 // We only load the page synchronously if the user rotates (or triggers a
485 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800486 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700487 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800488 }
489
490 // For handling default keys
491 mDefaultKeySsb = new SpannableStringBuilder();
492 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800493
494 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
495 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800496
Adam Cohenf9426d52012-06-04 17:26:21 -0700497 updateGlobalIcons();
498
499 // On large interfaces, we want the screen to auto-rotate based on the current orientation
500 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700501
Adam Cohen432609a2014-03-13 17:03:22 -0700502 if (shouldShowIntroScreen()) {
503 showIntroScreen();
504 } else {
505 showFirstRunActivity();
506 }
507
Winson Chunge43a1e72014-01-15 10:33:02 -0800508 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
509 // on the device, then we always show the first run cling experience (or if there is no
510 // launcher2). Otherwise, we prompt the user upon started for migration
Winson Chunge43a1e72014-01-15 10:33:02 -0800511 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
512 if (mModel.canMigrateFromOldLauncherDb(this)) {
513 mLauncherClings.showMigrationCling();
514 } else {
515 mLauncherClings.showFirstRunCling();
516 }
Winson Chunga6945242014-01-08 14:04:34 -0800517 } else {
Winson Chunge43a1e72014-01-15 10:33:02 -0800518 mLauncherClings.removeFirstRunAndMigrationClings();
Winson Chunga6945242014-01-08 14:04:34 -0800519 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700520 }
521
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700522 @Override
523 public void onLauncherProviderChange() { }
524
Winson Chung98ca0f72013-07-29 12:58:51 -0700525 /** To be overriden by subclasses to hint to Launcher that we have custom content */
526 protected boolean hasCustomContentToLeft() {
527 return false;
528 }
529
Dave Hawkeya8881582013-09-17 15:55:33 -0600530 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500531 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600532 * {@link #addToCustomContentPage}. This will only be invoked if
533 * {@link #hasCustomContentToLeft()} is {@code true}.
534 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500535 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600536 }
537
538 /**
539 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
540 * ensure the custom content page is added or removed if necessary.
541 */
542 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600543 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600544 // Not bound yet, wait for bindScreens to be called.
545 return;
546 }
547
548 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
549 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500550 mWorkspace.createCustomContentContainer();
551 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600552 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
553 mWorkspace.removeCustomContentPage();
554 }
555 }
556
Adam Cohenf9426d52012-06-04 17:26:21 -0700557 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700558 boolean searchVisible = false;
559 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800560 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700561 int coi = getCurrentOrientationIndexForGlobalIcons();
562 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
563 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700564 if (!DISABLE_MARKET_BUTTON) {
565 updateAppMarketIcon();
566 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700567 searchVisible = updateGlobalSearchIcon();
568 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700569 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700570 if (sGlobalSearchIcon[coi] != null) {
571 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700572 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700573 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700574 if (sVoiceSearchIcon[coi] != null) {
575 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700576 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700577 }
Winson Chungd64a6662013-09-30 11:06:59 -0700578 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700579 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800580 }
Winson Chungadf0c182012-08-23 14:59:07 -0700581 if (mSearchDropTargetBar != null) {
582 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
583 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800584 }
Romain Guycbb89e42009-06-08 15:52:54 -0700585
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800586 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700587 if (sLocaleConfiguration == null) {
588 new AsyncTask<Void, Void, LocaleConfiguration>() {
589 @Override
590 protected LocaleConfiguration doInBackground(Void... unused) {
591 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
592 readConfiguration(Launcher.this, localeConfiguration);
593 return localeConfiguration;
594 }
595
596 @Override
597 protected void onPostExecute(LocaleConfiguration result) {
598 sLocaleConfiguration = result;
599 checkForLocaleChange(); // recursive, but now with a locale configuration
600 }
601 }.execute();
602 return;
603 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700604
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800605 final Configuration configuration = getResources().getConfiguration();
606
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700607 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800608 final String locale = configuration.locale.toString();
609
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700610 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800611 final int mcc = configuration.mcc;
612
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700613 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800614 final int mnc = configuration.mnc;
615
Romain Guy84f296c2009-11-04 15:00:44 -0800616 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800617
Romain Guy84f296c2009-11-04 15:00:44 -0800618 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700619 sLocaleConfiguration.locale = locale;
620 sLocaleConfiguration.mcc = mcc;
621 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700622
Joe Onorato0589f0f2010-02-08 13:44:00 -0800623 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700624
625 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100626 new AsyncTask<Void, Void, Void>() {
627 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700628 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100629 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700630 }
Michael Jurka43467462013-11-14 12:03:58 +0100631 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700632 }
633 }
634
635 private static class LocaleConfiguration {
636 public String locale;
637 public int mcc = -1;
638 public int mnc = -1;
639 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700640
Romain Guy98d01652009-06-30 16:21:04 -0700641 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
642 DataInputStream in = null;
643 try {
644 in = new DataInputStream(context.openFileInput(PREFERENCES));
645 configuration.locale = in.readUTF();
646 configuration.mcc = in.readInt();
647 configuration.mnc = in.readInt();
648 } catch (FileNotFoundException e) {
649 // Ignore
650 } catch (IOException e) {
651 // Ignore
652 } finally {
653 if (in != null) {
654 try {
655 in.close();
656 } catch (IOException e) {
657 // Ignore
658 }
659 }
660 }
661 }
662
663 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
664 DataOutputStream out = null;
665 try {
666 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
667 out.writeUTF(configuration.locale);
668 out.writeInt(configuration.mcc);
669 out.writeInt(configuration.mnc);
670 out.flush();
671 } catch (FileNotFoundException e) {
672 // Ignore
673 } catch (IOException e) {
674 //noinspection ResultOfMethodCallIgnored
675 context.getFileStreamPath(PREFERENCES).delete();
676 } finally {
677 if (out != null) {
678 try {
679 out.close();
680 } catch (IOException e) {
681 // Ignore
682 }
683 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800684 }
685 }
686
Anton Hanssona2f665f2013-09-26 12:18:32 +0100687 public Stats getStats() {
688 return mStats;
689 }
690
Bjorn Bringertc459e522013-06-07 19:36:01 +0100691 public LayoutInflater getInflater() {
692 return mInflater;
693 }
694
Winson Chung36a62fe2012-05-06 18:04:42 -0700695 boolean isDraggingEnabled() {
696 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
697 // that is subsequently removed from the workspace in startBinding().
698 return !mModel.isLoadingWorkspace();
699 }
700
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800701 static int getScreen() {
702 synchronized (sLock) {
703 return sScreen;
704 }
705 }
706
707 static void setScreen(int screen) {
708 synchronized (sLock) {
709 sScreen = screen;
710 }
711 }
712
Winson Chung557d6ed2011-07-08 15:34:52 -0700713 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000714 * Copied from View -- the View version of the method isn't called
715 * anywhere else in our process and only exists for API level 17+,
716 * so it's ok to keep our own version with no API requirement.
717 */
718 public static int generateViewId() {
719 for (;;) {
720 final int result = sNextGeneratedId.get();
721 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
722 int newValue = result + 1;
723 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
724 if (sNextGeneratedId.compareAndSet(result, newValue)) {
725 return result;
726 }
727 }
728 }
729
730 public int getViewIdForItem(ItemInfo info) {
731 // This cast is safe given the > 2B range for int.
732 int itemId = (int) info.id;
733 if (mItemIdToViewId.containsKey(itemId)) {
734 return mItemIdToViewId.get(itemId);
735 }
736 int viewId = generateViewId();
737 mItemIdToViewId.put(itemId, viewId);
738 return viewId;
739 }
740
741 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700742 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
743 * a configuration step, this allows the proper animations to run after other transitions.
744 */
Adam Cohendb364c32014-05-20 14:23:40 -0700745 private long completeAdd(PendingAddArguments args) {
746
747 long screenId = ensurePendingDropLayoutExists(args.screenId);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800748 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800749 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700750 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700751 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700752 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800753 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700754 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700755 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700756 case REQUEST_RECONFIGURE_APPWIDGET:
757 completeRestoreAppWidget(args.appWidgetId);
758 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800759 }
Michael Jurka27614d22012-04-02 06:40:22 -0700760 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
761 // if you turned the screen off and then back while in All Apps, Launcher would not
762 // return to the workspace. Clearing mAddInfo.container here fixes this issue
763 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700764 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800765 }
766
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800767 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700768 protected void onActivityResult(
769 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700770 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700771 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700772 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800773 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700774
Adam Cohenad4e15c2013-10-17 16:21:35 -0700775 Runnable exitSpringLoaded = new Runnable() {
776 @Override
777 public void run() {
778 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
779 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
780 }
781 };
782
Michael Jurka8b805b12012-04-18 14:23:14 -0700783 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700784 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700785 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
786 if (resultCode == RESULT_CANCELED) {
787 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700788 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700789 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700790 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700791 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
792 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700793 }
794 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200795 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
796 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
797 mWorkspace.exitOverviewMode(false);
798 }
799 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700800 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200801
Adam Cohened66b2b2012-01-23 17:28:51 -0800802 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
803 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700804
Adam Cohendb364c32014-05-20 14:23:40 -0700805 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800806 // We have special handling for widgets
807 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800808 final int appWidgetId;
809 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
810 : -1;
811 if (widgetId < 0) {
812 appWidgetId = pendingAddWidgetId;
813 } else {
814 appWidgetId = widgetId;
815 }
816
Adam Cohenad4e15c2013-10-17 16:21:35 -0700817 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800818 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700819 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
820 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700821 result = RESULT_CANCELED;
822 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700823 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700824 @Override
825 public void run() {
826 exitSpringLoadedDragModeDelayed(false, 0, null);
827 }
828 };
Adam Cohendb364c32014-05-20 14:23:40 -0700829 if (workspaceLocked) {
830 // No need to remove the empty screen if we're mid-binding, as the
831 // the bind will not add the empty screen.
832 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
833 } else {
834 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
835 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
836 }
Winson Chung5aaab772012-04-27 15:24:02 -0700837 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700838 if (!workspaceLocked) {
839 mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
840 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
841
842 dropLayout.setDropPending(true);
843 final Runnable onComplete = new Runnable() {
844 @Override
845 public void run() {
846 completeTwoStageWidgetDrop(resultCode, appWidgetId);
847 dropLayout.setDropPending(false);
848 }
849 };
850 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
851 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
852 } else {
853 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
854 mPendingAddInfo);
855 sPendingAddItem = args;
856 }
Winson Chung5aaab772012-04-27 15:24:02 -0700857 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800858 return;
859 }
860
Sunny Goyalff572272014-07-23 13:58:07 -0700861 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
862 if (resultCode == RESULT_OK) {
863 // Update the widget view.
864 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
865 pendingAddWidgetId, mPendingAddInfo);
866 if (workspaceLocked) {
867 sPendingAddItem = args;
868 } else {
869 completeAdd(args);
870 }
871 }
872 // Leave the widget in the pending state if the user canceled the configure.
873 return;
874 }
875
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800876 // The pattern used here is that a user PICKs a specific application,
877 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700878
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800879 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
880 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700881 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700882 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
883 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800884 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700885 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800886 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700887 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700888 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
889 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800890 }
Adam Cohen00074722013-10-11 17:46:09 -0700891 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700892 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700893 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800894 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800895 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800896 }
897
Adam Cohendb364c32014-05-20 14:23:40 -0700898 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
899 appWidgetId, ItemInfo info) {
900 PendingAddArguments args = new PendingAddArguments();
901 args.requestCode = requestCode;
902 args.intent = data;
903 args.container = info.container;
904 args.screenId = info.screenId;
905 args.cellX = info.cellX;
906 args.cellY = info.cellY;
907 args.appWidgetId = appWidgetId;
908 return args;
909 }
910
911 /**
912 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
913 *
914 * @param screenId the screen id to check
915 * @return the new screen, or screenId if it exists
916 */
917 private long ensurePendingDropLayoutExists(long screenId) {
918 CellLayout dropLayout =
919 (CellLayout) mWorkspace.getScreenWithId(screenId);
920 if (dropLayout == null) {
921 // it's possible that the add screen was removed because it was
922 // empty and a re-bind occurred
923 mWorkspace.addExtraEmptyScreen();
924 return mWorkspace.commitExtraEmptyScreen();
925 } else {
926 return screenId;
927 }
928 }
929
Adam Cohened66b2b2012-01-23 17:28:51 -0800930 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700931 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700932 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800933 Runnable onCompleteRunnable = null;
934 int animationType = 0;
935
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700936 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800937 if (resultCode == RESULT_OK) {
938 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
939 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700940 mPendingAddWidgetInfo);
941 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800942 onCompleteRunnable = new Runnable() {
943 @Override
944 public void run() {
945 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700946 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700947 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
948 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800949 }
950 };
951 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800952 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800953 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800954 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700955 if (mDragLayer.getAnimatedView() != null) {
956 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
957 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
958 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700959 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700960 // The animated view may be null in the case of a rotation during widget configuration
961 onCompleteRunnable.run();
962 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800963 }
964
965 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700966 protected void onStop() {
967 super.onStop();
968 FirstFrameAnimatorHelper.setIsVisible(false);
969 }
970
971 @Override
972 protected void onStart() {
973 super.onStart();
974 FirstFrameAnimatorHelper.setIsVisible(true);
975 }
976
977 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800978 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200979 long startTime = 0;
980 if (DEBUG_RESUME_TIME) {
981 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400982 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200983 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800984 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700985
Winson Chung4a2afa32012-07-19 14:53:05 -0700986 // Restore the previous launcher state
987 if (mOnResumeState == State.WORKSPACE) {
988 showWorkspace(false);
989 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -0800990 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700991 }
992 mOnResumeState = State.NONE;
993
Craig Mautner360310b2012-10-26 15:13:08 -0700994 // Background was set to gradient in onPause(), restore to black if in all apps.
995 setWorkspaceBackground(mState == State.WORKSPACE);
996
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800997 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700998 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700999 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -05001000 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001001 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001002 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001003 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001004 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001005 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1006 // execute them here
1007 long startTimeCallbacks = 0;
1008 if (DEBUG_RESUME_TIME) {
1009 startTimeCallbacks = System.currentTimeMillis();
1010 }
1011
1012 if (mAppsCustomizeContent != null) {
1013 mAppsCustomizeContent.setBulkBind(true);
1014 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001015 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1016 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001017 }
1018 if (mAppsCustomizeContent != null) {
1019 mAppsCustomizeContent.setBulkBind(false);
1020 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001021 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001022 if (DEBUG_RESUME_TIME) {
1023 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1024 (System.currentTimeMillis() - startTimeCallbacks));
1025 }
Michael Jurka447bf842013-05-15 14:52:15 +02001026 }
Michael Jurka54554252013-08-01 12:52:23 +02001027 if (mOnResumeCallbacks.size() > 0) {
1028 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1029 mOnResumeCallbacks.get(i).run();
1030 }
1031 mOnResumeCallbacks.clear();
1032 }
Winson Chunge4e50662012-01-23 14:45:13 -08001033
1034 // Reset the pressed state of icons that were locked in the press state while activities
1035 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001036 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001037 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001038 mWaitingForResume.setStayPressed(false);
1039 }
Winson Chunge4e50662012-01-23 14:45:13 -08001040 if (mAppsCustomizeContent != null) {
1041 // Resets the previous all apps icon press state
1042 mAppsCustomizeContent.resetDrawableState();
1043 }
Winson Chung82963d52013-10-09 11:20:57 -07001044
Adam Cohen06dff352012-06-01 17:17:08 -07001045 // It is possible that widgets can receive updates while launcher is not in the foreground.
1046 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1047 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1048 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001049 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001050
Winson Chung780fe592013-09-26 14:48:44 -07001051 // Process any items that were added while Launcher was away.
1052 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1053
Winson Chung5841efa2013-09-30 18:06:44 -07001054 // Update the voice search button proxy
1055 updateVoiceButtonProxyVisible(false);
1056
Adam Cohenf9426d52012-06-04 17:26:21 -07001057 // Again, as with the above scenario, it's possible that one or more of the global icons
1058 // were updated in the wrong orientation.
1059 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001060 if (DEBUG_RESUME_TIME) {
1061 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1062 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001063
1064 if (mWorkspace.getCustomContentCallbacks() != null) {
1065 // If we are resuming and the custom content is the current page, we call onShow().
1066 // It is also poassible that onShow will instead be called slightly after first layout
1067 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1068 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001069 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001070 }
1071 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001072 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001073 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001074
1075 PackageInstallerCompat.getInstance(this).onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001076 }
1077
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001078 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001079 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001080 // Ensure that items added to Launcher are queued until Launcher returns
1081 InstallShortcutReceiver.enableInstallQueue();
Sunny Goyale755d462014-07-22 13:48:29 -07001082 PackageInstallerCompat.getInstance(this).onPause();
Winson Chung997a9232013-07-24 15:33:46 -07001083
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001084 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001085 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001086 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001087 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001088
1089 // We call onHide() aggressively. The custom content callbacks should be able to
1090 // debounce excess onHide calls.
1091 if (mWorkspace.getCustomContentCallbacks() != null) {
1092 mWorkspace.getCustomContentCallbacks().onHide();
1093 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001094 }
Romain Guycbb89e42009-06-08 15:52:54 -07001095
Adam Cohenbffe7452013-07-22 18:21:45 -07001096 QSBScroller mQsbScroller = new QSBScroller() {
1097 int scrollY = 0;
1098
1099 @Override
1100 public void setScrollY(int scroll) {
1101 scrollY = scroll;
1102
1103 if (mWorkspace.isOnOrMovingToCustomContent()) {
1104 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001105 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001106 }
1107 }
1108 };
1109
1110 public void resetQSBScroll() {
1111 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001112 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001113 }
1114
1115 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001116 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1117 // by a onResume or by scrolling otherwise.
1118 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001119
1120 // Custom content is completely hidden
1121 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001122
1123 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1124 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001125
1126 // Indicates whether the user is allowed to scroll away from the custom content.
1127 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001128 }
1129
Jorim Jaggid017f882014-01-14 17:08:48 -08001130 protected boolean hasSettings() {
1131 return false;
1132 }
1133
Adam Cohenbffe7452013-07-22 18:21:45 -07001134 public interface QSBScroller {
1135 public void setScrollY(int scrollY);
1136 }
1137
Winson Chung98ca0f72013-07-29 12:58:51 -07001138 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001139 CustomContentCallbacks callbacks, String description) {
1140 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001141 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001142 }
1143
Adam Cohenedb40762013-07-18 16:45:45 -07001144 // The custom content needs to offset its content to account for the QSB
1145 public int getTopOffsetForCustomContent() {
1146 return mWorkspace.getPaddingTop();
1147 }
1148
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001149 @Override
1150 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001151 // Flag the loader to stop early before switching
1152 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001153 if (mAppsCustomizeContent != null) {
1154 mAppsCustomizeContent.surrender();
1155 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001156 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001157 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001158
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001159 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001160 @Override
1161 public void onWindowFocusChanged(boolean hasFocus) {
1162 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001163 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001164 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001165
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001166 private boolean acceptFilter() {
1167 final InputMethodManager inputManager = (InputMethodManager)
1168 getSystemService(Context.INPUT_METHOD_SERVICE);
1169 return !inputManager.isFullscreenMode();
1170 }
1171
1172 @Override
1173 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001174 final int uniChar = event.getUnicodeChar();
1175 final boolean handled = super.onKeyDown(keyCode, event);
1176 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1177 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001178 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1179 keyCode, event);
1180 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001181 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001182 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001183 // showSearchDialog()
1184 // If there are multiple keystrokes before the search dialog takes focus,
1185 // onSearchRequested() will be called for every keystroke,
1186 // but it is idempotent, so it's fine.
1187 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001188 }
1189 }
1190
Joe Onorato8a9625e2010-01-28 15:55:35 -08001191 // Eat the long press event so the keyboard doesn't come up.
1192 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1193 return true;
1194 }
1195
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001196 return handled;
1197 }
1198
Karl Rosaen138a0412009-04-23 19:00:21 -07001199 private String getTypedText() {
1200 return mDefaultKeySsb.toString();
1201 }
1202
1203 private void clearTypedText() {
1204 mDefaultKeySsb.clear();
1205 mDefaultKeySsb.clearSpans();
1206 Selection.setSelection(mDefaultKeySsb, 0);
1207 }
1208
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001209 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001210 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1211 * State
1212 */
1213 private static State intToState(int stateOrdinal) {
1214 State state = State.WORKSPACE;
1215 final State[] stateValues = State.values();
1216 for (int i = 0; i < stateValues.length; i++) {
1217 if (stateValues[i].ordinal() == stateOrdinal) {
1218 state = stateValues[i];
1219 break;
1220 }
1221 }
1222 return state;
1223 }
1224
1225 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001226 * Restores the previous state, if it exists.
1227 *
1228 * @param savedState The previous state.
1229 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001230 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001231 private void restoreState(Bundle savedState) {
1232 if (savedState == null) {
1233 return;
1234 }
1235
Michael Jurka883f55b2010-10-21 15:47:14 -07001236 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001237 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001238 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001239 }
1240
Adam Cohen21cd0022013-10-09 18:57:02 -07001241 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1242 PagedView.INVALID_RESTORE_PAGE);
1243 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001244 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001245 }
1246
Winson Chung3d503fb2011-07-13 17:25:49 -07001247 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001248 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001249
Winson Chung3d503fb2011-07-13 17:25:49 -07001250 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1251 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001252 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001253 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1254 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001255 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1256 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1257 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001258 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001259 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001260 mRestoring = true;
1261 }
1262
1263 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1264 if (renameFolder) {
1265 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001266 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001267 mRestoring = true;
1268 }
Winson Chunga12a2502010-12-20 14:41:35 -08001269
Winson Chung785d2eb2011-04-14 16:08:02 -07001270 // Restore the AppsCustomize tab
1271 if (mAppsCustomizeTabHost != null) {
1272 String curTab = savedState.getString("apps_customize_currentTab");
1273 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001274 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001275 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001276 mAppsCustomizeContent.loadAssociatedPages(
1277 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001278 }
1279
Winson Chung5afbf7b2011-07-25 11:53:08 -07001280 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1281 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001282 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001283 mItemIdToViewId = (HashMap<Integer, Integer>)
1284 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001285 }
1286
1287 /**
1288 * Finds all the views we need and configure them properly.
1289 */
1290 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001291 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001292
Craig Mautner360310b2012-10-26 15:13:08 -07001293 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001294 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001295 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1296 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001297 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001298 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001299
John Spurlock77e1f472013-09-11 10:09:51 -04001300 mLauncherView.setSystemUiVisibility(
1301 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001302 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001303
Winson Chung4c98d922011-05-31 16:50:48 -07001304 // Setup the drag layer
1305 mDragLayer.setup(this, dragController);
1306
Winson Chung3d503fb2011-07-13 17:25:49 -07001307 // Setup the hotseat
1308 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1309 if (mHotseat != null) {
1310 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001311 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001312 }
1313
Jorim Jaggid017f882014-01-14 17:08:48 -08001314 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001315 View widgetButton = findViewById(R.id.widget_button);
1316 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001317 @Override
1318 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001319 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001320 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001321 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001322 }
1323 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001324 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1325
1326 View wallpaperButton = findViewById(R.id.wallpaper_button);
1327 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001328 @Override
1329 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001330 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001331 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001332 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001333 }
1334 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001335 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1336
1337 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001338 if (hasSettings()) {
1339 settingsButton.setOnClickListener(new OnClickListener() {
1340 @Override
1341 public void onClick(View arg0) {
1342 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001343 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001344 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001345 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001346 });
1347 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1348 } else {
1349 settingsButton.setVisibility(View.GONE);
1350 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1351 lp.gravity = Gravity.END | Gravity.TOP;
1352 widgetButton.requestLayout();
1353 }
1354
Adam Cohendbdff6b2013-09-18 19:09:15 -07001355 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001356
Winson Chung4c98d922011-05-31 16:50:48 -07001357 // Setup the workspace
1358 mWorkspace.setHapticFeedbackEnabled(false);
1359 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001360 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001361 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001362
Winson Chungf0ea4d32011-06-06 14:27:16 -07001363 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001364 mSearchDropTargetBar = (SearchDropTargetBar)
1365 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001366
Winson Chungf0ea4d32011-06-06 14:27:16 -07001367 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001368 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001369 mAppsCustomizeContent = (AppsCustomizePagedView)
1370 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1371 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001372
Winson Chung3d503fb2011-07-13 17:25:49 -07001373 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001374 dragController.setDragScoller(mWorkspace);
1375 dragController.setScrollView(mDragLayer);
1376 dragController.setMoveTarget(mWorkspace);
1377 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001378 if (mSearchDropTargetBar != null) {
1379 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001380 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001381
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001382 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001383 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001384 mWeightWatcher = new WeightWatcher(this);
1385 mWeightWatcher.setAlpha(0.5f);
1386 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001387 new FrameLayout.LayoutParams(
1388 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001389 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001390 Gravity.BOTTOM)
1391 );
Adam Cohen39a06042013-07-19 14:30:12 -07001392
1393 boolean show = shouldShowWeightWatcher();
1394 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001395 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001396 }
1397
1398 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001399 * Sets the all apps button. This method is called from {@link Hotseat}.
1400 */
1401 public void setAllAppsButton(View allAppsButton) {
1402 mAllAppsButton = allAppsButton;
1403 }
1404
1405 public View getAllAppsButton() {
1406 return mAllAppsButton;
1407 }
1408
1409 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001410 * Creates a view representing a shortcut.
1411 *
1412 * @param info The data structure describing the shortcut.
1413 *
1414 * @return A View inflated from R.layout.application.
1415 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001416 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001417 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001418 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001419 }
1420
1421 /**
1422 * Creates a view representing a shortcut inflated from the specified resource.
1423 *
1424 * @param layoutResId The id of the XML layout used to create the shortcut.
1425 * @param parent The group the shortcut belongs to.
1426 * @param info The data structure describing the shortcut.
1427 *
1428 * @return A View inflated from layoutResId.
1429 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001430 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001431 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001432 favorite.applyFromShortcutInfo(info, mIconCache, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001433 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001434 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001435 return favorite;
1436 }
1437
1438 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001439 * Add a shortcut to the workspace.
1440 *
1441 * @param data The intent describing the shortcut.
1442 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001443 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001444 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001445 int cellY) {
1446 int[] cellXY = mTmpAddItemCellCoordinates;
1447 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001448 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001449
Michael Jurkad3ef3062010-11-23 16:23:58 -08001450 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001451
Adam Cohen558baaf2011-08-15 15:22:57 -07001452 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001453 if (info == null) {
1454 return;
1455 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001456 final View view = createShortcut(info);
1457
Adam Cohenfbba09b2011-07-18 21:43:05 -07001458 // First we check if we already know the exact location where we want to add this item.
1459 if (cellX >= 0 && cellY >= 0) {
1460 cellXY[0] = cellX;
1461 cellXY[1] = cellY;
1462 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001463
1464 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001465 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001466 true, null,null)) {
1467 return;
1468 }
1469 DragObject dragObject = new DragObject();
1470 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001471 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1472 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001473 return;
1474 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001475 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001476 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001477 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001478 foundCellSpan = (result != null);
1479 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001480 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001481 }
1482
1483 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001484 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001485 return;
1486 }
1487
Adam Cohendcd297f2013-06-18 13:13:40 -07001488 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001489
1490 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001491 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001492 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001493 }
1494 }
1495
Adam Cohen2f093b62012-04-30 18:59:53 -07001496 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1497 int minHeight) {
1498 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001499 // We want to account for the extra amount of padding that we are adding to the widget
1500 // to ensure that it gets the full amount of space that it has requested
1501 int requiredWidth = minWidth + padding.left + padding.right;
1502 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001503 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001504 }
1505
Adam Cohen2f093b62012-04-30 18:59:53 -07001506 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1507 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001508 }
1509
Adam Cohen2f093b62012-04-30 18:59:53 -07001510 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1511 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001512 }
1513
Adam Cohen2f093b62012-04-30 18:59:53 -07001514 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1515 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001516 }
1517
Adam Cohen2f093b62012-04-30 18:59:53 -07001518 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1519 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001520 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001521 }
1522
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001523 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001524 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001525 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001526 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001527 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001528 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001529 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001530 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1531 if (appWidgetInfo == null) {
1532 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1533 }
Romain Guycbb89e42009-06-08 15:52:54 -07001534
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001535 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001536 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001537
Adam Cohen2f093b62012-04-30 18:59:53 -07001538 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1539 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001540
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001541 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001542 // We have saved the position to which the widget was dragged-- this really only matters
1543 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001544 int[] cellXY = mTmpAddItemCellCoordinates;
1545 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001546 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001547 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001548 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1549 cellXY[0] = mPendingAddInfo.cellX;
1550 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001551 spanXY[0] = mPendingAddInfo.spanX;
1552 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001553 foundCellSpan = true;
1554 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001555 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001556 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001557 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1558 spanXY[1], cellXY, finalSpan);
1559 spanXY[0] = finalSpan[0];
1560 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001561 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001562 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001563 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001564 }
1565
Michael Jurka0280c3b2010-09-17 15:00:07 -07001566 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001567 if (appWidgetId != -1) {
1568 // Deleting an app widget ID is a void call but writes to disk before returning
1569 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001570 new AsyncTask<Void, Void, Void>() {
1571 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001572 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001573 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001574 }
Michael Jurka43467462013-11-14 12:03:58 +01001575 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001576 }
Winson Chung93eef082012-03-23 15:59:27 -07001577 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001578 return;
1579 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001580
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001581 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001582 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1583 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001584 launcherInfo.spanX = spanXY[0];
1585 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001586 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1587 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001588
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001589 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001590 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001591
1592 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001593 if (hostView == null) {
1594 // Perform actual inflation because we're live
1595 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1596 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1597 } else {
1598 // The AppWidgetHostView has already been inflated and instantiated
1599 launcherInfo.hostView = hostView;
1600 }
Romain Guycbb89e42009-06-08 15:52:54 -07001601
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001602 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001603 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001604 launcherInfo.notifyWidgetSizeChanged(this);
1605
Adam Cohendcd297f2013-06-18 13:13:40 -07001606 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001607 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001608
1609 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001610 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001611 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001612 }
Romain Guycbb89e42009-06-08 15:52:54 -07001613
Adam Cohended9f8d2010-11-03 13:25:16 -07001614 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1615 @Override
1616 public void onReceive(Context context, Intent intent) {
1617 final String action = intent.getAction();
1618 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1619 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001620 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001621 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001622
Winson Chungc100e8e2011-08-09 16:02:43 -07001623 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001624 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001625 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001626 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001627 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001628 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1629 mUserPresent = true;
1630 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001631 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1632 mModel.resetLoadedState(false, true);
1633 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1634 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1635 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1636 mModel.resetLoadedState(false, true);
1637 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1638 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1639 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001640 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1641 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1642 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001643 }
1644 }
1645 };
1646
1647 @Override
1648 public void onAttachedToWindow() {
1649 super.onAttachedToWindow();
1650
1651 // Listen for broadcasts related to user-presence
1652 final IntentFilter filter = new IntentFilter();
1653 filter.addAction(Intent.ACTION_SCREEN_OFF);
1654 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001655 // For handling managed profiles
1656 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1657 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001658 if (ENABLE_DEBUG_INTENTS) {
1659 filter.addAction(DebugIntents.DELETE_DATABASE);
1660 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1661 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001662 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001663 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001664 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001665 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001666 mVisible = true;
1667 }
1668
Adam Cohen0b395352014-06-09 22:54:36 +00001669 /**
1670 * Sets up transparent navigation and status bars in LMP.
1671 * This method is a no-op for other platform versions.
1672 */
1673 @TargetApi(19)
1674 private void setupTransparentSystemBarsForLmp() {
1675 // TODO(sansid): use the APIs directly when compiling against L sdk.
1676 // Currently we use reflection to access the flags and the API to set the transparency
1677 // on the System bars.
1678 if (Utilities.isLmp()) {
1679 try {
1680 getWindow().getAttributes().systemUiVisibility |=
1681 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1682 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1683 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1684 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1685 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1686 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1687 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1688 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1689
1690 Method setStatusBarColorMethod =
1691 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1692 Method setNavigationBarColorMethod =
1693 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1694 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1695 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1696 } catch (NoSuchFieldException e) {
1697 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1698 } catch (NoSuchMethodException ex) {
1699 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1700 } catch (IllegalAccessException e) {
1701 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1702 } catch (IllegalArgumentException e) {
1703 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1704 } catch (InvocationTargetException e) {
1705 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1706 } finally {}
1707 }
1708 }
1709
Adam Cohended9f8d2010-11-03 13:25:16 -07001710 @Override
1711 public void onDetachedFromWindow() {
1712 super.onDetachedFromWindow();
1713 mVisible = false;
1714
Adam Cohend113e0c2010-11-11 10:48:05 -08001715 if (mAttached) {
1716 unregisterReceiver(mReceiver);
1717 mAttached = false;
1718 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001719 updateRunning();
1720 }
1721
1722 public void onWindowVisibilityChanged(int visibility) {
1723 mVisible = visibility == View.VISIBLE;
1724 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001725 // The following code used to be in onResume, but it turns out onResume is called when
1726 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1727 // is a more appropriate event to handle
1728 if (mVisible) {
1729 mAppsCustomizeTabHost.onWindowVisible();
1730 if (!mWorkspaceLoading) {
1731 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001732 // We want to let Launcher draw itself at least once before we force it to build
1733 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001734 // apps is nice and speedy.
1735 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001736 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001737 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001738 if (mStarted) return;
1739 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001740 // We delay the layer building a bit in order to give
1741 // other message processing a time to run. In particular
1742 // this avoids a delay in hiding the IME if it was
1743 // currently shown, because doing that may involve
1744 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001745 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001746 final ViewTreeObserver.OnDrawListener listener = this;
1747 mWorkspace.post(new Runnable() {
1748 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001749 if (mWorkspace != null &&
1750 mWorkspace.getViewTreeObserver() != null) {
1751 mWorkspace.getViewTreeObserver().
1752 removeOnDrawListener(listener);
1753 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001754 }
1755 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001756 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001757 }
1758 });
1759 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001760 // When Launcher comes back to foreground, a different Activity might be responsible for
1761 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001762 if (!DISABLE_MARKET_BUTTON) {
1763 updateAppMarketIcon();
1764 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001765 clearTypedText();
1766 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001767 }
1768
1769 private void sendAdvanceMessage(long delay) {
1770 mHandler.removeMessages(ADVANCE_MSG);
1771 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1772 mHandler.sendMessageDelayed(msg, delay);
1773 mAutoAdvanceSentTime = System.currentTimeMillis();
1774 }
1775
1776 private void updateRunning() {
1777 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1778 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1779 mAutoAdvanceRunning = autoAdvanceRunning;
1780 if (autoAdvanceRunning) {
1781 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1782 sendAdvanceMessage(delay);
1783 } else {
1784 if (!mWidgetsToAdvance.isEmpty()) {
1785 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1786 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1787 }
1788 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001789 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001790 }
1791 }
1792 }
1793
1794 private final Handler mHandler = new Handler() {
1795 @Override
1796 public void handleMessage(Message msg) {
1797 if (msg.what == ADVANCE_MSG) {
1798 int i = 0;
1799 for (View key: mWidgetsToAdvance.keySet()) {
1800 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1801 final int delay = mAdvanceStagger * i;
1802 if (v instanceof Advanceable) {
1803 postDelayed(new Runnable() {
1804 public void run() {
1805 ((Advanceable) v).advance();
1806 }
1807 }, delay);
1808 }
1809 i++;
1810 }
1811 sendAdvanceMessage(mAdvanceInterval);
1812 }
1813 }
1814 };
1815
1816 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001817 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001818 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1819 if (v instanceof Advanceable) {
1820 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001821 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001822 updateRunning();
1823 }
1824 }
1825
1826 void removeWidgetToAutoAdvance(View hostView) {
1827 if (mWidgetsToAdvance.containsKey(hostView)) {
1828 mWidgetsToAdvance.remove(hostView);
1829 updateRunning();
1830 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001831 }
1832
Joe Onorato9c1289c2009-08-17 11:03:03 -04001833 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001834 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001835 launcherInfo.hostView = null;
1836 }
1837
Winson Chung93eef082012-03-23 15:59:27 -07001838 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1839 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1840 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001841 }
1842
Winson Chunga6945242014-01-08 14:04:34 -08001843 public DragLayer getDragLayer() {
1844 return mDragLayer;
1845 }
1846
1847 public Workspace getWorkspace() {
1848 return mWorkspace;
1849 }
1850
1851 public Hotseat getHotseat() {
1852 return mHotseat;
1853 }
1854
Jorim Jaggid017f882014-01-14 17:08:48 -08001855 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001856 return mOverviewPanel;
1857 }
1858
1859 public SearchDropTargetBar getSearchBar() {
1860 return mSearchDropTargetBar;
1861 }
1862
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001863 public LauncherAppWidgetHost getAppWidgetHost() {
1864 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001865 }
Romain Guycbb89e42009-06-08 15:52:54 -07001866
Winson Chunga9abd0e2010-10-27 17:18:37 -07001867 public LauncherModel getModel() {
1868 return mModel;
1869 }
1870
Winson Chunga6945242014-01-08 14:04:34 -08001871 public LauncherClings getLauncherClings() {
1872 return mLauncherClings;
1873 }
1874
1875 protected SharedPreferences getSharedPrefs() {
1876 return mSharedPrefs;
1877 }
1878
Bjorn Bringertc459e522013-06-07 19:36:01 +01001879 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001880 getWindow().closeAllPanels();
1881
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001882 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001883 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001884 }
1885
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001886 @Override
1887 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001888 long startTime = 0;
1889 if (DEBUG_RESUME_TIME) {
1890 startTime = System.currentTimeMillis();
1891 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001892 super.onNewIntent(intent);
1893
1894 // Close the menu
1895 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001896 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001897 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001898
Adam Cohened307df2013-10-02 09:37:31 -07001899 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1900 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1901 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001902
Adam Cohen6fecd412013-10-02 17:41:50 -07001903 if (mWorkspace == null) {
1904 // Can be cases where mWorkspace is null, this prevents a NPE
1905 return;
1906 }
1907 Folder openFolder = mWorkspace.getOpenFolder();
1908 // In all these cases, only animate if we're already on home
1909 mWorkspace.exitWidgetResizeMode();
1910 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001911 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001912 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001913 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001914
Adam Cohen6fecd412013-10-02 17:41:50 -07001915 closeFolder();
1916 exitSpringLoadedDragMode();
1917
1918 // If we are already on home, then just animate back to the workspace,
1919 // otherwise, just wait until onResume to set the state back to Workspace
1920 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001921 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001922 } else {
1923 mOnResumeState = State.WORKSPACE;
1924 }
1925
1926 final View v = getWindow().peekDecorView();
1927 if (v != null && v.getWindowToken() != null) {
1928 InputMethodManager imm = (InputMethodManager)getSystemService(
1929 INPUT_METHOD_SERVICE);
1930 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1931 }
1932
1933 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001934 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001935 mAppsCustomizeTabHost.reset();
1936 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001937
1938 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001939 }
Adam Cohened307df2013-10-02 09:37:31 -07001940
Michael Jurka447bf842013-05-15 14:52:15 +02001941 if (DEBUG_RESUME_TIME) {
1942 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1943 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001944 }
1945
Adam Coppa120b8e2013-11-12 16:26:04 +00001946 /**
1947 * Override point for subclasses to prevent movement to the default screen when the home
1948 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1949 */
1950 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1951 return true;
1952 }
1953
1954 /**
1955 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1956 */
1957 protected void onHomeIntent() {
1958 // Do nothing
1959 }
1960
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001961 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001962 public void onRestoreInstanceState(Bundle state) {
1963 super.onRestoreInstanceState(state);
1964 for (int page: mSynchronouslyBoundPages) {
1965 mWorkspace.restoreInstanceStateForChild(page);
1966 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001967 }
1968
1969 @Override
1970 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001971 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001972 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1973 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001974 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001975 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001976
Michael Jurka883f55b2010-10-21 15:47:14 -07001977 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001978 // We close any open folder since it will not be re-opened, and we need to make sure
1979 // this state is reflected.
1980 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001981
Adam Cohendcd297f2013-06-18 13:13:40 -07001982 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001983 mWaitingForResult) {
1984 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001985 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001986 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1987 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001988 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1989 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1990 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001991 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001992 }
1993
1994 if (mFolderInfo != null && mWaitingForResult) {
1995 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1996 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1997 }
Michael Jurka946ad472010-07-09 18:05:18 -07001998
Winson Chung785d2eb2011-04-14 16:08:02 -07001999 // Save the current AppsCustomize tab
2000 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08002001 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
2002 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07002003 if (currentTabTag != null) {
2004 outState.putString("apps_customize_currentTab", currentTabTag);
2005 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07002006 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
2007 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07002008 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00002009 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002010 }
2011
2012 @Override
2013 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002014 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07002015
Winson Chunge7a03942011-08-05 15:05:12 -07002016 // Remove all pending runnables
2017 mHandler.removeMessages(ADVANCE_MSG);
2018 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07002019 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002020
Winson Chungcd2b0142011-06-08 16:02:26 -07002021 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04002022 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07002023 mModel.stopLoader();
2024 app.setLauncher(null);
2025
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002026 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002027 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002028 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002029 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002030 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002031 mAppWidgetHost = null;
2032
2033 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002034
2035 TextKeyListener.getInstance().release();
2036
Winson Chung81b52252012-08-27 15:34:29 -07002037 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2038 // to prevent leaking Launcher activities on orientation change.
2039 if (mModel != null) {
2040 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2041 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002042
2043 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002044 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002045
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002046 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002047 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002048 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002049 mWorkspace = null;
2050 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002051
Sunny Goyale755d462014-07-22 13:48:29 -07002052 PackageInstallerCompat.getInstance(this).onStop();
Michael Jurka2ecf9952012-06-18 12:52:28 -07002053 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002054 }
2055
Adam Cohena9cf38f2011-05-02 15:36:58 -07002056 public DragController getDragController() {
2057 return mDragController;
2058 }
2059
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002060 @Override
2061 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002062 if (requestCode >= 0) {
2063 setWaitingForResult(true);
2064 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002065 super.startActivityForResult(intent, requestCode);
2066 }
2067
Winson Chung70d72102011-08-12 11:24:35 -07002068 /**
2069 * Indicates that we want global search for this activity by setting the globalSearch
2070 * argument for {@link #startSearch} to true.
2071 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002072 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002073 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002074 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002075
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002076 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002077
Karl Rosaen138a0412009-04-23 19:00:21 -07002078 if (initialQuery == null) {
2079 // Use any text typed in the launcher as the initial query
2080 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002081 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002082 if (appSearchData == null) {
2083 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002084 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002085 }
Winson Chungadf0c182012-08-23 14:59:07 -07002086 Rect sourceBounds = new Rect();
2087 if (mSearchDropTargetBar != null) {
2088 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2089 }
Romain Guycbb89e42009-06-08 15:52:54 -07002090
Bjorn Bringertc459e522013-06-07 19:36:01 +01002091 startSearch(initialQuery, selectInitialQuery,
2092 appSearchData, sourceBounds);
2093 }
2094
2095 public void startSearch(String initialQuery,
2096 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002097 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002098 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07002099 }
2100
2101 /**
2102 * Starts the global search activity. This code is a copied from SearchManager
2103 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002104 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002105 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002106 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002107 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2108 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2109 if (globalSearchActivity == null) {
2110 Log.w(TAG, "No global search activity found.");
2111 return;
2112 }
2113 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2114 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2115 intent.setComponent(globalSearchActivity);
2116 // Make sure that we have a Bundle to put source in
2117 if (appSearchData == null) {
2118 appSearchData = new Bundle();
2119 } else {
2120 appSearchData = new Bundle(appSearchData);
2121 }
2122 // Set source to package name of app that starts global search, if not set already.
2123 if (!appSearchData.containsKey("source")) {
2124 appSearchData.putString("source", getPackageName());
2125 }
2126 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2127 if (!TextUtils.isEmpty(initialQuery)) {
2128 intent.putExtra(SearchManager.QUERY, initialQuery);
2129 }
2130 if (selectInitialQuery) {
2131 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2132 }
2133 intent.setSourceBounds(sourceBounds);
2134 try {
2135 startActivity(intent);
2136 } catch (ActivityNotFoundException ex) {
2137 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2138 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002139 }
2140
Yura4f93ec62014-02-04 14:15:21 +00002141 public boolean isOnCustomContent() {
2142 return mWorkspace.isOnOrMovingToCustomContent();
2143 }
2144
Winson Chung70d72102011-08-12 11:24:35 -07002145 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002146 public boolean onPrepareOptionsMenu(Menu menu) {
2147 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002148 if (!isOnCustomContent()) {
2149 // Close any open folders
2150 closeFolder();
2151 // Stop resizing any widgets
2152 mWorkspace.exitWidgetResizeMode();
2153 if (!mWorkspace.isInOverviewMode()) {
2154 // Show the overview mode
2155 showOverviewMode(true);
2156 } else {
2157 showWorkspace(true);
2158 }
Winson Chunge0298742014-01-17 12:03:00 -08002159 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002160 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002161 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002162
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002163 @Override
2164 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002165 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002166 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002167 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002168 }
2169
Joe Onorato9c1289c2009-08-17 11:03:03 -04002170 public boolean isWorkspaceLocked() {
2171 return mWorkspaceLoading || mWaitingForResult;
2172 }
2173
Adam Cohen517a7f52014-03-01 12:12:59 -08002174 public boolean isWorkspaceLoading() {
2175 return mWorkspaceLoading;
2176 }
2177
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002178 private void setWorkspaceLoading(boolean value) {
2179 boolean isLocked = isWorkspaceLocked();
2180 mWorkspaceLoading = value;
2181 if (isLocked != isWorkspaceLocked()) {
2182 onWorkspaceLockedChanged();
2183 }
2184 }
2185
2186 private void setWaitingForResult(boolean value) {
2187 boolean isLocked = isWorkspaceLocked();
2188 mWaitingForResult = value;
2189 if (isLocked != isWorkspaceLocked()) {
2190 onWorkspaceLockedChanged();
2191 }
2192 }
2193
2194 protected void onWorkspaceLockedChanged() { }
2195
Michael Jurka0280c3b2010-09-17 15:00:07 -07002196 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002197 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002198 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002199 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2200 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002201 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002202 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002203 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002204
Adam Cohenad4e15c2013-10-17 16:21:35 -07002205 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2206 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2207 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2208 }
2209
2210 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2211 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2212 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002213 if (appWidgetInfo.configure != null) {
2214 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002215 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002216
Bjorn Bringert7984c942009-12-09 15:38:25 +00002217 // Launch over to configure widget, if needed
2218 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002219 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002220 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002221 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002222 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002223 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002224 Runnable onComplete = new Runnable() {
2225 @Override
2226 public void run() {
2227 // Exit spring loaded mode if necessary after adding the widget
2228 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2229 null);
2230 }
2231 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002232 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002233 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002234 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002235 }
2236 }
Romain Guycbb89e42009-06-08 15:52:54 -07002237
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002238 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002239 // Close any folders that may be open.
2240 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002241 mWorkspace.moveToCustomContentScreen(animate);
2242 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002243 /**
2244 * Process a shortcut drop.
2245 *
2246 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002247 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002248 * @param cell The cell it should be added to, optional
2249 * @param position The location on the screen where it was dropped, optional
2250 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002251 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002252 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002253 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002254 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002255 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002256 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002257
2258 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002259 mPendingAddInfo.cellX = cell[0];
2260 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002261 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002262
2263 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2264 createShortcutIntent.setComponent(componentName);
2265 processShortcut(createShortcutIntent);
2266 }
2267
Adam Cohenfbba09b2011-07-18 21:43:05 -07002268 /**
2269 * Process a widget drop.
2270 *
2271 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002272 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002273 * @param cell The cell it should be added to, optional
2274 * @param position The location on the screen where it was dropped, optional
2275 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002276 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002277 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002278 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002279 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002280 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002281 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002282 mPendingAddInfo.minSpanX = info.minSpanX;
2283 mPendingAddInfo.minSpanY = info.minSpanY;
2284
Adam Cohenfbba09b2011-07-18 21:43:05 -07002285 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002286 mPendingAddInfo.cellX = cell[0];
2287 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002288 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002289 if (span != null) {
2290 mPendingAddInfo.spanX = span[0];
2291 mPendingAddInfo.spanY = span[1];
2292 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002293
Adam Cohened66b2b2012-01-23 17:28:51 -08002294 AppWidgetHostView hostView = info.boundWidget;
2295 int appWidgetId;
2296 if (hostView != null) {
2297 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002298 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002299 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002300 // In this case, we either need to start an activity to get permission to bind
2301 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002302 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002303 Bundle options = info.bindOptions;
2304
2305 boolean success = false;
2306 if (options != null) {
2307 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2308 info.componentName, options);
2309 } else {
2310 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2311 info.componentName);
2312 }
2313 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002314 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002315 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002316 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002317 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2318 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2319 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002320 // TODO: we need to make sure that this accounts for the options bundle.
2321 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002322 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2323 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002324 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002325 }
2326
Joe Onoratodeb98af2010-02-19 14:59:39 -08002327 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002328 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002329 }
2330
Winson Chung24ab2f12010-09-16 14:10:47 -07002331 void processWallpaper(Intent intent) {
2332 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2333 }
2334
Adam Cohendcd297f2013-06-18 13:13:40 -07002335 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002336 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002337 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002338 folderInfo.title = getText(R.string.folder_name);
2339
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002340 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002341 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002342 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002343 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002344
2345 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002346 FolderIcon newFolder =
2347 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002348 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002349 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002350 // Force measure the new folder icon
2351 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2352 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002353 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002354 }
Romain Guycbb89e42009-06-08 15:52:54 -07002355
Joe Onorato9c1289c2009-08-17 11:03:03 -04002356 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002357 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002358 }
2359
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002360 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002361 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002362 }
2363
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002364 /**
2365 * Registers various content observers. The current implementation registers
2366 * only a favorites observer to keep track of the favorites applications.
2367 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002368 private void registerContentObservers() {
2369 ContentResolver resolver = getContentResolver();
2370 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2371 true, mWidgetObserver);
2372 }
2373
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002374 @Override
2375 public boolean dispatchKeyEvent(KeyEvent event) {
2376 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2377 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002378 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002379 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002380 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002381 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002382 dumpState();
2383 return true;
2384 }
2385 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002386 }
2387 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2388 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002389 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002390 return true;
2391 }
2392 }
2393
2394 return super.dispatchKeyEvent(event);
2395 }
2396
Joe Onorato88ec0992009-11-19 13:16:06 -08002397 @Override
2398 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002399 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002400 if (mAppsCustomizeContent.getContentType() ==
2401 AppsCustomizePagedView.ContentType.Applications) {
2402 showWorkspace(true);
2403 } else {
2404 showOverviewMode(true);
2405 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002406 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002407 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002408 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002409 Folder openFolder = mWorkspace.getOpenFolder();
2410 if (openFolder.isEditingName()) {
2411 openFolder.dismissEditingName();
2412 } else {
2413 closeFolder();
2414 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002415 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002416 mWorkspace.exitWidgetResizeMode();
2417
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002418 // Back button is a no-op here, but give at least some feedback for the button press
2419 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002420 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002421 }
2422
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002423 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002424 * Re-listen when widgets are reset.
2425 */
2426 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002427 if (mAppWidgetHost != null) {
2428 mAppWidgetHost.startListening();
2429 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002430 }
2431
2432 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002433 * Launches the intent referred by the clicked shortcut.
2434 *
2435 * @param v The view representing the clicked shortcut.
2436 */
2437 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002438 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2439 // view has detached (it's possible for this to happen if the view is removed mid touch).
2440 if (v.getWindowToken() == null) {
2441 return;
2442 }
2443
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002444 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002445 return;
2446 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002447
Adam Cohen1697b792013-09-17 19:08:21 -07002448 if (v instanceof Workspace) {
2449 if (mWorkspace.isInOverviewMode()) {
2450 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002451 }
2452 return;
2453 }
2454
2455 if (v instanceof CellLayout) {
2456 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002457 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002458 }
2459 }
2460
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002461 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002462 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002463 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002464 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002465 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002466 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002467 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002468 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002469 onClickAllAppsButton(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002470 } else if (tag instanceof LauncherAppWidgetInfo) {
2471 if (v instanceof PendingAppWidgetHostView) {
2472 onClickPendingWidget((PendingAppWidgetHostView) v);
2473 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002474 }
2475 }
2476
Michael Jurka0e260592010-06-30 17:07:39 -07002477 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002478 return false;
2479 }
2480
Michael Jurkaaf442092010-06-10 17:01:57 -07002481 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002482 * Event handler for the app widget view which has not fully restored.
2483 */
2484 public void onClickPendingWidget(PendingAppWidgetHostView v) {
2485 if (v.isReadyForClickSetup()) {
2486 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
2487 int widgetId = info.appWidgetId;
2488 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2489 if (appWidgetInfo != null) {
2490 mPendingAddWidgetInfo = appWidgetInfo;
2491 mPendingAddInfo.copyFrom(info);
2492 mPendingAddWidgetId = widgetId;
2493
2494 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
2495 intent.setComponent(appWidgetInfo.configure);
2496 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, info.appWidgetId);
2497 Utilities.startActivityForResultSafely(this, intent, REQUEST_RECONFIGURE_APPWIDGET);
2498 }
2499 }
2500 }
2501
2502 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002503 * Event handler for the search button
2504 *
2505 * @param v The view that was clicked.
2506 */
2507 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002508 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2509
Amith Yamasania135ba82011-08-09 17:42:01 -07002510 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002511 }
2512
2513 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002514 * Event handler for the voice button
2515 *
2516 * @param v The view that was clicked.
2517 */
2518 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002519 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002520
Bjorn Bringertc459e522013-06-07 19:36:01 +01002521 startVoice();
2522 }
2523
2524 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002525 try {
2526 final SearchManager searchManager =
2527 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2528 ComponentName activityName = searchManager.getGlobalSearchActivity();
2529 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002530 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002531 if (activityName != null) {
2532 intent.setPackage(activityName.getPackageName());
2533 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002534 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002535 } catch (ActivityNotFoundException e) {
2536 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002537 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002538 startActivitySafely(null, intent, "onClickVoiceButton");
2539 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002540 }
2541
2542 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002543 * Event handler for the "grid" button that appears on the home screen, which
2544 * enters all apps mode.
2545 *
2546 * @param v The view that was clicked.
2547 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002548 protected void onClickAllAppsButton(View v) {
2549 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2550 if (isAllAppsVisible()) {
2551 showWorkspace(true);
2552 } else {
2553 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2554 }
2555 }
2556
2557 /**
Mohammadinamul Sheik3b1a54a2014-03-18 11:28:19 -07002558 * Event handler for a paged view icon click.
2559 * @param v The view that was clicked.
2560 * @param appInfo The {link AppInfo} of the view.
2561 */
2562 public void onClickPagedViewIcon(View v, AppInfo appInfo) {
2563 if (LOGD) Log.d(TAG, "onClickPagedViewIcon");
2564 startActivitySafely(v, appInfo.intent, appInfo);
2565 getStats().recordLaunch(appInfo.intent);
2566 }
2567
2568 /**
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002569 * Event handler for an app shortcut click.
2570 *
2571 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2572 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002573 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002574 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2575 Object tag = v.getTag();
2576 if (!(tag instanceof ShortcutInfo)) {
2577 throw new IllegalArgumentException("Input must be a Shortcut");
2578 }
2579
2580 // Open shortcut
2581 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2582 final Intent intent = shortcut.intent;
2583
2584 // Check for special shortcuts
2585 if (intent.getComponent() != null) {
2586 final String shortcutClass = intent.getComponent().getClassName();
2587
2588 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2589 MemoryDumpActivity.startDump(this);
2590 return;
2591 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2592 toggleShowWeightWatcher();
2593 return;
2594 }
2595 }
2596
Chris Wren40c5ed32014-06-24 18:24:23 -04002597 // Check for abandoned promise
2598 if (shortcut.isAbandoned() && v instanceof BubbleTextView) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002599 AlertDialog.Builder builder = new AlertDialog.Builder(this);
2600 builder.setTitle(R.string.abandoned_promises_title);
Chris Wren803a4be2014-07-01 16:52:49 -04002601 builder.setMessage(R.string.abandoned_promise_explanation);
Chris Wren40c5ed32014-06-24 18:24:23 -04002602 builder.setPositiveButton(R.string.abandoned_search,
2603 new DialogInterface.OnClickListener() {
2604 public void onClick(DialogInterface dialog, int id) {
2605 startAppShortcutActivity(v);
2606 }
2607 }
2608 );
Chris Wren40c5ed32014-06-24 18:24:23 -04002609 builder.setNeutralButton(R.string.abandoned_clean_this,
2610 new DialogInterface.OnClickListener() {
2611 public void onClick(DialogInterface dialog, int id) {
2612 final BubbleTextView bubble = (BubbleTextView) v;
2613 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2614 mWorkspace.removeAbandonedPromise(bubble, user);
2615 }
2616 });
2617 builder.create().show();
2618 return;
2619 }
2620
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002621 // Start activities
Chris Wren40c5ed32014-06-24 18:24:23 -04002622 startAppShortcutActivity(v);
2623 }
2624
2625 private void startAppShortcutActivity(View v) {
2626 Object tag = v.getTag();
2627 if (!(tag instanceof ShortcutInfo)) {
2628 throw new IllegalArgumentException("Input must be a Shortcut");
2629 }
2630 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2631 final Intent intent = shortcut.intent;
2632
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002633 int[] pos = new int[2];
2634 v.getLocationOnScreen(pos);
2635 intent.setSourceBounds(new Rect(pos[0], pos[1],
2636 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2637
2638 boolean success = startActivitySafely(v, intent, tag);
2639
2640 mStats.recordLaunch(intent, shortcut);
2641
2642 if (success && v instanceof BubbleTextView) {
2643 mWaitingForResume = (BubbleTextView) v;
2644 mWaitingForResume.setStayPressed(true);
2645 }
2646 }
2647
2648 /**
2649 * Event handler for a folder icon click.
2650 *
2651 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2652 */
2653 protected void onClickFolderIcon(View v) {
2654 if (LOGD) Log.d(TAG, "onClickFolder");
2655 if (!(v instanceof FolderIcon)){
2656 throw new IllegalArgumentException("Input must be a FolderIcon");
2657 }
2658
2659 FolderIcon folderIcon = (FolderIcon) v;
2660 final FolderInfo info = folderIcon.getFolderInfo();
2661 Folder openFolder = mWorkspace.getFolderForTag(info);
2662
2663 // If the folder info reports that the associated folder is open, then verify that
2664 // it is actually opened. There have been a few instances where this gets out of sync.
2665 if (info.opened && openFolder == null) {
2666 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2667 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2668 info.opened = false;
2669 }
2670
2671 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2672 // Close any open folder
2673 closeFolder();
2674 // Open the requested folder
2675 openFolder(folderIcon);
2676 } else {
2677 // Find the open folder...
2678 int folderScreen;
2679 if (openFolder != null) {
2680 folderScreen = mWorkspace.getPageForView(openFolder);
2681 // .. and close it
2682 closeFolder(openFolder);
2683 if (folderScreen != mWorkspace.getCurrentPage()) {
2684 // Close any folder open on the current screen
2685 closeFolder();
2686 // Pull the folder onto this screen
2687 openFolder(folderIcon);
2688 }
2689 }
2690 }
Michael Jurka5130e402011-10-13 04:55:35 -07002691 }
2692
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002693 /**
2694 * Event handler for the (Add) Widgets button that appears after a long press
2695 * on the home screen.
2696 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002697 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002698 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002699 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2700 }
2701
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002702 /**
2703 * Event handler for the wallpaper picker button that appears after a long press
2704 * on the home screen.
2705 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002706 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002707 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2708 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2709 pickWallpaper.setComponent(getWallpaperPickerComponent());
2710 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2711 }
2712
2713 /**
2714 * Event handler for a click on the settings button that appears after a long press
2715 * on the home screen.
2716 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002717 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002718 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2719 }
2720
Michael Jurka5130e402011-10-13 04:55:35 -07002721 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002722 // Provide the same haptic feedback that the system offers for virtual keys.
2723 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002724 }
2725
Adam Cohen61f560d2013-09-30 15:58:20 -07002726 public void performHapticFeedbackOnTouchDown(View v) {
2727 // Provide the same haptic feedback that the system offers for virtual keys.
2728 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2729 }
2730
2731 public View.OnTouchListener getHapticFeedbackTouchListener() {
2732 if (mHapticFeedbackTouchListener == null) {
2733 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2734 @Override
2735 public boolean onTouch(View v, MotionEvent event) {
2736 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2737 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2738 }
2739 return false;
2740 }
2741 };
2742 }
2743 return mHapticFeedbackTouchListener;
2744 }
2745
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002746 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002747 if (!DISABLE_MARKET_BUTTON) {
2748 if (mAppMarketIntent != null) {
2749 startActivitySafely(v, mAppMarketIntent, "app market");
2750 } else {
2751 Log.e(TAG, "Invalid app market intent.");
2752 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002753 }
2754 }
2755
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002756 public void onDragStarted(View view) {}
2757
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002758 /**
2759 * Called when the user stops interacting with the launcher.
2760 * This implies that the user is now on the homescreen and is not doing housekeeping.
2761 */
2762 protected void onInteractionEnd() {}
2763
2764 /**
2765 * Called when the user starts interacting with the launcher.
2766 * The possible interactions are:
2767 * - open all apps
2768 * - reorder an app shortcut, or a widget
2769 * - open the overview mode.
2770 * This is a good time to stop doing things that only make sense
2771 * when the user is on the homescreen and not doing housekeeping.
2772 */
2773 protected void onInteractionBegin() {}
2774
Kenny Guyf07af7b2014-07-31 11:39:16 +01002775 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002776 String packageName = componentName.getPackageName();
Kenny Guyf07af7b2014-07-31 11:39:16 +01002777 try {
2778 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2779 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2780 launcherApps.showAppDetailsForProfile(componentName, user);
2781 } catch (SecurityException e) {
2782 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2783 Log.e(TAG, "Launcher does not have permission to launch settings");
2784 } catch (ActivityNotFoundException e) {
2785 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2786 Log.e(TAG, "Unable to launch settings");
2787 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002788 }
2789
Michael Jurka1e2f4652013-07-08 18:03:46 -07002790 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002791 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2792 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002793 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002794 // System applications cannot be installed. For now, show a toast explaining that.
2795 // We may give them the option of disabling apps this way.
2796 int messageId = R.string.uninstall_system_app_text;
2797 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002798 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002799 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002800 String packageName = componentName.getPackageName();
2801 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002802 Intent intent = new Intent(
2803 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002804 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2805 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002806 if (user != null) {
2807 user.addToIntent(intent, Intent.EXTRA_USER);
2808 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002809 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002810 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002811 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002812 }
2813
Michael Jurka86a720e2012-05-09 11:23:23 -07002814 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002815 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002816 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002817 // Only launch using the new animation if the shortcut has not opted out (this is a
2818 // private contract between launcher and may be ignored in the future).
2819 boolean useLaunchAnimation = (v != null) &&
2820 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002821 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2822 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002823
Kenny Guy1317e2d2014-05-08 18:52:50 +01002824 UserHandleCompat user = null;
2825 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2826 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2827 user = userManager.getUserForSerialNumber(serialNumber);
2828 }
2829
2830 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002831 if (useLaunchAnimation) {
Adam Cohen4da294d2014-07-28 10:56:19 -07002832 ActivityOptions opts = Utilities.isLmp() ?
2833 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) :
2834 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Adam Cohen6ea3b112014-06-11 11:38:49 -07002835 optsBundle = opts.toBundle();
2836 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002837
2838 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2839 // Could be launching some bookkeeping activity
2840 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002841 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002842 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002843 launcherApps.startActivityForProfile(intent.getComponent(), user,
2844 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002845 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002846 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002847 } catch (SecurityException e) {
2848 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002849 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002850 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002851 "or use the exported attribute for this activity. "
2852 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002853 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002854 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002855 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002856
Michael Jurka86a720e2012-05-09 11:23:23 -07002857 boolean startActivitySafely(View v, Intent intent, Object tag) {
2858 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002859 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2860 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2861 return false;
2862 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002863 try {
2864 success = startActivity(v, intent, tag);
2865 } catch (ActivityNotFoundException e) {
2866 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2867 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2868 }
2869 return success;
2870 }
2871
Adam Cohen268c4752012-06-06 17:47:33 -07002872 /**
2873 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2874 * in the DragLayer in the exact absolute location of the original FolderIcon.
2875 */
2876 private void copyFolderIconToImage(FolderIcon fi) {
2877 final int width = fi.getMeasuredWidth();
2878 final int height = fi.getMeasuredHeight();
2879
2880 // Lazy load ImageView, Bitmap and Canvas
2881 if (mFolderIconImageView == null) {
2882 mFolderIconImageView = new ImageView(this);
2883 }
2884 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2885 mFolderIconBitmap.getHeight() != height) {
2886 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2887 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2888 }
2889
2890 DragLayer.LayoutParams lp;
2891 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2892 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2893 } else {
2894 lp = new DragLayer.LayoutParams(width, height);
2895 }
2896
Adam Cohen307fe232012-08-16 17:55:58 -07002897 // The layout from which the folder is being opened may be scaled, adjust the starting
2898 // view size by this scale factor.
2899 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002900 lp.customPosition = true;
2901 lp.x = mRectForFolderAnimation.left;
2902 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002903 lp.width = (int) (scale * width);
2904 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002905
2906 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2907 fi.draw(mFolderIconCanvas);
2908 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002909 if (fi.getFolder() != null) {
2910 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2911 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002912 }
Adam Cohen268c4752012-06-06 17:47:33 -07002913 // Just in case this image view is still in the drag layer from a previous animation,
2914 // we remove it and re-add it.
2915 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2916 mDragLayer.removeView(mFolderIconImageView);
2917 }
2918 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002919 if (fi.getFolder() != null) {
2920 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002921 }
Adam Cohen268c4752012-06-06 17:47:33 -07002922 }
2923
Adam Cohen2801caf2011-05-13 20:57:39 -07002924 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002925 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002926 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2927 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2928 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2929
Adam Cohenc51934b2011-07-26 21:07:43 -07002930 FolderInfo info = (FolderInfo) fi.getTag();
2931 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2932 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002933 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2934 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002935 }
2936
Adam Cohen268c4752012-06-06 17:47:33 -07002937 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2938 copyFolderIconToImage(fi);
2939 fi.setVisibility(View.INVISIBLE);
2940
Michael Jurka2ecf9952012-06-18 12:52:28 -07002941 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002942 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002943 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2944 oa.start();
2945 }
2946
Adam Cohen268c4752012-06-06 17:47:33 -07002947 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002948 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002949 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2950 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2951 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2952
Adam Cohen268c4752012-06-06 17:47:33 -07002953 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002954
Adam Cohen268c4752012-06-06 17:47:33 -07002955 // We remove and re-draw the FolderIcon in-case it has changed
2956 mDragLayer.removeView(mFolderIconImageView);
2957 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002958 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002959 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002960 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002961 oa.addListener(new AnimatorListenerAdapter() {
2962 @Override
2963 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002964 if (cl != null) {
2965 cl.clearFolderLeaveBehind();
2966 // Remove the ImageView copy of the FolderIcon and make the original visible.
2967 mDragLayer.removeView(mFolderIconImageView);
2968 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002969 }
2970 }
2971 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002972 oa.start();
2973 }
2974
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002975 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002976 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002977 * is animated relative to the specified View. If the View is null, no animation
2978 * is played.
2979 *
2980 * @param folderInfo The FolderInfo describing the folder to open.
2981 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002982 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002983 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002984 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002985
Adam Cohena9cf38f2011-05-02 15:36:58 -07002986 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002987
Adam Cohen4554ee12011-08-03 16:13:21 -07002988 // Just verify that the folder hasn't already been added to the DragLayer.
2989 // There was a one-off crash where the folder had a parent already.
2990 if (folder.getParent() == null) {
2991 mDragLayer.addView(folder);
2992 mDragController.addDropTarget((DropTarget) folder);
2993 } else {
2994 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2995 folder.getParent() + ").");
2996 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002997 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002998 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002999
3000 // Notify the accessibility manager that this folder "window" has appeared and occluded
3001 // the workspace items
3002 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3003 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003004 }
3005
3006 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08003007 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003008 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003009 if (folder.isEditingName()) {
3010 folder.dismissEditingName();
3011 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003012 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07003013
3014 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08003015 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07003016 }
3017 }
3018
3019 void closeFolder(Folder folder) {
3020 folder.getInfo().opened = false;
3021
3022 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3023 if (parent != null) {
3024 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3025 shrinkAndFadeInFolderIcon(fi);
3026 }
3027 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003028
3029 // Notify the accessibility manager that this folder "window" has disappeard and no
3030 // longer occludeds the workspace items
3031 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003032 }
3033
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003034 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003035 if (!isDraggingEnabled()) return false;
3036 if (isWorkspaceLocked()) return false;
3037 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003038
Adam Cohen1697b792013-09-17 19:08:21 -07003039 if (v instanceof Workspace) {
3040 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07003041 if (mWorkspace.enterOverviewMode()) {
3042 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3043 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3044 return true;
3045 } else {
3046 return false;
3047 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003048 } else {
3049 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003050 }
Adam Cohen1697b792013-09-17 19:08:21 -07003051 }
3052
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003053 CellLayout.CellInfo longClickCellInfo = null;
3054 View itemUnderLongClick = null;
3055 if (v.getTag() instanceof ItemInfo) {
3056 ItemInfo info = (ItemInfo) v.getTag();
3057 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3058 itemUnderLongClick = longClickCellInfo.cell;
3059 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003060 }
3061
Winson Chung3d503fb2011-07-13 17:25:49 -07003062 // The hotseat touch handling does not go through Workspace, and we always allow long press
3063 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003064 final boolean inHotseat = isHotseatLayout(v);
3065 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07003066 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003067 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003068 // User long pressed on empty space
3069 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3070 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003071 if (mWorkspace.isInOverviewMode()) {
3072 mWorkspace.startReordering(v);
3073 } else {
3074 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07003075 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003076 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003077 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3078 mHotseat.getOrderInHotseat(
3079 longClickCellInfo.cellX,
3080 longClickCellInfo.cellY));
3081 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003082 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003083 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003084 }
3085 }
3086 }
3087 return true;
3088 }
3089
Winson Chung3d503fb2011-07-13 17:25:49 -07003090 boolean isHotseatLayout(View layout) {
3091 return mHotseat != null && layout != null &&
3092 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3093 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003094
Winson Chung3d503fb2011-07-13 17:25:49 -07003095 /**
3096 * Returns the CellLayout of the specified container at the specified screen.
3097 */
Adam Cohendcd297f2013-06-18 13:13:40 -07003098 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003099 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3100 if (mHotseat != null) {
3101 return mHotseat.getLayout();
3102 } else {
3103 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003104 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003105 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07003106 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003107 }
3108 }
3109
Daniel Sandler843e8602010-06-07 14:59:01 -04003110 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003111 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003112 }
3113
Craig Mautner360310b2012-10-26 15:13:08 -07003114 private void setWorkspaceBackground(boolean workspace) {
3115 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003116 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003117 }
3118
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003119 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003120 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3121 int curflags = getWindow().getAttributes().flags
3122 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3123 if (wpflags != curflags) {
3124 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3125 }
Craig Mautner360310b2012-10-26 15:13:08 -07003126 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003127 }
3128
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003129 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3130 if (v instanceof LauncherTransitionable) {
3131 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3132 }
3133 }
3134
Michael Jurkabed61d22012-02-14 22:51:29 -08003135 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3136 if (v instanceof LauncherTransitionable) {
3137 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3138 }
Winson Chung70442722012-02-10 15:43:22 -08003139
3140 // Update the workspace transition step as well
3141 dispatchOnLauncherTransitionStep(v, 0f);
3142 }
3143
3144 private void dispatchOnLauncherTransitionStep(View v, float t) {
3145 if (v instanceof LauncherTransitionable) {
3146 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3147 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003148 }
3149
3150 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3151 if (v instanceof LauncherTransitionable) {
3152 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3153 }
Winson Chung70442722012-02-10 15:43:22 -08003154
3155 // Update the workspace transition step as well
3156 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003157 }
3158
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003159 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003160 * Things to test when changing the following seven functions.
3161 * - Home from workspace
3162 * - from center screen
3163 * - from other screens
3164 * - Home from all apps
3165 * - from center screen
3166 * - from other screens
3167 * - Back from all apps
3168 * - from center screen
3169 * - from other screens
3170 * - Launch app from workspace and quit
3171 * - with back
3172 * - with home
3173 * - Launch app from all apps and quit
3174 * - with back
3175 * - with home
3176 * - Go to a screen that's not the default, then all
3177 * apps, and launch and app, and go back
3178 * - with back
3179 * -with home
3180 * - On workspace, long press power and go back
3181 * - with back
3182 * - with home
3183 * - On all apps, long press power and go back
3184 * - with back
3185 * - with home
3186 * - On workspace, power off
3187 * - On all apps, power off
3188 * - Launch an app and turn off the screen while in that app
3189 * - Go back with home key
3190 * - Go back with back key TODO: make this not go to workspace
3191 * - From all apps
3192 * - From workspace
3193 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3194 * - From all apps
3195 * - From the center workspace
3196 * - From another workspace
3197 */
3198
3199 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003200 * Zoom the camera out from the workspace to reveal 'toView'.
3201 * Assumes that the view to show is anchored at either the very top or very bottom
3202 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003203 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003204 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003205 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3206 showAppsCustomizeHelper(animated, springLoaded, contentType);
3207 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003208
Winson Chungc58497e2013-09-03 17:48:37 -07003209 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3210 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003211 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003212 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003213 mStateAnimation.cancel();
3214 mStateAnimation = null;
3215 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003216
3217 boolean material = Utilities.isLmp();
3218
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003219 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003220
Winson Chungf0ea4d32011-06-06 14:27:16 -07003221 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3222 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003223 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003224 final int itemsAlphaStagger =
3225 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003226
Winson Chungf0ea4d32011-06-06 14:27:16 -07003227 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003228 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003229 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07003230 final int startDelay =
3231 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07003232
Adam Cohen6c5891a2014-07-09 23:53:15 -07003233 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3234 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003235 Animator workspaceAnim =
Adam Cohen6c5891a2014-07-09 23:53:15 -07003236 mWorkspace.getChangeStateAnimation(workspaceState, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003237 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003238 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3239 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003240 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3241 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003242
3243 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003244 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen61033d32010-11-15 18:29:44 -08003245
Adam Cohen9bfdb762014-07-21 17:44:06 -07003246 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3247 toView.findViewById(R.id.apps_customize_pane_content);
Adam Cohenf16e5712011-01-13 13:31:45 -08003248
Adam Cohen9bfdb762014-07-21 17:44:06 -07003249 final View page = content.getPageAt(content.getCurrentPage());
3250 final View revealView = toView.findViewById(R.id.fake_page);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003251
Adam Cohen4e243a22014-08-10 18:30:55 -07003252 if (contentType == AppsCustomizePagedView.ContentType.Widgets) {
3253 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3254 } else {
3255 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3256 }
3257
Adam Cohen9bfdb762014-07-21 17:44:06 -07003258 // Hide the real page background, and swap in the fake one
3259 revealView.setVisibility(View.VISIBLE);
3260 content.setPageBackgroundsVisible(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003261
Adam Cohen9bfdb762014-07-21 17:44:06 -07003262 int width = revealView.getMeasuredWidth();
3263 int height = revealView.getMeasuredHeight();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003264
Adam Cohen9bfdb762014-07-21 17:44:06 -07003265 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
3266 float yDrift = height / 2f;
Adam Cohen6c5891a2014-07-09 23:53:15 -07003267
Adam Cohen9bfdb762014-07-21 17:44:06 -07003268 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3269 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", 0.4f, 1f);
3270 PropertyValuesHolder panelDrift =
3271 PropertyValuesHolder.ofFloat("translationY", yDrift, 0f);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003272
Adam Cohen9bfdb762014-07-21 17:44:06 -07003273 ObjectAnimator panelAlphaAndDrift =
3274 ObjectAnimator.ofPropertyValuesHolder(revealView, panelAlpha, panelDrift);
3275 panelAlphaAndDrift.setDuration(revealDuration);
3276 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003277
Adam Cohen9bfdb762014-07-21 17:44:06 -07003278 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003279
Adam Cohen4e243a22014-08-10 18:30:55 -07003280 if (page != null) {
3281 page.setVisibility(View.VISIBLE);
3282 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003283
Adam Cohen4e243a22014-08-10 18:30:55 -07003284 ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0);
3285 pageDrift.setDuration(revealDuration);
3286 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3287 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003288
Adam Cohen4e243a22014-08-10 18:30:55 -07003289 // TODO (adamcohen): remove this 0.01f hack once fw is fixed
3290 // it's there to work around a framework bug (16918357)
3291 page.setAlpha(0.01f);
3292 ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0.01f, 1f);
3293 itemsAlpha.setDuration(revealDuration);
3294 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3295 itemsAlpha.setStartDelay(itemsAlphaStagger);
3296 mStateAnimation.play(itemsAlpha);
3297 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003298
Adam Cohen4e243a22014-08-10 18:30:55 -07003299 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3300 pageIndicators.setAlpha(0.01f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003301 ObjectAnimator indicatorsAlpha =
3302 ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f);
3303 indicatorsAlpha.setDuration(revealDuration);
3304 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003305
Adam Cohen9bfdb762014-07-21 17:44:06 -07003306 if (material) {
3307 ValueAnimator reveal = (ValueAnimator)
Adam Cohen6c5891a2014-07-09 23:53:15 -07003308 ViewAnimationUtils.createCircularReveal(revealView, width / 2,
Adam Cohen9bfdb762014-07-21 17:44:06 -07003309 height / 2, 0f, revealRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003310 reveal.setDuration(revealDuration);
3311 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003312 mStateAnimation.play(reveal);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003313 }
Michael Jurka1899a362011-11-03 13:50:45 -07003314
Adam Cohen9bfdb762014-07-21 17:44:06 -07003315 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3316 @Override
3317 public void onAnimationEnd(Animator animation) {
3318 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3319 dispatchOnLauncherTransitionEnd(toView, animated, false);
3320
3321 revealView.setVisibility(View.INVISIBLE);
3322 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003323 if (page != null) {
3324 page.setLayerType(View.LAYER_TYPE_NONE, null);
3325 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003326 content.setPageBackgroundsVisible(true);
3327
3328 // Hide the search bar
3329 if (mSearchDropTargetBar != null) {
3330 mSearchDropTargetBar.hideSearchBar(false);
3331 }
3332 }
3333
3334 @Override
3335 public void onAnimationStart(Animator animation) {
3336 // Prepare the position
3337 toView.bringToFront();
3338 toView.setVisibility(View.VISIBLE);
3339 }
3340 });
3341
Michael Jurka1899a362011-11-03 13:50:45 -07003342 boolean delayAnim = false;
Adam Cohen6c5891a2014-07-09 23:53:15 -07003343 if (workspaceAnim != null) {
3344 mStateAnimation.play(workspaceAnim);
3345 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003346 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3347 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003348
3349 // If any of the objects being animated haven't been measured/laid out
3350 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003351 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003352 (mWorkspace.getMeasuredWidth() == 0) ||
3353 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003354 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003355 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003356
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003357 final AnimatorSet stateAnimation = mStateAnimation;
3358 final Runnable startAnimRunnable = new Runnable() {
3359 public void run() {
3360 // Check that mStateAnimation hasn't changed while
3361 // we waited for a layout/draw pass
3362 if (mStateAnimation != stateAnimation)
3363 return;
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003364 dispatchOnLauncherTransitionStart(fromView, animated, false);
3365 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003366 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003367 }
3368 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003369 if (delayAnim) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003370 toView.bringToFront();
3371 toView.setVisibility(View.VISIBLE);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003372 final ViewTreeObserver observer = toView.getViewTreeObserver();
3373 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3374 public void onGlobalLayout() {
3375 startAnimRunnable.run();
3376 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3377 }
3378 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003379 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003380 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003381 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003382 } else {
3383 toView.setTranslationX(0.0f);
3384 toView.setTranslationY(0.0f);
3385 toView.setScaleX(1.0f);
3386 toView.setScaleY(1.0f);
3387 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003388 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003389
Daniel Sandlere4f98912013-06-25 15:13:26 -04003390 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003391 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003392 if (mSearchDropTargetBar != null) {
3393 mSearchDropTargetBar.hideSearchBar(false);
3394 }
Michael Jurkaabded662011-03-04 12:06:57 -08003395 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003396 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003397 dispatchOnLauncherTransitionStart(fromView, animated, false);
3398 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003399 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003400 dispatchOnLauncherTransitionStart(toView, animated, false);
3401 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003402 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003403 }
3404
3405 /**
3406 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003407 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003408 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003409 */
Adam Cohened307df2013-10-02 09:37:31 -07003410 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003411 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003412
Michael Jurkab3e22d92011-10-31 15:58:33 -07003413 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003414 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003415 mStateAnimation.cancel();
3416 mStateAnimation = null;
3417 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003418
3419 boolean material = Utilities.isLmp();
3420
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003421 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003422
Winson Chungf0ea4d32011-06-06 14:27:16 -07003423 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003424 final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
3425 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003426 final int itemsAlphaStagger =
3427 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003428
Winson Chungf0ea4d32011-06-06 14:27:16 -07003429 final float scaleFactor = (float)
3430 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3431 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003432 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003433 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003434 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003435 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
3436 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003437 toState, animated, stagger, -1);
3438 } else if (toState == Workspace.State.SPRING_LOADED ||
3439 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003440 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003441 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003442 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003443
Winson Chung4afe9b32011-07-27 17:46:20 -07003444 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003445 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003446 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka159b4cc2012-01-17 03:00:35 -08003447
Adam Cohen9bfdb762014-07-21 17:44:06 -07003448 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3449 fromView.findViewById(R.id.apps_customize_pane_content);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003450
Adam Cohen9bfdb762014-07-21 17:44:06 -07003451 final View page = content.getPageAt(content.getNextPage());
3452 final View revealView = fromView.findViewById(R.id.fake_page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003453
Adam Cohen4e243a22014-08-10 18:30:55 -07003454 AppsCustomizePagedView.ContentType contentType = content.getContentType();
3455 if (contentType == AppsCustomizePagedView.ContentType.Widgets) {
3456 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3457 } else {
3458 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3459 }
3460
Adam Cohen9bfdb762014-07-21 17:44:06 -07003461 int width = revealView.getMeasuredWidth();
3462 int height = revealView.getMeasuredHeight();
3463 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003464
Adam Cohen9bfdb762014-07-21 17:44:06 -07003465 // Hide the real page background, and swap in the fake one
3466 revealView.setVisibility(View.VISIBLE);
3467 content.setPageBackgroundsVisible(false);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003468
Adam Cohen9bfdb762014-07-21 17:44:06 -07003469 float yDrift = height / 2f;
Adam Cohen6c5891a2014-07-09 23:53:15 -07003470
Adam Cohen9bfdb762014-07-21 17:44:06 -07003471 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003472
Adam Cohen9bfdb762014-07-21 17:44:06 -07003473 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat(View.ALPHA, 1f, 0f);
3474 PropertyValuesHolder panelDrift =
Adam Cohen4e243a22014-08-10 18:30:55 -07003475 PropertyValuesHolder.ofFloat("translationY", 0, yDrift);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003476 ObjectAnimator panelAlphaAndDrift =
3477 ObjectAnimator.ofPropertyValuesHolder(revealView, panelAlpha, panelDrift);
3478 panelAlphaAndDrift.setDuration(revealDuration);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003479
Adam Cohen9bfdb762014-07-21 17:44:06 -07003480 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3481 panelAlphaAndDrift.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003482
Adam Cohen9bfdb762014-07-21 17:44:06 -07003483 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003484
Adam Cohen4e243a22014-08-10 18:30:55 -07003485 if (page != null) {
3486 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003487
Adam Cohen4e243a22014-08-10 18:30:55 -07003488 ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", 0, yDrift);
3489 pageDrift.setDuration(revealDuration);
3490 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3491 pageDrift.setStartDelay(itemsAlphaStagger);
3492 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003493
Adam Cohen4e243a22014-08-10 18:30:55 -07003494 page.setAlpha(1f);
3495 ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, View.ALPHA, 1f, 0f);
3496 itemsAlpha.setDuration(revealDuration);
3497 itemsAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0));
3498 mStateAnimation.play(itemsAlpha);
3499 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003500
Adam Cohen9bfdb762014-07-21 17:44:06 -07003501 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
Adam Cohen4e243a22014-08-10 18:30:55 -07003502 pageIndicators.setAlpha(1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003503 ObjectAnimator indicatorsAlpha =
Adam Cohen4e243a22014-08-10 18:30:55 -07003504 ObjectAnimator.ofFloat(pageIndicators, "alpha", 0f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003505 indicatorsAlpha.setDuration(revealDuration);
3506 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3507 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003508
Adam Cohen9bfdb762014-07-21 17:44:06 -07003509 width = revealView.getMeasuredWidth();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003510
Adam Cohen9bfdb762014-07-21 17:44:06 -07003511 if (material) {
Nilesh Agrawal300c1502014-07-22 13:20:54 -07003512 Animator reveal =
Adam Cohen6c5891a2014-07-09 23:53:15 -07003513 ViewAnimationUtils.createCircularReveal(revealView, width / 2,
3514 height / 2 + 100, revealRadius, 0f);
3515 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3516 reveal.setDuration(revealDuration);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003517 reveal.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003518
3519 reveal.addListener(new AnimatorListenerAdapter() {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003520 public void onAnimationEnd(Animator animation) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003521 revealView.setVisibility(View.INVISIBLE);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003522 }
3523 });
3524
Adam Cohen6c5891a2014-07-09 23:53:15 -07003525 mStateAnimation.play(reveal);
3526 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003527
3528 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3529 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3530 mAppsCustomizeContent.stopScrolling();
3531
Adam Cohen6c5891a2014-07-09 23:53:15 -07003532 if (workspaceAnim != null) {
3533 mStateAnimation.play(workspaceAnim);
3534 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003535
3536 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003537 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003538 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003539 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003540 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3541 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003542 if (onCompleteRunnable != null) {
3543 onCompleteRunnable.run();
3544 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003545
3546 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003547 if (page != null) {
3548 page.setLayerType(View.LAYER_TYPE_NONE, null);
3549 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003550 content.setPageBackgroundsVisible(true);
Chet Haasebc2f0822012-10-26 17:59:53 -07003551 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003552 }
3553 });
3554
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003555 dispatchOnLauncherTransitionStart(fromView, animated, true);
3556 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003557 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003558 } else {
3559 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003560 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003561 dispatchOnLauncherTransitionStart(fromView, animated, true);
3562 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003563 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003564 dispatchOnLauncherTransitionStart(toView, animated, true);
3565 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003566 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003567 }
3568
Michael Jurkae326f182011-11-21 14:05:46 -08003569 @Override
3570 public void onTrimMemory(int level) {
3571 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003572 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003573 mAppsCustomizeTabHost.onTrimMemory();
3574 }
3575 }
3576
Adam Cohened307df2013-10-02 09:37:31 -07003577 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003578 showWorkspace(animated, null);
3579 }
3580
Adam Cohened307df2013-10-02 09:37:31 -07003581 protected void showWorkspace() {
3582 showWorkspace(true);
3583 }
3584
Adam Cohened66b2b2012-01-23 17:28:51 -08003585 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohene25c5d12014-06-18 10:34:58 -07003586 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
Winson Chung2d75f122013-09-23 16:53:31 -07003587 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003588 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003589 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003590
Winson Chungc7d2b602012-05-16 17:02:20 -07003591 // Show the search bar (only animate if we were showing the drop target bar in spring
3592 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003593 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003594 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003595 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003596
Michael Jurkab3e22d92011-10-31 15:58:33 -07003597 // Set focus to the AppsCustomize button
3598 if (mAllAppsButton != null) {
3599 mAllAppsButton.requestFocus();
3600 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003601 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003602
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003603 // Change the state *after* we've called all the transition code
3604 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003605
Winson Chung5fb63472011-02-02 17:03:37 -08003606 // Resume the auto-advance of widgets
3607 mUserPresent = true;
3608 updateRunning();
3609
alanv1d4fde62012-10-17 13:15:47 -07003610 // Send an accessibility event to announce the context change
3611 getWindow().getDecorView()
3612 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003613
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003614 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003615 }
3616
Adam Cohened307df2013-10-02 09:37:31 -07003617 void showOverviewMode(boolean animated) {
3618 mWorkspace.setVisibility(View.VISIBLE);
3619 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3620 mState = State.WORKSPACE;
3621 onWorkspaceShown(animated);
3622 }
3623
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003624 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003625 }
3626
Winson Chung82963d52013-10-09 11:20:57 -07003627 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3628 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003629 if (mState != State.WORKSPACE) return;
3630
Winson Chung82963d52013-10-09 11:20:57 -07003631 if (resetPageToZero) {
3632 mAppsCustomizeTabHost.reset();
3633 }
Winson Chungc58497e2013-09-03 17:48:37 -07003634 showAppsCustomizeHelper(animated, false, contentType);
Adam Cohendcc5e712014-06-23 15:38:55 -04003635 mAppsCustomizeTabHost.post(new Runnable() {
3636 @Override
3637 public void run() {
3638 // We post this in-case the all apps view isn't yet constructed.
3639 mAppsCustomizeTabHost.requestFocus();
3640 }
3641 });
Michael Jurkab3e22d92011-10-31 15:58:33 -07003642
Michael Jurkab3e22d92011-10-31 15:58:33 -07003643 // Change the state *after* we've called all the transition code
3644 mState = State.APPS_CUSTOMIZE;
3645
3646 // Pause the auto-advance of widgets until we are out of AllApps
3647 mUserPresent = false;
3648 updateRunning();
3649 closeFolder();
3650
3651 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003652 getWindow().getDecorView()
3653 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003654 }
3655
Adam Cohen7777d962011-08-18 18:58:38 -07003656 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003657 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003658 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003659 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003660 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003661 }
Adam Cohen7777d962011-08-18 18:58:38 -07003662
Adam Cohenad4e15c2013-10-17 16:21:35 -07003663 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003664 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003665 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3666
Winson Chunge7a03942011-08-05 15:05:12 -07003667 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003668 @Override
3669 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003670 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003671 // Before we show workspace, hide all apps again because
3672 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3673 // clean up our state transition functions
3674 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003675 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003676 } else {
3677 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003678 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003679 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003680 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003681 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003682
Michael Jurkad3ef3062010-11-23 16:23:58 -08003683 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003684 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003685 final boolean animated = true;
3686 final boolean springLoaded = true;
3687 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003688 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003689 }
3690 // Otherwise, we are not in spring loaded mode, so don't do anything.
3691 }
3692
Michael Jurkab3e22d92011-10-31 15:58:33 -07003693 void lockAllApps() {
3694 // TODO
3695 }
3696
3697 void unlockAllApps() {
3698 // TODO
3699 }
3700
Winson Chungf0ea4d32011-06-06 14:27:16 -07003701 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003702 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003703 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003704 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003705 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003706 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003707 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003708 int duration = 0;
3709 if (mSearchDropTargetBar != null) {
3710 duration = mSearchDropTargetBar.getTransitionInDuration();
3711 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003712 mHotseat.animate().alpha(1f).setDuration(duration);
3713 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003714 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003715 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003716 }
3717 }
3718 }
3719
3720 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003721 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003722 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003723 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003724 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003725 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003726 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003727 int duration = 0;
3728 if (mSearchDropTargetBar != null) {
3729 duration = mSearchDropTargetBar.getTransitionOutDuration();
3730 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003731 mHotseat.animate().alpha(0f).setDuration(duration);
3732 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003733 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003734 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003735 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003736 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003737 }
3738
Patrick Dubroy5f445422011-02-18 14:35:21 -08003739 /**
3740 * Add an item from all apps or customize onto the given workspace screen.
3741 * If layout is null, add to the current screen.
3742 */
3743 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003744 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003745 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003746 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003747 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003748
Winson Chungdff8ebb2011-09-08 17:25:31 -07003749 /** Maps the current orientation to an index for referencing orientation correct global icons */
3750 private int getCurrentOrientationIndexForGlobalIcons() {
3751 // default - 0, landscape - 1
3752 switch (getResources().getConfiguration().orientation) {
3753 case Configuration.ORIENTATION_LANDSCAPE:
3754 return 1;
3755 default:
3756 return 0;
3757 }
3758 }
3759
Michael Jurkaae65ee32012-04-30 11:45:54 -07003760 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003761 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003762 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003763 // Look for the toolbar icon specified in the activity meta-data
3764 Bundle metaData = packageManager.getActivityInfo(
3765 activityName, PackageManager.GET_META_DATA).metaData;
3766 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003767 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003768 if (iconResId != 0) {
3769 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003770 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003771 }
3772 }
3773 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003774 // This can happen if the activity defines an invalid drawable
3775 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3776 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003777 } catch (Resources.NotFoundException nfe) {
3778 // This can happen if the activity defines an invalid drawable
3779 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3780 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003781 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003782 return null;
3783 }
3784
3785 // if successful in getting icon, return it; otherwise, set button to use default drawable
3786 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003787 int buttonId, ComponentName activityName, int fallbackDrawableId,
3788 String toolbarResourceName) {
3789 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003790 Resources r = getResources();
3791 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3792 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003793
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003794 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003795 // If we were unable to find the icon via the meta-data, use a generic one
3796 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003797 toolbarIcon = r.getDrawable(fallbackDrawableId);
3798 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003799 if (button != null) {
3800 button.setCompoundDrawables(toolbarIcon, null, null, null);
3801 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003802 return null;
3803 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003804 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003805 if (button != null) {
3806 button.setCompoundDrawables(toolbarIcon, null, null, null);
3807 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003808 return toolbarIcon.getConstantState();
3809 }
3810 }
3811
3812 // if successful in getting icon, return it; otherwise, set button to use default drawable
3813 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003814 int buttonId, ComponentName activityName, int fallbackDrawableId,
3815 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003816 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003817 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003818
Michael Jurka19e0fc52011-07-22 18:00:21 -07003819 if (button != null) {
3820 // If we were unable to find the icon via the meta-data, use a
3821 // generic one
3822 if (toolbarIcon == null) {
3823 button.setImageResource(fallbackDrawableId);
3824 } else {
3825 button.setImageDrawable(toolbarIcon);
3826 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003827 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003828
3829 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3830
Michael Jurka0423dcf2010-10-05 14:56:18 -07003831 }
3832
Winson Chung1b884092012-06-08 17:13:02 -07003833 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003834 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003835 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003836 }
3837
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003838 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003839 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003840 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003841 }
3842
Winson Chungbb185bd2011-11-21 12:31:42 -08003843 private void invalidatePressedFocusedStates(View container, View button) {
3844 if (container instanceof HolographicLinearLayout) {
3845 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3846 layout.invalidatePressedFocusedStates();
3847 } else if (button instanceof HolographicImageView) {
3848 HolographicImageView view = (HolographicImageView) button;
3849 view.invalidatePressedFocusedStates();
3850 }
3851 }
3852
Cristina Stancu476493b2013-08-07 17:20:14 +01003853 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003854 if (mQsb == null) {
3855 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3856 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003857 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003858 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003859 }
3860
3861 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003862 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003863 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003864 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003865 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003866
Winson Chung1cad91e2011-05-25 17:41:01 -07003867 final SearchManager searchManager =
3868 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3869 ComponentName activityName = searchManager.getGlobalSearchActivity();
3870 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003871 int coi = getCurrentOrientationIndexForGlobalIcons();
3872 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003873 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3874 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3875 if (sGlobalSearchIcon[coi] == null) {
3876 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3877 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3878 TOOLBAR_ICON_METADATA_NAME);
3879 }
3880
Winson Chungc51db6a2011-10-05 11:44:49 -07003881 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3882 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003883 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003884 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003885 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003886 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003887 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3888 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003889 if (searchButton != null) searchButton.setVisibility(View.GONE);
3890 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003891 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003892 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003893 }
3894 }
3895
Cristina Stancu476493b2013-08-07 17:20:14 +01003896 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003897 final View searchButtonContainer = findViewById(R.id.search_button_container);
3898 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003899 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003900 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003901 }
3902
Cristina Stancu476493b2013-08-07 17:20:14 +01003903 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003904 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003905 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003906
Winson Chungc51db6a2011-10-05 11:44:49 -07003907 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003908 final SearchManager searchManager =
3909 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3910 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3911
3912 ComponentName activityName = null;
3913 if (globalSearchActivity != null) {
3914 // Check if the global search activity handles voice search
3915 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3916 intent.setPackage(globalSearchActivity.getPackageName());
3917 activityName = intent.resolveActivity(getPackageManager());
3918 }
3919
3920 if (activityName == null) {
3921 // Fallback: check if an activity other than the global search activity
3922 // resolves this
3923 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3924 activityName = intent.resolveActivity(getPackageManager());
3925 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003926 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003927 int coi = getCurrentOrientationIndexForGlobalIcons();
3928 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003929 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3930 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3931 if (sVoiceSearchIcon[coi] == null) {
3932 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3933 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3934 TOOLBAR_ICON_METADATA_NAME);
3935 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003936 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003937 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003938 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003939 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003940 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003941 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003942 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003943 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003944 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003945 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003946 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003947 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003948
Cristina Stancu476493b2013-08-07 17:20:14 +01003949 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003950 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3951 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003952 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003953 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003954 }
3955
Winson Chung5841efa2013-09-30 18:06:44 -07003956 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003957 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3958 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003959 boolean visible = !forceDisableVoiceButtonProxy &&
3960 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003961 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003962 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003963 }
3964 }
Winson Chung5841efa2013-09-30 18:06:44 -07003965
3966 /**
3967 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3968 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3969 */
3970 public void disableVoiceButtonProxy(boolean disabled) {
3971 updateVoiceButtonProxyVisible(disabled);
3972 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003973 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003974 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003975 */
3976 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003977 if (!DISABLE_MARKET_BUTTON) {
3978 final View marketButton = findViewById(R.id.market_button);
3979 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3980 // Find the app market activity by resolving an intent.
3981 // (If multiple app markets are installed, it will return the ResolverActivity.)
3982 ComponentName activityName = intent.resolveActivity(getPackageManager());
3983 if (activityName != null) {
3984 int coi = getCurrentOrientationIndexForGlobalIcons();
3985 mAppMarketIntent = intent;
3986 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3987 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3988 TOOLBAR_ICON_METADATA_NAME);
3989 marketButton.setVisibility(View.VISIBLE);
3990 } else {
3991 // We should hide and disable the view so that we don't try and restore the visibility
3992 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3993 marketButton.setVisibility(View.GONE);
3994 marketButton.setEnabled(false);
3995 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003996 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003997 }
3998
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003999 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07004000 if (!DISABLE_MARKET_BUTTON) {
4001 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
4002 Resources r = getResources();
4003 Drawable marketIconDrawable = d.newDrawable(r);
4004 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
4005 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
4006 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07004007
Winson Chungd64a6662013-09-30 11:06:59 -07004008 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
4009 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08004010 }
4011
Michael Jurkad7c28052012-04-27 15:43:36 -07004012 @Override
4013 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07004014 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07004015 final List<CharSequence> text = event.getText();
4016 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07004017 // Populate event with a fake title based on the current state.
4018 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07004019 text.add(mAppsCustomizeTabHost.getContentTag());
alanv1d4fde62012-10-17 13:15:47 -07004020 } else {
4021 text.add(getString(R.string.all_apps_home_button_label));
4022 }
Michael Jurkad7c28052012-04-27 15:43:36 -07004023 return result;
4024 }
4025
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004026 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07004027 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004028 */
4029 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4030 @Override
4031 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004032 closeSystemDialogs();
4033 }
4034 }
4035
4036 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08004037 * Receives notifications whenever the appwidgets are reset.
4038 */
4039 private class AppWidgetResetObserver extends ContentObserver {
4040 public AppWidgetResetObserver() {
4041 super(new Handler());
4042 }
4043
4044 @Override
4045 public void onChange(boolean selfChange) {
4046 onAppWidgetReset();
4047 }
4048 }
4049
4050 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07004051 * If the activity is currently paused, signal that we need to run the passed Runnable
4052 * in onResume.
4053 *
4054 * This needs to be called from incoming places where resources might have been loaded
4055 * while we are paused. That is becaues the Configuration might be wrong
4056 * when we're not running, and if it comes back to what it was when we
4057 * were paused, we are not restarted.
4058 *
4059 * Implementation of the method from LauncherModel.Callbacks.
4060 *
4061 * @return true if we are currently paused. The caller might be able to
4062 * skip some work in that case since we will come back again.
4063 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004064 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004065 if (mPaused) {
4066 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02004067 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07004068 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004069 }
4070 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07004071 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07004072 return true;
4073 } else {
4074 return false;
4075 }
4076 }
4077
Michael Jurkac402cd92013-05-20 15:49:32 +02004078 private boolean waitUntilResume(Runnable run) {
4079 return waitUntilResume(run, false);
4080 }
4081
Michael Jurka1e2f4652013-07-08 18:03:46 -07004082 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02004083 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07004084 }
4085
Michael Jurka7607c2f2013-04-03 14:33:19 -07004086 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004087 * If the activity is currently paused, signal that we need to re-run the loader
4088 * in onResume.
4089 *
4090 * This needs to be called from incoming places where resources might have been loaded
4091 * while we are paused. That is becaues the Configuration might be wrong
4092 * when we're not running, and if it comes back to what it was when we
4093 * were paused, we are not restarted.
4094 *
4095 * Implementation of the method from LauncherModel.Callbacks.
4096 *
4097 * @return true if we are currently paused. The caller might be able to
4098 * skip some work in that case since we will come back again.
4099 */
4100 public boolean setLoadOnResume() {
4101 if (mPaused) {
4102 Log.i(TAG, "setLoadOnResume");
4103 mOnResumeNeedsLoad = true;
4104 return true;
4105 } else {
4106 return false;
4107 }
4108 }
4109
4110 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004111 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004112 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04004113 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07004114 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07004115 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07004116 } else {
4117 return SCREEN_COUNT / 2;
4118 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004119 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07004120
Joe Onorato9c1289c2009-08-17 11:03:03 -04004121 /**
4122 * Refreshes the shortcuts shown on the workspace.
4123 *
4124 * Implementation of the method from LauncherModel.Callbacks.
4125 */
4126 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004127 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08004128
Michael Jurka7607c2f2013-04-03 14:33:19 -07004129 // If we're starting binding all over again, clear any bind calls we'd postponed in
4130 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4131 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07004132 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07004133
Winson Chungd64d1762013-08-20 14:37:16 -07004134 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07004135 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07004136 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07004137
Michael Jurka05bf6442011-11-30 20:28:53 -08004138 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07004139 if (mHotseat != null) {
4140 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004141 }
4142 }
4143
Adam Cohendcd297f2013-06-18 13:13:40 -07004144 @Override
4145 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07004146 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07004147
Adam Cohen5084cba2013-09-03 12:01:16 -07004148 // If there are no screens, we need to have an empty screen
4149 if (orderedScreenIds.size() == 0) {
4150 mWorkspace.addExtraEmptyScreen();
4151 }
Winson Chung0e6a7132013-08-23 12:55:10 -07004152
4153 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06004154 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05004155 if (hasCustomContentToLeft()) {
4156 mWorkspace.createCustomContentContainer();
4157 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07004158 }
Winson Chung64359a52013-07-08 17:17:08 -07004159 }
4160
4161 @Override
4162 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08004163 // Log to disk
4164 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4165 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4166 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07004167 int count = orderedScreenIds.size();
4168 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07004169 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07004170 }
Adam Cohendcd297f2013-06-18 13:13:40 -07004171 }
4172
Adam Cohen39a06042013-07-19 14:30:12 -07004173 private boolean shouldShowWeightWatcher() {
4174 String spKey = LauncherAppState.getSharedPreferencesKey();
4175 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07004176 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07004177
4178 return show;
4179 }
4180
4181 private void toggleShowWeightWatcher() {
4182 String spKey = LauncherAppState.getSharedPreferencesKey();
4183 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4184 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4185
4186 show = !show;
4187
4188 SharedPreferences.Editor editor = sp.edit();
4189 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4190 editor.commit();
4191
4192 if (mWeightWatcher != null) {
4193 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4194 }
4195 }
4196
Winson Chungd64d1762013-08-20 14:37:16 -07004197 public void bindAppsAdded(final ArrayList<Long> newScreens,
4198 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07004199 final ArrayList<ItemInfo> addAnimated,
4200 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004201 Runnable r = new Runnable() {
4202 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07004203 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07004204 }
4205 };
4206 if (waitUntilResume(r)) {
4207 return;
4208 }
4209
Winson Chungd64d1762013-08-20 14:37:16 -07004210 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08004211 if (newScreens != null) {
4212 bindAddScreens(newScreens);
4213 }
Winson Chungd64d1762013-08-20 14:37:16 -07004214
4215 // We add the items without animation on non-visible pages, and with
4216 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08004217 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004218 bindItems(addNotAnimated, 0,
4219 addNotAnimated.size(), false);
4220 }
Adam Cohen76a47a12014-02-05 11:47:43 -08004221 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004222 bindItems(addAnimated, 0,
4223 addAnimated.size(), true);
4224 }
Winson Chungc58497e2013-09-03 17:48:37 -07004225
Winson Chung87412982013-10-03 18:34:14 -07004226 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004227 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004228
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004229 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004230 addedApps != null && mAppsCustomizeContent != null) {
4231 mAppsCustomizeContent.addApps(addedApps);
4232 }
Winson Chungd64d1762013-08-20 14:37:16 -07004233 }
4234
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004235 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004236 * Bind the items start-end from the list.
4237 *
4238 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004239 */
Winson Chung64359a52013-07-08 17:17:08 -07004240 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4241 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004242 Runnable r = new Runnable() {
4243 public void run() {
4244 bindItems(shortcuts, start, end, forceAnimateIcons);
4245 }
4246 };
4247 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004248 return;
4249 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004250
Winson Chungf0c6ae02012-03-21 16:10:31 -07004251 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004252 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4253 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004254 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004255 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004256 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004257 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004258 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004259
4260 // Short circuit if we are loading dock items for a configuration which has no dock
4261 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4262 mHotseat == null) {
4263 continue;
4264 }
4265
Joe Onorato9c1289c2009-08-17 11:03:03 -04004266 switch (item.itemType) {
4267 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4268 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004269 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004270 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004271
Winson Chung64359a52013-07-08 17:17:08 -07004272 /*
4273 * TODO: FIX collision case
4274 */
Winson Chungce376632013-07-11 16:12:41 -07004275 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4276 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4277 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004278 View v = cl.getChildAt(item.cellX, item.cellY);
4279 Object tag = v.getTag();
4280 String desc = "Collision while binding workspace item: " + item
4281 + ". Collides with " + tag;
4282 if (LauncherAppState.isDogfoodBuild()) {
4283 throw (new RuntimeException(desc));
4284 } else {
4285 Log.d(TAG, desc);
4286 }
Winson Chungce376632013-07-11 16:12:41 -07004287 }
Winson Chung64359a52013-07-08 17:17:08 -07004288 }
4289
Adam Cohendcd297f2013-06-18 13:13:40 -07004290 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4291 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004292 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004293 // Animate all the applications up now
4294 shortcut.setAlpha(0f);
4295 shortcut.setScaleX(0f);
4296 shortcut.setScaleY(0f);
4297 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004298 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004299 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004300 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004301 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004302 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004303 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004304 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004305 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4306 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004307 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004308 default:
4309 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004310 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004311 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004312
Winson Chung997a9232013-07-24 15:33:46 -07004313 if (animateIcons) {
4314 // Animate to the correct page
4315 if (newShortcutsScreenId > -1) {
4316 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004317 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004318 final Runnable startBounceAnimRunnable = new Runnable() {
4319 public void run() {
4320 anim.playTogether(bounceAnims);
4321 anim.start();
4322 }
4323 };
Winson Chung997a9232013-07-24 15:33:46 -07004324 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004325 // We post the animation slightly delayed to prevent slowdowns
4326 // when we are loading right after we return to launcher.
4327 mWorkspace.postDelayed(new Runnable() {
4328 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004329 if (mWorkspace != null) {
4330 mWorkspace.snapToPage(newScreenIndex);
4331 mWorkspace.postDelayed(startBounceAnimRunnable,
4332 NEW_APPS_ANIMATION_DELAY);
4333 }
Winson Chung94d67682013-09-25 16:29:40 -07004334 }
4335 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004336 } else {
4337 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004338 }
4339 }
Winson Chung64359a52013-07-08 17:17:08 -07004340 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004341 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004342 }
4343
Joe Onorato9c1289c2009-08-17 11:03:03 -04004344 /**
4345 * Implementation of the method from LauncherModel.Callbacks.
4346 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004347 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004348 Runnable r = new Runnable() {
4349 public void run() {
4350 bindFolders(folders);
4351 }
4352 };
4353 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004354 return;
4355 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004356 sFolders.clear();
4357 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004358 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004359
4360 /**
4361 * Add the views for a widget to the workspace.
4362 *
4363 * Implementation of the method from LauncherModel.Callbacks.
4364 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004365 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004366 Runnable r = new Runnable() {
4367 public void run() {
4368 bindAppWidget(item);
4369 }
4370 };
4371 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004372 return;
4373 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004374
Daniel Sandler843e8602010-06-07 14:59:01 -04004375 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4376 if (DEBUG_WIDGETS) {
4377 Log.d(TAG, "bindAppWidget: " + item);
4378 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004379 final Workspace workspace = mWorkspace;
4380
Sunny Goyalff572272014-07-23 13:58:07 -07004381 AppWidgetProviderInfo appWidgetInfo;
4382 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4383 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4384
4385 appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
4386 if (appWidgetInfo == null) {
4387 if (DEBUG_WIDGETS) {
4388 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4389 + " belongs to component " + item.providerName
4390 + ", as the povider is null");
4391 }
4392 LauncherModel.deleteItemFromDatabase(this, item);
4393 return;
4394 }
4395 // Note: This assumes that the id remap broadcast is received before this step.
4396 // If that is not the case, the id remap will be ignored and user may see the
4397 // click to setup view.
4398 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4399 pendingInfo.spanX = item.spanX;
4400 pendingInfo.spanY = item.spanY;
4401 pendingInfo.minSpanX = item.minSpanX;
4402 pendingInfo.minSpanY = item.minSpanY;
4403 Bundle options =
4404 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4405
4406 boolean success = false;
4407 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4408 if (options != null) {
4409 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId,
4410 appWidgetInfo.provider, options);
4411 } else {
4412 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId,
4413 appWidgetInfo.provider);
4414 }
4415
4416 // TODO consider showing a permission dialog when the widget is clicked.
4417 if (!success) {
4418 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4419 if (DEBUG_WIDGETS) {
4420 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4421 + " belongs to component " + item.providerName
4422 + ", as the launcher is unable to bing a new widget id");
4423 }
4424 LauncherModel.deleteItemFromDatabase(this, item);
4425 return;
4426 }
4427
4428 item.appWidgetId = newWidgetId;
4429
4430 // If the widget has a configure activity, it is still needs to set it up, otherwise
4431 // the widget is ready to go.
4432 item.restoreStatus = (appWidgetInfo.configure == null)
4433 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4434 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4435
4436 LauncherModel.updateItemInDatabase(this, item);
4437 }
4438
Sunny Goyal651077b2014-06-30 14:15:31 -07004439 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4440 final int appWidgetId = item.appWidgetId;
4441 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4442 if (DEBUG_WIDGETS) {
4443 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4444 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004445
Sunny Goyal651077b2014-06-30 14:15:31 -07004446 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4447 } else {
4448 appWidgetInfo = null;
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004449 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item);
4450 view.updateIcon(mIconCache);
4451 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004452 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004453 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004454 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004455
Joe Onorato9c1289c2009-08-17 11:03:03 -04004456 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004457 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004458
Adam Cohendcd297f2013-06-18 13:13:40 -07004459 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004460 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004461 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4462
Joe Onorato9c1289c2009-08-17 11:03:03 -04004463 workspace.requestLayout();
4464
Daniel Sandler843e8602010-06-07 14:59:01 -04004465 if (DEBUG_WIDGETS) {
4466 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4467 + (SystemClock.uptimeMillis()-start) + "ms");
4468 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004469 }
4470
Sunny Goyalff572272014-07-23 13:58:07 -07004471 /**
4472 * Restores a pending widget.
4473 *
4474 * @param appWidgetId The app widget id
4475 * @param cellInfo The position on screen where to create the widget.
4476 */
4477 private void completeRestoreAppWidget(final int appWidgetId) {
4478 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4479 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4480 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4481 return;
4482 }
4483
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004484 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004485 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4486
4487 mWorkspace.reinflateWidgetsIfNecessary();
4488 LauncherModel.updateItemInDatabase(this, info);
4489 }
4490
Adam Cohen1462de32012-07-24 22:34:36 -07004491 public void onPageBoundSynchronously(int page) {
4492 mSynchronouslyBoundPages.add(page);
4493 }
4494
Joe Onorato9c1289c2009-08-17 11:03:03 -04004495 /**
4496 * Callback saying that there aren't any more items to bind.
4497 *
4498 * Implementation of the method from LauncherModel.Callbacks.
4499 */
Adam Cohene25af792013-06-06 23:08:25 -07004500 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004501 Runnable r = new Runnable() {
4502 public void run() {
4503 finishBindingItems(upgradePath);
4504 }
4505 };
4506 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004507 return;
4508 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004509 if (mSavedState != null) {
4510 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004511 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004512 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004513 mSavedState = null;
4514 }
4515
Adam Cohen1462de32012-07-24 22:34:36 -07004516 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004517
Winson Chungc51db6a2011-10-05 11:44:49 -07004518 // Update the market app icon as necessary (the other icons will be managed in response to
4519 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07004520 if (!DISABLE_MARKET_BUTTON) {
4521 updateAppMarketIcon();
4522 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07004523
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004524 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004525 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004526
4527 // If we received the result of any pending adds while the loader was running (e.g. the
4528 // widget configuration forced an orientation change), process them now.
4529 if (sPendingAddItem != null) {
4530 final long screenId = completeAdd(sPendingAddItem);
4531
4532 // TODO: this moves the user to the page where the pending item was added. Ideally,
4533 // the screen would be guaranteed to exist after bind, and the page would be set through
4534 // the workspace restore process.
4535 mWorkspace.post(new Runnable() {
4536 @Override
4537 public void run() {
4538 mWorkspace.snapToScreenId(screenId);
4539 }
4540 });
4541 sPendingAddItem = null;
4542 }
4543
Adam Cohene25af792013-06-06 23:08:25 -07004544 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004545 mWorkspace.getUniqueComponents(true, null);
4546 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004547 }
Sunny Goyale755d462014-07-22 13:48:29 -07004548 PackageInstallerCompat.getInstance(this).onFinishBind();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004549 }
4550
Adam Cohen3ed316a2014-07-23 18:21:20 -07004551 private void sendLoadingCompleteBroadcastIfNecessary() {
4552 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4553 String permission =
4554 getResources().getString(R.string.receive_first_load_broadcast_permission);
4555 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4556 sendBroadcast(intent, permission);
4557 SharedPreferences.Editor editor = mSharedPrefs.edit();
4558 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4559 editor.apply();
4560 }
4561 }
4562
Winson Chunga0b7e862013-09-05 16:03:15 -07004563 public boolean isAllAppsButtonRank(int rank) {
4564 if (mHotseat != null) {
4565 return mHotseat.isAllAppsButtonRank(rank);
4566 }
4567 return false;
4568 }
4569
Winson Chunga2413752012-04-03 14:22:34 -07004570 private boolean canRunNewAppsAnimation() {
4571 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4572 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4573 }
4574
Winson Chungc9168342013-06-26 14:54:55 -07004575 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4576 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4577 PropertyValuesHolder.ofFloat("alpha", 1f),
4578 PropertyValuesHolder.ofFloat("scaleX", 1f),
4579 PropertyValuesHolder.ofFloat("scaleY", 1f));
4580 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4581 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4582 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4583 return bounceAnim;
4584 }
4585
Adam Cohen27772732013-11-11 14:00:56 +00004586 public boolean useVerticalBarLayout() {
4587 return LauncherAppState.getInstance().getDynamicGrid().
4588 getDeviceProfile().isVerticalBarLayout();
4589 }
4590
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004591 protected Rect getSearchBarBounds() {
4592 return LauncherAppState.getInstance().getDynamicGrid().
4593 getDeviceProfile().getSearchBarBounds();
4594 }
4595
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004596 @Override
4597 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004598 boolean searchVisible = updateGlobalSearchIcon();
4599 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004600 if (mSearchDropTargetBar != null) {
4601 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4602 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004603 }
4604
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004605 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004606 * Add the icons for all apps.
4607 *
4608 * Implementation of the method from LauncherModel.Callbacks.
4609 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004610 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004611 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004612 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4613 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4614 getHotseat().addAllAppsFolder(mIconCache, apps,
4615 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4616 }
4617 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004618 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004619 if (mAppsCustomizeContent != null) {
4620 mAppsCustomizeContent.onPackagesUpdated(
4621 LauncherModel.getSortedWidgetsAndShortcuts(this));
4622 }
Winson Chungc58497e2013-09-03 17:48:37 -07004623 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004624 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004625 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004626 mAppsCustomizeContent.onPackagesUpdated(
4627 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004628 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004629 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004630 }
4631
4632 /**
4633 * A package was updated.
4634 *
4635 * Implementation of the method from LauncherModel.Callbacks.
4636 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004637 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004638 Runnable r = new Runnable() {
4639 public void run() {
4640 bindAppsUpdated(apps);
4641 }
4642 };
4643 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004644 return;
4645 }
4646
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004647 if (mWorkspace != null) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004648 mWorkspace.updateShortcutsAndWidgets(apps);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004649 }
Winson Chungc58497e2013-09-03 17:48:37 -07004650
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004651 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004652 mAppsCustomizeContent != null) {
4653 mAppsCustomizeContent.updateApps(apps);
4654 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004655 }
4656
4657 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004658 * Update the state of a package, typically related to install state.
4659 *
4660 * Implementation of the method from LauncherModel.Callbacks.
4661 */
Sunny Goyale755d462014-07-22 13:48:29 -07004662 @Override
4663 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004664 if (mWorkspace != null) {
Sunny Goyale755d462014-07-22 13:48:29 -07004665 mWorkspace.updatePackageState(installInfo);
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004666 }
4667 }
4668
4669 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004670 * A package was uninstalled. We take both the super set of packageNames
4671 * in addition to specific applications to remove, the reason being that
4672 * this can be called when a package is updated as well. In that scenario,
4673 * we only remove specific components from the workspace, where as
4674 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004675 *
4676 * Implementation of the method from LauncherModel.Callbacks.
4677 */
Winson Chung83892cc2013-05-01 16:53:33 -07004678 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004679 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004680 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004681 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004682 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004683 }
Winson Chungd64d1762013-08-20 14:37:16 -07004684 };
4685 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004686 return;
4687 }
4688
Winson Chungdf95eb12013-10-16 14:57:07 -07004689 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004690 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004691 }
4692 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004693 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004694 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004695
Winson Chunga1820962011-10-03 16:31:06 -07004696 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004697 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004698
Winson Chungdf95eb12013-10-16 14:57:07 -07004699 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004700 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004701 mAppsCustomizeContent != null) {
4702 mAppsCustomizeContent.removeApps(appInfos);
4703 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004704 }
Joe Onoratobe386092009-11-17 17:32:16 -08004705
4706 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004707 * A number of packages were updated.
4708 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004709 private ArrayList<Object> mWidgetsAndShortcuts;
4710 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004711 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004712 bindPackagesUpdated(mWidgetsAndShortcuts);
4713 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004714 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004715 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004716 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4717 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4718 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004719 return;
4720 }
4721
Winson Chung64359a52013-07-08 17:17:08 -07004722 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004723 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004724 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004725 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004726 }
4727
Winson Chung400438b2011-01-16 17:53:48 -08004728 private int mapConfigurationOriActivityInfoOri(int configOri) {
4729 final Display d = getWindowManager().getDefaultDisplay();
4730 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4731 switch (d.getRotation()) {
4732 case Surface.ROTATION_0:
4733 case Surface.ROTATION_180:
4734 // We are currently in the same basic orientation as the natural orientation
4735 naturalOri = configOri;
4736 break;
4737 case Surface.ROTATION_90:
4738 case Surface.ROTATION_270:
4739 // We are currently in the other basic orientation to the natural orientation
4740 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4741 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4742 break;
4743 }
4744
4745 int[] oriMap = {
4746 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4747 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4748 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4749 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4750 };
4751 // Since the map starts at portrait, we need to offset if this device's natural orientation
4752 // is landscape.
4753 int indexOffset = 0;
4754 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4755 indexOffset = 1;
4756 }
4757 return oriMap[(d.getRotation() + indexOffset) % 4];
4758 }
Adam Cohen446e9402011-09-15 18:21:21 -07004759
Winson Chung4b919f82012-05-01 10:44:08 -07004760 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004761 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004762 getResources().getBoolean(R.bool.allow_rotation);
4763 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004764 }
Winson Chung4b919f82012-05-01 10:44:08 -07004765 public void lockScreenOrientation() {
4766 if (isRotationEnabled()) {
4767 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4768 .getConfiguration().orientation));
4769 }
4770 }
4771 public void unlockScreenOrientation(boolean immediate) {
4772 if (isRotationEnabled()) {
4773 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004774 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004775 } else {
4776 mHandler.postDelayed(new Runnable() {
4777 public void run() {
4778 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4779 }
4780 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004781 }
Winson Chung4b919f82012-05-01 10:44:08 -07004782 }
Winson Chung400438b2011-01-16 17:53:48 -08004783 }
4784
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004785 /**
4786 * Called when the SearchBar hint should be changed.
4787 *
4788 * @param hint the hint to be displayed in the search bar.
4789 */
4790 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004791 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004792 }
4793
Winson Chunge43a1e72014-01-15 10:33:02 -08004794 protected boolean isLauncherPreinstalled() {
4795 PackageManager pm = getPackageManager();
4796 try {
4797 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4798 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4799 return true;
4800 } else {
4801 return false;
4802 }
4803 } catch (NameNotFoundException e) {
4804 e.printStackTrace();
4805 return false;
4806 }
4807 }
4808
Adam Cohenea90f832014-05-21 15:03:34 -07004809 /**
4810 * This method indicates whether or not we should suggest default wallpaper dimensions
4811 * when our wallpaper cropper was not yet used to set a wallpaper.
4812 */
4813 protected boolean overrideWallpaperDimensions() {
4814 return true;
4815 }
4816
Adam Cohen5eed5d82014-05-19 13:12:13 -07004817 protected boolean shouldClingFocusHotseatApp() {
4818 return false;
4819 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004820 protected String getFirstRunClingSearchBarHint() {
4821 return "";
4822 }
4823 protected String getFirstRunCustomContentHint() {
4824 return "";
4825 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004826 protected int getFirstRunFocusedHotseatAppDrawableId() {
4827 return -1;
4828 }
4829 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4830 return null;
4831 }
4832 protected int getFirstRunFocusedHotseatAppRank() {
4833 return -1;
4834 }
4835 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4836 return "";
4837 }
4838 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4839 return "";
4840 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004841
Winson Chungaf40f202013-09-18 18:26:31 -07004842 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004843 mLauncherClings.dismissFirstRunCling(v);
4844 }
4845 public void dismissMigrationClingCopyApps(View v) {
4846 mLauncherClings.dismissMigrationClingCopyApps(v);
4847 }
4848 public void dismissMigrationClingUseDefault(View v) {
4849 mLauncherClings.dismissMigrationClingUseDefault(v);
4850 }
4851 public void dismissMigrationWorkspaceCling(View v) {
4852 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004853 }
Winson Chung82f55532011-08-09 14:14:23 -07004854 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004855 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004856 }
4857 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004858 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004859 }
Adam Cohen6268f2d2014-05-16 16:42:35 -07004860 public void markFolderClingDismissedIfNecessary() {
4861 mLauncherClings.markFolderClingDismissedIfNecessary();
4862 }
Adam Cohen432609a2014-03-13 17:03:22 -07004863
4864 /**
4865 * To be overridden by subclasses to indicate that there is an activity to launch
4866 * before showing the standard launcher experience.
4867 */
4868 protected boolean hasFirstRunActivity() {
4869 return false;
4870 }
4871
4872 /**
4873 * To be overridden by subclasses to launch any first run activity
4874 */
4875 protected Intent getFirstRunActivity() {
4876 return null;
4877 }
4878
Winson Chunga6945242014-01-08 14:04:34 -08004879 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004880 return !ActivityManager.isRunningInTestHarness() &&
4881 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004882 }
4883
Adam Cohen4a9423d2014-03-28 14:22:31 -07004884 protected boolean hasRunFirstRunActivity() {
4885 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4886 }
4887
Adam Cohen432609a2014-03-13 17:03:22 -07004888 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004889 if (shouldRunFirstRunActivity() &&
4890 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004891 Intent firstRunIntent = getFirstRunActivity();
4892 if (firstRunIntent != null) {
4893 startActivity(firstRunIntent);
4894 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004895 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004896 }
4897 }
Adam Cohen432609a2014-03-13 17:03:22 -07004898 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004899 }
4900
4901 private void markFirstRunActivityShown() {
4902 SharedPreferences.Editor editor = mSharedPrefs.edit();
4903 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4904 editor.apply();
4905 }
4906
Adam Cohen432609a2014-03-13 17:03:22 -07004907 /**
4908 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4909 * screen that must be displayed and dismissed.
4910 */
4911 protected boolean hasDismissableIntroScreen() {
4912 return false;
4913 }
4914
4915 /**
4916 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4917 */
4918 protected View getIntroScreen() {
4919 return null;
4920 }
4921
4922 /**
4923 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4924 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4925 */
4926 private boolean shouldShowIntroScreen() {
4927 return hasDismissableIntroScreen() &&
4928 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4929 }
4930
4931 protected void showIntroScreen() {
4932 View introScreen = getIntroScreen();
4933 changeWallpaperVisiblity(false);
4934 if (introScreen != null) {
4935 mDragLayer.showOverlayView(introScreen);
4936 }
4937 }
4938
4939 public void dismissIntroScreen() {
4940 markIntroScreenDismissed();
4941 if (showFirstRunActivity()) {
4942 // We delay hiding the intro view until the first run activity is showing. This
4943 // avoids a blip.
4944 mWorkspace.postDelayed(new Runnable() {
4945 @Override
4946 public void run() {
4947 mDragLayer.dismissOverlayView();
4948 }
4949 }, ACTIVITY_START_DELAY);
4950 } else {
4951 mDragLayer.dismissOverlayView();
4952 }
4953 changeWallpaperVisiblity(true);
4954 }
4955
4956 private void markIntroScreenDismissed() {
4957 SharedPreferences.Editor editor = mSharedPrefs.edit();
4958 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4959 editor.apply();
4960 }
4961
Winson Chunga6945242014-01-08 14:04:34 -08004962 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004963 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4964 if (mHotseat != null) mHotseat.setAlpha(1f);
4965 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4966 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004967 }
4968
4969 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004970 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4971 if (mHotseat != null) mHotseat.setAlpha(0f);
4972 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4973 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004974 }
4975
Mathew Inwood72fbec12013-11-19 15:45:07 +00004976 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004977 // Called from search suggestion, not supported in other profiles.
4978 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4979 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4980 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4981 myUser);
4982 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004983 return null;
4984 }
Kenny Guyed131872014-04-30 03:02:21 +01004985 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004986 }
4987
4988 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4989 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004990 // Called from search suggestion, not supported in other profiles.
4991 return createShortcutDragInfo(shortcutIntent, caption, icon,
4992 UserHandleCompat.myUserHandle());
4993 }
4994
4995 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4996 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01004997 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01004998 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01004999 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005000 }
5001
Mathew Inwoodb90860a2014-04-11 17:17:39 +01005002 protected void moveWorkspaceToDefaultScreen() {
5003 mWorkspace.moveToDefaultScreen(false);
5004 }
5005
Mathew Inwood72fbec12013-11-19 15:45:07 +00005006 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
5007 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07005008 mWorkspace.onExternalDragStartedWithItem(dragView);
5009 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005010 }
5011
Anjali Koppalf5d29132014-02-28 13:33:27 -08005012 @Override
5013 public void onPageSwitch(View newPage, int newPageIndex) {
5014 }
5015
Winson Chung80baf5a2010-08-09 16:03:15 -07005016 /**
Joe Onoratobe386092009-11-17 17:32:16 -08005017 * Prints out out state for debugging.
5018 */
5019 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04005020 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08005021 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08005022 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
5023 Log.d(TAG, "mRestoring=" + mRestoring);
5024 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
5025 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07005026 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08005027 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07005028
Winson Chung785d2eb2011-04-14 16:08:02 -07005029 if (mAppsCustomizeContent != null) {
5030 mAppsCustomizeContent.dumpState();
5031 }
Daniel Sandler325dc232013-06-05 22:57:57 -04005032 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08005033 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005034
5035 @Override
5036 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5037 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07005038 synchronized (sDumpLogs) {
5039 writer.println(" ");
5040 writer.println("Debug logs: ");
5041 for (int i = 0; i < sDumpLogs.size(); i++) {
5042 writer.println(" " + sDumpLogs.get(i));
5043 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005044 }
5045 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005046
5047 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07005048 if (DEBUG_DUMP_LOG) {
5049 synchronized (sDumpLogs) {
5050 Log.d(TAG, "");
5051 Log.d(TAG, "*********************");
5052 Log.d(TAG, "Launcher debug logs: ");
5053 for (int i = 0; i < sDumpLogs.size(); i++) {
5054 Log.d(TAG, " " + sDumpLogs.get(i));
5055 }
5056 Log.d(TAG, "*********************");
5057 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07005058 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005059 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005060 }
5061
5062 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005063 addDumpLog(tag, log, null, debugLog);
5064 }
5065
5066 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07005067 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005068 if (e != null) {
5069 Log.d(tag, log, e);
5070 } else {
5071 Log.d(tag, log);
5072 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005073 }
Winson Chungede41292013-09-19 16:27:36 -07005074 if (DEBUG_DUMP_LOG) {
5075 sDateStamp.setTime(System.currentTimeMillis());
5076 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05005077 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5078 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07005079 }
Winson Chungede41292013-09-19 16:27:36 -07005080 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005081 }
5082
Winson Chungede41292013-09-19 16:27:36 -07005083 public void dumpLogsToLocalData() {
5084 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01005085 new AsyncTask<Void, Void, Void>() {
5086 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07005087 boolean success = false;
5088 sDateStamp.setTime(sRunStart);
5089 String FILENAME = sDateStamp.getMonth() + "-"
5090 + sDateStamp.getDay() + "_"
5091 + sDateStamp.getHours() + "-"
5092 + sDateStamp.getMinutes() + "_"
5093 + sDateStamp.getSeconds() + ".txt";
5094
5095 FileOutputStream fos = null;
5096 File outFile = null;
5097 try {
5098 outFile = new File(getFilesDir(), FILENAME);
5099 outFile.createNewFile();
5100 fos = new FileOutputStream(outFile);
5101 } catch (Exception e) {
5102 e.printStackTrace();
5103 }
5104 if (fos != null) {
5105 PrintWriter writer = new PrintWriter(fos);
5106
5107 writer.println(" ");
5108 writer.println("Debug logs: ");
5109 synchronized (sDumpLogs) {
5110 for (int i = 0; i < sDumpLogs.size(); i++) {
5111 writer.println(" " + sDumpLogs.get(i));
5112 }
5113 }
5114 writer.close();
5115 }
5116 try {
5117 if (fos != null) {
5118 fos.close();
5119 success = true;
5120 }
5121 } catch (IOException e) {
5122 e.printStackTrace();
5123 }
Michael Jurka43467462013-11-14 12:03:58 +01005124 return null;
Winson Chungede41292013-09-19 16:27:36 -07005125 }
Michael Jurka43467462013-11-14 12:03:58 +01005126 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07005127 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005128 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08005129}
Michael Jurka2763be32011-02-24 11:19:57 -08005130
Michael Jurkaabded662011-03-04 12:06:57 -08005131interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08005132 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07005133 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08005134 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08005135 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08005136 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08005137}
Dan Sandlerd5024042014-01-09 15:01:33 -05005138
5139interface DebugIntents {
5140 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5141 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00005142}