blob: 062e8483855dc2bbfd51e2670d54c2102dac0bee [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
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800387 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800388 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700389 }
390
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800391 @Override
392 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700393 if (DEBUG_STRICT_MODE) {
394 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
395 .detectDiskReads()
396 .detectDiskWrites()
397 .detectNetwork() // or .detectAll() for all detectable problems
398 .penaltyLog()
399 .build());
400 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
401 .detectLeakedSqlLiteObjects()
402 .detectLeakedClosableObjects()
403 .penaltyLog()
404 .penaltyDeath()
405 .build());
406 }
407
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800408 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400409
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400410 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400411 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700412 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700413 // Determine the dynamic grid properties
414 Point smallestSize = new Point();
415 Point largestSize = new Point();
416 Point realSize = new Point();
417 Display display = getWindowManager().getDefaultDisplay();
418 display.getCurrentSizeRange(smallestSize, largestSize);
419 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700420 DisplayMetrics dm = new DisplayMetrics();
421 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700422
Winson Chung5f8afe62013-08-12 16:19:28 -0700423 // Lazy-initialize the dynamic grid
424 DeviceProfile grid = app.initDynamicGrid(this,
425 Math.min(smallestSize.x, smallestSize.y),
426 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700427 realSize.x, realSize.y,
428 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700429
430 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400431 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700432 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700433 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800434 mModel = app.setLauncher(this);
435 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700436 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400437 mDragController = new DragController(this);
Winson Chunga6945242014-01-08 14:04:34 -0800438 mLauncherClings = new LauncherClings(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800439 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700440
Daniel Sandlerff02d492013-08-05 02:12:05 -0400441 mStats = new Stats(this);
442
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700443 mAppWidgetManager = AppWidgetManager.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700444
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700445 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
446 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700447
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700448 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
449 // this also ensures that any synchronous binding below doesn't re-trigger another
450 // LauncherModel load.
451 mPaused = false;
452
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800453 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200454 android.os.Debug.startMethodTracing(
455 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800456 }
457
Adam Cohen53805212013-10-01 10:39:23 -0700458
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800459 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700461
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800462 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100463 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800464
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800465 registerContentObservers();
466
Joe Onorato7c312c12009-08-13 21:36:53 -0700467 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700468
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800469 mSavedState = savedInstanceState;
470 restoreState(mSavedState);
471
472 if (PROFILE_STARTUP) {
473 android.os.Debug.stopMethodTracing();
474 }
475
476 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700477 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700478 // If the user leaves launcher, then we should just load items asynchronously when
479 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500480 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700481 } else {
482 // We only load the page synchronously if the user rotates (or triggers a
483 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800484 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700485 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800486 }
487
488 // For handling default keys
489 mDefaultKeySsb = new SpannableStringBuilder();
490 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800491
492 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
493 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800494
Adam Cohenf9426d52012-06-04 17:26:21 -0700495 updateGlobalIcons();
496
497 // On large interfaces, we want the screen to auto-rotate based on the current orientation
498 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700499
Adam Cohen432609a2014-03-13 17:03:22 -0700500 if (shouldShowIntroScreen()) {
501 showIntroScreen();
502 } else {
503 showFirstRunActivity();
504 }
505
Winson Chunge43a1e72014-01-15 10:33:02 -0800506 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
507 // on the device, then we always show the first run cling experience (or if there is no
508 // launcher2). Otherwise, we prompt the user upon started for migration
Winson Chunge43a1e72014-01-15 10:33:02 -0800509 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
510 if (mModel.canMigrateFromOldLauncherDb(this)) {
511 mLauncherClings.showMigrationCling();
512 } else {
513 mLauncherClings.showFirstRunCling();
514 }
Winson Chunga6945242014-01-08 14:04:34 -0800515 } else {
Winson Chunge43a1e72014-01-15 10:33:02 -0800516 mLauncherClings.removeFirstRunAndMigrationClings();
Winson Chunga6945242014-01-08 14:04:34 -0800517 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700518 }
519
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700520 @Override
521 public void onLauncherProviderChange() { }
522
Winson Chung98ca0f72013-07-29 12:58:51 -0700523 /** To be overriden by subclasses to hint to Launcher that we have custom content */
524 protected boolean hasCustomContentToLeft() {
525 return false;
526 }
527
Dave Hawkeya8881582013-09-17 15:55:33 -0600528 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500529 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600530 * {@link #addToCustomContentPage}. This will only be invoked if
531 * {@link #hasCustomContentToLeft()} is {@code true}.
532 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500533 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600534 }
535
536 /**
537 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
538 * ensure the custom content page is added or removed if necessary.
539 */
540 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600541 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600542 // Not bound yet, wait for bindScreens to be called.
543 return;
544 }
545
546 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
547 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500548 mWorkspace.createCustomContentContainer();
549 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600550 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
551 mWorkspace.removeCustomContentPage();
552 }
553 }
554
Adam Cohenf9426d52012-06-04 17:26:21 -0700555 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700556 boolean searchVisible = false;
557 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800558 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700559 int coi = getCurrentOrientationIndexForGlobalIcons();
560 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
561 sAppMarketIcon[coi] == null) {
Winson Chungd64a6662013-09-30 11:06:59 -0700562 if (!DISABLE_MARKET_BUTTON) {
563 updateAppMarketIcon();
564 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700565 searchVisible = updateGlobalSearchIcon();
566 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700567 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700568 if (sGlobalSearchIcon[coi] != null) {
569 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700570 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700571 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700572 if (sVoiceSearchIcon[coi] != null) {
573 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700574 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700575 }
Winson Chungd64a6662013-09-30 11:06:59 -0700576 if (!DISABLE_MARKET_BUTTON && sAppMarketIcon[coi] != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -0700577 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800578 }
Winson Chungadf0c182012-08-23 14:59:07 -0700579 if (mSearchDropTargetBar != null) {
580 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
581 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800582 }
Romain Guycbb89e42009-06-08 15:52:54 -0700583
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800584 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700585 if (sLocaleConfiguration == null) {
586 new AsyncTask<Void, Void, LocaleConfiguration>() {
587 @Override
588 protected LocaleConfiguration doInBackground(Void... unused) {
589 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
590 readConfiguration(Launcher.this, localeConfiguration);
591 return localeConfiguration;
592 }
593
594 @Override
595 protected void onPostExecute(LocaleConfiguration result) {
596 sLocaleConfiguration = result;
597 checkForLocaleChange(); // recursive, but now with a locale configuration
598 }
599 }.execute();
600 return;
601 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700602
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800603 final Configuration configuration = getResources().getConfiguration();
604
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700605 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800606 final String locale = configuration.locale.toString();
607
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700608 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800609 final int mcc = configuration.mcc;
610
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700611 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800612 final int mnc = configuration.mnc;
613
Romain Guy84f296c2009-11-04 15:00:44 -0800614 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800615
Romain Guy84f296c2009-11-04 15:00:44 -0800616 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700617 sLocaleConfiguration.locale = locale;
618 sLocaleConfiguration.mcc = mcc;
619 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700620
Joe Onorato0589f0f2010-02-08 13:44:00 -0800621 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700622
623 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100624 new AsyncTask<Void, Void, Void>() {
625 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700626 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100627 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700628 }
Michael Jurka43467462013-11-14 12:03:58 +0100629 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700630 }
631 }
632
633 private static class LocaleConfiguration {
634 public String locale;
635 public int mcc = -1;
636 public int mnc = -1;
637 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700638
Romain Guy98d01652009-06-30 16:21:04 -0700639 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
640 DataInputStream in = null;
641 try {
642 in = new DataInputStream(context.openFileInput(PREFERENCES));
643 configuration.locale = in.readUTF();
644 configuration.mcc = in.readInt();
645 configuration.mnc = in.readInt();
646 } catch (FileNotFoundException e) {
647 // Ignore
648 } catch (IOException e) {
649 // Ignore
650 } finally {
651 if (in != null) {
652 try {
653 in.close();
654 } catch (IOException e) {
655 // Ignore
656 }
657 }
658 }
659 }
660
661 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
662 DataOutputStream out = null;
663 try {
664 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
665 out.writeUTF(configuration.locale);
666 out.writeInt(configuration.mcc);
667 out.writeInt(configuration.mnc);
668 out.flush();
669 } catch (FileNotFoundException e) {
670 // Ignore
671 } catch (IOException e) {
672 //noinspection ResultOfMethodCallIgnored
673 context.getFileStreamPath(PREFERENCES).delete();
674 } finally {
675 if (out != null) {
676 try {
677 out.close();
678 } catch (IOException e) {
679 // Ignore
680 }
681 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800682 }
683 }
684
Anton Hanssona2f665f2013-09-26 12:18:32 +0100685 public Stats getStats() {
686 return mStats;
687 }
688
Bjorn Bringertc459e522013-06-07 19:36:01 +0100689 public LayoutInflater getInflater() {
690 return mInflater;
691 }
692
Winson Chung36a62fe2012-05-06 18:04:42 -0700693 boolean isDraggingEnabled() {
694 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
695 // that is subsequently removed from the workspace in startBinding().
696 return !mModel.isLoadingWorkspace();
697 }
698
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800699 static int getScreen() {
700 synchronized (sLock) {
701 return sScreen;
702 }
703 }
704
705 static void setScreen(int screen) {
706 synchronized (sLock) {
707 sScreen = screen;
708 }
709 }
710
Winson Chung557d6ed2011-07-08 15:34:52 -0700711 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000712 * Copied from View -- the View version of the method isn't called
713 * anywhere else in our process and only exists for API level 17+,
714 * so it's ok to keep our own version with no API requirement.
715 */
716 public static int generateViewId() {
717 for (;;) {
718 final int result = sNextGeneratedId.get();
719 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
720 int newValue = result + 1;
721 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
722 if (sNextGeneratedId.compareAndSet(result, newValue)) {
723 return result;
724 }
725 }
726 }
727
728 public int getViewIdForItem(ItemInfo info) {
729 // This cast is safe given the > 2B range for int.
730 int itemId = (int) info.id;
731 if (mItemIdToViewId.containsKey(itemId)) {
732 return mItemIdToViewId.get(itemId);
733 }
734 int viewId = generateViewId();
735 mItemIdToViewId.put(itemId, viewId);
736 return viewId;
737 }
738
739 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700740 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
741 * a configuration step, this allows the proper animations to run after other transitions.
742 */
Adam Cohendb364c32014-05-20 14:23:40 -0700743 private long completeAdd(PendingAddArguments args) {
744
745 long screenId = ensurePendingDropLayoutExists(args.screenId);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800746 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800747 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700748 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700749 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700750 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800751 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700752 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700753 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700754 case REQUEST_RECONFIGURE_APPWIDGET:
755 completeRestoreAppWidget(args.appWidgetId);
756 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800757 }
Michael Jurka27614d22012-04-02 06:40:22 -0700758 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
759 // if you turned the screen off and then back while in All Apps, Launcher would not
760 // return to the workspace. Clearing mAddInfo.container here fixes this issue
761 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700762 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800763 }
764
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800765 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700766 protected void onActivityResult(
767 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700768 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700769 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700770 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800771 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700772
Adam Cohenad4e15c2013-10-17 16:21:35 -0700773 Runnable exitSpringLoaded = new Runnable() {
774 @Override
775 public void run() {
776 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
777 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
778 }
779 };
780
Michael Jurka8b805b12012-04-18 14:23:14 -0700781 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700782 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700783 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
784 if (resultCode == RESULT_CANCELED) {
785 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700786 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700787 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700788 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700789 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
790 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700791 }
792 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200793 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
794 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
795 mWorkspace.exitOverviewMode(false);
796 }
797 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700798 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200799
Adam Cohened66b2b2012-01-23 17:28:51 -0800800 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
801 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700802
Adam Cohendb364c32014-05-20 14:23:40 -0700803 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800804 // We have special handling for widgets
805 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800806 final int appWidgetId;
807 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
808 : -1;
809 if (widgetId < 0) {
810 appWidgetId = pendingAddWidgetId;
811 } else {
812 appWidgetId = widgetId;
813 }
814
Adam Cohenad4e15c2013-10-17 16:21:35 -0700815 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800816 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700817 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
818 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700819 result = RESULT_CANCELED;
820 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700821 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700822 @Override
823 public void run() {
824 exitSpringLoadedDragModeDelayed(false, 0, null);
825 }
826 };
Adam Cohendb364c32014-05-20 14:23:40 -0700827 if (workspaceLocked) {
828 // No need to remove the empty screen if we're mid-binding, as the
829 // the bind will not add the empty screen.
830 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
831 } else {
832 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
833 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
834 }
Winson Chung5aaab772012-04-27 15:24:02 -0700835 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700836 if (!workspaceLocked) {
837 mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
838 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
839
840 dropLayout.setDropPending(true);
841 final Runnable onComplete = new Runnable() {
842 @Override
843 public void run() {
844 completeTwoStageWidgetDrop(resultCode, appWidgetId);
845 dropLayout.setDropPending(false);
846 }
847 };
848 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
849 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
850 } else {
851 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
852 mPendingAddInfo);
853 sPendingAddItem = args;
854 }
Winson Chung5aaab772012-04-27 15:24:02 -0700855 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800856 return;
857 }
858
Sunny Goyalff572272014-07-23 13:58:07 -0700859 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
860 if (resultCode == RESULT_OK) {
861 // Update the widget view.
862 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
863 pendingAddWidgetId, mPendingAddInfo);
864 if (workspaceLocked) {
865 sPendingAddItem = args;
866 } else {
867 completeAdd(args);
868 }
869 }
870 // Leave the widget in the pending state if the user canceled the configure.
871 return;
872 }
873
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800874 // The pattern used here is that a user PICKs a specific application,
875 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700876
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800877 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
878 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700879 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700880 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
881 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800882 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700883 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800884 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700885 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700886 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
887 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800888 }
Adam Cohen00074722013-10-11 17:46:09 -0700889 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700890 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700891 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800892 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800893 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800894 }
895
Adam Cohendb364c32014-05-20 14:23:40 -0700896 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
897 appWidgetId, ItemInfo info) {
898 PendingAddArguments args = new PendingAddArguments();
899 args.requestCode = requestCode;
900 args.intent = data;
901 args.container = info.container;
902 args.screenId = info.screenId;
903 args.cellX = info.cellX;
904 args.cellY = info.cellY;
905 args.appWidgetId = appWidgetId;
906 return args;
907 }
908
909 /**
910 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
911 *
912 * @param screenId the screen id to check
913 * @return the new screen, or screenId if it exists
914 */
915 private long ensurePendingDropLayoutExists(long screenId) {
916 CellLayout dropLayout =
917 (CellLayout) mWorkspace.getScreenWithId(screenId);
918 if (dropLayout == null) {
919 // it's possible that the add screen was removed because it was
920 // empty and a re-bind occurred
921 mWorkspace.addExtraEmptyScreen();
922 return mWorkspace.commitExtraEmptyScreen();
923 } else {
924 return screenId;
925 }
926 }
927
Adam Cohened66b2b2012-01-23 17:28:51 -0800928 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700929 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700930 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800931 Runnable onCompleteRunnable = null;
932 int animationType = 0;
933
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700934 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800935 if (resultCode == RESULT_OK) {
936 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
937 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700938 mPendingAddWidgetInfo);
939 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800940 onCompleteRunnable = new Runnable() {
941 @Override
942 public void run() {
943 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700944 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700945 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
946 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800947 }
948 };
949 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800950 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800951 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800952 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700953 if (mDragLayer.getAnimatedView() != null) {
954 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
955 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
956 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700957 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700958 // The animated view may be null in the case of a rotation during widget configuration
959 onCompleteRunnable.run();
960 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800961 }
962
963 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700964 protected void onStop() {
965 super.onStop();
966 FirstFrameAnimatorHelper.setIsVisible(false);
967 }
968
969 @Override
970 protected void onStart() {
971 super.onStart();
972 FirstFrameAnimatorHelper.setIsVisible(true);
973 }
974
975 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800976 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200977 long startTime = 0;
978 if (DEBUG_RESUME_TIME) {
979 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400980 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200981 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800982 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700983
Winson Chung4a2afa32012-07-19 14:53:05 -0700984 // Restore the previous launcher state
985 if (mOnResumeState == State.WORKSPACE) {
986 showWorkspace(false);
987 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c62013-11-06 15:49:51 -0800988 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700989 }
990 mOnResumeState = State.NONE;
991
Craig Mautner360310b2012-10-26 15:13:08 -0700992 // Background was set to gradient in onPause(), restore to black if in all apps.
993 setWorkspaceBackground(mState == State.WORKSPACE);
994
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800995 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700996 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700997 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500998 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400999 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001000 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001001 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001002 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001003 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1004 // execute them here
1005 long startTimeCallbacks = 0;
1006 if (DEBUG_RESUME_TIME) {
1007 startTimeCallbacks = System.currentTimeMillis();
1008 }
1009
1010 if (mAppsCustomizeContent != null) {
1011 mAppsCustomizeContent.setBulkBind(true);
1012 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001013 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1014 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001015 }
1016 if (mAppsCustomizeContent != null) {
1017 mAppsCustomizeContent.setBulkBind(false);
1018 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001019 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001020 if (DEBUG_RESUME_TIME) {
1021 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1022 (System.currentTimeMillis() - startTimeCallbacks));
1023 }
Michael Jurka447bf842013-05-15 14:52:15 +02001024 }
Michael Jurka54554252013-08-01 12:52:23 +02001025 if (mOnResumeCallbacks.size() > 0) {
1026 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1027 mOnResumeCallbacks.get(i).run();
1028 }
1029 mOnResumeCallbacks.clear();
1030 }
Winson Chunge4e50662012-01-23 14:45:13 -08001031
1032 // Reset the pressed state of icons that were locked in the press state while activities
1033 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001034 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001035 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001036 mWaitingForResume.setStayPressed(false);
1037 }
Winson Chunge4e50662012-01-23 14:45:13 -08001038 if (mAppsCustomizeContent != null) {
1039 // Resets the previous all apps icon press state
1040 mAppsCustomizeContent.resetDrawableState();
1041 }
Winson Chung82963d52013-10-09 11:20:57 -07001042
Adam Cohen06dff352012-06-01 17:17:08 -07001043 // It is possible that widgets can receive updates while launcher is not in the foreground.
1044 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1045 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1046 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001047 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001048
Winson Chung780fe592013-09-26 14:48:44 -07001049 // Process any items that were added while Launcher was away.
1050 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1051
Winson Chung5841efa2013-09-30 18:06:44 -07001052 // Update the voice search button proxy
1053 updateVoiceButtonProxyVisible(false);
1054
Adam Cohenf9426d52012-06-04 17:26:21 -07001055 // Again, as with the above scenario, it's possible that one or more of the global icons
1056 // were updated in the wrong orientation.
1057 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001058 if (DEBUG_RESUME_TIME) {
1059 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1060 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001061
1062 if (mWorkspace.getCustomContentCallbacks() != null) {
1063 // If we are resuming and the custom content is the current page, we call onShow().
1064 // It is also poassible that onShow will instead be called slightly after first layout
1065 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1066 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001067 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001068 }
1069 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001070 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001071 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001072
1073 PackageInstallerCompat.getInstance(this).onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001074 }
1075
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001076 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001077 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001078 // Ensure that items added to Launcher are queued until Launcher returns
1079 InstallShortcutReceiver.enableInstallQueue();
Sunny Goyale755d462014-07-22 13:48:29 -07001080 PackageInstallerCompat.getInstance(this).onPause();
Winson Chung997a9232013-07-24 15:33:46 -07001081
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001082 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001083 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001084 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001085 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001086
1087 // We call onHide() aggressively. The custom content callbacks should be able to
1088 // debounce excess onHide calls.
1089 if (mWorkspace.getCustomContentCallbacks() != null) {
1090 mWorkspace.getCustomContentCallbacks().onHide();
1091 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001092 }
Romain Guycbb89e42009-06-08 15:52:54 -07001093
Adam Cohenbffe7452013-07-22 18:21:45 -07001094 QSBScroller mQsbScroller = new QSBScroller() {
1095 int scrollY = 0;
1096
1097 @Override
1098 public void setScrollY(int scroll) {
1099 scrollY = scroll;
1100
1101 if (mWorkspace.isOnOrMovingToCustomContent()) {
1102 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001103 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001104 }
1105 }
1106 };
1107
1108 public void resetQSBScroll() {
1109 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001110 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001111 }
1112
1113 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001114 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1115 // by a onResume or by scrolling otherwise.
1116 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001117
1118 // Custom content is completely hidden
1119 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001120
1121 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1122 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001123
1124 // Indicates whether the user is allowed to scroll away from the custom content.
1125 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001126 }
1127
Jorim Jaggid017f882014-01-14 17:08:48 -08001128 protected boolean hasSettings() {
1129 return false;
1130 }
1131
Adam Cohenbffe7452013-07-22 18:21:45 -07001132 public interface QSBScroller {
1133 public void setScrollY(int scrollY);
1134 }
1135
Winson Chung98ca0f72013-07-29 12:58:51 -07001136 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001137 CustomContentCallbacks callbacks, String description) {
1138 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001139 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001140 }
1141
Adam Cohenedb40762013-07-18 16:45:45 -07001142 // The custom content needs to offset its content to account for the QSB
1143 public int getTopOffsetForCustomContent() {
1144 return mWorkspace.getPaddingTop();
1145 }
1146
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001147 @Override
1148 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001149 // Flag the loader to stop early before switching
1150 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001151 if (mAppsCustomizeContent != null) {
1152 mAppsCustomizeContent.surrender();
1153 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001154 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001155 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001156
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001157 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001158 @Override
1159 public void onWindowFocusChanged(boolean hasFocus) {
1160 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001161 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001162 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001163
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001164 private boolean acceptFilter() {
1165 final InputMethodManager inputManager = (InputMethodManager)
1166 getSystemService(Context.INPUT_METHOD_SERVICE);
1167 return !inputManager.isFullscreenMode();
1168 }
1169
1170 @Override
1171 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001172 final int uniChar = event.getUnicodeChar();
1173 final boolean handled = super.onKeyDown(keyCode, event);
1174 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1175 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001176 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1177 keyCode, event);
1178 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001179 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001180 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001181 // showSearchDialog()
1182 // If there are multiple keystrokes before the search dialog takes focus,
1183 // onSearchRequested() will be called for every keystroke,
1184 // but it is idempotent, so it's fine.
1185 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001186 }
1187 }
1188
Joe Onorato8a9625e2010-01-28 15:55:35 -08001189 // Eat the long press event so the keyboard doesn't come up.
1190 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1191 return true;
1192 }
1193
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001194 return handled;
1195 }
1196
Karl Rosaen138a0412009-04-23 19:00:21 -07001197 private String getTypedText() {
1198 return mDefaultKeySsb.toString();
1199 }
1200
1201 private void clearTypedText() {
1202 mDefaultKeySsb.clear();
1203 mDefaultKeySsb.clearSpans();
1204 Selection.setSelection(mDefaultKeySsb, 0);
1205 }
1206
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001207 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001208 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1209 * State
1210 */
1211 private static State intToState(int stateOrdinal) {
1212 State state = State.WORKSPACE;
1213 final State[] stateValues = State.values();
1214 for (int i = 0; i < stateValues.length; i++) {
1215 if (stateValues[i].ordinal() == stateOrdinal) {
1216 state = stateValues[i];
1217 break;
1218 }
1219 }
1220 return state;
1221 }
1222
1223 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001224 * Restores the previous state, if it exists.
1225 *
1226 * @param savedState The previous state.
1227 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001228 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229 private void restoreState(Bundle savedState) {
1230 if (savedState == null) {
1231 return;
1232 }
1233
Michael Jurka883f55b2010-10-21 15:47:14 -07001234 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001235 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001236 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001237 }
1238
Adam Cohen21cd0022013-10-09 18:57:02 -07001239 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1240 PagedView.INVALID_RESTORE_PAGE);
1241 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001242 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001243 }
1244
Winson Chung3d503fb2011-07-13 17:25:49 -07001245 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001246 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001247
Winson Chung3d503fb2011-07-13 17:25:49 -07001248 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1249 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001250 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001251 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1252 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001253 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1254 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1255 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001256 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001257 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001258 mRestoring = true;
1259 }
1260
1261 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1262 if (renameFolder) {
1263 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001264 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265 mRestoring = true;
1266 }
Winson Chunga12a2502010-12-20 14:41:35 -08001267
Winson Chung785d2eb2011-04-14 16:08:02 -07001268 // Restore the AppsCustomize tab
1269 if (mAppsCustomizeTabHost != null) {
1270 String curTab = savedState.getString("apps_customize_currentTab");
1271 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001272 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001273 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001274 mAppsCustomizeContent.loadAssociatedPages(
1275 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001276 }
1277
Winson Chung5afbf7b2011-07-25 11:53:08 -07001278 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1279 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001280 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001281 mItemIdToViewId = (HashMap<Integer, Integer>)
1282 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001283 }
1284
1285 /**
1286 * Finds all the views we need and configure them properly.
1287 */
1288 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001289 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001290
Craig Mautner360310b2012-10-26 15:13:08 -07001291 mLauncherView = findViewById(R.id.launcher);
Winson Chung4c98d922011-05-31 16:50:48 -07001292 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1293 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001294 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001295 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001296
John Spurlock77e1f472013-09-11 10:09:51 -04001297 mLauncherView.setSystemUiVisibility(
1298 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001299 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001300
Winson Chung4c98d922011-05-31 16:50:48 -07001301 // Setup the drag layer
1302 mDragLayer.setup(this, dragController);
1303
Winson Chung3d503fb2011-07-13 17:25:49 -07001304 // Setup the hotseat
1305 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1306 if (mHotseat != null) {
1307 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001308 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001309 }
1310
Jorim Jaggid017f882014-01-14 17:08:48 -08001311 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001312 View widgetButton = findViewById(R.id.widget_button);
1313 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001314 @Override
1315 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001316 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001317 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001318 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001319 }
1320 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001321 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1322
1323 View wallpaperButton = findViewById(R.id.wallpaper_button);
1324 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001325 @Override
1326 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001327 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001328 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001329 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001330 }
1331 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001332 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1333
1334 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001335 if (hasSettings()) {
1336 settingsButton.setOnClickListener(new OnClickListener() {
1337 @Override
1338 public void onClick(View arg0) {
1339 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001340 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001341 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001342 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001343 });
1344 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1345 } else {
1346 settingsButton.setVisibility(View.GONE);
1347 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1348 lp.gravity = Gravity.END | Gravity.TOP;
1349 widgetButton.requestLayout();
1350 }
1351
Adam Cohendbdff6b2013-09-18 19:09:15 -07001352 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001353
Winson Chung4c98d922011-05-31 16:50:48 -07001354 // Setup the workspace
1355 mWorkspace.setHapticFeedbackEnabled(false);
1356 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001357 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001358 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001359
Winson Chungf0ea4d32011-06-06 14:27:16 -07001360 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001361 mSearchDropTargetBar = (SearchDropTargetBar)
1362 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001363
Winson Chungf0ea4d32011-06-06 14:27:16 -07001364 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001365 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001366 mAppsCustomizeContent = (AppsCustomizePagedView)
1367 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1368 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001369
Winson Chung3d503fb2011-07-13 17:25:49 -07001370 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001371 dragController.setDragScoller(mWorkspace);
1372 dragController.setScrollView(mDragLayer);
1373 dragController.setMoveTarget(mWorkspace);
1374 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001375 if (mSearchDropTargetBar != null) {
1376 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001377 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001378
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001379 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001380 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001381 mWeightWatcher = new WeightWatcher(this);
1382 mWeightWatcher.setAlpha(0.5f);
1383 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001384 new FrameLayout.LayoutParams(
1385 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001386 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001387 Gravity.BOTTOM)
1388 );
Adam Cohen39a06042013-07-19 14:30:12 -07001389
1390 boolean show = shouldShowWeightWatcher();
1391 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001392 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001393 }
1394
1395 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001396 * Sets the all apps button. This method is called from {@link Hotseat}.
1397 */
1398 public void setAllAppsButton(View allAppsButton) {
1399 mAllAppsButton = allAppsButton;
1400 }
1401
1402 public View getAllAppsButton() {
1403 return mAllAppsButton;
1404 }
1405
1406 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001407 * Creates a view representing a shortcut.
1408 *
1409 * @param info The data structure describing the shortcut.
1410 *
1411 * @return A View inflated from R.layout.application.
1412 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001413 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001415 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001416 }
1417
1418 /**
1419 * Creates a view representing a shortcut inflated from the specified resource.
1420 *
1421 * @param layoutResId The id of the XML layout used to create the shortcut.
1422 * @param parent The group the shortcut belongs to.
1423 * @param info The data structure describing the shortcut.
1424 *
1425 * @return A View inflated from layoutResId.
1426 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001427 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001428 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001429 favorite.applyFromShortcutInfo(info, mIconCache, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001430 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001431 return favorite;
1432 }
1433
1434 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001435 * Add a shortcut to the workspace.
1436 *
1437 * @param data The intent describing the shortcut.
1438 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001439 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001440 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001441 int cellY) {
1442 int[] cellXY = mTmpAddItemCellCoordinates;
1443 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001444 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001445
Michael Jurkad3ef3062010-11-23 16:23:58 -08001446 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001447
Adam Cohen558baaf2011-08-15 15:22:57 -07001448 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001449 if (info == null) {
1450 return;
1451 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001452 final View view = createShortcut(info);
1453
Adam Cohenfbba09b2011-07-18 21:43:05 -07001454 // First we check if we already know the exact location where we want to add this item.
1455 if (cellX >= 0 && cellY >= 0) {
1456 cellXY[0] = cellX;
1457 cellXY[1] = cellY;
1458 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001459
1460 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001461 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001462 true, null,null)) {
1463 return;
1464 }
1465 DragObject dragObject = new DragObject();
1466 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001467 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1468 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001469 return;
1470 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001471 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001472 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001473 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001474 foundCellSpan = (result != null);
1475 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001476 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001477 }
1478
1479 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001480 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001481 return;
1482 }
1483
Adam Cohendcd297f2013-06-18 13:13:40 -07001484 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001485
1486 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001487 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001488 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001489 }
1490 }
1491
Adam Cohen2f093b62012-04-30 18:59:53 -07001492 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1493 int minHeight) {
1494 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001495 // We want to account for the extra amount of padding that we are adding to the widget
1496 // to ensure that it gets the full amount of space that it has requested
1497 int requiredWidth = minWidth + padding.left + padding.right;
1498 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001499 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001500 }
1501
Adam Cohen2f093b62012-04-30 18:59:53 -07001502 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1503 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001504 }
1505
Adam Cohen2f093b62012-04-30 18:59:53 -07001506 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1507 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001508 }
1509
Adam Cohen2f093b62012-04-30 18:59:53 -07001510 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1511 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001512 }
1513
Adam Cohen2f093b62012-04-30 18:59:53 -07001514 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1515 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001516 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001517 }
1518
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001519 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001520 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001521 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001522 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001523 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001524 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001525 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001526 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1527 if (appWidgetInfo == null) {
1528 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1529 }
Romain Guycbb89e42009-06-08 15:52:54 -07001530
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001531 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001532 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001533
Adam Cohen2f093b62012-04-30 18:59:53 -07001534 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1535 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001536
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001537 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001538 // We have saved the position to which the widget was dragged-- this really only matters
1539 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001540 int[] cellXY = mTmpAddItemCellCoordinates;
1541 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001542 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001543 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001544 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1545 cellXY[0] = mPendingAddInfo.cellX;
1546 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001547 spanXY[0] = mPendingAddInfo.spanX;
1548 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001549 foundCellSpan = true;
1550 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001551 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001552 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001553 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1554 spanXY[1], cellXY, finalSpan);
1555 spanXY[0] = finalSpan[0];
1556 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001557 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001558 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001559 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001560 }
1561
Michael Jurka0280c3b2010-09-17 15:00:07 -07001562 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001563 if (appWidgetId != -1) {
1564 // Deleting an app widget ID is a void call but writes to disk before returning
1565 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001566 new AsyncTask<Void, Void, Void>() {
1567 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001568 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001569 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001570 }
Michael Jurka43467462013-11-14 12:03:58 +01001571 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001572 }
Winson Chung93eef082012-03-23 15:59:27 -07001573 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001574 return;
1575 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001576
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001577 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001578 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1579 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001580 launcherInfo.spanX = spanXY[0];
1581 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001582 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1583 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Romain Guycbb89e42009-06-08 15:52:54 -07001584
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001585 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001586 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001587
1588 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001589 if (hostView == null) {
1590 // Perform actual inflation because we're live
1591 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1592 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1593 } else {
1594 // The AppWidgetHostView has already been inflated and instantiated
1595 launcherInfo.hostView = hostView;
1596 }
Romain Guycbb89e42009-06-08 15:52:54 -07001597
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001598 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001599 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001600 launcherInfo.notifyWidgetSizeChanged(this);
1601
Adam Cohendcd297f2013-06-18 13:13:40 -07001602 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001603 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001604
1605 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001606 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001607 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001608 }
Romain Guycbb89e42009-06-08 15:52:54 -07001609
Adam Cohended9f8d2010-11-03 13:25:16 -07001610 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1611 @Override
1612 public void onReceive(Context context, Intent intent) {
1613 final String action = intent.getAction();
1614 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1615 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001616 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001617 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001618
Winson Chungc100e8e2011-08-09 16:02:43 -07001619 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001620 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001621 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001622 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001623 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001624 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1625 mUserPresent = true;
1626 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001627 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1628 mModel.resetLoadedState(false, true);
1629 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1630 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1631 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1632 mModel.resetLoadedState(false, true);
1633 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1634 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1635 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001636 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1637 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1638 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001639 }
1640 }
1641 };
1642
1643 @Override
1644 public void onAttachedToWindow() {
1645 super.onAttachedToWindow();
1646
1647 // Listen for broadcasts related to user-presence
1648 final IntentFilter filter = new IntentFilter();
1649 filter.addAction(Intent.ACTION_SCREEN_OFF);
1650 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001651 // For handling managed profiles
1652 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1653 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001654 if (ENABLE_DEBUG_INTENTS) {
1655 filter.addAction(DebugIntents.DELETE_DATABASE);
1656 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1657 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001658 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001659 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001660 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001661 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001662 mVisible = true;
1663 }
1664
Adam Cohen0b395352014-06-09 22:54:36 +00001665 /**
1666 * Sets up transparent navigation and status bars in LMP.
1667 * This method is a no-op for other platform versions.
1668 */
1669 @TargetApi(19)
1670 private void setupTransparentSystemBarsForLmp() {
1671 // TODO(sansid): use the APIs directly when compiling against L sdk.
1672 // Currently we use reflection to access the flags and the API to set the transparency
1673 // on the System bars.
1674 if (Utilities.isLmp()) {
1675 try {
1676 getWindow().getAttributes().systemUiVisibility |=
1677 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1678 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1679 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1680 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1681 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1682 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1683 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1684 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1685
1686 Method setStatusBarColorMethod =
1687 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1688 Method setNavigationBarColorMethod =
1689 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1690 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1691 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1692 } catch (NoSuchFieldException e) {
1693 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1694 } catch (NoSuchMethodException ex) {
1695 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1696 } catch (IllegalAccessException e) {
1697 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1698 } catch (IllegalArgumentException e) {
1699 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1700 } catch (InvocationTargetException e) {
1701 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1702 } finally {}
1703 }
1704 }
1705
Adam Cohended9f8d2010-11-03 13:25:16 -07001706 @Override
1707 public void onDetachedFromWindow() {
1708 super.onDetachedFromWindow();
1709 mVisible = false;
1710
Adam Cohend113e0c2010-11-11 10:48:05 -08001711 if (mAttached) {
1712 unregisterReceiver(mReceiver);
1713 mAttached = false;
1714 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001715 updateRunning();
1716 }
1717
1718 public void onWindowVisibilityChanged(int visibility) {
1719 mVisible = visibility == View.VISIBLE;
1720 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001721 // The following code used to be in onResume, but it turns out onResume is called when
1722 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1723 // is a more appropriate event to handle
1724 if (mVisible) {
1725 mAppsCustomizeTabHost.onWindowVisible();
1726 if (!mWorkspaceLoading) {
1727 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001728 // We want to let Launcher draw itself at least once before we force it to build
1729 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001730 // apps is nice and speedy.
1731 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001732 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001733 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001734 if (mStarted) return;
1735 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001736 // We delay the layer building a bit in order to give
1737 // other message processing a time to run. In particular
1738 // this avoids a delay in hiding the IME if it was
1739 // currently shown, because doing that may involve
1740 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001741 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001742 final ViewTreeObserver.OnDrawListener listener = this;
1743 mWorkspace.post(new Runnable() {
1744 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001745 if (mWorkspace != null &&
1746 mWorkspace.getViewTreeObserver() != null) {
1747 mWorkspace.getViewTreeObserver().
1748 removeOnDrawListener(listener);
1749 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001750 }
1751 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001752 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001753 }
1754 });
1755 }
Michael Jurka6ee21d22012-02-21 18:20:27 -08001756 // When Launcher comes back to foreground, a different Activity might be responsible for
1757 // the app market intent, so refresh the icon
Winson Chungd64a6662013-09-30 11:06:59 -07001758 if (!DISABLE_MARKET_BUTTON) {
1759 updateAppMarketIcon();
1760 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001761 clearTypedText();
1762 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001763 }
1764
1765 private void sendAdvanceMessage(long delay) {
1766 mHandler.removeMessages(ADVANCE_MSG);
1767 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1768 mHandler.sendMessageDelayed(msg, delay);
1769 mAutoAdvanceSentTime = System.currentTimeMillis();
1770 }
1771
1772 private void updateRunning() {
1773 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1774 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1775 mAutoAdvanceRunning = autoAdvanceRunning;
1776 if (autoAdvanceRunning) {
1777 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1778 sendAdvanceMessage(delay);
1779 } else {
1780 if (!mWidgetsToAdvance.isEmpty()) {
1781 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1782 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1783 }
1784 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001785 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001786 }
1787 }
1788 }
1789
1790 private final Handler mHandler = new Handler() {
1791 @Override
1792 public void handleMessage(Message msg) {
1793 if (msg.what == ADVANCE_MSG) {
1794 int i = 0;
1795 for (View key: mWidgetsToAdvance.keySet()) {
1796 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1797 final int delay = mAdvanceStagger * i;
1798 if (v instanceof Advanceable) {
1799 postDelayed(new Runnable() {
1800 public void run() {
1801 ((Advanceable) v).advance();
1802 }
1803 }, delay);
1804 }
1805 i++;
1806 }
1807 sendAdvanceMessage(mAdvanceInterval);
1808 }
1809 }
1810 };
1811
1812 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001813 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001814 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1815 if (v instanceof Advanceable) {
1816 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001817 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001818 updateRunning();
1819 }
1820 }
1821
1822 void removeWidgetToAutoAdvance(View hostView) {
1823 if (mWidgetsToAdvance.containsKey(hostView)) {
1824 mWidgetsToAdvance.remove(hostView);
1825 updateRunning();
1826 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001827 }
1828
Joe Onorato9c1289c2009-08-17 11:03:03 -04001829 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001830 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001831 launcherInfo.hostView = null;
1832 }
1833
Winson Chung93eef082012-03-23 15:59:27 -07001834 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1835 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1836 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001837 }
1838
Winson Chunga6945242014-01-08 14:04:34 -08001839 public DragLayer getDragLayer() {
1840 return mDragLayer;
1841 }
1842
1843 public Workspace getWorkspace() {
1844 return mWorkspace;
1845 }
1846
1847 public Hotseat getHotseat() {
1848 return mHotseat;
1849 }
1850
Jorim Jaggid017f882014-01-14 17:08:48 -08001851 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001852 return mOverviewPanel;
1853 }
1854
1855 public SearchDropTargetBar getSearchBar() {
1856 return mSearchDropTargetBar;
1857 }
1858
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001859 public LauncherAppWidgetHost getAppWidgetHost() {
1860 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001861 }
Romain Guycbb89e42009-06-08 15:52:54 -07001862
Winson Chunga9abd0e2010-10-27 17:18:37 -07001863 public LauncherModel getModel() {
1864 return mModel;
1865 }
1866
Winson Chunga6945242014-01-08 14:04:34 -08001867 public LauncherClings getLauncherClings() {
1868 return mLauncherClings;
1869 }
1870
1871 protected SharedPreferences getSharedPrefs() {
1872 return mSharedPrefs;
1873 }
1874
Bjorn Bringertc459e522013-06-07 19:36:01 +01001875 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001876 getWindow().closeAllPanels();
1877
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001878 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001879 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001880 }
1881
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001882 @Override
1883 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001884 long startTime = 0;
1885 if (DEBUG_RESUME_TIME) {
1886 startTime = System.currentTimeMillis();
1887 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001888 super.onNewIntent(intent);
1889
1890 // Close the menu
1891 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001892 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001893 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001894
Adam Cohened307df2013-10-02 09:37:31 -07001895 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1896 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1897 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001898
Adam Cohen6fecd412013-10-02 17:41:50 -07001899 if (mWorkspace == null) {
1900 // Can be cases where mWorkspace is null, this prevents a NPE
1901 return;
1902 }
1903 Folder openFolder = mWorkspace.getOpenFolder();
1904 // In all these cases, only animate if we're already on home
1905 mWorkspace.exitWidgetResizeMode();
1906 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001907 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001908 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001909 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001910
Adam Cohen6fecd412013-10-02 17:41:50 -07001911 closeFolder();
1912 exitSpringLoadedDragMode();
1913
1914 // If we are already on home, then just animate back to the workspace,
1915 // otherwise, just wait until onResume to set the state back to Workspace
1916 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001917 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001918 } else {
1919 mOnResumeState = State.WORKSPACE;
1920 }
1921
1922 final View v = getWindow().peekDecorView();
1923 if (v != null && v.getWindowToken() != null) {
1924 InputMethodManager imm = (InputMethodManager)getSystemService(
1925 INPUT_METHOD_SERVICE);
1926 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1927 }
1928
1929 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001930 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001931 mAppsCustomizeTabHost.reset();
1932 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001933
1934 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001935 }
Adam Cohened307df2013-10-02 09:37:31 -07001936
Michael Jurka447bf842013-05-15 14:52:15 +02001937 if (DEBUG_RESUME_TIME) {
1938 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1939 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001940 }
1941
Adam Coppa120b8e2013-11-12 16:26:04 +00001942 /**
1943 * Override point for subclasses to prevent movement to the default screen when the home
1944 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1945 */
1946 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1947 return true;
1948 }
1949
1950 /**
1951 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1952 */
1953 protected void onHomeIntent() {
1954 // Do nothing
1955 }
1956
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001957 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001958 public void onRestoreInstanceState(Bundle state) {
1959 super.onRestoreInstanceState(state);
1960 for (int page: mSynchronouslyBoundPages) {
1961 mWorkspace.restoreInstanceStateForChild(page);
1962 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001963 }
1964
1965 @Override
1966 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001967 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001968 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1969 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001970 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001971 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001972
Michael Jurka883f55b2010-10-21 15:47:14 -07001973 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001974 // We close any open folder since it will not be re-opened, and we need to make sure
1975 // this state is reflected.
1976 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001977
Adam Cohendcd297f2013-06-18 13:13:40 -07001978 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001979 mWaitingForResult) {
1980 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001981 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001982 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1983 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001984 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1985 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1986 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001987 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001988 }
1989
1990 if (mFolderInfo != null && mWaitingForResult) {
1991 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1992 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1993 }
Michael Jurka946ad472010-07-09 18:05:18 -07001994
Winson Chung785d2eb2011-04-14 16:08:02 -07001995 // Save the current AppsCustomize tab
1996 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c62013-11-06 15:49:51 -08001997 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1998 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001999 if (currentTabTag != null) {
2000 outState.putString("apps_customize_currentTab", currentTabTag);
2001 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07002002 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
2003 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07002004 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00002005 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002006 }
2007
2008 @Override
2009 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002010 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07002011
Winson Chunge7a03942011-08-05 15:05:12 -07002012 // Remove all pending runnables
2013 mHandler.removeMessages(ADVANCE_MSG);
2014 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07002015 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002016
Winson Chungcd2b0142011-06-08 16:02:26 -07002017 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04002018 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07002019 mModel.stopLoader();
2020 app.setLauncher(null);
2021
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002022 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002023 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002024 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002025 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002026 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002027 mAppWidgetHost = null;
2028
2029 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002030
2031 TextKeyListener.getInstance().release();
2032
Winson Chung81b52252012-08-27 15:34:29 -07002033 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2034 // to prevent leaking Launcher activities on orientation change.
2035 if (mModel != null) {
2036 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2037 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002038
2039 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002040 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002041
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002042 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002043 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002044 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002045 mWorkspace = null;
2046 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002047
Sunny Goyale755d462014-07-22 13:48:29 -07002048 PackageInstallerCompat.getInstance(this).onStop();
Michael Jurka2ecf9952012-06-18 12:52:28 -07002049 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002050 }
2051
Adam Cohena9cf38f2011-05-02 15:36:58 -07002052 public DragController getDragController() {
2053 return mDragController;
2054 }
2055
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002056 @Override
2057 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002058 if (requestCode >= 0) {
2059 setWaitingForResult(true);
2060 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002061 super.startActivityForResult(intent, requestCode);
2062 }
2063
Winson Chung70d72102011-08-12 11:24:35 -07002064 /**
2065 * Indicates that we want global search for this activity by setting the globalSearch
2066 * argument for {@link #startSearch} to true.
2067 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002068 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002069 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002070 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002071
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002072 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002073
Karl Rosaen138a0412009-04-23 19:00:21 -07002074 if (initialQuery == null) {
2075 // Use any text typed in the launcher as the initial query
2076 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002077 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002078 if (appSearchData == null) {
2079 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002080 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002081 }
Winson Chungadf0c182012-08-23 14:59:07 -07002082 Rect sourceBounds = new Rect();
2083 if (mSearchDropTargetBar != null) {
2084 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2085 }
Romain Guycbb89e42009-06-08 15:52:54 -07002086
Bjorn Bringertc459e522013-06-07 19:36:01 +01002087 startSearch(initialQuery, selectInitialQuery,
2088 appSearchData, sourceBounds);
2089 }
2090
2091 public void startSearch(String initialQuery,
2092 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002093 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002094 appSearchData, sourceBounds);
Michael Jurkaa33411c2012-06-14 16:18:21 -07002095 }
2096
2097 /**
2098 * Starts the global search activity. This code is a copied from SearchManager
2099 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002100 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002101 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002102 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002103 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2104 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2105 if (globalSearchActivity == null) {
2106 Log.w(TAG, "No global search activity found.");
2107 return;
2108 }
2109 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2110 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2111 intent.setComponent(globalSearchActivity);
2112 // Make sure that we have a Bundle to put source in
2113 if (appSearchData == null) {
2114 appSearchData = new Bundle();
2115 } else {
2116 appSearchData = new Bundle(appSearchData);
2117 }
2118 // Set source to package name of app that starts global search, if not set already.
2119 if (!appSearchData.containsKey("source")) {
2120 appSearchData.putString("source", getPackageName());
2121 }
2122 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2123 if (!TextUtils.isEmpty(initialQuery)) {
2124 intent.putExtra(SearchManager.QUERY, initialQuery);
2125 }
2126 if (selectInitialQuery) {
2127 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2128 }
2129 intent.setSourceBounds(sourceBounds);
2130 try {
2131 startActivity(intent);
2132 } catch (ActivityNotFoundException ex) {
2133 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2134 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002135 }
2136
Yura4f93ec62014-02-04 14:15:21 +00002137 public boolean isOnCustomContent() {
2138 return mWorkspace.isOnOrMovingToCustomContent();
2139 }
2140
Winson Chung70d72102011-08-12 11:24:35 -07002141 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002142 public boolean onPrepareOptionsMenu(Menu menu) {
2143 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002144 if (!isOnCustomContent()) {
2145 // Close any open folders
2146 closeFolder();
2147 // Stop resizing any widgets
2148 mWorkspace.exitWidgetResizeMode();
2149 if (!mWorkspace.isInOverviewMode()) {
2150 // Show the overview mode
2151 showOverviewMode(true);
2152 } else {
2153 showWorkspace(true);
2154 }
Winson Chunge0298742014-01-17 12:03:00 -08002155 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002156 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002157 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002158
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002159 @Override
2160 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002161 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002162 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002163 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002164 }
2165
Joe Onorato9c1289c2009-08-17 11:03:03 -04002166 public boolean isWorkspaceLocked() {
2167 return mWorkspaceLoading || mWaitingForResult;
2168 }
2169
Adam Cohen517a7f52014-03-01 12:12:59 -08002170 public boolean isWorkspaceLoading() {
2171 return mWorkspaceLoading;
2172 }
2173
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002174 private void setWorkspaceLoading(boolean value) {
2175 boolean isLocked = isWorkspaceLocked();
2176 mWorkspaceLoading = value;
2177 if (isLocked != isWorkspaceLocked()) {
2178 onWorkspaceLockedChanged();
2179 }
2180 }
2181
2182 private void setWaitingForResult(boolean value) {
2183 boolean isLocked = isWorkspaceLocked();
2184 mWaitingForResult = value;
2185 if (isLocked != isWorkspaceLocked()) {
2186 onWorkspaceLockedChanged();
2187 }
2188 }
2189
2190 protected void onWorkspaceLockedChanged() { }
2191
Michael Jurka0280c3b2010-09-17 15:00:07 -07002192 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002193 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002194 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002195 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2196 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002197 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002198 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002199 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002200
Adam Cohenad4e15c2013-10-17 16:21:35 -07002201 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2202 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2203 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2204 }
2205
2206 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2207 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2208 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002209 if (appWidgetInfo.configure != null) {
2210 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002211 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002212
Bjorn Bringert7984c942009-12-09 15:38:25 +00002213 // Launch over to configure widget, if needed
2214 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002215 intent.setComponent(appWidgetInfo.configure);
Bjorn Bringert7984c942009-12-09 15:38:25 +00002216 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Michael Jurkaa805e1a2013-08-22 15:00:33 +02002217 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002218 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002219 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002220 Runnable onComplete = new Runnable() {
2221 @Override
2222 public void run() {
2223 // Exit spring loaded mode if necessary after adding the widget
2224 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2225 null);
2226 }
2227 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002228 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002229 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002230 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002231 }
2232 }
Romain Guycbb89e42009-06-08 15:52:54 -07002233
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002234 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002235 // Close any folders that may be open.
2236 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002237 mWorkspace.moveToCustomContentScreen(animate);
2238 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002239 /**
2240 * Process a shortcut drop.
2241 *
2242 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002243 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002244 * @param cell The cell it should be added to, optional
2245 * @param position The location on the screen where it was dropped, optional
2246 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002247 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002248 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002249 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002250 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002251 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002252 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002253
2254 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002255 mPendingAddInfo.cellX = cell[0];
2256 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002257 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002258
2259 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2260 createShortcutIntent.setComponent(componentName);
2261 processShortcut(createShortcutIntent);
2262 }
2263
Adam Cohenfbba09b2011-07-18 21:43:05 -07002264 /**
2265 * Process a widget drop.
2266 *
2267 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002268 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002269 * @param cell The cell it should be added to, optional
2270 * @param position The location on the screen where it was dropped, optional
2271 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002272 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002273 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002274 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002275 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002276 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002277 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002278 mPendingAddInfo.minSpanX = info.minSpanX;
2279 mPendingAddInfo.minSpanY = info.minSpanY;
2280
Adam Cohenfbba09b2011-07-18 21:43:05 -07002281 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002282 mPendingAddInfo.cellX = cell[0];
2283 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002284 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002285 if (span != null) {
2286 mPendingAddInfo.spanX = span[0];
2287 mPendingAddInfo.spanY = span[1];
2288 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002289
Adam Cohened66b2b2012-01-23 17:28:51 -08002290 AppWidgetHostView hostView = info.boundWidget;
2291 int appWidgetId;
2292 if (hostView != null) {
2293 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002294 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002295 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002296 // In this case, we either need to start an activity to get permission to bind
2297 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002298 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002299 Bundle options = info.bindOptions;
2300
2301 boolean success = false;
2302 if (options != null) {
2303 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2304 info.componentName, options);
2305 } else {
2306 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
2307 info.componentName);
2308 }
2309 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002310 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002311 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002312 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002313 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2314 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2315 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Adam Cohendd70d662012-10-04 16:53:44 -07002316 // TODO: we need to make sure that this accounts for the options bundle.
2317 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002318 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2319 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002320 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002321 }
2322
Joe Onoratodeb98af2010-02-19 14:59:39 -08002323 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002324 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002325 }
2326
Winson Chung24ab2f12010-09-16 14:10:47 -07002327 void processWallpaper(Intent intent) {
2328 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2329 }
2330
Adam Cohendcd297f2013-06-18 13:13:40 -07002331 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002332 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002333 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002334 folderInfo.title = getText(R.string.folder_name);
2335
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002336 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002337 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002338 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002339 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002340
2341 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002342 FolderIcon newFolder =
2343 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002344 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002345 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002346 // Force measure the new folder icon
2347 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2348 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002349 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002350 }
Romain Guycbb89e42009-06-08 15:52:54 -07002351
Joe Onorato9c1289c2009-08-17 11:03:03 -04002352 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002353 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002354 }
2355
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002356 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002357 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002358 }
2359
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002360 /**
2361 * Registers various content observers. The current implementation registers
2362 * only a favorites observer to keep track of the favorites applications.
2363 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002364 private void registerContentObservers() {
2365 ContentResolver resolver = getContentResolver();
2366 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2367 true, mWidgetObserver);
2368 }
2369
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002370 @Override
2371 public boolean dispatchKeyEvent(KeyEvent event) {
2372 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2373 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002374 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002375 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002376 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002377 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002378 dumpState();
2379 return true;
2380 }
2381 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002382 }
2383 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2384 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002385 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002386 return true;
2387 }
2388 }
2389
2390 return super.dispatchKeyEvent(event);
2391 }
2392
Joe Onorato88ec0992009-11-19 13:16:06 -08002393 @Override
2394 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002395 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002396 if (mAppsCustomizeContent.getContentType() ==
2397 AppsCustomizePagedView.ContentType.Applications) {
2398 showWorkspace(true);
2399 } else {
2400 showOverviewMode(true);
2401 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002402 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002403 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002404 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002405 Folder openFolder = mWorkspace.getOpenFolder();
2406 if (openFolder.isEditingName()) {
2407 openFolder.dismissEditingName();
2408 } else {
2409 closeFolder();
2410 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002411 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002412 mWorkspace.exitWidgetResizeMode();
2413
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002414 // Back button is a no-op here, but give at least some feedback for the button press
2415 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002416 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002417 }
2418
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002419 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002420 * Re-listen when widgets are reset.
2421 */
2422 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002423 if (mAppWidgetHost != null) {
2424 mAppWidgetHost.startListening();
2425 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002426 }
2427
2428 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002429 * Launches the intent referred by the clicked shortcut.
2430 *
2431 * @param v The view representing the clicked shortcut.
2432 */
2433 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002434 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2435 // view has detached (it's possible for this to happen if the view is removed mid touch).
2436 if (v.getWindowToken() == null) {
2437 return;
2438 }
2439
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002440 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002441 return;
2442 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002443
Adam Cohen1697b792013-09-17 19:08:21 -07002444 if (v instanceof Workspace) {
2445 if (mWorkspace.isInOverviewMode()) {
2446 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002447 }
2448 return;
2449 }
2450
2451 if (v instanceof CellLayout) {
2452 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002453 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002454 }
2455 }
2456
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002457 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002458 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002459 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002460 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002461 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002462 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002463 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002464 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002465 onClickAllAppsButton(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002466 } else if (tag instanceof LauncherAppWidgetInfo) {
2467 if (v instanceof PendingAppWidgetHostView) {
2468 onClickPendingWidget((PendingAppWidgetHostView) v);
2469 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002470 }
2471 }
2472
Michael Jurka0e260592010-06-30 17:07:39 -07002473 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002474 return false;
2475 }
2476
Michael Jurkaaf442092010-06-10 17:01:57 -07002477 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002478 * Event handler for the app widget view which has not fully restored.
2479 */
2480 public void onClickPendingWidget(PendingAppWidgetHostView v) {
2481 if (v.isReadyForClickSetup()) {
2482 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
2483 int widgetId = info.appWidgetId;
2484 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2485 if (appWidgetInfo != null) {
2486 mPendingAddWidgetInfo = appWidgetInfo;
2487 mPendingAddInfo.copyFrom(info);
2488 mPendingAddWidgetId = widgetId;
2489
2490 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
2491 intent.setComponent(appWidgetInfo.configure);
2492 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, info.appWidgetId);
2493 Utilities.startActivityForResultSafely(this, intent, REQUEST_RECONFIGURE_APPWIDGET);
2494 }
2495 }
2496 }
2497
2498 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002499 * Event handler for the search button
2500 *
2501 * @param v The view that was clicked.
2502 */
2503 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002504 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2505
Amith Yamasania135ba82011-08-09 17:42:01 -07002506 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002507 }
2508
2509 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002510 * Event handler for the voice button
2511 *
2512 * @param v The view that was clicked.
2513 */
2514 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002515 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002516
Bjorn Bringertc459e522013-06-07 19:36:01 +01002517 startVoice();
2518 }
2519
2520 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002521 try {
2522 final SearchManager searchManager =
2523 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2524 ComponentName activityName = searchManager.getGlobalSearchActivity();
2525 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002526 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002527 if (activityName != null) {
2528 intent.setPackage(activityName.getPackageName());
2529 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002530 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002531 } catch (ActivityNotFoundException e) {
2532 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002533 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002534 startActivitySafely(null, intent, "onClickVoiceButton");
2535 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002536 }
2537
2538 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002539 * Event handler for the "grid" button that appears on the home screen, which
2540 * enters all apps mode.
2541 *
2542 * @param v The view that was clicked.
2543 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002544 protected void onClickAllAppsButton(View v) {
2545 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2546 if (isAllAppsVisible()) {
2547 showWorkspace(true);
2548 } else {
2549 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2550 }
2551 }
2552
2553 /**
Mohammadinamul Sheik3b1a54a2014-03-18 11:28:19 -07002554 * Event handler for a paged view icon click.
2555 * @param v The view that was clicked.
2556 * @param appInfo The {link AppInfo} of the view.
2557 */
2558 public void onClickPagedViewIcon(View v, AppInfo appInfo) {
2559 if (LOGD) Log.d(TAG, "onClickPagedViewIcon");
2560 startActivitySafely(v, appInfo.intent, appInfo);
2561 getStats().recordLaunch(appInfo.intent);
2562 }
2563
2564 /**
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002565 * Event handler for an app shortcut click.
2566 *
2567 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2568 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002569 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002570 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2571 Object tag = v.getTag();
2572 if (!(tag instanceof ShortcutInfo)) {
2573 throw new IllegalArgumentException("Input must be a Shortcut");
2574 }
2575
2576 // Open shortcut
2577 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2578 final Intent intent = shortcut.intent;
2579
2580 // Check for special shortcuts
2581 if (intent.getComponent() != null) {
2582 final String shortcutClass = intent.getComponent().getClassName();
2583
2584 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2585 MemoryDumpActivity.startDump(this);
2586 return;
2587 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2588 toggleShowWeightWatcher();
2589 return;
2590 }
2591 }
2592
Chris Wren40c5ed32014-06-24 18:24:23 -04002593 // Check for abandoned promise
2594 if (shortcut.isAbandoned() && v instanceof BubbleTextView) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002595 AlertDialog.Builder builder = new AlertDialog.Builder(this);
2596 builder.setTitle(R.string.abandoned_promises_title);
Chris Wren803a4be2014-07-01 16:52:49 -04002597 builder.setMessage(R.string.abandoned_promise_explanation);
Chris Wren40c5ed32014-06-24 18:24:23 -04002598 builder.setPositiveButton(R.string.abandoned_search,
2599 new DialogInterface.OnClickListener() {
2600 public void onClick(DialogInterface dialog, int id) {
2601 startAppShortcutActivity(v);
2602 }
2603 }
2604 );
Chris Wren40c5ed32014-06-24 18:24:23 -04002605 builder.setNeutralButton(R.string.abandoned_clean_this,
2606 new DialogInterface.OnClickListener() {
2607 public void onClick(DialogInterface dialog, int id) {
2608 final BubbleTextView bubble = (BubbleTextView) v;
2609 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2610 mWorkspace.removeAbandonedPromise(bubble, user);
2611 }
2612 });
2613 builder.create().show();
2614 return;
2615 }
2616
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002617 // Start activities
Chris Wren40c5ed32014-06-24 18:24:23 -04002618 startAppShortcutActivity(v);
2619 }
2620
2621 private void startAppShortcutActivity(View v) {
2622 Object tag = v.getTag();
2623 if (!(tag instanceof ShortcutInfo)) {
2624 throw new IllegalArgumentException("Input must be a Shortcut");
2625 }
2626 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2627 final Intent intent = shortcut.intent;
2628
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002629 int[] pos = new int[2];
2630 v.getLocationOnScreen(pos);
2631 intent.setSourceBounds(new Rect(pos[0], pos[1],
2632 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2633
2634 boolean success = startActivitySafely(v, intent, tag);
2635
2636 mStats.recordLaunch(intent, shortcut);
2637
2638 if (success && v instanceof BubbleTextView) {
2639 mWaitingForResume = (BubbleTextView) v;
2640 mWaitingForResume.setStayPressed(true);
2641 }
2642 }
2643
2644 /**
2645 * Event handler for a folder icon click.
2646 *
2647 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2648 */
2649 protected void onClickFolderIcon(View v) {
2650 if (LOGD) Log.d(TAG, "onClickFolder");
2651 if (!(v instanceof FolderIcon)){
2652 throw new IllegalArgumentException("Input must be a FolderIcon");
2653 }
2654
2655 FolderIcon folderIcon = (FolderIcon) v;
2656 final FolderInfo info = folderIcon.getFolderInfo();
2657 Folder openFolder = mWorkspace.getFolderForTag(info);
2658
2659 // If the folder info reports that the associated folder is open, then verify that
2660 // it is actually opened. There have been a few instances where this gets out of sync.
2661 if (info.opened && openFolder == null) {
2662 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2663 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2664 info.opened = false;
2665 }
2666
2667 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2668 // Close any open folder
2669 closeFolder();
2670 // Open the requested folder
2671 openFolder(folderIcon);
2672 } else {
2673 // Find the open folder...
2674 int folderScreen;
2675 if (openFolder != null) {
2676 folderScreen = mWorkspace.getPageForView(openFolder);
2677 // .. and close it
2678 closeFolder(openFolder);
2679 if (folderScreen != mWorkspace.getCurrentPage()) {
2680 // Close any folder open on the current screen
2681 closeFolder();
2682 // Pull the folder onto this screen
2683 openFolder(folderIcon);
2684 }
2685 }
2686 }
Michael Jurka5130e402011-10-13 04:55:35 -07002687 }
2688
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002689 /**
2690 * Event handler for the (Add) Widgets button that appears after a long press
2691 * on the home screen.
2692 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002693 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002694 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002695 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2696 }
2697
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002698 /**
2699 * Event handler for the wallpaper picker button that appears after a long press
2700 * on the home screen.
2701 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002702 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002703 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2704 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2705 pickWallpaper.setComponent(getWallpaperPickerComponent());
2706 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2707 }
2708
2709 /**
2710 * Event handler for a click on the settings button that appears after a long press
2711 * on the home screen.
2712 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002713 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002714 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2715 }
2716
Michael Jurka5130e402011-10-13 04:55:35 -07002717 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002718 // Provide the same haptic feedback that the system offers for virtual keys.
2719 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002720 }
2721
Adam Cohen61f560d2013-09-30 15:58:20 -07002722 public void performHapticFeedbackOnTouchDown(View v) {
2723 // Provide the same haptic feedback that the system offers for virtual keys.
2724 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2725 }
2726
2727 public View.OnTouchListener getHapticFeedbackTouchListener() {
2728 if (mHapticFeedbackTouchListener == null) {
2729 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2730 @Override
2731 public boolean onTouch(View v, MotionEvent event) {
2732 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2733 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2734 }
2735 return false;
2736 }
2737 };
2738 }
2739 return mHapticFeedbackTouchListener;
2740 }
2741
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002742 public void onClickAppMarketButton(View v) {
Winson Chungd64a6662013-09-30 11:06:59 -07002743 if (!DISABLE_MARKET_BUTTON) {
2744 if (mAppMarketIntent != null) {
2745 startActivitySafely(v, mAppMarketIntent, "app market");
2746 } else {
2747 Log.e(TAG, "Invalid app market intent.");
2748 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002749 }
2750 }
2751
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002752 public void onDragStarted(View view) {}
2753
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002754 /**
2755 * Called when the user stops interacting with the launcher.
2756 * This implies that the user is now on the homescreen and is not doing housekeeping.
2757 */
2758 protected void onInteractionEnd() {}
2759
2760 /**
2761 * Called when the user starts interacting with the launcher.
2762 * The possible interactions are:
2763 * - open all apps
2764 * - reorder an app shortcut, or a widget
2765 * - open the overview mode.
2766 * This is a good time to stop doing things that only make sense
2767 * when the user is on the homescreen and not doing housekeeping.
2768 */
2769 protected void onInteractionBegin() {}
2770
Kenny Guyf07af7b2014-07-31 11:39:16 +01002771 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002772 String packageName = componentName.getPackageName();
Kenny Guyf07af7b2014-07-31 11:39:16 +01002773 try {
2774 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2775 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2776 launcherApps.showAppDetailsForProfile(componentName, user);
2777 } catch (SecurityException e) {
2778 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2779 Log.e(TAG, "Launcher does not have permission to launch settings");
2780 } catch (ActivityNotFoundException e) {
2781 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2782 Log.e(TAG, "Unable to launch settings");
2783 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002784 }
2785
Michael Jurka1e2f4652013-07-08 18:03:46 -07002786 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002787 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2788 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002789 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002790 // System applications cannot be installed. For now, show a toast explaining that.
2791 // We may give them the option of disabling apps this way.
2792 int messageId = R.string.uninstall_system_app_text;
2793 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002794 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002795 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002796 String packageName = componentName.getPackageName();
2797 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002798 Intent intent = new Intent(
2799 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002800 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2801 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002802 if (user != null) {
2803 user.addToIntent(intent, Intent.EXTRA_USER);
2804 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002805 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002806 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002807 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002808 }
2809
Michael Jurka86a720e2012-05-09 11:23:23 -07002810 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002811 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002812 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002813 // Only launch using the new animation if the shortcut has not opted out (this is a
2814 // private contract between launcher and may be ignored in the future).
2815 boolean useLaunchAnimation = (v != null) &&
2816 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002817 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2818 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002819
Kenny Guy1317e2d2014-05-08 18:52:50 +01002820 UserHandleCompat user = null;
2821 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2822 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2823 user = userManager.getUserForSerialNumber(serialNumber);
2824 }
2825
2826 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002827 if (useLaunchAnimation) {
Adam Cohen4da294d2014-07-28 10:56:19 -07002828 ActivityOptions opts = Utilities.isLmp() ?
2829 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) :
2830 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Adam Cohen6ea3b112014-06-11 11:38:49 -07002831 optsBundle = opts.toBundle();
2832 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002833
2834 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2835 // Could be launching some bookkeeping activity
2836 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002837 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002838 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002839 launcherApps.startActivityForProfile(intent.getComponent(), user,
2840 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002841 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002842 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002843 } catch (SecurityException e) {
2844 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002845 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002846 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002847 "or use the exported attribute for this activity. "
2848 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002849 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002850 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002851 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002852
Michael Jurka86a720e2012-05-09 11:23:23 -07002853 boolean startActivitySafely(View v, Intent intent, Object tag) {
2854 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002855 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2856 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2857 return false;
2858 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002859 try {
2860 success = startActivity(v, intent, tag);
2861 } catch (ActivityNotFoundException e) {
2862 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2863 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2864 }
2865 return success;
2866 }
2867
Adam Cohen268c4752012-06-06 17:47:33 -07002868 /**
2869 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2870 * in the DragLayer in the exact absolute location of the original FolderIcon.
2871 */
2872 private void copyFolderIconToImage(FolderIcon fi) {
2873 final int width = fi.getMeasuredWidth();
2874 final int height = fi.getMeasuredHeight();
2875
2876 // Lazy load ImageView, Bitmap and Canvas
2877 if (mFolderIconImageView == null) {
2878 mFolderIconImageView = new ImageView(this);
2879 }
2880 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2881 mFolderIconBitmap.getHeight() != height) {
2882 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2883 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2884 }
2885
2886 DragLayer.LayoutParams lp;
2887 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2888 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2889 } else {
2890 lp = new DragLayer.LayoutParams(width, height);
2891 }
2892
Adam Cohen307fe232012-08-16 17:55:58 -07002893 // The layout from which the folder is being opened may be scaled, adjust the starting
2894 // view size by this scale factor.
2895 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002896 lp.customPosition = true;
2897 lp.x = mRectForFolderAnimation.left;
2898 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002899 lp.width = (int) (scale * width);
2900 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002901
2902 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2903 fi.draw(mFolderIconCanvas);
2904 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002905 if (fi.getFolder() != null) {
2906 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2907 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002908 }
Adam Cohen268c4752012-06-06 17:47:33 -07002909 // Just in case this image view is still in the drag layer from a previous animation,
2910 // we remove it and re-add it.
2911 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2912 mDragLayer.removeView(mFolderIconImageView);
2913 }
2914 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002915 if (fi.getFolder() != null) {
2916 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002917 }
Adam Cohen268c4752012-06-06 17:47:33 -07002918 }
2919
Adam Cohen2801caf2011-05-13 20:57:39 -07002920 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002921 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002922 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2923 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2924 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2925
Adam Cohenc51934b2011-07-26 21:07:43 -07002926 FolderInfo info = (FolderInfo) fi.getTag();
2927 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2928 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002929 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2930 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002931 }
2932
Adam Cohen268c4752012-06-06 17:47:33 -07002933 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2934 copyFolderIconToImage(fi);
2935 fi.setVisibility(View.INVISIBLE);
2936
Michael Jurka2ecf9952012-06-18 12:52:28 -07002937 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002938 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002939 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
2940 oa.start();
2941 }
2942
Adam Cohen268c4752012-06-06 17:47:33 -07002943 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002944 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002945 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2946 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2947 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2948
Adam Cohen268c4752012-06-06 17:47:33 -07002949 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002950
Adam Cohen268c4752012-06-06 17:47:33 -07002951 // We remove and re-draw the FolderIcon in-case it has changed
2952 mDragLayer.removeView(mFolderIconImageView);
2953 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002954 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002955 scaleX, scaleY);
Adam Cohen2801caf2011-05-13 20:57:39 -07002956 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002957 oa.addListener(new AnimatorListenerAdapter() {
2958 @Override
2959 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002960 if (cl != null) {
2961 cl.clearFolderLeaveBehind();
2962 // Remove the ImageView copy of the FolderIcon and make the original visible.
2963 mDragLayer.removeView(mFolderIconImageView);
2964 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002965 }
2966 }
2967 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002968 oa.start();
2969 }
2970
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002971 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002972 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002973 * is animated relative to the specified View. If the View is null, no animation
2974 * is played.
2975 *
2976 * @param folderInfo The FolderInfo describing the folder to open.
2977 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002978 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002979 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002980 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002981
Adam Cohena9cf38f2011-05-02 15:36:58 -07002982 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002983
Adam Cohen4554ee12011-08-03 16:13:21 -07002984 // Just verify that the folder hasn't already been added to the DragLayer.
2985 // There was a one-off crash where the folder had a parent already.
2986 if (folder.getParent() == null) {
2987 mDragLayer.addView(folder);
2988 mDragController.addDropTarget((DropTarget) folder);
2989 } else {
2990 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2991 folder.getParent() + ").");
2992 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002993 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002994 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002995
2996 // Notify the accessibility manager that this folder "window" has appeared and occluded
2997 // the workspace items
2998 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2999 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003000 }
3001
3002 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08003003 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003004 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003005 if (folder.isEditingName()) {
3006 folder.dismissEditingName();
3007 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003008 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07003009
3010 // Dismiss the folder cling
Winson Chunga6945242014-01-08 14:04:34 -08003011 mLauncherClings.dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07003012 }
3013 }
3014
3015 void closeFolder(Folder folder) {
3016 folder.getInfo().opened = false;
3017
3018 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3019 if (parent != null) {
3020 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3021 shrinkAndFadeInFolderIcon(fi);
3022 }
3023 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003024
3025 // Notify the accessibility manager that this folder "window" has disappeard and no
3026 // longer occludeds the workspace items
3027 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003028 }
3029
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003030 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003031 if (!isDraggingEnabled()) return false;
3032 if (isWorkspaceLocked()) return false;
3033 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003034
Adam Cohen1697b792013-09-17 19:08:21 -07003035 if (v instanceof Workspace) {
3036 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07003037 if (mWorkspace.enterOverviewMode()) {
3038 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3039 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3040 return true;
3041 } else {
3042 return false;
3043 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003044 } else {
3045 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003046 }
Adam Cohen1697b792013-09-17 19:08:21 -07003047 }
3048
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003049 CellLayout.CellInfo longClickCellInfo = null;
3050 View itemUnderLongClick = null;
3051 if (v.getTag() instanceof ItemInfo) {
3052 ItemInfo info = (ItemInfo) v.getTag();
3053 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3054 itemUnderLongClick = longClickCellInfo.cell;
3055 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003056 }
3057
Winson Chung3d503fb2011-07-13 17:25:49 -07003058 // The hotseat touch handling does not go through Workspace, and we always allow long press
3059 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003060 final boolean inHotseat = isHotseatLayout(v);
3061 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07003062 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003063 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003064 // User long pressed on empty space
3065 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3066 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003067 if (mWorkspace.isInOverviewMode()) {
3068 mWorkspace.startReordering(v);
3069 } else {
3070 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07003071 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003072 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003073 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3074 mHotseat.getOrderInHotseat(
3075 longClickCellInfo.cellX,
3076 longClickCellInfo.cellY));
3077 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003078 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003079 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003080 }
3081 }
3082 }
3083 return true;
3084 }
3085
Winson Chung3d503fb2011-07-13 17:25:49 -07003086 boolean isHotseatLayout(View layout) {
3087 return mHotseat != null && layout != null &&
3088 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3089 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003090
Winson Chung3d503fb2011-07-13 17:25:49 -07003091 /**
3092 * Returns the CellLayout of the specified container at the specified screen.
3093 */
Adam Cohendcd297f2013-06-18 13:13:40 -07003094 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003095 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3096 if (mHotseat != null) {
3097 return mHotseat.getLayout();
3098 } else {
3099 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003100 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003101 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07003102 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003103 }
3104 }
3105
Daniel Sandler843e8602010-06-07 14:59:01 -04003106 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003107 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003108 }
3109
Craig Mautner360310b2012-10-26 15:13:08 -07003110 private void setWorkspaceBackground(boolean workspace) {
3111 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003112 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003113 }
3114
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003115 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003116 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3117 int curflags = getWindow().getAttributes().flags
3118 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3119 if (wpflags != curflags) {
3120 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3121 }
Craig Mautner360310b2012-10-26 15:13:08 -07003122 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003123 }
3124
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003125 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3126 if (v instanceof LauncherTransitionable) {
3127 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3128 }
3129 }
3130
Michael Jurkabed61d22012-02-14 22:51:29 -08003131 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3132 if (v instanceof LauncherTransitionable) {
3133 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3134 }
Winson Chung70442722012-02-10 15:43:22 -08003135
3136 // Update the workspace transition step as well
3137 dispatchOnLauncherTransitionStep(v, 0f);
3138 }
3139
3140 private void dispatchOnLauncherTransitionStep(View v, float t) {
3141 if (v instanceof LauncherTransitionable) {
3142 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3143 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003144 }
3145
3146 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3147 if (v instanceof LauncherTransitionable) {
3148 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3149 }
Winson Chung70442722012-02-10 15:43:22 -08003150
3151 // Update the workspace transition step as well
3152 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003153 }
3154
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003155 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003156 * Things to test when changing the following seven functions.
3157 * - Home from workspace
3158 * - from center screen
3159 * - from other screens
3160 * - Home from all apps
3161 * - from center screen
3162 * - from other screens
3163 * - Back from all apps
3164 * - from center screen
3165 * - from other screens
3166 * - Launch app from workspace and quit
3167 * - with back
3168 * - with home
3169 * - Launch app from all apps and quit
3170 * - with back
3171 * - with home
3172 * - Go to a screen that's not the default, then all
3173 * apps, and launch and app, and go back
3174 * - with back
3175 * -with home
3176 * - On workspace, long press power and go back
3177 * - with back
3178 * - with home
3179 * - On all apps, long press power and go back
3180 * - with back
3181 * - with home
3182 * - On workspace, power off
3183 * - On all apps, power off
3184 * - Launch an app and turn off the screen while in that app
3185 * - Go back with home key
3186 * - Go back with back key TODO: make this not go to workspace
3187 * - From all apps
3188 * - From workspace
3189 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3190 * - From all apps
3191 * - From the center workspace
3192 * - From another workspace
3193 */
3194
3195 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003196 * Zoom the camera out from the workspace to reveal 'toView'.
3197 * Assumes that the view to show is anchored at either the very top or very bottom
3198 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003199 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003200 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003201 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3202 showAppsCustomizeHelper(animated, springLoaded, contentType);
3203 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003204
Winson Chungc58497e2013-09-03 17:48:37 -07003205 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3206 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003207 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003208 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003209 mStateAnimation.cancel();
3210 mStateAnimation = null;
3211 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003212
3213 boolean material = Utilities.isLmp();
3214
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003215 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003216
Winson Chungf0ea4d32011-06-06 14:27:16 -07003217 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3218 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003219 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003220 final int itemsAlphaStagger =
3221 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003222
Winson Chungf0ea4d32011-06-06 14:27:16 -07003223 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003224 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003225 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07003226 final int startDelay =
3227 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07003228
Adam Cohen6c5891a2014-07-09 23:53:15 -07003229 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3230 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003231 Animator workspaceAnim =
Adam Cohen6c5891a2014-07-09 23:53:15 -07003232 mWorkspace.getChangeStateAnimation(workspaceState, animated);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003233 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003234 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3235 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003236 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3237 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003238
3239 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003240 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen61033d32010-11-15 18:29:44 -08003241
Adam Cohen9bfdb762014-07-21 17:44:06 -07003242 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3243 toView.findViewById(R.id.apps_customize_pane_content);
Adam Cohenf16e5712011-01-13 13:31:45 -08003244
Adam Cohen9bfdb762014-07-21 17:44:06 -07003245 final View page = content.getPageAt(content.getCurrentPage());
3246 final View revealView = toView.findViewById(R.id.fake_page);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003247
Adam Cohen4e243a22014-08-10 18:30:55 -07003248 if (contentType == AppsCustomizePagedView.ContentType.Widgets) {
3249 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3250 } else {
3251 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3252 }
3253
Adam Cohen9bfdb762014-07-21 17:44:06 -07003254 // Hide the real page background, and swap in the fake one
3255 revealView.setVisibility(View.VISIBLE);
3256 content.setPageBackgroundsVisible(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003257
Adam Cohen9bfdb762014-07-21 17:44:06 -07003258 int width = revealView.getMeasuredWidth();
3259 int height = revealView.getMeasuredHeight();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003260
Adam Cohen9bfdb762014-07-21 17:44:06 -07003261 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
3262 float yDrift = height / 2f;
Adam Cohen6c5891a2014-07-09 23:53:15 -07003263
Adam Cohen9bfdb762014-07-21 17:44:06 -07003264 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3265 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", 0.4f, 1f);
3266 PropertyValuesHolder panelDrift =
3267 PropertyValuesHolder.ofFloat("translationY", yDrift, 0f);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003268
Adam Cohen9bfdb762014-07-21 17:44:06 -07003269 ObjectAnimator panelAlphaAndDrift =
3270 ObjectAnimator.ofPropertyValuesHolder(revealView, panelAlpha, panelDrift);
3271 panelAlphaAndDrift.setDuration(revealDuration);
3272 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003273
Adam Cohen9bfdb762014-07-21 17:44:06 -07003274 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003275
Adam Cohen4e243a22014-08-10 18:30:55 -07003276 if (page != null) {
3277 page.setVisibility(View.VISIBLE);
3278 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003279
Adam Cohen4e243a22014-08-10 18:30:55 -07003280 ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0);
3281 pageDrift.setDuration(revealDuration);
3282 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3283 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003284
Adam Cohen4e243a22014-08-10 18:30:55 -07003285 // TODO (adamcohen): remove this 0.01f hack once fw is fixed
3286 // it's there to work around a framework bug (16918357)
3287 page.setAlpha(0.01f);
3288 ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0.01f, 1f);
3289 itemsAlpha.setDuration(revealDuration);
3290 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3291 itemsAlpha.setStartDelay(itemsAlphaStagger);
3292 mStateAnimation.play(itemsAlpha);
3293 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003294
Adam Cohen4e243a22014-08-10 18:30:55 -07003295 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3296 pageIndicators.setAlpha(0.01f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003297 ObjectAnimator indicatorsAlpha =
3298 ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f);
3299 indicatorsAlpha.setDuration(revealDuration);
3300 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003301
Adam Cohen9bfdb762014-07-21 17:44:06 -07003302 if (material) {
3303 ValueAnimator reveal = (ValueAnimator)
Adam Cohen6c5891a2014-07-09 23:53:15 -07003304 ViewAnimationUtils.createCircularReveal(revealView, width / 2,
Adam Cohen9bfdb762014-07-21 17:44:06 -07003305 height / 2, 0f, revealRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003306 reveal.setDuration(revealDuration);
3307 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003308 mStateAnimation.play(reveal);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003309 }
Michael Jurka1899a362011-11-03 13:50:45 -07003310
Adam Cohen9bfdb762014-07-21 17:44:06 -07003311 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3312 @Override
3313 public void onAnimationEnd(Animator animation) {
3314 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3315 dispatchOnLauncherTransitionEnd(toView, animated, false);
3316
3317 revealView.setVisibility(View.INVISIBLE);
3318 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003319 if (page != null) {
3320 page.setLayerType(View.LAYER_TYPE_NONE, null);
3321 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003322 content.setPageBackgroundsVisible(true);
3323
3324 // Hide the search bar
3325 if (mSearchDropTargetBar != null) {
3326 mSearchDropTargetBar.hideSearchBar(false);
3327 }
3328 }
3329
3330 @Override
3331 public void onAnimationStart(Animator animation) {
3332 // Prepare the position
3333 toView.bringToFront();
3334 toView.setVisibility(View.VISIBLE);
3335 }
3336 });
3337
Michael Jurka1899a362011-11-03 13:50:45 -07003338 boolean delayAnim = false;
Adam Cohen6c5891a2014-07-09 23:53:15 -07003339 if (workspaceAnim != null) {
3340 mStateAnimation.play(workspaceAnim);
3341 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003342 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3343 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003344
3345 // If any of the objects being animated haven't been measured/laid out
3346 // yet, delay the animation until we get a layout pass
Michael Jurkabed61d22012-02-14 22:51:29 -08003347 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003348 (mWorkspace.getMeasuredWidth() == 0) ||
3349 (toView.getMeasuredWidth() == 0)) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003350 delayAnim = true;
Michael Jurka1899a362011-11-03 13:50:45 -07003351 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003352
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003353 final AnimatorSet stateAnimation = mStateAnimation;
3354 final Runnable startAnimRunnable = new Runnable() {
3355 public void run() {
3356 // Check that mStateAnimation hasn't changed while
3357 // we waited for a layout/draw pass
3358 if (mStateAnimation != stateAnimation)
3359 return;
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003360 dispatchOnLauncherTransitionStart(fromView, animated, false);
3361 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003362 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003363 }
3364 };
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003365 if (delayAnim) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003366 toView.bringToFront();
3367 toView.setVisibility(View.VISIBLE);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003368 final ViewTreeObserver observer = toView.getViewTreeObserver();
3369 observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
3370 public void onGlobalLayout() {
3371 startAnimRunnable.run();
3372 toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
3373 }
3374 });
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003375 } else {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003376 startAnimRunnable.run();
Michael Jurka1899a362011-11-03 13:50:45 -07003377 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003378 } else {
3379 toView.setTranslationX(0.0f);
3380 toView.setTranslationY(0.0f);
3381 toView.setScaleX(1.0f);
3382 toView.setScaleY(1.0f);
3383 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003384 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003385
Daniel Sandlere4f98912013-06-25 15:13:26 -04003386 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003387 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003388 if (mSearchDropTargetBar != null) {
3389 mSearchDropTargetBar.hideSearchBar(false);
3390 }
Michael Jurkaabded662011-03-04 12:06:57 -08003391 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003392 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003393 dispatchOnLauncherTransitionStart(fromView, animated, false);
3394 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003395 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003396 dispatchOnLauncherTransitionStart(toView, animated, false);
3397 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003398 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003399 }
3400
3401 /**
3402 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003403 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003404 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003405 */
Adam Cohened307df2013-10-02 09:37:31 -07003406 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003407 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003408
Michael Jurkab3e22d92011-10-31 15:58:33 -07003409 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003410 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003411 mStateAnimation.cancel();
3412 mStateAnimation = null;
3413 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003414
3415 boolean material = Utilities.isLmp();
3416
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003417 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003418
Winson Chungf0ea4d32011-06-06 14:27:16 -07003419 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003420 final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
3421 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003422 final int itemsAlphaStagger =
3423 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003424
Winson Chungf0ea4d32011-06-06 14:27:16 -07003425 final float scaleFactor = (float)
3426 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3427 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003428 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003429 Animator workspaceAnim = null;
Adam Cohened307df2013-10-02 09:37:31 -07003430 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003431 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
3432 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003433 toState, animated, stagger, -1);
3434 } else if (toState == Workspace.State.SPRING_LOADED ||
3435 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003436 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohened307df2013-10-02 09:37:31 -07003437 toState, animated);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003438 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003439
Winson Chung4afe9b32011-07-27 17:46:20 -07003440 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003441 if (animated) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003442 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Michael Jurka159b4cc2012-01-17 03:00:35 -08003443
Adam Cohen9bfdb762014-07-21 17:44:06 -07003444 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3445 fromView.findViewById(R.id.apps_customize_pane_content);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003446
Adam Cohen9bfdb762014-07-21 17:44:06 -07003447 final View page = content.getPageAt(content.getNextPage());
3448 final View revealView = fromView.findViewById(R.id.fake_page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003449
Adam Cohen4e243a22014-08-10 18:30:55 -07003450 AppsCustomizePagedView.ContentType contentType = content.getContentType();
3451 if (contentType == AppsCustomizePagedView.ContentType.Widgets) {
3452 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3453 } else {
3454 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3455 }
3456
Adam Cohen9bfdb762014-07-21 17:44:06 -07003457 int width = revealView.getMeasuredWidth();
3458 int height = revealView.getMeasuredHeight();
3459 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003460
Adam Cohen9bfdb762014-07-21 17:44:06 -07003461 // Hide the real page background, and swap in the fake one
3462 revealView.setVisibility(View.VISIBLE);
3463 content.setPageBackgroundsVisible(false);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003464
Adam Cohen9bfdb762014-07-21 17:44:06 -07003465 float yDrift = height / 2f;
Adam Cohen6c5891a2014-07-09 23:53:15 -07003466
Adam Cohen9bfdb762014-07-21 17:44:06 -07003467 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003468
Adam Cohen9bfdb762014-07-21 17:44:06 -07003469 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat(View.ALPHA, 1f, 0f);
3470 PropertyValuesHolder panelDrift =
Adam Cohen4e243a22014-08-10 18:30:55 -07003471 PropertyValuesHolder.ofFloat("translationY", 0, yDrift);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003472 ObjectAnimator panelAlphaAndDrift =
3473 ObjectAnimator.ofPropertyValuesHolder(revealView, panelAlpha, panelDrift);
3474 panelAlphaAndDrift.setDuration(revealDuration);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003475
Adam Cohen9bfdb762014-07-21 17:44:06 -07003476 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3477 panelAlphaAndDrift.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003478
Adam Cohen9bfdb762014-07-21 17:44:06 -07003479 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003480
Adam Cohen4e243a22014-08-10 18:30:55 -07003481 if (page != null) {
3482 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003483
Adam Cohen4e243a22014-08-10 18:30:55 -07003484 ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", 0, yDrift);
3485 pageDrift.setDuration(revealDuration);
3486 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3487 pageDrift.setStartDelay(itemsAlphaStagger);
3488 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003489
Adam Cohen4e243a22014-08-10 18:30:55 -07003490 page.setAlpha(1f);
3491 ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, View.ALPHA, 1f, 0f);
3492 itemsAlpha.setDuration(revealDuration);
3493 itemsAlpha.setInterpolator(new LogDecelerateInterpolator(100, 0));
3494 mStateAnimation.play(itemsAlpha);
3495 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003496
Adam Cohen9bfdb762014-07-21 17:44:06 -07003497 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
Adam Cohen4e243a22014-08-10 18:30:55 -07003498 pageIndicators.setAlpha(1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003499 ObjectAnimator indicatorsAlpha =
Adam Cohen4e243a22014-08-10 18:30:55 -07003500 ObjectAnimator.ofFloat(pageIndicators, "alpha", 0f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003501 indicatorsAlpha.setDuration(revealDuration);
3502 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3503 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003504
Adam Cohen9bfdb762014-07-21 17:44:06 -07003505 width = revealView.getMeasuredWidth();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003506
Adam Cohen9bfdb762014-07-21 17:44:06 -07003507 if (material) {
Nilesh Agrawal300c1502014-07-22 13:20:54 -07003508 Animator reveal =
Adam Cohen6c5891a2014-07-09 23:53:15 -07003509 ViewAnimationUtils.createCircularReveal(revealView, width / 2,
3510 height / 2 + 100, revealRadius, 0f);
3511 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3512 reveal.setDuration(revealDuration);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003513 reveal.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003514
3515 reveal.addListener(new AnimatorListenerAdapter() {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003516 public void onAnimationEnd(Animator animation) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003517 revealView.setVisibility(View.INVISIBLE);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003518 }
3519 });
3520
Adam Cohen6c5891a2014-07-09 23:53:15 -07003521 mStateAnimation.play(reveal);
3522 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003523
3524 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3525 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3526 mAppsCustomizeContent.stopScrolling();
3527
Adam Cohen6c5891a2014-07-09 23:53:15 -07003528 if (workspaceAnim != null) {
3529 mStateAnimation.play(workspaceAnim);
3530 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003531
3532 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003533 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003534 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003535 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003536 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3537 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003538 if (onCompleteRunnable != null) {
3539 onCompleteRunnable.run();
3540 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003541
3542 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003543 if (page != null) {
3544 page.setLayerType(View.LAYER_TYPE_NONE, null);
3545 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003546 content.setPageBackgroundsVisible(true);
Chet Haasebc2f0822012-10-26 17:59:53 -07003547 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003548 }
3549 });
3550
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003551 dispatchOnLauncherTransitionStart(fromView, animated, true);
3552 dispatchOnLauncherTransitionStart(toView, animated, true);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003553 LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003554 } else {
3555 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003556 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003557 dispatchOnLauncherTransitionStart(fromView, animated, true);
3558 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003559 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003560 dispatchOnLauncherTransitionStart(toView, animated, true);
3561 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003562 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003563 }
3564
Michael Jurkae326f182011-11-21 14:05:46 -08003565 @Override
3566 public void onTrimMemory(int level) {
3567 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003568 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003569 mAppsCustomizeTabHost.onTrimMemory();
3570 }
3571 }
3572
Adam Cohened307df2013-10-02 09:37:31 -07003573 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003574 showWorkspace(animated, null);
3575 }
3576
Adam Cohened307df2013-10-02 09:37:31 -07003577 protected void showWorkspace() {
3578 showWorkspace(true);
3579 }
3580
Adam Cohened66b2b2012-01-23 17:28:51 -08003581 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohene25c5d12014-06-18 10:34:58 -07003582 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
Winson Chung2d75f122013-09-23 16:53:31 -07003583 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003584 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003585 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003586
Winson Chungc7d2b602012-05-16 17:02:20 -07003587 // Show the search bar (only animate if we were showing the drop target bar in spring
3588 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003589 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003590 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003591 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003592
Michael Jurkab3e22d92011-10-31 15:58:33 -07003593 // Set focus to the AppsCustomize button
3594 if (mAllAppsButton != null) {
3595 mAllAppsButton.requestFocus();
3596 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003597 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003598
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003599 // Change the state *after* we've called all the transition code
3600 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003601
Winson Chung5fb63472011-02-02 17:03:37 -08003602 // Resume the auto-advance of widgets
3603 mUserPresent = true;
3604 updateRunning();
3605
alanv1d4fde62012-10-17 13:15:47 -07003606 // Send an accessibility event to announce the context change
3607 getWindow().getDecorView()
3608 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003609
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003610 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003611 }
3612
Adam Cohened307df2013-10-02 09:37:31 -07003613 void showOverviewMode(boolean animated) {
3614 mWorkspace.setVisibility(View.VISIBLE);
3615 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3616 mState = State.WORKSPACE;
3617 onWorkspaceShown(animated);
3618 }
3619
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003620 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003621 }
3622
Winson Chung82963d52013-10-09 11:20:57 -07003623 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3624 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003625 if (mState != State.WORKSPACE) return;
3626
Winson Chung82963d52013-10-09 11:20:57 -07003627 if (resetPageToZero) {
3628 mAppsCustomizeTabHost.reset();
3629 }
Winson Chungc58497e2013-09-03 17:48:37 -07003630 showAppsCustomizeHelper(animated, false, contentType);
Adam Cohendcc5e712014-06-23 15:38:55 -04003631 mAppsCustomizeTabHost.post(new Runnable() {
3632 @Override
3633 public void run() {
3634 // We post this in-case the all apps view isn't yet constructed.
3635 mAppsCustomizeTabHost.requestFocus();
3636 }
3637 });
Michael Jurkab3e22d92011-10-31 15:58:33 -07003638
Michael Jurkab3e22d92011-10-31 15:58:33 -07003639 // Change the state *after* we've called all the transition code
3640 mState = State.APPS_CUSTOMIZE;
3641
3642 // Pause the auto-advance of widgets until we are out of AllApps
3643 mUserPresent = false;
3644 updateRunning();
3645 closeFolder();
3646
3647 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003648 getWindow().getDecorView()
3649 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003650 }
3651
Adam Cohen7777d962011-08-18 18:58:38 -07003652 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003653 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003654 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003655 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003656 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003657 }
Adam Cohen7777d962011-08-18 18:58:38 -07003658
Adam Cohenad4e15c2013-10-17 16:21:35 -07003659 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003660 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003661 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3662
Winson Chunge7a03942011-08-05 15:05:12 -07003663 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003664 @Override
3665 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003666 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003667 // Before we show workspace, hide all apps again because
3668 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3669 // clean up our state transition functions
3670 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003671 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003672 } else {
3673 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003674 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003675 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003676 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003677 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003678
Michael Jurkad3ef3062010-11-23 16:23:58 -08003679 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003680 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003681 final boolean animated = true;
3682 final boolean springLoaded = true;
3683 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003684 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003685 }
3686 // Otherwise, we are not in spring loaded mode, so don't do anything.
3687 }
3688
Michael Jurkab3e22d92011-10-31 15:58:33 -07003689 void lockAllApps() {
3690 // TODO
3691 }
3692
3693 void unlockAllApps() {
3694 // TODO
3695 }
3696
Winson Chungf0ea4d32011-06-06 14:27:16 -07003697 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003698 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003699 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003700 void showHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003701 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003702 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003703 if (mHotseat.getAlpha() != 1f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003704 int duration = 0;
3705 if (mSearchDropTargetBar != null) {
3706 duration = mSearchDropTargetBar.getTransitionInDuration();
3707 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003708 mHotseat.animate().alpha(1f).setDuration(duration);
3709 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003710 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003711 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003712 }
3713 }
3714 }
3715
3716 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003717 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003718 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003719 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003720 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003721 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003722 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003723 int duration = 0;
3724 if (mSearchDropTargetBar != null) {
3725 duration = mSearchDropTargetBar.getTransitionOutDuration();
3726 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003727 mHotseat.animate().alpha(0f).setDuration(duration);
3728 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003729 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003730 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003731 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003732 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003733 }
3734
Patrick Dubroy5f445422011-02-18 14:35:21 -08003735 /**
3736 * Add an item from all apps or customize onto the given workspace screen.
3737 * If layout is null, add to the current screen.
3738 */
3739 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003740 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003741 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003742 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003743 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003744
Winson Chungdff8ebb2011-09-08 17:25:31 -07003745 /** Maps the current orientation to an index for referencing orientation correct global icons */
3746 private int getCurrentOrientationIndexForGlobalIcons() {
3747 // default - 0, landscape - 1
3748 switch (getResources().getConfiguration().orientation) {
3749 case Configuration.ORIENTATION_LANDSCAPE:
3750 return 1;
3751 default:
3752 return 0;
3753 }
3754 }
3755
Michael Jurkaae65ee32012-04-30 11:45:54 -07003756 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003757 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003758 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003759 // Look for the toolbar icon specified in the activity meta-data
3760 Bundle metaData = packageManager.getActivityInfo(
3761 activityName, PackageManager.GET_META_DATA).metaData;
3762 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003763 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003764 if (iconResId != 0) {
3765 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003766 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003767 }
3768 }
3769 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003770 // This can happen if the activity defines an invalid drawable
3771 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3772 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003773 } catch (Resources.NotFoundException nfe) {
3774 // This can happen if the activity defines an invalid drawable
3775 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3776 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003777 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003778 return null;
3779 }
3780
3781 // if successful in getting icon, return it; otherwise, set button to use default drawable
3782 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003783 int buttonId, ComponentName activityName, int fallbackDrawableId,
3784 String toolbarResourceName) {
3785 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003786 Resources r = getResources();
3787 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3788 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003789
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003790 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003791 // If we were unable to find the icon via the meta-data, use a generic one
3792 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003793 toolbarIcon = r.getDrawable(fallbackDrawableId);
3794 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003795 if (button != null) {
3796 button.setCompoundDrawables(toolbarIcon, null, null, null);
3797 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003798 return null;
3799 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003800 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003801 if (button != null) {
3802 button.setCompoundDrawables(toolbarIcon, null, null, null);
3803 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003804 return toolbarIcon.getConstantState();
3805 }
3806 }
3807
3808 // if successful in getting icon, return it; otherwise, set button to use default drawable
3809 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003810 int buttonId, ComponentName activityName, int fallbackDrawableId,
3811 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003812 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003813 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003814
Michael Jurka19e0fc52011-07-22 18:00:21 -07003815 if (button != null) {
3816 // If we were unable to find the icon via the meta-data, use a
3817 // generic one
3818 if (toolbarIcon == null) {
3819 button.setImageResource(fallbackDrawableId);
3820 } else {
3821 button.setImageDrawable(toolbarIcon);
3822 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003823 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003824
3825 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3826
Michael Jurka0423dcf2010-10-05 14:56:18 -07003827 }
3828
Winson Chung1b884092012-06-08 17:13:02 -07003829 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003830 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003831 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003832 }
3833
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003834 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003835 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003836 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003837 }
3838
Winson Chungbb185bd2011-11-21 12:31:42 -08003839 private void invalidatePressedFocusedStates(View container, View button) {
3840 if (container instanceof HolographicLinearLayout) {
3841 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3842 layout.invalidatePressedFocusedStates();
3843 } else if (button instanceof HolographicImageView) {
3844 HolographicImageView view = (HolographicImageView) button;
3845 view.invalidatePressedFocusedStates();
3846 }
3847 }
3848
Cristina Stancu476493b2013-08-07 17:20:14 +01003849 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003850 if (mQsb == null) {
3851 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3852 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003853 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003854 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003855 }
3856
3857 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003858 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003859 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003860 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003861 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003862
Winson Chung1cad91e2011-05-25 17:41:01 -07003863 final SearchManager searchManager =
3864 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3865 ComponentName activityName = searchManager.getGlobalSearchActivity();
3866 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003867 int coi = getCurrentOrientationIndexForGlobalIcons();
3868 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003869 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3870 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3871 if (sGlobalSearchIcon[coi] == null) {
3872 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3873 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3874 TOOLBAR_ICON_METADATA_NAME);
3875 }
3876
Winson Chungc51db6a2011-10-05 11:44:49 -07003877 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3878 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003879 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003880 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003881 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003882 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003883 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3884 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003885 if (searchButton != null) searchButton.setVisibility(View.GONE);
3886 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003887 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003888 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003889 }
3890 }
3891
Cristina Stancu476493b2013-08-07 17:20:14 +01003892 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003893 final View searchButtonContainer = findViewById(R.id.search_button_container);
3894 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003895 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003896 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003897 }
3898
Cristina Stancu476493b2013-08-07 17:20:14 +01003899 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003900 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003901 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003902
Winson Chungc51db6a2011-10-05 11:44:49 -07003903 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003904 final SearchManager searchManager =
3905 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3906 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3907
3908 ComponentName activityName = null;
3909 if (globalSearchActivity != null) {
3910 // Check if the global search activity handles voice search
3911 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3912 intent.setPackage(globalSearchActivity.getPackageName());
3913 activityName = intent.resolveActivity(getPackageManager());
3914 }
3915
3916 if (activityName == null) {
3917 // Fallback: check if an activity other than the global search activity
3918 // resolves this
3919 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3920 activityName = intent.resolveActivity(getPackageManager());
3921 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003922 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003923 int coi = getCurrentOrientationIndexForGlobalIcons();
3924 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003925 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3926 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3927 if (sVoiceSearchIcon[coi] == null) {
3928 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3929 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3930 TOOLBAR_ICON_METADATA_NAME);
3931 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003932 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003933 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003934 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003935 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003936 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003937 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07003938 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003939 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003940 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003941 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003942 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003943 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003944
Cristina Stancu476493b2013-08-07 17:20:14 +01003945 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003946 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
3947 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003948 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003949 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003950 }
3951
Winson Chung5841efa2013-09-30 18:06:44 -07003952 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003953 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
3954 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07003955 boolean visible = !forceDisableVoiceButtonProxy &&
3956 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003957 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003958 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01003959 }
3960 }
Winson Chung5841efa2013-09-30 18:06:44 -07003961
3962 /**
3963 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
3964 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
3965 */
3966 public void disableVoiceButtonProxy(boolean disabled) {
3967 updateVoiceButtonProxyVisible(disabled);
3968 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003969 /**
Winson Chungeb66b142011-06-16 13:14:22 -07003970 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003971 */
3972 private void updateAppMarketIcon() {
Winson Chungd64a6662013-09-30 11:06:59 -07003973 if (!DISABLE_MARKET_BUTTON) {
3974 final View marketButton = findViewById(R.id.market_button);
3975 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3976 // Find the app market activity by resolving an intent.
3977 // (If multiple app markets are installed, it will return the ResolverActivity.)
3978 ComponentName activityName = intent.resolveActivity(getPackageManager());
3979 if (activityName != null) {
3980 int coi = getCurrentOrientationIndexForGlobalIcons();
3981 mAppMarketIntent = intent;
3982 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
3983 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo,
3984 TOOLBAR_ICON_METADATA_NAME);
3985 marketButton.setVisibility(View.VISIBLE);
3986 } else {
3987 // We should hide and disable the view so that we don't try and restore the visibility
3988 // of it when we swap between drag & normal states from IconDropTarget subclasses.
3989 marketButton.setVisibility(View.GONE);
3990 marketButton.setEnabled(false);
3991 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003992 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003993 }
3994
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003995 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungd64a6662013-09-30 11:06:59 -07003996 if (!DISABLE_MARKET_BUTTON) {
3997 // Ensure that the new drawable we are creating has the approprate toolbar icon bounds
3998 Resources r = getResources();
3999 Drawable marketIconDrawable = d.newDrawable(r);
4000 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
4001 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
4002 marketIconDrawable.setBounds(0, 0, w, h);
Winson Chung1b884092012-06-08 17:13:02 -07004003
Winson Chungd64a6662013-09-30 11:06:59 -07004004 updateTextButtonWithDrawable(R.id.market_button, marketIconDrawable);
4005 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08004006 }
4007
Michael Jurkad7c28052012-04-27 15:43:36 -07004008 @Override
4009 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07004010 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07004011 final List<CharSequence> text = event.getText();
4012 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07004013 // Populate event with a fake title based on the current state.
4014 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07004015 text.add(mAppsCustomizeTabHost.getContentTag());
alanv1d4fde62012-10-17 13:15:47 -07004016 } else {
4017 text.add(getString(R.string.all_apps_home_button_label));
4018 }
Michael Jurkad7c28052012-04-27 15:43:36 -07004019 return result;
4020 }
4021
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004022 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07004023 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004024 */
4025 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4026 @Override
4027 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004028 closeSystemDialogs();
4029 }
4030 }
4031
4032 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08004033 * Receives notifications whenever the appwidgets are reset.
4034 */
4035 private class AppWidgetResetObserver extends ContentObserver {
4036 public AppWidgetResetObserver() {
4037 super(new Handler());
4038 }
4039
4040 @Override
4041 public void onChange(boolean selfChange) {
4042 onAppWidgetReset();
4043 }
4044 }
4045
4046 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07004047 * If the activity is currently paused, signal that we need to run the passed Runnable
4048 * in onResume.
4049 *
4050 * This needs to be called from incoming places where resources might have been loaded
4051 * while we are paused. That is becaues the Configuration might be wrong
4052 * when we're not running, and if it comes back to what it was when we
4053 * were paused, we are not restarted.
4054 *
4055 * Implementation of the method from LauncherModel.Callbacks.
4056 *
4057 * @return true if we are currently paused. The caller might be able to
4058 * skip some work in that case since we will come back again.
4059 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004060 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004061 if (mPaused) {
4062 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02004063 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07004064 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004065 }
4066 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07004067 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07004068 return true;
4069 } else {
4070 return false;
4071 }
4072 }
4073
Michael Jurkac402cd92013-05-20 15:49:32 +02004074 private boolean waitUntilResume(Runnable run) {
4075 return waitUntilResume(run, false);
4076 }
4077
Michael Jurka1e2f4652013-07-08 18:03:46 -07004078 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02004079 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07004080 }
4081
Michael Jurka7607c2f2013-04-03 14:33:19 -07004082 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004083 * If the activity is currently paused, signal that we need to re-run the loader
4084 * in onResume.
4085 *
4086 * This needs to be called from incoming places where resources might have been loaded
4087 * while we are paused. That is becaues the Configuration might be wrong
4088 * when we're not running, and if it comes back to what it was when we
4089 * were paused, we are not restarted.
4090 *
4091 * Implementation of the method from LauncherModel.Callbacks.
4092 *
4093 * @return true if we are currently paused. The caller might be able to
4094 * skip some work in that case since we will come back again.
4095 */
4096 public boolean setLoadOnResume() {
4097 if (mPaused) {
4098 Log.i(TAG, "setLoadOnResume");
4099 mOnResumeNeedsLoad = true;
4100 return true;
4101 } else {
4102 return false;
4103 }
4104 }
4105
4106 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004107 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004108 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04004109 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07004110 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07004111 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07004112 } else {
4113 return SCREEN_COUNT / 2;
4114 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004115 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07004116
Joe Onorato9c1289c2009-08-17 11:03:03 -04004117 /**
4118 * Refreshes the shortcuts shown on the workspace.
4119 *
4120 * Implementation of the method from LauncherModel.Callbacks.
4121 */
4122 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004123 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08004124
Michael Jurka7607c2f2013-04-03 14:33:19 -07004125 // If we're starting binding all over again, clear any bind calls we'd postponed in
4126 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4127 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07004128 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07004129
Winson Chungd64d1762013-08-20 14:37:16 -07004130 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07004131 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07004132 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07004133
Michael Jurka05bf644e2011-11-30 20:28:53 -08004134 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07004135 if (mHotseat != null) {
4136 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004137 }
4138 }
4139
Adam Cohendcd297f2013-06-18 13:13:40 -07004140 @Override
4141 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07004142 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07004143
Adam Cohen5084cba2013-09-03 12:01:16 -07004144 // If there are no screens, we need to have an empty screen
4145 if (orderedScreenIds.size() == 0) {
4146 mWorkspace.addExtraEmptyScreen();
4147 }
Winson Chung0e6a7132013-08-23 12:55:10 -07004148
4149 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06004150 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05004151 if (hasCustomContentToLeft()) {
4152 mWorkspace.createCustomContentContainer();
4153 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07004154 }
Winson Chung64359a52013-07-08 17:17:08 -07004155 }
4156
4157 @Override
4158 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08004159 // Log to disk
4160 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4161 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4162 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07004163 int count = orderedScreenIds.size();
4164 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07004165 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07004166 }
Adam Cohendcd297f2013-06-18 13:13:40 -07004167 }
4168
Adam Cohen39a06042013-07-19 14:30:12 -07004169 private boolean shouldShowWeightWatcher() {
4170 String spKey = LauncherAppState.getSharedPreferencesKey();
4171 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07004172 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07004173
4174 return show;
4175 }
4176
4177 private void toggleShowWeightWatcher() {
4178 String spKey = LauncherAppState.getSharedPreferencesKey();
4179 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4180 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4181
4182 show = !show;
4183
4184 SharedPreferences.Editor editor = sp.edit();
4185 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4186 editor.commit();
4187
4188 if (mWeightWatcher != null) {
4189 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4190 }
4191 }
4192
Winson Chungd64d1762013-08-20 14:37:16 -07004193 public void bindAppsAdded(final ArrayList<Long> newScreens,
4194 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07004195 final ArrayList<ItemInfo> addAnimated,
4196 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004197 Runnable r = new Runnable() {
4198 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07004199 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07004200 }
4201 };
4202 if (waitUntilResume(r)) {
4203 return;
4204 }
4205
Winson Chungd64d1762013-08-20 14:37:16 -07004206 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08004207 if (newScreens != null) {
4208 bindAddScreens(newScreens);
4209 }
Winson Chungd64d1762013-08-20 14:37:16 -07004210
4211 // We add the items without animation on non-visible pages, and with
4212 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08004213 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004214 bindItems(addNotAnimated, 0,
4215 addNotAnimated.size(), false);
4216 }
Adam Cohen76a47a12014-02-05 11:47:43 -08004217 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004218 bindItems(addAnimated, 0,
4219 addAnimated.size(), true);
4220 }
Winson Chungc58497e2013-09-03 17:48:37 -07004221
Winson Chung87412982013-10-03 18:34:14 -07004222 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004223 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004224
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004225 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004226 addedApps != null && mAppsCustomizeContent != null) {
4227 mAppsCustomizeContent.addApps(addedApps);
4228 }
Winson Chungd64d1762013-08-20 14:37:16 -07004229 }
4230
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004231 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004232 * Bind the items start-end from the list.
4233 *
4234 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004235 */
Winson Chung64359a52013-07-08 17:17:08 -07004236 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4237 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004238 Runnable r = new Runnable() {
4239 public void run() {
4240 bindItems(shortcuts, start, end, forceAnimateIcons);
4241 }
4242 };
4243 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004244 return;
4245 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004246
Winson Chungf0c6ae02012-03-21 16:10:31 -07004247 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004248 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4249 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004250 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004251 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004252 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004253 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004254 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004255
4256 // Short circuit if we are loading dock items for a configuration which has no dock
4257 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4258 mHotseat == null) {
4259 continue;
4260 }
4261
Joe Onorato9c1289c2009-08-17 11:03:03 -04004262 switch (item.itemType) {
4263 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4264 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004265 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004266 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004267
Winson Chung64359a52013-07-08 17:17:08 -07004268 /*
4269 * TODO: FIX collision case
4270 */
Winson Chungce376632013-07-11 16:12:41 -07004271 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4272 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4273 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004274 View v = cl.getChildAt(item.cellX, item.cellY);
4275 Object tag = v.getTag();
4276 String desc = "Collision while binding workspace item: " + item
4277 + ". Collides with " + tag;
4278 if (LauncherAppState.isDogfoodBuild()) {
4279 throw (new RuntimeException(desc));
4280 } else {
4281 Log.d(TAG, desc);
4282 }
Winson Chungce376632013-07-11 16:12:41 -07004283 }
Winson Chung64359a52013-07-08 17:17:08 -07004284 }
4285
Adam Cohendcd297f2013-06-18 13:13:40 -07004286 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4287 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004288 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004289 // Animate all the applications up now
4290 shortcut.setAlpha(0f);
4291 shortcut.setScaleX(0f);
4292 shortcut.setScaleY(0f);
4293 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004294 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004295 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004296 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004297 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004298 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004299 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004300 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004301 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4302 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004303 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004304 default:
4305 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004306 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004307 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004308
Winson Chung997a9232013-07-24 15:33:46 -07004309 if (animateIcons) {
4310 // Animate to the correct page
4311 if (newShortcutsScreenId > -1) {
4312 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004313 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004314 final Runnable startBounceAnimRunnable = new Runnable() {
4315 public void run() {
4316 anim.playTogether(bounceAnims);
4317 anim.start();
4318 }
4319 };
Winson Chung997a9232013-07-24 15:33:46 -07004320 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004321 // We post the animation slightly delayed to prevent slowdowns
4322 // when we are loading right after we return to launcher.
4323 mWorkspace.postDelayed(new Runnable() {
4324 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004325 if (mWorkspace != null) {
4326 mWorkspace.snapToPage(newScreenIndex);
4327 mWorkspace.postDelayed(startBounceAnimRunnable,
4328 NEW_APPS_ANIMATION_DELAY);
4329 }
Winson Chung94d67682013-09-25 16:29:40 -07004330 }
4331 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004332 } else {
4333 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004334 }
4335 }
Winson Chung64359a52013-07-08 17:17:08 -07004336 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004337 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004338 }
4339
Joe Onorato9c1289c2009-08-17 11:03:03 -04004340 /**
4341 * Implementation of the method from LauncherModel.Callbacks.
4342 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004343 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004344 Runnable r = new Runnable() {
4345 public void run() {
4346 bindFolders(folders);
4347 }
4348 };
4349 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004350 return;
4351 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004352 sFolders.clear();
4353 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004354 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004355
4356 /**
4357 * Add the views for a widget to the workspace.
4358 *
4359 * Implementation of the method from LauncherModel.Callbacks.
4360 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004361 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004362 Runnable r = new Runnable() {
4363 public void run() {
4364 bindAppWidget(item);
4365 }
4366 };
4367 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004368 return;
4369 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004370
Daniel Sandler843e8602010-06-07 14:59:01 -04004371 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4372 if (DEBUG_WIDGETS) {
4373 Log.d(TAG, "bindAppWidget: " + item);
4374 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004375 final Workspace workspace = mWorkspace;
4376
Sunny Goyalff572272014-07-23 13:58:07 -07004377 AppWidgetProviderInfo appWidgetInfo;
4378 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4379 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4380
4381 appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
4382 if (appWidgetInfo == null) {
4383 if (DEBUG_WIDGETS) {
4384 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4385 + " belongs to component " + item.providerName
4386 + ", as the povider is null");
4387 }
4388 LauncherModel.deleteItemFromDatabase(this, item);
4389 return;
4390 }
4391 // Note: This assumes that the id remap broadcast is received before this step.
4392 // If that is not the case, the id remap will be ignored and user may see the
4393 // click to setup view.
4394 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4395 pendingInfo.spanX = item.spanX;
4396 pendingInfo.spanY = item.spanY;
4397 pendingInfo.minSpanX = item.minSpanX;
4398 pendingInfo.minSpanY = item.minSpanY;
4399 Bundle options =
4400 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4401
4402 boolean success = false;
4403 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4404 if (options != null) {
4405 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId,
4406 appWidgetInfo.provider, options);
4407 } else {
4408 success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId,
4409 appWidgetInfo.provider);
4410 }
4411
4412 // TODO consider showing a permission dialog when the widget is clicked.
4413 if (!success) {
4414 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4415 if (DEBUG_WIDGETS) {
4416 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4417 + " belongs to component " + item.providerName
4418 + ", as the launcher is unable to bing a new widget id");
4419 }
4420 LauncherModel.deleteItemFromDatabase(this, item);
4421 return;
4422 }
4423
4424 item.appWidgetId = newWidgetId;
4425
4426 // If the widget has a configure activity, it is still needs to set it up, otherwise
4427 // the widget is ready to go.
4428 item.restoreStatus = (appWidgetInfo.configure == null)
4429 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4430 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4431
4432 LauncherModel.updateItemInDatabase(this, item);
4433 }
4434
Sunny Goyal651077b2014-06-30 14:15:31 -07004435 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4436 final int appWidgetId = item.appWidgetId;
4437 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4438 if (DEBUG_WIDGETS) {
4439 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4440 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004441
Sunny Goyal651077b2014-06-30 14:15:31 -07004442 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4443 } else {
4444 appWidgetInfo = null;
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004445 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item);
4446 view.updateIcon(mIconCache);
4447 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004448 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004449 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004450 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004451
Joe Onorato9c1289c2009-08-17 11:03:03 -04004452 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004453 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004454
Adam Cohendcd297f2013-06-18 13:13:40 -07004455 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004456 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004457 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4458
Joe Onorato9c1289c2009-08-17 11:03:03 -04004459 workspace.requestLayout();
4460
Daniel Sandler843e8602010-06-07 14:59:01 -04004461 if (DEBUG_WIDGETS) {
4462 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4463 + (SystemClock.uptimeMillis()-start) + "ms");
4464 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004465 }
4466
Sunny Goyalff572272014-07-23 13:58:07 -07004467 /**
4468 * Restores a pending widget.
4469 *
4470 * @param appWidgetId The app widget id
4471 * @param cellInfo The position on screen where to create the widget.
4472 */
4473 private void completeRestoreAppWidget(final int appWidgetId) {
4474 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4475 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4476 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4477 return;
4478 }
4479
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004480 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004481 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4482
4483 mWorkspace.reinflateWidgetsIfNecessary();
4484 LauncherModel.updateItemInDatabase(this, info);
4485 }
4486
Adam Cohen1462de32012-07-24 22:34:36 -07004487 public void onPageBoundSynchronously(int page) {
4488 mSynchronouslyBoundPages.add(page);
4489 }
4490
Joe Onorato9c1289c2009-08-17 11:03:03 -04004491 /**
4492 * Callback saying that there aren't any more items to bind.
4493 *
4494 * Implementation of the method from LauncherModel.Callbacks.
4495 */
Adam Cohene25af792013-06-06 23:08:25 -07004496 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004497 Runnable r = new Runnable() {
4498 public void run() {
4499 finishBindingItems(upgradePath);
4500 }
4501 };
4502 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004503 return;
4504 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004505 if (mSavedState != null) {
4506 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004507 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004508 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004509 mSavedState = null;
4510 }
4511
Adam Cohen1462de32012-07-24 22:34:36 -07004512 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004513
Winson Chungc51db6a2011-10-05 11:44:49 -07004514 // Update the market app icon as necessary (the other icons will be managed in response to
4515 // package changes in bindSearchablesChanged()
Winson Chungd64a6662013-09-30 11:06:59 -07004516 if (!DISABLE_MARKET_BUTTON) {
4517 updateAppMarketIcon();
4518 }
Michael Jurkac1f5d262011-09-30 19:32:27 -07004519
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004520 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004521 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004522
4523 // If we received the result of any pending adds while the loader was running (e.g. the
4524 // widget configuration forced an orientation change), process them now.
4525 if (sPendingAddItem != null) {
4526 final long screenId = completeAdd(sPendingAddItem);
4527
4528 // TODO: this moves the user to the page where the pending item was added. Ideally,
4529 // the screen would be guaranteed to exist after bind, and the page would be set through
4530 // the workspace restore process.
4531 mWorkspace.post(new Runnable() {
4532 @Override
4533 public void run() {
4534 mWorkspace.snapToScreenId(screenId);
4535 }
4536 });
4537 sPendingAddItem = null;
4538 }
4539
Adam Cohene25af792013-06-06 23:08:25 -07004540 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004541 mWorkspace.getUniqueComponents(true, null);
4542 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004543 }
Sunny Goyale755d462014-07-22 13:48:29 -07004544 PackageInstallerCompat.getInstance(this).onFinishBind();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004545 }
4546
Adam Cohen3ed316a2014-07-23 18:21:20 -07004547 private void sendLoadingCompleteBroadcastIfNecessary() {
4548 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4549 String permission =
4550 getResources().getString(R.string.receive_first_load_broadcast_permission);
4551 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4552 sendBroadcast(intent, permission);
4553 SharedPreferences.Editor editor = mSharedPrefs.edit();
4554 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4555 editor.apply();
4556 }
4557 }
4558
Winson Chunga0b7e862013-09-05 16:03:15 -07004559 public boolean isAllAppsButtonRank(int rank) {
4560 if (mHotseat != null) {
4561 return mHotseat.isAllAppsButtonRank(rank);
4562 }
4563 return false;
4564 }
4565
Winson Chunga2413752012-04-03 14:22:34 -07004566 private boolean canRunNewAppsAnimation() {
4567 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4568 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4569 }
4570
Winson Chungc9168342013-06-26 14:54:55 -07004571 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4572 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4573 PropertyValuesHolder.ofFloat("alpha", 1f),
4574 PropertyValuesHolder.ofFloat("scaleX", 1f),
4575 PropertyValuesHolder.ofFloat("scaleY", 1f));
4576 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4577 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4578 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4579 return bounceAnim;
4580 }
4581
Adam Cohen27772732013-11-11 14:00:56 +00004582 public boolean useVerticalBarLayout() {
4583 return LauncherAppState.getInstance().getDynamicGrid().
4584 getDeviceProfile().isVerticalBarLayout();
4585 }
4586
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004587 protected Rect getSearchBarBounds() {
4588 return LauncherAppState.getInstance().getDynamicGrid().
4589 getDeviceProfile().getSearchBarBounds();
4590 }
4591
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004592 @Override
4593 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004594 boolean searchVisible = updateGlobalSearchIcon();
4595 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004596 if (mSearchDropTargetBar != null) {
4597 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4598 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004599 }
4600
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004601 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004602 * Add the icons for all apps.
4603 *
4604 * Implementation of the method from LauncherModel.Callbacks.
4605 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004606 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004607 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004608 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4609 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4610 getHotseat().addAllAppsFolder(mIconCache, apps,
4611 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4612 }
4613 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004614 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004615 if (mAppsCustomizeContent != null) {
4616 mAppsCustomizeContent.onPackagesUpdated(
4617 LauncherModel.getSortedWidgetsAndShortcuts(this));
4618 }
Winson Chungc58497e2013-09-03 17:48:37 -07004619 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004620 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004621 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004622 mAppsCustomizeContent.onPackagesUpdated(
4623 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004624 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004625 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004626 }
4627
4628 /**
4629 * A package was updated.
4630 *
4631 * Implementation of the method from LauncherModel.Callbacks.
4632 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004633 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004634 Runnable r = new Runnable() {
4635 public void run() {
4636 bindAppsUpdated(apps);
4637 }
4638 };
4639 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004640 return;
4641 }
4642
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004643 if (mWorkspace != null) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004644 mWorkspace.updateShortcutsAndWidgets(apps);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004645 }
Winson Chungc58497e2013-09-03 17:48:37 -07004646
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004647 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004648 mAppsCustomizeContent != null) {
4649 mAppsCustomizeContent.updateApps(apps);
4650 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004651 }
4652
4653 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004654 * Update the state of a package, typically related to install state.
4655 *
4656 * Implementation of the method from LauncherModel.Callbacks.
4657 */
Sunny Goyale755d462014-07-22 13:48:29 -07004658 @Override
4659 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004660 if (mWorkspace != null) {
Sunny Goyale755d462014-07-22 13:48:29 -07004661 mWorkspace.updatePackageState(installInfo);
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004662 }
4663 }
4664
4665 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004666 * A package was uninstalled. We take both the super set of packageNames
4667 * in addition to specific applications to remove, the reason being that
4668 * this can be called when a package is updated as well. In that scenario,
4669 * we only remove specific components from the workspace, where as
4670 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004671 *
4672 * Implementation of the method from LauncherModel.Callbacks.
4673 */
Winson Chung83892cc2013-05-01 16:53:33 -07004674 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004675 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004676 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004677 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004678 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004679 }
Winson Chungd64d1762013-08-20 14:37:16 -07004680 };
4681 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004682 return;
4683 }
4684
Winson Chungdf95eb12013-10-16 14:57:07 -07004685 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004686 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004687 }
4688 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004689 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004690 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004691
Winson Chunga1820962011-10-03 16:31:06 -07004692 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004693 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004694
Winson Chungdf95eb12013-10-16 14:57:07 -07004695 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004696 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004697 mAppsCustomizeContent != null) {
4698 mAppsCustomizeContent.removeApps(appInfos);
4699 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004700 }
Joe Onoratobe386092009-11-17 17:32:16 -08004701
4702 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004703 * A number of packages were updated.
4704 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004705 private ArrayList<Object> mWidgetsAndShortcuts;
4706 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004707 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004708 bindPackagesUpdated(mWidgetsAndShortcuts);
4709 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004710 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004711 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004712 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4713 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4714 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004715 return;
4716 }
4717
Winson Chung64359a52013-07-08 17:17:08 -07004718 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004719 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004720 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004721 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004722 }
4723
Winson Chung400438b2011-01-16 17:53:48 -08004724 private int mapConfigurationOriActivityInfoOri(int configOri) {
4725 final Display d = getWindowManager().getDefaultDisplay();
4726 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4727 switch (d.getRotation()) {
4728 case Surface.ROTATION_0:
4729 case Surface.ROTATION_180:
4730 // We are currently in the same basic orientation as the natural orientation
4731 naturalOri = configOri;
4732 break;
4733 case Surface.ROTATION_90:
4734 case Surface.ROTATION_270:
4735 // We are currently in the other basic orientation to the natural orientation
4736 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4737 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4738 break;
4739 }
4740
4741 int[] oriMap = {
4742 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4743 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4744 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4745 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4746 };
4747 // Since the map starts at portrait, we need to offset if this device's natural orientation
4748 // is landscape.
4749 int indexOffset = 0;
4750 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4751 indexOffset = 1;
4752 }
4753 return oriMap[(d.getRotation() + indexOffset) % 4];
4754 }
Adam Cohen446e9402011-09-15 18:21:21 -07004755
Winson Chung4b919f82012-05-01 10:44:08 -07004756 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004757 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004758 getResources().getBoolean(R.bool.allow_rotation);
4759 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004760 }
Winson Chung4b919f82012-05-01 10:44:08 -07004761 public void lockScreenOrientation() {
4762 if (isRotationEnabled()) {
4763 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4764 .getConfiguration().orientation));
4765 }
4766 }
4767 public void unlockScreenOrientation(boolean immediate) {
4768 if (isRotationEnabled()) {
4769 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004770 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004771 } else {
4772 mHandler.postDelayed(new Runnable() {
4773 public void run() {
4774 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4775 }
4776 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004777 }
Winson Chung4b919f82012-05-01 10:44:08 -07004778 }
Winson Chung400438b2011-01-16 17:53:48 -08004779 }
4780
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004781 /**
4782 * Called when the SearchBar hint should be changed.
4783 *
4784 * @param hint the hint to be displayed in the search bar.
4785 */
4786 protected void onSearchBarHintChanged(String hint) {
Winson Chunga6945242014-01-08 14:04:34 -08004787 mLauncherClings.updateSearchBarHint(hint);
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004788 }
4789
Winson Chunge43a1e72014-01-15 10:33:02 -08004790 protected boolean isLauncherPreinstalled() {
4791 PackageManager pm = getPackageManager();
4792 try {
4793 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4794 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4795 return true;
4796 } else {
4797 return false;
4798 }
4799 } catch (NameNotFoundException e) {
4800 e.printStackTrace();
4801 return false;
4802 }
4803 }
4804
Adam Cohenea90f832014-05-21 15:03:34 -07004805 /**
4806 * This method indicates whether or not we should suggest default wallpaper dimensions
4807 * when our wallpaper cropper was not yet used to set a wallpaper.
4808 */
4809 protected boolean overrideWallpaperDimensions() {
4810 return true;
4811 }
4812
Adam Cohen5eed5d82014-05-19 13:12:13 -07004813 protected boolean shouldClingFocusHotseatApp() {
4814 return false;
4815 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004816 protected String getFirstRunClingSearchBarHint() {
4817 return "";
4818 }
4819 protected String getFirstRunCustomContentHint() {
4820 return "";
4821 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004822 protected int getFirstRunFocusedHotseatAppDrawableId() {
4823 return -1;
4824 }
4825 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4826 return null;
4827 }
4828 protected int getFirstRunFocusedHotseatAppRank() {
4829 return -1;
4830 }
4831 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4832 return "";
4833 }
4834 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4835 return "";
4836 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004837
Winson Chungaf40f202013-09-18 18:26:31 -07004838 public void dismissFirstRunCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004839 mLauncherClings.dismissFirstRunCling(v);
4840 }
4841 public void dismissMigrationClingCopyApps(View v) {
4842 mLauncherClings.dismissMigrationClingCopyApps(v);
4843 }
4844 public void dismissMigrationClingUseDefault(View v) {
4845 mLauncherClings.dismissMigrationClingUseDefault(v);
4846 }
4847 public void dismissMigrationWorkspaceCling(View v) {
4848 mLauncherClings.dismissMigrationWorkspaceCling(v);
Winson Chungaf40f202013-09-18 18:26:31 -07004849 }
Winson Chung82f55532011-08-09 14:14:23 -07004850 public void dismissWorkspaceCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004851 mLauncherClings.dismissWorkspaceCling(v);
Winson Chung7d7541e2011-09-16 20:14:36 -07004852 }
4853 public void dismissFolderCling(View v) {
Winson Chunga6945242014-01-08 14:04:34 -08004854 mLauncherClings.dismissFolderCling(v);
Winson Chung82f55532011-08-09 14:14:23 -07004855 }
Adam Cohen6268f2d2014-05-16 16:42:35 -07004856 public void markFolderClingDismissedIfNecessary() {
4857 mLauncherClings.markFolderClingDismissedIfNecessary();
4858 }
Adam Cohen432609a2014-03-13 17:03:22 -07004859
4860 /**
4861 * To be overridden by subclasses to indicate that there is an activity to launch
4862 * before showing the standard launcher experience.
4863 */
4864 protected boolean hasFirstRunActivity() {
4865 return false;
4866 }
4867
4868 /**
4869 * To be overridden by subclasses to launch any first run activity
4870 */
4871 protected Intent getFirstRunActivity() {
4872 return null;
4873 }
4874
Winson Chunga6945242014-01-08 14:04:34 -08004875 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004876 return !ActivityManager.isRunningInTestHarness() &&
4877 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004878 }
4879
Adam Cohen4a9423d2014-03-28 14:22:31 -07004880 protected boolean hasRunFirstRunActivity() {
4881 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4882 }
4883
Adam Cohen432609a2014-03-13 17:03:22 -07004884 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004885 if (shouldRunFirstRunActivity() &&
4886 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004887 Intent firstRunIntent = getFirstRunActivity();
4888 if (firstRunIntent != null) {
4889 startActivity(firstRunIntent);
4890 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004891 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004892 }
4893 }
Adam Cohen432609a2014-03-13 17:03:22 -07004894 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004895 }
4896
4897 private void markFirstRunActivityShown() {
4898 SharedPreferences.Editor editor = mSharedPrefs.edit();
4899 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4900 editor.apply();
4901 }
4902
Adam Cohen432609a2014-03-13 17:03:22 -07004903 /**
4904 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4905 * screen that must be displayed and dismissed.
4906 */
4907 protected boolean hasDismissableIntroScreen() {
4908 return false;
4909 }
4910
4911 /**
4912 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4913 */
4914 protected View getIntroScreen() {
4915 return null;
4916 }
4917
4918 /**
4919 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4920 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4921 */
4922 private boolean shouldShowIntroScreen() {
4923 return hasDismissableIntroScreen() &&
4924 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4925 }
4926
4927 protected void showIntroScreen() {
4928 View introScreen = getIntroScreen();
4929 changeWallpaperVisiblity(false);
4930 if (introScreen != null) {
4931 mDragLayer.showOverlayView(introScreen);
4932 }
4933 }
4934
4935 public void dismissIntroScreen() {
4936 markIntroScreenDismissed();
4937 if (showFirstRunActivity()) {
4938 // We delay hiding the intro view until the first run activity is showing. This
4939 // avoids a blip.
4940 mWorkspace.postDelayed(new Runnable() {
4941 @Override
4942 public void run() {
4943 mDragLayer.dismissOverlayView();
4944 }
4945 }, ACTIVITY_START_DELAY);
4946 } else {
4947 mDragLayer.dismissOverlayView();
4948 }
4949 changeWallpaperVisiblity(true);
4950 }
4951
4952 private void markIntroScreenDismissed() {
4953 SharedPreferences.Editor editor = mSharedPrefs.edit();
4954 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4955 editor.apply();
4956 }
4957
Winson Chunga6945242014-01-08 14:04:34 -08004958 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004959 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4960 if (mHotseat != null) mHotseat.setAlpha(1f);
4961 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4962 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004963 }
4964
4965 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004966 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4967 if (mHotseat != null) mHotseat.setAlpha(0f);
4968 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4969 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004970 }
4971
Mathew Inwood72fbec12013-11-19 15:45:07 +00004972 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004973 // Called from search suggestion, not supported in other profiles.
4974 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4975 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4976 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4977 myUser);
4978 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004979 return null;
4980 }
Kenny Guyed131872014-04-30 03:02:21 +01004981 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004982 }
4983
4984 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4985 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004986 // Called from search suggestion, not supported in other profiles.
4987 return createShortcutDragInfo(shortcutIntent, caption, icon,
4988 UserHandleCompat.myUserHandle());
4989 }
4990
4991 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4992 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01004993 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01004994 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01004995 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004996 }
4997
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004998 protected void moveWorkspaceToDefaultScreen() {
4999 mWorkspace.moveToDefaultScreen(false);
5000 }
5001
Mathew Inwood72fbec12013-11-19 15:45:07 +00005002 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
5003 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07005004 mWorkspace.onExternalDragStartedWithItem(dragView);
5005 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005006 }
5007
Anjali Koppalf5d29132014-02-28 13:33:27 -08005008 @Override
5009 public void onPageSwitch(View newPage, int newPageIndex) {
5010 }
5011
Winson Chung80baf5a2010-08-09 16:03:15 -07005012 /**
Joe Onoratobe386092009-11-17 17:32:16 -08005013 * Prints out out state for debugging.
5014 */
5015 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04005016 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08005017 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08005018 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
5019 Log.d(TAG, "mRestoring=" + mRestoring);
5020 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
5021 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07005022 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08005023 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07005024
Winson Chung785d2eb2011-04-14 16:08:02 -07005025 if (mAppsCustomizeContent != null) {
5026 mAppsCustomizeContent.dumpState();
5027 }
Daniel Sandler325dc232013-06-05 22:57:57 -04005028 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08005029 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005030
5031 @Override
5032 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5033 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07005034 synchronized (sDumpLogs) {
5035 writer.println(" ");
5036 writer.println("Debug logs: ");
5037 for (int i = 0; i < sDumpLogs.size(); i++) {
5038 writer.println(" " + sDumpLogs.get(i));
5039 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005040 }
5041 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005042
5043 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07005044 if (DEBUG_DUMP_LOG) {
5045 synchronized (sDumpLogs) {
5046 Log.d(TAG, "");
5047 Log.d(TAG, "*********************");
5048 Log.d(TAG, "Launcher debug logs: ");
5049 for (int i = 0; i < sDumpLogs.size(); i++) {
5050 Log.d(TAG, " " + sDumpLogs.get(i));
5051 }
5052 Log.d(TAG, "*********************");
5053 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07005054 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005055 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005056 }
5057
5058 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005059 addDumpLog(tag, log, null, debugLog);
5060 }
5061
5062 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07005063 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005064 if (e != null) {
5065 Log.d(tag, log, e);
5066 } else {
5067 Log.d(tag, log);
5068 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005069 }
Winson Chungede41292013-09-19 16:27:36 -07005070 if (DEBUG_DUMP_LOG) {
5071 sDateStamp.setTime(System.currentTimeMillis());
5072 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05005073 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5074 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07005075 }
Winson Chungede41292013-09-19 16:27:36 -07005076 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005077 }
5078
Winson Chungede41292013-09-19 16:27:36 -07005079 public void dumpLogsToLocalData() {
5080 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01005081 new AsyncTask<Void, Void, Void>() {
5082 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07005083 boolean success = false;
5084 sDateStamp.setTime(sRunStart);
5085 String FILENAME = sDateStamp.getMonth() + "-"
5086 + sDateStamp.getDay() + "_"
5087 + sDateStamp.getHours() + "-"
5088 + sDateStamp.getMinutes() + "_"
5089 + sDateStamp.getSeconds() + ".txt";
5090
5091 FileOutputStream fos = null;
5092 File outFile = null;
5093 try {
5094 outFile = new File(getFilesDir(), FILENAME);
5095 outFile.createNewFile();
5096 fos = new FileOutputStream(outFile);
5097 } catch (Exception e) {
5098 e.printStackTrace();
5099 }
5100 if (fos != null) {
5101 PrintWriter writer = new PrintWriter(fos);
5102
5103 writer.println(" ");
5104 writer.println("Debug logs: ");
5105 synchronized (sDumpLogs) {
5106 for (int i = 0; i < sDumpLogs.size(); i++) {
5107 writer.println(" " + sDumpLogs.get(i));
5108 }
5109 }
5110 writer.close();
5111 }
5112 try {
5113 if (fos != null) {
5114 fos.close();
5115 success = true;
5116 }
5117 } catch (IOException e) {
5118 e.printStackTrace();
5119 }
Michael Jurka43467462013-11-14 12:03:58 +01005120 return null;
Winson Chungede41292013-09-19 16:27:36 -07005121 }
Michael Jurka43467462013-11-14 12:03:58 +01005122 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07005123 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005124 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08005125}
Michael Jurka2763be32011-02-24 11:19:57 -08005126
Michael Jurkaabded662011-03-04 12:06:57 -08005127interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08005128 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07005129 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08005130 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08005131 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08005132 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08005133}
Dan Sandlerd5024042014-01-09 15:01:33 -05005134
5135interface DebugIntents {
5136 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5137 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00005138}