blob: 33cc29e677dff7eb02cd537d211708d1680fd4d1 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Daniel Sandler325dc232013-06-05 22:57:57 -040018package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
24import android.animation.PropertyValuesHolder;
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;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020063import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080064import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070065import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070066import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040067import android.os.SystemClock;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080068import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.text.Selection;
70import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070071import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070073import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070074import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070075import android.view.Display;
76import android.view.Gravity;
77import android.view.HapticFeedbackConstants;
78import android.view.KeyEvent;
79import android.view.LayoutInflater;
80import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070081import android.view.MotionEvent;
82import android.view.Surface;
83import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070084import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080085import android.view.View.OnLongClickListener;
Adam Cohen2854d252014-08-27 16:04:07 -070086import android.view.ViewAnimationUtils;
Adam Cohen96d30a12013-07-16 18:13:21 -070087import android.view.ViewGroup;
88import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080089import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Sunny Goyal651077b2014-06-30 14:15:31 -070090import android.view.Window;
Adam Cohen96d30a12013-07-16 18:13:21 -070091import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080092import android.view.accessibility.AccessibilityEvent;
Adam Cohen9bfdb762014-07-21 17:44:06 -070093import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080094import android.view.animation.DecelerateInterpolator;
Adam Cohen2854d252014-08-27 16:04:07 -070095import android.view.animation.Interpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080096import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070097import android.widget.Advanceable;
98import android.widget.FrameLayout;
99import android.widget.ImageView;
100import android.widget.TextView;
101import android.widget.Toast;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700102
Sunny Goyal651077b2014-06-30 14:15:31 -0700103import com.android.launcher3.DropTarget.DragObject;
104import com.android.launcher3.PagedView.PageSwitchListener;
Sunny Goyalffe83f12014-08-14 17:39:34 -0700105import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100106import com.android.launcher3.compat.LauncherActivityInfoCompat;
107import com.android.launcher3.compat.LauncherAppsCompat;
Sunny Goyale755d462014-07-22 13:48:29 -0700108import com.android.launcher3.compat.PackageInstallerCompat;
109import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
Kenny Guyed131872014-04-30 03:02:21 +0100110import com.android.launcher3.compat.UserHandleCompat;
111import com.android.launcher3.compat.UserManagerCompat;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700112
Adam Cohenc0dcf592011-06-01 15:30:43 -0700113import java.io.DataInputStream;
114import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700115import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700116import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700117import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700118import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700119import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700120import java.io.PrintWriter;
Adam Cohen0b395352014-06-09 22:54:36 +0000121import java.lang.reflect.Field;
122import java.lang.reflect.InvocationTargetException;
123import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700124import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700125import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700126import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700127import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700128import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700129import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000130import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700131
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132/**
133 * Default launcher application.
134 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100135public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700136 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700137 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800138 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700139 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140
Daniel Sandlerf061f822013-06-27 13:59:36 -0400141 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400142 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700143 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400144 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700145 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700146
Dan Sandlerd5024042014-01-09 15:01:33 -0500147 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
148
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700150 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700152 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700153 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Michael Jurka8b805b12012-04-18 14:23:14 -0700155 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700156 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700157
Mathew Inwood876a8462013-06-14 14:12:41 +0100158 /**
159 * IntentStarter uses request codes starting with this. This must be greater than all activity
160 * request codes used internally.
161 */
162 protected static final int REQUEST_LAST = 100;
163
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
165
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800166 static final int SCREEN_COUNT = 5;
167 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800168
Romain Guy98d01652009-06-30 16:21:04 -0700169 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800170 // To turn on these properties, type
171 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
172 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
173 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800174 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800175
Winson Chung2672ff92012-05-04 16:22:30 -0700176 // The Intent extra that defines whether to ignore the launch animation
177 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400178 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700179
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180 // Type: int
181 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700182 // Type: int
183 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700185 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
186 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
188 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700189 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700191 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192 // Type: boolean
193 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
194 // Type: long
195 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700196 // Type: int
197 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
198 // Type: int
199 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
200 // Type: parcelable
201 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000202 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800203 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000204 // Type: int[]
205 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800206
Adam Cohen432609a2014-03-13 17:03:22 -0700207 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800208 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
209
Adam Cohen3ed316a2014-07-23 18:21:20 -0700210 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
211 static final String ACTION_FIRST_LOAD_COMPLETE =
212 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
213
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100214 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700215 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100216 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700217 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100218 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700219
Adam Cohen39a06042013-07-19 14:30:12 -0700220 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b8002013-08-15 15:44:26 -0700221 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700222
Winson Chunga6945242014-01-08 14:04:34 -0800223 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
224
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700225 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700226 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700227 private State mState = State.WORKSPACE;
228 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700229
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700230 private boolean mIsSafeModeEnabled;
231
Joe Onorato9c1289c2009-08-17 11:03:03 -0400232 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700233 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
234 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700235 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800237 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800238 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800239
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000240 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
241 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
242
Winson Chunga2413752012-04-03 14:22:34 -0700243 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700244 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
245 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700246 private static int NEW_APPS_ANIMATION_DELAY = 500;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700247 private static final int SINGLE_FRAME_DELAY = 16;
Winson Chunga2413752012-04-03 14:22:34 -0700248
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800249 private final BroadcastReceiver mCloseSystemDialogsReceiver
250 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800251 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
252
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800253 private LayoutInflater mInflater;
254
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800255 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700256 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800257 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800258 private DragLayer mDragLayer;
259 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700260 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700261
Sunny Goyalffe83f12014-08-14 17:39:34 -0700262 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700263 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700264
Michael Jurkac9d95c52011-08-29 14:03:34 -0700265 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700266 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800267 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700268
Michael Jurka0280c3b2010-09-17 15:00:07 -0700269 private int[] mTmpAddItemCellCoordinates = new int[2];
270
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800271 private FolderInfo mFolderInfo;
272
Winson Chung3d503fb2011-07-13 17:25:49 -0700273 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800274 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700275
Michael Jurka838a4ca2011-02-07 13:33:06 -0800276 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700277
Winson Chungc51db6a2011-10-05 11:44:49 -0700278 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700279 private AppsCustomizeTabHost mAppsCustomizeTabHost;
280 private AppsCustomizePagedView mAppsCustomizeContent;
281 private boolean mAutoAdvanceRunning = false;
Adam Cohen24ce0b32014-01-14 16:18:14 -0800282 private View mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800283
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800284 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700285 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
286 // scroll issues (because the workspace may not have been measured yet) and extra work.
287 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
288 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800289
290 private SpannableStringBuilder mDefaultKeySsb = null;
291
Joe Onorato9c1289c2009-08-17 11:03:03 -0400292 private boolean mWorkspaceLoading = true;
293
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800294 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800295 private boolean mRestoring;
296 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700297 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800298
Michael Jurka1e2f4652013-07-08 18:03:46 -0700299 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700300 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
301
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800302 private Bundle mSavedInstanceState;
303
Joe Onorato9c1289c2009-08-17 11:03:03 -0400304 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800305 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800306 private boolean mUserPresent = true;
307 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700308 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800309 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400310
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700311 private static LocaleConfiguration sLocaleConfiguration = null;
312
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700313 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700314
Adam Cohen61f560d2013-09-30 15:58:20 -0700315 private View.OnTouchListener mHapticFeedbackTouchListener;
316
Adam Cohended9f8d2010-11-03 13:25:16 -0700317 // Related to the auto-advancing of widgets
318 private final int ADVANCE_MSG = 1;
319 private final int mAdvanceInterval = 20000;
320 private final int mAdvanceStagger = 250;
321 private long mAutoAdvanceSentTime;
322 private long mAutoAdvanceTimeLeft = -1;
323 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
324 new HashMap<View, AppWidgetProviderInfo>();
325
Winson Chung400438b2011-01-16 17:53:48 -0800326 // Determines how long to wait after a rotation before restoring the screen orientation to
327 // match the sensor state.
328 private final int mRestoreScreenOrientationDelay = 500;
329
Michael Jurka4ef207b2010-11-29 17:05:45 -0800330 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700331 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
332 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
Winson Chungd64a6662013-09-30 11:06:59 -0700333
Craig Mautner360310b2012-10-26 15:13:08 -0700334 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700335
Adam Cohen1462de32012-07-24 22:34:36 -0700336 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700337 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700338
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700339 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700340 static Date sDateStamp = new Date();
341 static DateFormat sDateFormat =
342 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
343 static long sRunStart = System.currentTimeMillis();
344 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700345
Winson Chung46353de2012-02-16 14:05:10 -0800346 // We only want to get the SharedPreferences once since it does an FS stat each time we get
347 // it from the context.
348 private SharedPreferences mSharedPrefs;
349
Adam Cohene25af792013-06-06 23:08:25 -0700350 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
351
Winson Chungf0c6ae02012-03-21 16:10:31 -0700352 // Holds the page that we need to animate to, and the icon views that we need to animate up
353 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700354 private ImageView mFolderIconImageView;
355 private Bitmap mFolderIconBitmap;
356 private Canvas mFolderIconCanvas;
357 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700358
Michael Jurkaddd62e92011-02-16 17:49:14 -0800359 private BubbleTextView mWaitingForResume;
360
Michael Jurkac1f5d262011-09-30 19:32:27 -0700361 private Runnable mBuildLayersRunnable = new Runnable() {
362 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700363 if (mWorkspace != null) {
364 mWorkspace.buildPageHardwareLayers();
365 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700366 }
367 };
368
Adam Cohendb364c32014-05-20 14:23:40 -0700369 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800370
Michael Jurka7267fa52013-09-26 15:29:57 -0700371 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800372
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800373 private static class PendingAddArguments {
374 int requestCode;
375 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700376 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700377 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800378 int cellX;
379 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700380 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800381 }
382
Daniel Sandlerff02d492013-08-05 02:12:05 -0400383 private Stats mStats;
384
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700385 FocusIndicatorView mFocusHandler;
386
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800387 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800388 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700389 }
390
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800391 @Override
392 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700393 if (DEBUG_STRICT_MODE) {
394 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
395 .detectDiskReads()
396 .detectDiskWrites()
397 .detectNetwork() // or .detectAll() for all detectable problems
398 .penaltyLog()
399 .build());
400 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
401 .detectLeakedSqlLiteObjects()
402 .detectLeakedClosableObjects()
403 .penaltyLog()
404 .penaltyDeath()
405 .build());
406 }
407
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800408 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400409
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400410 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400411 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700412 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700413 // Determine the dynamic grid properties
414 Point smallestSize = new Point();
415 Point largestSize = new Point();
416 Point realSize = new Point();
417 Display display = getWindowManager().getDefaultDisplay();
418 display.getCurrentSizeRange(smallestSize, largestSize);
419 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700420 DisplayMetrics dm = new DisplayMetrics();
421 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700422
Winson Chung5f8afe62013-08-12 16:19:28 -0700423 // Lazy-initialize the dynamic grid
424 DeviceProfile grid = app.initDynamicGrid(this,
425 Math.min(smallestSize.x, smallestSize.y),
426 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700427 realSize.x, realSize.y,
428 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700429
430 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400431 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700432 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700433 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800434 mModel = app.setLauncher(this);
435 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700436 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400437 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800438 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700439
Daniel Sandlerff02d492013-08-05 02:12:05 -0400440 mStats = new Stats(this);
441
Sunny Goyalffe83f12014-08-14 17:39:34 -0700442 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700443
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700444 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
445 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700446
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700447 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
448 // this also ensures that any synchronous binding below doesn't re-trigger another
449 // LauncherModel load.
450 mPaused = false;
451
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800452 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200453 android.os.Debug.startMethodTracing(
454 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800455 }
456
457 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800458 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700459
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800460 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100461 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800462
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800463 registerContentObservers();
464
Joe Onorato7c312c12009-08-13 21:36:53 -0700465 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700466
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800467 mSavedState = savedInstanceState;
468 restoreState(mSavedState);
469
470 if (PROFILE_STARTUP) {
471 android.os.Debug.stopMethodTracing();
472 }
473
474 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700475 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700476 // If the user leaves launcher, then we should just load items asynchronously when
477 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500478 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700479 } else {
480 // We only load the page synchronously if the user rotates (or triggers a
481 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800482 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700483 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800484 }
485
486 // For handling default keys
487 mDefaultKeySsb = new SpannableStringBuilder();
488 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800489
490 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
491 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800492
Adam Cohenf9426d52012-06-04 17:26:21 -0700493 updateGlobalIcons();
494
495 // On large interfaces, we want the screen to auto-rotate based on the current orientation
496 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700497
Adam Cohen432609a2014-03-13 17:03:22 -0700498 if (shouldShowIntroScreen()) {
499 showIntroScreen();
500 } else {
501 showFirstRunActivity();
Sunny Goyal88d60f12014-09-08 03:47:29 -0700502 showFirstRunClings();
Winson Chunga6945242014-01-08 14:04:34 -0800503 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700504 }
505
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700506 @Override
507 public void onLauncherProviderChange() { }
508
Winson Chung98ca0f72013-07-29 12:58:51 -0700509 /** To be overriden by subclasses to hint to Launcher that we have custom content */
510 protected boolean hasCustomContentToLeft() {
511 return false;
512 }
513
Dave Hawkeya8881582013-09-17 15:55:33 -0600514 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500515 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600516 * {@link #addToCustomContentPage}. This will only be invoked if
517 * {@link #hasCustomContentToLeft()} is {@code true}.
518 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500519 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600520 }
521
522 /**
523 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
524 * ensure the custom content page is added or removed if necessary.
525 */
526 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600527 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600528 // Not bound yet, wait for bindScreens to be called.
529 return;
530 }
531
532 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
533 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500534 mWorkspace.createCustomContentContainer();
535 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600536 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
537 mWorkspace.removeCustomContentPage();
538 }
539 }
540
Adam Cohenf9426d52012-06-04 17:26:21 -0700541 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700542 boolean searchVisible = false;
543 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800544 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700545 int coi = getCurrentOrientationIndexForGlobalIcons();
Adam Cohena00673c2014-08-14 12:57:28 -0700546 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700547 searchVisible = updateGlobalSearchIcon();
548 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700549 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700550 if (sGlobalSearchIcon[coi] != null) {
551 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700552 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700553 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700554 if (sVoiceSearchIcon[coi] != null) {
555 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700556 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700557 }
Winson Chungadf0c182012-08-23 14:59:07 -0700558 if (mSearchDropTargetBar != null) {
559 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
560 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800561 }
Romain Guycbb89e42009-06-08 15:52:54 -0700562
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800563 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700564 if (sLocaleConfiguration == null) {
565 new AsyncTask<Void, Void, LocaleConfiguration>() {
566 @Override
567 protected LocaleConfiguration doInBackground(Void... unused) {
568 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
569 readConfiguration(Launcher.this, localeConfiguration);
570 return localeConfiguration;
571 }
572
573 @Override
574 protected void onPostExecute(LocaleConfiguration result) {
575 sLocaleConfiguration = result;
576 checkForLocaleChange(); // recursive, but now with a locale configuration
577 }
578 }.execute();
579 return;
580 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700581
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800582 final Configuration configuration = getResources().getConfiguration();
583
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700584 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800585 final String locale = configuration.locale.toString();
586
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700587 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800588 final int mcc = configuration.mcc;
589
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700590 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800591 final int mnc = configuration.mnc;
592
Romain Guy84f296c2009-11-04 15:00:44 -0800593 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800594
Romain Guy84f296c2009-11-04 15:00:44 -0800595 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700596 sLocaleConfiguration.locale = locale;
597 sLocaleConfiguration.mcc = mcc;
598 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700599
Joe Onorato0589f0f2010-02-08 13:44:00 -0800600 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700601
602 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100603 new AsyncTask<Void, Void, Void>() {
604 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700605 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100606 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700607 }
Michael Jurka43467462013-11-14 12:03:58 +0100608 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700609 }
610 }
611
612 private static class LocaleConfiguration {
613 public String locale;
614 public int mcc = -1;
615 public int mnc = -1;
616 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700617
Romain Guy98d01652009-06-30 16:21:04 -0700618 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
619 DataInputStream in = null;
620 try {
621 in = new DataInputStream(context.openFileInput(PREFERENCES));
622 configuration.locale = in.readUTF();
623 configuration.mcc = in.readInt();
624 configuration.mnc = in.readInt();
625 } catch (FileNotFoundException e) {
626 // Ignore
627 } catch (IOException e) {
628 // Ignore
629 } finally {
630 if (in != null) {
631 try {
632 in.close();
633 } catch (IOException e) {
634 // Ignore
635 }
636 }
637 }
638 }
639
640 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
641 DataOutputStream out = null;
642 try {
643 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
644 out.writeUTF(configuration.locale);
645 out.writeInt(configuration.mcc);
646 out.writeInt(configuration.mnc);
647 out.flush();
648 } catch (FileNotFoundException e) {
649 // Ignore
650 } catch (IOException e) {
651 //noinspection ResultOfMethodCallIgnored
652 context.getFileStreamPath(PREFERENCES).delete();
653 } finally {
654 if (out != null) {
655 try {
656 out.close();
657 } catch (IOException e) {
658 // Ignore
659 }
660 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800661 }
662 }
663
Anton Hanssona2f665f2013-09-26 12:18:32 +0100664 public Stats getStats() {
665 return mStats;
666 }
667
Bjorn Bringertc459e522013-06-07 19:36:01 +0100668 public LayoutInflater getInflater() {
669 return mInflater;
670 }
671
Winson Chung36a62fe2012-05-06 18:04:42 -0700672 boolean isDraggingEnabled() {
673 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
674 // that is subsequently removed from the workspace in startBinding().
675 return !mModel.isLoadingWorkspace();
676 }
677
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800678 static int getScreen() {
679 synchronized (sLock) {
680 return sScreen;
681 }
682 }
683
684 static void setScreen(int screen) {
685 synchronized (sLock) {
686 sScreen = screen;
687 }
688 }
689
Winson Chung557d6ed2011-07-08 15:34:52 -0700690 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000691 * Copied from View -- the View version of the method isn't called
692 * anywhere else in our process and only exists for API level 17+,
693 * so it's ok to keep our own version with no API requirement.
694 */
695 public static int generateViewId() {
696 for (;;) {
697 final int result = sNextGeneratedId.get();
698 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
699 int newValue = result + 1;
700 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
701 if (sNextGeneratedId.compareAndSet(result, newValue)) {
702 return result;
703 }
704 }
705 }
706
707 public int getViewIdForItem(ItemInfo info) {
708 // This cast is safe given the > 2B range for int.
709 int itemId = (int) info.id;
710 if (mItemIdToViewId.containsKey(itemId)) {
711 return mItemIdToViewId.get(itemId);
712 }
713 int viewId = generateViewId();
714 mItemIdToViewId.put(itemId, viewId);
715 return viewId;
716 }
717
718 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700719 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
720 * a configuration step, this allows the proper animations to run after other transitions.
721 */
Adam Cohendb364c32014-05-20 14:23:40 -0700722 private long completeAdd(PendingAddArguments args) {
723
724 long screenId = ensurePendingDropLayoutExists(args.screenId);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800725 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800726 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700727 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700728 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700729 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800730 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700731 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700732 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700733 case REQUEST_RECONFIGURE_APPWIDGET:
734 completeRestoreAppWidget(args.appWidgetId);
735 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800736 }
Michael Jurka27614d22012-04-02 06:40:22 -0700737 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
738 // if you turned the screen off and then back while in All Apps, Launcher would not
739 // return to the workspace. Clearing mAddInfo.container here fixes this issue
740 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700741 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800742 }
743
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800744 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700745 protected void onActivityResult(
746 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700747 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700748 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700749 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800750 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700751
Adam Cohenad4e15c2013-10-17 16:21:35 -0700752 Runnable exitSpringLoaded = new Runnable() {
753 @Override
754 public void run() {
755 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
756 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
757 }
758 };
759
Michael Jurka8b805b12012-04-18 14:23:14 -0700760 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700761 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700762 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
763 if (resultCode == RESULT_CANCELED) {
764 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700765 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700766 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700767 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700768 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
769 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700770 }
771 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200772 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
773 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
774 mWorkspace.exitOverviewMode(false);
775 }
776 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700777 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200778
Adam Cohened66b2b2012-01-23 17:28:51 -0800779 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
780 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700781
Adam Cohendb364c32014-05-20 14:23:40 -0700782 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800783 // We have special handling for widgets
784 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800785 final int appWidgetId;
786 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
787 : -1;
788 if (widgetId < 0) {
789 appWidgetId = pendingAddWidgetId;
790 } else {
791 appWidgetId = widgetId;
792 }
793
Adam Cohenad4e15c2013-10-17 16:21:35 -0700794 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800795 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700796 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
797 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700798 result = RESULT_CANCELED;
799 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700800 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700801 @Override
802 public void run() {
803 exitSpringLoadedDragModeDelayed(false, 0, null);
804 }
805 };
Adam Cohendb364c32014-05-20 14:23:40 -0700806 if (workspaceLocked) {
807 // No need to remove the empty screen if we're mid-binding, as the
808 // the bind will not add the empty screen.
809 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
810 } else {
811 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
812 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
813 }
Winson Chung5aaab772012-04-27 15:24:02 -0700814 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700815 if (!workspaceLocked) {
816 mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
817 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
818
819 dropLayout.setDropPending(true);
820 final Runnable onComplete = new Runnable() {
821 @Override
822 public void run() {
823 completeTwoStageWidgetDrop(resultCode, appWidgetId);
824 dropLayout.setDropPending(false);
825 }
826 };
827 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
828 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
829 } else {
830 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
831 mPendingAddInfo);
832 sPendingAddItem = args;
833 }
Winson Chung5aaab772012-04-27 15:24:02 -0700834 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800835 return;
836 }
837
Sunny Goyalff572272014-07-23 13:58:07 -0700838 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
839 if (resultCode == RESULT_OK) {
840 // Update the widget view.
841 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
842 pendingAddWidgetId, mPendingAddInfo);
843 if (workspaceLocked) {
844 sPendingAddItem = args;
845 } else {
846 completeAdd(args);
847 }
848 }
849 // Leave the widget in the pending state if the user canceled the configure.
850 return;
851 }
852
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800853 // The pattern used here is that a user PICKs a specific application,
854 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700855
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800856 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
857 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700858 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700859 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
860 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800861 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700862 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800863 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700864 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700865 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
866 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800867 }
Adam Cohen00074722013-10-11 17:46:09 -0700868 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700869 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700870 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800871 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800872 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800873 }
874
Adam Cohendb364c32014-05-20 14:23:40 -0700875 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
876 appWidgetId, ItemInfo info) {
877 PendingAddArguments args = new PendingAddArguments();
878 args.requestCode = requestCode;
879 args.intent = data;
880 args.container = info.container;
881 args.screenId = info.screenId;
882 args.cellX = info.cellX;
883 args.cellY = info.cellY;
884 args.appWidgetId = appWidgetId;
885 return args;
886 }
887
888 /**
889 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
890 *
891 * @param screenId the screen id to check
892 * @return the new screen, or screenId if it exists
893 */
894 private long ensurePendingDropLayoutExists(long screenId) {
895 CellLayout dropLayout =
896 (CellLayout) mWorkspace.getScreenWithId(screenId);
897 if (dropLayout == null) {
898 // it's possible that the add screen was removed because it was
899 // empty and a re-bind occurred
900 mWorkspace.addExtraEmptyScreen();
901 return mWorkspace.commitExtraEmptyScreen();
902 } else {
903 return screenId;
904 }
905 }
906
Adam Cohened66b2b2012-01-23 17:28:51 -0800907 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700908 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700909 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800910 Runnable onCompleteRunnable = null;
911 int animationType = 0;
912
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700913 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800914 if (resultCode == RESULT_OK) {
915 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
916 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700917 mPendingAddWidgetInfo);
918 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800919 onCompleteRunnable = new Runnable() {
920 @Override
921 public void run() {
922 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700923 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700924 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
925 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800926 }
927 };
928 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800929 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800930 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800931 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700932 if (mDragLayer.getAnimatedView() != null) {
933 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
934 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
935 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700936 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700937 // The animated view may be null in the case of a rotation during widget configuration
938 onCompleteRunnable.run();
939 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800940 }
941
942 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700943 protected void onStop() {
944 super.onStop();
945 FirstFrameAnimatorHelper.setIsVisible(false);
946 }
947
948 @Override
949 protected void onStart() {
950 super.onStart();
951 FirstFrameAnimatorHelper.setIsVisible(true);
952 }
953
954 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800955 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200956 long startTime = 0;
957 if (DEBUG_RESUME_TIME) {
958 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400959 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200960 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800961 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700962
Winson Chung4a2afa32012-07-19 14:53:05 -0700963 // Restore the previous launcher state
964 if (mOnResumeState == State.WORKSPACE) {
965 showWorkspace(false);
966 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c62013-11-06 15:49:51 -0800967 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700968 }
969 mOnResumeState = State.NONE;
970
Craig Mautner360310b2012-10-26 15:13:08 -0700971 // Background was set to gradient in onPause(), restore to black if in all apps.
972 setWorkspaceBackground(mState == State.WORKSPACE);
973
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800974 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700975 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700976 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500977 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400978 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700979 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800980 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700981 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200982 // We might have postponed some bind calls until onResume (see waitUntilResume) --
983 // execute them here
984 long startTimeCallbacks = 0;
985 if (DEBUG_RESUME_TIME) {
986 startTimeCallbacks = System.currentTimeMillis();
987 }
988
989 if (mAppsCustomizeContent != null) {
990 mAppsCustomizeContent.setBulkBind(true);
991 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700992 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
993 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200994 }
995 if (mAppsCustomizeContent != null) {
996 mAppsCustomizeContent.setBulkBind(false);
997 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700998 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +0200999 if (DEBUG_RESUME_TIME) {
1000 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1001 (System.currentTimeMillis() - startTimeCallbacks));
1002 }
Michael Jurka447bf842013-05-15 14:52:15 +02001003 }
Michael Jurka54554252013-08-01 12:52:23 +02001004 if (mOnResumeCallbacks.size() > 0) {
1005 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1006 mOnResumeCallbacks.get(i).run();
1007 }
1008 mOnResumeCallbacks.clear();
1009 }
Winson Chunge4e50662012-01-23 14:45:13 -08001010
1011 // Reset the pressed state of icons that were locked in the press state while activities
1012 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001013 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001014 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001015 mWaitingForResume.setStayPressed(false);
1016 }
Winson Chung82963d52013-10-09 11:20:57 -07001017
Adam Cohen06dff352012-06-01 17:17:08 -07001018 // It is possible that widgets can receive updates while launcher is not in the foreground.
1019 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1020 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1021 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001022 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001023
Winson Chung780fe592013-09-26 14:48:44 -07001024 // Process any items that were added while Launcher was away.
1025 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1026
Winson Chung5841efa2013-09-30 18:06:44 -07001027 // Update the voice search button proxy
1028 updateVoiceButtonProxyVisible(false);
1029
Adam Cohenf9426d52012-06-04 17:26:21 -07001030 // Again, as with the above scenario, it's possible that one or more of the global icons
1031 // were updated in the wrong orientation.
1032 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001033 if (DEBUG_RESUME_TIME) {
1034 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1035 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001036
1037 if (mWorkspace.getCustomContentCallbacks() != null) {
1038 // If we are resuming and the custom content is the current page, we call onShow().
1039 // It is also poassible that onShow will instead be called slightly after first layout
1040 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1041 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001042 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001043 }
1044 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001045 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001046 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001047
1048 PackageInstallerCompat.getInstance(this).onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001049 }
1050
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001051 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001052 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001053 // Ensure that items added to Launcher are queued until Launcher returns
1054 InstallShortcutReceiver.enableInstallQueue();
Sunny Goyale755d462014-07-22 13:48:29 -07001055 PackageInstallerCompat.getInstance(this).onPause();
Winson Chung997a9232013-07-24 15:33:46 -07001056
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001057 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001058 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001059 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001060 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001061
1062 // We call onHide() aggressively. The custom content callbacks should be able to
1063 // debounce excess onHide calls.
1064 if (mWorkspace.getCustomContentCallbacks() != null) {
1065 mWorkspace.getCustomContentCallbacks().onHide();
1066 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001067 }
Romain Guycbb89e42009-06-08 15:52:54 -07001068
Adam Cohenbffe7452013-07-22 18:21:45 -07001069 QSBScroller mQsbScroller = new QSBScroller() {
1070 int scrollY = 0;
1071
1072 @Override
1073 public void setScrollY(int scroll) {
1074 scrollY = scroll;
1075
1076 if (mWorkspace.isOnOrMovingToCustomContent()) {
1077 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001078 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001079 }
1080 }
1081 };
1082
1083 public void resetQSBScroll() {
1084 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001085 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001086 }
1087
1088 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001089 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1090 // by a onResume or by scrolling otherwise.
1091 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001092
1093 // Custom content is completely hidden
1094 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001095
1096 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1097 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001098
1099 // Indicates whether the user is allowed to scroll away from the custom content.
1100 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001101 }
1102
Jorim Jaggid017f882014-01-14 17:08:48 -08001103 protected boolean hasSettings() {
1104 return false;
1105 }
1106
Adam Cohenbffe7452013-07-22 18:21:45 -07001107 public interface QSBScroller {
1108 public void setScrollY(int scrollY);
1109 }
1110
Winson Chung98ca0f72013-07-29 12:58:51 -07001111 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001112 CustomContentCallbacks callbacks, String description) {
1113 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001114 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001115 }
1116
Adam Cohenedb40762013-07-18 16:45:45 -07001117 // The custom content needs to offset its content to account for the QSB
1118 public int getTopOffsetForCustomContent() {
1119 return mWorkspace.getPaddingTop();
1120 }
1121
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001122 @Override
1123 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001124 // Flag the loader to stop early before switching
1125 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001126 if (mAppsCustomizeContent != null) {
1127 mAppsCustomizeContent.surrender();
1128 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001129 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001130 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001131
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001132 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001133 @Override
1134 public void onWindowFocusChanged(boolean hasFocus) {
1135 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001136 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001137 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001138
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001139 private boolean acceptFilter() {
1140 final InputMethodManager inputManager = (InputMethodManager)
1141 getSystemService(Context.INPUT_METHOD_SERVICE);
1142 return !inputManager.isFullscreenMode();
1143 }
1144
1145 @Override
1146 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001147 final int uniChar = event.getUnicodeChar();
1148 final boolean handled = super.onKeyDown(keyCode, event);
1149 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1150 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001151 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1152 keyCode, event);
1153 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001154 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001155 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001156 // showSearchDialog()
1157 // If there are multiple keystrokes before the search dialog takes focus,
1158 // onSearchRequested() will be called for every keystroke,
1159 // but it is idempotent, so it's fine.
1160 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001161 }
1162 }
1163
Joe Onorato8a9625e2010-01-28 15:55:35 -08001164 // Eat the long press event so the keyboard doesn't come up.
1165 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1166 return true;
1167 }
1168
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001169 return handled;
1170 }
1171
Karl Rosaen138a0412009-04-23 19:00:21 -07001172 private String getTypedText() {
1173 return mDefaultKeySsb.toString();
1174 }
1175
1176 private void clearTypedText() {
1177 mDefaultKeySsb.clear();
1178 mDefaultKeySsb.clearSpans();
1179 Selection.setSelection(mDefaultKeySsb, 0);
1180 }
1181
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001182 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001183 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1184 * State
1185 */
1186 private static State intToState(int stateOrdinal) {
1187 State state = State.WORKSPACE;
1188 final State[] stateValues = State.values();
1189 for (int i = 0; i < stateValues.length; i++) {
1190 if (stateValues[i].ordinal() == stateOrdinal) {
1191 state = stateValues[i];
1192 break;
1193 }
1194 }
1195 return state;
1196 }
1197
1198 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001199 * Restores the previous state, if it exists.
1200 *
1201 * @param savedState The previous state.
1202 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001203 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001204 private void restoreState(Bundle savedState) {
1205 if (savedState == null) {
1206 return;
1207 }
1208
Michael Jurka883f55b2010-10-21 15:47:14 -07001209 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001210 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001211 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001212 }
1213
Adam Cohen21cd0022013-10-09 18:57:02 -07001214 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1215 PagedView.INVALID_RESTORE_PAGE);
1216 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001217 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001218 }
1219
Winson Chung3d503fb2011-07-13 17:25:49 -07001220 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001221 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001222
Winson Chung3d503fb2011-07-13 17:25:49 -07001223 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1224 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001225 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001226 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1227 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001228 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1229 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1230 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001231 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001232 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001233 mRestoring = true;
1234 }
1235
1236 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1237 if (renameFolder) {
1238 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001239 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001240 mRestoring = true;
1241 }
Winson Chunga12a2502010-12-20 14:41:35 -08001242
Winson Chung785d2eb2011-04-14 16:08:02 -07001243 // Restore the AppsCustomize tab
1244 if (mAppsCustomizeTabHost != null) {
1245 String curTab = savedState.getString("apps_customize_currentTab");
1246 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001247 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001248 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001249 mAppsCustomizeContent.loadAssociatedPages(
1250 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001251 }
1252
Winson Chung5afbf7b2011-07-25 11:53:08 -07001253 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1254 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001255 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001256 mItemIdToViewId = (HashMap<Integer, Integer>)
1257 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001258 }
1259
1260 /**
1261 * Finds all the views we need and configure them properly.
1262 */
1263 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001264 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001265
Craig Mautner360310b2012-10-26 15:13:08 -07001266 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001267 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001268 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1269 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001270 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001271 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001272
John Spurlock77e1f472013-09-11 10:09:51 -04001273 mLauncherView.setSystemUiVisibility(
1274 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001275 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001276
Winson Chung4c98d922011-05-31 16:50:48 -07001277 // Setup the drag layer
1278 mDragLayer.setup(this, dragController);
1279
Winson Chung3d503fb2011-07-13 17:25:49 -07001280 // Setup the hotseat
1281 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1282 if (mHotseat != null) {
1283 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001284 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001285 }
1286
Jorim Jaggid017f882014-01-14 17:08:48 -08001287 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001288 View widgetButton = findViewById(R.id.widget_button);
1289 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001290 @Override
1291 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001292 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001293 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001294 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001295 }
1296 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001297 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1298
1299 View wallpaperButton = findViewById(R.id.wallpaper_button);
1300 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001301 @Override
1302 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001303 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001304 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001305 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001306 }
1307 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001308 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1309
1310 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001311 if (hasSettings()) {
1312 settingsButton.setOnClickListener(new OnClickListener() {
1313 @Override
1314 public void onClick(View arg0) {
1315 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001316 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001317 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001318 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001319 });
1320 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1321 } else {
1322 settingsButton.setVisibility(View.GONE);
1323 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1324 lp.gravity = Gravity.END | Gravity.TOP;
1325 widgetButton.requestLayout();
1326 }
1327
Adam Cohendbdff6b2013-09-18 19:09:15 -07001328 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001329
Winson Chung4c98d922011-05-31 16:50:48 -07001330 // Setup the workspace
1331 mWorkspace.setHapticFeedbackEnabled(false);
1332 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001333 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001334 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001335
Winson Chungf0ea4d32011-06-06 14:27:16 -07001336 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001337 mSearchDropTargetBar = (SearchDropTargetBar)
1338 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001339
Winson Chungf0ea4d32011-06-06 14:27:16 -07001340 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001341 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001342 mAppsCustomizeContent = (AppsCustomizePagedView)
1343 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1344 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001345
Winson Chung3d503fb2011-07-13 17:25:49 -07001346 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001347 dragController.setDragScoller(mWorkspace);
1348 dragController.setScrollView(mDragLayer);
1349 dragController.setMoveTarget(mWorkspace);
1350 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001351 if (mSearchDropTargetBar != null) {
1352 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001353 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001354
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001355 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001356 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001357 mWeightWatcher = new WeightWatcher(this);
1358 mWeightWatcher.setAlpha(0.5f);
1359 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001360 new FrameLayout.LayoutParams(
1361 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001362 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001363 Gravity.BOTTOM)
1364 );
Adam Cohen39a06042013-07-19 14:30:12 -07001365
1366 boolean show = shouldShowWeightWatcher();
1367 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001368 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001369 }
1370
1371 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001372 * Sets the all apps button. This method is called from {@link Hotseat}.
1373 */
1374 public void setAllAppsButton(View allAppsButton) {
1375 mAllAppsButton = allAppsButton;
1376 }
1377
1378 public View getAllAppsButton() {
1379 return mAllAppsButton;
1380 }
1381
1382 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001383 * Creates a view representing a shortcut.
1384 *
1385 * @param info The data structure describing the shortcut.
1386 *
1387 * @return A View inflated from R.layout.application.
1388 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001389 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001390 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001391 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001392 }
1393
1394 /**
1395 * Creates a view representing a shortcut inflated from the specified resource.
1396 *
1397 * @param layoutResId The id of the XML layout used to create the shortcut.
1398 * @param parent The group the shortcut belongs to.
1399 * @param info The data structure describing the shortcut.
1400 *
1401 * @return A View inflated from layoutResId.
1402 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001403 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001404 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001405 favorite.applyFromShortcutInfo(info, mIconCache, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001406 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001407 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001408 return favorite;
1409 }
1410
1411 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001412 * Add a shortcut to the workspace.
1413 *
1414 * @param data The intent describing the shortcut.
1415 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001416 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001417 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001418 int cellY) {
1419 int[] cellXY = mTmpAddItemCellCoordinates;
1420 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001421 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001422
Michael Jurkad3ef3062010-11-23 16:23:58 -08001423 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001424
Adam Cohen558baaf2011-08-15 15:22:57 -07001425 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001426 if (info == null) {
1427 return;
1428 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001429 final View view = createShortcut(info);
1430
Adam Cohenfbba09b2011-07-18 21:43:05 -07001431 // First we check if we already know the exact location where we want to add this item.
1432 if (cellX >= 0 && cellY >= 0) {
1433 cellXY[0] = cellX;
1434 cellXY[1] = cellY;
1435 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001436
1437 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001438 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001439 true, null,null)) {
1440 return;
1441 }
1442 DragObject dragObject = new DragObject();
1443 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001444 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1445 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001446 return;
1447 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001448 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001449 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001450 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001451 foundCellSpan = (result != null);
1452 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001453 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001454 }
1455
1456 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001457 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001458 return;
1459 }
1460
Adam Cohendcd297f2013-06-18 13:13:40 -07001461 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001462
1463 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001464 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001465 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001466 }
1467 }
1468
Adam Cohen2f093b62012-04-30 18:59:53 -07001469 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1470 int minHeight) {
1471 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001472 // We want to account for the extra amount of padding that we are adding to the widget
1473 // to ensure that it gets the full amount of space that it has requested
1474 int requiredWidth = minWidth + padding.left + padding.right;
1475 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001476 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001477 }
1478
Adam Cohen2f093b62012-04-30 18:59:53 -07001479 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1480 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001481 }
1482
Adam Cohen2f093b62012-04-30 18:59:53 -07001483 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1484 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001485 }
1486
Adam Cohen2f093b62012-04-30 18:59:53 -07001487 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1488 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001489 }
1490
Adam Cohen2f093b62012-04-30 18:59:53 -07001491 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1492 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001493 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001494 }
1495
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001496 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001497 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001498 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001499 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001500 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001501 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001502 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001503 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1504 if (appWidgetInfo == null) {
1505 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1506 }
Romain Guycbb89e42009-06-08 15:52:54 -07001507
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001508 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001509 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001510
Adam Cohen2f093b62012-04-30 18:59:53 -07001511 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1512 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001513
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001514 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001515 // We have saved the position to which the widget was dragged-- this really only matters
1516 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001517 int[] cellXY = mTmpAddItemCellCoordinates;
1518 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001519 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001520 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001521 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1522 cellXY[0] = mPendingAddInfo.cellX;
1523 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001524 spanXY[0] = mPendingAddInfo.spanX;
1525 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001526 foundCellSpan = true;
1527 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001528 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001529 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001530 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1531 spanXY[1], cellXY, finalSpan);
1532 spanXY[0] = finalSpan[0];
1533 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001534 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001535 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001536 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001537 }
1538
Michael Jurka0280c3b2010-09-17 15:00:07 -07001539 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001540 if (appWidgetId != -1) {
1541 // Deleting an app widget ID is a void call but writes to disk before returning
1542 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001543 new AsyncTask<Void, Void, Void>() {
1544 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001545 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001546 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001547 }
Michael Jurka43467462013-11-14 12:03:58 +01001548 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001549 }
Winson Chung93eef082012-03-23 15:59:27 -07001550 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001551 return;
1552 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001553
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001554 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001555 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1556 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001557 launcherInfo.spanX = spanXY[0];
1558 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001559 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1560 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001561 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001562
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001563 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001564 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001565
1566 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001567 if (hostView == null) {
1568 // Perform actual inflation because we're live
1569 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1570 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1571 } else {
1572 // The AppWidgetHostView has already been inflated and instantiated
1573 launcherInfo.hostView = hostView;
1574 }
Romain Guycbb89e42009-06-08 15:52:54 -07001575
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001576 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001577 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001578 launcherInfo.notifyWidgetSizeChanged(this);
1579
Adam Cohendcd297f2013-06-18 13:13:40 -07001580 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001581 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001582
1583 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001584 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001585 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001586 }
Romain Guycbb89e42009-06-08 15:52:54 -07001587
Adam Cohended9f8d2010-11-03 13:25:16 -07001588 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1589 @Override
1590 public void onReceive(Context context, Intent intent) {
1591 final String action = intent.getAction();
1592 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1593 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001594 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001595 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001596
Winson Chungc100e8e2011-08-09 16:02:43 -07001597 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001598 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001599 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001600 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001601 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001602 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1603 mUserPresent = true;
1604 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001605 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1606 mModel.resetLoadedState(false, true);
1607 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1608 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1609 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1610 mModel.resetLoadedState(false, true);
1611 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1612 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1613 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001614 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1615 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1616 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001617 }
1618 }
1619 };
1620
1621 @Override
1622 public void onAttachedToWindow() {
1623 super.onAttachedToWindow();
1624
1625 // Listen for broadcasts related to user-presence
1626 final IntentFilter filter = new IntentFilter();
1627 filter.addAction(Intent.ACTION_SCREEN_OFF);
1628 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001629 // For handling managed profiles
1630 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1631 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001632 if (ENABLE_DEBUG_INTENTS) {
1633 filter.addAction(DebugIntents.DELETE_DATABASE);
1634 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1635 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001636 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001637 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001638 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001639 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001640 mVisible = true;
1641 }
1642
Adam Cohen0b395352014-06-09 22:54:36 +00001643 /**
1644 * Sets up transparent navigation and status bars in LMP.
1645 * This method is a no-op for other platform versions.
1646 */
1647 @TargetApi(19)
1648 private void setupTransparentSystemBarsForLmp() {
1649 // TODO(sansid): use the APIs directly when compiling against L sdk.
1650 // Currently we use reflection to access the flags and the API to set the transparency
1651 // on the System bars.
1652 if (Utilities.isLmp()) {
1653 try {
1654 getWindow().getAttributes().systemUiVisibility |=
1655 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1656 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1657 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1658 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1659 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1660 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1661 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1662 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1663
1664 Method setStatusBarColorMethod =
1665 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1666 Method setNavigationBarColorMethod =
1667 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1668 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1669 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1670 } catch (NoSuchFieldException e) {
1671 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1672 } catch (NoSuchMethodException ex) {
1673 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1674 } catch (IllegalAccessException e) {
1675 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1676 } catch (IllegalArgumentException e) {
1677 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1678 } catch (InvocationTargetException e) {
1679 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1680 } finally {}
1681 }
1682 }
1683
Adam Cohended9f8d2010-11-03 13:25:16 -07001684 @Override
1685 public void onDetachedFromWindow() {
1686 super.onDetachedFromWindow();
1687 mVisible = false;
1688
Adam Cohend113e0c2010-11-11 10:48:05 -08001689 if (mAttached) {
1690 unregisterReceiver(mReceiver);
1691 mAttached = false;
1692 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001693 updateRunning();
1694 }
1695
1696 public void onWindowVisibilityChanged(int visibility) {
1697 mVisible = visibility == View.VISIBLE;
1698 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001699 // The following code used to be in onResume, but it turns out onResume is called when
1700 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1701 // is a more appropriate event to handle
1702 if (mVisible) {
1703 mAppsCustomizeTabHost.onWindowVisible();
1704 if (!mWorkspaceLoading) {
1705 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001706 // We want to let Launcher draw itself at least once before we force it to build
1707 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001708 // apps is nice and speedy.
1709 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001710 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001711 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001712 if (mStarted) return;
1713 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001714 // We delay the layer building a bit in order to give
1715 // other message processing a time to run. In particular
1716 // this avoids a delay in hiding the IME if it was
1717 // currently shown, because doing that may involve
1718 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001719 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001720 final ViewTreeObserver.OnDrawListener listener = this;
1721 mWorkspace.post(new Runnable() {
1722 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001723 if (mWorkspace != null &&
1724 mWorkspace.getViewTreeObserver() != null) {
1725 mWorkspace.getViewTreeObserver().
1726 removeOnDrawListener(listener);
1727 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001728 }
1729 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001730 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001731 }
1732 });
1733 }
1734 clearTypedText();
1735 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001736 }
1737
1738 private void sendAdvanceMessage(long delay) {
1739 mHandler.removeMessages(ADVANCE_MSG);
1740 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1741 mHandler.sendMessageDelayed(msg, delay);
1742 mAutoAdvanceSentTime = System.currentTimeMillis();
1743 }
1744
1745 private void updateRunning() {
1746 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1747 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1748 mAutoAdvanceRunning = autoAdvanceRunning;
1749 if (autoAdvanceRunning) {
1750 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1751 sendAdvanceMessage(delay);
1752 } else {
1753 if (!mWidgetsToAdvance.isEmpty()) {
1754 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1755 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1756 }
1757 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001758 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001759 }
1760 }
1761 }
1762
1763 private final Handler mHandler = new Handler() {
1764 @Override
1765 public void handleMessage(Message msg) {
1766 if (msg.what == ADVANCE_MSG) {
1767 int i = 0;
1768 for (View key: mWidgetsToAdvance.keySet()) {
1769 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1770 final int delay = mAdvanceStagger * i;
1771 if (v instanceof Advanceable) {
1772 postDelayed(new Runnable() {
1773 public void run() {
1774 ((Advanceable) v).advance();
1775 }
1776 }, delay);
1777 }
1778 i++;
1779 }
1780 sendAdvanceMessage(mAdvanceInterval);
1781 }
1782 }
1783 };
1784
1785 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001786 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001787 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1788 if (v instanceof Advanceable) {
1789 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001790 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001791 updateRunning();
1792 }
1793 }
1794
1795 void removeWidgetToAutoAdvance(View hostView) {
1796 if (mWidgetsToAdvance.containsKey(hostView)) {
1797 mWidgetsToAdvance.remove(hostView);
1798 updateRunning();
1799 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001800 }
1801
Joe Onorato9c1289c2009-08-17 11:03:03 -04001802 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001803 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001804 launcherInfo.hostView = null;
1805 }
1806
Winson Chung93eef082012-03-23 15:59:27 -07001807 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1808 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1809 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001810 }
1811
Winson Chunga6945242014-01-08 14:04:34 -08001812 public DragLayer getDragLayer() {
1813 return mDragLayer;
1814 }
1815
1816 public Workspace getWorkspace() {
1817 return mWorkspace;
1818 }
1819
1820 public Hotseat getHotseat() {
1821 return mHotseat;
1822 }
1823
Jorim Jaggid017f882014-01-14 17:08:48 -08001824 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001825 return mOverviewPanel;
1826 }
1827
1828 public SearchDropTargetBar getSearchBar() {
1829 return mSearchDropTargetBar;
1830 }
1831
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001832 public LauncherAppWidgetHost getAppWidgetHost() {
1833 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001834 }
Romain Guycbb89e42009-06-08 15:52:54 -07001835
Winson Chunga9abd0e2010-10-27 17:18:37 -07001836 public LauncherModel getModel() {
1837 return mModel;
1838 }
1839
Winson Chunga6945242014-01-08 14:04:34 -08001840 protected SharedPreferences getSharedPrefs() {
1841 return mSharedPrefs;
1842 }
1843
Bjorn Bringertc459e522013-06-07 19:36:01 +01001844 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001845 getWindow().closeAllPanels();
1846
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001847 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001848 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001849 }
1850
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001851 @Override
1852 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001853 long startTime = 0;
1854 if (DEBUG_RESUME_TIME) {
1855 startTime = System.currentTimeMillis();
1856 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001857 super.onNewIntent(intent);
1858
1859 // Close the menu
1860 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001861 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001862 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001863
Adam Cohened307df2013-10-02 09:37:31 -07001864 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1865 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1866 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001867
Adam Cohen6fecd412013-10-02 17:41:50 -07001868 if (mWorkspace == null) {
1869 // Can be cases where mWorkspace is null, this prevents a NPE
1870 return;
1871 }
1872 Folder openFolder = mWorkspace.getOpenFolder();
1873 // In all these cases, only animate if we're already on home
1874 mWorkspace.exitWidgetResizeMode();
1875 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001876 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001877 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001878 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001879
Adam Cohen6fecd412013-10-02 17:41:50 -07001880 closeFolder();
1881 exitSpringLoadedDragMode();
1882
1883 // If we are already on home, then just animate back to the workspace,
1884 // otherwise, just wait until onResume to set the state back to Workspace
1885 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001886 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001887 } else {
1888 mOnResumeState = State.WORKSPACE;
1889 }
1890
1891 final View v = getWindow().peekDecorView();
1892 if (v != null && v.getWindowToken() != null) {
1893 InputMethodManager imm = (InputMethodManager)getSystemService(
1894 INPUT_METHOD_SERVICE);
1895 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1896 }
1897
1898 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001899 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001900 mAppsCustomizeTabHost.reset();
1901 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001902
1903 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001904 }
Adam Cohened307df2013-10-02 09:37:31 -07001905
Michael Jurka447bf842013-05-15 14:52:15 +02001906 if (DEBUG_RESUME_TIME) {
1907 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1908 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001909 }
1910
Adam Coppa120b8e2013-11-12 16:26:04 +00001911 /**
1912 * Override point for subclasses to prevent movement to the default screen when the home
1913 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1914 */
1915 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1916 return true;
1917 }
1918
1919 /**
1920 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1921 */
1922 protected void onHomeIntent() {
1923 // Do nothing
1924 }
1925
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001926 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001927 public void onRestoreInstanceState(Bundle state) {
1928 super.onRestoreInstanceState(state);
1929 for (int page: mSynchronouslyBoundPages) {
1930 mWorkspace.restoreInstanceStateForChild(page);
1931 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001932 }
1933
1934 @Override
1935 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001936 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001937 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1938 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001939 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001940 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001941
Michael Jurka883f55b2010-10-21 15:47:14 -07001942 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001943 // We close any open folder since it will not be re-opened, and we need to make sure
1944 // this state is reflected.
1945 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001946
Adam Cohendcd297f2013-06-18 13:13:40 -07001947 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001948 mWaitingForResult) {
1949 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001950 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001951 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1952 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001953 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1954 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1955 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001956 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001957 }
1958
1959 if (mFolderInfo != null && mWaitingForResult) {
1960 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1961 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1962 }
Michael Jurka946ad472010-07-09 18:05:18 -07001963
Winson Chung785d2eb2011-04-14 16:08:02 -07001964 // Save the current AppsCustomize tab
1965 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c62013-11-06 15:49:51 -08001966 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1967 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001968 if (currentTabTag != null) {
1969 outState.putString("apps_customize_currentTab", currentTabTag);
1970 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001971 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1972 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001973 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001974 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001975 }
1976
1977 @Override
1978 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001979 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001980
Winson Chunge7a03942011-08-05 15:05:12 -07001981 // Remove all pending runnables
1982 mHandler.removeMessages(ADVANCE_MSG);
1983 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001984 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001985
Winson Chungcd2b0142011-06-08 16:02:26 -07001986 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001987 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001988 mModel.stopLoader();
1989 app.setLauncher(null);
1990
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001991 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001992 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001993 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001994 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001995 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001996 mAppWidgetHost = null;
1997
1998 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001999
2000 TextKeyListener.getInstance().release();
2001
Winson Chung81b52252012-08-27 15:34:29 -07002002 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2003 // to prevent leaking Launcher activities on orientation change.
2004 if (mModel != null) {
2005 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2006 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002007
2008 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002009 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002010
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002011 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002012 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002013 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002014 mWorkspace = null;
2015 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002016
Sunny Goyale755d462014-07-22 13:48:29 -07002017 PackageInstallerCompat.getInstance(this).onStop();
Michael Jurka2ecf9952012-06-18 12:52:28 -07002018 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002019 }
2020
Adam Cohena9cf38f2011-05-02 15:36:58 -07002021 public DragController getDragController() {
2022 return mDragController;
2023 }
2024
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002025 @Override
2026 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002027 if (requestCode >= 0) {
2028 setWaitingForResult(true);
2029 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002030 super.startActivityForResult(intent, requestCode);
2031 }
2032
Winson Chung70d72102011-08-12 11:24:35 -07002033 /**
2034 * Indicates that we want global search for this activity by setting the globalSearch
2035 * argument for {@link #startSearch} to true.
2036 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002037 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002038 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002039 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002040
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002041 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002042
Karl Rosaen138a0412009-04-23 19:00:21 -07002043 if (initialQuery == null) {
2044 // Use any text typed in the launcher as the initial query
2045 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002046 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002047 if (appSearchData == null) {
2048 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002049 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002050 }
Winson Chungadf0c182012-08-23 14:59:07 -07002051 Rect sourceBounds = new Rect();
2052 if (mSearchDropTargetBar != null) {
2053 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2054 }
Romain Guycbb89e42009-06-08 15:52:54 -07002055
Ian Parkinson047036e2014-09-01 15:40:53 +01002056 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002057 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002058 if (clearTextImmediately) {
2059 clearTypedText();
2060 }
Bjorn Bringertc459e522013-06-07 19:36:01 +01002061 }
2062
Ian Parkinson047036e2014-09-01 15:40:53 +01002063 /**
2064 * Start a text search.
2065 *
2066 * @return {@code true} if the search will start immediately, so any further keypresses
2067 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2068 * to buffer keypresses.
2069 */
2070 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002071 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002072 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002073 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002074 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002075 }
2076
2077 /**
2078 * Starts the global search activity. This code is a copied from SearchManager
2079 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002080 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002081 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002082 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002083 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2084 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2085 if (globalSearchActivity == null) {
2086 Log.w(TAG, "No global search activity found.");
2087 return;
2088 }
2089 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2090 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2091 intent.setComponent(globalSearchActivity);
2092 // Make sure that we have a Bundle to put source in
2093 if (appSearchData == null) {
2094 appSearchData = new Bundle();
2095 } else {
2096 appSearchData = new Bundle(appSearchData);
2097 }
2098 // Set source to package name of app that starts global search, if not set already.
2099 if (!appSearchData.containsKey("source")) {
2100 appSearchData.putString("source", getPackageName());
2101 }
2102 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2103 if (!TextUtils.isEmpty(initialQuery)) {
2104 intent.putExtra(SearchManager.QUERY, initialQuery);
2105 }
2106 if (selectInitialQuery) {
2107 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2108 }
2109 intent.setSourceBounds(sourceBounds);
2110 try {
2111 startActivity(intent);
2112 } catch (ActivityNotFoundException ex) {
2113 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2114 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002115 }
2116
Yura4f93ec62014-02-04 14:15:21 +00002117 public boolean isOnCustomContent() {
2118 return mWorkspace.isOnOrMovingToCustomContent();
2119 }
2120
Winson Chung70d72102011-08-12 11:24:35 -07002121 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002122 public boolean onPrepareOptionsMenu(Menu menu) {
2123 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002124 if (!isOnCustomContent()) {
2125 // Close any open folders
2126 closeFolder();
2127 // Stop resizing any widgets
2128 mWorkspace.exitWidgetResizeMode();
2129 if (!mWorkspace.isInOverviewMode()) {
2130 // Show the overview mode
2131 showOverviewMode(true);
2132 } else {
2133 showWorkspace(true);
2134 }
Winson Chunge0298742014-01-17 12:03:00 -08002135 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002136 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002137 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002138
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002139 @Override
2140 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002141 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002142 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002143 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002144 }
2145
Joe Onorato9c1289c2009-08-17 11:03:03 -04002146 public boolean isWorkspaceLocked() {
2147 return mWorkspaceLoading || mWaitingForResult;
2148 }
2149
Adam Cohen517a7f52014-03-01 12:12:59 -08002150 public boolean isWorkspaceLoading() {
2151 return mWorkspaceLoading;
2152 }
2153
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002154 private void setWorkspaceLoading(boolean value) {
2155 boolean isLocked = isWorkspaceLocked();
2156 mWorkspaceLoading = value;
2157 if (isLocked != isWorkspaceLocked()) {
2158 onWorkspaceLockedChanged();
2159 }
2160 }
2161
2162 private void setWaitingForResult(boolean value) {
2163 boolean isLocked = isWorkspaceLocked();
2164 mWaitingForResult = value;
2165 if (isLocked != isWorkspaceLocked()) {
2166 onWorkspaceLockedChanged();
2167 }
2168 }
2169
2170 protected void onWorkspaceLockedChanged() { }
2171
Michael Jurka0280c3b2010-09-17 15:00:07 -07002172 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002173 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002174 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002175 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2176 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002177 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002178 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002179 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002180
Adam Cohenad4e15c2013-10-17 16:21:35 -07002181 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2182 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2183 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2184 }
2185
2186 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2187 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2188 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002189 if (appWidgetInfo.configure != null) {
2190 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002191 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002192
Bjorn Bringert7984c942009-12-09 15:38:25 +00002193 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002194 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2195 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2196
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002197 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002198 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002199 Runnable onComplete = new Runnable() {
2200 @Override
2201 public void run() {
2202 // Exit spring loaded mode if necessary after adding the widget
2203 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2204 null);
2205 }
2206 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002207 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002208 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002209 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002210 }
2211 }
Romain Guycbb89e42009-06-08 15:52:54 -07002212
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002213 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002214 // Close any folders that may be open.
2215 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002216 mWorkspace.moveToCustomContentScreen(animate);
2217 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002218 /**
2219 * Process a shortcut drop.
2220 *
2221 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002222 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002223 * @param cell The cell it should be added to, optional
2224 * @param position The location on the screen where it was dropped, optional
2225 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002226 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002227 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002228 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002229 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002230 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002231 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002232
2233 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002234 mPendingAddInfo.cellX = cell[0];
2235 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002236 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002237
2238 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2239 createShortcutIntent.setComponent(componentName);
2240 processShortcut(createShortcutIntent);
2241 }
2242
Adam Cohenfbba09b2011-07-18 21:43:05 -07002243 /**
2244 * Process a widget drop.
2245 *
2246 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002247 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002248 * @param cell The cell it should be added to, optional
2249 * @param position The location on the screen where it was dropped, optional
2250 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002251 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002252 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002253 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002254 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002255 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002256 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002257 mPendingAddInfo.minSpanX = info.minSpanX;
2258 mPendingAddInfo.minSpanY = info.minSpanY;
2259
Adam Cohenfbba09b2011-07-18 21:43:05 -07002260 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002261 mPendingAddInfo.cellX = cell[0];
2262 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002263 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002264 if (span != null) {
2265 mPendingAddInfo.spanX = span[0];
2266 mPendingAddInfo.spanY = span[1];
2267 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002268
Adam Cohened66b2b2012-01-23 17:28:51 -08002269 AppWidgetHostView hostView = info.boundWidget;
2270 int appWidgetId;
2271 if (hostView != null) {
2272 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002273 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002274 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002275 // In this case, we either need to start an activity to get permission to bind
2276 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002277 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002278 Bundle options = info.bindOptions;
2279
Sunny Goyalffe83f12014-08-14 17:39:34 -07002280 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2281 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002282 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002283 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002284 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002285 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002286 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2287 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2288 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002289 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2290 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002291 // TODO: we need to make sure that this accounts for the options bundle.
2292 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002293 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2294 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002295 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002296 }
2297
Joe Onoratodeb98af2010-02-19 14:59:39 -08002298 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002299 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002300 }
2301
Winson Chung24ab2f12010-09-16 14:10:47 -07002302 void processWallpaper(Intent intent) {
2303 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2304 }
2305
Adam Cohendcd297f2013-06-18 13:13:40 -07002306 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002307 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002308 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002309 folderInfo.title = getText(R.string.folder_name);
2310
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002311 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002312 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002313 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002314 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002315
2316 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002317 FolderIcon newFolder =
2318 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002319 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002320 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002321 // Force measure the new folder icon
2322 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2323 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002324 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002325 }
Romain Guycbb89e42009-06-08 15:52:54 -07002326
Joe Onorato9c1289c2009-08-17 11:03:03 -04002327 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002328 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002329 }
2330
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002331 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002332 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002333 }
2334
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002335 /**
2336 * Registers various content observers. The current implementation registers
2337 * only a favorites observer to keep track of the favorites applications.
2338 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002339 private void registerContentObservers() {
2340 ContentResolver resolver = getContentResolver();
2341 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2342 true, mWidgetObserver);
2343 }
2344
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002345 @Override
2346 public boolean dispatchKeyEvent(KeyEvent event) {
2347 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2348 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002349 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002350 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002351 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002352 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002353 dumpState();
2354 return true;
2355 }
2356 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002357 }
2358 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2359 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002360 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002361 return true;
2362 }
2363 }
2364
2365 return super.dispatchKeyEvent(event);
2366 }
2367
Joe Onorato88ec0992009-11-19 13:16:06 -08002368 @Override
2369 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002370 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002371 if (mAppsCustomizeContent.getContentType() ==
2372 AppsCustomizePagedView.ContentType.Applications) {
2373 showWorkspace(true);
2374 } else {
2375 showOverviewMode(true);
2376 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002377 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002378 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002379 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002380 Folder openFolder = mWorkspace.getOpenFolder();
2381 if (openFolder.isEditingName()) {
2382 openFolder.dismissEditingName();
2383 } else {
2384 closeFolder();
2385 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002386 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002387 mWorkspace.exitWidgetResizeMode();
2388
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002389 // Back button is a no-op here, but give at least some feedback for the button press
2390 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002391 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002392 }
2393
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002394 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002395 * Re-listen when widgets are reset.
2396 */
2397 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002398 if (mAppWidgetHost != null) {
2399 mAppWidgetHost.startListening();
2400 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002401 }
2402
2403 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002404 * Launches the intent referred by the clicked shortcut.
2405 *
2406 * @param v The view representing the clicked shortcut.
2407 */
2408 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002409 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2410 // view has detached (it's possible for this to happen if the view is removed mid touch).
2411 if (v.getWindowToken() == null) {
2412 return;
2413 }
2414
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002415 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002416 return;
2417 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002418
Adam Cohen1697b792013-09-17 19:08:21 -07002419 if (v instanceof Workspace) {
2420 if (mWorkspace.isInOverviewMode()) {
2421 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002422 }
2423 return;
2424 }
2425
2426 if (v instanceof CellLayout) {
2427 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002428 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002429 }
2430 }
2431
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002432 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002433 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002434 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002435 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002436 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002437 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002438 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002439 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002440 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002441 } else if (tag instanceof AppInfo) {
2442 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002443 } else if (tag instanceof LauncherAppWidgetInfo) {
2444 if (v instanceof PendingAppWidgetHostView) {
2445 onClickPendingWidget((PendingAppWidgetHostView) v);
2446 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002447 }
2448 }
2449
Sunny Goyal508da152014-08-14 10:53:27 -07002450 public void onClickPagedViewIcon(View v) {
2451 startAppShortcutOrInfoActivity(v);
2452 }
2453
Michael Jurka0e260592010-06-30 17:07:39 -07002454 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002455 return false;
2456 }
2457
Michael Jurkaaf442092010-06-10 17:01:57 -07002458 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002459 * Event handler for the app widget view which has not fully restored.
2460 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002461 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
2462 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002463 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002464 int widgetId = info.appWidgetId;
2465 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2466 if (appWidgetInfo != null) {
2467 mPendingAddWidgetInfo = appWidgetInfo;
2468 mPendingAddInfo.copyFrom(info);
2469 mPendingAddWidgetId = widgetId;
2470
Sunny Goyalffe83f12014-08-14 17:39:34 -07002471 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2472 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002473 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002474 } else if (info.installProgress < 0) {
2475 // The install has not been queued
2476 final String packageName = info.providerName.getPackageName();
2477 showBrokenAppInstallDialog(packageName,
2478 new DialogInterface.OnClickListener() {
2479 public void onClick(DialogInterface dialog, int id) {
2480 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2481 }
2482 });
2483 } else {
2484 // Download has started.
2485 final String packageName = info.providerName.getPackageName();
2486 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002487 }
2488 }
2489
2490 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002491 * Event handler for the search button
2492 *
2493 * @param v The view that was clicked.
2494 */
2495 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002496 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2497
Amith Yamasania135ba82011-08-09 17:42:01 -07002498 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002499 }
2500
2501 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002502 * Event handler for the voice button
2503 *
2504 * @param v The view that was clicked.
2505 */
2506 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002507 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002508
Bjorn Bringertc459e522013-06-07 19:36:01 +01002509 startVoice();
2510 }
2511
2512 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002513 try {
2514 final SearchManager searchManager =
2515 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2516 ComponentName activityName = searchManager.getGlobalSearchActivity();
2517 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002518 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002519 if (activityName != null) {
2520 intent.setPackage(activityName.getPackageName());
2521 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002522 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002523 } catch (ActivityNotFoundException e) {
2524 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002525 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002526 startActivitySafely(null, intent, "onClickVoiceButton");
2527 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002528 }
2529
2530 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002531 * Event handler for the "grid" button that appears on the home screen, which
2532 * enters all apps mode.
2533 *
2534 * @param v The view that was clicked.
2535 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002536 protected void onClickAllAppsButton(View v) {
2537 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2538 if (isAllAppsVisible()) {
2539 showWorkspace(true);
2540 } else {
2541 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2542 }
2543 }
2544
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002545 private void showBrokenAppInstallDialog(final String packageName,
2546 DialogInterface.OnClickListener onSearchClickListener) {
2547 new AlertDialog.Builder(this)
2548 .setTitle(R.string.abandoned_promises_title)
2549 .setMessage(R.string.abandoned_promise_explanation)
2550 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2551 .setNeutralButton(R.string.abandoned_clean_this,
2552 new DialogInterface.OnClickListener() {
2553 public void onClick(DialogInterface dialog, int id) {
2554 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2555 mWorkspace.removeAbandonedPromise(packageName, user);
2556 }
2557 })
2558 .create().show();
2559 return;
2560 }
2561
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002562 /**
2563 * Event handler for an app shortcut click.
2564 *
2565 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2566 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002567 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002568 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2569 Object tag = v.getTag();
2570 if (!(tag instanceof ShortcutInfo)) {
2571 throw new IllegalArgumentException("Input must be a Shortcut");
2572 }
2573
2574 // Open shortcut
2575 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2576 final Intent intent = shortcut.intent;
2577
2578 // Check for special shortcuts
2579 if (intent.getComponent() != null) {
2580 final String shortcutClass = intent.getComponent().getClassName();
2581
2582 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2583 MemoryDumpActivity.startDump(this);
2584 return;
2585 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2586 toggleShowWeightWatcher();
2587 return;
2588 }
2589 }
2590
Chris Wren40c5ed32014-06-24 18:24:23 -04002591 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002592 if ((v instanceof BubbleTextView)
2593 && shortcut.isPromise()
2594 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002595 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002596 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002597 new DialogInterface.OnClickListener() {
2598 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002599 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002600 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002601 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002602 return;
2603 }
2604
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002605 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002606 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002607 }
2608
Sunny Goyal508da152014-08-14 10:53:27 -07002609 private void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002610 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002611 final ShortcutInfo shortcut;
2612 final Intent intent;
2613 if (tag instanceof ShortcutInfo) {
2614 shortcut = (ShortcutInfo) tag;
2615 intent = shortcut.intent;
2616 int[] pos = new int[2];
2617 v.getLocationOnScreen(pos);
2618 intent.setSourceBounds(new Rect(pos[0], pos[1],
2619 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002620
Sunny Goyal508da152014-08-14 10:53:27 -07002621 } else if (tag instanceof AppInfo) {
2622 shortcut = null;
2623 intent = ((AppInfo) tag).intent;
2624 } else {
2625 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2626 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002627
2628 boolean success = startActivitySafely(v, intent, tag);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002629 mStats.recordLaunch(intent, shortcut);
2630
2631 if (success && v instanceof BubbleTextView) {
2632 mWaitingForResume = (BubbleTextView) v;
2633 mWaitingForResume.setStayPressed(true);
2634 }
2635 }
2636
2637 /**
2638 * Event handler for a folder icon click.
2639 *
2640 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2641 */
2642 protected void onClickFolderIcon(View v) {
2643 if (LOGD) Log.d(TAG, "onClickFolder");
2644 if (!(v instanceof FolderIcon)){
2645 throw new IllegalArgumentException("Input must be a FolderIcon");
2646 }
2647
2648 FolderIcon folderIcon = (FolderIcon) v;
2649 final FolderInfo info = folderIcon.getFolderInfo();
2650 Folder openFolder = mWorkspace.getFolderForTag(info);
2651
2652 // If the folder info reports that the associated folder is open, then verify that
2653 // it is actually opened. There have been a few instances where this gets out of sync.
2654 if (info.opened && openFolder == null) {
2655 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2656 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2657 info.opened = false;
2658 }
2659
2660 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2661 // Close any open folder
2662 closeFolder();
2663 // Open the requested folder
2664 openFolder(folderIcon);
2665 } else {
2666 // Find the open folder...
2667 int folderScreen;
2668 if (openFolder != null) {
2669 folderScreen = mWorkspace.getPageForView(openFolder);
2670 // .. and close it
2671 closeFolder(openFolder);
2672 if (folderScreen != mWorkspace.getCurrentPage()) {
2673 // Close any folder open on the current screen
2674 closeFolder();
2675 // Pull the folder onto this screen
2676 openFolder(folderIcon);
2677 }
2678 }
2679 }
Michael Jurka5130e402011-10-13 04:55:35 -07002680 }
2681
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002682 /**
2683 * Event handler for the (Add) Widgets button that appears after a long press
2684 * on the home screen.
2685 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002686 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002687 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002688 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2689 }
2690
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002691 /**
2692 * Event handler for the wallpaper picker button that appears after a long press
2693 * on the home screen.
2694 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002695 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002696 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2697 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2698 pickWallpaper.setComponent(getWallpaperPickerComponent());
2699 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2700 }
2701
2702 /**
2703 * Event handler for a click on the settings button that appears after a long press
2704 * on the home screen.
2705 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002706 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002707 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2708 }
2709
Michael Jurka5130e402011-10-13 04:55:35 -07002710 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002711 // Provide the same haptic feedback that the system offers for virtual keys.
2712 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002713 }
2714
Adam Cohen61f560d2013-09-30 15:58:20 -07002715 public void performHapticFeedbackOnTouchDown(View v) {
2716 // Provide the same haptic feedback that the system offers for virtual keys.
2717 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2718 }
2719
2720 public View.OnTouchListener getHapticFeedbackTouchListener() {
2721 if (mHapticFeedbackTouchListener == null) {
2722 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2723 @Override
2724 public boolean onTouch(View v, MotionEvent event) {
2725 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2726 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2727 }
2728 return false;
2729 }
2730 };
2731 }
2732 return mHapticFeedbackTouchListener;
2733 }
2734
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002735 public void onDragStarted(View view) {}
2736
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002737 /**
2738 * Called when the user stops interacting with the launcher.
2739 * This implies that the user is now on the homescreen and is not doing housekeeping.
2740 */
2741 protected void onInteractionEnd() {}
2742
2743 /**
2744 * Called when the user starts interacting with the launcher.
2745 * The possible interactions are:
2746 * - open all apps
2747 * - reorder an app shortcut, or a widget
2748 * - open the overview mode.
2749 * This is a good time to stop doing things that only make sense
2750 * when the user is on the homescreen and not doing housekeeping.
2751 */
2752 protected void onInteractionBegin() {}
2753
Kenny Guyf07af7b2014-07-31 11:39:16 +01002754 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002755 String packageName = componentName.getPackageName();
Kenny Guyf07af7b2014-07-31 11:39:16 +01002756 try {
2757 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2758 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2759 launcherApps.showAppDetailsForProfile(componentName, user);
2760 } catch (SecurityException e) {
2761 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2762 Log.e(TAG, "Launcher does not have permission to launch settings");
2763 } catch (ActivityNotFoundException e) {
2764 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2765 Log.e(TAG, "Unable to launch settings");
2766 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002767 }
2768
Michael Jurka1e2f4652013-07-08 18:03:46 -07002769 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002770 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2771 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002772 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002773 // System applications cannot be installed. For now, show a toast explaining that.
2774 // We may give them the option of disabling apps this way.
2775 int messageId = R.string.uninstall_system_app_text;
2776 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002777 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002778 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002779 String packageName = componentName.getPackageName();
2780 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002781 Intent intent = new Intent(
2782 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002783 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2784 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002785 if (user != null) {
2786 user.addToIntent(intent, Intent.EXTRA_USER);
2787 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002788 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002789 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002790 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002791 }
2792
Michael Jurka86a720e2012-05-09 11:23:23 -07002793 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002794 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002795 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002796 // Only launch using the new animation if the shortcut has not opted out (this is a
2797 // private contract between launcher and may be ignored in the future).
2798 boolean useLaunchAnimation = (v != null) &&
2799 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002800 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2801 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002802
Kenny Guy1317e2d2014-05-08 18:52:50 +01002803 UserHandleCompat user = null;
2804 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2805 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2806 user = userManager.getUserForSerialNumber(serialNumber);
2807 }
2808
2809 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002810 if (useLaunchAnimation) {
Adam Cohen4da294d2014-07-28 10:56:19 -07002811 ActivityOptions opts = Utilities.isLmp() ?
2812 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) :
2813 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Adam Cohen6ea3b112014-06-11 11:38:49 -07002814 optsBundle = opts.toBundle();
2815 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002816
2817 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2818 // Could be launching some bookkeeping activity
2819 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002820 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002821 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002822 launcherApps.startActivityForProfile(intent.getComponent(), user,
2823 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002824 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002825 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002826 } catch (SecurityException e) {
2827 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002828 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002829 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002830 "or use the exported attribute for this activity. "
2831 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002832 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002833 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002834 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002835
Michael Jurka86a720e2012-05-09 11:23:23 -07002836 boolean startActivitySafely(View v, Intent intent, Object tag) {
2837 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002838 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2839 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2840 return false;
2841 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002842 try {
2843 success = startActivity(v, intent, tag);
2844 } catch (ActivityNotFoundException e) {
2845 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2846 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2847 }
2848 return success;
2849 }
2850
Adam Cohen268c4752012-06-06 17:47:33 -07002851 /**
2852 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2853 * in the DragLayer in the exact absolute location of the original FolderIcon.
2854 */
2855 private void copyFolderIconToImage(FolderIcon fi) {
2856 final int width = fi.getMeasuredWidth();
2857 final int height = fi.getMeasuredHeight();
2858
2859 // Lazy load ImageView, Bitmap and Canvas
2860 if (mFolderIconImageView == null) {
2861 mFolderIconImageView = new ImageView(this);
2862 }
2863 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2864 mFolderIconBitmap.getHeight() != height) {
2865 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2866 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2867 }
2868
2869 DragLayer.LayoutParams lp;
2870 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2871 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2872 } else {
2873 lp = new DragLayer.LayoutParams(width, height);
2874 }
2875
Adam Cohen307fe232012-08-16 17:55:58 -07002876 // The layout from which the folder is being opened may be scaled, adjust the starting
2877 // view size by this scale factor.
2878 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002879 lp.customPosition = true;
2880 lp.x = mRectForFolderAnimation.left;
2881 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002882 lp.width = (int) (scale * width);
2883 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002884
2885 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2886 fi.draw(mFolderIconCanvas);
2887 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002888 if (fi.getFolder() != null) {
2889 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2890 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002891 }
Adam Cohen268c4752012-06-06 17:47:33 -07002892 // Just in case this image view is still in the drag layer from a previous animation,
2893 // we remove it and re-add it.
2894 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2895 mDragLayer.removeView(mFolderIconImageView);
2896 }
2897 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002898 if (fi.getFolder() != null) {
2899 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002900 }
Adam Cohen268c4752012-06-06 17:47:33 -07002901 }
2902
Adam Cohen2801caf2011-05-13 20:57:39 -07002903 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002904 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002905 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2906 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2907 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2908
Adam Cohenc51934b2011-07-26 21:07:43 -07002909 FolderInfo info = (FolderInfo) fi.getTag();
2910 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2911 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002912 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2913 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002914 }
2915
Adam Cohen268c4752012-06-06 17:47:33 -07002916 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2917 copyFolderIconToImage(fi);
2918 fi.setVisibility(View.INVISIBLE);
2919
Michael Jurka2ecf9952012-06-18 12:52:28 -07002920 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002921 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002922 if (Utilities.isLmp()) {
2923 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
2924 }
2925 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07002926 oa.start();
2927 }
2928
Adam Cohen268c4752012-06-06 17:47:33 -07002929 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002930 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002931 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2932 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2933 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2934
Adam Cohen268c4752012-06-06 17:47:33 -07002935 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002936
Adam Cohen268c4752012-06-06 17:47:33 -07002937 // We remove and re-draw the FolderIcon in-case it has changed
2938 mDragLayer.removeView(mFolderIconImageView);
2939 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002940 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002941 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002942 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002943 oa.addListener(new AnimatorListenerAdapter() {
2944 @Override
2945 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002946 if (cl != null) {
2947 cl.clearFolderLeaveBehind();
2948 // Remove the ImageView copy of the FolderIcon and make the original visible.
2949 mDragLayer.removeView(mFolderIconImageView);
2950 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002951 }
2952 }
2953 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002954 oa.start();
2955 }
2956
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002957 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002958 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002959 * is animated relative to the specified View. If the View is null, no animation
2960 * is played.
2961 *
2962 * @param folderInfo The FolderInfo describing the folder to open.
2963 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002964 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002965 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002966 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002967
Adam Cohena9cf38f2011-05-02 15:36:58 -07002968 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002969
Adam Cohen4554ee12011-08-03 16:13:21 -07002970 // Just verify that the folder hasn't already been added to the DragLayer.
2971 // There was a one-off crash where the folder had a parent already.
2972 if (folder.getParent() == null) {
2973 mDragLayer.addView(folder);
2974 mDragController.addDropTarget((DropTarget) folder);
2975 } else {
2976 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2977 folder.getParent() + ").");
2978 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002979 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002980 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002981
2982 // Notify the accessibility manager that this folder "window" has appeared and occluded
2983 // the workspace items
2984 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2985 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002986 }
2987
2988 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002989 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002990 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002991 if (folder.isEditingName()) {
2992 folder.dismissEditingName();
2993 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002994 closeFolder(folder);
2995 }
2996 }
2997
2998 void closeFolder(Folder folder) {
2999 folder.getInfo().opened = false;
3000
3001 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3002 if (parent != null) {
3003 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3004 shrinkAndFadeInFolderIcon(fi);
3005 }
3006 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003007
3008 // Notify the accessibility manager that this folder "window" has disappeard and no
3009 // longer occludeds the workspace items
3010 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003011 }
3012
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003013 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003014 if (!isDraggingEnabled()) return false;
3015 if (isWorkspaceLocked()) return false;
3016 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003017
Adam Cohen1697b792013-09-17 19:08:21 -07003018 if (v instanceof Workspace) {
3019 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07003020 if (mWorkspace.enterOverviewMode()) {
3021 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3022 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3023 return true;
3024 } else {
3025 return false;
3026 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003027 } else {
3028 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003029 }
Adam Cohen1697b792013-09-17 19:08:21 -07003030 }
3031
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003032 CellLayout.CellInfo longClickCellInfo = null;
3033 View itemUnderLongClick = null;
3034 if (v.getTag() instanceof ItemInfo) {
3035 ItemInfo info = (ItemInfo) v.getTag();
3036 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3037 itemUnderLongClick = longClickCellInfo.cell;
3038 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003039 }
3040
Winson Chung3d503fb2011-07-13 17:25:49 -07003041 // The hotseat touch handling does not go through Workspace, and we always allow long press
3042 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003043 final boolean inHotseat = isHotseatLayout(v);
3044 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07003045 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003046 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003047 // User long pressed on empty space
3048 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3049 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003050 if (mWorkspace.isInOverviewMode()) {
3051 mWorkspace.startReordering(v);
3052 } else {
3053 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07003054 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003055 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003056 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3057 mHotseat.getOrderInHotseat(
3058 longClickCellInfo.cellX,
3059 longClickCellInfo.cellY));
3060 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003061 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003062 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003063 }
3064 }
3065 }
3066 return true;
3067 }
3068
Winson Chung3d503fb2011-07-13 17:25:49 -07003069 boolean isHotseatLayout(View layout) {
3070 return mHotseat != null && layout != null &&
3071 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3072 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003073
Winson Chung3d503fb2011-07-13 17:25:49 -07003074 /**
3075 * Returns the CellLayout of the specified container at the specified screen.
3076 */
Adam Cohendcd297f2013-06-18 13:13:40 -07003077 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003078 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3079 if (mHotseat != null) {
3080 return mHotseat.getLayout();
3081 } else {
3082 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003083 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003084 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07003085 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003086 }
3087 }
3088
Daniel Sandler843e8602010-06-07 14:59:01 -04003089 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003090 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003091 }
3092
Craig Mautner360310b2012-10-26 15:13:08 -07003093 private void setWorkspaceBackground(boolean workspace) {
3094 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003095 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003096 }
3097
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003098 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003099 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3100 int curflags = getWindow().getAttributes().flags
3101 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3102 if (wpflags != curflags) {
3103 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3104 }
Craig Mautner360310b2012-10-26 15:13:08 -07003105 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003106 }
3107
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003108 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3109 if (v instanceof LauncherTransitionable) {
3110 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3111 }
3112 }
3113
Michael Jurkabed61d22012-02-14 22:51:29 -08003114 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3115 if (v instanceof LauncherTransitionable) {
3116 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3117 }
Winson Chung70442722012-02-10 15:43:22 -08003118
3119 // Update the workspace transition step as well
3120 dispatchOnLauncherTransitionStep(v, 0f);
3121 }
3122
3123 private void dispatchOnLauncherTransitionStep(View v, float t) {
3124 if (v instanceof LauncherTransitionable) {
3125 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3126 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003127 }
3128
3129 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3130 if (v instanceof LauncherTransitionable) {
3131 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3132 }
Winson Chung70442722012-02-10 15:43:22 -08003133
3134 // Update the workspace transition step as well
3135 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003136 }
3137
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003138 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003139 * Things to test when changing the following seven functions.
3140 * - Home from workspace
3141 * - from center screen
3142 * - from other screens
3143 * - Home from all apps
3144 * - from center screen
3145 * - from other screens
3146 * - Back from all apps
3147 * - from center screen
3148 * - from other screens
3149 * - Launch app from workspace and quit
3150 * - with back
3151 * - with home
3152 * - Launch app from all apps and quit
3153 * - with back
3154 * - with home
3155 * - Go to a screen that's not the default, then all
3156 * apps, and launch and app, and go back
3157 * - with back
3158 * -with home
3159 * - On workspace, long press power and go back
3160 * - with back
3161 * - with home
3162 * - On all apps, long press power and go back
3163 * - with back
3164 * - with home
3165 * - On workspace, power off
3166 * - On all apps, power off
3167 * - Launch an app and turn off the screen while in that app
3168 * - Go back with home key
3169 * - Go back with back key TODO: make this not go to workspace
3170 * - From all apps
3171 * - From workspace
3172 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3173 * - From all apps
3174 * - From the center workspace
3175 * - From another workspace
3176 */
3177
3178 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003179 * Zoom the camera out from the workspace to reveal 'toView'.
3180 * Assumes that the view to show is anchored at either the very top or very bottom
3181 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003182 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003183 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003184 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3185 showAppsCustomizeHelper(animated, springLoaded, contentType);
3186 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003187
Winson Chungc58497e2013-09-03 17:48:37 -07003188 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3189 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003190 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003191 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003192 mStateAnimation.cancel();
3193 mStateAnimation = null;
3194 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003195
3196 boolean material = Utilities.isLmp();
3197
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003198 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003199
Winson Chungf0ea4d32011-06-06 14:27:16 -07003200 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3201 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003202 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003203 final int itemsAlphaStagger =
3204 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003205
Winson Chungf0ea4d32011-06-06 14:27:16 -07003206 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003207 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003208 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07003209
Adam Cohen2854d252014-08-27 16:04:07 -07003210 final ArrayList<View> layerViews = new ArrayList<View>();
3211
Adam Cohen6c5891a2014-07-09 23:53:15 -07003212 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3213 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003214 Animator workspaceAnim =
Adam Cohen2854d252014-08-27 16:04:07 -07003215 mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003216 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003217 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3218 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003219 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3220 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003221
Adam Cohena38dc902014-09-07 17:48:55 +02003222 // If for some reason our views aren't initialized, don't animate
3223 boolean initialized = getAllAppsButton() != null;
3224
3225 if (animated && initialized) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003226 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen9bfdb762014-07-21 17:44:06 -07003227 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3228 toView.findViewById(R.id.apps_customize_pane_content);
Adam Cohenf16e5712011-01-13 13:31:45 -08003229
Adam Cohen9bfdb762014-07-21 17:44:06 -07003230 final View page = content.getPageAt(content.getCurrentPage());
3231 final View revealView = toView.findViewById(R.id.fake_page);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003232
Adam Cohen63f1ec02014-08-12 09:23:13 -07003233 final float initialPanelAlpha = 1f;
3234
3235 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3236 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003237 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3238 } else {
3239 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3240 }
3241
Adam Cohen9bfdb762014-07-21 17:44:06 -07003242 // Hide the real page background, and swap in the fake one
Adam Cohen9bfdb762014-07-21 17:44:06 -07003243 content.setPageBackgroundsVisible(false);
Adam Cohen2854d252014-08-27 16:04:07 -07003244 revealView.setVisibility(View.VISIBLE);
3245 // We need to hide this view as the animation start will be posted.
3246 revealView.setAlpha(0);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003247
Adam Cohen9bfdb762014-07-21 17:44:06 -07003248 int width = revealView.getMeasuredWidth();
3249 int height = revealView.getMeasuredHeight();
Adam Cohen9bfdb762014-07-21 17:44:06 -07003250 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen2854d252014-08-27 16:04:07 -07003251
Adam Cohen63f1ec02014-08-12 09:23:13 -07003252 revealView.setTranslationY(0);
Adam Cohen94afab42014-08-24 16:10:54 -07003253 revealView.setTranslationX(0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003254
Adam Cohen63f1ec02014-08-12 09:23:13 -07003255 // Get the y delta between the center of the page and the center of the all apps button
3256 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3257 getAllAppsButton(), null);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003258
Adam Cohen2854d252014-08-27 16:04:07 -07003259 float alpha = 0;
3260 float xDrift = 0;
3261 float yDrift = 0;
3262 if (material) {
3263 alpha = isWidgetTray ? 0.3f : 1f;
3264 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3265 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3266 } else {
3267 yDrift = 2 * height / 3;
3268 xDrift = 0;
3269 }
3270 final float initAlpha = alpha;
3271
Adam Cohen9bfdb762014-07-21 17:44:06 -07003272 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen2854d252014-08-27 16:04:07 -07003273 layerViews.add(revealView);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003274 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
Adam Cohen94afab42014-08-24 16:10:54 -07003275 PropertyValuesHolder panelDriftY =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003276 PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
Adam Cohen94afab42014-08-24 16:10:54 -07003277 PropertyValuesHolder panelDriftX =
3278 PropertyValuesHolder.ofFloat("translationX", xDrift, 0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003279
Adam Cohen2854d252014-08-27 16:04:07 -07003280 ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView,
3281 panelAlpha, panelDriftY, panelDriftX);
3282
Adam Cohen9bfdb762014-07-21 17:44:06 -07003283 panelAlphaAndDrift.setDuration(revealDuration);
3284 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003285
Adam Cohen9bfdb762014-07-21 17:44:06 -07003286 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003287
Adam Cohen4e243a22014-08-10 18:30:55 -07003288 if (page != null) {
3289 page.setVisibility(View.VISIBLE);
3290 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen2854d252014-08-27 16:04:07 -07003291 layerViews.add(page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003292
Adam Cohen2854d252014-08-27 16:04:07 -07003293 ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0);
3294 page.setTranslationY(yDrift);
Adam Cohen4e243a22014-08-10 18:30:55 -07003295 pageDrift.setDuration(revealDuration);
3296 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003297 pageDrift.setStartDelay(itemsAlphaStagger);
Adam Cohen4e243a22014-08-10 18:30:55 -07003298 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003299
Adam Cohen63f1ec02014-08-12 09:23:13 -07003300 page.setAlpha(0f);
Adam Cohen2854d252014-08-27 16:04:07 -07003301 ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f);
Adam Cohen4e243a22014-08-10 18:30:55 -07003302 itemsAlpha.setDuration(revealDuration);
3303 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3304 itemsAlpha.setStartDelay(itemsAlphaStagger);
3305 mStateAnimation.play(itemsAlpha);
3306 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003307
Adam Cohen4e243a22014-08-10 18:30:55 -07003308 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3309 pageIndicators.setAlpha(0.01f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003310 ObjectAnimator indicatorsAlpha =
Adam Cohen2854d252014-08-27 16:04:07 -07003311 ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003312 indicatorsAlpha.setDuration(revealDuration);
3313 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003314
Adam Cohen9bfdb762014-07-21 17:44:06 -07003315 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003316 final View allApps = getAllAppsButton();
3317 int allAppsButtonSize = LauncherAppState.getInstance().
3318 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3319 float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Adam Cohen2854d252014-08-27 16:04:07 -07003320 Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2,
Adam Cohen63f1ec02014-08-12 09:23:13 -07003321 height / 2, startRadius, revealRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003322 reveal.setDuration(revealDuration);
3323 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003324
3325 reveal.addListener(new AnimatorListenerAdapter() {
3326 public void onAnimationStart(Animator animation) {
3327 if (!isWidgetTray) {
3328 allApps.setVisibility(View.INVISIBLE);
3329 }
3330 }
3331 public void onAnimationEnd(Animator animation) {
3332 if (!isWidgetTray) {
3333 allApps.setVisibility(View.VISIBLE);
3334 }
3335 }
3336 });
Adam Cohen6c5891a2014-07-09 23:53:15 -07003337 mStateAnimation.play(reveal);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003338 }
Michael Jurka1899a362011-11-03 13:50:45 -07003339
Adam Cohen9bfdb762014-07-21 17:44:06 -07003340 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3341 @Override
3342 public void onAnimationEnd(Animator animation) {
3343 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3344 dispatchOnLauncherTransitionEnd(toView, animated, false);
3345
3346 revealView.setVisibility(View.INVISIBLE);
3347 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003348 if (page != null) {
3349 page.setLayerType(View.LAYER_TYPE_NONE, null);
3350 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003351 content.setPageBackgroundsVisible(true);
3352
3353 // Hide the search bar
3354 if (mSearchDropTargetBar != null) {
3355 mSearchDropTargetBar.hideSearchBar(false);
3356 }
3357 }
3358
Adam Cohen9bfdb762014-07-21 17:44:06 -07003359 });
3360
Adam Cohen6c5891a2014-07-09 23:53:15 -07003361 if (workspaceAnim != null) {
3362 mStateAnimation.play(workspaceAnim);
3363 }
Adam Cohen2854d252014-08-27 16:04:07 -07003364
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003365 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3366 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003367 final AnimatorSet stateAnimation = mStateAnimation;
3368 final Runnable startAnimRunnable = new Runnable() {
3369 public void run() {
3370 // Check that mStateAnimation hasn't changed while
3371 // we waited for a layout/draw pass
3372 if (mStateAnimation != stateAnimation)
3373 return;
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003374 dispatchOnLauncherTransitionStart(fromView, animated, false);
3375 dispatchOnLauncherTransitionStart(toView, animated, false);
Adam Cohen2854d252014-08-27 16:04:07 -07003376
3377 revealView.setAlpha(initAlpha);
3378 if (Utilities.isLmp()) {
3379 for (int i = 0; i < layerViews.size(); i++) {
3380 View v = layerViews.get(i);
Adam Cohenc761d3c2014-09-06 18:16:32 +02003381 if (v != null && v.isAttachedToWindow()) v.buildLayer();
Adam Cohen2854d252014-08-27 16:04:07 -07003382 }
3383 }
3384 mStateAnimation.start();
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003385 }
3386 };
Adam Cohen2854d252014-08-27 16:04:07 -07003387 toView.bringToFront();
3388 toView.setVisibility(View.VISIBLE);
3389 toView.post(startAnimRunnable);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003390 } else {
3391 toView.setTranslationX(0.0f);
3392 toView.setTranslationY(0.0f);
3393 toView.setScaleX(1.0f);
3394 toView.setScaleY(1.0f);
3395 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003396 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003397
Daniel Sandlere4f98912013-06-25 15:13:26 -04003398 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003399 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003400 if (mSearchDropTargetBar != null) {
3401 mSearchDropTargetBar.hideSearchBar(false);
3402 }
Michael Jurkaabded662011-03-04 12:06:57 -08003403 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003404 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003405 dispatchOnLauncherTransitionStart(fromView, animated, false);
3406 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003407 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003408 dispatchOnLauncherTransitionStart(toView, animated, false);
3409 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003410 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003411 }
3412
3413 /**
3414 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003415 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003416 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003417 */
Adam Cohened307df2013-10-02 09:37:31 -07003418 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003419 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003420
Michael Jurkab3e22d92011-10-31 15:58:33 -07003421 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003422 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003423 mStateAnimation.cancel();
3424 mStateAnimation = null;
3425 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003426
3427 boolean material = Utilities.isLmp();
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003428 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003429
Winson Chungf0ea4d32011-06-06 14:27:16 -07003430 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003431 final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003432 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003433 final int itemsAlphaStagger =
3434 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003435
Winson Chungf0ea4d32011-06-06 14:27:16 -07003436 final float scaleFactor = (float)
3437 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3438 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003439 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003440 Animator workspaceAnim = null;
Adam Cohen2854d252014-08-27 16:04:07 -07003441 final ArrayList<View> layerViews = new ArrayList<View>();
3442
Adam Cohened307df2013-10-02 09:37:31 -07003443 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003444 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohen2854d252014-08-27 16:04:07 -07003445 toState, animated, layerViews);
Adam Cohened307df2013-10-02 09:37:31 -07003446 } else if (toState == Workspace.State.SPRING_LOADED ||
3447 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003448 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohen2854d252014-08-27 16:04:07 -07003449 toState, animated, layerViews);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003450 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003451
Adam Cohena38dc902014-09-07 17:48:55 +02003452 // If for some reason our views aren't initialized, don't animate
3453 boolean initialized = getAllAppsButton() != null;
3454
3455 if (animated && initialized) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003456 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen2854d252014-08-27 16:04:07 -07003457 if (workspaceAnim != null) {
3458 mStateAnimation.play(workspaceAnim);
3459 }
Michael Jurka159b4cc2012-01-17 03:00:35 -08003460
Adam Cohen9bfdb762014-07-21 17:44:06 -07003461 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3462 fromView.findViewById(R.id.apps_customize_pane_content);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003463
Adam Cohen9bfdb762014-07-21 17:44:06 -07003464 final View page = content.getPageAt(content.getNextPage());
3465 final View revealView = fromView.findViewById(R.id.fake_page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003466
Adam Cohen2854d252014-08-27 16:04:07 -07003467 // hideAppsCustomizeHelper is called in some cases when it is already hidden
3468 // don't perform all these no-op animations. In particularly, this was causing
3469 // the all-apps button to pop in and out.
3470 if (fromView.getVisibility() == View.VISIBLE) {
3471 AppsCustomizePagedView.ContentType contentType = content.getContentType();
3472 final boolean isWidgetTray =
3473 contentType == AppsCustomizePagedView.ContentType.Widgets;
Adam Cohen63f1ec02014-08-12 09:23:13 -07003474
Adam Cohen2854d252014-08-27 16:04:07 -07003475 if (isWidgetTray) {
3476 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3477 } else {
3478 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003479 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003480
Adam Cohen2854d252014-08-27 16:04:07 -07003481 int width = revealView.getMeasuredWidth();
3482 int height = revealView.getMeasuredHeight();
3483 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
3484
3485 // Hide the real page background, and swap in the fake one
3486 revealView.setVisibility(View.VISIBLE);
3487 content.setPageBackgroundsVisible(false);
3488
3489 final View allAppsButton = getAllAppsButton();
3490 revealView.setTranslationY(0);
3491 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3492 allAppsButton, null);
3493
3494 float xDrift = 0;
3495 float yDrift = 0;
3496 if (material) {
3497 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3498 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3499 } else {
3500 yDrift = 5 * height / 4;
3501 xDrift = 0;
3502 }
3503
3504 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3505 TimeInterpolator decelerateInterpolator = material ?
3506 new LogDecelerateInterpolator(100, 0) :
3507 new LogDecelerateInterpolator(30, 0);
3508
3509 // The vertical motion of the apps panel should be delayed by one frame
3510 // from the conceal animation in order to give the right feel. We correpsondingly
3511 // shorten the duration so that the slide and conceal end at the same time.
3512 ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY",
3513 0, yDrift);
3514 panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3515 panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3516 panelDriftY.setInterpolator(decelerateInterpolator);
3517 mStateAnimation.play(panelDriftY);
3518
3519 ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX",
3520 0, xDrift);
3521 panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3522 panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3523 panelDriftX.setInterpolator(decelerateInterpolator);
3524 mStateAnimation.play(panelDriftX);
3525
3526 if (isWidgetTray || !material) {
3527 float finalAlpha = material ? 0.4f : 0f;
3528 revealView.setAlpha(1f);
3529 ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha",
3530 1f, finalAlpha);
3531 panelAlpha.setDuration(revealDuration);
3532 panelAlpha.setInterpolator(material ? decelerateInterpolator :
3533 new AccelerateInterpolator(1.5f));
3534 mStateAnimation.play(panelAlpha);
3535 }
3536
3537 if (page != null) {
3538 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3539
3540 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
3541 0, yDrift);
3542 page.setTranslationY(0);
3543 pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3544 pageDrift.setInterpolator(decelerateInterpolator);
3545 pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3546 mStateAnimation.play(pageDrift);
3547
3548 page.setAlpha(1f);
3549 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
3550 itemsAlpha.setDuration(100);
3551 itemsAlpha.setInterpolator(decelerateInterpolator);
3552 mStateAnimation.play(itemsAlpha);
3553 }
3554
3555 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
3556 pageIndicators.setAlpha(1f);
3557 ObjectAnimator indicatorsAlpha =
3558 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
3559 indicatorsAlpha.setDuration(revealDuration);
3560 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3561 mStateAnimation.play(indicatorsAlpha);
3562
3563 width = revealView.getMeasuredWidth();
3564
3565 if (material) {
3566 if (!isWidgetTray) {
3567 allAppsButton.setVisibility(View.INVISIBLE);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003568 }
Adam Cohen2854d252014-08-27 16:04:07 -07003569 int allAppsButtonSize = LauncherAppState.getInstance().
3570 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3571 float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
3572 Animator reveal =
3573 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3574 height / 2, revealRadius, finalRadius);
3575 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3576 reveal.setDuration(revealDuration);
3577 reveal.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003578
Adam Cohen2854d252014-08-27 16:04:07 -07003579 reveal.addListener(new AnimatorListenerAdapter() {
3580 public void onAnimationEnd(Animator animation) {
3581 revealView.setVisibility(View.INVISIBLE);
3582 if (!isWidgetTray) {
3583 allAppsButton.setVisibility(View.VISIBLE);
3584 }
3585 }
3586 });
Adam Cohen9bfdb762014-07-21 17:44:06 -07003587
Adam Cohen2854d252014-08-27 16:04:07 -07003588 mStateAnimation.play(reveal);
3589 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003590
Adam Cohen2854d252014-08-27 16:04:07 -07003591 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3592 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3593 mAppsCustomizeContent.stopScrolling();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003594 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003595
3596 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003597 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003598 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003599 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003600 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3601 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003602 if (onCompleteRunnable != null) {
3603 onCompleteRunnable.run();
3604 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003605
3606 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003607 if (page != null) {
3608 page.setLayerType(View.LAYER_TYPE_NONE, null);
3609 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003610 content.setPageBackgroundsVisible(true);
Chet Haasebc2f0822012-10-26 17:59:53 -07003611 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003612 }
3613 });
3614
Adam Cohen2854d252014-08-27 16:04:07 -07003615 final AnimatorSet stateAnimation = mStateAnimation;
3616 final Runnable startAnimRunnable = new Runnable() {
3617 public void run() {
3618 // Check that mStateAnimation hasn't changed while
3619 // we waited for a layout/draw pass
3620 if (mStateAnimation != stateAnimation)
3621 return;
3622 dispatchOnLauncherTransitionStart(fromView, animated, false);
3623 dispatchOnLauncherTransitionStart(toView, animated, false);
3624
3625 if (Utilities.isLmp()) {
3626 for (int i = 0; i < layerViews.size(); i++) {
3627 View v = layerViews.get(i);
Adam Cohencd145282014-09-06 18:32:56 +02003628 if (v != null && v.isAttachedToWindow()) v.buildLayer();
Adam Cohen2854d252014-08-27 16:04:07 -07003629 }
3630 }
3631 mStateAnimation.start();
3632 }
3633 };
3634 fromView.post(startAnimRunnable);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003635 } else {
3636 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003637 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003638 dispatchOnLauncherTransitionStart(fromView, animated, true);
3639 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003640 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003641 dispatchOnLauncherTransitionStart(toView, animated, true);
3642 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003643 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003644 }
3645
Michael Jurkae326f182011-11-21 14:05:46 -08003646 @Override
3647 public void onTrimMemory(int level) {
3648 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003649 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003650 mAppsCustomizeTabHost.onTrimMemory();
3651 }
3652 }
3653
Adam Cohened307df2013-10-02 09:37:31 -07003654 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003655 showWorkspace(animated, null);
3656 }
3657
Adam Cohened307df2013-10-02 09:37:31 -07003658 protected void showWorkspace() {
3659 showWorkspace(true);
3660 }
3661
Adam Cohened66b2b2012-01-23 17:28:51 -08003662 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohene25c5d12014-06-18 10:34:58 -07003663 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
Winson Chung2d75f122013-09-23 16:53:31 -07003664 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003665 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003666 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003667
Winson Chungc7d2b602012-05-16 17:02:20 -07003668 // Show the search bar (only animate if we were showing the drop target bar in spring
3669 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003670 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003671 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003672 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003673
Michael Jurkab3e22d92011-10-31 15:58:33 -07003674 // Set focus to the AppsCustomize button
3675 if (mAllAppsButton != null) {
3676 mAllAppsButton.requestFocus();
3677 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003678 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003679
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003680 // Change the state *after* we've called all the transition code
3681 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003682
Winson Chung5fb63472011-02-02 17:03:37 -08003683 // Resume the auto-advance of widgets
3684 mUserPresent = true;
3685 updateRunning();
3686
alanv1d4fde62012-10-17 13:15:47 -07003687 // Send an accessibility event to announce the context change
3688 getWindow().getDecorView()
3689 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003690
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003691 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003692 }
3693
Adam Cohened307df2013-10-02 09:37:31 -07003694 void showOverviewMode(boolean animated) {
3695 mWorkspace.setVisibility(View.VISIBLE);
3696 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3697 mState = State.WORKSPACE;
3698 onWorkspaceShown(animated);
3699 }
3700
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003701 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003702 }
3703
Winson Chung82963d52013-10-09 11:20:57 -07003704 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3705 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003706 if (mState != State.WORKSPACE) return;
3707
Winson Chung82963d52013-10-09 11:20:57 -07003708 if (resetPageToZero) {
3709 mAppsCustomizeTabHost.reset();
3710 }
Winson Chungc58497e2013-09-03 17:48:37 -07003711 showAppsCustomizeHelper(animated, false, contentType);
Adam Cohendcc5e712014-06-23 15:38:55 -04003712 mAppsCustomizeTabHost.post(new Runnable() {
3713 @Override
3714 public void run() {
3715 // We post this in-case the all apps view isn't yet constructed.
3716 mAppsCustomizeTabHost.requestFocus();
3717 }
3718 });
Michael Jurkab3e22d92011-10-31 15:58:33 -07003719
Michael Jurkab3e22d92011-10-31 15:58:33 -07003720 // Change the state *after* we've called all the transition code
3721 mState = State.APPS_CUSTOMIZE;
3722
3723 // Pause the auto-advance of widgets until we are out of AllApps
3724 mUserPresent = false;
3725 updateRunning();
3726 closeFolder();
3727
3728 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003729 getWindow().getDecorView()
3730 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003731 }
3732
Adam Cohen7777d962011-08-18 18:58:38 -07003733 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003734 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003735 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003736 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003737 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003738 }
Adam Cohen7777d962011-08-18 18:58:38 -07003739
Adam Cohenad4e15c2013-10-17 16:21:35 -07003740 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003741 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003742 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3743
Winson Chunge7a03942011-08-05 15:05:12 -07003744 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003745 @Override
3746 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003747 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003748 // Before we show workspace, hide all apps again because
3749 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3750 // clean up our state transition functions
3751 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003752 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003753 } else {
3754 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003755 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003756 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003757 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003758 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003759
Michael Jurkad3ef3062010-11-23 16:23:58 -08003760 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003761 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003762 final boolean animated = true;
3763 final boolean springLoaded = true;
3764 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003765 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003766 }
3767 // Otherwise, we are not in spring loaded mode, so don't do anything.
3768 }
3769
Michael Jurkab3e22d92011-10-31 15:58:33 -07003770 void lockAllApps() {
3771 // TODO
3772 }
3773
3774 void unlockAllApps() {
3775 // TODO
3776 }
3777
Winson Chungf0ea4d32011-06-06 14:27:16 -07003778 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003779 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003780 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003781 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003782 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003783 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003784 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003785 int duration = 0;
3786 if (mSearchDropTargetBar != null) {
3787 duration = mSearchDropTargetBar.getTransitionOutDuration();
3788 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003789 mHotseat.animate().alpha(0f).setDuration(duration);
3790 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003791 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003792 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003793 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003794 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003795 }
3796
Patrick Dubroy5f445422011-02-18 14:35:21 -08003797 /**
3798 * Add an item from all apps or customize onto the given workspace screen.
3799 * If layout is null, add to the current screen.
3800 */
3801 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003802 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003803 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003804 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003805 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003806
Winson Chungdff8ebb2011-09-08 17:25:31 -07003807 /** Maps the current orientation to an index for referencing orientation correct global icons */
3808 private int getCurrentOrientationIndexForGlobalIcons() {
3809 // default - 0, landscape - 1
3810 switch (getResources().getConfiguration().orientation) {
3811 case Configuration.ORIENTATION_LANDSCAPE:
3812 return 1;
3813 default:
3814 return 0;
3815 }
3816 }
3817
Michael Jurkaae65ee32012-04-30 11:45:54 -07003818 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003819 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003820 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003821 // Look for the toolbar icon specified in the activity meta-data
3822 Bundle metaData = packageManager.getActivityInfo(
3823 activityName, PackageManager.GET_META_DATA).metaData;
3824 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003825 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003826 if (iconResId != 0) {
3827 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003828 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003829 }
3830 }
3831 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003832 // This can happen if the activity defines an invalid drawable
3833 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3834 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003835 } catch (Resources.NotFoundException nfe) {
3836 // This can happen if the activity defines an invalid drawable
3837 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3838 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003839 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003840 return null;
3841 }
3842
3843 // if successful in getting icon, return it; otherwise, set button to use default drawable
3844 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003845 int buttonId, ComponentName activityName, int fallbackDrawableId,
3846 String toolbarResourceName) {
3847 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003848 Resources r = getResources();
3849 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3850 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003851
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003852 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003853 // If we were unable to find the icon via the meta-data, use a generic one
3854 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003855 toolbarIcon = r.getDrawable(fallbackDrawableId);
3856 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003857 if (button != null) {
3858 button.setCompoundDrawables(toolbarIcon, null, null, null);
3859 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003860 return null;
3861 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003862 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003863 if (button != null) {
3864 button.setCompoundDrawables(toolbarIcon, null, null, null);
3865 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003866 return toolbarIcon.getConstantState();
3867 }
3868 }
3869
3870 // if successful in getting icon, return it; otherwise, set button to use default drawable
3871 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003872 int buttonId, ComponentName activityName, int fallbackDrawableId,
3873 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003874 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003875 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003876
Michael Jurka19e0fc52011-07-22 18:00:21 -07003877 if (button != null) {
3878 // If we were unable to find the icon via the meta-data, use a
3879 // generic one
3880 if (toolbarIcon == null) {
3881 button.setImageResource(fallbackDrawableId);
3882 } else {
3883 button.setImageDrawable(toolbarIcon);
3884 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003885 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003886
3887 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3888
Michael Jurka0423dcf2010-10-05 14:56:18 -07003889 }
3890
Winson Chung1b884092012-06-08 17:13:02 -07003891 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003892 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003893 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003894 }
3895
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003896 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003897 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003898 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003899 }
3900
Winson Chungbb185bd2011-11-21 12:31:42 -08003901 private void invalidatePressedFocusedStates(View container, View button) {
3902 if (container instanceof HolographicLinearLayout) {
3903 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3904 layout.invalidatePressedFocusedStates();
3905 } else if (button instanceof HolographicImageView) {
3906 HolographicImageView view = (HolographicImageView) button;
3907 view.invalidatePressedFocusedStates();
3908 }
3909 }
3910
Cristina Stancu476493b2013-08-07 17:20:14 +01003911 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003912 if (mQsb == null) {
3913 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3914 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003915 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003916 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003917 }
3918
3919 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003920 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003921 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003922 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003923 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003924
Winson Chung1cad91e2011-05-25 17:41:01 -07003925 final SearchManager searchManager =
3926 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3927 ComponentName activityName = searchManager.getGlobalSearchActivity();
3928 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003929 int coi = getCurrentOrientationIndexForGlobalIcons();
3930 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003931 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3932 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3933 if (sGlobalSearchIcon[coi] == null) {
3934 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3935 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3936 TOOLBAR_ICON_METADATA_NAME);
3937 }
3938
Winson Chungc51db6a2011-10-05 11:44:49 -07003939 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3940 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003941 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003942 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003943 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003944 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003945 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3946 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003947 if (searchButton != null) searchButton.setVisibility(View.GONE);
3948 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003949 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003950 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003951 }
3952 }
3953
Cristina Stancu476493b2013-08-07 17:20:14 +01003954 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003955 final View searchButtonContainer = findViewById(R.id.search_button_container);
3956 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003957 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003958 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003959 }
3960
Cristina Stancu476493b2013-08-07 17:20:14 +01003961 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003962 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003963 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003964
Winson Chungc51db6a2011-10-05 11:44:49 -07003965 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07003966 final SearchManager searchManager =
3967 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3968 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
3969
3970 ComponentName activityName = null;
3971 if (globalSearchActivity != null) {
3972 // Check if the global search activity handles voice search
3973 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3974 intent.setPackage(globalSearchActivity.getPackageName());
3975 activityName = intent.resolveActivity(getPackageManager());
3976 }
3977
3978 if (activityName == null) {
3979 // Fallback: check if an activity other than the global search activity
3980 // resolves this
3981 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3982 activityName = intent.resolveActivity(getPackageManager());
3983 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003984 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003985 int coi = getCurrentOrientationIndexForGlobalIcons();
3986 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003987 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3988 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
3989 if (sVoiceSearchIcon[coi] == null) {
3990 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3991 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
3992 TOOLBAR_ICON_METADATA_NAME);
3993 }
Winson Chungc51db6a2011-10-05 11:44:49 -07003994 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07003995 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07003996 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08003997 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003998 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003999 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07004000 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04004001 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07004002 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07004003 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004004 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07004005 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07004006
Cristina Stancu476493b2013-08-07 17:20:14 +01004007 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08004008 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
4009 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08004010 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08004011 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08004012 }
4013
Winson Chung5841efa2013-09-30 18:06:44 -07004014 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01004015 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
4016 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07004017 boolean visible = !forceDisableVoiceButtonProxy &&
4018 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01004019 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07004020 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01004021 }
4022 }
Winson Chung5841efa2013-09-30 18:06:44 -07004023
4024 /**
4025 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
4026 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
4027 */
4028 public void disableVoiceButtonProxy(boolean disabled) {
4029 updateVoiceButtonProxyVisible(disabled);
4030 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08004031
Michael Jurkad7c28052012-04-27 15:43:36 -07004032 @Override
4033 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07004034 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07004035 final List<CharSequence> text = event.getText();
4036 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07004037 // Populate event with a fake title based on the current state.
4038 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07004039 text.add(mAppsCustomizeTabHost.getContentTag());
alanv1d4fde62012-10-17 13:15:47 -07004040 } else {
4041 text.add(getString(R.string.all_apps_home_button_label));
4042 }
Michael Jurkad7c28052012-04-27 15:43:36 -07004043 return result;
4044 }
4045
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004046 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07004047 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004048 */
4049 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4050 @Override
4051 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004052 closeSystemDialogs();
4053 }
4054 }
4055
4056 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08004057 * Receives notifications whenever the appwidgets are reset.
4058 */
4059 private class AppWidgetResetObserver extends ContentObserver {
4060 public AppWidgetResetObserver() {
4061 super(new Handler());
4062 }
4063
4064 @Override
4065 public void onChange(boolean selfChange) {
4066 onAppWidgetReset();
4067 }
4068 }
4069
4070 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07004071 * If the activity is currently paused, signal that we need to run the passed Runnable
4072 * in onResume.
4073 *
4074 * This needs to be called from incoming places where resources might have been loaded
4075 * while we are paused. That is becaues the Configuration might be wrong
4076 * when we're not running, and if it comes back to what it was when we
4077 * were paused, we are not restarted.
4078 *
4079 * Implementation of the method from LauncherModel.Callbacks.
4080 *
4081 * @return true if we are currently paused. The caller might be able to
4082 * skip some work in that case since we will come back again.
4083 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004084 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004085 if (mPaused) {
4086 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02004087 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07004088 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004089 }
4090 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07004091 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07004092 return true;
4093 } else {
4094 return false;
4095 }
4096 }
4097
Michael Jurkac402cd92013-05-20 15:49:32 +02004098 private boolean waitUntilResume(Runnable run) {
4099 return waitUntilResume(run, false);
4100 }
4101
Michael Jurka1e2f4652013-07-08 18:03:46 -07004102 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02004103 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07004104 }
4105
Michael Jurka7607c2f2013-04-03 14:33:19 -07004106 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004107 * If the activity is currently paused, signal that we need to re-run the loader
4108 * in onResume.
4109 *
4110 * This needs to be called from incoming places where resources might have been loaded
4111 * while we are paused. That is becaues the Configuration might be wrong
4112 * when we're not running, and if it comes back to what it was when we
4113 * were paused, we are not restarted.
4114 *
4115 * Implementation of the method from LauncherModel.Callbacks.
4116 *
4117 * @return true if we are currently paused. The caller might be able to
4118 * skip some work in that case since we will come back again.
4119 */
4120 public boolean setLoadOnResume() {
4121 if (mPaused) {
4122 Log.i(TAG, "setLoadOnResume");
4123 mOnResumeNeedsLoad = true;
4124 return true;
4125 } else {
4126 return false;
4127 }
4128 }
4129
4130 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004131 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004132 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04004133 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07004134 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07004135 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07004136 } else {
4137 return SCREEN_COUNT / 2;
4138 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004139 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07004140
Joe Onorato9c1289c2009-08-17 11:03:03 -04004141 /**
4142 * Refreshes the shortcuts shown on the workspace.
4143 *
4144 * Implementation of the method from LauncherModel.Callbacks.
4145 */
4146 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004147 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08004148
Michael Jurka7607c2f2013-04-03 14:33:19 -07004149 // If we're starting binding all over again, clear any bind calls we'd postponed in
4150 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4151 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07004152 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07004153
Winson Chungd64d1762013-08-20 14:37:16 -07004154 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07004155 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07004156 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07004157
Michael Jurka05bf644e2011-11-30 20:28:53 -08004158 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07004159 if (mHotseat != null) {
4160 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004161 }
4162 }
4163
Adam Cohendcd297f2013-06-18 13:13:40 -07004164 @Override
4165 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07004166 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07004167
Adam Cohen5084cba2013-09-03 12:01:16 -07004168 // If there are no screens, we need to have an empty screen
4169 if (orderedScreenIds.size() == 0) {
4170 mWorkspace.addExtraEmptyScreen();
4171 }
Winson Chung0e6a7132013-08-23 12:55:10 -07004172
4173 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06004174 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05004175 if (hasCustomContentToLeft()) {
4176 mWorkspace.createCustomContentContainer();
4177 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07004178 }
Winson Chung64359a52013-07-08 17:17:08 -07004179 }
4180
4181 @Override
4182 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08004183 // Log to disk
4184 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4185 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4186 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07004187 int count = orderedScreenIds.size();
4188 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07004189 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07004190 }
Adam Cohendcd297f2013-06-18 13:13:40 -07004191 }
4192
Adam Cohen39a06042013-07-19 14:30:12 -07004193 private boolean shouldShowWeightWatcher() {
4194 String spKey = LauncherAppState.getSharedPreferencesKey();
4195 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b8002013-08-15 15:44:26 -07004196 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07004197
4198 return show;
4199 }
4200
4201 private void toggleShowWeightWatcher() {
4202 String spKey = LauncherAppState.getSharedPreferencesKey();
4203 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4204 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4205
4206 show = !show;
4207
4208 SharedPreferences.Editor editor = sp.edit();
4209 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4210 editor.commit();
4211
4212 if (mWeightWatcher != null) {
4213 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4214 }
4215 }
4216
Winson Chungd64d1762013-08-20 14:37:16 -07004217 public void bindAppsAdded(final ArrayList<Long> newScreens,
4218 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07004219 final ArrayList<ItemInfo> addAnimated,
4220 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004221 Runnable r = new Runnable() {
4222 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07004223 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07004224 }
4225 };
4226 if (waitUntilResume(r)) {
4227 return;
4228 }
4229
Winson Chungd64d1762013-08-20 14:37:16 -07004230 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08004231 if (newScreens != null) {
4232 bindAddScreens(newScreens);
4233 }
Winson Chungd64d1762013-08-20 14:37:16 -07004234
4235 // We add the items without animation on non-visible pages, and with
4236 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08004237 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004238 bindItems(addNotAnimated, 0,
4239 addNotAnimated.size(), false);
4240 }
Adam Cohen76a47a12014-02-05 11:47:43 -08004241 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004242 bindItems(addAnimated, 0,
4243 addAnimated.size(), true);
4244 }
Winson Chungc58497e2013-09-03 17:48:37 -07004245
Winson Chung87412982013-10-03 18:34:14 -07004246 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004247 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004248
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004249 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004250 addedApps != null && mAppsCustomizeContent != null) {
4251 mAppsCustomizeContent.addApps(addedApps);
4252 }
Winson Chungd64d1762013-08-20 14:37:16 -07004253 }
4254
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004255 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004256 * Bind the items start-end from the list.
4257 *
4258 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004259 */
Winson Chung64359a52013-07-08 17:17:08 -07004260 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4261 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004262 Runnable r = new Runnable() {
4263 public void run() {
4264 bindItems(shortcuts, start, end, forceAnimateIcons);
4265 }
4266 };
4267 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004268 return;
4269 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004270
Winson Chungf0c6ae02012-03-21 16:10:31 -07004271 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004272 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4273 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004274 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004275 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004276 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004277 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004278 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004279
4280 // Short circuit if we are loading dock items for a configuration which has no dock
4281 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4282 mHotseat == null) {
4283 continue;
4284 }
4285
Joe Onorato9c1289c2009-08-17 11:03:03 -04004286 switch (item.itemType) {
4287 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4288 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004289 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004290 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004291
Winson Chung64359a52013-07-08 17:17:08 -07004292 /*
4293 * TODO: FIX collision case
4294 */
Winson Chungce376632013-07-11 16:12:41 -07004295 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4296 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4297 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004298 View v = cl.getChildAt(item.cellX, item.cellY);
4299 Object tag = v.getTag();
4300 String desc = "Collision while binding workspace item: " + item
4301 + ". Collides with " + tag;
4302 if (LauncherAppState.isDogfoodBuild()) {
4303 throw (new RuntimeException(desc));
4304 } else {
4305 Log.d(TAG, desc);
4306 }
Winson Chungce376632013-07-11 16:12:41 -07004307 }
Winson Chung64359a52013-07-08 17:17:08 -07004308 }
4309
Adam Cohendcd297f2013-06-18 13:13:40 -07004310 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4311 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004312 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004313 // Animate all the applications up now
4314 shortcut.setAlpha(0f);
4315 shortcut.setScaleX(0f);
4316 shortcut.setScaleY(0f);
4317 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004318 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004319 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004320 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004321 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004322 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004323 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004324 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004325 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4326 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004327 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004328 default:
4329 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004330 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004331 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004332
Winson Chung997a9232013-07-24 15:33:46 -07004333 if (animateIcons) {
4334 // Animate to the correct page
4335 if (newShortcutsScreenId > -1) {
4336 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004337 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004338 final Runnable startBounceAnimRunnable = new Runnable() {
4339 public void run() {
4340 anim.playTogether(bounceAnims);
4341 anim.start();
4342 }
4343 };
Winson Chung997a9232013-07-24 15:33:46 -07004344 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004345 // We post the animation slightly delayed to prevent slowdowns
4346 // when we are loading right after we return to launcher.
4347 mWorkspace.postDelayed(new Runnable() {
4348 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004349 if (mWorkspace != null) {
4350 mWorkspace.snapToPage(newScreenIndex);
4351 mWorkspace.postDelayed(startBounceAnimRunnable,
4352 NEW_APPS_ANIMATION_DELAY);
4353 }
Winson Chung94d67682013-09-25 16:29:40 -07004354 }
4355 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004356 } else {
4357 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004358 }
4359 }
Winson Chung64359a52013-07-08 17:17:08 -07004360 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004361 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004362 }
4363
Joe Onorato9c1289c2009-08-17 11:03:03 -04004364 /**
4365 * Implementation of the method from LauncherModel.Callbacks.
4366 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004367 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004368 Runnable r = new Runnable() {
4369 public void run() {
4370 bindFolders(folders);
4371 }
4372 };
4373 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004374 return;
4375 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004376 sFolders.clear();
4377 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004378 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004379
4380 /**
4381 * Add the views for a widget to the workspace.
4382 *
4383 * Implementation of the method from LauncherModel.Callbacks.
4384 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004385 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004386 Runnable r = new Runnable() {
4387 public void run() {
4388 bindAppWidget(item);
4389 }
4390 };
4391 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004392 return;
4393 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004394
Daniel Sandler843e8602010-06-07 14:59:01 -04004395 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4396 if (DEBUG_WIDGETS) {
4397 Log.d(TAG, "bindAppWidget: " + item);
4398 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004399 final Workspace workspace = mWorkspace;
4400
Sunny Goyalff572272014-07-23 13:58:07 -07004401 AppWidgetProviderInfo appWidgetInfo;
4402 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4403 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4404
4405 appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
4406 if (appWidgetInfo == null) {
4407 if (DEBUG_WIDGETS) {
4408 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4409 + " belongs to component " + item.providerName
4410 + ", as the povider is null");
4411 }
4412 LauncherModel.deleteItemFromDatabase(this, item);
4413 return;
4414 }
4415 // Note: This assumes that the id remap broadcast is received before this step.
4416 // If that is not the case, the id remap will be ignored and user may see the
4417 // click to setup view.
4418 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4419 pendingInfo.spanX = item.spanX;
4420 pendingInfo.spanY = item.spanY;
4421 pendingInfo.minSpanX = item.minSpanX;
4422 pendingInfo.minSpanY = item.minSpanY;
4423 Bundle options =
4424 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4425
Sunny Goyalff572272014-07-23 13:58:07 -07004426 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
Sunny Goyalffe83f12014-08-14 17:39:34 -07004427 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4428 newWidgetId, appWidgetInfo, options);
Sunny Goyalff572272014-07-23 13:58:07 -07004429
4430 // TODO consider showing a permission dialog when the widget is clicked.
4431 if (!success) {
4432 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4433 if (DEBUG_WIDGETS) {
4434 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4435 + " belongs to component " + item.providerName
4436 + ", as the launcher is unable to bing a new widget id");
4437 }
4438 LauncherModel.deleteItemFromDatabase(this, item);
4439 return;
4440 }
4441
4442 item.appWidgetId = newWidgetId;
4443
4444 // If the widget has a configure activity, it is still needs to set it up, otherwise
4445 // the widget is ready to go.
4446 item.restoreStatus = (appWidgetInfo.configure == null)
4447 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4448 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4449
4450 LauncherModel.updateItemInDatabase(this, item);
4451 }
4452
Sunny Goyal651077b2014-06-30 14:15:31 -07004453 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4454 final int appWidgetId = item.appWidgetId;
4455 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4456 if (DEBUG_WIDGETS) {
4457 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4458 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004459
Sunny Goyal651077b2014-06-30 14:15:31 -07004460 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4461 } else {
4462 appWidgetInfo = null;
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004463 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item);
4464 view.updateIcon(mIconCache);
4465 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004466 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004467 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004468 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004469
Joe Onorato9c1289c2009-08-17 11:03:03 -04004470 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004471 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004472
Adam Cohendcd297f2013-06-18 13:13:40 -07004473 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004474 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004475 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4476
Joe Onorato9c1289c2009-08-17 11:03:03 -04004477 workspace.requestLayout();
4478
Daniel Sandler843e8602010-06-07 14:59:01 -04004479 if (DEBUG_WIDGETS) {
4480 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4481 + (SystemClock.uptimeMillis()-start) + "ms");
4482 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004483 }
4484
Sunny Goyalff572272014-07-23 13:58:07 -07004485 /**
4486 * Restores a pending widget.
4487 *
4488 * @param appWidgetId The app widget id
4489 * @param cellInfo The position on screen where to create the widget.
4490 */
4491 private void completeRestoreAppWidget(final int appWidgetId) {
4492 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4493 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4494 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4495 return;
4496 }
4497
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004498 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004499 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4500
4501 mWorkspace.reinflateWidgetsIfNecessary();
4502 LauncherModel.updateItemInDatabase(this, info);
4503 }
4504
Adam Cohen1462de32012-07-24 22:34:36 -07004505 public void onPageBoundSynchronously(int page) {
4506 mSynchronouslyBoundPages.add(page);
4507 }
4508
Joe Onorato9c1289c2009-08-17 11:03:03 -04004509 /**
4510 * Callback saying that there aren't any more items to bind.
4511 *
4512 * Implementation of the method from LauncherModel.Callbacks.
4513 */
Adam Cohene25af792013-06-06 23:08:25 -07004514 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004515 Runnable r = new Runnable() {
4516 public void run() {
4517 finishBindingItems(upgradePath);
4518 }
4519 };
4520 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004521 return;
4522 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004523 if (mSavedState != null) {
4524 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004525 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004526 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004527 mSavedState = null;
4528 }
4529
Adam Cohen1462de32012-07-24 22:34:36 -07004530 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004531
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004532 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004533 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004534
4535 // If we received the result of any pending adds while the loader was running (e.g. the
4536 // widget configuration forced an orientation change), process them now.
4537 if (sPendingAddItem != null) {
4538 final long screenId = completeAdd(sPendingAddItem);
4539
4540 // TODO: this moves the user to the page where the pending item was added. Ideally,
4541 // the screen would be guaranteed to exist after bind, and the page would be set through
4542 // the workspace restore process.
4543 mWorkspace.post(new Runnable() {
4544 @Override
4545 public void run() {
4546 mWorkspace.snapToScreenId(screenId);
4547 }
4548 });
4549 sPendingAddItem = null;
4550 }
4551
Adam Cohene25af792013-06-06 23:08:25 -07004552 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004553 mWorkspace.getUniqueComponents(true, null);
4554 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004555 }
Sunny Goyale755d462014-07-22 13:48:29 -07004556 PackageInstallerCompat.getInstance(this).onFinishBind();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004557 }
4558
Adam Cohen3ed316a2014-07-23 18:21:20 -07004559 private void sendLoadingCompleteBroadcastIfNecessary() {
4560 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4561 String permission =
4562 getResources().getString(R.string.receive_first_load_broadcast_permission);
4563 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4564 sendBroadcast(intent, permission);
4565 SharedPreferences.Editor editor = mSharedPrefs.edit();
4566 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4567 editor.apply();
4568 }
4569 }
4570
Winson Chunga0b7e862013-09-05 16:03:15 -07004571 public boolean isAllAppsButtonRank(int rank) {
4572 if (mHotseat != null) {
4573 return mHotseat.isAllAppsButtonRank(rank);
4574 }
4575 return false;
4576 }
4577
Winson Chunga2413752012-04-03 14:22:34 -07004578 private boolean canRunNewAppsAnimation() {
4579 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4580 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4581 }
4582
Winson Chungc9168342013-06-26 14:54:55 -07004583 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4584 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4585 PropertyValuesHolder.ofFloat("alpha", 1f),
4586 PropertyValuesHolder.ofFloat("scaleX", 1f),
4587 PropertyValuesHolder.ofFloat("scaleY", 1f));
4588 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4589 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4590 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4591 return bounceAnim;
4592 }
4593
Adam Cohen27772732013-11-11 14:00:56 +00004594 public boolean useVerticalBarLayout() {
4595 return LauncherAppState.getInstance().getDynamicGrid().
4596 getDeviceProfile().isVerticalBarLayout();
4597 }
4598
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004599 protected Rect getSearchBarBounds() {
4600 return LauncherAppState.getInstance().getDynamicGrid().
4601 getDeviceProfile().getSearchBarBounds();
4602 }
4603
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004604 @Override
4605 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004606 boolean searchVisible = updateGlobalSearchIcon();
4607 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004608 if (mSearchDropTargetBar != null) {
4609 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4610 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004611 }
4612
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004613 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004614 * Add the icons for all apps.
4615 *
4616 * Implementation of the method from LauncherModel.Callbacks.
4617 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004618 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004619 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004620 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4621 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4622 getHotseat().addAllAppsFolder(mIconCache, apps,
4623 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4624 }
4625 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004626 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004627 if (mAppsCustomizeContent != null) {
4628 mAppsCustomizeContent.onPackagesUpdated(
4629 LauncherModel.getSortedWidgetsAndShortcuts(this));
4630 }
Winson Chungc58497e2013-09-03 17:48:37 -07004631 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004632 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004633 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004634 mAppsCustomizeContent.onPackagesUpdated(
4635 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004636 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004637 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004638 }
4639
4640 /**
4641 * A package was updated.
4642 *
4643 * Implementation of the method from LauncherModel.Callbacks.
4644 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004645 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004646 Runnable r = new Runnable() {
4647 public void run() {
4648 bindAppsUpdated(apps);
4649 }
4650 };
4651 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004652 return;
4653 }
4654
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004655 if (mWorkspace != null) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004656 mWorkspace.updateShortcutsAndWidgets(apps);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004657 }
Winson Chungc58497e2013-09-03 17:48:37 -07004658
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004659 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004660 mAppsCustomizeContent != null) {
4661 mAppsCustomizeContent.updateApps(apps);
4662 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004663 }
4664
4665 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004666 * Update the state of a package, typically related to install state.
4667 *
4668 * Implementation of the method from LauncherModel.Callbacks.
4669 */
Sunny Goyale755d462014-07-22 13:48:29 -07004670 @Override
4671 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004672 if (mWorkspace != null) {
Sunny Goyale755d462014-07-22 13:48:29 -07004673 mWorkspace.updatePackageState(installInfo);
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004674 }
4675 }
4676
4677 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004678 * A package was uninstalled. We take both the super set of packageNames
4679 * in addition to specific applications to remove, the reason being that
4680 * this can be called when a package is updated as well. In that scenario,
4681 * we only remove specific components from the workspace, where as
4682 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004683 *
4684 * Implementation of the method from LauncherModel.Callbacks.
4685 */
Winson Chung83892cc2013-05-01 16:53:33 -07004686 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004687 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004688 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004689 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004690 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004691 }
Winson Chungd64d1762013-08-20 14:37:16 -07004692 };
4693 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004694 return;
4695 }
4696
Winson Chungdf95eb12013-10-16 14:57:07 -07004697 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004698 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004699 }
4700 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004701 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004702 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004703
Winson Chunga1820962011-10-03 16:31:06 -07004704 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004705 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004706
Winson Chungdf95eb12013-10-16 14:57:07 -07004707 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004708 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004709 mAppsCustomizeContent != null) {
4710 mAppsCustomizeContent.removeApps(appInfos);
4711 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004712 }
Joe Onoratobe386092009-11-17 17:32:16 -08004713
4714 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004715 * A number of packages were updated.
4716 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004717 private ArrayList<Object> mWidgetsAndShortcuts;
4718 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004719 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004720 bindPackagesUpdated(mWidgetsAndShortcuts);
4721 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004722 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004723 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004724 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4725 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4726 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004727 return;
4728 }
4729
Winson Chung64359a52013-07-08 17:17:08 -07004730 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004731 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004732 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004733 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004734 }
4735
Winson Chung400438b2011-01-16 17:53:48 -08004736 private int mapConfigurationOriActivityInfoOri(int configOri) {
4737 final Display d = getWindowManager().getDefaultDisplay();
4738 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4739 switch (d.getRotation()) {
4740 case Surface.ROTATION_0:
4741 case Surface.ROTATION_180:
4742 // We are currently in the same basic orientation as the natural orientation
4743 naturalOri = configOri;
4744 break;
4745 case Surface.ROTATION_90:
4746 case Surface.ROTATION_270:
4747 // We are currently in the other basic orientation to the natural orientation
4748 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4749 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4750 break;
4751 }
4752
4753 int[] oriMap = {
4754 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4755 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4756 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4757 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4758 };
4759 // Since the map starts at portrait, we need to offset if this device's natural orientation
4760 // is landscape.
4761 int indexOffset = 0;
4762 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4763 indexOffset = 1;
4764 }
4765 return oriMap[(d.getRotation() + indexOffset) % 4];
4766 }
Adam Cohen446e9402011-09-15 18:21:21 -07004767
Winson Chung4b919f82012-05-01 10:44:08 -07004768 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004769 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004770 getResources().getBoolean(R.bool.allow_rotation);
4771 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004772 }
Winson Chung4b919f82012-05-01 10:44:08 -07004773 public void lockScreenOrientation() {
4774 if (isRotationEnabled()) {
4775 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4776 .getConfiguration().orientation));
4777 }
4778 }
4779 public void unlockScreenOrientation(boolean immediate) {
4780 if (isRotationEnabled()) {
4781 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004782 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004783 } else {
4784 mHandler.postDelayed(new Runnable() {
4785 public void run() {
4786 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4787 }
4788 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004789 }
Winson Chung4b919f82012-05-01 10:44:08 -07004790 }
Winson Chung400438b2011-01-16 17:53:48 -08004791 }
4792
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004793 /**
4794 * Called when the SearchBar hint should be changed.
4795 *
4796 * @param hint the hint to be displayed in the search bar.
4797 */
4798 protected void onSearchBarHintChanged(String hint) {
Sunny Goyal424418b2014-08-22 16:09:37 -07004799
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004800 }
4801
Winson Chunge43a1e72014-01-15 10:33:02 -08004802 protected boolean isLauncherPreinstalled() {
4803 PackageManager pm = getPackageManager();
4804 try {
4805 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4806 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4807 return true;
4808 } else {
4809 return false;
4810 }
4811 } catch (NameNotFoundException e) {
4812 e.printStackTrace();
4813 return false;
4814 }
4815 }
4816
Adam Cohenea90f832014-05-21 15:03:34 -07004817 /**
4818 * This method indicates whether or not we should suggest default wallpaper dimensions
4819 * when our wallpaper cropper was not yet used to set a wallpaper.
4820 */
4821 protected boolean overrideWallpaperDimensions() {
4822 return true;
4823 }
4824
Adam Cohen5eed5d82014-05-19 13:12:13 -07004825 protected boolean shouldClingFocusHotseatApp() {
4826 return false;
4827 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004828 protected String getFirstRunClingSearchBarHint() {
4829 return "";
4830 }
4831 protected String getFirstRunCustomContentHint() {
4832 return "";
4833 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004834 protected int getFirstRunFocusedHotseatAppDrawableId() {
4835 return -1;
4836 }
4837 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4838 return null;
4839 }
4840 protected int getFirstRunFocusedHotseatAppRank() {
4841 return -1;
4842 }
4843 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4844 return "";
4845 }
4846 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4847 return "";
4848 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004849
Adam Cohen432609a2014-03-13 17:03:22 -07004850 /**
4851 * To be overridden by subclasses to indicate that there is an activity to launch
4852 * before showing the standard launcher experience.
4853 */
4854 protected boolean hasFirstRunActivity() {
4855 return false;
4856 }
4857
4858 /**
4859 * To be overridden by subclasses to launch any first run activity
4860 */
4861 protected Intent getFirstRunActivity() {
4862 return null;
4863 }
4864
Winson Chunga6945242014-01-08 14:04:34 -08004865 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004866 return !ActivityManager.isRunningInTestHarness() &&
4867 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004868 }
4869
Adam Cohen4a9423d2014-03-28 14:22:31 -07004870 protected boolean hasRunFirstRunActivity() {
4871 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4872 }
4873
Adam Cohen432609a2014-03-13 17:03:22 -07004874 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004875 if (shouldRunFirstRunActivity() &&
4876 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004877 Intent firstRunIntent = getFirstRunActivity();
4878 if (firstRunIntent != null) {
4879 startActivity(firstRunIntent);
4880 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004881 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004882 }
4883 }
Adam Cohen432609a2014-03-13 17:03:22 -07004884 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004885 }
4886
4887 private void markFirstRunActivityShown() {
4888 SharedPreferences.Editor editor = mSharedPrefs.edit();
4889 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4890 editor.apply();
4891 }
4892
Adam Cohen432609a2014-03-13 17:03:22 -07004893 /**
4894 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4895 * screen that must be displayed and dismissed.
4896 */
4897 protected boolean hasDismissableIntroScreen() {
4898 return false;
4899 }
4900
4901 /**
4902 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4903 */
4904 protected View getIntroScreen() {
4905 return null;
4906 }
4907
4908 /**
4909 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4910 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4911 */
4912 private boolean shouldShowIntroScreen() {
4913 return hasDismissableIntroScreen() &&
4914 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4915 }
4916
4917 protected void showIntroScreen() {
4918 View introScreen = getIntroScreen();
4919 changeWallpaperVisiblity(false);
4920 if (introScreen != null) {
4921 mDragLayer.showOverlayView(introScreen);
4922 }
4923 }
4924
4925 public void dismissIntroScreen() {
4926 markIntroScreenDismissed();
4927 if (showFirstRunActivity()) {
4928 // We delay hiding the intro view until the first run activity is showing. This
4929 // avoids a blip.
4930 mWorkspace.postDelayed(new Runnable() {
4931 @Override
4932 public void run() {
4933 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004934 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004935 }
4936 }, ACTIVITY_START_DELAY);
4937 } else {
4938 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004939 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004940 }
4941 changeWallpaperVisiblity(true);
4942 }
4943
4944 private void markIntroScreenDismissed() {
4945 SharedPreferences.Editor editor = mSharedPrefs.edit();
4946 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4947 editor.apply();
4948 }
4949
Sunny Goyal88d60f12014-09-08 03:47:29 -07004950 private void showFirstRunClings() {
4951 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4952 // on the device, then we always show the first run cling experience (or if there is no
4953 // launcher2). Otherwise, we prompt the user upon started for migration
4954 LauncherClings launcherClings = new LauncherClings(this);
4955 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
4956 if (mModel.canMigrateFromOldLauncherDb(this)) {
4957 launcherClings.showMigrationCling();
4958 } else {
4959 launcherClings.showLongPressCling(false);
4960 }
4961 }
4962 }
4963
Winson Chunga6945242014-01-08 14:04:34 -08004964 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004965 if (mWorkspace != null) mWorkspace.setAlpha(1f);
4966 if (mHotseat != null) mHotseat.setAlpha(1f);
4967 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
4968 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004969 }
4970
4971 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08004972 if (mWorkspace != null) mWorkspace.setAlpha(0f);
4973 if (mHotseat != null) mHotseat.setAlpha(0f);
4974 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
4975 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08004976 }
4977
Mathew Inwood72fbec12013-11-19 15:45:07 +00004978 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01004979 // Called from search suggestion, not supported in other profiles.
4980 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
4981 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
4982 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
4983 myUser);
4984 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00004985 return null;
4986 }
Kenny Guyed131872014-04-30 03:02:21 +01004987 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00004988 }
4989
4990 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4991 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01004992 // Called from search suggestion, not supported in other profiles.
4993 return createShortcutDragInfo(shortcutIntent, caption, icon,
4994 UserHandleCompat.myUserHandle());
4995 }
4996
4997 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
4998 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01004999 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01005000 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01005001 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005002 }
5003
Mathew Inwoodb90860a2014-04-11 17:17:39 +01005004 protected void moveWorkspaceToDefaultScreen() {
5005 mWorkspace.moveToDefaultScreen(false);
5006 }
5007
Mathew Inwood72fbec12013-11-19 15:45:07 +00005008 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
5009 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07005010 mWorkspace.onExternalDragStartedWithItem(dragView);
5011 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005012 }
5013
Anjali Koppalf5d29132014-02-28 13:33:27 -08005014 @Override
5015 public void onPageSwitch(View newPage, int newPageIndex) {
5016 }
5017
Winson Chung80baf5a2010-08-09 16:03:15 -07005018 /**
Joe Onoratobe386092009-11-17 17:32:16 -08005019 * Prints out out state for debugging.
5020 */
5021 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04005022 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08005023 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08005024 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
5025 Log.d(TAG, "mRestoring=" + mRestoring);
5026 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
5027 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07005028 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08005029 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07005030
Winson Chung785d2eb2011-04-14 16:08:02 -07005031 if (mAppsCustomizeContent != null) {
5032 mAppsCustomizeContent.dumpState();
5033 }
Daniel Sandler325dc232013-06-05 22:57:57 -04005034 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08005035 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005036
5037 @Override
5038 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5039 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07005040 synchronized (sDumpLogs) {
5041 writer.println(" ");
5042 writer.println("Debug logs: ");
5043 for (int i = 0; i < sDumpLogs.size(); i++) {
5044 writer.println(" " + sDumpLogs.get(i));
5045 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005046 }
5047 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005048
5049 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07005050 if (DEBUG_DUMP_LOG) {
5051 synchronized (sDumpLogs) {
5052 Log.d(TAG, "");
5053 Log.d(TAG, "*********************");
5054 Log.d(TAG, "Launcher debug logs: ");
5055 for (int i = 0; i < sDumpLogs.size(); i++) {
5056 Log.d(TAG, " " + sDumpLogs.get(i));
5057 }
5058 Log.d(TAG, "*********************");
5059 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07005060 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005061 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005062 }
5063
5064 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005065 addDumpLog(tag, log, null, debugLog);
5066 }
5067
5068 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07005069 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005070 if (e != null) {
5071 Log.d(tag, log, e);
5072 } else {
5073 Log.d(tag, log);
5074 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005075 }
Winson Chungede41292013-09-19 16:27:36 -07005076 if (DEBUG_DUMP_LOG) {
5077 sDateStamp.setTime(System.currentTimeMillis());
5078 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05005079 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5080 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07005081 }
Winson Chungede41292013-09-19 16:27:36 -07005082 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005083 }
5084
Winson Chungede41292013-09-19 16:27:36 -07005085 public void dumpLogsToLocalData() {
5086 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01005087 new AsyncTask<Void, Void, Void>() {
5088 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07005089 boolean success = false;
5090 sDateStamp.setTime(sRunStart);
5091 String FILENAME = sDateStamp.getMonth() + "-"
5092 + sDateStamp.getDay() + "_"
5093 + sDateStamp.getHours() + "-"
5094 + sDateStamp.getMinutes() + "_"
5095 + sDateStamp.getSeconds() + ".txt";
5096
5097 FileOutputStream fos = null;
5098 File outFile = null;
5099 try {
5100 outFile = new File(getFilesDir(), FILENAME);
5101 outFile.createNewFile();
5102 fos = new FileOutputStream(outFile);
5103 } catch (Exception e) {
5104 e.printStackTrace();
5105 }
5106 if (fos != null) {
5107 PrintWriter writer = new PrintWriter(fos);
5108
5109 writer.println(" ");
5110 writer.println("Debug logs: ");
5111 synchronized (sDumpLogs) {
5112 for (int i = 0; i < sDumpLogs.size(); i++) {
5113 writer.println(" " + sDumpLogs.get(i));
5114 }
5115 }
5116 writer.close();
5117 }
5118 try {
5119 if (fos != null) {
5120 fos.close();
5121 success = true;
5122 }
5123 } catch (IOException e) {
5124 e.printStackTrace();
5125 }
Michael Jurka43467462013-11-14 12:03:58 +01005126 return null;
Winson Chungede41292013-09-19 16:27:36 -07005127 }
Michael Jurka43467462013-11-14 12:03:58 +01005128 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07005129 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005130 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08005131}
Michael Jurka2763be32011-02-24 11:19:57 -08005132
Michael Jurkaabded662011-03-04 12:06:57 -08005133interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08005134 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07005135 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08005136 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08005137 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08005138 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08005139}
Dan Sandlerd5024042014-01-09 15:01:33 -05005140
5141interface DebugIntents {
5142 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5143 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00005144}