blob: 221a8cf09ced5e7c7fd303b4e237a478a12ae87d [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
Jose Pascoal05218202014-11-19 11:17:38 +000018package com.fairphone.fplauncher3;
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;
Adam Cohen2854d252014-08-27 16:04:07 -070025import android.animation.TimeInterpolator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070026import android.animation.ValueAnimator;
Adam Cohen0b395352014-06-09 22:54:36 +000027import android.annotation.TargetApi;
Michael Jurka946ad472010-07-09 18:05:18 -070028import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070029import android.app.ActivityManager;
Winson Chungc7450e32012-04-17 17:34:08 -070030import android.app.ActivityOptions;
Chris Wren40c5ed32014-06-24 18:24:23 -040031import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080033import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
Chris Wren40c5ed32014-06-24 18:24:23 -040042import android.content.DialogInterface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070044import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070045import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
Winson Chunge43a1e72014-01-15 10:33:02 -080047import android.content.pm.ApplicationInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070049import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070051import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080052import android.database.ContentObserver;
Adam Cohen268c4752012-06-06 17:47:33 -070053import android.graphics.Bitmap;
54import android.graphics.Canvas;
Sandeep Siddhartha2efc7d92014-05-16 17:21:15 -070055import android.graphics.Color;
Winson Chung5f8afe62013-08-12 16:19:28 -070056import android.graphics.Point;
Adam Cohen268c4752012-06-06 17:47:33 -070057import android.graphics.PorterDuff;
Michael Jurkaaf442092010-06-10 17:01:57 -070058import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040060import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070061import android.os.AsyncTask;
Adam Cohen0f668f32014-09-08 19:54:17 +020062import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080063import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020064import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080065import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070066import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070067import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040068import android.os.SystemClock;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080069import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.text.Selection;
71import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070072import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070074import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070075import android.util.Log;
Sunny Goyalf8763012014-09-23 16:22:10 -070076import android.view.ContextThemeWrapper;
Adam Cohen96d30a12013-07-16 18:13:21 -070077import android.view.Display;
78import android.view.Gravity;
79import android.view.HapticFeedbackConstants;
80import android.view.KeyEvent;
81import android.view.LayoutInflater;
82import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070083import android.view.MotionEvent;
84import android.view.Surface;
85import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070086import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080087import android.view.View.OnLongClickListener;
Adam Cohen2854d252014-08-27 16:04:07 -070088import android.view.ViewAnimationUtils;
Adam Cohen96d30a12013-07-16 18:13:21 -070089import android.view.ViewGroup;
90import android.view.ViewTreeObserver;
Sunny Goyal651077b2014-06-30 14:15:31 -070091import android.view.Window;
Adam Cohen96d30a12013-07-16 18:13:21 -070092import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080093import android.view.accessibility.AccessibilityEvent;
Adam Cohen9bfdb762014-07-21 17:44:06 -070094import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080095import android.view.animation.DecelerateInterpolator;
Jose Pascoal0f0b6782015-01-22 17:31:23 +000096import android.view.animation.OvershootInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070098import android.widget.Advanceable;
99import android.widget.FrameLayout;
100import android.widget.ImageView;
101import android.widget.TextView;
102import android.widget.Toast;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700103
Jose Pascoal05218202014-11-19 11:17:38 +0000104import com.fairphone.fplauncher3.R;
105import com.fairphone.fplauncher3.DropTarget.DragObject;
106import com.fairphone.fplauncher3.PagedView.PageSwitchListener;
Jose Pascoal3c0767e2014-12-03 18:52:04 +0000107import com.fairphone.fplauncher3.applifecycle.AppDrawerView;
Jose Pascoal05218202014-11-19 11:17:38 +0000108import com.fairphone.fplauncher3.compat.AppWidgetManagerCompat;
109import com.fairphone.fplauncher3.compat.LauncherActivityInfoCompat;
110import com.fairphone.fplauncher3.compat.LauncherAppsCompat;
111import com.fairphone.fplauncher3.compat.PackageInstallerCompat;
112import com.fairphone.fplauncher3.compat.UserHandleCompat;
113import com.fairphone.fplauncher3.compat.UserManagerCompat;
114import com.fairphone.fplauncher3.compat.PackageInstallerCompat.PackageInstallInfo;
Jose Pascoala046c672014-11-26 19:46:03 +0000115import com.fairphone.fplauncher3.edgeswipe.EdgeSwipeMenu;
Jose Pascoalec3574b2014-12-02 19:53:40 +0000116import com.fairphone.fplauncher3.edgeswipe.editor.AppDiscoverer;
Jose Pascoald1f7ac92014-11-25 19:12:02 +0000117import com.fairphone.fplauncher3.edgeswipe.editor.EditFavoritesActivity;
Filiped63c86b2015-07-31 12:29:22 +0000118import com.fairphone.fplauncher3.oobe.OOBEActivity;
Jose Pascoalca875e52014-11-24 12:34:59 +0000119import com.fairphone.fplauncher3.widgets.appswitcher.AppSwitcherManager;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700120
Adam Cohenc0dcf592011-06-01 15:30:43 -0700121import java.io.DataInputStream;
122import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700123import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700124import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700125import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700126import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700127import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700128import java.io.PrintWriter;
Adam Cohen0b395352014-06-09 22:54:36 +0000129import java.lang.reflect.Field;
130import java.lang.reflect.InvocationTargetException;
131import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700132import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700133import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700134import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700135import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700136import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700137import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000138import java.util.concurrent.atomic.AtomicInteger;
telmo.agostinhof8e60ba2015-10-29 15:33:41 +0000139import com.android.internal.telephony.cat.AppInterface;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700140
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141/**
142 * Default launcher application.
143 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100144public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700145 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700146 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800147 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700148 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149
Daniel Sandlerf061f822013-06-27 13:59:36 -0400150 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400151 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700152 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400153 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700154 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700155
Dan Sandlerd5024042014-01-09 15:01:33 -0500156 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
157
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700159 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700161 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700162 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163
Michael Jurka8b805b12012-04-18 14:23:14 -0700164 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700165 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Jose Pascoalfa945132014-11-25 12:57:42 +0000166
167 private static final int REQUEST_PICK_SETTINGS = 98;
Jose Pascoald1f7ac92014-11-25 19:12:02 +0000168 private static final int REQUEST_EDIT_FAVORITES = 99;
Michael Jurka8b805b12012-04-18 14:23:14 -0700169
Filiped63c86b2015-07-31 12:29:22 +0000170 //OOBE setting
171 private static final String SHOW_OOBE_EDIT_FAVORITES = "SHOW_FP_OOBE_EDIT_FAVORITES";
172 private static final String SHOW_OOBE_EDGE_SWIPE_MENU = "SHOW_FP_OOBE_EDGE_SWIPE_MENU";
173 private static final String SHOW_VALUES_VIDEO = "SHOW_FAIRPHONE_VALUES_VIDEO";
174
Mathew Inwood876a8462013-06-14 14:12:41 +0100175 /**
176 * IntentStarter uses request codes starting with this. This must be greater than all activity
177 * request codes used internally.
178 */
179 protected static final int REQUEST_LAST = 100;
180
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
182
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800183 static final int SCREEN_COUNT = 5;
184 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185
Romain Guy98d01652009-06-30 16:21:04 -0700186 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800187 // To turn on these properties, type
188 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
189 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
190 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800191 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192
Winson Chung2672ff92012-05-04 16:22:30 -0700193 // The Intent extra that defines whether to ignore the launch animation
194 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400195 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700196
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800197 // Type: int
198 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700199 // Type: int
200 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800201 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700202 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
203 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
205 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700206 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700208 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800209 // Type: boolean
210 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
211 // Type: long
212 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700213 // Type: int
214 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
215 // Type: int
216 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
217 // Type: parcelable
218 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000219 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800220 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000221 // Type: int[]
222 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800223
Adam Cohen432609a2014-03-13 17:03:22 -0700224 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800225 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
226
Adam Cohen3ed316a2014-07-23 18:21:20 -0700227 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
228 static final String ACTION_FIRST_LOAD_COMPLETE =
229 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
230
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100231 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700232 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100233 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700234 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100235 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700236
Adam Cohen39a06042013-07-19 14:30:12 -0700237 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700238 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700239
Winson Chunga6945242014-01-08 14:04:34 -0800240 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
241
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700242 /** The different states that Launcher can be in. */
Jose Pascoal3379bd12015-02-10 12:34:48 +0000243 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED }
244
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700245 private State mState = State.WORKSPACE;
246 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700247
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700248 private boolean mIsSafeModeEnabled;
249
Joe Onorato9c1289c2009-08-17 11:03:03 -0400250 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700251 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
252 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700253 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800254
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800255 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800256 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800257
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000258 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
259 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
260
Winson Chunga2413752012-04-03 14:22:34 -0700261 // How long to wait before the new-shortcut animation automatically pans the workspace
Jose Pascoalf354dfe2015-02-10 19:21:21 +0000262 private static final int NEW_APPS_PAGE_MOVE_DELAY = 500;
263 private static final int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
264 private static final int NEW_APPS_ANIMATION_DELAY = 500;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700265 private static final int SINGLE_FRAME_DELAY = 16;
Winson Chunga2413752012-04-03 14:22:34 -0700266
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800267 private final BroadcastReceiver mCloseSystemDialogsReceiver
268 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800269 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
270
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800271 private LayoutInflater mInflater;
272
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800273 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700274 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800275 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800276 private DragLayer mDragLayer;
277 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700278 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700279
Sunny Goyalffe83f12014-08-14 17:39:34 -0700280 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700281 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700282
Jose Pascoalf354dfe2015-02-10 19:21:21 +0000283 private final ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700284 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800285 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700286
Jose Pascoalf354dfe2015-02-10 19:21:21 +0000287 private final int[] mTmpAddItemCellCoordinates = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -0700288
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800289 private FolderInfo mFolderInfo;
290
Jorim Jaggid017f882014-01-14 17:08:48 -0800291 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700292
Michael Jurka838a4ca2011-02-07 13:33:06 -0800293 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700294
Winson Chungc51db6a2011-10-05 11:44:49 -0700295 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700296 private AppsCustomizeTabHost mAppsCustomizeTabHost;
297 private AppsCustomizePagedView mAppsCustomizeContent;
298 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800299
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800300 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700301 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
302 // scroll issues (because the workspace may not have been measured yet) and extra work.
303 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
304 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800305
306 private SpannableStringBuilder mDefaultKeySsb = null;
307
Joe Onorato9c1289c2009-08-17 11:03:03 -0400308 private boolean mWorkspaceLoading = true;
309
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800310 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800311 private boolean mRestoring;
312 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700313 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800314
Jose Pascoalf354dfe2015-02-10 19:21:21 +0000315 private final ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
316 private final ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700317
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800318 private Bundle mSavedInstanceState;
319
Joe Onorato9c1289c2009-08-17 11:03:03 -0400320 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800321 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800322 private boolean mUserPresent = true;
323 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700324 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800325 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400326
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700327 private static LocaleConfiguration sLocaleConfiguration = null;
328
Jose Pascoalf354dfe2015-02-10 19:21:21 +0000329 private static final HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700330
Adam Cohen61f560d2013-09-30 15:58:20 -0700331 private View.OnTouchListener mHapticFeedbackTouchListener;
332
Adam Cohended9f8d2010-11-03 13:25:16 -0700333 // Related to the auto-advancing of widgets
Jose Pascoal76701272015-02-11 19:12:01 +0000334 private static final int ADVANCE_MSG = 1;
335 private static final int mAdvanceInterval = 20000;
336 private static final int mAdvanceStagger = 250;
Adam Cohended9f8d2010-11-03 13:25:16 -0700337 private long mAutoAdvanceSentTime;
338 private long mAutoAdvanceTimeLeft = -1;
Jose Pascoalf354dfe2015-02-10 19:21:21 +0000339 private final HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
Adam Cohended9f8d2010-11-03 13:25:16 -0700340 new HashMap<View, AppWidgetProviderInfo>();
341
Winson Chung400438b2011-01-16 17:53:48 -0800342 // Determines how long to wait after a rotation before restoring the screen orientation to
343 // match the sensor state.
Jose Pascoal76701272015-02-11 19:12:01 +0000344 private static final int mRestoreScreenOrientationDelay = 500;
Winson Chung400438b2011-01-16 17:53:48 -0800345
Craig Mautner360310b2012-10-26 15:13:08 -0700346 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700347
Adam Cohen1462de32012-07-24 22:34:36 -0700348 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700349 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700350
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700351 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700352 static Date sDateStamp = new Date();
353 static DateFormat sDateFormat =
354 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
355 static long sRunStart = System.currentTimeMillis();
356 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700357
Winson Chung46353de2012-02-16 14:05:10 -0800358 // We only want to get the SharedPreferences once since it does an FS stat each time we get
359 // it from the context.
360 private SharedPreferences mSharedPrefs;
361
Adam Cohene25af792013-06-06 23:08:25 -0700362 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
363
Winson Chungf0c6ae02012-03-21 16:10:31 -0700364 // Holds the page that we need to animate to, and the icon views that we need to animate up
365 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700366 private ImageView mFolderIconImageView;
367 private Bitmap mFolderIconBitmap;
368 private Canvas mFolderIconCanvas;
Jose Pascoalf354dfe2015-02-10 19:21:21 +0000369 private final Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700370
Michael Jurkaddd62e92011-02-16 17:49:14 -0800371 private BubbleTextView mWaitingForResume;
372
Jose Pascoalf354dfe2015-02-10 19:21:21 +0000373 private final Runnable mBuildLayersRunnable = new Runnable() {
Michael Jurkac1f5d262011-09-30 19:32:27 -0700374 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700375 if (mWorkspace != null) {
376 mWorkspace.buildPageHardwareLayers();
377 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700378 }
379 };
380
Adam Cohendb364c32014-05-20 14:23:40 -0700381 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800382
Michael Jurka7267fa52013-09-26 15:29:57 -0700383 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800384
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800385 private static class PendingAddArguments {
386 int requestCode;
387 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700388 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700389 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800390 int cellX;
391 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700392 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800393 }
394
Daniel Sandlerff02d492013-08-05 02:12:05 -0400395 private Stats mStats;
396
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700397 FocusIndicatorView mFocusHandler;
Filipe Gonçalvesa804b282015-06-23 17:47:42 +0100398
Jose Pascoala046c672014-11-26 19:46:03 +0000399 private FrameLayout mEdgeMenuContainerView;
400 private EdgeSwipeMenu mEdgeSwipeMenu;
Jose Pascoal3c0767e2014-12-03 18:52:04 +0000401 private AppDrawerView mAgingAppDrawer;
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700402
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800403 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800404 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700405 }
406
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800407 @Override
408 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700409 if (DEBUG_STRICT_MODE) {
410 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
411 .detectDiskReads()
412 .detectDiskWrites()
413 .detectNetwork() // or .detectAll() for all detectable problems
414 .penaltyLog()
415 .build());
416 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
417 .detectLeakedSqlLiteObjects()
418 .detectLeakedClosableObjects()
419 .penaltyLog()
420 .penaltyDeath()
421 .build());
422 }
423
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800424 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400425
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400426 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400427 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700428 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700429 // Determine the dynamic grid properties
430 Point smallestSize = new Point();
431 Point largestSize = new Point();
432 Point realSize = new Point();
433 Display display = getWindowManager().getDefaultDisplay();
434 display.getCurrentSizeRange(smallestSize, largestSize);
435 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700436 DisplayMetrics dm = new DisplayMetrics();
437 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700438
Winson Chung5f8afe62013-08-12 16:19:28 -0700439 // Lazy-initialize the dynamic grid
440 DeviceProfile grid = app.initDynamicGrid(this,
441 Math.min(smallestSize.x, smallestSize.y),
442 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700443 realSize.x, realSize.y,
444 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700445
446 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400447 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700448 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700449 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800450 mModel = app.setLauncher(this);
451 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700452 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400453 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800454 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700455
Daniel Sandlerff02d492013-08-05 02:12:05 -0400456 mStats = new Stats(this);
457
Sunny Goyalffe83f12014-08-14 17:39:34 -0700458 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700459
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700460 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
461 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700462
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700463 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
464 // this also ensures that any synchronous binding below doesn't re-trigger another
465 // LauncherModel load.
466 mPaused = false;
467
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800468 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200469 android.os.Debug.startMethodTracing(
470 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800471 }
472
473 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800474 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700475
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800476 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100477 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800478
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800479 registerContentObservers();
480
Joe Onorato7c312c12009-08-13 21:36:53 -0700481 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700482
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800483 mSavedState = savedInstanceState;
484 restoreState(mSavedState);
485
486 if (PROFILE_STARTUP) {
487 android.os.Debug.stopMethodTracing();
488 }
489
490 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700491 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700492 // If the user leaves launcher, then we should just load items asynchronously when
493 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500494 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700495 } else {
496 // We only load the page synchronously if the user rotates (or triggers a
497 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800498 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700499 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800500 }
501
502 // For handling default keys
503 mDefaultKeySsb = new SpannableStringBuilder();
504 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800505
506 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
507 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800508
Adam Cohenf9426d52012-06-04 17:26:21 -0700509 // On large interfaces, we want the screen to auto-rotate based on the current orientation
510 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700511
Adam Cohen432609a2014-03-13 17:03:22 -0700512 if (shouldShowIntroScreen()) {
513 showIntroScreen();
514 } else {
515 showFirstRunActivity();
Sunny Goyal88d60f12014-09-08 03:47:29 -0700516 showFirstRunClings();
Winson Chunga6945242014-01-08 14:04:34 -0800517 }
Filipe Gonçalvesa804b282015-06-23 17:47:42 +0100518
Jose Pascoala046c672014-11-26 19:46:03 +0000519 setupEdgeSwipeMenu();
Adam Cohenf9426d52012-06-04 17:26:21 -0700520 }
521
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700522 @Override
523 public void onLauncherProviderChange() { }
524
Winson Chung98ca0f72013-07-29 12:58:51 -0700525 /** To be overriden by subclasses to hint to Launcher that we have custom content */
Jose Pascoal8bdb3642015-02-13 13:15:11 +0000526 protected static boolean hasCustomContentToLeft() {
Winson Chung98ca0f72013-07-29 12:58:51 -0700527 return false;
528 }
529
Dave Hawkeya8881582013-09-17 15:55:33 -0600530 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500531 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600532 * {@link #addToCustomContentPage}. This will only be invoked if
533 * {@link #hasCustomContentToLeft()} is {@code true}.
534 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500535 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600536 }
537
538 /**
539 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
540 * ensure the custom content page is added or removed if necessary.
541 */
542 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600543 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600544 // Not bound yet, wait for bindScreens to be called.
545 return;
546 }
547
548 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
549 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500550 mWorkspace.createCustomContentContainer();
551 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600552 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
553 mWorkspace.removeCustomContentPage();
554 }
555 }
Jose Pascoal48612372014-11-19 17:39:00 +0000556
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800557 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700558 if (sLocaleConfiguration == null) {
559 new AsyncTask<Void, Void, LocaleConfiguration>() {
560 @Override
561 protected LocaleConfiguration doInBackground(Void... unused) {
562 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
563 readConfiguration(Launcher.this, localeConfiguration);
564 return localeConfiguration;
565 }
566
567 @Override
568 protected void onPostExecute(LocaleConfiguration result) {
569 sLocaleConfiguration = result;
570 checkForLocaleChange(); // recursive, but now with a locale configuration
571 }
572 }.execute();
573 return;
574 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700575
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800576 final Configuration configuration = getResources().getConfiguration();
577
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700578 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800579 final String locale = configuration.locale.toString();
580
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700581 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800582 final int mcc = configuration.mcc;
583
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700584 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800585 final int mnc = configuration.mnc;
586
Romain Guy84f296c2009-11-04 15:00:44 -0800587 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800588
Romain Guy84f296c2009-11-04 15:00:44 -0800589 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700590 sLocaleConfiguration.locale = locale;
591 sLocaleConfiguration.mcc = mcc;
592 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700593
Joe Onorato0589f0f2010-02-08 13:44:00 -0800594 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700595
596 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100597 new AsyncTask<Void, Void, Void>() {
598 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700599 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100600 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700601 }
Michael Jurka43467462013-11-14 12:03:58 +0100602 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700603 }
604 }
605
606 private static class LocaleConfiguration {
607 public String locale;
608 public int mcc = -1;
609 public int mnc = -1;
610 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700611
Romain Guy98d01652009-06-30 16:21:04 -0700612 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
613 DataInputStream in = null;
614 try {
615 in = new DataInputStream(context.openFileInput(PREFERENCES));
616 configuration.locale = in.readUTF();
617 configuration.mcc = in.readInt();
618 configuration.mnc = in.readInt();
619 } catch (FileNotFoundException e) {
620 // Ignore
621 } catch (IOException e) {
622 // Ignore
623 } finally {
624 if (in != null) {
625 try {
626 in.close();
627 } catch (IOException e) {
628 // Ignore
629 }
630 }
631 }
632 }
633
634 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
635 DataOutputStream out = null;
636 try {
637 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
638 out.writeUTF(configuration.locale);
639 out.writeInt(configuration.mcc);
640 out.writeInt(configuration.mnc);
641 out.flush();
642 } catch (FileNotFoundException e) {
643 // Ignore
644 } catch (IOException e) {
645 //noinspection ResultOfMethodCallIgnored
646 context.getFileStreamPath(PREFERENCES).delete();
647 } finally {
648 if (out != null) {
649 try {
650 out.close();
651 } catch (IOException e) {
652 // Ignore
653 }
654 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800655 }
656 }
657
Anton Hanssona2f665f2013-09-26 12:18:32 +0100658 public Stats getStats() {
659 return mStats;
660 }
661
Bjorn Bringertc459e522013-06-07 19:36:01 +0100662 public LayoutInflater getInflater() {
663 return mInflater;
664 }
665
Jose Pascoal4b1e3122014-12-04 17:36:37 +0000666 public boolean isDraggingEnabled() {
Winson Chung36a62fe2012-05-06 18:04:42 -0700667 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
668 // that is subsequently removed from the workspace in startBinding().
669 return !mModel.isLoadingWorkspace();
670 }
671
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800672 static int getScreen() {
673 synchronized (sLock) {
674 return sScreen;
675 }
676 }
677
678 static void setScreen(int screen) {
679 synchronized (sLock) {
680 sScreen = screen;
681 }
682 }
683
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000684 public static int generateViewId() {
Ian Parkinson0c2918f2014-10-06 14:24:31 +0100685 if (Build.VERSION.SDK_INT >= 17) {
686 return View.generateViewId();
687 } else {
688 // View.generateViewId() is not available. The following fallback logic is a copy
689 // of its implementation.
690 for (;;) {
691 final int result = sNextGeneratedId.get();
692 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
693 int newValue = result + 1;
Jose Pascoal65766f82015-02-10 17:55:27 +0000694 if (newValue > 0x00FFFFFF) {
695 newValue = 1; // Roll over to 1, not 0.
696 }
Ian Parkinson0c2918f2014-10-06 14:24:31 +0100697 if (sNextGeneratedId.compareAndSet(result, newValue)) {
698 return result;
699 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000700 }
701 }
702 }
703
704 public int getViewIdForItem(ItemInfo info) {
705 // This cast is safe given the > 2B range for int.
706 int itemId = (int) info.id;
707 if (mItemIdToViewId.containsKey(itemId)) {
708 return mItemIdToViewId.get(itemId);
709 }
710 int viewId = generateViewId();
711 mItemIdToViewId.put(itemId, viewId);
712 return viewId;
713 }
714
715 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700716 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
717 * a configuration step, this allows the proper animations to run after other transitions.
718 */
Adam Cohendb364c32014-05-20 14:23:40 -0700719 private long completeAdd(PendingAddArguments args) {
Adam Cohen83079e42014-09-19 17:43:08 -0700720 long screenId = args.screenId;
721 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
722 // When the screen id represents an actual screen (as opposed to a rank) we make sure
723 // that the drop page actually exists.
724 screenId = ensurePendingDropLayoutExists(args.screenId);
725 }
Adam Cohendb364c32014-05-20 14:23:40 -0700726
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800727 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800728 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700729 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700730 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700731 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800732 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700733 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700734 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700735 case REQUEST_RECONFIGURE_APPWIDGET:
736 completeRestoreAppWidget(args.appWidgetId);
737 break;
Jose Pascoald1f7ac92014-11-25 19:12:02 +0000738 case REQUEST_EDIT_FAVORITES:
739 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800740 }
Michael Jurka27614d22012-04-02 06:40:22 -0700741 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
742 // if you turned the screen off and then back while in All Apps, Launcher would not
743 // return to the workspace. Clearing mAddInfo.container here fixes this issue
744 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700745 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800746 }
747
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800748 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700749 protected void onActivityResult(
750 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700751 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700752 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700753 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800754 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700755
Adam Cohenad4e15c2013-10-17 16:21:35 -0700756 Runnable exitSpringLoaded = new Runnable() {
757 @Override
758 public void run() {
759 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
760 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
761 }
762 };
763
Michael Jurka8b805b12012-04-18 14:23:14 -0700764 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700765 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700766 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
767 if (resultCode == RESULT_CANCELED) {
768 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700769 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700770 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700771 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700772 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
773 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700774 }
775 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200776 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
777 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
778 mWorkspace.exitOverviewMode(false);
779 }
780 return;
Jose Pascoalfa945132014-11-25 12:57:42 +0000781 }else if (requestCode == REQUEST_PICK_SETTINGS) {
782 if (mWorkspace.isInOverviewMode()) {
783 mWorkspace.exitOverviewMode(false);
784 }
785 return;
Jose Pascoald1f7ac92014-11-25 19:12:02 +0000786 } else if (requestCode == REQUEST_EDIT_FAVORITES) {
787 mWaitingForResult = false;
788 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700789 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200790
Jose Pascoalfa945132014-11-25 12:57:42 +0000791
Adam Cohened66b2b2012-01-23 17:28:51 -0800792 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
793 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700794
Adam Cohendb364c32014-05-20 14:23:40 -0700795 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800796 // We have special handling for widgets
797 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800798 final int appWidgetId;
799 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
800 : -1;
801 if (widgetId < 0) {
802 appWidgetId = pendingAddWidgetId;
803 } else {
804 appWidgetId = widgetId;
805 }
806
Adam Cohenad4e15c2013-10-17 16:21:35 -0700807 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800808 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700809 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
810 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700811 result = RESULT_CANCELED;
812 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700813 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700814 @Override
815 public void run() {
816 exitSpringLoadedDragModeDelayed(false, 0, null);
817 }
818 };
Adam Cohendb364c32014-05-20 14:23:40 -0700819 if (workspaceLocked) {
820 // No need to remove the empty screen if we're mid-binding, as the
821 // the bind will not add the empty screen.
822 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
823 } else {
824 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
825 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
826 }
Winson Chung5aaab772012-04-27 15:24:02 -0700827 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700828 if (!workspaceLocked) {
Adam Cohen83079e42014-09-19 17:43:08 -0700829 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
830 // When the screen id represents an actual screen (as opposed to a rank)
831 // we make sure that the drop page actually exists.
832 mPendingAddInfo.screenId =
833 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
834 }
Adam Cohendb364c32014-05-20 14:23:40 -0700835 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
836
837 dropLayout.setDropPending(true);
838 final Runnable onComplete = new Runnable() {
839 @Override
840 public void run() {
841 completeTwoStageWidgetDrop(resultCode, appWidgetId);
842 dropLayout.setDropPending(false);
843 }
844 };
845 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
846 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
847 } else {
848 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
849 mPendingAddInfo);
850 sPendingAddItem = args;
851 }
Winson Chung5aaab772012-04-27 15:24:02 -0700852 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800853 return;
854 }
855
Sunny Goyalff572272014-07-23 13:58:07 -0700856 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
857 if (resultCode == RESULT_OK) {
858 // Update the widget view.
859 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
860 pendingAddWidgetId, mPendingAddInfo);
861 if (workspaceLocked) {
862 sPendingAddItem = args;
863 } else {
864 completeAdd(args);
865 }
866 }
867 // Leave the widget in the pending state if the user canceled the configure.
868 return;
869 }
870
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800871 // The pattern used here is that a user PICKs a specific application,
872 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700873
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800874 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
875 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700876 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700877 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
878 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800879 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700880 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800881 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700882 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700883 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
884 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800885 }
Adam Cohen00074722013-10-11 17:46:09 -0700886 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700887 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700888 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800889 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800890 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800891 }
892
Jose Pascoal8bdb3642015-02-13 13:15:11 +0000893 private static PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
Adam Cohendb364c32014-05-20 14:23:40 -0700894 appWidgetId, ItemInfo info) {
895 PendingAddArguments args = new PendingAddArguments();
896 args.requestCode = requestCode;
897 args.intent = data;
898 args.container = info.container;
899 args.screenId = info.screenId;
900 args.cellX = info.cellX;
901 args.cellY = info.cellY;
902 args.appWidgetId = appWidgetId;
903 return args;
904 }
905
906 /**
907 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
908 *
909 * @param screenId the screen id to check
910 * @return the new screen, or screenId if it exists
911 */
912 private long ensurePendingDropLayoutExists(long screenId) {
913 CellLayout dropLayout =
914 (CellLayout) mWorkspace.getScreenWithId(screenId);
915 if (dropLayout == null) {
916 // it's possible that the add screen was removed because it was
917 // empty and a re-bind occurred
918 mWorkspace.addExtraEmptyScreen();
919 return mWorkspace.commitExtraEmptyScreen();
920 } else {
921 return screenId;
922 }
923 }
924
Adam Cohened66b2b2012-01-23 17:28:51 -0800925 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700926 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700927 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800928 Runnable onCompleteRunnable = null;
929 int animationType = 0;
930
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700931 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800932 if (resultCode == RESULT_OK) {
933 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
934 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700935 mPendingAddWidgetInfo);
936 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800937 onCompleteRunnable = new Runnable() {
938 @Override
939 public void run() {
940 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700941 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700942 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
943 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800944 }
945 };
946 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800947 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800948 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800949 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700950 if (mDragLayer.getAnimatedView() != null) {
951 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
952 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
953 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700954 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700955 // The animated view may be null in the case of a rotation during widget configuration
956 onCompleteRunnable.run();
957 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800958 }
959
960 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700961 protected void onStop() {
962 super.onStop();
963 FirstFrameAnimatorHelper.setIsVisible(false);
964 }
965
966 @Override
967 protected void onStart() {
968 super.onStart();
969 FirstFrameAnimatorHelper.setIsVisible(true);
970 }
971
972 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800973 protected void onResume() {
Jose Pascoalfe3b08b2015-02-11 18:01:38 +0000974 @SuppressWarnings("UnusedAssignment") long startTime = 0;
Michael Jurka447bf842013-05-15 14:52:15 +0200975 if (DEBUG_RESUME_TIME) {
976 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400977 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200978 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800979 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700980
Winson Chung4a2afa32012-07-19 14:53:05 -0700981 // Restore the previous launcher state
982 if (mOnResumeState == State.WORKSPACE) {
983 showWorkspace(false);
984 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -0800985 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700986 }
987 mOnResumeState = State.NONE;
988
Craig Mautner360310b2012-10-26 15:13:08 -0700989 // Background was set to gradient in onPause(), restore to black if in all apps.
990 setWorkspaceBackground(mState == State.WORKSPACE);
991
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800992 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700993 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700994 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500995 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400996 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700997 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800998 }
Jose Pascoal8d032d62015-02-10 14:48:51 +0000999 if (!mBindOnResumeCallbacks.isEmpty()) {
Michael Jurkac402cd92013-05-20 15:49:32 +02001000 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1001 // execute them here
Jose Pascoalfe3b08b2015-02-11 18:01:38 +00001002 @SuppressWarnings("UnusedAssignment") long startTimeCallbacks = 0;
Michael Jurkac402cd92013-05-20 15:49:32 +02001003 if (DEBUG_RESUME_TIME) {
1004 startTimeCallbacks = System.currentTimeMillis();
1005 }
1006
1007 if (mAppsCustomizeContent != null) {
1008 mAppsCustomizeContent.setBulkBind(true);
1009 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001010 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1011 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +02001012 }
1013 if (mAppsCustomizeContent != null) {
1014 mAppsCustomizeContent.setBulkBind(false);
1015 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07001016 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001017 if (DEBUG_RESUME_TIME) {
1018 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1019 (System.currentTimeMillis() - startTimeCallbacks));
1020 }
Michael Jurka447bf842013-05-15 14:52:15 +02001021 }
Jose Pascoal8d032d62015-02-10 14:48:51 +00001022 if (!mOnResumeCallbacks.isEmpty()) {
Michael Jurka54554252013-08-01 12:52:23 +02001023 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1024 mOnResumeCallbacks.get(i).run();
1025 }
1026 mOnResumeCallbacks.clear();
1027 }
Winson Chunge4e50662012-01-23 14:45:13 -08001028
1029 // Reset the pressed state of icons that were locked in the press state while activities
1030 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001031 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001032 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001033 mWaitingForResume.setStayPressed(false);
1034 }
Winson Chung82963d52013-10-09 11:20:57 -07001035
Adam Cohen06dff352012-06-01 17:17:08 -07001036 // It is possible that widgets can receive updates while launcher is not in the foreground.
1037 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1038 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1039 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001040 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001041
Winson Chung780fe592013-09-26 14:48:44 -07001042 // Process any items that were added while Launcher was away.
1043 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1044
Michael Jurka447bf842013-05-15 14:52:15 +02001045 if (DEBUG_RESUME_TIME) {
1046 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1047 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001048
telmo.agostinhof8e60ba2015-10-29 15:33:41 +00001049 Intent idleScreenIntent = new Intent(AppInterface.CAT_IDLE_SCREEN_ACTION);
1050 idleScreenIntent.putExtra("SCREEN_IDLE", true);
1051 Log.d(TAG,"Broadcasting Home Idle Screen Intent ...");
1052 sendBroadcast(idleScreenIntent);
1053
1054
Adam Cohen6fecd412013-10-02 17:41:50 -07001055 if (mWorkspace.getCustomContentCallbacks() != null) {
1056 // If we are resuming and the custom content is the current page, we call onShow().
Jose Pascoal3c0767e2014-12-03 18:52:04 +00001057 // It is also possible that onShow will instead be called slightly after first layout
Adam Cohen6fecd412013-10-02 17:41:50 -07001058 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1059 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001060 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001061 }
1062 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001063 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001064 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001065
1066 PackageInstallerCompat.getInstance(this).onResume();
Filipe Gonçalvesa804b282015-06-23 17:47:42 +01001067
1068 AppSwitcherManager.loadAppSwitcherData(this);
1069 AppSwitcherManager.registerAppSwitcherBroadcastReceivers(this);
1070
Filiped63c86b2015-07-31 12:29:22 +00001071 // show OOBE
1072 startOOBEActivityOnFirstUse(SHOW_OOBE_EDGE_SWIPE_MENU, OOBEActivity.OOBE_DEVICE_TUTORIAL);
Adam Cohen06dff352012-06-01 17:17:08 -07001073 }
1074
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001075 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001076 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001077 // Ensure that items added to Launcher are queued until Launcher returns
1078 InstallShortcutReceiver.enableInstallQueue();
Sunny Goyale755d462014-07-22 13:48:29 -07001079 PackageInstallerCompat.getInstance(this).onPause();
Winson Chung997a9232013-07-24 15:33:46 -07001080
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001081 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001082 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001083 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001084 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001085
1086 // We call onHide() aggressively. The custom content callbacks should be able to
1087 // debounce excess onHide calls.
1088 if (mWorkspace.getCustomContentCallbacks() != null) {
1089 mWorkspace.getCustomContentCallbacks().onHide();
1090 }
Jose Pascoalca875e52014-11-24 12:34:59 +00001091
Filipe Gonçalvesa804b282015-06-23 17:47:42 +01001092 AppSwitcherManager.saveAppSwitcherData(this);
1093 AppSwitcherManager.unregisterAppSwitcherBroadcastReceivers(this);
Jose Pascoalec3574b2014-12-02 19:53:40 +00001094
1095 AppDiscoverer.getInstance().saveAppAgingData(this);
Jose Pascoal4b1e3122014-12-04 17:36:37 +00001096
1097 if(isAgingAppDrawerVisible()){
1098 hideAgingAppDrawer();
1099 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001100 }
Romain Guycbb89e42009-06-08 15:52:54 -07001101
Adam Cohenbffe7452013-07-22 18:21:45 -07001102 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001103 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1104 // by a onResume or by scrolling otherwise.
1105 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001106
1107 // Custom content is completely hidden
1108 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001109
1110 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1111 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001112
1113 // Indicates whether the user is allowed to scroll away from the custom content.
1114 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001115 }
1116
Jose Pascoal8bdb3642015-02-13 13:15:11 +00001117 protected static boolean hasSettings() {
Jorim Jaggid017f882014-01-14 17:08:48 -08001118 return false;
1119 }
Jose Pascoalfa945132014-11-25 12:57:42 +00001120
Jose Pascoal8bdb3642015-02-13 13:15:11 +00001121 protected static boolean hasAllApps()
Jose Pascoalfa945132014-11-25 12:57:42 +00001122 {
1123 // Change to false to hide all apps on the overview pane
1124 return true;
1125 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001126
Adam Cohenedb40762013-07-18 16:45:45 -07001127 // The custom content needs to offset its content to account for the QSB
1128 public int getTopOffsetForCustomContent() {
1129 return mWorkspace.getPaddingTop();
1130 }
1131
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001132 @Override
1133 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001134 // Flag the loader to stop early before switching
Adam Cohen1a85c582014-09-30 09:48:49 -07001135 if (mModel.isCurrentCallbacks(this)) {
1136 mModel.stopLoader();
1137 }
Winson Chung785d2eb2011-04-14 16:08:02 -07001138 if (mAppsCustomizeContent != null) {
1139 mAppsCustomizeContent.surrender();
1140 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001141 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001142 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001143
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001144 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001145 @Override
1146 public void onWindowFocusChanged(boolean hasFocus) {
1147 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001148 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001149 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001150
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001151 private boolean acceptFilter() {
1152 final InputMethodManager inputManager = (InputMethodManager)
1153 getSystemService(Context.INPUT_METHOD_SERVICE);
1154 return !inputManager.isFullscreenMode();
1155 }
1156
1157 @Override
1158 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001159 final int uniChar = event.getUnicodeChar();
1160 final boolean handled = super.onKeyDown(keyCode, event);
1161 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1162 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001163 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1164 keyCode, event);
1165 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001166 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001167 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001168 // showSearchDialog()
1169 // If there are multiple keystrokes before the search dialog takes focus,
1170 // onSearchRequested() will be called for every keystroke,
1171 // but it is idempotent, so it's fine.
1172 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001173 }
1174 }
1175
Joe Onorato8a9625e2010-01-28 15:55:35 -08001176 // Eat the long press event so the keyboard doesn't come up.
Jose Pascoal8e9ffdc2015-02-11 11:25:42 +00001177 return keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress() || handled;
Joe Onorato8a9625e2010-01-28 15:55:35 -08001178
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001179 }
1180
Karl Rosaen138a0412009-04-23 19:00:21 -07001181 private String getTypedText() {
1182 return mDefaultKeySsb.toString();
1183 }
1184
1185 private void clearTypedText() {
1186 mDefaultKeySsb.clear();
1187 mDefaultKeySsb.clearSpans();
1188 Selection.setSelection(mDefaultKeySsb, 0);
1189 }
1190
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001191 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001192 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1193 * State
1194 */
1195 private static State intToState(int stateOrdinal) {
1196 State state = State.WORKSPACE;
1197 final State[] stateValues = State.values();
1198 for (int i = 0; i < stateValues.length; i++) {
1199 if (stateValues[i].ordinal() == stateOrdinal) {
1200 state = stateValues[i];
1201 break;
1202 }
1203 }
1204 return state;
1205 }
1206
1207 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001208 * Restores the previous state, if it exists.
1209 *
1210 * @param savedState The previous state.
1211 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001212 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001213 private void restoreState(Bundle savedState) {
1214 if (savedState == null) {
1215 return;
1216 }
1217
Michael Jurka883f55b2010-10-21 15:47:14 -07001218 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001219 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001220 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001221 }
1222
Adam Cohen21cd0022013-10-09 18:57:02 -07001223 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1224 PagedView.INVALID_RESTORE_PAGE);
1225 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001226 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001227 }
1228
Winson Chung3d503fb2011-07-13 17:25:49 -07001229 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001230 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001231
Winson Chung3d503fb2011-07-13 17:25:49 -07001232 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1233 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001234 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001235 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1236 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001237 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1238 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1239 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001240 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001241 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001242 mRestoring = true;
1243 }
1244
1245 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1246 if (renameFolder) {
1247 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Jose Pascoal8bdb3642015-02-13 13:15:11 +00001248 mFolderInfo = LauncherModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001249 mRestoring = true;
1250 }
Winson Chunga12a2502010-12-20 14:41:35 -08001251
Winson Chung785d2eb2011-04-14 16:08:02 -07001252 // Restore the AppsCustomize tab
1253 if (mAppsCustomizeTabHost != null) {
1254 String curTab = savedState.getString("apps_customize_currentTab");
1255 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001256 mAppsCustomizeTabHost.setContentTypeImmediate(
Jose Pascoal8bdb3642015-02-13 13:15:11 +00001257 AppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001258 mAppsCustomizeContent.loadAssociatedPages(
1259 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001260 }
1261
Winson Chung5afbf7b2011-07-25 11:53:08 -07001262 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1263 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001264 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001265 mItemIdToViewId = (HashMap<Integer, Integer>)
1266 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001267 }
1268
1269 /**
1270 * Finds all the views we need and configure them properly.
1271 */
1272 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001273 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001274
Craig Mautner360310b2012-10-26 15:13:08 -07001275 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001276 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001277 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1278 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001279 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001280 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001281
John Spurlock77e1f472013-09-11 10:09:51 -04001282 mLauncherView.setSystemUiVisibility(
1283 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001284 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001285
Winson Chung4c98d922011-05-31 16:50:48 -07001286 // Setup the drag layer
1287 mDragLayer.setup(this, dragController);
1288
Jorim Jaggid017f882014-01-14 17:08:48 -08001289 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001290 View widgetButton = findViewById(R.id.widget_button);
1291 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001292 @Override
1293 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001294 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001295 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001296 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001297 }
1298 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001299 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1300
1301 View wallpaperButton = findViewById(R.id.wallpaper_button);
Adam Cohen61f560d2013-09-30 15:58:20 -07001302
1303 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001304 if (hasSettings()) {
Jose Pascoalfa945132014-11-25 12:57:42 +00001305 wallpaperButton.setVisibility(View.GONE);
1306
Jorim Jaggid017f882014-01-14 17:08:48 -08001307 settingsButton.setOnClickListener(new OnClickListener() {
1308 @Override
1309 public void onClick(View arg0) {
1310 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001311 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001312 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001313 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001314 });
1315 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1316 } else {
1317 settingsButton.setVisibility(View.GONE);
Jose Pascoalfa945132014-11-25 12:57:42 +00001318
1319 wallpaperButton.setOnClickListener(new OnClickListener() {
1320 @Override
1321 public void onClick(View arg0) {
1322 if (!mWorkspace.isSwitchingState()) {
1323 onClickWallpaperPicker(arg0);
1324 }
1325 }
1326 });
1327 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1328 }
1329
1330 View appsButton = findViewById(R.id.applications_button);
1331 if (hasAllApps())
1332 {
1333 appsButton.setOnClickListener(new OnClickListener()
1334 {
1335 @Override
1336 public void onClick(View arg0)
1337 {
1338 if (!mWorkspace.isSwitchingState())
1339 {
1340 onClickAllAppsButton(arg0);
1341 }
1342 }
1343 });
1344 appsButton.setOnLongClickListener(new OnLongClickListener()
1345 {
1346
1347 @Override
1348 public boolean onLongClick(View v)
1349 {
1350 Toast.makeText(getApplicationContext(), "Don't push me so hard :(", Toast.LENGTH_LONG).show();
1351 return true;
1352 }
1353 });
1354 appsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1355 }
1356 else
1357 {
1358 appsButton.setVisibility(View.GONE);
Jorim Jaggid017f882014-01-14 17:08:48 -08001359 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1360 lp.gravity = Gravity.END | Gravity.TOP;
1361 widgetButton.requestLayout();
1362 }
1363
Adam Cohendbdff6b2013-09-18 19:09:15 -07001364 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001365
Winson Chung4c98d922011-05-31 16:50:48 -07001366 // Setup the workspace
1367 mWorkspace.setHapticFeedbackEnabled(false);
1368 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001369 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001370 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001371
Winson Chungf0ea4d32011-06-06 14:27:16 -07001372 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001373 mSearchDropTargetBar = (SearchDropTargetBar)
1374 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001375
Winson Chungf0ea4d32011-06-06 14:27:16 -07001376 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001377 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001378 mAppsCustomizeContent = (AppsCustomizePagedView)
1379 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1380 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001381
Winson Chung3d503fb2011-07-13 17:25:49 -07001382 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001383 dragController.setDragScoller(mWorkspace);
1384 dragController.setScrollView(mDragLayer);
1385 dragController.setMoveTarget(mWorkspace);
1386 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001387 if (mSearchDropTargetBar != null) {
1388 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001389 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001390
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001391 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001392 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001393 mWeightWatcher = new WeightWatcher(this);
1394 mWeightWatcher.setAlpha(0.5f);
1395 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001396 new FrameLayout.LayoutParams(
1397 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001398 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001399 Gravity.BOTTOM)
1400 );
Adam Cohen39a06042013-07-19 14:30:12 -07001401
1402 boolean show = shouldShowWeightWatcher();
1403 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001404 }
Jose Pascoal3c0767e2014-12-03 18:52:04 +00001405
1406 mAgingAppDrawer = (AppDrawerView) findViewById(R.id.aging_app_drawer);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001407 }
1408
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00001409 public View getPageIndicator() {
1410 return mPageIndicators;
Anjali Koppal5ad44842014-03-10 20:34:39 -07001411 }
1412
1413 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414 * Creates a view representing a shortcut.
1415 *
1416 * @param info The data structure describing the shortcut.
1417 *
1418 * @return A View inflated from R.layout.application.
1419 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001420 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001421 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001422 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001423 }
1424
1425 /**
1426 * Creates a view representing a shortcut inflated from the specified resource.
1427 *
1428 * @param layoutResId The id of the XML layout used to create the shortcut.
1429 * @param parent The group the shortcut belongs to.
1430 * @param info The data structure describing the shortcut.
1431 *
1432 * @return A View inflated from layoutResId.
1433 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001434 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001435 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001436 favorite.applyFromShortcutInfo(info, mIconCache, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001437 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001438 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001439 return favorite;
1440 }
1441
1442 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001443 * Add a shortcut to the workspace.
1444 *
1445 * @param data The intent describing the shortcut.
1446 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001447 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001448 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001449 int cellY) {
1450 int[] cellXY = mTmpAddItemCellCoordinates;
1451 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001452 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001453
Jose Pascoalfe3b08b2015-02-11 18:01:38 +00001454 boolean foundCellSpan;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001455
Adam Cohen558baaf2011-08-15 15:22:57 -07001456 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001457 if (info == null) {
1458 return;
1459 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001460 final View view = createShortcut(info);
1461
Adam Cohenfbba09b2011-07-18 21:43:05 -07001462 // First we check if we already know the exact location where we want to add this item.
1463 if (cellX >= 0 && cellY >= 0) {
1464 cellXY[0] = cellX;
1465 cellXY[1] = cellY;
1466 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001467
1468 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001469 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001470 true, null,null)) {
1471 return;
1472 }
1473 DragObject dragObject = new DragObject();
1474 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001475 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1476 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001477 return;
1478 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001479 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001480 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001481 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001482 foundCellSpan = (result != null);
1483 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001484 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001485 }
1486
1487 if (!foundCellSpan) {
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00001488 showOutOfSpaceMessage();
Michael Jurka0280c3b2010-09-17 15:00:07 -07001489 return;
1490 }
1491
Adam Cohendcd297f2013-06-18 13:13:40 -07001492 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001493
1494 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001495 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001496 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001497 }
1498 }
1499
Adam Cohen2f093b62012-04-30 18:59:53 -07001500 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1501 int minHeight) {
1502 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001503 // We want to account for the extra amount of padding that we are adding to the widget
1504 // to ensure that it gets the full amount of space that it has requested
1505 int requiredWidth = minWidth + padding.left + padding.right;
1506 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001507 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001508 }
1509
Adam Cohen2f093b62012-04-30 18:59:53 -07001510 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1511 return getSpanForWidget(context, info.provider, 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, AppWidgetProviderInfo info) {
1515 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001516 }
1517
Adam Cohen2f093b62012-04-30 18:59:53 -07001518 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1519 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001520 }
1521
Adam Cohen2f093b62012-04-30 18:59:53 -07001522 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1523 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001524 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001525 }
1526
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001527 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001528 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001529 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001530 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001531 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001532 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001533 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001534 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1535 if (appWidgetInfo == null) {
1536 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1537 }
Romain Guycbb89e42009-06-08 15:52:54 -07001538
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001539 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001540 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001541
Adam Cohen2f093b62012-04-30 18:59:53 -07001542 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1543 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001544
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001545 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001546 // We have saved the position to which the widget was dragged-- this really only matters
1547 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001548 int[] cellXY = mTmpAddItemCellCoordinates;
1549 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001550 int[] finalSpan = new int[2];
Jose Pascoalfe3b08b2015-02-11 18:01:38 +00001551 boolean foundCellSpan;
Winson Chung3d503fb2011-07-13 17:25:49 -07001552 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1553 cellXY[0] = mPendingAddInfo.cellX;
1554 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001555 spanXY[0] = mPendingAddInfo.spanX;
1556 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001557 foundCellSpan = true;
1558 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001559 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001560 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001561 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1562 spanXY[1], cellXY, finalSpan);
1563 spanXY[0] = finalSpan[0];
1564 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001565 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001566 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001567 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001568 }
1569
Michael Jurka0280c3b2010-09-17 15:00:07 -07001570 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001571 if (appWidgetId != -1) {
1572 // Deleting an app widget ID is a void call but writes to disk before returning
1573 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001574 new AsyncTask<Void, Void, Void>() {
1575 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001576 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001577 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001578 }
Michael Jurka43467462013-11-14 12:03:58 +01001579 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001580 }
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00001581 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001582 return;
1583 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001584
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001585 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001586 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1587 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001588 launcherInfo.spanX = spanXY[0];
1589 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001590 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1591 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001592 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001593
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001594 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001595 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001596
1597 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001598 if (hostView == null) {
1599 // Perform actual inflation because we're live
1600 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1601 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1602 } else {
1603 // The AppWidgetHostView has already been inflated and instantiated
1604 launcherInfo.hostView = hostView;
1605 }
Romain Guycbb89e42009-06-08 15:52:54 -07001606
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001607 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001608 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001609 launcherInfo.notifyWidgetSizeChanged(this);
1610
Adam Cohendcd297f2013-06-18 13:13:40 -07001611 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001612 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001613
1614 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001615 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001616 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001617 }
Romain Guycbb89e42009-06-08 15:52:54 -07001618
Adam Cohended9f8d2010-11-03 13:25:16 -07001619 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1620 @Override
1621 public void onReceive(Context context, Intent intent) {
1622 final String action = intent.getAction();
1623 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1624 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001625 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001626 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001627
Winson Chungc100e8e2011-08-09 16:02:43 -07001628 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001629 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001630 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001631 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001632 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001633 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1634 mUserPresent = true;
1635 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001636 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1637 mModel.resetLoadedState(false, true);
1638 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1639 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1640 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1641 mModel.resetLoadedState(false, true);
1642 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1643 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1644 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001645 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1646 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1647 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001648 }
1649 }
1650 };
1651
1652 @Override
1653 public void onAttachedToWindow() {
1654 super.onAttachedToWindow();
1655
1656 // Listen for broadcasts related to user-presence
1657 final IntentFilter filter = new IntentFilter();
1658 filter.addAction(Intent.ACTION_SCREEN_OFF);
1659 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001660 // For handling managed profiles
1661 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1662 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001663 if (ENABLE_DEBUG_INTENTS) {
1664 filter.addAction(DebugIntents.DELETE_DATABASE);
1665 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1666 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001667 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001668 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001669 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001670 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001671 mVisible = true;
1672 }
1673
Adam Cohen0b395352014-06-09 22:54:36 +00001674 /**
1675 * Sets up transparent navigation and status bars in LMP.
1676 * This method is a no-op for other platform versions.
1677 */
1678 @TargetApi(19)
1679 private void setupTransparentSystemBarsForLmp() {
1680 // TODO(sansid): use the APIs directly when compiling against L sdk.
1681 // Currently we use reflection to access the flags and the API to set the transparency
1682 // on the System bars.
Kenny Guyd794a3f2014-09-16 15:17:58 +01001683 if (Utilities.isLmpOrAbove()) {
Adam Cohen0b395352014-06-09 22:54:36 +00001684 try {
1685 getWindow().getAttributes().systemUiVisibility |=
1686 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1687 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1688 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1689 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1690 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1691 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1692 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1693 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1694
1695 Method setStatusBarColorMethod =
1696 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1697 Method setNavigationBarColorMethod =
1698 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1699 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1700 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1701 } catch (NoSuchFieldException e) {
1702 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1703 } catch (NoSuchMethodException ex) {
1704 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1705 } catch (IllegalAccessException e) {
1706 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1707 } catch (IllegalArgumentException e) {
1708 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1709 } catch (InvocationTargetException e) {
1710 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1711 } finally {}
1712 }
1713 }
Tiago Costadaaa70c2014-12-10 15:15:57 +00001714
1715 @TargetApi(19)
1716 private void setupGrayoutSystemBarsForLmp() {
1717 if (Utilities.isLmpOrAbove()) {
Jose Pascoal8218a2b2014-12-18 16:31:06 +00001718 getWindow().getAttributes().systemUiVisibility |=
1719 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1720 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1721 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1722 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1723 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
Tiago Costadaaa70c2014-12-10 15:15:57 +00001724 }
1725 }
1726
Adam Cohen0b395352014-06-09 22:54:36 +00001727
Adam Cohended9f8d2010-11-03 13:25:16 -07001728 @Override
1729 public void onDetachedFromWindow() {
1730 super.onDetachedFromWindow();
1731 mVisible = false;
1732
Adam Cohend113e0c2010-11-11 10:48:05 -08001733 if (mAttached) {
1734 unregisterReceiver(mReceiver);
1735 mAttached = false;
1736 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001737 updateRunning();
1738 }
1739
1740 public void onWindowVisibilityChanged(int visibility) {
1741 mVisible = visibility == View.VISIBLE;
1742 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001743 // The following code used to be in onResume, but it turns out onResume is called when
1744 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1745 // is a more appropriate event to handle
1746 if (mVisible) {
1747 mAppsCustomizeTabHost.onWindowVisible();
1748 if (!mWorkspaceLoading) {
1749 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001750 // We want to let Launcher draw itself at least once before we force it to build
1751 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001752 // apps is nice and speedy.
1753 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001754 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001755 public void onDraw() {
Jose Pascoal65766f82015-02-10 17:55:27 +00001756 if (mStarted) {
1757 return;
1758 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001759 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001760 // We delay the layer building a bit in order to give
1761 // other message processing a time to run. In particular
1762 // this avoids a delay in hiding the IME if it was
1763 // currently shown, because doing that may involve
1764 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001765 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001766 final ViewTreeObserver.OnDrawListener listener = this;
1767 mWorkspace.post(new Runnable() {
1768 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001769 if (mWorkspace != null &&
1770 mWorkspace.getViewTreeObserver() != null) {
1771 mWorkspace.getViewTreeObserver().
1772 removeOnDrawListener(listener);
1773 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001774 }
1775 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001776 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001777 }
1778 });
1779 }
1780 clearTypedText();
1781 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001782 }
1783
1784 private void sendAdvanceMessage(long delay) {
1785 mHandler.removeMessages(ADVANCE_MSG);
1786 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1787 mHandler.sendMessageDelayed(msg, delay);
1788 mAutoAdvanceSentTime = System.currentTimeMillis();
1789 }
1790
1791 private void updateRunning() {
1792 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1793 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1794 mAutoAdvanceRunning = autoAdvanceRunning;
1795 if (autoAdvanceRunning) {
1796 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1797 sendAdvanceMessage(delay);
1798 } else {
1799 if (!mWidgetsToAdvance.isEmpty()) {
1800 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1801 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1802 }
1803 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001804 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001805 }
1806 }
1807 }
1808
1809 private final Handler mHandler = new Handler() {
1810 @Override
1811 public void handleMessage(Message msg) {
1812 if (msg.what == ADVANCE_MSG) {
1813 int i = 0;
1814 for (View key: mWidgetsToAdvance.keySet()) {
1815 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1816 final int delay = mAdvanceStagger * i;
1817 if (v instanceof Advanceable) {
1818 postDelayed(new Runnable() {
1819 public void run() {
1820 ((Advanceable) v).advance();
1821 }
1822 }, delay);
1823 }
1824 i++;
1825 }
1826 sendAdvanceMessage(mAdvanceInterval);
1827 }
1828 }
1829 };
1830
1831 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Jose Pascoal65766f82015-02-10 17:55:27 +00001832 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) {
1833 return;
1834 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001835 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1836 if (v instanceof Advanceable) {
1837 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001838 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001839 updateRunning();
1840 }
1841 }
1842
1843 void removeWidgetToAutoAdvance(View hostView) {
1844 if (mWidgetsToAdvance.containsKey(hostView)) {
1845 mWidgetsToAdvance.remove(hostView);
1846 updateRunning();
1847 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001848 }
1849
Joe Onorato9c1289c2009-08-17 11:03:03 -04001850 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001851 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001852 launcherInfo.hostView = null;
1853 }
1854
Jose Pascoal43aab392014-12-05 18:00:55 +00001855 public void showOutOfSpaceMessage() {
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00001856 int strId = R.string.out_of_space;
Winson Chung93eef082012-03-23 15:59:27 -07001857 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001858 }
1859
Winson Chunga6945242014-01-08 14:04:34 -08001860 public DragLayer getDragLayer() {
1861 return mDragLayer;
1862 }
1863
1864 public Workspace getWorkspace() {
1865 return mWorkspace;
1866 }
1867
Jorim Jaggid017f882014-01-14 17:08:48 -08001868 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001869 return mOverviewPanel;
1870 }
1871
1872 public SearchDropTargetBar getSearchBar() {
1873 return mSearchDropTargetBar;
1874 }
1875
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001876 public LauncherAppWidgetHost getAppWidgetHost() {
1877 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001878 }
Romain Guycbb89e42009-06-08 15:52:54 -07001879
Winson Chunga9abd0e2010-10-27 17:18:37 -07001880 public LauncherModel getModel() {
1881 return mModel;
1882 }
1883
Winson Chunga6945242014-01-08 14:04:34 -08001884 protected SharedPreferences getSharedPrefs() {
1885 return mSharedPrefs;
1886 }
1887
Bjorn Bringertc459e522013-06-07 19:36:01 +01001888 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001889 getWindow().closeAllPanels();
1890
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001891 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001892 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001893 }
1894
Jose Pascoalfe3b08b2015-02-11 18:01:38 +00001895 @SuppressWarnings("UnusedAssignment")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001896 @Override
1897 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001898 long startTime = 0;
1899 if (DEBUG_RESUME_TIME) {
1900 startTime = System.currentTimeMillis();
1901 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001902 super.onNewIntent(intent);
1903
1904 // Close the menu
1905 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001906 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001907 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001908
Adam Cohened307df2013-10-02 09:37:31 -07001909 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1910 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1911 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001912
Adam Cohen6fecd412013-10-02 17:41:50 -07001913 if (mWorkspace == null) {
1914 // Can be cases where mWorkspace is null, this prevents a NPE
1915 return;
1916 }
1917 Folder openFolder = mWorkspace.getOpenFolder();
1918 // In all these cases, only animate if we're already on home
1919 mWorkspace.exitWidgetResizeMode();
1920 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001921 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001922 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001923 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001924
Adam Cohen6fecd412013-10-02 17:41:50 -07001925 closeFolder();
1926 exitSpringLoadedDragMode();
1927
1928 // If we are already on home, then just animate back to the workspace,
1929 // otherwise, just wait until onResume to set the state back to Workspace
1930 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001931 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001932 } else {
1933 mOnResumeState = State.WORKSPACE;
1934 }
1935
1936 final View v = getWindow().peekDecorView();
1937 if (v != null && v.getWindowToken() != null) {
1938 InputMethodManager imm = (InputMethodManager)getSystemService(
1939 INPUT_METHOD_SERVICE);
1940 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1941 }
1942
1943 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001944 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001945 mAppsCustomizeTabHost.reset();
1946 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001947
1948 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001949 }
Adam Cohened307df2013-10-02 09:37:31 -07001950
Michael Jurka447bf842013-05-15 14:52:15 +02001951 if (DEBUG_RESUME_TIME) {
1952 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1953 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001954 }
1955
Adam Coppa120b8e2013-11-12 16:26:04 +00001956 /**
1957 * Override point for subclasses to prevent movement to the default screen when the home
1958 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1959 */
Jose Pascoal8bdb3642015-02-13 13:15:11 +00001960 protected static boolean shouldMoveToDefaultScreenOnHomeIntent() {
Adam Coppa120b8e2013-11-12 16:26:04 +00001961 return true;
1962 }
1963
1964 /**
1965 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1966 */
1967 protected void onHomeIntent() {
Jose Pascoal3c0767e2014-12-03 18:52:04 +00001968 if(isAgingAppDrawerVisible()){
1969 hideAgingAppDrawer();
1970 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001971 }
1972
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001973 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001974 public void onRestoreInstanceState(Bundle state) {
1975 super.onRestoreInstanceState(state);
1976 for (int page: mSynchronouslyBoundPages) {
1977 mWorkspace.restoreInstanceStateForChild(page);
1978 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001979 }
1980
1981 @Override
1982 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001983 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001984 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1985 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001986 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001987 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001988
Michael Jurka883f55b2010-10-21 15:47:14 -07001989 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001990 // We close any open folder since it will not be re-opened, and we need to make sure
1991 // this state is reflected.
1992 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001993
Adam Cohendcd297f2013-06-18 13:13:40 -07001994 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001995 mWaitingForResult) {
1996 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001997 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001998 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1999 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002000 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
2001 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
2002 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08002003 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002004 }
2005
2006 if (mFolderInfo != null && mWaitingForResult) {
2007 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
2008 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
2009 }
Michael Jurka946ad472010-07-09 18:05:18 -07002010
Winson Chung785d2eb2011-04-14 16:08:02 -07002011 // Save the current AppsCustomize tab
2012 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08002013 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
Jose Pascoal8bdb3642015-02-13 13:15:11 +00002014 String currentTabTag = AppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07002015 if (currentTabTag != null) {
2016 outState.putString("apps_customize_currentTab", currentTabTag);
2017 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07002018 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
2019 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07002020 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00002021 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002022 }
2023
2024 @Override
2025 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002026 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07002027
Winson Chunge7a03942011-08-05 15:05:12 -07002028 // Remove all pending runnables
2029 mHandler.removeMessages(ADVANCE_MSG);
2030 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07002031 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07002032
Winson Chungcd2b0142011-06-08 16:02:26 -07002033 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04002034 LauncherAppState app = (LauncherAppState.getInstance());
Adam Cohen1a85c582014-09-30 09:48:49 -07002035
2036 // It's possible to receive onDestroy after a new Launcher activity has
2037 // been created. In this case, don't interfere with the new Launcher.
2038 if (mModel.isCurrentCallbacks(this)) {
2039 mModel.stopLoader();
2040 app.setLauncher(null);
2041 }
Winson Chungcd2b0142011-06-08 16:02:26 -07002042
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002043 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07002044 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002045 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002046 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002047 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002048 mAppWidgetHost = null;
2049
2050 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002051
2052 TextKeyListener.getInstance().release();
2053
Winson Chung81b52252012-08-27 15:34:29 -07002054 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2055 // to prevent leaking Launcher activities on orientation change.
2056 if (mModel != null) {
2057 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2058 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002059
2060 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002061 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002062
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002063 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002064 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002065 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002066 mWorkspace = null;
2067 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002068
Sunny Goyale755d462014-07-22 13:48:29 -07002069 PackageInstallerCompat.getInstance(this).onStop();
Michael Jurka2ecf9952012-06-18 12:52:28 -07002070 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002071 }
2072
Adam Cohena9cf38f2011-05-02 15:36:58 -07002073 public DragController getDragController() {
2074 return mDragController;
2075 }
2076
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002077 @Override
2078 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002079 if (requestCode >= 0) {
2080 setWaitingForResult(true);
2081 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002082 super.startActivityForResult(intent, requestCode);
2083 }
2084
Winson Chung70d72102011-08-12 11:24:35 -07002085 /**
2086 * Indicates that we want global search for this activity by setting the globalSearch
2087 * argument for {@link #startSearch} to true.
2088 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002089 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002090 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002091 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002092
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002093 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002094
Karl Rosaen138a0412009-04-23 19:00:21 -07002095 if (initialQuery == null) {
2096 // Use any text typed in the launcher as the initial query
2097 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002098 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002099 if (appSearchData == null) {
2100 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002101 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002102 }
Winson Chungadf0c182012-08-23 14:59:07 -07002103 Rect sourceBounds = new Rect();
Romain Guycbb89e42009-06-08 15:52:54 -07002104
Ian Parkinson047036e2014-09-01 15:40:53 +01002105 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002106 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002107 if (clearTextImmediately) {
2108 clearTypedText();
2109 }
Bjorn Bringertc459e522013-06-07 19:36:01 +01002110 }
2111
Ian Parkinson047036e2014-09-01 15:40:53 +01002112 /**
2113 * Start a text search.
2114 *
2115 * @return {@code true} if the search will start immediately, so any further keypresses
2116 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2117 * to buffer keypresses.
2118 */
2119 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002120 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002121 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002122 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002123 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002124 }
2125
2126 /**
2127 * Starts the global search activity. This code is a copied from SearchManager
2128 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002129 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002130 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002131 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002132 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2133 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2134 if (globalSearchActivity == null) {
2135 Log.w(TAG, "No global search activity found.");
2136 return;
2137 }
2138 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2139 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2140 intent.setComponent(globalSearchActivity);
2141 // Make sure that we have a Bundle to put source in
2142 if (appSearchData == null) {
2143 appSearchData = new Bundle();
2144 } else {
2145 appSearchData = new Bundle(appSearchData);
2146 }
2147 // Set source to package name of app that starts global search, if not set already.
2148 if (!appSearchData.containsKey("source")) {
2149 appSearchData.putString("source", getPackageName());
2150 }
2151 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2152 if (!TextUtils.isEmpty(initialQuery)) {
2153 intent.putExtra(SearchManager.QUERY, initialQuery);
2154 }
2155 if (selectInitialQuery) {
2156 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2157 }
2158 intent.setSourceBounds(sourceBounds);
2159 try {
2160 startActivity(intent);
2161 } catch (ActivityNotFoundException ex) {
2162 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2163 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002164 }
2165
Yura4f93ec62014-02-04 14:15:21 +00002166 public boolean isOnCustomContent() {
2167 return mWorkspace.isOnOrMovingToCustomContent();
2168 }
2169
Winson Chung70d72102011-08-12 11:24:35 -07002170 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002171 public boolean onPrepareOptionsMenu(Menu menu) {
2172 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002173 if (!isOnCustomContent()) {
2174 // Close any open folders
2175 closeFolder();
2176 // Stop resizing any widgets
2177 mWorkspace.exitWidgetResizeMode();
2178 if (!mWorkspace.isInOverviewMode()) {
2179 // Show the overview mode
2180 showOverviewMode(true);
2181 } else {
2182 showWorkspace(true);
2183 }
Winson Chunge0298742014-01-17 12:03:00 -08002184 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002185 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002186 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002187
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002188 @Override
2189 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002190 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002191 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002192 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002193 }
2194
Joe Onorato9c1289c2009-08-17 11:03:03 -04002195 public boolean isWorkspaceLocked() {
2196 return mWorkspaceLoading || mWaitingForResult;
2197 }
2198
Adam Cohen517a7f52014-03-01 12:12:59 -08002199 public boolean isWorkspaceLoading() {
2200 return mWorkspaceLoading;
2201 }
2202
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002203 private void setWorkspaceLoading(boolean value) {
2204 boolean isLocked = isWorkspaceLocked();
2205 mWorkspaceLoading = value;
2206 if (isLocked != isWorkspaceLocked()) {
2207 onWorkspaceLockedChanged();
2208 }
2209 }
2210
2211 private void setWaitingForResult(boolean value) {
2212 boolean isLocked = isWorkspaceLocked();
2213 mWaitingForResult = value;
2214 if (isLocked != isWorkspaceLocked()) {
2215 onWorkspaceLockedChanged();
2216 }
2217 }
2218
2219 protected void onWorkspaceLockedChanged() { }
2220
Michael Jurka0280c3b2010-09-17 15:00:07 -07002221 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002222 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002223 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002224 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2225 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002226 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002227 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002228 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002229
Adam Cohenad4e15c2013-10-17 16:21:35 -07002230 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2231 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2232 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2233 }
2234
2235 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2236 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2237 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002238 if (appWidgetInfo.configure != null) {
2239 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002240 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002241
Bjorn Bringert7984c942009-12-09 15:38:25 +00002242 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002243 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2244 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2245
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002246 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002247 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002248 Runnable onComplete = new Runnable() {
2249 @Override
2250 public void run() {
2251 // Exit spring loaded mode if necessary after adding the widget
2252 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2253 null);
2254 }
2255 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002256 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002257 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002258 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002259 }
2260 }
Romain Guycbb89e42009-06-08 15:52:54 -07002261
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002262 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002263 // Close any folders that may be open.
2264 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002265 mWorkspace.moveToCustomContentScreen(animate);
2266 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002267 /**
2268 * Process a shortcut drop.
2269 *
2270 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002271 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002272 * @param cell The cell it should be added to, optional
2273 * @param position The location on the screen where it was dropped, optional
2274 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002275 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002276 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002277 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002278 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002279 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002280 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002281
2282 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002283 mPendingAddInfo.cellX = cell[0];
2284 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002285 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002286
2287 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2288 createShortcutIntent.setComponent(componentName);
2289 processShortcut(createShortcutIntent);
2290 }
2291
Adam Cohenfbba09b2011-07-18 21:43:05 -07002292 /**
2293 * Process a widget drop.
2294 *
2295 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002296 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002297 * @param cell The cell it should be added to, optional
2298 * @param position The location on the screen where it was dropped, optional
2299 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002300 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002301 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002302 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002303 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002304 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002305 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002306 mPendingAddInfo.minSpanX = info.minSpanX;
2307 mPendingAddInfo.minSpanY = info.minSpanY;
2308
Adam Cohenfbba09b2011-07-18 21:43:05 -07002309 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002310 mPendingAddInfo.cellX = cell[0];
2311 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002312 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002313 if (span != null) {
2314 mPendingAddInfo.spanX = span[0];
2315 mPendingAddInfo.spanY = span[1];
2316 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002317
Adam Cohened66b2b2012-01-23 17:28:51 -08002318 AppWidgetHostView hostView = info.boundWidget;
2319 int appWidgetId;
2320 if (hostView != null) {
2321 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002322 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002323 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002324 // In this case, we either need to start an activity to get permission to bind
2325 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002326 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002327 Bundle options = info.bindOptions;
2328
Sunny Goyalffe83f12014-08-14 17:39:34 -07002329 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2330 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002331 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002332 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002333 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002334 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002335 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2336 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2337 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002338 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2339 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002340 // TODO: we need to make sure that this accounts for the options bundle.
2341 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002342 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2343 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002344 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002345 }
2346
Joe Onoratodeb98af2010-02-19 14:59:39 -08002347 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002348 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002349 }
2350
Winson Chung24ab2f12010-09-16 14:10:47 -07002351 void processWallpaper(Intent intent) {
2352 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2353 }
2354
Adam Cohendcd297f2013-06-18 13:13:40 -07002355 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002356 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002357 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002358 folderInfo.title = getText(R.string.folder_name);
2359
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002360 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002361 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002362 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002363 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002364
2365 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002366 FolderIcon newFolder =
2367 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002368 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002369 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002370 // Force measure the new folder icon
2371 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2372 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002373 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002374 }
Romain Guycbb89e42009-06-08 15:52:54 -07002375
Jose Pascoal8bdb3642015-02-13 13:15:11 +00002376 static void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002377 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002378 }
2379
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002380 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002381 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002382 }
2383
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002384 /**
2385 * Registers various content observers. The current implementation registers
2386 * only a favorites observer to keep track of the favorites applications.
2387 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002388 private void registerContentObservers() {
2389 ContentResolver resolver = getContentResolver();
2390 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2391 true, mWidgetObserver);
2392 }
2393
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002394 @Override
2395 public boolean dispatchKeyEvent(KeyEvent event) {
2396 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2397 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002398 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002399 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002400 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002401 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002402 dumpState();
2403 return true;
2404 }
2405 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002406 }
2407 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2408 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002409 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002410 return true;
2411 }
2412 }
2413
2414 return super.dispatchKeyEvent(event);
2415 }
2416
Joe Onorato88ec0992009-11-19 13:16:06 -08002417 @Override
2418 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002419 if (isAllAppsVisible()) {
Jose Pascoal3c0767e2014-12-03 18:52:04 +00002420 hideAgingAppDrawer();
Adam Cohened307df2013-10-02 09:37:31 -07002421 if (mAppsCustomizeContent.getContentType() ==
2422 AppsCustomizePagedView.ContentType.Applications) {
2423 showWorkspace(true);
2424 } else {
2425 showOverviewMode(true);
2426 }
Jose Pascoal3c0767e2014-12-03 18:52:04 +00002427 } else if(isAgingAppDrawerVisible()){
2428 hideAgingAppDrawer();
Jose Pascoalcc1a43b2015-01-26 20:46:43 +00002429 } else if (mWorkspace.isInOverviewMode() && !mWorkspace.isSwitchingState()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002430 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002431 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002432 Folder openFolder = mWorkspace.getOpenFolder();
2433 if (openFolder.isEditingName()) {
2434 openFolder.dismissEditingName();
2435 } else {
2436 closeFolder();
2437 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002438 } else {
Jose Pascoal3c0767e2014-12-03 18:52:04 +00002439 hideAgingAppDrawer();
Jose Pascoalcc1a43b2015-01-26 20:46:43 +00002440 if(mWorkspace.isInWidgetResizeMode()){
2441 mWorkspace.exitWidgetResizeMode();
2442
2443 // Back button is a no-op here, but give at least some feedback for the button press
2444 mWorkspace.showOutlinesTemporarily();
2445 }
Michael Jurkaaf442092010-06-10 17:01:57 -07002446 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002447 }
2448
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002449 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002450 * Re-listen when widgets are reset.
2451 */
2452 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002453 if (mAppWidgetHost != null) {
2454 mAppWidgetHost.startListening();
2455 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002456 }
2457
2458 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002459 * Launches the intent referred by the clicked shortcut.
2460 *
2461 * @param v The view representing the clicked shortcut.
2462 */
2463 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002464 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2465 // view has detached (it's possible for this to happen if the view is removed mid touch).
2466 if (v.getWindowToken() == null) {
2467 return;
2468 }
2469
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002470 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002471 return;
2472 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002473
Adam Cohen1697b792013-09-17 19:08:21 -07002474 if (v instanceof Workspace) {
2475 if (mWorkspace.isInOverviewMode()) {
2476 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002477 }
2478 return;
2479 }
2480
2481 if (v instanceof CellLayout) {
2482 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002483 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002484 }
2485 }
2486
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002487 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002488 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002489 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002490 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002491 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002492 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002493 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002494 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002495 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002496 } else if (tag instanceof AppInfo) {
2497 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002498 } else if (tag instanceof LauncherAppWidgetInfo) {
2499 if (v instanceof PendingAppWidgetHostView) {
2500 onClickPendingWidget((PendingAppWidgetHostView) v);
2501 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002502 }
2503 }
2504
Sunny Goyal508da152014-08-14 10:53:27 -07002505 public void onClickPagedViewIcon(View v) {
2506 startAppShortcutOrInfoActivity(v);
2507 }
2508
Michael Jurka0e260592010-06-30 17:07:39 -07002509 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002510 return false;
2511 }
2512
Michael Jurkaaf442092010-06-10 17:01:57 -07002513 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002514 * Event handler for the app widget view which has not fully restored.
2515 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002516 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
2517 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002518 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002519 int widgetId = info.appWidgetId;
2520 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2521 if (appWidgetInfo != null) {
2522 mPendingAddWidgetInfo = appWidgetInfo;
2523 mPendingAddInfo.copyFrom(info);
2524 mPendingAddWidgetId = widgetId;
2525
Sunny Goyalffe83f12014-08-14 17:39:34 -07002526 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2527 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002528 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002529 } else if (info.installProgress < 0) {
2530 // The install has not been queued
2531 final String packageName = info.providerName.getPackageName();
2532 showBrokenAppInstallDialog(packageName,
2533 new DialogInterface.OnClickListener() {
2534 public void onClick(DialogInterface dialog, int id) {
2535 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2536 }
2537 });
2538 } else {
2539 // Download has started.
2540 final String packageName = info.providerName.getPackageName();
2541 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002542 }
2543 }
2544
2545 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002546 * Event handler for the search button
2547 *
2548 * @param v The view that was clicked.
2549 */
2550 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002551 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2552
Amith Yamasania135ba82011-08-09 17:42:01 -07002553 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002554 }
2555
2556 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002557 * Event handler for the voice button
2558 *
2559 * @param v The view that was clicked.
2560 */
2561 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002562 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002563
Bjorn Bringertc459e522013-06-07 19:36:01 +01002564 startVoice();
2565 }
2566
2567 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002568 try {
2569 final SearchManager searchManager =
2570 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2571 ComponentName activityName = searchManager.getGlobalSearchActivity();
2572 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002573 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002574 if (activityName != null) {
2575 intent.setPackage(activityName.getPackageName());
2576 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002577 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002578 } catch (ActivityNotFoundException e) {
2579 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002580 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002581 startActivitySafely(null, intent, "onClickVoiceButton");
2582 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002583 }
2584
2585 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002586 * Event handler for the "grid" button that appears on the home screen, which
2587 * enters all apps mode.
2588 *
2589 * @param v The view that was clicked.
2590 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002591 protected void onClickAllAppsButton(View v) {
Jose Pascoal65766f82015-02-10 17:55:27 +00002592 if (LOGD) {
2593 Log.d(TAG, "onClickAllAppsButton");
2594 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002595 if (isAllAppsVisible()) {
2596 showWorkspace(true);
Jose Pascoal3c0767e2014-12-03 18:52:04 +00002597 } else if(!isAllAppsVisible()){
2598 showAgingAppDrawer();
2599 }else {
2600 hideAgingAppDrawer();
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002601 }
2602 }
Jose Pascoalca875e52014-11-24 12:34:59 +00002603
2604 public void showAllAppsDrawer(){
2605 onClickAllAppsButton(null);
2606 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002607
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002608 private void showBrokenAppInstallDialog(final String packageName,
2609 DialogInterface.OnClickListener onSearchClickListener) {
Sunny Goyalf8763012014-09-23 16:22:10 -07002610 new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_DeviceDefault))
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002611 .setTitle(R.string.abandoned_promises_title)
2612 .setMessage(R.string.abandoned_promise_explanation)
2613 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2614 .setNeutralButton(R.string.abandoned_clean_this,
2615 new DialogInterface.OnClickListener() {
2616 public void onClick(DialogInterface dialog, int id) {
2617 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2618 mWorkspace.removeAbandonedPromise(packageName, user);
2619 }
2620 })
2621 .create().show();
2622 return;
2623 }
2624
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002625 /**
2626 * Event handler for an app shortcut click.
2627 *
2628 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2629 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002630 protected void onClickAppShortcut(final View v) {
Jose Pascoal65766f82015-02-10 17:55:27 +00002631 if (LOGD) {
2632 Log.d(TAG, "onClickAppShortcut");
2633 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002634 Object tag = v.getTag();
2635 if (!(tag instanceof ShortcutInfo)) {
2636 throw new IllegalArgumentException("Input must be a Shortcut");
2637 }
2638
2639 // Open shortcut
2640 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2641 final Intent intent = shortcut.intent;
2642
2643 // Check for special shortcuts
2644 if (intent.getComponent() != null) {
2645 final String shortcutClass = intent.getComponent().getClassName();
2646
2647 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2648 MemoryDumpActivity.startDump(this);
2649 return;
2650 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2651 toggleShowWeightWatcher();
2652 return;
2653 }
2654 }
2655
Chris Wren40c5ed32014-06-24 18:24:23 -04002656 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002657 if ((v instanceof BubbleTextView)
2658 && shortcut.isPromise()
2659 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002660 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002661 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002662 new DialogInterface.OnClickListener() {
2663 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002664 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002665 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002666 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002667 return;
2668 }
2669
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002670 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002671 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002672 }
2673
Sunny Goyal508da152014-08-14 10:53:27 -07002674 private void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002675 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002676 final ShortcutInfo shortcut;
2677 final Intent intent;
2678 if (tag instanceof ShortcutInfo) {
2679 shortcut = (ShortcutInfo) tag;
2680 intent = shortcut.intent;
2681 int[] pos = new int[2];
2682 v.getLocationOnScreen(pos);
2683 intent.setSourceBounds(new Rect(pos[0], pos[1],
2684 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002685
Sunny Goyal508da152014-08-14 10:53:27 -07002686 } else if (tag instanceof AppInfo) {
2687 shortcut = null;
2688 intent = ((AppInfo) tag).intent;
2689 } else {
2690 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2691 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002692
2693 boolean success = startActivitySafely(v, intent, tag);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002694 mStats.recordLaunch(intent, shortcut);
Jose Pascoal61169492014-11-25 16:15:23 +00002695
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002696 if (success && v instanceof BubbleTextView) {
2697 mWaitingForResume = (BubbleTextView) v;
2698 mWaitingForResume.setStayPressed(true);
2699 }
2700 }
2701
2702 /**
2703 * Event handler for a folder icon click.
2704 *
2705 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2706 */
2707 protected void onClickFolderIcon(View v) {
Jose Pascoal65766f82015-02-10 17:55:27 +00002708 if (LOGD) {
2709 Log.d(TAG, "onClickFolder");
2710 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002711 if (!(v instanceof FolderIcon)){
2712 throw new IllegalArgumentException("Input must be a FolderIcon");
2713 }
2714
2715 FolderIcon folderIcon = (FolderIcon) v;
2716 final FolderInfo info = folderIcon.getFolderInfo();
2717 Folder openFolder = mWorkspace.getFolderForTag(info);
2718
2719 // If the folder info reports that the associated folder is open, then verify that
2720 // it is actually opened. There have been a few instances where this gets out of sync.
2721 if (info.opened && openFolder == null) {
2722 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2723 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2724 info.opened = false;
2725 }
2726
2727 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2728 // Close any open folder
2729 closeFolder();
2730 // Open the requested folder
2731 openFolder(folderIcon);
2732 } else {
2733 // Find the open folder...
2734 int folderScreen;
2735 if (openFolder != null) {
2736 folderScreen = mWorkspace.getPageForView(openFolder);
2737 // .. and close it
2738 closeFolder(openFolder);
2739 if (folderScreen != mWorkspace.getCurrentPage()) {
2740 // Close any folder open on the current screen
2741 closeFolder();
2742 // Pull the folder onto this screen
2743 openFolder(folderIcon);
2744 }
2745 }
2746 }
Michael Jurka5130e402011-10-13 04:55:35 -07002747 }
2748
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002749 /**
2750 * Event handler for the (Add) Widgets button that appears after a long press
2751 * on the home screen.
2752 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002753 protected void onClickAddWidgetButton(View view) {
Jose Pascoal65766f82015-02-10 17:55:27 +00002754 if (LOGD) {
2755 Log.d(TAG, "onClickAddWidgetButton");
2756 }
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002757 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2758 }
2759
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002760 /**
2761 * Event handler for the wallpaper picker button that appears after a long press
2762 * on the home screen.
2763 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002764 protected void onClickWallpaperPicker(View v) {
Jose Pascoal65766f82015-02-10 17:55:27 +00002765 if (LOGD) {
2766 Log.d(TAG, "onClickWallpaperPicker");
2767 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002768 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2769 pickWallpaper.setComponent(getWallpaperPickerComponent());
2770 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2771 }
2772
2773 /**
2774 * Event handler for a click on the settings button that appears after a long press
2775 * on the home screen.
2776 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002777 protected void onClickSettingsButton(View v) {
Jose Pascoal65766f82015-02-10 17:55:27 +00002778 if (LOGD) {
2779 Log.d(TAG, "onClickSettingsButton");
2780 }
Jose Pascoalfa945132014-11-25 12:57:42 +00002781 startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), REQUEST_PICK_SETTINGS);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002782 }
2783
Jose Pascoal8bdb3642015-02-13 13:15:11 +00002784 public static void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002785 // Provide the same haptic feedback that the system offers for virtual keys.
2786 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002787 }
2788
Jose Pascoal8bdb3642015-02-13 13:15:11 +00002789 public static void performHapticFeedbackOnTouchDown(View v) {
Adam Cohen61f560d2013-09-30 15:58:20 -07002790 // Provide the same haptic feedback that the system offers for virtual keys.
2791 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2792 }
2793
2794 public View.OnTouchListener getHapticFeedbackTouchListener() {
2795 if (mHapticFeedbackTouchListener == null) {
2796 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2797 @Override
2798 public boolean onTouch(View v, MotionEvent event) {
2799 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2800 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2801 }
2802 return false;
2803 }
2804 };
2805 }
2806 return mHapticFeedbackTouchListener;
2807 }
2808
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002809 public void onDragStarted(View view) {}
2810
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002811 /**
2812 * Called when the user stops interacting with the launcher.
2813 * This implies that the user is now on the homescreen and is not doing housekeeping.
2814 */
2815 protected void onInteractionEnd() {}
2816
2817 /**
2818 * Called when the user starts interacting with the launcher.
2819 * The possible interactions are:
2820 * - open all apps
2821 * - reorder an app shortcut, or a widget
2822 * - open the overview mode.
2823 * This is a good time to stop doing things that only make sense
2824 * when the user is on the homescreen and not doing housekeeping.
2825 */
2826 protected void onInteractionBegin() {}
2827
Kenny Guyf07af7b2014-07-31 11:39:16 +01002828 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Kenny Guyf07af7b2014-07-31 11:39:16 +01002829 try {
2830 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
Kenny Guyf07af7b2014-07-31 11:39:16 +01002831 launcherApps.showAppDetailsForProfile(componentName, user);
2832 } catch (SecurityException e) {
2833 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2834 Log.e(TAG, "Launcher does not have permission to launch settings");
2835 } catch (ActivityNotFoundException e) {
2836 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2837 Log.e(TAG, "Unable to launch settings");
2838 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002839 }
2840
Michael Jurka1e2f4652013-07-08 18:03:46 -07002841 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002842 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2843 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002844 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002845 // System applications cannot be installed. For now, show a toast explaining that.
2846 // We may give them the option of disabling apps this way.
2847 int messageId = R.string.uninstall_system_app_text;
2848 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002849 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002850 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002851 String packageName = componentName.getPackageName();
2852 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002853 Intent intent = new Intent(
2854 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002855 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2856 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002857 if (user != null) {
2858 user.addToIntent(intent, Intent.EXTRA_USER);
2859 }
Jose Pascoalca875e52014-11-24 12:34:59 +00002860
Patrick Dubroy5539af72010-09-07 15:22:01 -07002861 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002862 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002863 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002864 }
2865
Jose Pascoala046c672014-11-26 19:46:03 +00002866 public boolean startActivity(View v, Intent intent, Object tag) {
Jose Pascoalca875e52014-11-24 12:34:59 +00002867 ComponentName component = intent != null ? intent.getComponent() : null;
2868 Log.d(TAG, "Start Activity >>> " + (component != null ? component.toString() : "implicit Intent."));
2869
2870 boolean explicitIntent = component != null;
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002871 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002872 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002873 // Only launch using the new animation if the shortcut has not opted out (this is a
2874 // private contract between launcher and may be ignored in the future).
2875 boolean useLaunchAnimation = (v != null) &&
2876 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002877 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2878 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002879
Kenny Guy1317e2d2014-05-08 18:52:50 +01002880 UserHandleCompat user = null;
2881 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2882 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2883 user = userManager.getUserForSerialNumber(serialNumber);
2884 }
2885
2886 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002887 if (useLaunchAnimation) {
Kenny Guyd794a3f2014-09-16 15:17:58 +01002888 ActivityOptions opts = Utilities.isLmpOrAbove() ?
Adam Cohen4da294d2014-07-28 10:56:19 -07002889 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) :
2890 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Adam Cohen6ea3b112014-06-11 11:38:49 -07002891 optsBundle = opts.toBundle();
2892 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002893
2894 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2895 // Could be launching some bookkeeping activity
2896 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002897 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002898 // TODO Component can be null when shortcuts are supported for secondary user
Jose Pascoalca875e52014-11-24 12:34:59 +00002899 launcherApps.startActivityForProfile(intent.getComponent(), user,
2900 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002901 }
Jose Pascoalca875e52014-11-24 12:34:59 +00002902
2903 if (explicitIntent)
2904 {
2905 updateActivityInfoViaExplicitIntent(component);
2906 }
2907
Michael Jurkaddd62e92011-02-16 17:49:14 -08002908 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002909 } catch (SecurityException e) {
2910 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002911 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002912 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002913 "or use the exported attribute for this activity. "
2914 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002915 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002916 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002917 }
Jose Pascoalca875e52014-11-24 12:34:59 +00002918
2919 public boolean launchActivity(View v, Intent intent, Object tag){
2920 return startActivity(v, intent, tag);
2921 }
2922
Michael Jurka86a720e2012-05-09 11:23:23 -07002923 boolean startActivitySafely(View v, Intent intent, Object tag) {
2924 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002925 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2926 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2927 return false;
2928 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002929 try {
2930 success = startActivity(v, intent, tag);
2931 } catch (ActivityNotFoundException e) {
2932 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2933 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2934 }
2935 return success;
2936 }
2937
Adam Cohen268c4752012-06-06 17:47:33 -07002938 /**
2939 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2940 * in the DragLayer in the exact absolute location of the original FolderIcon.
2941 */
2942 private void copyFolderIconToImage(FolderIcon fi) {
2943 final int width = fi.getMeasuredWidth();
2944 final int height = fi.getMeasuredHeight();
2945
2946 // Lazy load ImageView, Bitmap and Canvas
2947 if (mFolderIconImageView == null) {
2948 mFolderIconImageView = new ImageView(this);
2949 }
2950 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2951 mFolderIconBitmap.getHeight() != height) {
2952 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2953 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2954 }
2955
2956 DragLayer.LayoutParams lp;
2957 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2958 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2959 } else {
2960 lp = new DragLayer.LayoutParams(width, height);
2961 }
2962
Adam Cohen307fe232012-08-16 17:55:58 -07002963 // The layout from which the folder is being opened may be scaled, adjust the starting
2964 // view size by this scale factor.
2965 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002966 lp.customPosition = true;
2967 lp.x = mRectForFolderAnimation.left;
2968 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002969 lp.width = (int) (scale * width);
2970 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002971
2972 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2973 fi.draw(mFolderIconCanvas);
2974 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002975 if (fi.getFolder() != null) {
2976 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2977 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002978 }
Adam Cohen268c4752012-06-06 17:47:33 -07002979 // Just in case this image view is still in the drag layer from a previous animation,
2980 // we remove it and re-add it.
2981 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2982 mDragLayer.removeView(mFolderIconImageView);
2983 }
2984 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002985 if (fi.getFolder() != null) {
2986 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002987 }
Adam Cohen268c4752012-06-06 17:47:33 -07002988 }
2989
Adam Cohen2801caf2011-05-13 20:57:39 -07002990 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Jose Pascoal65766f82015-02-10 17:55:27 +00002991 if (fi == null) {
2992 return;
2993 }
Adam Cohen2801caf2011-05-13 20:57:39 -07002994 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2995 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2996 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2997
Adam Cohen268c4752012-06-06 17:47:33 -07002998 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2999 copyFolderIconToImage(fi);
3000 fi.setVisibility(View.INVISIBLE);
3001
Michael Jurka2ecf9952012-06-18 12:52:28 -07003002 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07003003 scaleX, scaleY);
Kenny Guyd794a3f2014-09-16 15:17:58 +01003004 if (Utilities.isLmpOrAbove()) {
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003005 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3006 }
3007 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07003008 oa.start();
3009 }
3010
Adam Cohen268c4752012-06-06 17:47:33 -07003011 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Jose Pascoal65766f82015-02-10 17:55:27 +00003012 if (fi == null) {
3013 return;
3014 }
Adam Cohen2801caf2011-05-13 20:57:39 -07003015 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
3016 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
3017 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
3018
Adam Cohen268c4752012-06-06 17:47:33 -07003019 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07003020
Adam Cohen268c4752012-06-06 17:47:33 -07003021 // We remove and re-draw the FolderIcon in-case it has changed
3022 mDragLayer.removeView(mFolderIconImageView);
3023 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07003024 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07003025 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07003026 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07003027 oa.addListener(new AnimatorListenerAdapter() {
3028 @Override
3029 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07003030 if (cl != null) {
3031 cl.clearFolderLeaveBehind();
3032 // Remove the ImageView copy of the FolderIcon and make the original visible.
3033 mDragLayer.removeView(mFolderIconImageView);
3034 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07003035 }
3036 }
3037 });
Adam Cohen2801caf2011-05-13 20:57:39 -07003038 oa.start();
3039 }
3040
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003041 /**
Michael Jurka774bd372010-10-22 13:40:50 -07003042 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003043 * is animated relative to the specified View. If the View is null, no animation
3044 * is played.
3045 *
3046 * @param folderInfo The FolderInfo describing the folder to open.
3047 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07003048 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07003049 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07003050 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003051
Adam Cohena9cf38f2011-05-02 15:36:58 -07003052 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003053
Adam Cohen4554ee12011-08-03 16:13:21 -07003054 // Just verify that the folder hasn't already been added to the DragLayer.
3055 // There was a one-off crash where the folder had a parent already.
3056 if (folder.getParent() == null) {
3057 mDragLayer.addView(folder);
3058 mDragController.addDropTarget((DropTarget) folder);
3059 } else {
3060 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3061 folder.getParent() + ").");
3062 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07003063 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07003064 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07003065
3066 // Notify the accessibility manager that this folder "window" has appeared and occluded
3067 // the workspace items
3068 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3069 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07003070 }
3071
3072 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08003073 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07003074 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07003075 if (folder.isEditingName()) {
3076 folder.dismissEditingName();
3077 }
Adam Cohen4554ee12011-08-03 16:13:21 -07003078 closeFolder(folder);
3079 }
3080 }
3081
3082 void closeFolder(Folder folder) {
3083 folder.getInfo().opened = false;
3084
3085 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3086 if (parent != null) {
3087 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3088 shrinkAndFadeInFolderIcon(fi);
3089 }
3090 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003091
3092 // Notify the accessibility manager that this folder "window" has disappeard and no
3093 // longer occludeds the workspace items
3094 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003095 }
3096
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003097 public boolean onLongClick(View v) {
Jose Pascoal65766f82015-02-10 17:55:27 +00003098 if (!isDraggingEnabled()) {
3099 return false;
3100 }
3101 if (isWorkspaceLocked()) {
3102 return false;
3103 }
3104 if (mState != State.WORKSPACE) {
3105 return false;
3106 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003107
Adam Cohen1697b792013-09-17 19:08:21 -07003108 if (v instanceof Workspace) {
3109 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07003110 if (mWorkspace.enterOverviewMode()) {
3111 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3112 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3113 return true;
3114 } else {
3115 return false;
3116 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003117 } else {
3118 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003119 }
Adam Cohen1697b792013-09-17 19:08:21 -07003120 }
3121
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003122 CellLayout.CellInfo longClickCellInfo = null;
3123 View itemUnderLongClick = null;
3124 if (v.getTag() instanceof ItemInfo) {
3125 ItemInfo info = (ItemInfo) v.getTag();
Jose Pascoal3379bd12015-02-10 12:34:48 +00003126 longClickCellInfo = new CellLayout.CellInfo(v, info);
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003127 itemUnderLongClick = longClickCellInfo.cell;
3128 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003129 }
3130
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00003131 boolean allowLongPress = mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07003132 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003133 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003134 // User long pressed on empty space
3135 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3136 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003137 if (mWorkspace.isInOverviewMode()) {
3138 mWorkspace.startReordering(v);
3139 } else {
3140 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07003141 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003142 } else {
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00003143 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003144 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003145 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003146 }
3147 }
3148 }
3149 return true;
3150 }
3151
Winson Chung3d503fb2011-07-13 17:25:49 -07003152 /**
3153 * Returns the CellLayout of the specified container at the specified screen.
3154 */
Adam Cohendcd297f2013-06-18 13:13:40 -07003155 CellLayout getCellLayout(long container, long screenId) {
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00003156 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003157 }
3158
Daniel Sandler843e8602010-06-07 14:59:01 -04003159 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003160 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003161 }
3162
Craig Mautner360310b2012-10-26 15:13:08 -07003163 private void setWorkspaceBackground(boolean workspace) {
3164 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003165 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003166 }
3167
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003168 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003169 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3170 int curflags = getWindow().getAttributes().flags
3171 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3172 if (wpflags != curflags) {
3173 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3174 }
Craig Mautner360310b2012-10-26 15:13:08 -07003175 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003176 }
3177
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003178 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3179 if (v instanceof LauncherTransitionable) {
3180 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3181 }
3182 }
3183
Michael Jurkabed61d22012-02-14 22:51:29 -08003184 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3185 if (v instanceof LauncherTransitionable) {
3186 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3187 }
Winson Chung70442722012-02-10 15:43:22 -08003188
3189 // Update the workspace transition step as well
3190 dispatchOnLauncherTransitionStep(v, 0f);
3191 }
3192
3193 private void dispatchOnLauncherTransitionStep(View v, float t) {
3194 if (v instanceof LauncherTransitionable) {
3195 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3196 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003197 }
3198
3199 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3200 if (v instanceof LauncherTransitionable) {
3201 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3202 }
Winson Chung70442722012-02-10 15:43:22 -08003203
3204 // Update the workspace transition step as well
3205 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003206 }
3207
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003208 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003209 * Things to test when changing the following seven functions.
3210 * - Home from workspace
3211 * - from center screen
3212 * - from other screens
3213 * - Home from all apps
3214 * - from center screen
3215 * - from other screens
3216 * - Back from all apps
3217 * - from center screen
3218 * - from other screens
3219 * - Launch app from workspace and quit
3220 * - with back
3221 * - with home
3222 * - Launch app from all apps and quit
3223 * - with back
3224 * - with home
3225 * - Go to a screen that's not the default, then all
3226 * apps, and launch and app, and go back
3227 * - with back
3228 * -with home
3229 * - On workspace, long press power and go back
3230 * - with back
3231 * - with home
3232 * - On all apps, long press power and go back
3233 * - with back
3234 * - with home
3235 * - On workspace, power off
3236 * - On all apps, power off
3237 * - Launch an app and turn off the screen while in that app
3238 * - Go back with home key
3239 * - Go back with back key TODO: make this not go to workspace
3240 * - From all apps
3241 * - From workspace
3242 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3243 * - From all apps
3244 * - From the center workspace
3245 * - From another workspace
3246 */
3247
3248 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003249 * Zoom the camera out from the workspace to reveal 'toView'.
3250 * Assumes that the view to show is anchored at either the very top or very bottom
3251 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003252 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003253 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003254 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3255 showAppsCustomizeHelper(animated, springLoaded, contentType);
3256 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003257
Winson Chungc58497e2013-09-03 17:48:37 -07003258 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3259 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003260 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003261 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003262 mStateAnimation.cancel();
3263 mStateAnimation = null;
3264 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003265
Kenny Guyd794a3f2014-09-16 15:17:58 +01003266 boolean material = Utilities.isLmpOrAbove();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003267
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003268 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003269
Adam Cohen6c5891a2014-07-09 23:53:15 -07003270 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003271 final int itemsAlphaStagger =
3272 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003273
Michael Jurkabed61d22012-02-14 22:51:29 -08003274 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003275 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07003276
Adam Cohen2854d252014-08-27 16:04:07 -07003277 final ArrayList<View> layerViews = new ArrayList<View>();
3278
Adam Cohen6c5891a2014-07-09 23:53:15 -07003279 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3280 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003281 Animator workspaceAnim =
Adam Cohen2854d252014-08-27 16:04:07 -07003282 mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003283 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003284 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3285 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003286 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3287 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003288
Adam Cohena38dc902014-09-07 17:48:55 +02003289 // If for some reason our views aren't initialized, don't animate
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00003290 boolean initialized = getPageIndicator() != null;
Adam Cohena38dc902014-09-07 17:48:55 +02003291
3292 if (animated && initialized) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003293 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen9bfdb762014-07-21 17:44:06 -07003294 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3295 toView.findViewById(R.id.apps_customize_pane_content);
Adam Cohenf16e5712011-01-13 13:31:45 -08003296
Adam Cohen9bfdb762014-07-21 17:44:06 -07003297 final View page = content.getPageAt(content.getCurrentPage());
3298 final View revealView = toView.findViewById(R.id.fake_page);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003299
Adam Cohen63f1ec02014-08-12 09:23:13 -07003300 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3301 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003302 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3303 } else {
3304 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3305 }
3306
Adam Cohen9bfdb762014-07-21 17:44:06 -07003307 // Hide the real page background, and swap in the fake one
Adam Cohen9bfdb762014-07-21 17:44:06 -07003308 content.setPageBackgroundsVisible(false);
Adam Cohen2854d252014-08-27 16:04:07 -07003309 revealView.setVisibility(View.VISIBLE);
3310 // We need to hide this view as the animation start will be posted.
3311 revealView.setAlpha(0);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003312
Adam Cohen9bfdb762014-07-21 17:44:06 -07003313 int width = revealView.getMeasuredWidth();
3314 int height = revealView.getMeasuredHeight();
Adam Cohen9bfdb762014-07-21 17:44:06 -07003315 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen2854d252014-08-27 16:04:07 -07003316
Adam Cohen63f1ec02014-08-12 09:23:13 -07003317 revealView.setTranslationY(0);
Adam Cohen94afab42014-08-24 16:10:54 -07003318 revealView.setTranslationX(0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003319
Adam Cohen63f1ec02014-08-12 09:23:13 -07003320 // Get the y delta between the center of the page and the center of the all apps button
3321 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00003322 getPageIndicator(), null);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003323
Adam Cohen2854d252014-08-27 16:04:07 -07003324 float alpha = 0;
Jose Pascoalfe3b08b2015-02-11 18:01:38 +00003325 float xDrift;
3326 float yDrift;
Adam Cohen2854d252014-08-27 16:04:07 -07003327 if (material) {
3328 alpha = isWidgetTray ? 0.3f : 1f;
3329 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3330 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3331 } else {
3332 yDrift = 2 * height / 3;
3333 xDrift = 0;
3334 }
3335 final float initAlpha = alpha;
3336
Adam Cohen9bfdb762014-07-21 17:44:06 -07003337 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen2854d252014-08-27 16:04:07 -07003338 layerViews.add(revealView);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003339 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
Adam Cohen94afab42014-08-24 16:10:54 -07003340 PropertyValuesHolder panelDriftY =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003341 PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
Adam Cohen94afab42014-08-24 16:10:54 -07003342 PropertyValuesHolder panelDriftX =
3343 PropertyValuesHolder.ofFloat("translationX", xDrift, 0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003344
Adam Cohen2854d252014-08-27 16:04:07 -07003345 ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView,
3346 panelAlpha, panelDriftY, panelDriftX);
3347
Adam Cohen9bfdb762014-07-21 17:44:06 -07003348 panelAlphaAndDrift.setDuration(revealDuration);
3349 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003350
Adam Cohen9bfdb762014-07-21 17:44:06 -07003351 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003352
Adam Cohen4e243a22014-08-10 18:30:55 -07003353 if (page != null) {
3354 page.setVisibility(View.VISIBLE);
3355 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen2854d252014-08-27 16:04:07 -07003356 layerViews.add(page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003357
Adam Cohen2854d252014-08-27 16:04:07 -07003358 ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0);
3359 page.setTranslationY(yDrift);
Adam Cohen4e243a22014-08-10 18:30:55 -07003360 pageDrift.setDuration(revealDuration);
3361 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003362 pageDrift.setStartDelay(itemsAlphaStagger);
Adam Cohen4e243a22014-08-10 18:30:55 -07003363 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003364
Adam Cohen63f1ec02014-08-12 09:23:13 -07003365 page.setAlpha(0f);
Adam Cohen2854d252014-08-27 16:04:07 -07003366 ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f);
Adam Cohen4e243a22014-08-10 18:30:55 -07003367 itemsAlpha.setDuration(revealDuration);
3368 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3369 itemsAlpha.setStartDelay(itemsAlphaStagger);
3370 mStateAnimation.play(itemsAlpha);
3371 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003372
Adam Cohen4e243a22014-08-10 18:30:55 -07003373 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3374 pageIndicators.setAlpha(0.01f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003375 ObjectAnimator indicatorsAlpha =
Adam Cohen2854d252014-08-27 16:04:07 -07003376 ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003377 indicatorsAlpha.setDuration(revealDuration);
3378 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003379
Adam Cohen9bfdb762014-07-21 17:44:06 -07003380 if (material) {
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00003381 final View pageIndicator = getPageIndicator();
Adam Cohen63f1ec02014-08-12 09:23:13 -07003382 int allAppsButtonSize = LauncherAppState.getInstance().
3383 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3384 float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Adam Cohen2854d252014-08-27 16:04:07 -07003385 Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2,
Adam Cohen63f1ec02014-08-12 09:23:13 -07003386 height / 2, startRadius, revealRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003387 reveal.setDuration(revealDuration);
3388 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003389
3390 reveal.addListener(new AnimatorListenerAdapter() {
3391 public void onAnimationStart(Animator animation) {
3392 if (!isWidgetTray) {
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00003393 pageIndicator.setVisibility(View.INVISIBLE);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003394 }
3395 }
3396 public void onAnimationEnd(Animator animation) {
3397 if (!isWidgetTray) {
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00003398 pageIndicator.setVisibility(View.VISIBLE);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003399 }
3400 }
3401 });
Adam Cohen6c5891a2014-07-09 23:53:15 -07003402 mStateAnimation.play(reveal);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003403 }
Michael Jurka1899a362011-11-03 13:50:45 -07003404
Adam Cohen9bfdb762014-07-21 17:44:06 -07003405 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3406 @Override
3407 public void onAnimationEnd(Animator animation) {
3408 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3409 dispatchOnLauncherTransitionEnd(toView, animated, false);
3410
3411 revealView.setVisibility(View.INVISIBLE);
3412 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003413 if (page != null) {
3414 page.setLayerType(View.LAYER_TYPE_NONE, null);
3415 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003416 content.setPageBackgroundsVisible(true);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003417 }
3418
Adam Cohen9bfdb762014-07-21 17:44:06 -07003419 });
3420
Adam Cohen6c5891a2014-07-09 23:53:15 -07003421 if (workspaceAnim != null) {
3422 mStateAnimation.play(workspaceAnim);
3423 }
Adam Cohen2854d252014-08-27 16:04:07 -07003424
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003425 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3426 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003427 final AnimatorSet stateAnimation = mStateAnimation;
3428 final Runnable startAnimRunnable = new Runnable() {
3429 public void run() {
3430 // Check that mStateAnimation hasn't changed while
3431 // we waited for a layout/draw pass
Jose Pascoal65766f82015-02-10 17:55:27 +00003432 if (mStateAnimation != stateAnimation) {
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003433 return;
Jose Pascoal65766f82015-02-10 17:55:27 +00003434 }
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003435 dispatchOnLauncherTransitionStart(fromView, animated, false);
3436 dispatchOnLauncherTransitionStart(toView, animated, false);
Adam Cohen2854d252014-08-27 16:04:07 -07003437
3438 revealView.setAlpha(initAlpha);
Kenny Guyd794a3f2014-09-16 15:17:58 +01003439 if (Utilities.isLmpOrAbove()) {
Filipee7484672015-09-22 11:50:56 +00003440
Adam Cohen2854d252014-08-27 16:04:07 -07003441 for (int i = 0; i < layerViews.size(); i++) {
3442 View v = layerViews.get(i);
Adam Cohen0f668f32014-09-08 19:54:17 +02003443 if (v != null) {
3444 boolean attached = true;
3445 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
3446 attached = v.isAttachedToWindow();
3447 }
Jose Pascoal65766f82015-02-10 17:55:27 +00003448 if (attached) {
3449 v.buildLayer();
3450 }
Adam Cohen0f668f32014-09-08 19:54:17 +02003451 }
Filipee7484672015-09-22 11:50:56 +00003452
Adam Cohen2854d252014-08-27 16:04:07 -07003453 }
3454 }
3455 mStateAnimation.start();
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003456 }
3457 };
Adam Cohen2854d252014-08-27 16:04:07 -07003458 toView.bringToFront();
3459 toView.setVisibility(View.VISIBLE);
3460 toView.post(startAnimRunnable);
Filipee7484672015-09-22 11:50:56 +00003461
3462 Log.wtf(TAG, "Launcher Show widgets showAppsCustomizeHelper final step");
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003463 } else {
3464 toView.setTranslationX(0.0f);
3465 toView.setTranslationY(0.0f);
3466 toView.setScaleX(1.0f);
3467 toView.setScaleY(1.0f);
3468 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003469 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003470
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003471 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003472 dispatchOnLauncherTransitionStart(fromView, animated, false);
3473 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003474 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003475 dispatchOnLauncherTransitionStart(toView, animated, false);
3476 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003477 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003478 }
3479
3480 /**
3481 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003482 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003483 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003484 */
Adam Cohened307df2013-10-02 09:37:31 -07003485 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003486 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003487
Michael Jurkab3e22d92011-10-31 15:58:33 -07003488 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003489 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003490 mStateAnimation.cancel();
3491 mStateAnimation = null;
3492 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003493
Kenny Guyd794a3f2014-09-16 15:17:58 +01003494 boolean material = Utilities.isLmpOrAbove();
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003495 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003496
Adam Cohen63f1ec02014-08-12 09:23:13 -07003497 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003498 final int itemsAlphaStagger =
3499 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003500
Winson Chungf0ea4d32011-06-06 14:27:16 -07003501 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003502 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003503 Animator workspaceAnim = null;
Adam Cohen2854d252014-08-27 16:04:07 -07003504 final ArrayList<View> layerViews = new ArrayList<View>();
3505
Jose Pascoal43aab392014-12-05 18:00:55 +00003506 if (toState == Workspace.State.NORMAL || toState == Workspace.State.SPRING_LOADED || toState == Workspace.State.OVERVIEW) {
3507 workspaceAnim = mWorkspace.getChangeStateAnimation(toState, animated, layerViews);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003508 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003509
Adam Cohena38dc902014-09-07 17:48:55 +02003510 // If for some reason our views aren't initialized, don't animate
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00003511 boolean initialized = getPageIndicator() != null;
Adam Cohena38dc902014-09-07 17:48:55 +02003512
3513 if (animated && initialized) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003514 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen2854d252014-08-27 16:04:07 -07003515 if (workspaceAnim != null) {
3516 mStateAnimation.play(workspaceAnim);
3517 }
Michael Jurka159b4cc2012-01-17 03:00:35 -08003518
Adam Cohen9bfdb762014-07-21 17:44:06 -07003519 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3520 fromView.findViewById(R.id.apps_customize_pane_content);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003521
Adam Cohen9bfdb762014-07-21 17:44:06 -07003522 final View page = content.getPageAt(content.getNextPage());
Adam Cohen8e894fa2014-09-08 19:45:43 +02003523
3524 // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases
3525 int count = content.getChildCount();
3526 for (int i = 0; i < count; i++) {
3527 View child = content.getChildAt(i);
3528 if (child != page) {
3529 child.setVisibility(View.INVISIBLE);
3530 }
3531 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003532 final View revealView = fromView.findViewById(R.id.fake_page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003533
Adam Cohen2854d252014-08-27 16:04:07 -07003534 // hideAppsCustomizeHelper is called in some cases when it is already hidden
3535 // don't perform all these no-op animations. In particularly, this was causing
3536 // the all-apps button to pop in and out.
3537 if (fromView.getVisibility() == View.VISIBLE) {
3538 AppsCustomizePagedView.ContentType contentType = content.getContentType();
3539 final boolean isWidgetTray =
3540 contentType == AppsCustomizePagedView.ContentType.Widgets;
Adam Cohen63f1ec02014-08-12 09:23:13 -07003541
Adam Cohen2854d252014-08-27 16:04:07 -07003542 if (isWidgetTray) {
3543 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3544 } else {
3545 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003546 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003547
Adam Cohen2854d252014-08-27 16:04:07 -07003548 int width = revealView.getMeasuredWidth();
3549 int height = revealView.getMeasuredHeight();
3550 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
3551
3552 // Hide the real page background, and swap in the fake one
3553 revealView.setVisibility(View.VISIBLE);
3554 content.setPageBackgroundsVisible(false);
3555
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00003556 final View pageIndicatorView = getPageIndicator();
Adam Cohen2854d252014-08-27 16:04:07 -07003557 revealView.setTranslationY(0);
3558 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00003559 pageIndicatorView, null);
Adam Cohen2854d252014-08-27 16:04:07 -07003560
Jose Pascoalfe3b08b2015-02-11 18:01:38 +00003561 float xDrift;
3562 float yDrift;
Adam Cohen2854d252014-08-27 16:04:07 -07003563 if (material) {
3564 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3565 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3566 } else {
3567 yDrift = 5 * height / 4;
3568 xDrift = 0;
3569 }
3570
3571 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3572 TimeInterpolator decelerateInterpolator = material ?
3573 new LogDecelerateInterpolator(100, 0) :
3574 new LogDecelerateInterpolator(30, 0);
3575
3576 // The vertical motion of the apps panel should be delayed by one frame
3577 // from the conceal animation in order to give the right feel. We correpsondingly
3578 // shorten the duration so that the slide and conceal end at the same time.
3579 ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY",
3580 0, yDrift);
3581 panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3582 panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3583 panelDriftY.setInterpolator(decelerateInterpolator);
3584 mStateAnimation.play(panelDriftY);
3585
3586 ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX",
3587 0, xDrift);
3588 panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3589 panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3590 panelDriftX.setInterpolator(decelerateInterpolator);
3591 mStateAnimation.play(panelDriftX);
3592
3593 if (isWidgetTray || !material) {
3594 float finalAlpha = material ? 0.4f : 0f;
3595 revealView.setAlpha(1f);
3596 ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha",
3597 1f, finalAlpha);
3598 panelAlpha.setDuration(revealDuration);
3599 panelAlpha.setInterpolator(material ? decelerateInterpolator :
3600 new AccelerateInterpolator(1.5f));
3601 mStateAnimation.play(panelAlpha);
3602 }
3603
3604 if (page != null) {
3605 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3606
3607 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
3608 0, yDrift);
3609 page.setTranslationY(0);
3610 pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3611 pageDrift.setInterpolator(decelerateInterpolator);
3612 pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3613 mStateAnimation.play(pageDrift);
3614
3615 page.setAlpha(1f);
3616 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
3617 itemsAlpha.setDuration(100);
3618 itemsAlpha.setInterpolator(decelerateInterpolator);
3619 mStateAnimation.play(itemsAlpha);
3620 }
3621
3622 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
3623 pageIndicators.setAlpha(1f);
3624 ObjectAnimator indicatorsAlpha =
3625 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
3626 indicatorsAlpha.setDuration(revealDuration);
3627 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3628 mStateAnimation.play(indicatorsAlpha);
3629
3630 width = revealView.getMeasuredWidth();
3631
3632 if (material) {
3633 if (!isWidgetTray) {
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00003634 pageIndicatorView.setVisibility(View.INVISIBLE);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003635 }
Adam Cohen2854d252014-08-27 16:04:07 -07003636 int allAppsButtonSize = LauncherAppState.getInstance().
3637 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3638 float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
3639 Animator reveal =
3640 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3641 height / 2, revealRadius, finalRadius);
3642 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3643 reveal.setDuration(revealDuration);
3644 reveal.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003645
Adam Cohen2854d252014-08-27 16:04:07 -07003646 reveal.addListener(new AnimatorListenerAdapter() {
3647 public void onAnimationEnd(Animator animation) {
3648 revealView.setVisibility(View.INVISIBLE);
3649 if (!isWidgetTray) {
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00003650 pageIndicatorView.setVisibility(View.VISIBLE);
Adam Cohen2854d252014-08-27 16:04:07 -07003651 }
3652 }
3653 });
Adam Cohen9bfdb762014-07-21 17:44:06 -07003654
Adam Cohen2854d252014-08-27 16:04:07 -07003655 mStateAnimation.play(reveal);
3656 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003657
Adam Cohen2854d252014-08-27 16:04:07 -07003658 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3659 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3660 mAppsCustomizeContent.stopScrolling();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003661 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003662
3663 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003664 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003665 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003666 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003667 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3668 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003669 if (onCompleteRunnable != null) {
3670 onCompleteRunnable.run();
3671 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003672
3673 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003674 if (page != null) {
3675 page.setLayerType(View.LAYER_TYPE_NONE, null);
3676 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003677 content.setPageBackgroundsVisible(true);
Adam Cohen8e894fa2014-09-08 19:45:43 +02003678 // Unhide side pages
3679 int count = content.getChildCount();
3680 for (int i = 0; i < count; i++) {
3681 View child = content.getChildAt(i);
3682 child.setVisibility(View.VISIBLE);
3683 }
3684
3685 // Reset page transforms
Adam Cohen493f6bc2014-09-18 08:11:05 -07003686 if (page != null) {
3687 page.setTranslationX(0);
3688 page.setTranslationY(0);
3689 page.setAlpha(1);
3690 }
Adam Cohen8e894fa2014-09-08 19:45:43 +02003691 content.setCurrentPage(content.getNextPage());
3692
Chet Haasebc2f0822012-10-26 17:59:53 -07003693 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003694 }
3695 });
3696
Adam Cohen2854d252014-08-27 16:04:07 -07003697 final AnimatorSet stateAnimation = mStateAnimation;
3698 final Runnable startAnimRunnable = new Runnable() {
3699 public void run() {
3700 // Check that mStateAnimation hasn't changed while
3701 // we waited for a layout/draw pass
Jose Pascoal65766f82015-02-10 17:55:27 +00003702 if (mStateAnimation != stateAnimation) {
Adam Cohen2854d252014-08-27 16:04:07 -07003703 return;
Jose Pascoal65766f82015-02-10 17:55:27 +00003704 }
Adam Cohen2854d252014-08-27 16:04:07 -07003705 dispatchOnLauncherTransitionStart(fromView, animated, false);
3706 dispatchOnLauncherTransitionStart(toView, animated, false);
3707
Kenny Guyd794a3f2014-09-16 15:17:58 +01003708 if (Utilities.isLmpOrAbove()) {
Adam Cohen2854d252014-08-27 16:04:07 -07003709 for (int i = 0; i < layerViews.size(); i++) {
3710 View v = layerViews.get(i);
Adam Cohen0f668f32014-09-08 19:54:17 +02003711 if (v != null) {
3712 boolean attached = true;
3713 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
3714 attached = v.isAttachedToWindow();
3715 }
Jose Pascoal65766f82015-02-10 17:55:27 +00003716 if (attached) {
3717 v.buildLayer();
3718 }
Adam Cohen0f668f32014-09-08 19:54:17 +02003719 }
Adam Cohen2854d252014-08-27 16:04:07 -07003720 }
3721 }
3722 mStateAnimation.start();
3723 }
3724 };
3725 fromView.post(startAnimRunnable);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003726 } else {
3727 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003728 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003729 dispatchOnLauncherTransitionStart(fromView, animated, true);
3730 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003731 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003732 dispatchOnLauncherTransitionStart(toView, animated, true);
3733 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003734 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003735 }
3736
Michael Jurkae326f182011-11-21 14:05:46 -08003737 @Override
3738 public void onTrimMemory(int level) {
3739 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003740 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003741 mAppsCustomizeTabHost.onTrimMemory();
3742 }
3743 }
3744
Adam Cohened307df2013-10-02 09:37:31 -07003745 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003746 showWorkspace(animated, null);
3747 }
3748
Adam Cohened307df2013-10-02 09:37:31 -07003749 protected void showWorkspace() {
3750 showWorkspace(true);
3751 }
3752
Adam Cohened66b2b2012-01-23 17:28:51 -08003753 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohene25c5d12014-06-18 10:34:58 -07003754 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003755 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003756 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003757
Michael Jurkab3e22d92011-10-31 15:58:33 -07003758 // Set focus to the AppsCustomize button
3759 if (mAllAppsButton != null) {
3760 mAllAppsButton.requestFocus();
3761 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003762 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003763
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003764 // Change the state *after* we've called all the transition code
3765 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003766
Winson Chung5fb63472011-02-02 17:03:37 -08003767 // Resume the auto-advance of widgets
3768 mUserPresent = true;
3769 updateRunning();
3770
alanv1d4fde62012-10-17 13:15:47 -07003771 // Send an accessibility event to announce the context change
3772 getWindow().getDecorView()
3773 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003774
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003775 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003776 }
3777
Jose Pascoal4b1e3122014-12-04 17:36:37 +00003778 public void showOverviewMode(boolean animated) {
Jose Pascoal3c0767e2014-12-03 18:52:04 +00003779 if(isAgingAppDrawerVisible()){
3780 hideAgingAppDrawer();
3781 }
Adam Cohened307df2013-10-02 09:37:31 -07003782 mWorkspace.setVisibility(View.VISIBLE);
3783 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3784 mState = State.WORKSPACE;
3785 onWorkspaceShown(animated);
3786 }
3787
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003788 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003789 }
3790
Winson Chung82963d52013-10-09 11:20:57 -07003791 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3792 boolean resetPageToZero) {
Filipee7484672015-09-22 11:50:56 +00003793
Jose Pascoal65766f82015-02-10 17:55:27 +00003794 if (mState != State.WORKSPACE) {
3795 return;
3796 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003797
Winson Chung82963d52013-10-09 11:20:57 -07003798 if (resetPageToZero) {
3799 mAppsCustomizeTabHost.reset();
3800 }
Filipee7484672015-09-22 11:50:56 +00003801
Winson Chungc58497e2013-09-03 17:48:37 -07003802 showAppsCustomizeHelper(animated, false, contentType);
Filipee7484672015-09-22 11:50:56 +00003803
Adam Cohendcc5e712014-06-23 15:38:55 -04003804 mAppsCustomizeTabHost.post(new Runnable() {
3805 @Override
3806 public void run() {
3807 // We post this in-case the all apps view isn't yet constructed.
3808 mAppsCustomizeTabHost.requestFocus();
3809 }
3810 });
Michael Jurkab3e22d92011-10-31 15:58:33 -07003811
Michael Jurkab3e22d92011-10-31 15:58:33 -07003812 // Change the state *after* we've called all the transition code
3813 mState = State.APPS_CUSTOMIZE;
3814
3815 // Pause the auto-advance of widgets until we are out of AllApps
3816 mUserPresent = false;
3817 updateRunning();
3818 closeFolder();
3819
3820 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003821 getWindow().getDecorView()
3822 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003823 }
3824
Jose Pascoal4b1e3122014-12-04 17:36:37 +00003825 public void enterSpringLoadedDragMode() {
Jose Pascoal43aab392014-12-05 18:00:55 +00003826 if (isAllAppsVisible() || isAgingAppDrawerVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003827 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003828 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003829 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003830 }
Adam Cohen7777d962011-08-18 18:58:38 -07003831
Adam Cohenad4e15c2013-10-17 16:21:35 -07003832 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003833 final Runnable onCompleteRunnable) {
Jose Pascoal65766f82015-02-10 17:55:27 +00003834 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) {
3835 return;
3836 }
Winson Chung09bfc452011-09-09 11:30:20 -07003837
Winson Chunge7a03942011-08-05 15:05:12 -07003838 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003839 @Override
3840 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003841 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003842 // Before we show workspace, hide all apps again because
3843 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3844 // clean up our state transition functions
3845 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003846 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003847 } else {
3848 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003849 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003850 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003851 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003852 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003853
Jose Pascoal43aab392014-12-05 18:00:55 +00003854 public void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003855 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003856 final boolean animated = true;
3857 final boolean springLoaded = true;
3858 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003859 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003860 }
3861 // Otherwise, we are not in spring loaded mode, so don't do anything.
3862 }
3863
Michael Jurkab3e22d92011-10-31 15:58:33 -07003864 void lockAllApps() {
3865 // TODO
3866 }
3867
3868 void unlockAllApps() {
3869 // TODO
3870 }
3871
Winson Chungf0ea4d32011-06-06 14:27:16 -07003872 /**
Patrick Dubroy5f445422011-02-18 14:35:21 -08003873 * Add an item from all apps or customize onto the given workspace screen.
3874 * If layout is null, add to the current screen.
3875 */
3876 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003877 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Jose Pascoal5b89c7c2014-11-20 17:42:29 +00003878 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07003879 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003880 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003881
Winson Chungdff8ebb2011-09-08 17:25:31 -07003882 /** Maps the current orientation to an index for referencing orientation correct global icons */
3883 private int getCurrentOrientationIndexForGlobalIcons() {
3884 // default - 0, landscape - 1
3885 switch (getResources().getConfiguration().orientation) {
3886 case Configuration.ORIENTATION_LANDSCAPE:
3887 return 1;
3888 default:
3889 return 0;
3890 }
3891 }
3892
Michael Jurkaae65ee32012-04-30 11:45:54 -07003893 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003894 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003895 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003896 // Look for the toolbar icon specified in the activity meta-data
3897 Bundle metaData = packageManager.getActivityInfo(
3898 activityName, PackageManager.GET_META_DATA).metaData;
3899 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003900 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003901 if (iconResId != 0) {
3902 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003903 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003904 }
3905 }
3906 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003907 // This can happen if the activity defines an invalid drawable
3908 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3909 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003910 } catch (Resources.NotFoundException nfe) {
3911 // This can happen if the activity defines an invalid drawable
3912 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3913 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003914 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003915 return null;
3916 }
3917
3918 // if successful in getting icon, return it; otherwise, set button to use default drawable
3919 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003920 int buttonId, ComponentName activityName, int fallbackDrawableId,
3921 String toolbarResourceName) {
3922 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003923 Resources r = getResources();
3924 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3925 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003926
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003927 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003928 // If we were unable to find the icon via the meta-data, use a generic one
3929 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003930 toolbarIcon = r.getDrawable(fallbackDrawableId);
3931 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003932 if (button != null) {
3933 button.setCompoundDrawables(toolbarIcon, null, null, null);
3934 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003935 return null;
3936 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003937 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003938 if (button != null) {
3939 button.setCompoundDrawables(toolbarIcon, null, null, null);
3940 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003941 return toolbarIcon.getConstantState();
3942 }
3943 }
3944
3945 // if successful in getting icon, return it; otherwise, set button to use default drawable
3946 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003947 int buttonId, ComponentName activityName, int fallbackDrawableId,
3948 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003949 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003950 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003951
Michael Jurka19e0fc52011-07-22 18:00:21 -07003952 if (button != null) {
3953 // If we were unable to find the icon via the meta-data, use a
3954 // generic one
3955 if (toolbarIcon == null) {
3956 button.setImageResource(fallbackDrawableId);
3957 } else {
3958 button.setImageDrawable(toolbarIcon);
3959 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003960 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003961
3962 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3963
Michael Jurka0423dcf2010-10-05 14:56:18 -07003964 }
3965
Cristina Stancu476493b2013-08-07 17:20:14 +01003966 protected boolean updateGlobalSearchIcon() {
Winson Chung1cad91e2011-05-25 17:41:01 -07003967 final SearchManager searchManager =
3968 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3969 ComponentName activityName = searchManager.getGlobalSearchActivity();
Jose Pascoal48612372014-11-19 17:39:00 +00003970 return activityName != null;
Winson Chung5841efa2013-09-30 18:06:44 -07003971 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08003972
Michael Jurkad7c28052012-04-27 15:43:36 -07003973 @Override
3974 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07003975 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07003976 final List<CharSequence> text = event.getText();
3977 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07003978 // Populate event with a fake title based on the current state.
3979 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07003980 text.add(mAppsCustomizeTabHost.getContentTag());
alanv1d4fde62012-10-17 13:15:47 -07003981 } else {
3982 text.add(getString(R.string.all_apps_home_button_label));
3983 }
Michael Jurkad7c28052012-04-27 15:43:36 -07003984 return result;
3985 }
3986
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003987 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07003988 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003989 */
3990 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3991 @Override
3992 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003993 closeSystemDialogs();
3994 }
3995 }
3996
3997 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003998 * Receives notifications whenever the appwidgets are reset.
3999 */
4000 private class AppWidgetResetObserver extends ContentObserver {
4001 public AppWidgetResetObserver() {
4002 super(new Handler());
4003 }
4004
4005 @Override
4006 public void onChange(boolean selfChange) {
4007 onAppWidgetReset();
4008 }
4009 }
4010
4011 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07004012 * If the activity is currently paused, signal that we need to run the passed Runnable
4013 * in onResume.
4014 *
4015 * This needs to be called from incoming places where resources might have been loaded
4016 * while we are paused. That is becaues the Configuration might be wrong
4017 * when we're not running, and if it comes back to what it was when we
4018 * were paused, we are not restarted.
4019 *
4020 * Implementation of the method from LauncherModel.Callbacks.
4021 *
4022 * @return true if we are currently paused. The caller might be able to
4023 * skip some work in that case since we will come back again.
4024 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004025 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004026 if (mPaused) {
4027 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02004028 if (deletePreviousRunnables) {
Jose Pascoalad727c52015-02-11 18:54:17 +00004029 //noinspection StatementWithEmptyBody
Michael Jurka1e2f4652013-07-08 18:03:46 -07004030 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004031 }
4032 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07004033 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07004034 return true;
4035 } else {
4036 return false;
4037 }
4038 }
4039
Michael Jurkac402cd92013-05-20 15:49:32 +02004040 private boolean waitUntilResume(Runnable run) {
4041 return waitUntilResume(run, false);
4042 }
4043
Michael Jurka1e2f4652013-07-08 18:03:46 -07004044 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02004045 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07004046 }
4047
Michael Jurka7607c2f2013-04-03 14:33:19 -07004048 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004049 * If the activity is currently paused, signal that we need to re-run the loader
4050 * in onResume.
4051 *
4052 * This needs to be called from incoming places where resources might have been loaded
4053 * while we are paused. That is becaues the Configuration might be wrong
4054 * when we're not running, and if it comes back to what it was when we
4055 * were paused, we are not restarted.
4056 *
4057 * Implementation of the method from LauncherModel.Callbacks.
4058 *
4059 * @return true if we are currently paused. The caller might be able to
4060 * skip some work in that case since we will come back again.
4061 */
4062 public boolean setLoadOnResume() {
4063 if (mPaused) {
4064 Log.i(TAG, "setLoadOnResume");
4065 mOnResumeNeedsLoad = true;
4066 return true;
4067 } else {
4068 return false;
4069 }
4070 }
4071
4072 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004073 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004074 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04004075 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07004076 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07004077 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07004078 } else {
4079 return SCREEN_COUNT / 2;
4080 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004081 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07004082
Joe Onorato9c1289c2009-08-17 11:03:03 -04004083 /**
4084 * Refreshes the shortcuts shown on the workspace.
4085 *
4086 * Implementation of the method from LauncherModel.Callbacks.
4087 */
4088 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004089 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08004090
Michael Jurka7607c2f2013-04-03 14:33:19 -07004091 // If we're starting binding all over again, clear any bind calls we'd postponed in
4092 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4093 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07004094 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07004095
Winson Chungd64d1762013-08-20 14:37:16 -07004096 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07004097 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07004098 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07004099
Michael Jurka05bf6442011-11-30 20:28:53 -08004100 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004101 }
4102
Adam Cohendcd297f2013-06-18 13:13:40 -07004103 @Override
4104 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07004105 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07004106
Adam Cohen5084cba2013-09-03 12:01:16 -07004107 // If there are no screens, we need to have an empty screen
Jose Pascoal8d032d62015-02-10 14:48:51 +00004108 if (orderedScreenIds.isEmpty()) {
Adam Cohen5084cba2013-09-03 12:01:16 -07004109 mWorkspace.addExtraEmptyScreen();
4110 }
Winson Chung0e6a7132013-08-23 12:55:10 -07004111
4112 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06004113 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05004114 if (hasCustomContentToLeft()) {
4115 mWorkspace.createCustomContentContainer();
4116 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07004117 }
Winson Chung64359a52013-07-08 17:17:08 -07004118 }
4119
4120 @Override
4121 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08004122 // Log to disk
4123 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4124 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4125 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07004126 int count = orderedScreenIds.size();
4127 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07004128 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07004129 }
Adam Cohendcd297f2013-06-18 13:13:40 -07004130 }
4131
Adam Cohen39a06042013-07-19 14:30:12 -07004132 private boolean shouldShowWeightWatcher() {
4133 String spKey = LauncherAppState.getSharedPreferencesKey();
4134 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07004135 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07004136
4137 return show;
4138 }
4139
4140 private void toggleShowWeightWatcher() {
4141 String spKey = LauncherAppState.getSharedPreferencesKey();
4142 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4143 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4144
4145 show = !show;
4146
4147 SharedPreferences.Editor editor = sp.edit();
4148 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4149 editor.commit();
4150
4151 if (mWeightWatcher != null) {
4152 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4153 }
4154 }
4155
Winson Chungd64d1762013-08-20 14:37:16 -07004156 public void bindAppsAdded(final ArrayList<Long> newScreens,
4157 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07004158 final ArrayList<ItemInfo> addAnimated,
4159 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004160 Runnable r = new Runnable() {
4161 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07004162 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07004163 }
4164 };
4165 if (waitUntilResume(r)) {
4166 return;
4167 }
4168
Winson Chungd64d1762013-08-20 14:37:16 -07004169 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08004170 if (newScreens != null) {
4171 bindAddScreens(newScreens);
4172 }
Winson Chungd64d1762013-08-20 14:37:16 -07004173
4174 // We add the items without animation on non-visible pages, and with
4175 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08004176 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004177 bindItems(addNotAnimated, 0,
4178 addNotAnimated.size(), false);
4179 }
Adam Cohen76a47a12014-02-05 11:47:43 -08004180 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004181 bindItems(addAnimated, 0,
4182 addAnimated.size(), true);
4183 }
Winson Chungc58497e2013-09-03 17:48:37 -07004184
Winson Chung87412982013-10-03 18:34:14 -07004185 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004186 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004187
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004188 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004189 addedApps != null && mAppsCustomizeContent != null) {
4190 mAppsCustomizeContent.addApps(addedApps);
4191 }
Winson Chungd64d1762013-08-20 14:37:16 -07004192 }
4193
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004194 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004195 * Bind the items start-end from the list.
4196 *
4197 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004198 */
Winson Chung64359a52013-07-08 17:17:08 -07004199 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4200 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004201 Runnable r = new Runnable() {
4202 public void run() {
4203 bindItems(shortcuts, start, end, forceAnimateIcons);
4204 }
4205 };
4206 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004207 return;
4208 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004209
Winson Chungf0c6ae02012-03-21 16:10:31 -07004210 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004211 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4212 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004213 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004214 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004215 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004216 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004217 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004218
Joe Onorato9c1289c2009-08-17 11:03:03 -04004219 switch (item.itemType) {
4220 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4221 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004222 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004223 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004224
Winson Chung64359a52013-07-08 17:17:08 -07004225 /*
4226 * TODO: FIX collision case
4227 */
Winson Chungce376632013-07-11 16:12:41 -07004228 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4229 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4230 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004231 View v = cl.getChildAt(item.cellX, item.cellY);
4232 Object tag = v.getTag();
4233 String desc = "Collision while binding workspace item: " + item
4234 + ". Collides with " + tag;
4235 if (LauncherAppState.isDogfoodBuild()) {
4236 throw (new RuntimeException(desc));
4237 } else {
4238 Log.d(TAG, desc);
4239 }
Winson Chungce376632013-07-11 16:12:41 -07004240 }
Winson Chung64359a52013-07-08 17:17:08 -07004241 }
4242
Adam Cohendcd297f2013-06-18 13:13:40 -07004243 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4244 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004245 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004246 // Animate all the applications up now
4247 shortcut.setAlpha(0f);
4248 shortcut.setScaleX(0f);
4249 shortcut.setScaleY(0f);
4250 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004251 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004252 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004253 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004254 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004255 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004256 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004257 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004258 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4259 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004260 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004261 default:
4262 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004263 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004264 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004265
Winson Chung997a9232013-07-24 15:33:46 -07004266 if (animateIcons) {
4267 // Animate to the correct page
4268 if (newShortcutsScreenId > -1) {
4269 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004270 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004271 final Runnable startBounceAnimRunnable = new Runnable() {
4272 public void run() {
4273 anim.playTogether(bounceAnims);
4274 anim.start();
4275 }
4276 };
Winson Chung997a9232013-07-24 15:33:46 -07004277 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004278 // We post the animation slightly delayed to prevent slowdowns
4279 // when we are loading right after we return to launcher.
4280 mWorkspace.postDelayed(new Runnable() {
4281 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004282 if (mWorkspace != null) {
4283 mWorkspace.snapToPage(newScreenIndex);
4284 mWorkspace.postDelayed(startBounceAnimRunnable,
4285 NEW_APPS_ANIMATION_DELAY);
4286 }
Winson Chung94d67682013-09-25 16:29:40 -07004287 }
4288 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004289 } else {
4290 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004291 }
4292 }
Winson Chung64359a52013-07-08 17:17:08 -07004293 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004294 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004295 }
4296
Joe Onorato9c1289c2009-08-17 11:03:03 -04004297 /**
4298 * Implementation of the method from LauncherModel.Callbacks.
4299 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004300 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004301 Runnable r = new Runnable() {
4302 public void run() {
4303 bindFolders(folders);
4304 }
4305 };
4306 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004307 return;
4308 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004309 sFolders.clear();
4310 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004311 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004312
4313 /**
4314 * Add the views for a widget to the workspace.
4315 *
4316 * Implementation of the method from LauncherModel.Callbacks.
4317 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004318 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004319 Runnable r = new Runnable() {
4320 public void run() {
4321 bindAppWidget(item);
4322 }
4323 };
4324 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004325 return;
4326 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004327
Jose Pascoalfe3b08b2015-02-11 18:01:38 +00004328 @SuppressWarnings("UnusedAssignment") final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
Daniel Sandler843e8602010-06-07 14:59:01 -04004329 if (DEBUG_WIDGETS) {
4330 Log.d(TAG, "bindAppWidget: " + item);
4331 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004332 final Workspace workspace = mWorkspace;
4333
Sunny Goyalff572272014-07-23 13:58:07 -07004334 AppWidgetProviderInfo appWidgetInfo;
4335 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4336 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4337
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004338 appWidgetInfo = LauncherModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
Sunny Goyalff572272014-07-23 13:58:07 -07004339 if (appWidgetInfo == null) {
4340 if (DEBUG_WIDGETS) {
4341 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4342 + " belongs to component " + item.providerName
4343 + ", as the povider is null");
4344 }
4345 LauncherModel.deleteItemFromDatabase(this, item);
4346 return;
4347 }
4348 // Note: This assumes that the id remap broadcast is received before this step.
4349 // If that is not the case, the id remap will be ignored and user may see the
4350 // click to setup view.
4351 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4352 pendingInfo.spanX = item.spanX;
4353 pendingInfo.spanY = item.spanY;
4354 pendingInfo.minSpanX = item.minSpanX;
4355 pendingInfo.minSpanY = item.minSpanY;
4356 Bundle options =
4357 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4358
Sunny Goyalff572272014-07-23 13:58:07 -07004359 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
Sunny Goyalffe83f12014-08-14 17:39:34 -07004360 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4361 newWidgetId, appWidgetInfo, options);
Sunny Goyalff572272014-07-23 13:58:07 -07004362
4363 // TODO consider showing a permission dialog when the widget is clicked.
4364 if (!success) {
4365 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4366 if (DEBUG_WIDGETS) {
4367 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4368 + " belongs to component " + item.providerName
4369 + ", as the launcher is unable to bing a new widget id");
4370 }
4371 LauncherModel.deleteItemFromDatabase(this, item);
4372 return;
4373 }
4374
4375 item.appWidgetId = newWidgetId;
4376
4377 // If the widget has a configure activity, it is still needs to set it up, otherwise
4378 // the widget is ready to go.
4379 item.restoreStatus = (appWidgetInfo.configure == null)
4380 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4381 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4382
4383 LauncherModel.updateItemInDatabase(this, item);
4384 }
4385
Sunny Goyal651077b2014-06-30 14:15:31 -07004386 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4387 final int appWidgetId = item.appWidgetId;
4388 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4389 if (DEBUG_WIDGETS) {
4390 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4391 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004392
Sunny Goyal651077b2014-06-30 14:15:31 -07004393 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4394 } else {
4395 appWidgetInfo = null;
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004396 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item);
4397 view.updateIcon(mIconCache);
4398 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004399 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004400 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004401 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004402
Joe Onorato9c1289c2009-08-17 11:03:03 -04004403 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004404 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004405
Adam Cohendcd297f2013-06-18 13:13:40 -07004406 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004407 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004408 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4409
Joe Onorato9c1289c2009-08-17 11:03:03 -04004410 workspace.requestLayout();
4411
Daniel Sandler843e8602010-06-07 14:59:01 -04004412 if (DEBUG_WIDGETS) {
4413 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4414 + (SystemClock.uptimeMillis()-start) + "ms");
4415 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004416 }
4417
Sunny Goyalff572272014-07-23 13:58:07 -07004418 /**
4419 * Restores a pending widget.
4420 *
4421 * @param appWidgetId The app widget id
4422 * @param cellInfo The position on screen where to create the widget.
4423 */
4424 private void completeRestoreAppWidget(final int appWidgetId) {
4425 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4426 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4427 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4428 return;
4429 }
4430
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004431 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004432 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4433
4434 mWorkspace.reinflateWidgetsIfNecessary();
4435 LauncherModel.updateItemInDatabase(this, info);
4436 }
4437
Adam Cohen1462de32012-07-24 22:34:36 -07004438 public void onPageBoundSynchronously(int page) {
4439 mSynchronouslyBoundPages.add(page);
4440 }
4441
Joe Onorato9c1289c2009-08-17 11:03:03 -04004442 /**
4443 * Callback saying that there aren't any more items to bind.
4444 *
4445 * Implementation of the method from LauncherModel.Callbacks.
4446 */
Adam Cohene25af792013-06-06 23:08:25 -07004447 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004448 Runnable r = new Runnable() {
4449 public void run() {
4450 finishBindingItems(upgradePath);
4451 }
4452 };
4453 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004454 return;
4455 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004456 if (mSavedState != null) {
4457 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004458 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004459 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004460 mSavedState = null;
4461 }
4462
Adam Cohen1462de32012-07-24 22:34:36 -07004463 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004464
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004465 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004466 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004467
4468 // If we received the result of any pending adds while the loader was running (e.g. the
4469 // widget configuration forced an orientation change), process them now.
4470 if (sPendingAddItem != null) {
4471 final long screenId = completeAdd(sPendingAddItem);
4472
4473 // TODO: this moves the user to the page where the pending item was added. Ideally,
4474 // the screen would be guaranteed to exist after bind, and the page would be set through
4475 // the workspace restore process.
4476 mWorkspace.post(new Runnable() {
4477 @Override
4478 public void run() {
4479 mWorkspace.snapToScreenId(screenId);
4480 }
4481 });
4482 sPendingAddItem = null;
4483 }
4484
Adam Cohene25af792013-06-06 23:08:25 -07004485 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004486 mWorkspace.getUniqueComponents(true, null);
4487 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004488 }
Sunny Goyale755d462014-07-22 13:48:29 -07004489 PackageInstallerCompat.getInstance(this).onFinishBind();
Sunny Goyal8cce9dd2014-10-14 11:07:33 -07004490 mModel.recheckRestoredItems(this);
Winson Chungf0c6ae02012-03-21 16:10:31 -07004491 }
4492
Adam Cohen3ed316a2014-07-23 18:21:20 -07004493 private void sendLoadingCompleteBroadcastIfNecessary() {
4494 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4495 String permission =
4496 getResources().getString(R.string.receive_first_load_broadcast_permission);
4497 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4498 sendBroadcast(intent, permission);
4499 SharedPreferences.Editor editor = mSharedPrefs.edit();
4500 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4501 editor.apply();
4502 }
4503 }
4504
Winson Chunga0b7e862013-09-05 16:03:15 -07004505 public boolean isAllAppsButtonRank(int rank) {
Winson Chunga0b7e862013-09-05 16:03:15 -07004506 return false;
4507 }
4508
Winson Chunga2413752012-04-03 14:22:34 -07004509 private boolean canRunNewAppsAnimation() {
4510 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4511 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4512 }
4513
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004514 private static ValueAnimator createNewAppBounceAnimation(View v, int i) {
Winson Chungc9168342013-06-26 14:54:55 -07004515 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4516 PropertyValuesHolder.ofFloat("alpha", 1f),
4517 PropertyValuesHolder.ofFloat("scaleX", 1f),
4518 PropertyValuesHolder.ofFloat("scaleY", 1f));
4519 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4520 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4521 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4522 return bounceAnim;
4523 }
4524
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004525 public static boolean useVerticalBarLayout() {
Adam Cohen27772732013-11-11 14:00:56 +00004526 return LauncherAppState.getInstance().getDynamicGrid().
4527 getDeviceProfile().isVerticalBarLayout();
4528 }
4529
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004530 protected static Rect getSearchBarBounds() {
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004531 return LauncherAppState.getInstance().getDynamicGrid().
4532 getDeviceProfile().getSearchBarBounds();
4533 }
4534
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004535 @Override
4536 public void bindSearchablesChanged() {
Jose Pascoalfe3b08b2015-02-11 18:01:38 +00004537 updateGlobalSearchIcon();
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004538 }
4539
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004540 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004541 * Add the icons for all apps.
4542 *
4543 * Implementation of the method from LauncherModel.Callbacks.
4544 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004545 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004546 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004547 if (mIntentsOnWorkspaceFromUpgradePath != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004548 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004549 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004550 if (mAppsCustomizeContent != null) {
4551 mAppsCustomizeContent.onPackagesUpdated(
4552 LauncherModel.getSortedWidgetsAndShortcuts(this));
4553 }
Winson Chungc58497e2013-09-03 17:48:37 -07004554 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004555 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004556 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004557 mAppsCustomizeContent.onPackagesUpdated(
4558 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004559 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004560 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004561 }
4562
4563 /**
4564 * A package was updated.
4565 *
4566 * Implementation of the method from LauncherModel.Callbacks.
4567 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004568 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004569 Runnable r = new Runnable() {
4570 public void run() {
4571 bindAppsUpdated(apps);
4572 }
4573 };
4574 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004575 return;
4576 }
4577
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004578 if (mWorkspace != null) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004579 mWorkspace.updateShortcutsAndWidgets(apps);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004580 }
Winson Chungc58497e2013-09-03 17:48:37 -07004581
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004582 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004583 mAppsCustomizeContent != null) {
4584 mAppsCustomizeContent.updateApps(apps);
4585 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004586 }
4587
4588 /**
Sunny Goyal8cce9dd2014-10-14 11:07:33 -07004589 * Packages were restored
4590 */
4591 public void bindAppsRestored(final ArrayList<AppInfo> apps) {
4592 Runnable r = new Runnable() {
4593 public void run() {
4594 bindAppsRestored(apps);
4595 }
4596 };
4597 if (waitUntilResume(r)) {
4598 return;
4599 }
4600
4601 if (mWorkspace != null) {
4602 mWorkspace.updateShortcutsAndWidgets(apps);
4603 }
4604 }
4605
4606 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004607 * Update the state of a package, typically related to install state.
4608 *
4609 * Implementation of the method from LauncherModel.Callbacks.
4610 */
Sunny Goyale755d462014-07-22 13:48:29 -07004611 @Override
4612 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004613 if (mWorkspace != null) {
Sunny Goyale755d462014-07-22 13:48:29 -07004614 mWorkspace.updatePackageState(installInfo);
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004615 }
4616 }
4617
4618 /**
Sunny Goyala22666f2014-09-18 13:25:15 -07004619 * Update the label and icon of all the icons in a package
4620 *
4621 * Implementation of the method from LauncherModel.Callbacks.
4622 */
4623 @Override
4624 public void updatePackageBadge(String packageName) {
4625 if (mWorkspace != null) {
4626 mWorkspace.updatePackageBadge(packageName, UserHandleCompat.myUserHandle());
4627 }
4628 }
4629
4630 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004631 * A package was uninstalled. We take both the super set of packageNames
4632 * in addition to specific applications to remove, the reason being that
4633 * this can be called when a package is updated as well. In that scenario,
4634 * we only remove specific components from the workspace, where as
4635 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004636 *
4637 * Implementation of the method from LauncherModel.Callbacks.
4638 */
Winson Chung83892cc2013-05-01 16:53:33 -07004639 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004640 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004641 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004642 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004643 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004644 }
Winson Chungd64d1762013-08-20 14:37:16 -07004645 };
4646 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004647 return;
4648 }
4649
Winson Chungdf95eb12013-10-16 14:57:07 -07004650 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004651 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004652 }
4653 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004654 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004655 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004656
Winson Chunga1820962011-10-03 16:31:06 -07004657 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004658 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004659
Winson Chungdf95eb12013-10-16 14:57:07 -07004660 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004661 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004662 mAppsCustomizeContent != null) {
4663 mAppsCustomizeContent.removeApps(appInfos);
4664 }
Jose Pascoalbd1a70f2014-12-09 12:26:12 +00004665
4666 for (AppInfo appInfo : appInfos) {
4667 ComponentName componentName = appInfo.getComponentName();
4668 if(componentName != null){
Filipe Gonçalvesa804b282015-06-23 17:47:42 +01004669 AppSwitcherManager.applicationRemoved(this, componentName);
Jose Pascoalbd1a70f2014-12-09 12:26:12 +00004670 AppDiscoverer.getInstance().applicationRemoved(this, componentName);
4671 }
4672 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004673 }
Joe Onoratobe386092009-11-17 17:32:16 -08004674
4675 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004676 * A number of packages were updated.
4677 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004678 private ArrayList<Object> mWidgetsAndShortcuts;
Jose Pascoalf354dfe2015-02-10 19:21:21 +00004679 private final Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004680 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004681 bindPackagesUpdated(mWidgetsAndShortcuts);
4682 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004683 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004684 };
Jose Pascoal3c0767e2014-12-03 18:52:04 +00004685
Michael Jurkac402cd92013-05-20 15:49:32 +02004686 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4687 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4688 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004689 return;
4690 }
4691
Winson Chung64359a52013-07-08 17:17:08 -07004692 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004693 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004694 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004695 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004696 }
4697
Winson Chung400438b2011-01-16 17:53:48 -08004698 private int mapConfigurationOriActivityInfoOri(int configOri) {
4699 final Display d = getWindowManager().getDefaultDisplay();
4700 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4701 switch (d.getRotation()) {
4702 case Surface.ROTATION_0:
4703 case Surface.ROTATION_180:
4704 // We are currently in the same basic orientation as the natural orientation
4705 naturalOri = configOri;
4706 break;
4707 case Surface.ROTATION_90:
4708 case Surface.ROTATION_270:
4709 // We are currently in the other basic orientation to the natural orientation
4710 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4711 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4712 break;
4713 }
4714
4715 int[] oriMap = {
4716 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4717 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4718 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4719 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4720 };
4721 // Since the map starts at portrait, we need to offset if this device's natural orientation
4722 // is landscape.
4723 int indexOffset = 0;
4724 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4725 indexOffset = 1;
4726 }
4727 return oriMap[(d.getRotation() + indexOffset) % 4];
4728 }
Adam Cohen446e9402011-09-15 18:21:21 -07004729
Winson Chung4b919f82012-05-01 10:44:08 -07004730 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004731 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004732 getResources().getBoolean(R.bool.allow_rotation);
4733 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004734 }
Winson Chung4b919f82012-05-01 10:44:08 -07004735 public void lockScreenOrientation() {
4736 if (isRotationEnabled()) {
4737 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4738 .getConfiguration().orientation));
4739 }
4740 }
4741 public void unlockScreenOrientation(boolean immediate) {
4742 if (isRotationEnabled()) {
4743 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004744 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004745 } else {
4746 mHandler.postDelayed(new Runnable() {
4747 public void run() {
4748 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4749 }
4750 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004751 }
Winson Chung4b919f82012-05-01 10:44:08 -07004752 }
Winson Chung400438b2011-01-16 17:53:48 -08004753 }
4754
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004755 /**
4756 * Called when the SearchBar hint should be changed.
4757 *
4758 * @param hint the hint to be displayed in the search bar.
4759 */
4760 protected void onSearchBarHintChanged(String hint) {
Sunny Goyal424418b2014-08-22 16:09:37 -07004761
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004762 }
4763
Winson Chunge43a1e72014-01-15 10:33:02 -08004764 protected boolean isLauncherPreinstalled() {
4765 PackageManager pm = getPackageManager();
4766 try {
4767 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4768 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4769 return true;
4770 } else {
4771 return false;
4772 }
4773 } catch (NameNotFoundException e) {
4774 e.printStackTrace();
4775 return false;
4776 }
4777 }
4778
Adam Cohenea90f832014-05-21 15:03:34 -07004779 /**
4780 * This method indicates whether or not we should suggest default wallpaper dimensions
4781 * when our wallpaper cropper was not yet used to set a wallpaper.
4782 */
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004783 protected static boolean overrideWallpaperDimensions() {
Adam Cohenea90f832014-05-21 15:03:34 -07004784 return true;
4785 }
4786
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004787 protected static boolean shouldClingFocusHotseatApp() {
Adam Cohen5eed5d82014-05-19 13:12:13 -07004788 return false;
4789 }
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004790 protected static String getFirstRunClingSearchBarHint() {
Winson Chunge6eabff2013-09-24 11:01:23 -07004791 return "";
4792 }
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004793 protected static String getFirstRunCustomContentHint() {
Winson Chunge6eabff2013-09-24 11:01:23 -07004794 return "";
4795 }
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004796 protected static int getFirstRunFocusedHotseatAppDrawableId() {
Winson Chung3a6e7f32013-10-09 15:50:52 -07004797 return -1;
4798 }
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004799 protected static ComponentName getFirstRunFocusedHotseatAppComponentName() {
Winson Chung3a6e7f32013-10-09 15:50:52 -07004800 return null;
4801 }
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004802 protected static int getFirstRunFocusedHotseatAppRank() {
Winson Chung3a6e7f32013-10-09 15:50:52 -07004803 return -1;
4804 }
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004805 protected static String getFirstRunFocusedHotseatAppBubbleTitle() {
Winson Chung3a6e7f32013-10-09 15:50:52 -07004806 return "";
4807 }
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004808 protected static String getFirstRunFocusedHotseatAppBubbleDescription() {
Winson Chung3a6e7f32013-10-09 15:50:52 -07004809 return "";
4810 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004811
Adam Cohen432609a2014-03-13 17:03:22 -07004812 /**
4813 * To be overridden by subclasses to indicate that there is an activity to launch
4814 * before showing the standard launcher experience.
4815 */
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004816 protected static boolean hasFirstRunActivity() {
Adam Cohen432609a2014-03-13 17:03:22 -07004817 return false;
4818 }
4819
4820 /**
4821 * To be overridden by subclasses to launch any first run activity
4822 */
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004823 protected static Intent getFirstRunActivity() {
Adam Cohen432609a2014-03-13 17:03:22 -07004824 return null;
4825 }
4826
Winson Chunga6945242014-01-08 14:04:34 -08004827 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004828 return !ActivityManager.isRunningInTestHarness() &&
4829 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004830 }
4831
Adam Cohen4a9423d2014-03-28 14:22:31 -07004832 protected boolean hasRunFirstRunActivity() {
4833 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4834 }
4835
Adam Cohen432609a2014-03-13 17:03:22 -07004836 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004837 if (shouldRunFirstRunActivity() &&
4838 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004839 Intent firstRunIntent = getFirstRunActivity();
4840 if (firstRunIntent != null) {
4841 startActivity(firstRunIntent);
4842 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004843 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004844 }
4845 }
Adam Cohen432609a2014-03-13 17:03:22 -07004846 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004847 }
4848
4849 private void markFirstRunActivityShown() {
4850 SharedPreferences.Editor editor = mSharedPrefs.edit();
4851 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4852 editor.apply();
4853 }
4854
Adam Cohen432609a2014-03-13 17:03:22 -07004855 /**
4856 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4857 * screen that must be displayed and dismissed.
4858 */
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004859 protected static boolean hasDismissableIntroScreen() {
Adam Cohen432609a2014-03-13 17:03:22 -07004860 return false;
4861 }
4862
4863 /**
4864 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4865 */
Jose Pascoal8bdb3642015-02-13 13:15:11 +00004866 protected static View getIntroScreen() {
Adam Cohen432609a2014-03-13 17:03:22 -07004867 return null;
4868 }
4869
4870 /**
4871 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4872 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4873 */
4874 private boolean shouldShowIntroScreen() {
4875 return hasDismissableIntroScreen() &&
4876 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4877 }
4878
4879 protected void showIntroScreen() {
4880 View introScreen = getIntroScreen();
4881 changeWallpaperVisiblity(false);
4882 if (introScreen != null) {
4883 mDragLayer.showOverlayView(introScreen);
4884 }
4885 }
4886
4887 public void dismissIntroScreen() {
4888 markIntroScreenDismissed();
4889 if (showFirstRunActivity()) {
4890 // We delay hiding the intro view until the first run activity is showing. This
4891 // avoids a blip.
4892 mWorkspace.postDelayed(new Runnable() {
4893 @Override
4894 public void run() {
4895 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004896 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004897 }
4898 }, ACTIVITY_START_DELAY);
4899 } else {
4900 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004901 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004902 }
4903 changeWallpaperVisiblity(true);
4904 }
4905
4906 private void markIntroScreenDismissed() {
4907 SharedPreferences.Editor editor = mSharedPrefs.edit();
4908 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4909 editor.apply();
4910 }
4911
Sunny Goyal88d60f12014-09-08 03:47:29 -07004912 private void showFirstRunClings() {
4913 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4914 // on the device, then we always show the first run cling experience (or if there is no
4915 // launcher2). Otherwise, we prompt the user upon started for migration
4916 LauncherClings launcherClings = new LauncherClings(this);
4917 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
4918 if (mModel.canMigrateFromOldLauncherDb(this)) {
4919 launcherClings.showMigrationCling();
4920 } else {
Filiped63c86b2015-07-31 12:29:22 +00004921 //launcherClings.showLongPressCling(true);
Sunny Goyal88d60f12014-09-08 03:47:29 -07004922 }
4923 }
4924 }
4925
Winson Chunga6945242014-01-08 14:04:34 -08004926 void showWorkspaceSearchAndHotseat() {
Jose Pascoal65766f82015-02-10 17:55:27 +00004927 if (mWorkspace != null) {
4928 mWorkspace.setAlpha(1f);
4929 }
4930 if (mPageIndicators != null) {
4931 mPageIndicators.setAlpha(1f);
4932 }
Winson Chunga6945242014-01-08 14:04:34 -08004933 }
4934
4935 void hideWorkspaceSearchAndHotseat() {
Jose Pascoal65766f82015-02-10 17:55:27 +00004936 if (mWorkspace != null) {
4937 mWorkspace.setAlpha(0f);
4938 }
4939 if (mPageIndicators != null) {
4940 mPageIndicators.setAlpha(0f);
4941 }
Winson Chunga6945242014-01-08 14:04:34 -08004942 }
4943
Mathew Inwood72fbec12013-11-19 15:45:07 +00004944 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004945 // Called from search suggestion, not supported in other profiles.
4946 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4947 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4948 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4949 myUser);
4950 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004951 return null;
4952 }
Kenny Guyed131872014-04-30 03:02:21 +01004953 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004954 }
4955
4956 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4957 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004958 // Called from search suggestion, not supported in other profiles.
4959 return createShortcutDragInfo(shortcutIntent, caption, icon,
4960 UserHandleCompat.myUserHandle());
4961 }
4962
4963 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4964 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01004965 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01004966 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01004967 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004968 }
4969
Mathew Inwoodb90860a2014-04-11 17:17:39 +01004970 protected void moveWorkspaceToDefaultScreen() {
4971 mWorkspace.moveToDefaultScreen(false);
4972 }
4973
Mathew Inwood72fbec12013-11-19 15:45:07 +00004974 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
4975 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07004976 mWorkspace.onExternalDragStartedWithItem(dragView);
4977 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004978 }
4979
Anjali Koppalf5d29132014-02-28 13:33:27 -08004980 @Override
4981 public void onPageSwitch(View newPage, int newPageIndex) {
4982 }
4983
Winson Chung80baf5a2010-08-09 16:03:15 -07004984 /**
Joe Onoratobe386092009-11-17 17:32:16 -08004985 * Prints out out state for debugging.
4986 */
4987 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04004988 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08004989 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08004990 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
4991 Log.d(TAG, "mRestoring=" + mRestoring);
4992 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
4993 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004994 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08004995 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07004996
Winson Chung785d2eb2011-04-14 16:08:02 -07004997 if (mAppsCustomizeContent != null) {
4998 mAppsCustomizeContent.dumpState();
4999 }
Daniel Sandler325dc232013-06-05 22:57:57 -04005000 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08005001 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005002
5003 @Override
5004 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5005 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07005006 synchronized (sDumpLogs) {
5007 writer.println(" ");
5008 writer.println("Debug logs: ");
5009 for (int i = 0; i < sDumpLogs.size(); i++) {
5010 writer.println(" " + sDumpLogs.get(i));
5011 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005012 }
5013 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005014
5015 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07005016 if (DEBUG_DUMP_LOG) {
5017 synchronized (sDumpLogs) {
5018 Log.d(TAG, "");
5019 Log.d(TAG, "*********************");
5020 Log.d(TAG, "Launcher debug logs: ");
5021 for (int i = 0; i < sDumpLogs.size(); i++) {
5022 Log.d(TAG, " " + sDumpLogs.get(i));
5023 }
5024 Log.d(TAG, "*********************");
5025 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07005026 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005027 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005028 }
5029
5030 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005031 addDumpLog(tag, log, null, debugLog);
5032 }
5033
5034 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07005035 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005036 if (e != null) {
5037 Log.d(tag, log, e);
5038 } else {
5039 Log.d(tag, log);
5040 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005041 }
Winson Chungede41292013-09-19 16:27:36 -07005042 if (DEBUG_DUMP_LOG) {
5043 sDateStamp.setTime(System.currentTimeMillis());
5044 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05005045 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
Filiped63c86b2015-07-31 12:29:22 +00005046 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07005047 }
Winson Chungede41292013-09-19 16:27:36 -07005048 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005049 }
5050
Winson Chungede41292013-09-19 16:27:36 -07005051 public void dumpLogsToLocalData() {
5052 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01005053 new AsyncTask<Void, Void, Void>() {
Jose Pascoalfe3b08b2015-02-11 18:01:38 +00005054 @SuppressWarnings("UnusedAssignment")
Michael Jurka43467462013-11-14 12:03:58 +01005055 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07005056 boolean success = false;
5057 sDateStamp.setTime(sRunStart);
5058 String FILENAME = sDateStamp.getMonth() + "-"
5059 + sDateStamp.getDay() + "_"
5060 + sDateStamp.getHours() + "-"
5061 + sDateStamp.getMinutes() + "_"
5062 + sDateStamp.getSeconds() + ".txt";
5063
5064 FileOutputStream fos = null;
5065 File outFile = null;
5066 try {
5067 outFile = new File(getFilesDir(), FILENAME);
5068 outFile.createNewFile();
5069 fos = new FileOutputStream(outFile);
5070 } catch (Exception e) {
5071 e.printStackTrace();
5072 }
5073 if (fos != null) {
5074 PrintWriter writer = new PrintWriter(fos);
5075
5076 writer.println(" ");
5077 writer.println("Debug logs: ");
5078 synchronized (sDumpLogs) {
5079 for (int i = 0; i < sDumpLogs.size(); i++) {
5080 writer.println(" " + sDumpLogs.get(i));
5081 }
5082 }
5083 writer.close();
5084 }
5085 try {
5086 if (fos != null) {
5087 fos.close();
5088 success = true;
5089 }
5090 } catch (IOException e) {
5091 e.printStackTrace();
5092 }
Michael Jurka43467462013-11-14 12:03:58 +01005093 return null;
Winson Chungede41292013-09-19 16:27:36 -07005094 }
Michael Jurka43467462013-11-14 12:03:58 +01005095 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07005096 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005097 }
Jose Pascoalca875e52014-11-24 12:34:59 +00005098
5099 private void updateActivityInfoViaExplicitIntent(ComponentName component)
5100 {
Filipe Gonçalvesa804b282015-06-23 17:47:42 +01005101 AppSwitcherManager.applicationStarted(this, component);
Jose Pascoalec3574b2014-12-02 19:53:40 +00005102 AppDiscoverer.getInstance().applicationStarted(this, component);
Jose Pascoalca875e52014-11-24 12:34:59 +00005103 }
Jose Pascoald1f7ac92014-11-25 19:12:02 +00005104
5105 public void startEditFavorites()
5106 {
5107 startActivityForResult(new Intent(this, EditFavoritesActivity.class), REQUEST_EDIT_FAVORITES);
5108 }
Jose Pascoala046c672014-11-26 19:46:03 +00005109 public boolean isWorkspaceVisible() {
Jose Pascoal3c0767e2014-12-03 18:52:04 +00005110 return !isAgingAppDrawerVisible() && !mWorkspace.isInOverviewMode() && !isAllAppsVisible() && (mState == State.WORKSPACE) || (mOnResumeState == State.WORKSPACE);
Jose Pascoala046c672014-11-26 19:46:03 +00005111 }
5112
5113 private void setupEdgeSwipeMenu() {
5114 mEdgeMenuContainerView = (FrameLayout)findViewById(R.id.edge_menu_container);
Jose Pascoal5fbc58f2014-11-27 21:20:53 +00005115 mEdgeSwipeMenu = new EdgeSwipeMenu(this, this, mDragController, mEdgeMenuContainerView);
Jose Pascoala046c672014-11-26 19:46:03 +00005116 }
Filiped63c86b2015-07-31 12:29:22 +00005117
5118 /**
5119 * Show OOBE tutorial on first use of Edge Swipe, Edit Favorites, etc...
5120 *
5121 * @param oobeToShow
5122 * Activity identifier: SHOW_OOBE_EDIT_FAVORITES or
5123 * SHOW_OOBE_EDGE_SWIPE_MENU
5124 * @param oobeTutorial
5125 * Tutorial to show: OOBEActivity.OOBE_EDIT_FAVORITES_TUTORIAL,
5126 * OOBEActivity.OOBE_EDGE_SWIPE_TUTORIAL,
5127 * OOBEActivity.OOBE_FULL_TUTORIAL
5128 */
5129 private boolean startOOBEActivityOnFirstUse(String oobeToShow,
5130 int oobeTutorial) {
5131 boolean result = false;
5132
Filipe50b01712015-12-01 16:31:59 +00005133 //if (true || mSharedPrefs.getBoolean(oobeToShow, true)) { //Uncomment to loop the animation
Filiped63c86b2015-07-31 12:29:22 +00005134 if (mSharedPrefs.getBoolean(oobeToShow, true)) {
5135 startOOBEActivity(oobeTutorial);
5136 SharedPreferences.Editor editor = mSharedPrefs.edit();
5137 editor.putBoolean(oobeToShow, false);
5138 editor.commit();
5139
5140 result = true;
5141 }
5142
5143 return result;
5144 }
5145
5146 /**
5147 * Starts the OOBEActivity in the selected tutorial
5148 *
5149 * @param oobeTutorial
5150 * Tutorial to show: OOBEActivity.OOBE_EDIT_FAVORITES_TUTORIAL,
5151 * OOBEActivity.OOBE_EDGE_SWIPE_TUTORIAL,
5152 * OOBEActivity.OOBE_FULL_TUTORIAL
5153 */
5154 private void startOOBEActivity(int oobeTutorial) {
5155 Intent oobeEditFavoritesIntent = new Intent(this, OOBEActivity.class);
5156 oobeEditFavoritesIntent.putExtra(OOBEActivity.OOBE_TUTORIAL,
5157 oobeTutorial);
5158 startActivity(oobeEditFavoritesIntent);
5159 }
5160
5161 @TargetApi(21)
Jose Pascoal3c0767e2014-12-03 18:52:04 +00005162 public void showAgingAppDrawer() {
Tiago Costadaaa70c2014-12-10 15:15:57 +00005163
5164 if (Utilities.isLmpOrAbove()) {
Tiago Costadaaa70c2014-12-10 15:15:57 +00005165 setupGrayoutSystemBarsForLmp();
5166 }
5167
Jose Pascoal3c0767e2014-12-03 18:52:04 +00005168 mAgingAppDrawer.refreshView(this, this);
5169 mAgingAppDrawer.setVisibility(View.VISIBLE);
Jose Pascoal0f0b6782015-01-22 17:31:23 +00005170
5171 mAgingAppDrawer.setPivotX(mAgingAppDrawer.getWidth() / 2);
5172 mAgingAppDrawer.setPivotY((float) (mAgingAppDrawer.getHeight() / 5));
5173
5174 ObjectAnimator alpha = ObjectAnimator.ofFloat(mAgingAppDrawer,
5175 View.ALPHA, 0, 1);
5176 alpha.setDuration(180);
5177 alpha.start();
5178
5179 ObjectAnimator scaleX = ObjectAnimator.ofFloat(mAgingAppDrawer,
5180 View.SCALE_X, 0.3f, 1);
5181 scaleX.setDuration(360);
5182 scaleX.setInterpolator(new DecelerateInterpolator());
5183 scaleX.start();
5184
5185 ObjectAnimator scaleY = ObjectAnimator.ofFloat(mAgingAppDrawer,
5186 View.SCALE_Y, 0.3f, 1);
5187 scaleY.setDuration(360);
5188 scaleY.setInterpolator(new DecelerateInterpolator());
5189 scaleY.start();
5190
5191 ObjectAnimator translationY = ObjectAnimator.ofFloat(mAgingAppDrawer,
5192 View.TRANSLATION_Y, (mAgingAppDrawer.getHeight() / 2), 0);
5193 translationY.setDuration(480);
5194 translationY.setInterpolator(new OvershootInterpolator(0.5f));
5195 translationY.start();
Jose Pascoal3c0767e2014-12-03 18:52:04 +00005196 }
5197
Tiago Costadaaa70c2014-12-10 15:15:57 +00005198 @TargetApi(21)
Jose Pascoal3c0767e2014-12-03 18:52:04 +00005199 public void hideAgingAppDrawer() {
Tiago Costadaaa70c2014-12-10 15:15:57 +00005200
5201 if (Utilities.isLmpOrAbove()) {
Tiago Costadaaa70c2014-12-10 15:15:57 +00005202 setupTransparentSystemBarsForLmp();
5203 }
5204
Jose Pascoal3c0767e2014-12-03 18:52:04 +00005205 mAgingAppDrawer.setVisibility(View.GONE);
5206 }
5207
5208 public boolean isAgingAppDrawerVisible(){
5209 return mAgingAppDrawer.getVisibility() == View.VISIBLE;
5210 }
Jose Pascoal43aab392014-12-05 18:00:55 +00005211
5212 public void exitOverviewMode(){
5213 if (mWorkspace.isInOverviewMode()) {
5214 mWorkspace.exitOverviewMode(true);
5215 }
5216 }
Michael Jurka2763be32011-02-24 11:19:57 -08005217}
Dan Sandlerd5024042014-01-09 15:01:33 -05005218
5219interface DebugIntents {
5220 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5221 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00005222}