blob: da1afaa140671a74b6f5e2909518cbc00bc99b86 [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;
Adam Cohen0f668f32014-09-08 19:54:17 +020062import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080063import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020064import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080065import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070066import android.os.Message;
Winson Chunga2413752012-04-03 14:22:34 -070067import android.os.StrictMode;
Daniel Sandler843e8602010-06-07 14:59:01 -040068import android.os.SystemClock;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080069import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.text.Selection;
71import android.text.SpannableStringBuilder;
Michael Jurkaa33411c2012-06-14 16:18:21 -070072import android.text.TextUtils;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073import android.text.method.TextKeyListener;
Winson Chung892c74d2013-08-22 16:15:50 -070074import android.util.DisplayMetrics;
Joe Onorato7c312c12009-08-13 21:36:53 -070075import android.util.Log;
Adam Cohen96d30a12013-07-16 18:13:21 -070076import android.view.Display;
77import android.view.Gravity;
78import android.view.HapticFeedbackConstants;
79import android.view.KeyEvent;
80import android.view.LayoutInflater;
81import android.view.Menu;
Adam Cohen96d30a12013-07-16 18:13:21 -070082import android.view.MotionEvent;
83import android.view.Surface;
84import android.view.View;
Adam Cohenf358a4b2013-07-23 16:47:31 -070085import android.view.View.OnClickListener;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080086import android.view.View.OnLongClickListener;
Adam Cohen2854d252014-08-27 16:04:07 -070087import android.view.ViewAnimationUtils;
Adam Cohen96d30a12013-07-16 18:13:21 -070088import android.view.ViewGroup;
89import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080090import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Sunny Goyal651077b2014-06-30 14:15:31 -070091import android.view.Window;
Adam Cohen96d30a12013-07-16 18:13:21 -070092import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080093import android.view.accessibility.AccessibilityEvent;
Adam Cohen9bfdb762014-07-21 17:44:06 -070094import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080095import android.view.animation.DecelerateInterpolator;
Adam Cohen2854d252014-08-27 16:04:07 -070096import android.view.animation.Interpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097import android.view.inputmethod.InputMethodManager;
Adam Cohen96d30a12013-07-16 18:13:21 -070098import android.widget.Advanceable;
99import android.widget.FrameLayout;
100import android.widget.ImageView;
101import android.widget.TextView;
102import android.widget.Toast;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700103
Sunny Goyal651077b2014-06-30 14:15:31 -0700104import com.android.launcher3.DropTarget.DragObject;
105import com.android.launcher3.PagedView.PageSwitchListener;
Sunny Goyalffe83f12014-08-14 17:39:34 -0700106import com.android.launcher3.compat.AppWidgetManagerCompat;
Kenny Guyed131872014-04-30 03:02:21 +0100107import com.android.launcher3.compat.LauncherActivityInfoCompat;
108import com.android.launcher3.compat.LauncherAppsCompat;
Sunny Goyale755d462014-07-22 13:48:29 -0700109import com.android.launcher3.compat.PackageInstallerCompat;
110import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
Kenny Guyed131872014-04-30 03:02:21 +0100111import com.android.launcher3.compat.UserHandleCompat;
112import com.android.launcher3.compat.UserManagerCompat;
Adam Cohen6c5891a2014-07-09 23:53:15 -0700113
Adam Cohenc0dcf592011-06-01 15:30:43 -0700114import java.io.DataInputStream;
115import java.io.DataOutputStream;
Adam Cohen4caf2982013-08-20 18:54:31 -0700116import java.io.File;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700117import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700118import java.io.FileNotFoundException;
Adam Cohen4caf2982013-08-20 18:54:31 -0700119import java.io.FileOutputStream;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700120import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700121import java.io.PrintWriter;
Adam Cohen0b395352014-06-09 22:54:36 +0000122import java.lang.reflect.Field;
123import java.lang.reflect.InvocationTargetException;
124import java.lang.reflect.Method;
Adam Cohen4caf2982013-08-20 18:54:31 -0700125import java.text.DateFormat;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700126import java.util.ArrayList;
Winson Chungf0c6ae02012-03-21 16:10:31 -0700127import java.util.Collection;
Adam Cohen4caf2982013-08-20 18:54:31 -0700128import java.util.Date;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700129import java.util.HashMap;
Michael Jurkad7c28052012-04-27 15:43:36 -0700130import java.util.List;
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000131import java.util.concurrent.atomic.AtomicInteger;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700132
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133/**
134 * Default launcher application.
135 */
Bjorn Bringertc459e522013-06-07 19:36:01 +0100136public class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700137 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700138 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800139 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700140 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
Daniel Sandlerf061f822013-06-27 13:59:36 -0400142 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400143 static final boolean DEBUG_WIDGETS = false;
Winson Chunga2413752012-04-03 14:22:34 -0700144 static final boolean DEBUG_STRICT_MODE = false;
Daniel Sandlerf061f822013-06-27 13:59:36 -0400145 static final boolean DEBUG_RESUME_TIME = false;
Winson Chungede41292013-09-19 16:27:36 -0700146 static final boolean DEBUG_DUMP_LOG = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700147
Dan Sandlerd5024042014-01-09 15:01:33 -0500148 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
149
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700151 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800152 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700153 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700154 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800155
Michael Jurka8b805b12012-04-18 14:23:14 -0700156 private static final int REQUEST_BIND_APPWIDGET = 11;
Sunny Goyalff572272014-07-23 13:58:07 -0700157 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
Michael Jurka8b805b12012-04-18 14:23:14 -0700158
Mathew Inwood876a8462013-06-14 14:12:41 +0100159 /**
160 * IntentStarter uses request codes starting with this. This must be greater than all activity
161 * request codes used internally.
162 */
163 protected static final int REQUEST_LAST = 100;
164
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
166
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800167 static final int SCREEN_COUNT = 5;
168 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169
Romain Guy98d01652009-06-30 16:21:04 -0700170 private static final String PREFERENCES = "launcher.preferences";
Michael Jurka0a457bf2012-11-19 14:05:05 -0800171 // To turn on these properties, type
172 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
173 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
174 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800175 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176
Winson Chung2672ff92012-05-04 16:22:30 -0700177 // The Intent extra that defines whether to ignore the launch animation
178 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
Daniel Sandler325dc232013-06-05 22:57:57 -0400179 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
Winson Chung2672ff92012-05-04 16:22:30 -0700180
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 // Type: int
182 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700183 // Type: int
184 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700186 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
187 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
189 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700190 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700192 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800193 // Type: boolean
194 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
195 // Type: long
196 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700197 // Type: int
198 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
199 // Type: int
200 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
201 // Type: parcelable
202 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000203 // Type: parcelable
Adam Cohen4637b5a2013-11-04 18:21:24 -0800204 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000205 // Type: int[]
206 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207
Adam Cohen432609a2014-03-13 17:03:22 -0700208 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
Adam Cohenb54a5982014-01-08 15:21:04 -0800209 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
210
Adam Cohen3ed316a2014-07-23 18:21:20 -0700211 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
212 static final String ACTION_FIRST_LOAD_COMPLETE =
213 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
214
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100215 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700216 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100217 "com.android.launcher.toolbar_search_icon";
Michael Jurkaae65ee32012-04-30 11:45:54 -0700218 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
Bjorn Bringerte441bbc2013-06-06 21:54:20 +0100219 "com.android.launcher.toolbar_voice_search_icon";
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700220
Adam Cohen39a06042013-07-19 14:30:12 -0700221 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
Daniel Sandler6053b802013-08-15 15:44:26 -0700222 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
Adam Cohen39a06042013-07-19 14:30:12 -0700223
Winson Chunga6945242014-01-08 14:04:34 -0800224 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
225
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700226 /** The different states that Launcher can be in. */
Winson Chung4a2afa32012-07-19 14:53:05 -0700227 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700228 private State mState = State.WORKSPACE;
229 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700230
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700231 private boolean mIsSafeModeEnabled;
232
Joe Onorato9c1289c2009-08-17 11:03:03 -0400233 static final int APPWIDGET_HOST_ID = 1024;
Adam Cohenad4e15c2013-10-17 16:21:35 -0700234 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
235 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
Adam Cohen646fdf72014-04-08 16:59:36 -0700236 private static final int ACTIVITY_START_DELAY = 1000;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800237
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800238 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800239 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800240
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000241 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
242 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
243
Winson Chunga2413752012-04-03 14:22:34 -0700244 // How long to wait before the new-shortcut animation automatically pans the workspace
Winson Chung94d67682013-09-25 16:29:40 -0700245 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
246 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
Winson Chung64359a52013-07-08 17:17:08 -0700247 private static int NEW_APPS_ANIMATION_DELAY = 500;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700248 private static final int SINGLE_FRAME_DELAY = 16;
Winson Chunga2413752012-04-03 14:22:34 -0700249
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800250 private final BroadcastReceiver mCloseSystemDialogsReceiver
251 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800252 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
253
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800254 private LayoutInflater mInflater;
255
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800256 private Workspace mWorkspace;
Craig Mautner360310b2012-10-26 15:13:08 -0700257 private View mLauncherView;
Winson Chunga6945242014-01-08 14:04:34 -0800258 private View mPageIndicators;
Michael Jurkab737ee62011-11-15 15:57:22 -0800259 private DragLayer mDragLayer;
260 private DragController mDragController;
Adam Cohen39a06042013-07-19 14:30:12 -0700261 private View mWeightWatcher;
Romain Guycbb89e42009-06-08 15:52:54 -0700262
Sunny Goyalffe83f12014-08-14 17:39:34 -0700263 private AppWidgetManagerCompat mAppWidgetManager;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700264 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700265
Michael Jurkac9d95c52011-08-29 14:03:34 -0700266 private ItemInfo mPendingAddInfo = new ItemInfo();
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700267 private AppWidgetProviderInfo mPendingAddWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800268 private int mPendingAddWidgetId = -1;
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700269
Michael Jurka0280c3b2010-09-17 15:00:07 -0700270 private int[] mTmpAddItemCellCoordinates = new int[2];
271
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800272 private FolderInfo mFolderInfo;
273
Winson Chung3d503fb2011-07-13 17:25:49 -0700274 private Hotseat mHotseat;
Jorim Jaggid017f882014-01-14 17:08:48 -0800275 private ViewGroup mOverviewPanel;
Adam Cohenf358a4b2013-07-23 16:47:31 -0700276
Michael Jurka838a4ca2011-02-07 13:33:06 -0800277 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700278
Winson Chungc51db6a2011-10-05 11:44:49 -0700279 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700280 private AppsCustomizeTabHost mAppsCustomizeTabHost;
281 private AppsCustomizePagedView mAppsCustomizeContent;
282 private boolean mAutoAdvanceRunning = false;
Adam Cohen24ce0b32014-01-14 16:18:14 -0800283 private View mQsb;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800284
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800285 private Bundle mSavedState;
Winson Chung4a2afa32012-07-19 14:53:05 -0700286 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
287 // scroll issues (because the workspace may not have been measured yet) and extra work.
288 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
289 private State mOnResumeState = State.NONE;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800290
291 private SpannableStringBuilder mDefaultKeySsb = null;
292
Joe Onorato9c1289c2009-08-17 11:03:03 -0400293 private boolean mWorkspaceLoading = true;
294
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800295 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800296 private boolean mRestoring;
297 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700298 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800299
Michael Jurka1e2f4652013-07-08 18:03:46 -0700300 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
Michael Jurka7607c2f2013-04-03 14:33:19 -0700301 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
302
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800303 private Bundle mSavedInstanceState;
304
Joe Onorato9c1289c2009-08-17 11:03:03 -0400305 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800306 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800307 private boolean mUserPresent = true;
308 private boolean mVisible = false;
Adam Cohened307df2013-10-02 09:37:31 -0700309 private boolean mHasFocus = false;
Adam Cohend113e0c2010-11-11 10:48:05 -0800310 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400311
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700312 private static LocaleConfiguration sLocaleConfiguration = null;
313
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700314 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700315
Adam Cohen61f560d2013-09-30 15:58:20 -0700316 private View.OnTouchListener mHapticFeedbackTouchListener;
317
Adam Cohended9f8d2010-11-03 13:25:16 -0700318 // Related to the auto-advancing of widgets
319 private final int ADVANCE_MSG = 1;
320 private final int mAdvanceInterval = 20000;
321 private final int mAdvanceStagger = 250;
322 private long mAutoAdvanceSentTime;
323 private long mAutoAdvanceTimeLeft = -1;
324 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
325 new HashMap<View, AppWidgetProviderInfo>();
326
Winson Chung400438b2011-01-16 17:53:48 -0800327 // Determines how long to wait after a rotation before restoring the screen orientation to
328 // match the sensor state.
329 private final int mRestoreScreenOrientationDelay = 500;
330
Michael Jurka4ef207b2010-11-29 17:05:45 -0800331 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700332 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
333 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
Winson Chungd64a6662013-09-30 11:06:59 -0700334
Craig Mautner360310b2012-10-26 15:13:08 -0700335 private Drawable mWorkspaceBackgroundDrawable;
Craig Mautner360310b2012-10-26 15:13:08 -0700336
Adam Cohen1462de32012-07-24 22:34:36 -0700337 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
Winson Chung6e1c0d32013-10-25 15:24:24 -0700338 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
Adam Cohen1462de32012-07-24 22:34:36 -0700339
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700340 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
Adam Cohen4caf2982013-08-20 18:54:31 -0700341 static Date sDateStamp = new Date();
342 static DateFormat sDateFormat =
343 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
344 static long sRunStart = System.currentTimeMillis();
345 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700346
Winson Chung46353de2012-02-16 14:05:10 -0800347 // We only want to get the SharedPreferences once since it does an FS stat each time we get
348 // it from the context.
349 private SharedPreferences mSharedPrefs;
350
Adam Cohene25af792013-06-06 23:08:25 -0700351 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
352
Winson Chungf0c6ae02012-03-21 16:10:31 -0700353 // Holds the page that we need to animate to, and the icon views that we need to animate up
354 // when we scroll to that page on resume.
Adam Cohen268c4752012-06-06 17:47:33 -0700355 private ImageView mFolderIconImageView;
356 private Bitmap mFolderIconBitmap;
357 private Canvas mFolderIconCanvas;
358 private Rect mRectForFolderAnimation = new Rect();
Adam Cohen2801caf2011-05-13 20:57:39 -0700359
Michael Jurkaddd62e92011-02-16 17:49:14 -0800360 private BubbleTextView mWaitingForResume;
361
Michael Jurkac1f5d262011-09-30 19:32:27 -0700362 private Runnable mBuildLayersRunnable = new Runnable() {
363 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700364 if (mWorkspace != null) {
365 mWorkspace.buildPageHardwareLayers();
366 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700367 }
368 };
369
Adam Cohendb364c32014-05-20 14:23:40 -0700370 private static PendingAddArguments sPendingAddItem;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800371
Michael Jurka7267fa52013-09-26 15:29:57 -0700372 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
Michael Jurka0a457bf2012-11-19 14:05:05 -0800373
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800374 private static class PendingAddArguments {
375 int requestCode;
376 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700377 long container;
Adam Cohendcd297f2013-06-18 13:13:40 -0700378 long screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800379 int cellX;
380 int cellY;
Adam Cohendb364c32014-05-20 14:23:40 -0700381 int appWidgetId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800382 }
383
Daniel Sandlerff02d492013-08-05 02:12:05 -0400384 private Stats mStats;
385
Sunny Goyaldcbcc862014-08-12 15:58:36 -0700386 FocusIndicatorView mFocusHandler;
387
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -0800388 static boolean isPropertyEnabled(String propertyName) {
Michael Jurka0a457bf2012-11-19 14:05:05 -0800389 return Log.isLoggable(propertyName, Log.VERBOSE);
Michael Jurka9bc8eba2012-05-21 20:36:44 -0700390 }
391
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800392 @Override
393 protected void onCreate(Bundle savedInstanceState) {
Winson Chunga2413752012-04-03 14:22:34 -0700394 if (DEBUG_STRICT_MODE) {
395 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
396 .detectDiskReads()
397 .detectDiskWrites()
398 .detectNetwork() // or .detectAll() for all detectable problems
399 .penaltyLog()
400 .build());
401 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
402 .detectLeakedSqlLiteObjects()
403 .detectLeakedClosableObjects()
404 .penaltyLog()
405 .penaltyDeath()
406 .build());
407 }
408
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800409 super.onCreate(savedInstanceState);
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400410
Daniel Sandlere060b0b2013-06-27 21:47:55 -0400411 LauncherAppState.setApplicationContext(getApplicationContext());
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400412 LauncherAppState app = LauncherAppState.getInstance();
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700413 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
Winson Chung5f8afe62013-08-12 16:19:28 -0700414 // Determine the dynamic grid properties
415 Point smallestSize = new Point();
416 Point largestSize = new Point();
417 Point realSize = new Point();
418 Display display = getWindowManager().getDefaultDisplay();
419 display.getCurrentSizeRange(smallestSize, largestSize);
420 display.getRealSize(realSize);
Winson Chung892c74d2013-08-22 16:15:50 -0700421 DisplayMetrics dm = new DisplayMetrics();
422 display.getMetrics(dm);
Winson Chung6e1c0d32013-10-25 15:24:24 -0700423
Winson Chung5f8afe62013-08-12 16:19:28 -0700424 // Lazy-initialize the dynamic grid
425 DeviceProfile grid = app.initDynamicGrid(this,
426 Math.min(smallestSize.x, smallestSize.y),
427 Math.min(largestSize.x, largestSize.y),
Winson Chung892c74d2013-08-22 16:15:50 -0700428 realSize.x, realSize.y,
429 dm.widthPixels, dm.heightPixels);
Winson Chung5f8afe62013-08-12 16:19:28 -0700430
431 // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400432 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Winson Chungf0c6ae02012-03-21 16:10:31 -0700433 Context.MODE_PRIVATE);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -0700434 mIsSafeModeEnabled = getPackageManager().isSafeMode();
Joe Onorato0589f0f2010-02-08 13:44:00 -0800435 mModel = app.setLauncher(this);
436 mIconCache = app.getIconCache();
Winson Chunge5467dc2013-10-14 17:03:04 -0700437 mIconCache.flushInvalidIcons(grid);
Joe Onorato41a12d22009-10-31 18:30:00 -0400438 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800439 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700440
Daniel Sandlerff02d492013-08-05 02:12:05 -0400441 mStats = new Stats(this);
442
Sunny Goyalffe83f12014-08-14 17:39:34 -0700443 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
Adam Cohen53805212013-10-01 10:39:23 -0700444
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700445 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
446 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700447
Winson Chungb8b2a5a2012-07-12 17:55:31 -0700448 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
449 // this also ensures that any synchronous binding below doesn't re-trigger another
450 // LauncherModel load.
451 mPaused = false;
452
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800453 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200454 android.os.Debug.startMethodTracing(
455 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800456 }
457
458 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800459 setContentView(R.layout.launcher);
Michael Jurka7267fa52013-09-26 15:29:57 -0700460
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800461 setupViews();
Cristina Stancu476493b2013-08-07 17:20:14 +0100462 grid.layout(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800463
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800464 registerContentObservers();
465
Joe Onorato7c312c12009-08-13 21:36:53 -0700466 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700467
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800468 mSavedState = savedInstanceState;
469 restoreState(mSavedState);
470
471 if (PROFILE_STARTUP) {
472 android.os.Debug.stopMethodTracing();
473 }
474
475 if (!mRestoring) {
Adam Cohendb78dc82014-06-19 14:50:51 -0700476 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
Winson Chung4a2afa32012-07-19 14:53:05 -0700477 // If the user leaves launcher, then we should just load items asynchronously when
478 // they return.
Derek Prothro7aff3992013-12-10 14:00:37 -0500479 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Winson Chung4a2afa32012-07-19 14:53:05 -0700480 } else {
481 // We only load the page synchronously if the user rotates (or triggers a
482 // configuration change) while launcher is in the foreground
Winson Chung9b9fb962013-11-15 15:39:34 -0800483 mModel.startLoader(true, mWorkspace.getRestorePage());
Winson Chung4a2afa32012-07-19 14:53:05 -0700484 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800485 }
486
487 // For handling default keys
488 mDefaultKeySsb = new SpannableStringBuilder();
489 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800490
491 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
492 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800493
Adam Cohenf9426d52012-06-04 17:26:21 -0700494 updateGlobalIcons();
495
496 // On large interfaces, we want the screen to auto-rotate based on the current orientation
497 unlockScreenOrientation(true);
Winson Chungaf40f202013-09-18 18:26:31 -0700498
Adam Cohen432609a2014-03-13 17:03:22 -0700499 if (shouldShowIntroScreen()) {
500 showIntroScreen();
501 } else {
502 showFirstRunActivity();
Sunny Goyal88d60f12014-09-08 03:47:29 -0700503 showFirstRunClings();
Winson Chunga6945242014-01-08 14:04:34 -0800504 }
Adam Cohenf9426d52012-06-04 17:26:21 -0700505 }
506
Anjali Koppal67e7cae2014-03-13 12:14:12 -0700507 @Override
508 public void onLauncherProviderChange() { }
509
Winson Chung98ca0f72013-07-29 12:58:51 -0700510 /** To be overriden by subclasses to hint to Launcher that we have custom content */
511 protected boolean hasCustomContentToLeft() {
512 return false;
513 }
514
Dave Hawkeya8881582013-09-17 15:55:33 -0600515 /**
Derek Prothrodadd9842014-01-17 13:43:50 -0500516 * To be overridden by subclasses to populate the custom content container and call
Dave Hawkeya8881582013-09-17 15:55:33 -0600517 * {@link #addToCustomContentPage}. This will only be invoked if
518 * {@link #hasCustomContentToLeft()} is {@code true}.
519 */
Derek Prothrodadd9842014-01-17 13:43:50 -0500520 protected void populateCustomContentContainer() {
Dave Hawkeya8881582013-09-17 15:55:33 -0600521 }
522
523 /**
524 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
525 * ensure the custom content page is added or removed if necessary.
526 */
527 protected void invalidateHasCustomContentToLeft() {
Dave Hawkey3a733a72013-09-30 11:52:21 -0600528 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
Dave Hawkeya8881582013-09-17 15:55:33 -0600529 // Not bound yet, wait for bindScreens to be called.
530 return;
531 }
532
533 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
534 // Create the custom content page and call the subclass to populate it.
Derek Prothrodadd9842014-01-17 13:43:50 -0500535 mWorkspace.createCustomContentContainer();
536 populateCustomContentContainer();
Dave Hawkeya8881582013-09-17 15:55:33 -0600537 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
538 mWorkspace.removeCustomContentPage();
539 }
540 }
541
Adam Cohenf9426d52012-06-04 17:26:21 -0700542 private void updateGlobalIcons() {
Winson Chungc51db6a2011-10-05 11:44:49 -0700543 boolean searchVisible = false;
544 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800545 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700546 int coi = getCurrentOrientationIndexForGlobalIcons();
Adam Cohena00673c2014-08-14 12:57:28 -0700547 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700548 searchVisible = updateGlobalSearchIcon();
549 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700550 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700551 if (sGlobalSearchIcon[coi] != null) {
552 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700553 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700554 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700555 if (sVoiceSearchIcon[coi] != null) {
556 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700557 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700558 }
Winson Chungadf0c182012-08-23 14:59:07 -0700559 if (mSearchDropTargetBar != null) {
560 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
561 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800562 }
Romain Guycbb89e42009-06-08 15:52:54 -0700563
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800564 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700565 if (sLocaleConfiguration == null) {
566 new AsyncTask<Void, Void, LocaleConfiguration>() {
567 @Override
568 protected LocaleConfiguration doInBackground(Void... unused) {
569 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
570 readConfiguration(Launcher.this, localeConfiguration);
571 return localeConfiguration;
572 }
573
574 @Override
575 protected void onPostExecute(LocaleConfiguration result) {
576 sLocaleConfiguration = result;
577 checkForLocaleChange(); // recursive, but now with a locale configuration
578 }
579 }.execute();
580 return;
581 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700582
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800583 final Configuration configuration = getResources().getConfiguration();
584
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700585 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800586 final String locale = configuration.locale.toString();
587
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700588 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800589 final int mcc = configuration.mcc;
590
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700591 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800592 final int mnc = configuration.mnc;
593
Romain Guy84f296c2009-11-04 15:00:44 -0800594 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800595
Romain Guy84f296c2009-11-04 15:00:44 -0800596 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700597 sLocaleConfiguration.locale = locale;
598 sLocaleConfiguration.mcc = mcc;
599 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700600
Joe Onorato0589f0f2010-02-08 13:44:00 -0800601 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700602
603 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
Michael Jurka43467462013-11-14 12:03:58 +0100604 new AsyncTask<Void, Void, Void>() {
605 public Void doInBackground(Void ... args) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700606 writeConfiguration(Launcher.this, localeConfiguration);
Michael Jurka43467462013-11-14 12:03:58 +0100607 return null;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700608 }
Michael Jurka43467462013-11-14 12:03:58 +0100609 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Romain Guy98d01652009-06-30 16:21:04 -0700610 }
611 }
612
613 private static class LocaleConfiguration {
614 public String locale;
615 public int mcc = -1;
616 public int mnc = -1;
617 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700618
Romain Guy98d01652009-06-30 16:21:04 -0700619 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
620 DataInputStream in = null;
621 try {
622 in = new DataInputStream(context.openFileInput(PREFERENCES));
623 configuration.locale = in.readUTF();
624 configuration.mcc = in.readInt();
625 configuration.mnc = in.readInt();
626 } catch (FileNotFoundException e) {
627 // Ignore
628 } catch (IOException e) {
629 // Ignore
630 } finally {
631 if (in != null) {
632 try {
633 in.close();
634 } catch (IOException e) {
635 // Ignore
636 }
637 }
638 }
639 }
640
641 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
642 DataOutputStream out = null;
643 try {
644 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
645 out.writeUTF(configuration.locale);
646 out.writeInt(configuration.mcc);
647 out.writeInt(configuration.mnc);
648 out.flush();
649 } catch (FileNotFoundException e) {
650 // Ignore
651 } catch (IOException e) {
652 //noinspection ResultOfMethodCallIgnored
653 context.getFileStreamPath(PREFERENCES).delete();
654 } finally {
655 if (out != null) {
656 try {
657 out.close();
658 } catch (IOException e) {
659 // Ignore
660 }
661 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800662 }
663 }
664
Anton Hanssona2f665f2013-09-26 12:18:32 +0100665 public Stats getStats() {
666 return mStats;
667 }
668
Bjorn Bringertc459e522013-06-07 19:36:01 +0100669 public LayoutInflater getInflater() {
670 return mInflater;
671 }
672
Winson Chung36a62fe2012-05-06 18:04:42 -0700673 boolean isDraggingEnabled() {
674 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
675 // that is subsequently removed from the workspace in startBinding().
676 return !mModel.isLoadingWorkspace();
677 }
678
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800679 static int getScreen() {
680 synchronized (sLock) {
681 return sScreen;
682 }
683 }
684
685 static void setScreen(int screen) {
686 synchronized (sLock) {
687 sScreen = screen;
688 }
689 }
690
Winson Chung557d6ed2011-07-08 15:34:52 -0700691 /**
Adam Cohenc76e1dd2013-11-14 11:09:14 +0000692 * Copied from View -- the View version of the method isn't called
693 * anywhere else in our process and only exists for API level 17+,
694 * so it's ok to keep our own version with no API requirement.
695 */
696 public static int generateViewId() {
697 for (;;) {
698 final int result = sNextGeneratedId.get();
699 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
700 int newValue = result + 1;
701 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
702 if (sNextGeneratedId.compareAndSet(result, newValue)) {
703 return result;
704 }
705 }
706 }
707
708 public int getViewIdForItem(ItemInfo info) {
709 // This cast is safe given the > 2B range for int.
710 int itemId = (int) info.id;
711 if (mItemIdToViewId.containsKey(itemId)) {
712 return mItemIdToViewId.get(itemId);
713 }
714 int viewId = generateViewId();
715 mItemIdToViewId.put(itemId, viewId);
716 return viewId;
717 }
718
719 /**
Winson Chung557d6ed2011-07-08 15:34:52 -0700720 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
721 * a configuration step, this allows the proper animations to run after other transitions.
722 */
Adam Cohendb364c32014-05-20 14:23:40 -0700723 private long completeAdd(PendingAddArguments args) {
724
725 long screenId = ensurePendingDropLayoutExists(args.screenId);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800726 switch (args.requestCode) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800727 case REQUEST_CREATE_SHORTCUT:
Adam Cohendb364c32014-05-20 14:23:40 -0700728 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -0700729 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700730 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800731 case REQUEST_CREATE_APPWIDGET:
Adam Cohendb364c32014-05-20 14:23:40 -0700732 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
Winson Chungb8472bb2011-08-05 13:49:21 -0700733 break;
Sunny Goyalff572272014-07-23 13:58:07 -0700734 case REQUEST_RECONFIGURE_APPWIDGET:
735 completeRestoreAppWidget(args.appWidgetId);
736 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800737 }
Michael Jurka27614d22012-04-02 06:40:22 -0700738 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
739 // if you turned the screen off and then back while in All Apps, Launcher would not
740 // return to the workspace. Clearing mAddInfo.container here fixes this issue
741 resetAddInfo();
Adam Cohendb364c32014-05-20 14:23:40 -0700742 return screenId;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800743 }
744
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800745 @Override
Michael Jurka8b805b12012-04-18 14:23:14 -0700746 protected void onActivityResult(
747 final int requestCode, final int resultCode, final Intent data) {
Winson Chunge341d302013-08-16 14:31:00 -0700748 // Reset the startActivity waiting flag
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700749 setWaitingForResult(false);
Adam Cohendb364c32014-05-20 14:23:40 -0700750 final int pendingAddWidgetId = mPendingAddWidgetId;
Adam Cohen4637b5a2013-11-04 18:21:24 -0800751 mPendingAddWidgetId = -1;
Winson Chunge341d302013-08-16 14:31:00 -0700752
Adam Cohenad4e15c2013-10-17 16:21:35 -0700753 Runnable exitSpringLoaded = new Runnable() {
754 @Override
755 public void run() {
756 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
757 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
758 }
759 };
760
Michael Jurka8b805b12012-04-18 14:23:14 -0700761 if (requestCode == REQUEST_BIND_APPWIDGET) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700762 final int appWidgetId = data != null ?
Michael Jurka8b805b12012-04-18 14:23:14 -0700763 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
764 if (resultCode == RESULT_CANCELED) {
765 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
Adam Cohen689ff162014-05-08 17:27:56 -0700766 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700767 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
Michael Jurka8b805b12012-04-18 14:23:14 -0700768 } else if (resultCode == RESULT_OK) {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700769 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
770 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
Michael Jurka8b805b12012-04-18 14:23:14 -0700771 }
772 return;
Michael Jurka336fd4f2013-09-12 00:05:02 +0200773 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
774 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
775 mWorkspace.exitOverviewMode(false);
776 }
777 return;
Michael Jurka8b805b12012-04-18 14:23:14 -0700778 }
Michael Jurka336fd4f2013-09-12 00:05:02 +0200779
Adam Cohened66b2b2012-01-23 17:28:51 -0800780 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
781 requestCode == REQUEST_CREATE_APPWIDGET);
Romain Guyaad5ef42009-06-10 02:48:37 -0700782
Adam Cohendb364c32014-05-20 14:23:40 -0700783 final boolean workspaceLocked = isWorkspaceLocked();
Adam Cohened66b2b2012-01-23 17:28:51 -0800784 // We have special handling for widgets
785 if (isWidgetDrop) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800786 final int appWidgetId;
787 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
788 : -1;
789 if (widgetId < 0) {
790 appWidgetId = pendingAddWidgetId;
791 } else {
792 appWidgetId = widgetId;
793 }
794
Adam Cohenad4e15c2013-10-17 16:21:35 -0700795 final int result;
Adam Cohenf0129b12013-11-04 17:57:36 -0800796 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
Adam Cohendb364c32014-05-20 14:23:40 -0700797 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
798 "returned from the widget configuration activity.");
Adam Cohenad4e15c2013-10-17 16:21:35 -0700799 result = RESULT_CANCELED;
800 completeTwoStageWidgetDrop(result, appWidgetId);
Adam Cohendb364c32014-05-20 14:23:40 -0700801 final Runnable onComplete = new Runnable() {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700802 @Override
803 public void run() {
804 exitSpringLoadedDragModeDelayed(false, 0, null);
805 }
806 };
Adam Cohendb364c32014-05-20 14:23:40 -0700807 if (workspaceLocked) {
808 // No need to remove the empty screen if we're mid-binding, as the
809 // the bind will not add the empty screen.
810 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
811 } else {
812 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
813 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
814 }
Winson Chung5aaab772012-04-27 15:24:02 -0700815 } else {
Adam Cohendb364c32014-05-20 14:23:40 -0700816 if (!workspaceLocked) {
817 mPendingAddInfo.screenId = ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
818 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
819
820 dropLayout.setDropPending(true);
821 final Runnable onComplete = new Runnable() {
822 @Override
823 public void run() {
824 completeTwoStageWidgetDrop(resultCode, appWidgetId);
825 dropLayout.setDropPending(false);
826 }
827 };
828 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
829 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
830 } else {
831 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
832 mPendingAddInfo);
833 sPendingAddItem = args;
834 }
Winson Chung5aaab772012-04-27 15:24:02 -0700835 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800836 return;
837 }
838
Sunny Goyalff572272014-07-23 13:58:07 -0700839 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
840 if (resultCode == RESULT_OK) {
841 // Update the widget view.
842 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
843 pendingAddWidgetId, mPendingAddInfo);
844 if (workspaceLocked) {
845 sPendingAddItem = args;
846 } else {
847 completeAdd(args);
848 }
849 }
850 // Leave the widget in the pending state if the user canceled the configure.
851 return;
852 }
853
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800854 // The pattern used here is that a user PICKs a specific application,
855 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700856
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800857 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
858 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700859 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Adam Cohendb364c32014-05-20 14:23:40 -0700860 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
861 mPendingAddInfo);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800862 if (isWorkspaceLocked()) {
Adam Cohendb364c32014-05-20 14:23:40 -0700863 sPendingAddItem = args;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800864 } else {
Adam Cohenad4e15c2013-10-17 16:21:35 -0700865 completeAdd(args);
Adam Cohendb364c32014-05-20 14:23:40 -0700866 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
867 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800868 }
Adam Cohen00074722013-10-11 17:46:09 -0700869 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen689ff162014-05-08 17:27:56 -0700870 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
Adam Cohenad4e15c2013-10-17 16:21:35 -0700871 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800872 }
Adam Cohened66b2b2012-01-23 17:28:51 -0800873 mDragLayer.clearAnimatedView();
Adam Cohened66b2b2012-01-23 17:28:51 -0800874 }
875
Adam Cohendb364c32014-05-20 14:23:40 -0700876 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
877 appWidgetId, ItemInfo info) {
878 PendingAddArguments args = new PendingAddArguments();
879 args.requestCode = requestCode;
880 args.intent = data;
881 args.container = info.container;
882 args.screenId = info.screenId;
883 args.cellX = info.cellX;
884 args.cellY = info.cellY;
885 args.appWidgetId = appWidgetId;
886 return args;
887 }
888
889 /**
890 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
891 *
892 * @param screenId the screen id to check
893 * @return the new screen, or screenId if it exists
894 */
895 private long ensurePendingDropLayoutExists(long screenId) {
896 CellLayout dropLayout =
897 (CellLayout) mWorkspace.getScreenWithId(screenId);
898 if (dropLayout == null) {
899 // it's possible that the add screen was removed because it was
900 // empty and a re-bind occurred
901 mWorkspace.addExtraEmptyScreen();
902 return mWorkspace.commitExtraEmptyScreen();
903 } else {
904 return screenId;
905 }
906 }
907
Adam Cohened66b2b2012-01-23 17:28:51 -0800908 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700909 CellLayout cellLayout =
Adam Cohendcd297f2013-06-18 13:13:40 -0700910 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800911 Runnable onCompleteRunnable = null;
912 int animationType = 0;
913
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700914 AppWidgetHostView boundWidget = null;
Adam Cohened66b2b2012-01-23 17:28:51 -0800915 if (resultCode == RESULT_OK) {
916 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
917 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700918 mPendingAddWidgetInfo);
919 boundWidget = layout;
Adam Cohened66b2b2012-01-23 17:28:51 -0800920 onCompleteRunnable = new Runnable() {
921 @Override
922 public void run() {
923 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -0700924 mPendingAddInfo.screenId, layout, null);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700925 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
926 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
Adam Cohened66b2b2012-01-23 17:28:51 -0800927 }
928 };
929 } else if (resultCode == RESULT_CANCELED) {
Adam Cohen4637b5a2013-11-04 18:21:24 -0800930 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Adam Cohened66b2b2012-01-23 17:28:51 -0800931 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
Adam Cohened66b2b2012-01-23 17:28:51 -0800932 }
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700933 if (mDragLayer.getAnimatedView() != null) {
934 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
935 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
936 animationType, boundWidget, true);
Adam Cohenad4e15c2013-10-17 16:21:35 -0700937 } else if (onCompleteRunnable != null) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -0700938 // The animated view may be null in the case of a rotation during widget configuration
939 onCompleteRunnable.run();
940 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800941 }
942
943 @Override
Michael Jurkacd496d72013-04-11 11:32:45 -0700944 protected void onStop() {
945 super.onStop();
946 FirstFrameAnimatorHelper.setIsVisible(false);
947 }
948
949 @Override
950 protected void onStart() {
951 super.onStart();
952 FirstFrameAnimatorHelper.setIsVisible(true);
953 }
954
955 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800956 protected void onResume() {
Michael Jurka447bf842013-05-15 14:52:15 +0200957 long startTime = 0;
958 if (DEBUG_RESUME_TIME) {
959 startTime = System.currentTimeMillis();
Daniel Sandler924b9932013-06-12 00:38:25 -0400960 Log.v(TAG, "Launcher.onResume()");
Michael Jurka447bf842013-05-15 14:52:15 +0200961 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800962 super.onResume();
Winson Chungf0c6ae02012-03-21 16:10:31 -0700963
Winson Chung4a2afa32012-07-19 14:53:05 -0700964 // Restore the previous launcher state
965 if (mOnResumeState == State.WORKSPACE) {
966 showWorkspace(false);
967 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
Winson Chung07e045c2013-11-06 15:49:51 -0800968 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
Winson Chung4a2afa32012-07-19 14:53:05 -0700969 }
970 mOnResumeState = State.NONE;
971
Craig Mautner360310b2012-10-26 15:13:08 -0700972 // Background was set to gradient in onPause(), restore to black if in all apps.
973 setWorkspaceBackground(mState == State.WORKSPACE);
974
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800975 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700976 if (mRestoring || mOnResumeNeedsLoad) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -0700977 setWorkspaceLoading(true);
Derek Prothro7aff3992013-12-10 14:00:37 -0500978 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400979 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700980 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800981 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700982 if (mBindOnResumeCallbacks.size() > 0) {
Michael Jurkac402cd92013-05-20 15:49:32 +0200983 // We might have postponed some bind calls until onResume (see waitUntilResume) --
984 // execute them here
985 long startTimeCallbacks = 0;
986 if (DEBUG_RESUME_TIME) {
987 startTimeCallbacks = System.currentTimeMillis();
988 }
989
990 if (mAppsCustomizeContent != null) {
991 mAppsCustomizeContent.setBulkBind(true);
992 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700993 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
994 mBindOnResumeCallbacks.get(i).run();
Michael Jurkac402cd92013-05-20 15:49:32 +0200995 }
996 if (mAppsCustomizeContent != null) {
997 mAppsCustomizeContent.setBulkBind(false);
998 }
Michael Jurka1e2f4652013-07-08 18:03:46 -0700999 mBindOnResumeCallbacks.clear();
Michael Jurkac402cd92013-05-20 15:49:32 +02001000 if (DEBUG_RESUME_TIME) {
1001 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1002 (System.currentTimeMillis() - startTimeCallbacks));
1003 }
Michael Jurka447bf842013-05-15 14:52:15 +02001004 }
Michael Jurka54554252013-08-01 12:52:23 +02001005 if (mOnResumeCallbacks.size() > 0) {
1006 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1007 mOnResumeCallbacks.get(i).run();
1008 }
1009 mOnResumeCallbacks.clear();
1010 }
Winson Chunge4e50662012-01-23 14:45:13 -08001011
1012 // Reset the pressed state of icons that were locked in the press state while activities
1013 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -08001014 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -08001015 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -08001016 mWaitingForResume.setStayPressed(false);
1017 }
Winson Chung82963d52013-10-09 11:20:57 -07001018
Adam Cohen06dff352012-06-01 17:17:08 -07001019 // It is possible that widgets can receive updates while launcher is not in the foreground.
1020 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1021 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1022 // orientation.
Adam Cohen3d509322012-06-06 14:10:04 -07001023 getWorkspace().reinflateWidgetsIfNecessary();
Adam Cohenf9426d52012-06-04 17:26:21 -07001024
Winson Chung780fe592013-09-26 14:48:44 -07001025 // Process any items that were added while Launcher was away.
1026 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1027
Winson Chung5841efa2013-09-30 18:06:44 -07001028 // Update the voice search button proxy
1029 updateVoiceButtonProxyVisible(false);
1030
Adam Cohenf9426d52012-06-04 17:26:21 -07001031 // Again, as with the above scenario, it's possible that one or more of the global icons
1032 // were updated in the wrong orientation.
1033 updateGlobalIcons();
Michael Jurka447bf842013-05-15 14:52:15 +02001034 if (DEBUG_RESUME_TIME) {
1035 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1036 }
Adam Cohen6fecd412013-10-02 17:41:50 -07001037
1038 if (mWorkspace.getCustomContentCallbacks() != null) {
1039 // If we are resuming and the custom content is the current page, we call onShow().
1040 // It is also poassible that onShow will instead be called slightly after first layout
1041 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1042 if (mWorkspace.isOnOrMovingToCustomContent()) {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001043 mWorkspace.getCustomContentCallbacks().onShow(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001044 }
1045 }
Adam Cohenedaaa302013-10-01 17:33:27 -07001046 mWorkspace.updateInteractionForState();
Adam Cohen53805212013-10-01 10:39:23 -07001047 mWorkspace.onResume();
Sunny Goyale755d462014-07-22 13:48:29 -07001048
1049 PackageInstallerCompat.getInstance(this).onResume();
Adam Cohen06dff352012-06-01 17:17:08 -07001050 }
1051
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001052 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001053 protected void onPause() {
Winson Chung997a9232013-07-24 15:33:46 -07001054 // Ensure that items added to Launcher are queued until Launcher returns
1055 InstallShortcutReceiver.enableInstallQueue();
Sunny Goyale755d462014-07-22 13:48:29 -07001056 PackageInstallerCompat.getInstance(this).onPause();
Winson Chung997a9232013-07-24 15:33:46 -07001057
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001058 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -07001059 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -08001060 mDragController.cancelDrag();
Winson Chunga2413752012-04-03 14:22:34 -07001061 mDragController.resetLastGestureUpTime();
Adam Cohen6fecd412013-10-02 17:41:50 -07001062
1063 // We call onHide() aggressively. The custom content callbacks should be able to
1064 // debounce excess onHide calls.
1065 if (mWorkspace.getCustomContentCallbacks() != null) {
1066 mWorkspace.getCustomContentCallbacks().onHide();
1067 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001068 }
Romain Guycbb89e42009-06-08 15:52:54 -07001069
Adam Cohenbffe7452013-07-22 18:21:45 -07001070 QSBScroller mQsbScroller = new QSBScroller() {
1071 int scrollY = 0;
1072
1073 @Override
1074 public void setScrollY(int scroll) {
1075 scrollY = scroll;
1076
1077 if (mWorkspace.isOnOrMovingToCustomContent()) {
1078 mSearchDropTargetBar.setTranslationY(- scrollY);
Mark Brophyd7dc6812013-09-20 17:27:32 +01001079 getQsbBar().setTranslationY(-scrollY);
Adam Cohenbffe7452013-07-22 18:21:45 -07001080 }
1081 }
1082 };
1083
1084 public void resetQSBScroll() {
1085 mSearchDropTargetBar.animate().translationY(0).start();
Mark Brophyd7dc6812013-09-20 17:27:32 +01001086 getQsbBar().animate().translationY(0).start();
Adam Cohenbffe7452013-07-22 18:21:45 -07001087 }
1088
1089 public interface CustomContentCallbacks {
Selim Cinek3a8a8f72014-01-16 10:38:38 -08001090 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1091 // by a onResume or by scrolling otherwise.
1092 public void onShow(boolean fromResume);
Adam Cohenbffe7452013-07-22 18:21:45 -07001093
1094 // Custom content is completely hidden
1095 public void onHide();
Adam Cohenc36fa5c2013-08-29 11:54:42 -07001096
1097 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1098 public void onScrollProgressChanged(float progress);
Jan-Willem Maarse2ff91c42014-07-10 15:58:12 -07001099
1100 // Indicates whether the user is allowed to scroll away from the custom content.
1101 boolean isScrollingAllowed();
Adam Cohenbffe7452013-07-22 18:21:45 -07001102 }
1103
Jorim Jaggid017f882014-01-14 17:08:48 -08001104 protected boolean hasSettings() {
1105 return false;
1106 }
1107
Adam Cohenbffe7452013-07-22 18:21:45 -07001108 public interface QSBScroller {
1109 public void setScrollY(int scrollY);
1110 }
1111
Winson Chung98ca0f72013-07-29 12:58:51 -07001112 public QSBScroller addToCustomContentPage(View customContent,
Adam Cohen53805212013-10-01 10:39:23 -07001113 CustomContentCallbacks callbacks, String description) {
1114 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
Adam Cohenbffe7452013-07-22 18:21:45 -07001115 return mQsbScroller;
Adam Cohen66a01fd2013-06-11 12:48:00 -07001116 }
1117
Adam Cohenedb40762013-07-18 16:45:45 -07001118 // The custom content needs to offset its content to account for the QSB
1119 public int getTopOffsetForCustomContent() {
1120 return mWorkspace.getPaddingTop();
1121 }
1122
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001123 @Override
1124 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001125 // Flag the loader to stop early before switching
1126 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -07001127 if (mAppsCustomizeContent != null) {
1128 mAppsCustomizeContent.surrender();
1129 }
Romain Guy13c2e7b2010-03-10 19:45:00 -08001130 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001131 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001132
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001133 // We can't hide the IME if it was forced open. So don't bother
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001134 @Override
1135 public void onWindowFocusChanged(boolean hasFocus) {
1136 super.onWindowFocusChanged(hasFocus);
Adam Cohened307df2013-10-02 09:37:31 -07001137 mHasFocus = hasFocus;
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001138 }
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001139
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001140 private boolean acceptFilter() {
1141 final InputMethodManager inputManager = (InputMethodManager)
1142 getSystemService(Context.INPUT_METHOD_SERVICE);
1143 return !inputManager.isFullscreenMode();
1144 }
1145
1146 @Override
1147 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -07001148 final int uniChar = event.getUnicodeChar();
1149 final boolean handled = super.onKeyDown(keyCode, event);
1150 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1151 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001152 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1153 keyCode, event);
1154 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001155 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -07001156 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -07001157 // showSearchDialog()
1158 // If there are multiple keystrokes before the search dialog takes focus,
1159 // onSearchRequested() will be called for every keystroke,
1160 // but it is idempotent, so it's fine.
1161 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001162 }
1163 }
1164
Joe Onorato8a9625e2010-01-28 15:55:35 -08001165 // Eat the long press event so the keyboard doesn't come up.
1166 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1167 return true;
1168 }
1169
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001170 return handled;
1171 }
1172
Karl Rosaen138a0412009-04-23 19:00:21 -07001173 private String getTypedText() {
1174 return mDefaultKeySsb.toString();
1175 }
1176
1177 private void clearTypedText() {
1178 mDefaultKeySsb.clear();
1179 mDefaultKeySsb.clearSpans();
1180 Selection.setSelection(mDefaultKeySsb, 0);
1181 }
1182
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001183 /**
Michael Jurka883f55b2010-10-21 15:47:14 -07001184 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1185 * State
1186 */
1187 private static State intToState(int stateOrdinal) {
1188 State state = State.WORKSPACE;
1189 final State[] stateValues = State.values();
1190 for (int i = 0; i < stateValues.length; i++) {
1191 if (stateValues[i].ordinal() == stateOrdinal) {
1192 state = stateValues[i];
1193 break;
1194 }
1195 }
1196 return state;
1197 }
1198
1199 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001200 * Restores the previous state, if it exists.
1201 *
1202 * @param savedState The previous state.
1203 */
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001204 @SuppressWarnings("unchecked")
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001205 private void restoreState(Bundle savedState) {
1206 if (savedState == null) {
1207 return;
1208 }
1209
Michael Jurka883f55b2010-10-21 15:47:14 -07001210 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -07001211 if (state == State.APPS_CUSTOMIZE) {
Winson Chung4a2afa32012-07-19 14:53:05 -07001212 mOnResumeState = State.APPS_CUSTOMIZE;
Joe Onorato3a8820b2009-11-10 15:06:42 -08001213 }
1214
Adam Cohen21cd0022013-10-09 18:57:02 -07001215 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1216 PagedView.INVALID_RESTORE_PAGE);
1217 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
Winson Chung8c87cd82013-07-23 16:20:10 -07001218 mWorkspace.setRestorePage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001219 }
1220
Winson Chung3d503fb2011-07-13 17:25:49 -07001221 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
Adam Cohendcd297f2013-06-18 13:13:40 -07001222 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001223
Winson Chung3d503fb2011-07-13 17:25:49 -07001224 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1225 mPendingAddInfo.container = pendingAddContainer;
Adam Cohendcd297f2013-06-18 13:13:40 -07001226 mPendingAddInfo.screenId = pendingAddScreen;
Winson Chung3d503fb2011-07-13 17:25:49 -07001227 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1228 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001229 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1230 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1231 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001232 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001233 setWaitingForResult(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001234 mRestoring = true;
1235 }
1236
1237 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1238 if (renameFolder) {
1239 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001240 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001241 mRestoring = true;
1242 }
Winson Chunga12a2502010-12-20 14:41:35 -08001243
Winson Chung785d2eb2011-04-14 16:08:02 -07001244 // Restore the AppsCustomize tab
1245 if (mAppsCustomizeTabHost != null) {
1246 String curTab = savedState.getString("apps_customize_currentTab");
1247 if (curTab != null) {
Winson Chungc93e5ae2012-07-23 20:48:26 -07001248 mAppsCustomizeTabHost.setContentTypeImmediate(
Winson Chung785d2eb2011-04-14 16:08:02 -07001249 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
Winson Chungf314b0e2011-08-16 11:54:27 -07001250 mAppsCustomizeContent.loadAssociatedPages(
1251 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -07001252 }
1253
Winson Chung5afbf7b2011-07-25 11:53:08 -07001254 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1255 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001256 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001257 mItemIdToViewId = (HashMap<Integer, Integer>)
1258 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259 }
1260
1261 /**
1262 * Finds all the views we need and configure them properly.
1263 */
1264 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001265 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -04001266
Craig Mautner360310b2012-10-26 15:13:08 -07001267 mLauncherView = findViewById(R.id.launcher);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001268 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
Winson Chung4c98d922011-05-31 16:50:48 -07001269 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1270 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Anjali Koppalf5d29132014-02-28 13:33:27 -08001271 mWorkspace.setPageSwitchListener(this);
Winson Chunga6945242014-01-08 14:04:34 -08001272 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
Craig Mautner360310b2012-10-26 15:13:08 -07001273
John Spurlock77e1f472013-09-11 10:09:51 -04001274 mLauncherView.setSystemUiVisibility(
1275 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Craig Mautner360310b2012-10-26 15:13:08 -07001276 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001277
Winson Chung4c98d922011-05-31 16:50:48 -07001278 // Setup the drag layer
1279 mDragLayer.setup(this, dragController);
1280
Winson Chung3d503fb2011-07-13 17:25:49 -07001281 // Setup the hotseat
1282 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1283 if (mHotseat != null) {
1284 mHotseat.setup(this);
Winson Chung11a1a532013-09-13 11:14:45 -07001285 mHotseat.setOnLongClickListener(this);
Winson Chung3d503fb2011-07-13 17:25:49 -07001286 }
1287
Jorim Jaggid017f882014-01-14 17:08:48 -08001288 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
Adam Cohen61f560d2013-09-30 15:58:20 -07001289 View widgetButton = findViewById(R.id.widget_button);
1290 widgetButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001291 @Override
1292 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001293 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001294 onClickAddWidgetButton(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001295 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001296 }
1297 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001298 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1299
1300 View wallpaperButton = findViewById(R.id.wallpaper_button);
1301 wallpaperButton.setOnClickListener(new OnClickListener() {
Adam Cohenf358a4b2013-07-23 16:47:31 -07001302 @Override
1303 public void onClick(View arg0) {
Winson Chung8e15fdf2013-11-11 15:47:45 -08001304 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001305 onClickWallpaperPicker(arg0);
Winson Chung8e15fdf2013-11-11 15:47:45 -08001306 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07001307 }
1308 });
Adam Cohen61f560d2013-09-30 15:58:20 -07001309 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1310
1311 View settingsButton = findViewById(R.id.settings_button);
Jorim Jaggid017f882014-01-14 17:08:48 -08001312 if (hasSettings()) {
1313 settingsButton.setOnClickListener(new OnClickListener() {
1314 @Override
1315 public void onClick(View arg0) {
1316 if (!mWorkspace.isSwitchingState()) {
Anjali Koppal7b168a12014-03-04 17:16:11 -08001317 onClickSettingsButton(arg0);
Jorim Jaggid017f882014-01-14 17:08:48 -08001318 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08001319 }
Jorim Jaggid017f882014-01-14 17:08:48 -08001320 });
1321 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1322 } else {
1323 settingsButton.setVisibility(View.GONE);
1324 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1325 lp.gravity = Gravity.END | Gravity.TOP;
1326 widgetButton.requestLayout();
1327 }
1328
Adam Cohendbdff6b2013-09-18 19:09:15 -07001329 mOverviewPanel.setAlpha(0f);
Adam Cohenf358a4b2013-07-23 16:47:31 -07001330
Winson Chung4c98d922011-05-31 16:50:48 -07001331 // Setup the workspace
1332 mWorkspace.setHapticFeedbackEnabled(false);
1333 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -07001334 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -07001335 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -07001336
Winson Chungf0ea4d32011-06-06 14:27:16 -07001337 // Get the search/delete bar
Adam Cohen24ce0b32014-01-14 16:18:14 -08001338 mSearchDropTargetBar = (SearchDropTargetBar)
1339 mDragLayer.findViewById(R.id.search_drop_target_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001340
Winson Chungf0ea4d32011-06-06 14:27:16 -07001341 // Setup AppsCustomize
Craig Mautner360310b2012-10-26 15:13:08 -07001342 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
Winson Chungf0ea4d32011-06-06 14:27:16 -07001343 mAppsCustomizeContent = (AppsCustomizePagedView)
1344 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1345 mAppsCustomizeContent.setup(this, dragController);
Craig Mautner360310b2012-10-26 15:13:08 -07001346
Winson Chung3d503fb2011-07-13 17:25:49 -07001347 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -07001348 dragController.setDragScoller(mWorkspace);
1349 dragController.setScrollView(mDragLayer);
1350 dragController.setMoveTarget(mWorkspace);
1351 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -07001352 if (mSearchDropTargetBar != null) {
1353 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -08001354 }
Daniel Sandler924b9932013-06-12 00:38:25 -04001355
Daniel Sandlera127b7a2013-06-17 14:25:46 -04001356 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
Daniel Sandler924b9932013-06-12 00:38:25 -04001357 Log.v(TAG, "adding WeightWatcher");
Adam Cohen39a06042013-07-19 14:30:12 -07001358 mWeightWatcher = new WeightWatcher(this);
1359 mWeightWatcher.setAlpha(0.5f);
1360 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
Daniel Sandler924b9932013-06-12 00:38:25 -04001361 new FrameLayout.LayoutParams(
1362 FrameLayout.LayoutParams.MATCH_PARENT,
Daniel Sandlerb9eb2862013-06-14 20:17:30 -04001363 FrameLayout.LayoutParams.WRAP_CONTENT,
Daniel Sandler924b9932013-06-12 00:38:25 -04001364 Gravity.BOTTOM)
1365 );
Adam Cohen39a06042013-07-19 14:30:12 -07001366
1367 boolean show = shouldShowWeightWatcher();
1368 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
Daniel Sandler924b9932013-06-12 00:38:25 -04001369 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001370 }
1371
1372 /**
Anjali Koppal5ad44842014-03-10 20:34:39 -07001373 * Sets the all apps button. This method is called from {@link Hotseat}.
1374 */
1375 public void setAllAppsButton(View allAppsButton) {
1376 mAllAppsButton = allAppsButton;
1377 }
1378
1379 public View getAllAppsButton() {
1380 return mAllAppsButton;
1381 }
1382
1383 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001384 * Creates a view representing a shortcut.
1385 *
1386 * @param info The data structure describing the shortcut.
1387 *
1388 * @return A View inflated from R.layout.application.
1389 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001390 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001391 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001392 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001393 }
1394
1395 /**
1396 * Creates a view representing a shortcut inflated from the specified resource.
1397 *
1398 * @param layoutResId The id of the XML layout used to create the shortcut.
1399 * @param parent The group the shortcut belongs to.
1400 * @param info The data structure describing the shortcut.
1401 *
1402 * @return A View inflated from layoutResId.
1403 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001404 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001405 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07001406 favorite.applyFromShortcutInfo(info, mIconCache, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001407 favorite.setOnClickListener(this);
Sunny Goyaldcbcc862014-08-12 15:58:36 -07001408 favorite.setOnFocusChangeListener(mFocusHandler);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001409 return favorite;
1410 }
1411
1412 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001413 * Add a shortcut to the workspace.
1414 *
1415 * @param data The intent describing the shortcut.
1416 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001417 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001418 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07001419 int cellY) {
1420 int[] cellXY = mTmpAddItemCellCoordinates;
1421 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohendcd297f2013-06-18 13:13:40 -07001422 CellLayout layout = getCellLayout(container, screenId);
Romain Guycbb89e42009-06-08 15:52:54 -07001423
Michael Jurkad3ef3062010-11-23 16:23:58 -08001424 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001425
Adam Cohen558baaf2011-08-15 15:22:57 -07001426 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -08001427 if (info == null) {
1428 return;
1429 }
Adam Cohen558baaf2011-08-15 15:22:57 -07001430 final View view = createShortcut(info);
1431
Adam Cohenfbba09b2011-07-18 21:43:05 -07001432 // First we check if we already know the exact location where we want to add this item.
1433 if (cellX >= 0 && cellY >= 0) {
1434 cellXY[0] = cellX;
1435 cellXY[1] = cellY;
1436 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -07001437
1438 // If appropriate, either create a folder or add to an existing folder
Adam Cohen482ed822012-03-02 14:15:13 -08001439 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
Adam Cohen558baaf2011-08-15 15:22:57 -07001440 true, null,null)) {
1441 return;
1442 }
1443 DragObject dragObject = new DragObject();
1444 dragObject.dragInfo = info;
Adam Cohen482ed822012-03-02 14:15:13 -08001445 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1446 true)) {
Adam Cohen558baaf2011-08-15 15:22:57 -07001447 return;
1448 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07001449 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -08001450 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001451 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001452 foundCellSpan = (result != null);
1453 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001454 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -08001455 }
1456
1457 if (!foundCellSpan) {
Winson Chung93eef082012-03-23 15:59:27 -07001458 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka0280c3b2010-09-17 15:00:07 -07001459 return;
1460 }
1461
Adam Cohendcd297f2013-06-18 13:13:40 -07001462 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001463
1464 if (!mRestoring) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001465 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07001466 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001467 }
1468 }
1469
Adam Cohen2f093b62012-04-30 18:59:53 -07001470 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1471 int minHeight) {
1472 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001473 // We want to account for the extra amount of padding that we are adding to the widget
1474 // to ensure that it gets the full amount of space that it has requested
1475 int requiredWidth = minWidth + padding.left + padding.right;
1476 int requiredHeight = minHeight + padding.top + padding.bottom;
Winson Chung66700732013-08-20 16:56:15 -07001477 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
Adam Cohenf814aa02011-09-01 13:48:05 -07001478 }
1479
Adam Cohen2f093b62012-04-30 18:59:53 -07001480 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1481 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001482 }
1483
Adam Cohen2f093b62012-04-30 18:59:53 -07001484 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1485 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
Adam Cohencbf47e32011-09-16 17:32:37 -07001486 }
1487
Adam Cohen2f093b62012-04-30 18:59:53 -07001488 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1489 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
Adam Cohenf814aa02011-09-01 13:48:05 -07001490 }
1491
Adam Cohen2f093b62012-04-30 18:59:53 -07001492 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1493 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
Winson Chunga5c96362012-04-12 14:04:41 -07001494 info.minResizeHeight);
Adam Cohend41fbf52012-02-16 23:53:59 -08001495 }
1496
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001497 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001498 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001499 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001500 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001501 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001502 */
Adam Cohendcd297f2013-06-18 13:13:40 -07001503 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
Adam Cohened66b2b2012-01-23 17:28:51 -08001504 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1505 if (appWidgetInfo == null) {
1506 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1507 }
Romain Guycbb89e42009-06-08 15:52:54 -07001508
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001509 // Calculate the grid spans needed to fit this widget
Adam Cohendcd297f2013-06-18 13:13:40 -07001510 CellLayout layout = getCellLayout(container, screenId);
Adam Cohen09353862011-07-14 16:10:03 -07001511
Adam Cohen2f093b62012-04-30 18:59:53 -07001512 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1513 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001514
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001515 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001516 // We have saved the position to which the widget was dragged-- this really only matters
1517 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -07001518 int[] cellXY = mTmpAddItemCellCoordinates;
1519 int[] touchXY = mPendingAddInfo.dropPos;
Adam Cohend41fbf52012-02-16 23:53:59 -08001520 int[] finalSpan = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001521 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -07001522 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1523 cellXY[0] = mPendingAddInfo.cellX;
1524 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohend41fbf52012-02-16 23:53:59 -08001525 spanXY[0] = mPendingAddInfo.spanX;
1526 spanXY[1] = mPendingAddInfo.spanY;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001527 foundCellSpan = true;
1528 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001529 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -07001530 int[] result = layout.findNearestVacantArea(
Adam Cohend41fbf52012-02-16 23:53:59 -08001531 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1532 spanXY[1], cellXY, finalSpan);
1533 spanXY[0] = finalSpan[0];
1534 spanXY[1] = finalSpan[1];
Michael Jurkad3ef3062010-11-23 16:23:58 -08001535 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001536 } else {
Adam Cohend41fbf52012-02-16 23:53:59 -08001537 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001538 }
1539
Michael Jurka0280c3b2010-09-17 15:00:07 -07001540 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -08001541 if (appWidgetId != -1) {
1542 // Deleting an app widget ID is a void call but writes to disk before returning
1543 // to the caller...
Michael Jurka43467462013-11-14 12:03:58 +01001544 new AsyncTask<Void, Void, Void>() {
1545 public Void doInBackground(Void ... args) {
Winson Chungf7640c82011-02-28 13:47:29 -08001546 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka43467462013-11-14 12:03:58 +01001547 return null;
Winson Chungf7640c82011-02-28 13:47:29 -08001548 }
Michael Jurka43467462013-11-14 12:03:58 +01001549 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Winson Chungf7640c82011-02-28 13:47:29 -08001550 }
Winson Chung93eef082012-03-23 15:59:27 -07001551 showOutOfSpaceMessage(isHotseatLayout(layout));
Romain Guy18042c82009-11-06 11:44:55 -08001552 return;
1553 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001554
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001555 // Build Launcher-specific widget info and save to database
Winson Chung11a49372012-04-27 15:12:38 -07001556 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1557 appWidgetInfo.provider);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001558 launcherInfo.spanX = spanXY[0];
1559 launcherInfo.spanY = spanXY[1];
Adam Cohend41fbf52012-02-16 23:53:59 -08001560 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1561 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
Sunny Goyalffe83f12014-08-14 17:39:34 -07001562 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001563
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001564 LauncherModel.addItemToDatabase(this, launcherInfo,
Adam Cohendcd297f2013-06-18 13:13:40 -07001565 container, screenId, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001566
1567 if (!mRestoring) {
Adam Cohened66b2b2012-01-23 17:28:51 -08001568 if (hostView == null) {
1569 // Perform actual inflation because we're live
1570 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1571 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1572 } else {
1573 // The AppWidgetHostView has already been inflated and instantiated
1574 launcherInfo.hostView = hostView;
1575 }
Romain Guycbb89e42009-06-08 15:52:54 -07001576
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001577 launcherInfo.hostView.setTag(launcherInfo);
Adam Cohend41fbf52012-02-16 23:53:59 -08001578 launcherInfo.hostView.setVisibility(View.VISIBLE);
Adam Cohenaaa5c212012-10-05 18:14:31 -07001579 launcherInfo.notifyWidgetSizeChanged(this);
1580
Adam Cohendcd297f2013-06-18 13:13:40 -07001581 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001582 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001583
1584 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001585 }
Adam Cohen6af9af02012-02-02 15:41:45 -08001586 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001587 }
Romain Guycbb89e42009-06-08 15:52:54 -07001588
Adam Cohended9f8d2010-11-03 13:25:16 -07001589 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1590 @Override
1591 public void onReceive(Context context, Intent intent) {
1592 final String action = intent.getAction();
1593 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1594 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001595 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001596 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001597
Winson Chungc100e8e2011-08-09 16:02:43 -07001598 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001599 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001600 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
Adam Cohened307df2013-10-02 09:37:31 -07001601 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001602 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001603 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1604 mUserPresent = true;
1605 updateRunning();
Dan Sandlerd5024042014-01-09 15:01:33 -05001606 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1607 mModel.resetLoadedState(false, true);
1608 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1609 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1610 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1611 mModel.resetLoadedState(false, true);
1612 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1613 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1614 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001615 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1616 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1617 getModel().forceReload();
Adam Cohended9f8d2010-11-03 13:25:16 -07001618 }
1619 }
1620 };
1621
1622 @Override
1623 public void onAttachedToWindow() {
1624 super.onAttachedToWindow();
1625
1626 // Listen for broadcasts related to user-presence
1627 final IntentFilter filter = new IntentFilter();
1628 filter.addAction(Intent.ACTION_SCREEN_OFF);
1629 filter.addAction(Intent.ACTION_USER_PRESENT);
Amith Yamasani6cc806d2014-05-02 13:47:11 -07001630 // For handling managed profiles
1631 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1632 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
Dan Sandlerd5024042014-01-09 15:01:33 -05001633 if (ENABLE_DEBUG_INTENTS) {
1634 filter.addAction(DebugIntents.DELETE_DATABASE);
1635 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1636 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001637 registerReceiver(mReceiver, filter);
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001638 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
Adam Cohen0b395352014-06-09 22:54:36 +00001639 setupTransparentSystemBarsForLmp();
Adam Cohend113e0c2010-11-11 10:48:05 -08001640 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001641 mVisible = true;
1642 }
1643
Adam Cohen0b395352014-06-09 22:54:36 +00001644 /**
1645 * Sets up transparent navigation and status bars in LMP.
1646 * This method is a no-op for other platform versions.
1647 */
1648 @TargetApi(19)
1649 private void setupTransparentSystemBarsForLmp() {
1650 // TODO(sansid): use the APIs directly when compiling against L sdk.
1651 // Currently we use reflection to access the flags and the API to set the transparency
1652 // on the System bars.
1653 if (Utilities.isLmp()) {
1654 try {
1655 getWindow().getAttributes().systemUiVisibility |=
1656 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1657 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1658 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1659 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1660 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1661 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1662 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1663 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1664
1665 Method setStatusBarColorMethod =
1666 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1667 Method setNavigationBarColorMethod =
1668 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1669 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1670 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1671 } catch (NoSuchFieldException e) {
1672 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1673 } catch (NoSuchMethodException ex) {
1674 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1675 } catch (IllegalAccessException e) {
1676 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1677 } catch (IllegalArgumentException e) {
1678 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1679 } catch (InvocationTargetException e) {
1680 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1681 } finally {}
1682 }
1683 }
1684
Adam Cohended9f8d2010-11-03 13:25:16 -07001685 @Override
1686 public void onDetachedFromWindow() {
1687 super.onDetachedFromWindow();
1688 mVisible = false;
1689
Adam Cohend113e0c2010-11-11 10:48:05 -08001690 if (mAttached) {
1691 unregisterReceiver(mReceiver);
1692 mAttached = false;
1693 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001694 updateRunning();
1695 }
1696
1697 public void onWindowVisibilityChanged(int visibility) {
1698 mVisible = visibility == View.VISIBLE;
1699 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001700 // The following code used to be in onResume, but it turns out onResume is called when
1701 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1702 // is a more appropriate event to handle
1703 if (mVisible) {
1704 mAppsCustomizeTabHost.onWindowVisible();
1705 if (!mWorkspaceLoading) {
1706 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001707 // We want to let Launcher draw itself at least once before we force it to build
1708 // layers on all the workspace pages, so that transitioning to Launcher from other
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001709 // apps is nice and speedy.
1710 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001711 private boolean mStarted = false;
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001712 public void onDraw() {
Michael Jurkadf96add2013-04-03 16:25:02 -07001713 if (mStarted) return;
1714 mStarted = true;
Michael Jurka6ee21d22012-02-21 18:20:27 -08001715 // We delay the layer building a bit in order to give
1716 // other message processing a time to run. In particular
1717 // this avoids a delay in hiding the IME if it was
1718 // currently shown, because doing that may involve
1719 // some communication back with the app.
Winson Chungaeae56b2012-02-24 15:47:27 -08001720 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
Michael Jurkadf96add2013-04-03 16:25:02 -07001721 final ViewTreeObserver.OnDrawListener listener = this;
1722 mWorkspace.post(new Runnable() {
1723 public void run() {
Michael Jurkab68e03a2013-04-11 11:36:41 -07001724 if (mWorkspace != null &&
1725 mWorkspace.getViewTreeObserver() != null) {
1726 mWorkspace.getViewTreeObserver().
1727 removeOnDrawListener(listener);
1728 }
Michael Jurkadf96add2013-04-03 16:25:02 -07001729 }
1730 });
Michael Jurkaf1ad6082013-03-13 12:55:46 +01001731 return;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001732 }
1733 });
1734 }
1735 clearTypedText();
1736 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001737 }
1738
1739 private void sendAdvanceMessage(long delay) {
1740 mHandler.removeMessages(ADVANCE_MSG);
1741 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1742 mHandler.sendMessageDelayed(msg, delay);
1743 mAutoAdvanceSentTime = System.currentTimeMillis();
1744 }
1745
1746 private void updateRunning() {
1747 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1748 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1749 mAutoAdvanceRunning = autoAdvanceRunning;
1750 if (autoAdvanceRunning) {
1751 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1752 sendAdvanceMessage(delay);
1753 } else {
1754 if (!mWidgetsToAdvance.isEmpty()) {
1755 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1756 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1757 }
1758 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001759 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001760 }
1761 }
1762 }
1763
1764 private final Handler mHandler = new Handler() {
1765 @Override
1766 public void handleMessage(Message msg) {
1767 if (msg.what == ADVANCE_MSG) {
1768 int i = 0;
1769 for (View key: mWidgetsToAdvance.keySet()) {
1770 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1771 final int delay = mAdvanceStagger * i;
1772 if (v instanceof Advanceable) {
1773 postDelayed(new Runnable() {
1774 public void run() {
1775 ((Advanceable) v).advance();
1776 }
1777 }, delay);
1778 }
1779 i++;
1780 }
1781 sendAdvanceMessage(mAdvanceInterval);
1782 }
1783 }
1784 };
1785
1786 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001787 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001788 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1789 if (v instanceof Advanceable) {
1790 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001791 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001792 updateRunning();
1793 }
1794 }
1795
1796 void removeWidgetToAutoAdvance(View hostView) {
1797 if (mWidgetsToAdvance.containsKey(hostView)) {
1798 mWidgetsToAdvance.remove(hostView);
1799 updateRunning();
1800 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001801 }
1802
Joe Onorato9c1289c2009-08-17 11:03:03 -04001803 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001804 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001805 launcherInfo.hostView = null;
1806 }
1807
Winson Chung93eef082012-03-23 15:59:27 -07001808 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1809 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1810 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
Adam Cohended9f8d2010-11-03 13:25:16 -07001811 }
1812
Winson Chunga6945242014-01-08 14:04:34 -08001813 public DragLayer getDragLayer() {
1814 return mDragLayer;
1815 }
1816
1817 public Workspace getWorkspace() {
1818 return mWorkspace;
1819 }
1820
1821 public Hotseat getHotseat() {
1822 return mHotseat;
1823 }
1824
Jorim Jaggid017f882014-01-14 17:08:48 -08001825 public ViewGroup getOverviewPanel() {
Winson Chunga6945242014-01-08 14:04:34 -08001826 return mOverviewPanel;
1827 }
1828
1829 public SearchDropTargetBar getSearchBar() {
1830 return mSearchDropTargetBar;
1831 }
1832
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001833 public LauncherAppWidgetHost getAppWidgetHost() {
1834 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001835 }
Romain Guycbb89e42009-06-08 15:52:54 -07001836
Winson Chunga9abd0e2010-10-27 17:18:37 -07001837 public LauncherModel getModel() {
1838 return mModel;
1839 }
1840
Winson Chunga6945242014-01-08 14:04:34 -08001841 protected SharedPreferences getSharedPrefs() {
1842 return mSharedPrefs;
1843 }
1844
Bjorn Bringertc459e522013-06-07 19:36:01 +01001845 public void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001846 getWindow().closeAllPanels();
1847
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001848 // Whatever we were doing is hereby canceled.
Anjali Koppalff7ceff2014-05-01 18:26:37 -07001849 setWaitingForResult(false);
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001850 }
1851
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001852 @Override
1853 protected void onNewIntent(Intent intent) {
Michael Jurka447bf842013-05-15 14:52:15 +02001854 long startTime = 0;
1855 if (DEBUG_RESUME_TIME) {
1856 startTime = System.currentTimeMillis();
1857 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001858 super.onNewIntent(intent);
1859
1860 // Close the menu
1861 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001862 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001863 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001864
Adam Cohened307df2013-10-02 09:37:31 -07001865 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1866 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1867 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001868
Adam Cohen6fecd412013-10-02 17:41:50 -07001869 if (mWorkspace == null) {
1870 // Can be cases where mWorkspace is null, this prevents a NPE
1871 return;
1872 }
1873 Folder openFolder = mWorkspace.getOpenFolder();
1874 // In all these cases, only animate if we're already on home
1875 mWorkspace.exitWidgetResizeMode();
1876 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
Adam Coppa120b8e2013-11-12 16:26:04 +00001877 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001878 mWorkspace.moveToDefaultScreen(true);
Winson Chung4a2afa32012-07-19 14:53:05 -07001879 }
Romain Guy1dd3a072009-07-16 13:21:01 -07001880
Adam Cohen6fecd412013-10-02 17:41:50 -07001881 closeFolder();
1882 exitSpringLoadedDragMode();
1883
1884 // If we are already on home, then just animate back to the workspace,
1885 // otherwise, just wait until onResume to set the state back to Workspace
1886 if (alreadyOnHome) {
Adam Cohened307df2013-10-02 09:37:31 -07001887 showWorkspace(true);
Adam Cohen6fecd412013-10-02 17:41:50 -07001888 } else {
1889 mOnResumeState = State.WORKSPACE;
1890 }
1891
1892 final View v = getWindow().peekDecorView();
1893 if (v != null && v.getWindowToken() != null) {
1894 InputMethodManager imm = (InputMethodManager)getSystemService(
1895 INPUT_METHOD_SERVICE);
1896 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1897 }
1898
1899 // Reset the apps customize page
Winson Chunge7e97e62013-12-02 17:02:50 -08001900 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Adam Cohen6fecd412013-10-02 17:41:50 -07001901 mAppsCustomizeTabHost.reset();
1902 }
Adam Coppa120b8e2013-11-12 16:26:04 +00001903
1904 onHomeIntent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001905 }
Adam Cohened307df2013-10-02 09:37:31 -07001906
Michael Jurka447bf842013-05-15 14:52:15 +02001907 if (DEBUG_RESUME_TIME) {
1908 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1909 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001910 }
1911
Adam Coppa120b8e2013-11-12 16:26:04 +00001912 /**
1913 * Override point for subclasses to prevent movement to the default screen when the home
1914 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1915 */
1916 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1917 return true;
1918 }
1919
1920 /**
1921 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1922 */
1923 protected void onHomeIntent() {
1924 // Do nothing
1925 }
1926
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001927 @Override
Adam Cohen1462de32012-07-24 22:34:36 -07001928 public void onRestoreInstanceState(Bundle state) {
1929 super.onRestoreInstanceState(state);
1930 for (int page: mSynchronouslyBoundPages) {
1931 mWorkspace.restoreInstanceStateForChild(page);
1932 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001933 }
1934
1935 @Override
1936 protected void onSaveInstanceState(Bundle outState) {
Adam Cohen21cd0022013-10-09 18:57:02 -07001937 if (mWorkspace.getChildCount() > 0) {
Winson Chung9b9fb962013-11-15 15:39:34 -08001938 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
1939 mWorkspace.getCurrentPageOffsetFromCustomContent());
Adam Cohen21cd0022013-10-09 18:57:02 -07001940 }
Adam Cohen95bb8002011-07-03 23:40:28 -07001941 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001942
Michael Jurka883f55b2010-10-21 15:47:14 -07001943 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001944 // We close any open folder since it will not be re-opened, and we need to make sure
1945 // this state is reflected.
1946 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001947
Adam Cohendcd297f2013-06-18 13:13:40 -07001948 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
Winson Chung3d503fb2011-07-13 17:25:49 -07001949 mWaitingForResult) {
1950 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
Adam Cohendcd297f2013-06-18 13:13:40 -07001951 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
Winson Chung3d503fb2011-07-13 17:25:49 -07001952 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1953 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
Adam Cohen9d5b7d82012-05-09 18:00:44 -07001954 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
1955 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
1956 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
Adam Cohen4637b5a2013-11-04 18:21:24 -08001957 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001958 }
1959
1960 if (mFolderInfo != null && mWaitingForResult) {
1961 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1962 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1963 }
Michael Jurka946ad472010-07-09 18:05:18 -07001964
Winson Chung785d2eb2011-04-14 16:08:02 -07001965 // Save the current AppsCustomize tab
1966 if (mAppsCustomizeTabHost != null) {
Winson Chung07e045c2013-11-06 15:49:51 -08001967 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
1968 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
Winson Chung785d2eb2011-04-14 16:08:02 -07001969 if (currentTabTag != null) {
1970 outState.putString("apps_customize_currentTab", currentTabTag);
1971 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001972 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1973 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001974 }
Adam Cohenc76e1dd2013-11-14 11:09:14 +00001975 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001976 }
1977
1978 @Override
1979 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001980 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001981
Winson Chunge7a03942011-08-05 15:05:12 -07001982 // Remove all pending runnables
1983 mHandler.removeMessages(ADVANCE_MSG);
1984 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001985 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001986
Winson Chungcd2b0142011-06-08 16:02:26 -07001987 // Stop callbacks from LauncherModel
Daniel Sandlercc8befa2013-06-11 14:45:48 -04001988 LauncherAppState app = (LauncherAppState.getInstance());
Winson Chungcd2b0142011-06-08 16:02:26 -07001989 mModel.stopLoader();
1990 app.setLauncher(null);
1991
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001992 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001993 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001994 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001995 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001996 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001997 mAppWidgetHost = null;
1998
1999 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002000
2001 TextKeyListener.getInstance().release();
2002
Winson Chung81b52252012-08-27 15:34:29 -07002003 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2004 // to prevent leaking Launcher activities on orientation change.
2005 if (mModel != null) {
2006 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2007 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002008
2009 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002010 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002011
Adam Cohenaccf3bf2012-04-30 16:07:43 -07002012 mDragLayer.clearAllResizeFrames();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002013 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
Adam Cohend552dd92013-11-26 12:13:11 -08002014 mWorkspace.removeAllWorkspaceScreens();
Patrick Dubroy2313eff2011-01-11 20:01:31 -08002015 mWorkspace = null;
2016 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08002017
Sunny Goyale755d462014-07-22 13:48:29 -07002018 PackageInstallerCompat.getInstance(this).onStop();
Michael Jurka2ecf9952012-06-18 12:52:28 -07002019 LauncherAnimUtils.onDestroyActivity();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002020 }
2021
Adam Cohena9cf38f2011-05-02 15:36:58 -07002022 public DragController getDragController() {
2023 return mDragController;
2024 }
2025
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002026 @Override
2027 public void startActivityForResult(Intent intent, int requestCode) {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002028 if (requestCode >= 0) {
2029 setWaitingForResult(true);
2030 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031 super.startActivityForResult(intent, requestCode);
2032 }
2033
Winson Chung70d72102011-08-12 11:24:35 -07002034 /**
2035 * Indicates that we want global search for this activity by setting the globalSearch
2036 * argument for {@link #startSearch} to true.
2037 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002038 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07002039 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002040 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002041
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002042 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07002043
Karl Rosaen138a0412009-04-23 19:00:21 -07002044 if (initialQuery == null) {
2045 // Use any text typed in the launcher as the initial query
2046 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07002047 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002048 if (appSearchData == null) {
2049 appSearchData = new Bundle();
Bjorn Bringert32b12d22013-06-06 13:00:41 +01002050 appSearchData.putString("source", "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002051 }
Winson Chungadf0c182012-08-23 14:59:07 -07002052 Rect sourceBounds = new Rect();
2053 if (mSearchDropTargetBar != null) {
2054 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2055 }
Romain Guycbb89e42009-06-08 15:52:54 -07002056
Ian Parkinson047036e2014-09-01 15:40:53 +01002057 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002058 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002059 if (clearTextImmediately) {
2060 clearTypedText();
2061 }
Bjorn Bringertc459e522013-06-07 19:36:01 +01002062 }
2063
Ian Parkinson047036e2014-09-01 15:40:53 +01002064 /**
2065 * Start a text search.
2066 *
2067 * @return {@code true} if the search will start immediately, so any further keypresses
2068 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2069 * to buffer keypresses.
2070 */
2071 public boolean startSearch(String initialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002072 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Michael Jurkaa33411c2012-06-14 16:18:21 -07002073 startGlobalSearch(initialQuery, selectInitialQuery,
Bjorn Bringertc459e522013-06-07 19:36:01 +01002074 appSearchData, sourceBounds);
Ian Parkinson047036e2014-09-01 15:40:53 +01002075 return false;
Michael Jurkaa33411c2012-06-14 16:18:21 -07002076 }
2077
2078 /**
2079 * Starts the global search activity. This code is a copied from SearchManager
2080 */
Bjorn Bringertc459e522013-06-07 19:36:01 +01002081 private void startGlobalSearch(String initialQuery,
Michael Jurkaa33411c2012-06-14 16:18:21 -07002082 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
Karl Rosaen138a0412009-04-23 19:00:21 -07002083 final SearchManager searchManager =
Michael Jurkaa33411c2012-06-14 16:18:21 -07002084 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2085 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2086 if (globalSearchActivity == null) {
2087 Log.w(TAG, "No global search activity found.");
2088 return;
2089 }
2090 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2091 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2092 intent.setComponent(globalSearchActivity);
2093 // Make sure that we have a Bundle to put source in
2094 if (appSearchData == null) {
2095 appSearchData = new Bundle();
2096 } else {
2097 appSearchData = new Bundle(appSearchData);
2098 }
2099 // Set source to package name of app that starts global search, if not set already.
2100 if (!appSearchData.containsKey("source")) {
2101 appSearchData.putString("source", getPackageName());
2102 }
2103 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2104 if (!TextUtils.isEmpty(initialQuery)) {
2105 intent.putExtra(SearchManager.QUERY, initialQuery);
2106 }
2107 if (selectInitialQuery) {
2108 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2109 }
2110 intent.setSourceBounds(sourceBounds);
2111 try {
2112 startActivity(intent);
2113 } catch (ActivityNotFoundException ex) {
2114 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2115 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002116 }
2117
Yura4f93ec62014-02-04 14:15:21 +00002118 public boolean isOnCustomContent() {
2119 return mWorkspace.isOnOrMovingToCustomContent();
2120 }
2121
Winson Chung70d72102011-08-12 11:24:35 -07002122 @Override
Winson Chung70d72102011-08-12 11:24:35 -07002123 public boolean onPrepareOptionsMenu(Menu menu) {
2124 super.onPrepareOptionsMenu(menu);
Yura4f93ec62014-02-04 14:15:21 +00002125 if (!isOnCustomContent()) {
2126 // Close any open folders
2127 closeFolder();
2128 // Stop resizing any widgets
2129 mWorkspace.exitWidgetResizeMode();
2130 if (!mWorkspace.isInOverviewMode()) {
2131 // Show the overview mode
2132 showOverviewMode(true);
2133 } else {
2134 showWorkspace(true);
2135 }
Winson Chunge0298742014-01-17 12:03:00 -08002136 }
Michael Jurkab94f3f82013-09-11 18:08:54 +02002137 return false;
Winson Chung70d72102011-08-12 11:24:35 -07002138 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002139
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002140 @Override
2141 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07002142 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07002143 // Use a custom animation for launching search
Karl Rosaen138a0412009-04-23 19:00:21 -07002144 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07002145 }
2146
Joe Onorato9c1289c2009-08-17 11:03:03 -04002147 public boolean isWorkspaceLocked() {
2148 return mWorkspaceLoading || mWaitingForResult;
2149 }
2150
Adam Cohen517a7f52014-03-01 12:12:59 -08002151 public boolean isWorkspaceLoading() {
2152 return mWorkspaceLoading;
2153 }
2154
Anjali Koppalff7ceff2014-05-01 18:26:37 -07002155 private void setWorkspaceLoading(boolean value) {
2156 boolean isLocked = isWorkspaceLocked();
2157 mWorkspaceLoading = value;
2158 if (isLocked != isWorkspaceLocked()) {
2159 onWorkspaceLockedChanged();
2160 }
2161 }
2162
2163 private void setWaitingForResult(boolean value) {
2164 boolean isLocked = isWorkspaceLocked();
2165 mWaitingForResult = value;
2166 if (isLocked != isWorkspaceLocked()) {
2167 onWorkspaceLockedChanged();
2168 }
2169 }
2170
2171 protected void onWorkspaceLockedChanged() { }
2172
Michael Jurka0280c3b2010-09-17 15:00:07 -07002173 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07002174 mPendingAddInfo.container = ItemInfo.NO_ID;
Adam Cohendcd297f2013-06-18 13:13:40 -07002175 mPendingAddInfo.screenId = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002176 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2177 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
Adam Cohend41fbf52012-02-16 23:53:59 -08002178 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
Winson Chung3d503fb2011-07-13 17:25:49 -07002179 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07002180 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07002181
Adam Cohenad4e15c2013-10-17 16:21:35 -07002182 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2183 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2184 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2185 }
2186
2187 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2188 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2189 delay) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002190 if (appWidgetInfo.configure != null) {
2191 mPendingAddWidgetInfo = appWidgetInfo;
Adam Cohen4637b5a2013-11-04 18:21:24 -08002192 mPendingAddWidgetId = appWidgetId;
Michael Jurkaaf442092010-06-10 17:01:57 -07002193
Bjorn Bringert7984c942009-12-09 15:38:25 +00002194 // Launch over to configure widget, if needed
Sunny Goyalffe83f12014-08-14 17:39:34 -07002195 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2196 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2197
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002198 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00002199 // Otherwise just add it
Adam Cohenad4e15c2013-10-17 16:21:35 -07002200 Runnable onComplete = new Runnable() {
2201 @Override
2202 public void run() {
2203 // Exit spring loaded mode if necessary after adding the widget
2204 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2205 null);
2206 }
2207 };
Adam Cohendcd297f2013-06-18 13:13:40 -07002208 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002209 appWidgetInfo);
Adam Cohen689ff162014-05-08 17:27:56 -07002210 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002211 }
2212 }
Romain Guycbb89e42009-06-08 15:52:54 -07002213
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002214 protected void moveToCustomContentScreen(boolean animate) {
Sandeep Siddharthaf2b47f12013-09-26 19:49:27 -07002215 // Close any folders that may be open.
2216 closeFolder();
Allan Wojciechowskiaf110e82013-09-12 10:48:23 +01002217 mWorkspace.moveToCustomContentScreen(animate);
2218 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002219 /**
2220 * Process a shortcut drop.
2221 *
2222 * @param componentName The name of the component
Adam Cohendcd297f2013-06-18 13:13:40 -07002223 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002224 * @param cell The cell it should be added to, optional
2225 * @param position The location on the screen where it was dropped, optional
2226 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002227 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
Winson Chung3d503fb2011-07-13 17:25:49 -07002228 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002229 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002230 mPendingAddInfo.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002231 mPendingAddInfo.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002232 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07002233
2234 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002235 mPendingAddInfo.cellX = cell[0];
2236 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002237 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07002238
2239 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2240 createShortcutIntent.setComponent(componentName);
2241 processShortcut(createShortcutIntent);
2242 }
2243
Adam Cohenfbba09b2011-07-18 21:43:05 -07002244 /**
2245 * Process a widget drop.
2246 *
2247 * @param info The PendingAppWidgetInfo of the widget being added.
Adam Cohendcd297f2013-06-18 13:13:40 -07002248 * @param screenId The ID of the screen where it should be added
Adam Cohenfbba09b2011-07-18 21:43:05 -07002249 * @param cell The cell it should be added to, optional
2250 * @param position The location on the screen where it was dropped, optional
2251 */
Adam Cohendcd297f2013-06-18 13:13:40 -07002252 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
Adam Cohend41fbf52012-02-16 23:53:59 -08002253 int[] cell, int[] span, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07002254 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002255 mPendingAddInfo.container = info.container = container;
Adam Cohendcd297f2013-06-18 13:13:40 -07002256 mPendingAddInfo.screenId = info.screenId = screenId;
Winson Chung3d503fb2011-07-13 17:25:49 -07002257 mPendingAddInfo.dropPos = loc;
Adam Cohend41fbf52012-02-16 23:53:59 -08002258 mPendingAddInfo.minSpanX = info.minSpanX;
2259 mPendingAddInfo.minSpanY = info.minSpanY;
2260
Adam Cohenfbba09b2011-07-18 21:43:05 -07002261 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07002262 mPendingAddInfo.cellX = cell[0];
2263 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07002264 }
Adam Cohend41fbf52012-02-16 23:53:59 -08002265 if (span != null) {
2266 mPendingAddInfo.spanX = span[0];
2267 mPendingAddInfo.spanY = span[1];
2268 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002269
Adam Cohened66b2b2012-01-23 17:28:51 -08002270 AppWidgetHostView hostView = info.boundWidget;
2271 int appWidgetId;
2272 if (hostView != null) {
2273 appWidgetId = hostView.getAppWidgetId();
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002274 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
Adam Cohened66b2b2012-01-23 17:28:51 -08002275 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002276 // In this case, we either need to start an activity to get permission to bind
2277 // the widget, or we need to start an activity to configure the widget, or both.
Adam Cohened66b2b2012-01-23 17:28:51 -08002278 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Adam Cohendd70d662012-10-04 16:53:44 -07002279 Bundle options = info.bindOptions;
2280
Sunny Goyalffe83f12014-08-14 17:39:34 -07002281 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2282 appWidgetId, info.info, options);
Adam Cohendd70d662012-10-04 16:53:44 -07002283 if (success) {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002284 addAppWidgetImpl(appWidgetId, info, null, info.info);
Michael Jurka8b805b12012-04-18 14:23:14 -07002285 } else {
Adam Cohen9d5b7d82012-05-09 18:00:44 -07002286 mPendingAddWidgetInfo = info.info;
Michael Jurka8b805b12012-04-18 14:23:14 -07002287 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2288 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2289 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
Sunny Goyalffe83f12014-08-14 17:39:34 -07002290 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2291 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
Adam Cohendd70d662012-10-04 16:53:44 -07002292 // TODO: we need to make sure that this accounts for the options bundle.
2293 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
Michael Jurka8b805b12012-04-18 14:23:14 -07002294 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2295 }
Adam Cohened66b2b2012-01-23 17:28:51 -08002296 }
Adam Cohenfbba09b2011-07-18 21:43:05 -07002297 }
2298
Joe Onoratodeb98af2010-02-19 14:59:39 -08002299 void processShortcut(Intent intent) {
Kenny Guyed131872014-04-30 03:02:21 +01002300 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002301 }
2302
Winson Chung24ab2f12010-09-16 14:10:47 -07002303 void processWallpaper(Intent intent) {
2304 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2305 }
2306
Adam Cohendcd297f2013-06-18 13:13:40 -07002307 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
Winson Chung3d503fb2011-07-13 17:25:49 -07002308 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07002309 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002310 folderInfo.title = getText(R.string.folder_name);
2311
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002312 // Update the model
Adam Cohendcd297f2013-06-18 13:13:40 -07002313 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
Winson Chung3d503fb2011-07-13 17:25:49 -07002314 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002315 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002316
2317 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07002318 FolderIcon newFolder =
2319 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07002320 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
Winson Chung3d503fb2011-07-13 17:25:49 -07002321 isWorkspaceLocked());
Winson Chung5f8afe62013-08-12 16:19:28 -07002322 // Force measure the new folder icon
2323 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2324 parent.getShortcutsAndWidgets().measureChild(newFolder);
Adam Cohendf035382011-04-11 17:22:04 -07002325 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002326 }
Romain Guycbb89e42009-06-08 15:52:54 -07002327
Joe Onorato9c1289c2009-08-17 11:03:03 -04002328 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002329 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002330 }
2331
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002332 protected ComponentName getWallpaperPickerComponent() {
Michael Jurka7ad868b2013-12-12 15:04:25 +01002333 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002334 }
2335
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002336 /**
2337 * Registers various content observers. The current implementation registers
2338 * only a favorites observer to keep track of the favorites applications.
2339 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002340 private void registerContentObservers() {
2341 ContentResolver resolver = getContentResolver();
2342 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2343 true, mWidgetObserver);
2344 }
2345
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002346 @Override
2347 public boolean dispatchKeyEvent(KeyEvent event) {
2348 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2349 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002350 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07002351 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08002352 case KeyEvent.KEYCODE_VOLUME_DOWN:
Michael Jurka0a457bf2012-11-19 14:05:05 -08002353 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
Joe Onoratobe386092009-11-17 17:32:16 -08002354 dumpState();
2355 return true;
2356 }
2357 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07002358 }
2359 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2360 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07002361 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002362 return true;
2363 }
2364 }
2365
2366 return super.dispatchKeyEvent(event);
2367 }
2368
Joe Onorato88ec0992009-11-19 13:16:06 -08002369 @Override
2370 public void onBackPressed() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07002371 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07002372 if (mAppsCustomizeContent.getContentType() ==
2373 AppsCustomizePagedView.ContentType.Applications) {
2374 showWorkspace(true);
2375 } else {
2376 showOverviewMode(true);
2377 }
Adam Cohenf358a4b2013-07-23 16:47:31 -07002378 } else if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002379 mWorkspace.exitOverviewMode(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002380 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07002381 Folder openFolder = mWorkspace.getOpenFolder();
2382 if (openFolder.isEditingName()) {
2383 openFolder.dismissEditingName();
2384 } else {
2385 closeFolder();
2386 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002387 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08002388 mWorkspace.exitWidgetResizeMode();
2389
Patrick Dubroy94f78a52011-02-28 17:39:16 -08002390 // Back button is a no-op here, but give at least some feedback for the button press
2391 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07002392 }
Joe Onorato88ec0992009-11-19 13:16:06 -08002393 }
2394
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002395 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002396 * Re-listen when widgets are reset.
2397 */
2398 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08002399 if (mAppWidgetHost != null) {
2400 mAppWidgetHost.startListening();
2401 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002402 }
2403
2404 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002405 * Launches the intent referred by the clicked shortcut.
2406 *
2407 * @param v The view representing the clicked shortcut.
2408 */
2409 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002410 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2411 // view has detached (it's possible for this to happen if the view is removed mid touch).
2412 if (v.getWindowToken() == null) {
2413 return;
2414 }
2415
Winson Chung9b0b2fe2012-02-24 13:03:34 -08002416 if (!mWorkspace.isFinishedSwitchingState()) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002417 return;
2418 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07002419
Adam Cohen1697b792013-09-17 19:08:21 -07002420 if (v instanceof Workspace) {
2421 if (mWorkspace.isInOverviewMode()) {
2422 mWorkspace.exitOverviewMode(true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002423 }
2424 return;
2425 }
2426
2427 if (v instanceof CellLayout) {
2428 if (mWorkspace.isInOverviewMode()) {
Michael Jurka336fd4f2013-09-12 00:05:02 +02002429 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
Adam Cohenf358a4b2013-07-23 16:47:31 -07002430 }
2431 }
2432
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002433 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08002434 if (tag instanceof ShortcutInfo) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002435 onClickAppShortcut(v);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002436 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002437 if (v instanceof FolderIcon) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002438 onClickFolderIcon(v);
Adam Cohena9cf38f2011-05-02 15:36:58 -07002439 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002440 } else if (v == mAllAppsButton) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002441 onClickAllAppsButton(v);
Sunny Goyal508da152014-08-14 10:53:27 -07002442 } else if (tag instanceof AppInfo) {
2443 startAppShortcutOrInfoActivity(v);
Sunny Goyalff572272014-07-23 13:58:07 -07002444 } else if (tag instanceof LauncherAppWidgetInfo) {
2445 if (v instanceof PendingAppWidgetHostView) {
2446 onClickPendingWidget((PendingAppWidgetHostView) v);
2447 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002448 }
2449 }
2450
Sunny Goyal508da152014-08-14 10:53:27 -07002451 public void onClickPagedViewIcon(View v) {
2452 startAppShortcutOrInfoActivity(v);
2453 }
2454
Michael Jurka0e260592010-06-30 17:07:39 -07002455 public boolean onTouch(View v, MotionEvent event) {
Michael Jurka0e260592010-06-30 17:07:39 -07002456 return false;
2457 }
2458
Michael Jurkaaf442092010-06-10 17:01:57 -07002459 /**
Sunny Goyalff572272014-07-23 13:58:07 -07002460 * Event handler for the app widget view which has not fully restored.
2461 */
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002462 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
2463 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07002464 if (v.isReadyForClickSetup()) {
Sunny Goyalff572272014-07-23 13:58:07 -07002465 int widgetId = info.appWidgetId;
2466 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2467 if (appWidgetInfo != null) {
2468 mPendingAddWidgetInfo = appWidgetInfo;
2469 mPendingAddInfo.copyFrom(info);
2470 mPendingAddWidgetId = widgetId;
2471
Sunny Goyalffe83f12014-08-14 17:39:34 -07002472 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2473 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
Sunny Goyalff572272014-07-23 13:58:07 -07002474 }
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002475 } else if (info.installProgress < 0) {
2476 // The install has not been queued
2477 final String packageName = info.providerName.getPackageName();
2478 showBrokenAppInstallDialog(packageName,
2479 new DialogInterface.OnClickListener() {
2480 public void onClick(DialogInterface dialog, int id) {
2481 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2482 }
2483 });
2484 } else {
2485 // Download has started.
2486 final String packageName = info.providerName.getPackageName();
2487 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
Sunny Goyalff572272014-07-23 13:58:07 -07002488 }
2489 }
2490
2491 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002492 * Event handler for the search button
2493 *
2494 * @param v The view that was clicked.
2495 */
2496 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002497 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2498
Amith Yamasania135ba82011-08-09 17:42:01 -07002499 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002500 }
2501
2502 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002503 * Event handler for the voice button
2504 *
2505 * @param v The view that was clicked.
2506 */
2507 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002508 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002509
Bjorn Bringertc459e522013-06-07 19:36:01 +01002510 startVoice();
2511 }
2512
2513 public void startVoice() {
Michael Jurkaae65ee32012-04-30 11:45:54 -07002514 try {
2515 final SearchManager searchManager =
2516 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2517 ComponentName activityName = searchManager.getGlobalSearchActivity();
2518 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002519 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002520 if (activityName != null) {
2521 intent.setPackage(activityName.getPackageName());
2522 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002523 startActivity(null, intent, "onClickVoiceButton");
Michael Jurkaae65ee32012-04-30 11:45:54 -07002524 } catch (ActivityNotFoundException e) {
2525 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Andy Huangf615f712012-06-07 13:38:04 -07002526 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Michael Jurkaae65ee32012-04-30 11:45:54 -07002527 startActivitySafely(null, intent, "onClickVoiceButton");
2528 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002529 }
2530
2531 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002532 * Event handler for the "grid" button that appears on the home screen, which
2533 * enters all apps mode.
2534 *
2535 * @param v The view that was clicked.
2536 */
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002537 protected void onClickAllAppsButton(View v) {
2538 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2539 if (isAllAppsVisible()) {
2540 showWorkspace(true);
2541 } else {
2542 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2543 }
2544 }
2545
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002546 private void showBrokenAppInstallDialog(final String packageName,
2547 DialogInterface.OnClickListener onSearchClickListener) {
2548 new AlertDialog.Builder(this)
2549 .setTitle(R.string.abandoned_promises_title)
2550 .setMessage(R.string.abandoned_promise_explanation)
2551 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2552 .setNeutralButton(R.string.abandoned_clean_this,
2553 new DialogInterface.OnClickListener() {
2554 public void onClick(DialogInterface dialog, int id) {
2555 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2556 mWorkspace.removeAbandonedPromise(packageName, user);
2557 }
2558 })
2559 .create().show();
2560 return;
2561 }
2562
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002563 /**
2564 * Event handler for an app shortcut click.
2565 *
2566 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2567 */
Chris Wren40c5ed32014-06-24 18:24:23 -04002568 protected void onClickAppShortcut(final View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002569 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2570 Object tag = v.getTag();
2571 if (!(tag instanceof ShortcutInfo)) {
2572 throw new IllegalArgumentException("Input must be a Shortcut");
2573 }
2574
2575 // Open shortcut
2576 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2577 final Intent intent = shortcut.intent;
2578
2579 // Check for special shortcuts
2580 if (intent.getComponent() != null) {
2581 final String shortcutClass = intent.getComponent().getClassName();
2582
2583 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2584 MemoryDumpActivity.startDump(this);
2585 return;
2586 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2587 toggleShowWeightWatcher();
2588 return;
2589 }
2590 }
2591
Chris Wren40c5ed32014-06-24 18:24:23 -04002592 // Check for abandoned promise
Sunny Goyal34942622014-08-29 17:20:55 -07002593 if ((v instanceof BubbleTextView)
2594 && shortcut.isPromise()
2595 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
Sunny Goyale7b8cd92014-08-27 14:04:33 -07002596 showBrokenAppInstallDialog(
Sunny Goyal34942622014-08-29 17:20:55 -07002597 shortcut.getTargetComponent().getPackageName(),
Chris Wren40c5ed32014-06-24 18:24:23 -04002598 new DialogInterface.OnClickListener() {
2599 public void onClick(DialogInterface dialog, int id) {
Sunny Goyal508da152014-08-14 10:53:27 -07002600 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002601 }
Chris Wren40c5ed32014-06-24 18:24:23 -04002602 });
Chris Wren40c5ed32014-06-24 18:24:23 -04002603 return;
2604 }
2605
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002606 // Start activities
Sunny Goyal508da152014-08-14 10:53:27 -07002607 startAppShortcutOrInfoActivity(v);
Chris Wren40c5ed32014-06-24 18:24:23 -04002608 }
2609
Sunny Goyal508da152014-08-14 10:53:27 -07002610 private void startAppShortcutOrInfoActivity(View v) {
Chris Wren40c5ed32014-06-24 18:24:23 -04002611 Object tag = v.getTag();
Sunny Goyal508da152014-08-14 10:53:27 -07002612 final ShortcutInfo shortcut;
2613 final Intent intent;
2614 if (tag instanceof ShortcutInfo) {
2615 shortcut = (ShortcutInfo) tag;
2616 intent = shortcut.intent;
2617 int[] pos = new int[2];
2618 v.getLocationOnScreen(pos);
2619 intent.setSourceBounds(new Rect(pos[0], pos[1],
2620 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Chris Wren40c5ed32014-06-24 18:24:23 -04002621
Sunny Goyal508da152014-08-14 10:53:27 -07002622 } else if (tag instanceof AppInfo) {
2623 shortcut = null;
2624 intent = ((AppInfo) tag).intent;
2625 } else {
2626 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2627 }
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002628
2629 boolean success = startActivitySafely(v, intent, tag);
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002630 mStats.recordLaunch(intent, shortcut);
2631
2632 if (success && v instanceof BubbleTextView) {
2633 mWaitingForResume = (BubbleTextView) v;
2634 mWaitingForResume.setStayPressed(true);
2635 }
2636 }
2637
2638 /**
2639 * Event handler for a folder icon click.
2640 *
2641 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2642 */
2643 protected void onClickFolderIcon(View v) {
2644 if (LOGD) Log.d(TAG, "onClickFolder");
2645 if (!(v instanceof FolderIcon)){
2646 throw new IllegalArgumentException("Input must be a FolderIcon");
2647 }
2648
2649 FolderIcon folderIcon = (FolderIcon) v;
2650 final FolderInfo info = folderIcon.getFolderInfo();
2651 Folder openFolder = mWorkspace.getFolderForTag(info);
2652
2653 // If the folder info reports that the associated folder is open, then verify that
2654 // it is actually opened. There have been a few instances where this gets out of sync.
2655 if (info.opened && openFolder == null) {
2656 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2657 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2658 info.opened = false;
2659 }
2660
2661 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2662 // Close any open folder
2663 closeFolder();
2664 // Open the requested folder
2665 openFolder(folderIcon);
2666 } else {
2667 // Find the open folder...
2668 int folderScreen;
2669 if (openFolder != null) {
2670 folderScreen = mWorkspace.getPageForView(openFolder);
2671 // .. and close it
2672 closeFolder(openFolder);
2673 if (folderScreen != mWorkspace.getCurrentPage()) {
2674 // Close any folder open on the current screen
2675 closeFolder();
2676 // Pull the folder onto this screen
2677 openFolder(folderIcon);
2678 }
2679 }
2680 }
Michael Jurka5130e402011-10-13 04:55:35 -07002681 }
2682
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002683 /**
2684 * Event handler for the (Add) Widgets button that appears after a long press
2685 * on the home screen.
2686 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002687 protected void onClickAddWidgetButton(View view) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002688 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
Sandeep Siddharthad8058372014-01-28 10:41:15 -08002689 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2690 }
2691
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002692 /**
2693 * Event handler for the wallpaper picker button that appears after a long press
2694 * on the home screen.
2695 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002696 protected void onClickWallpaperPicker(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002697 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2698 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2699 pickWallpaper.setComponent(getWallpaperPickerComponent());
2700 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2701 }
2702
2703 /**
2704 * Event handler for a click on the settings button that appears after a long press
2705 * on the home screen.
2706 */
Anjali Koppal7b168a12014-03-04 17:16:11 -08002707 protected void onClickSettingsButton(View v) {
Sandeep Siddharthaa9420302014-02-12 18:24:31 -08002708 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2709 }
2710
Michael Jurka5130e402011-10-13 04:55:35 -07002711 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07002712 // Provide the same haptic feedback that the system offers for virtual keys.
2713 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002714 }
2715
Adam Cohen61f560d2013-09-30 15:58:20 -07002716 public void performHapticFeedbackOnTouchDown(View v) {
2717 // Provide the same haptic feedback that the system offers for virtual keys.
2718 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2719 }
2720
2721 public View.OnTouchListener getHapticFeedbackTouchListener() {
2722 if (mHapticFeedbackTouchListener == null) {
2723 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2724 @Override
2725 public boolean onTouch(View v, MotionEvent event) {
2726 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2727 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2728 }
2729 return false;
2730 }
2731 };
2732 }
2733 return mHapticFeedbackTouchListener;
2734 }
2735
Anjali Koppal62d18ed2014-03-10 17:04:03 -07002736 public void onDragStarted(View view) {}
2737
Sandeep Siddharthaab2d9d72013-09-17 13:18:24 -07002738 /**
2739 * Called when the user stops interacting with the launcher.
2740 * This implies that the user is now on the homescreen and is not doing housekeeping.
2741 */
2742 protected void onInteractionEnd() {}
2743
2744 /**
2745 * Called when the user starts interacting with the launcher.
2746 * The possible interactions are:
2747 * - open all apps
2748 * - reorder an app shortcut, or a widget
2749 * - open the overview mode.
2750 * This is a good time to stop doing things that only make sense
2751 * when the user is on the homescreen and not doing housekeeping.
2752 */
2753 protected void onInteractionBegin() {}
2754
Kenny Guyf07af7b2014-07-31 11:39:16 +01002755 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002756 String packageName = componentName.getPackageName();
Kenny Guyf07af7b2014-07-31 11:39:16 +01002757 try {
2758 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2759 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2760 launcherApps.showAppDetailsForProfile(componentName, user);
2761 } catch (SecurityException e) {
2762 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2763 Log.e(TAG, "Launcher does not have permission to launch settings");
2764 } catch (ActivityNotFoundException e) {
2765 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2766 Log.e(TAG, "Unable to launch settings");
2767 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002768 }
2769
Michael Jurka1e2f4652013-07-08 18:03:46 -07002770 // returns true if the activity was started
Kenny Guyd31df542014-06-30 15:12:11 +01002771 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2772 UserHandleCompat user) {
Michael Jurkaeadbfc52013-09-04 00:45:37 +02002773 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
Patrick Dubroy5539af72010-09-07 15:22:01 -07002774 // System applications cannot be installed. For now, show a toast explaining that.
2775 // We may give them the option of disabling apps this way.
2776 int messageId = R.string.uninstall_system_app_text;
2777 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
Michael Jurka1e2f4652013-07-08 18:03:46 -07002778 return false;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002779 } else {
Michael Jurka1e2f4652013-07-08 18:03:46 -07002780 String packageName = componentName.getPackageName();
2781 String className = componentName.getClassName();
Patrick Dubroy5539af72010-09-07 15:22:01 -07002782 Intent intent = new Intent(
2783 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07002784 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2785 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Kenny Guyd31df542014-06-30 15:12:11 +01002786 if (user != null) {
2787 user.addToIntent(intent, Intent.EXTRA_USER);
2788 }
Patrick Dubroy5539af72010-09-07 15:22:01 -07002789 startActivity(intent);
Michael Jurka1e2f4652013-07-08 18:03:46 -07002790 return true;
Patrick Dubroy5539af72010-09-07 15:22:01 -07002791 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002792 }
2793
Michael Jurka86a720e2012-05-09 11:23:23 -07002794 boolean startActivity(View v, Intent intent, Object tag) {
Kenny Guyb6cc40b2014-05-13 15:58:58 +01002795 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002796 try {
Winson Chung2672ff92012-05-04 16:22:30 -07002797 // Only launch using the new animation if the shortcut has not opted out (this is a
2798 // private contract between launcher and may be ignored in the future).
2799 boolean useLaunchAnimation = (v != null) &&
2800 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
Kenny Guyed131872014-04-30 03:02:21 +01002801 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2802 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyed131872014-04-30 03:02:21 +01002803
Kenny Guy1317e2d2014-05-08 18:52:50 +01002804 UserHandleCompat user = null;
2805 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2806 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2807 user = userManager.getUserForSerialNumber(serialNumber);
2808 }
2809
2810 Bundle optsBundle = null;
Winson Chung2672ff92012-05-04 16:22:30 -07002811 if (useLaunchAnimation) {
Adam Cohen4da294d2014-07-28 10:56:19 -07002812 ActivityOptions opts = Utilities.isLmp() ?
2813 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) :
2814 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Adam Cohen6ea3b112014-06-11 11:38:49 -07002815 optsBundle = opts.toBundle();
2816 }
Kenny Guy1317e2d2014-05-08 18:52:50 +01002817
2818 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2819 // Could be launching some bookkeeping activity
2820 startActivity(intent, optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002821 } else {
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002822 // TODO Component can be null when shortcuts are supported for secondary user
Kenny Guyc2bd8102014-06-30 12:30:31 +01002823 launcherApps.startActivityForProfile(intent.getComponent(), user,
2824 intent.getSourceBounds(), optsBundle);
Winson Chungc7450e32012-04-17 17:34:08 -07002825 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002826 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002827 } catch (SecurityException e) {
2828 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002829 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002830 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002831 "or use the exported attribute for this activity. "
2832 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002833 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08002834 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002835 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002836
Michael Jurka86a720e2012-05-09 11:23:23 -07002837 boolean startActivitySafely(View v, Intent intent, Object tag) {
2838 boolean success = false;
Sunny Goyalc5c60ad2014-07-14 12:02:01 -07002839 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2840 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2841 return false;
2842 }
Michael Jurka86a720e2012-05-09 11:23:23 -07002843 try {
2844 success = startActivity(v, intent, tag);
2845 } catch (ActivityNotFoundException e) {
2846 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2847 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2848 }
2849 return success;
2850 }
2851
Adam Cohen268c4752012-06-06 17:47:33 -07002852 /**
2853 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2854 * in the DragLayer in the exact absolute location of the original FolderIcon.
2855 */
2856 private void copyFolderIconToImage(FolderIcon fi) {
2857 final int width = fi.getMeasuredWidth();
2858 final int height = fi.getMeasuredHeight();
2859
2860 // Lazy load ImageView, Bitmap and Canvas
2861 if (mFolderIconImageView == null) {
2862 mFolderIconImageView = new ImageView(this);
2863 }
2864 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2865 mFolderIconBitmap.getHeight() != height) {
2866 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2867 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2868 }
2869
2870 DragLayer.LayoutParams lp;
2871 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2872 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2873 } else {
2874 lp = new DragLayer.LayoutParams(width, height);
2875 }
2876
Adam Cohen307fe232012-08-16 17:55:58 -07002877 // The layout from which the folder is being opened may be scaled, adjust the starting
2878 // view size by this scale factor.
2879 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
Adam Cohen268c4752012-06-06 17:47:33 -07002880 lp.customPosition = true;
2881 lp.x = mRectForFolderAnimation.left;
2882 lp.y = mRectForFolderAnimation.top;
Adam Cohen307fe232012-08-16 17:55:58 -07002883 lp.width = (int) (scale * width);
2884 lp.height = (int) (scale * height);
Adam Cohen268c4752012-06-06 17:47:33 -07002885
2886 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2887 fi.draw(mFolderIconCanvas);
2888 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
Adam Cohenfb91f302012-06-11 15:45:18 -07002889 if (fi.getFolder() != null) {
2890 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2891 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
Adam Cohen8ec23032012-06-08 14:46:22 -07002892 }
Adam Cohen268c4752012-06-06 17:47:33 -07002893 // Just in case this image view is still in the drag layer from a previous animation,
2894 // we remove it and re-add it.
2895 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2896 mDragLayer.removeView(mFolderIconImageView);
2897 }
2898 mDragLayer.addView(mFolderIconImageView, lp);
Adam Cohenfb91f302012-06-11 15:45:18 -07002899 if (fi.getFolder() != null) {
2900 fi.getFolder().bringToFront();
Adam Cohen8ec23032012-06-08 14:46:22 -07002901 }
Adam Cohen268c4752012-06-06 17:47:33 -07002902 }
2903
Adam Cohen2801caf2011-05-13 20:57:39 -07002904 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002905 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002906 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2907 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2908 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2909
Adam Cohenc51934b2011-07-26 21:07:43 -07002910 FolderInfo info = (FolderInfo) fi.getTag();
2911 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2912 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07002913 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2914 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07002915 }
2916
Adam Cohen268c4752012-06-06 17:47:33 -07002917 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2918 copyFolderIconToImage(fi);
2919 fi.setVisibility(View.INVISIBLE);
2920
Michael Jurka2ecf9952012-06-18 12:52:28 -07002921 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002922 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002923 if (Utilities.isLmp()) {
2924 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
2925 }
2926 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohen2801caf2011-05-13 20:57:39 -07002927 oa.start();
2928 }
2929
Adam Cohen268c4752012-06-06 17:47:33 -07002930 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07002931 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07002932 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
2933 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
2934 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
2935
Adam Cohen268c4752012-06-06 17:47:33 -07002936 final CellLayout cl = (CellLayout) fi.getParent().getParent();
Adam Cohenc51934b2011-07-26 21:07:43 -07002937
Adam Cohen268c4752012-06-06 17:47:33 -07002938 // We remove and re-draw the FolderIcon in-case it has changed
2939 mDragLayer.removeView(mFolderIconImageView);
2940 copyFolderIconToImage(fi);
Michael Jurka2ecf9952012-06-18 12:52:28 -07002941 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
Adam Cohen268c4752012-06-06 17:47:33 -07002942 scaleX, scaleY);
Adam Cohenc4fe9ea2014-08-18 18:54:10 -07002943 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07002944 oa.addListener(new AnimatorListenerAdapter() {
2945 @Override
2946 public void onAnimationEnd(Animator animation) {
Adam Cohen268c4752012-06-06 17:47:33 -07002947 if (cl != null) {
2948 cl.clearFolderLeaveBehind();
2949 // Remove the ImageView copy of the FolderIcon and make the original visible.
2950 mDragLayer.removeView(mFolderIconImageView);
2951 fi.setVisibility(View.VISIBLE);
Adam Cohenc51934b2011-07-26 21:07:43 -07002952 }
2953 }
2954 });
Adam Cohen2801caf2011-05-13 20:57:39 -07002955 oa.start();
2956 }
2957
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002958 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002959 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002960 * is animated relative to the specified View. If the View is null, no animation
2961 * is played.
2962 *
2963 * @param folderInfo The FolderInfo describing the folder to open.
2964 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07002965 public void openFolder(FolderIcon folderIcon) {
Adam Cohenfb91f302012-06-11 15:45:18 -07002966 Folder folder = folderIcon.getFolder();
Adam Cohena9cf38f2011-05-02 15:36:58 -07002967 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002968
Adam Cohena9cf38f2011-05-02 15:36:58 -07002969 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002970
Adam Cohen4554ee12011-08-03 16:13:21 -07002971 // Just verify that the folder hasn't already been added to the DragLayer.
2972 // There was a one-off crash where the folder had a parent already.
2973 if (folder.getParent() == null) {
2974 mDragLayer.addView(folder);
2975 mDragController.addDropTarget((DropTarget) folder);
2976 } else {
2977 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
2978 folder.getParent() + ").");
2979 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07002980 folder.animateOpen();
Adam Cohen268c4752012-06-06 17:47:33 -07002981 growAndFadeOutFolderIcon(folderIcon);
Winson Chung83ca4802013-04-12 15:10:52 -07002982
2983 // Notify the accessibility manager that this folder "window" has appeared and occluded
2984 // the workspace items
2985 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
2986 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Adam Cohen4554ee12011-08-03 16:13:21 -07002987 }
2988
2989 public void closeFolder() {
Adam Cohen37c717f2013-11-26 11:50:15 -08002990 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
Adam Cohen4554ee12011-08-03 16:13:21 -07002991 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07002992 if (folder.isEditingName()) {
2993 folder.dismissEditingName();
2994 }
Adam Cohen4554ee12011-08-03 16:13:21 -07002995 closeFolder(folder);
2996 }
2997 }
2998
2999 void closeFolder(Folder folder) {
3000 folder.getInfo().opened = false;
3001
3002 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3003 if (parent != null) {
3004 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3005 shrinkAndFadeInFolderIcon(fi);
3006 }
3007 folder.animateClosed();
Winson Chung83ca4802013-04-12 15:10:52 -07003008
3009 // Notify the accessibility manager that this folder "window" has disappeard and no
3010 // longer occludeds the workspace items
3011 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003012 }
3013
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003014 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -07003015 if (!isDraggingEnabled()) return false;
3016 if (isWorkspaceLocked()) return false;
3017 if (mState != State.WORKSPACE) return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003018
Adam Cohen1697b792013-09-17 19:08:21 -07003019 if (v instanceof Workspace) {
3020 if (!mWorkspace.isInOverviewMode()) {
Adam Cohen93c97562013-09-26 13:48:01 -07003021 if (mWorkspace.enterOverviewMode()) {
3022 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3023 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3024 return true;
3025 } else {
3026 return false;
3027 }
Adam Cohenaa4c8c12014-06-06 11:52:52 -07003028 } else {
3029 return false;
Adam Cohen1697b792013-09-17 19:08:21 -07003030 }
Adam Cohen1697b792013-09-17 19:08:21 -07003031 }
3032
Adam Cohene0aaa0d2014-05-12 12:44:22 -07003033 CellLayout.CellInfo longClickCellInfo = null;
3034 View itemUnderLongClick = null;
3035 if (v.getTag() instanceof ItemInfo) {
3036 ItemInfo info = (ItemInfo) v.getTag();
3037 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3038 itemUnderLongClick = longClickCellInfo.cell;
3039 resetAddInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003040 }
3041
Winson Chung3d503fb2011-07-13 17:25:49 -07003042 // The hotseat touch handling does not go through Workspace, and we always allow long press
3043 // on hotseat items.
Dan Sandlere26d0942014-01-13 14:30:14 -05003044 final boolean inHotseat = isHotseatLayout(v);
3045 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
Winson Chung3d503fb2011-07-13 17:25:49 -07003046 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07003047 if (itemUnderLongClick == null) {
Adam Cohend3ecce92013-09-16 14:58:00 -07003048 // User long pressed on empty space
3049 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3050 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Adam Cohend3ecce92013-09-16 14:58:00 -07003051 if (mWorkspace.isInOverviewMode()) {
3052 mWorkspace.startReordering(v);
3053 } else {
3054 mWorkspace.enterOverviewMode();
Adam Cohendedbd962013-07-11 14:21:49 -07003055 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003056 } else {
Dan Sandlere26d0942014-01-13 14:30:14 -05003057 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3058 mHotseat.getOrderInHotseat(
3059 longClickCellInfo.cellX,
3060 longClickCellInfo.cellY));
3061 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003062 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07003063 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003064 }
3065 }
3066 }
3067 return true;
3068 }
3069
Winson Chung3d503fb2011-07-13 17:25:49 -07003070 boolean isHotseatLayout(View layout) {
3071 return mHotseat != null && layout != null &&
3072 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3073 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08003074
Winson Chung3d503fb2011-07-13 17:25:49 -07003075 /**
3076 * Returns the CellLayout of the specified container at the specified screen.
3077 */
Adam Cohendcd297f2013-06-18 13:13:40 -07003078 CellLayout getCellLayout(long container, long screenId) {
Winson Chung3d503fb2011-07-13 17:25:49 -07003079 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3080 if (mHotseat != null) {
3081 return mHotseat.getLayout();
3082 } else {
3083 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08003084 }
Winson Chung3d503fb2011-07-13 17:25:49 -07003085 } else {
Adam Cohendcd297f2013-06-18 13:13:40 -07003086 return (CellLayout) mWorkspace.getScreenWithId(screenId);
Romain Guya6abce82009-11-10 02:54:41 -08003087 }
3088 }
3089
Daniel Sandler843e8602010-06-07 14:59:01 -04003090 public boolean isAllAppsVisible() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003091 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04003092 }
3093
Craig Mautner360310b2012-10-26 15:13:08 -07003094 private void setWorkspaceBackground(boolean workspace) {
3095 mLauncherView.setBackground(workspace ?
Michael Jurka496fefb2013-05-06 15:39:11 +02003096 mWorkspaceBackgroundDrawable : null);
Craig Mautner360310b2012-10-26 15:13:08 -07003097 }
3098
Selim Cinek3a8a8f72014-01-16 10:38:38 -08003099 protected void changeWallpaperVisiblity(boolean visible) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003100 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3101 int curflags = getWindow().getAttributes().flags
3102 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3103 if (wpflags != curflags) {
3104 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3105 }
Craig Mautner360310b2012-10-26 15:13:08 -07003106 setWorkspaceBackground(visible);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07003107 }
3108
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003109 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3110 if (v instanceof LauncherTransitionable) {
3111 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3112 }
3113 }
3114
Michael Jurkabed61d22012-02-14 22:51:29 -08003115 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3116 if (v instanceof LauncherTransitionable) {
3117 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3118 }
Winson Chung70442722012-02-10 15:43:22 -08003119
3120 // Update the workspace transition step as well
3121 dispatchOnLauncherTransitionStep(v, 0f);
3122 }
3123
3124 private void dispatchOnLauncherTransitionStep(View v, float t) {
3125 if (v instanceof LauncherTransitionable) {
3126 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3127 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003128 }
3129
3130 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3131 if (v instanceof LauncherTransitionable) {
3132 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3133 }
Winson Chung70442722012-02-10 15:43:22 -08003134
3135 // Update the workspace transition step as well
3136 dispatchOnLauncherTransitionStep(v, 1f);
Michael Jurkabed61d22012-02-14 22:51:29 -08003137 }
3138
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003139 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07003140 * Things to test when changing the following seven functions.
3141 * - Home from workspace
3142 * - from center screen
3143 * - from other screens
3144 * - Home from all apps
3145 * - from center screen
3146 * - from other screens
3147 * - Back from all apps
3148 * - from center screen
3149 * - from other screens
3150 * - Launch app from workspace and quit
3151 * - with back
3152 * - with home
3153 * - Launch app from all apps and quit
3154 * - with back
3155 * - with home
3156 * - Go to a screen that's not the default, then all
3157 * apps, and launch and app, and go back
3158 * - with back
3159 * -with home
3160 * - On workspace, long press power and go back
3161 * - with back
3162 * - with home
3163 * - On all apps, long press power and go back
3164 * - with back
3165 * - with home
3166 * - On workspace, power off
3167 * - On all apps, power off
3168 * - Launch an app and turn off the screen while in that app
3169 * - Go back with home key
3170 * - Go back with back key TODO: make this not go to workspace
3171 * - From all apps
3172 * - From workspace
3173 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3174 * - From all apps
3175 * - From the center workspace
3176 * - From another workspace
3177 */
3178
3179 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003180 * Zoom the camera out from the workspace to reveal 'toView'.
3181 * Assumes that the view to show is anchored at either the very top or very bottom
3182 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003183 */
Michael Jurkabed61d22012-02-14 22:51:29 -08003184 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Winson Chungc58497e2013-09-03 17:48:37 -07003185 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3186 showAppsCustomizeHelper(animated, springLoaded, contentType);
3187 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003188
Winson Chungc58497e2013-09-03 17:48:37 -07003189 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3190 final AppsCustomizePagedView.ContentType contentType) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003191 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003192 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003193 mStateAnimation.cancel();
3194 mStateAnimation = null;
3195 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003196
3197 boolean material = Utilities.isLmp();
3198
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003199 final Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003200
Winson Chungf0ea4d32011-06-06 14:27:16 -07003201 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3202 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003203 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003204 final int itemsAlphaStagger =
3205 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003206
Winson Chungf0ea4d32011-06-06 14:27:16 -07003207 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurkabed61d22012-02-14 22:51:29 -08003208 final View fromView = mWorkspace;
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003209 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
Patrick Dubroy558654c2010-07-23 16:48:11 -07003210
Adam Cohen2854d252014-08-27 16:04:07 -07003211 final ArrayList<View> layerViews = new ArrayList<View>();
3212
Adam Cohen6c5891a2014-07-09 23:53:15 -07003213 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3214 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003215 Animator workspaceAnim =
Adam Cohen2854d252014-08-27 16:04:07 -07003216 mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews);
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08003217 if (!LauncherAppState.isDisableAllApps()
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08003218 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3219 // Set the content type for the all apps/widgets space
Winson Chungc58497e2013-09-03 17:48:37 -07003220 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3221 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003222
Adam Cohena38dc902014-09-07 17:48:55 +02003223 // If for some reason our views aren't initialized, don't animate
3224 boolean initialized = getAllAppsButton() != null;
3225
3226 if (animated && initialized) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003227 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen9bfdb762014-07-21 17:44:06 -07003228 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3229 toView.findViewById(R.id.apps_customize_pane_content);
Adam Cohenf16e5712011-01-13 13:31:45 -08003230
Adam Cohen9bfdb762014-07-21 17:44:06 -07003231 final View page = content.getPageAt(content.getCurrentPage());
3232 final View revealView = toView.findViewById(R.id.fake_page);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003233
Adam Cohen63f1ec02014-08-12 09:23:13 -07003234 final float initialPanelAlpha = 1f;
3235
3236 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3237 if (isWidgetTray) {
Adam Cohen4e243a22014-08-10 18:30:55 -07003238 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3239 } else {
3240 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3241 }
3242
Adam Cohen9bfdb762014-07-21 17:44:06 -07003243 // Hide the real page background, and swap in the fake one
Adam Cohen9bfdb762014-07-21 17:44:06 -07003244 content.setPageBackgroundsVisible(false);
Adam Cohen2854d252014-08-27 16:04:07 -07003245 revealView.setVisibility(View.VISIBLE);
3246 // We need to hide this view as the animation start will be posted.
3247 revealView.setAlpha(0);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003248
Adam Cohen9bfdb762014-07-21 17:44:06 -07003249 int width = revealView.getMeasuredWidth();
3250 int height = revealView.getMeasuredHeight();
Adam Cohen9bfdb762014-07-21 17:44:06 -07003251 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
Adam Cohen2854d252014-08-27 16:04:07 -07003252
Adam Cohen63f1ec02014-08-12 09:23:13 -07003253 revealView.setTranslationY(0);
Adam Cohen94afab42014-08-24 16:10:54 -07003254 revealView.setTranslationX(0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003255
Adam Cohen63f1ec02014-08-12 09:23:13 -07003256 // Get the y delta between the center of the page and the center of the all apps button
3257 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3258 getAllAppsButton(), null);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003259
Adam Cohen2854d252014-08-27 16:04:07 -07003260 float alpha = 0;
3261 float xDrift = 0;
3262 float yDrift = 0;
3263 if (material) {
3264 alpha = isWidgetTray ? 0.3f : 1f;
3265 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3266 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3267 } else {
3268 yDrift = 2 * height / 3;
3269 xDrift = 0;
3270 }
3271 final float initAlpha = alpha;
3272
Adam Cohen9bfdb762014-07-21 17:44:06 -07003273 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen2854d252014-08-27 16:04:07 -07003274 layerViews.add(revealView);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003275 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
Adam Cohen94afab42014-08-24 16:10:54 -07003276 PropertyValuesHolder panelDriftY =
Adam Cohen63f1ec02014-08-12 09:23:13 -07003277 PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
Adam Cohen94afab42014-08-24 16:10:54 -07003278 PropertyValuesHolder panelDriftX =
3279 PropertyValuesHolder.ofFloat("translationX", xDrift, 0);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003280
Adam Cohen2854d252014-08-27 16:04:07 -07003281 ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView,
3282 panelAlpha, panelDriftY, panelDriftX);
3283
Adam Cohen9bfdb762014-07-21 17:44:06 -07003284 panelAlphaAndDrift.setDuration(revealDuration);
3285 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen6c5891a2014-07-09 23:53:15 -07003286
Adam Cohen9bfdb762014-07-21 17:44:06 -07003287 mStateAnimation.play(panelAlphaAndDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003288
Adam Cohen4e243a22014-08-10 18:30:55 -07003289 if (page != null) {
3290 page.setVisibility(View.VISIBLE);
3291 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Adam Cohen2854d252014-08-27 16:04:07 -07003292 layerViews.add(page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003293
Adam Cohen2854d252014-08-27 16:04:07 -07003294 ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0);
3295 page.setTranslationY(yDrift);
Adam Cohen4e243a22014-08-10 18:30:55 -07003296 pageDrift.setDuration(revealDuration);
3297 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003298 pageDrift.setStartDelay(itemsAlphaStagger);
Adam Cohen4e243a22014-08-10 18:30:55 -07003299 mStateAnimation.play(pageDrift);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003300
Adam Cohen63f1ec02014-08-12 09:23:13 -07003301 page.setAlpha(0f);
Adam Cohen2854d252014-08-27 16:04:07 -07003302 ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f);
Adam Cohen4e243a22014-08-10 18:30:55 -07003303 itemsAlpha.setDuration(revealDuration);
3304 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3305 itemsAlpha.setStartDelay(itemsAlphaStagger);
3306 mStateAnimation.play(itemsAlpha);
3307 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003308
Adam Cohen4e243a22014-08-10 18:30:55 -07003309 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3310 pageIndicators.setAlpha(0.01f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003311 ObjectAnimator indicatorsAlpha =
Adam Cohen2854d252014-08-27 16:04:07 -07003312 ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003313 indicatorsAlpha.setDuration(revealDuration);
3314 mStateAnimation.play(indicatorsAlpha);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003315
Adam Cohen9bfdb762014-07-21 17:44:06 -07003316 if (material) {
Adam Cohen63f1ec02014-08-12 09:23:13 -07003317 final View allApps = getAllAppsButton();
3318 int allAppsButtonSize = LauncherAppState.getInstance().
3319 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3320 float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
Adam Cohen2854d252014-08-27 16:04:07 -07003321 Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2,
Adam Cohen63f1ec02014-08-12 09:23:13 -07003322 height / 2, startRadius, revealRadius);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003323 reveal.setDuration(revealDuration);
3324 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003325
3326 reveal.addListener(new AnimatorListenerAdapter() {
3327 public void onAnimationStart(Animator animation) {
3328 if (!isWidgetTray) {
3329 allApps.setVisibility(View.INVISIBLE);
3330 }
3331 }
3332 public void onAnimationEnd(Animator animation) {
3333 if (!isWidgetTray) {
3334 allApps.setVisibility(View.VISIBLE);
3335 }
3336 }
3337 });
Adam Cohen6c5891a2014-07-09 23:53:15 -07003338 mStateAnimation.play(reveal);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003339 }
Michael Jurka1899a362011-11-03 13:50:45 -07003340
Adam Cohen9bfdb762014-07-21 17:44:06 -07003341 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3342 @Override
3343 public void onAnimationEnd(Animator animation) {
3344 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3345 dispatchOnLauncherTransitionEnd(toView, animated, false);
3346
3347 revealView.setVisibility(View.INVISIBLE);
3348 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003349 if (page != null) {
3350 page.setLayerType(View.LAYER_TYPE_NONE, null);
3351 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003352 content.setPageBackgroundsVisible(true);
3353
3354 // Hide the search bar
3355 if (mSearchDropTargetBar != null) {
3356 mSearchDropTargetBar.hideSearchBar(false);
3357 }
3358 }
3359
Adam Cohen9bfdb762014-07-21 17:44:06 -07003360 });
3361
Adam Cohen6c5891a2014-07-09 23:53:15 -07003362 if (workspaceAnim != null) {
3363 mStateAnimation.play(workspaceAnim);
3364 }
Adam Cohen2854d252014-08-27 16:04:07 -07003365
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003366 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3367 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003368 final AnimatorSet stateAnimation = mStateAnimation;
3369 final Runnable startAnimRunnable = new Runnable() {
3370 public void run() {
3371 // Check that mStateAnimation hasn't changed while
3372 // we waited for a layout/draw pass
3373 if (mStateAnimation != stateAnimation)
3374 return;
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003375 dispatchOnLauncherTransitionStart(fromView, animated, false);
3376 dispatchOnLauncherTransitionStart(toView, animated, false);
Adam Cohen2854d252014-08-27 16:04:07 -07003377
3378 revealView.setAlpha(initAlpha);
3379 if (Utilities.isLmp()) {
3380 for (int i = 0; i < layerViews.size(); i++) {
3381 View v = layerViews.get(i);
Adam Cohen0f668f32014-09-08 19:54:17 +02003382 if (v != null) {
3383 boolean attached = true;
3384 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
3385 attached = v.isAttachedToWindow();
3386 }
3387 if (attached) v.buildLayer();
3388 }
Adam Cohen2854d252014-08-27 16:04:07 -07003389 }
3390 }
3391 mStateAnimation.start();
Michael Jurka3dcd79e2012-05-31 07:50:33 -07003392 }
3393 };
Adam Cohen2854d252014-08-27 16:04:07 -07003394 toView.bringToFront();
3395 toView.setVisibility(View.VISIBLE);
3396 toView.post(startAnimRunnable);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003397 } else {
3398 toView.setTranslationX(0.0f);
3399 toView.setTranslationY(0.0f);
3400 toView.setScaleX(1.0f);
3401 toView.setScaleY(1.0f);
3402 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07003403 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07003404
Daniel Sandlere4f98912013-06-25 15:13:26 -04003405 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungc7d2b602012-05-16 17:02:20 -07003406 // Hide the search bar
Winson Chungadf0c182012-08-23 14:59:07 -07003407 if (mSearchDropTargetBar != null) {
3408 mSearchDropTargetBar.hideSearchBar(false);
3409 }
Michael Jurkaabded662011-03-04 12:06:57 -08003410 }
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003411 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003412 dispatchOnLauncherTransitionStart(fromView, animated, false);
3413 dispatchOnLauncherTransitionEnd(fromView, animated, false);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003414 dispatchOnLauncherTransitionPrepare(toView, animated, false);
Michael Jurkabed61d22012-02-14 22:51:29 -08003415 dispatchOnLauncherTransitionStart(toView, animated, false);
3416 dispatchOnLauncherTransitionEnd(toView, animated, false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003417 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003418 }
3419
3420 /**
3421 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07003422 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07003423 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003424 */
Adam Cohened307df2013-10-02 09:37:31 -07003425 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
Adam Cohened66b2b2012-01-23 17:28:51 -08003426 final boolean springLoaded, final Runnable onCompleteRunnable) {
Michael Jurkabed61d22012-02-14 22:51:29 -08003427
Michael Jurkab3e22d92011-10-31 15:58:33 -07003428 if (mStateAnimation != null) {
Michael Jurkaf1ad6082013-03-13 12:55:46 +01003429 mStateAnimation.setDuration(0);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003430 mStateAnimation.cancel();
3431 mStateAnimation = null;
3432 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003433
3434 boolean material = Utilities.isLmp();
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003435 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08003436
Winson Chungf0ea4d32011-06-06 14:27:16 -07003437 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003438 final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Adam Cohen63f1ec02014-08-12 09:23:13 -07003439 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
Adam Cohen9bfdb762014-07-21 17:44:06 -07003440 final int itemsAlphaStagger =
3441 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003442
Winson Chungf0ea4d32011-06-06 14:27:16 -07003443 final float scaleFactor = (float)
3444 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3445 final View fromView = mAppsCustomizeTabHost;
Michael Jurkabed61d22012-02-14 22:51:29 -08003446 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003447 Animator workspaceAnim = null;
Adam Cohen2854d252014-08-27 16:04:07 -07003448 final ArrayList<View> layerViews = new ArrayList<View>();
3449
Adam Cohened307df2013-10-02 09:37:31 -07003450 if (toState == Workspace.State.NORMAL) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003451 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohen2854d252014-08-27 16:04:07 -07003452 toState, animated, layerViews);
Adam Cohened307df2013-10-02 09:37:31 -07003453 } else if (toState == Workspace.State.SPRING_LOADED ||
3454 toState == Workspace.State.OVERVIEW) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003455 workspaceAnim = mWorkspace.getChangeStateAnimation(
Adam Cohen2854d252014-08-27 16:04:07 -07003456 toState, animated, layerViews);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003457 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003458
Adam Cohena38dc902014-09-07 17:48:55 +02003459 // If for some reason our views aren't initialized, don't animate
3460 boolean initialized = getAllAppsButton() != null;
3461
3462 if (animated && initialized) {
Adam Cohen9bfdb762014-07-21 17:44:06 -07003463 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
Adam Cohen2854d252014-08-27 16:04:07 -07003464 if (workspaceAnim != null) {
3465 mStateAnimation.play(workspaceAnim);
3466 }
Michael Jurka159b4cc2012-01-17 03:00:35 -08003467
Adam Cohen9bfdb762014-07-21 17:44:06 -07003468 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3469 fromView.findViewById(R.id.apps_customize_pane_content);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003470
Adam Cohen9bfdb762014-07-21 17:44:06 -07003471 final View page = content.getPageAt(content.getNextPage());
Adam Cohen8e894fa2014-09-08 19:45:43 +02003472
3473 // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases
3474 int count = content.getChildCount();
3475 for (int i = 0; i < count; i++) {
3476 View child = content.getChildAt(i);
3477 if (child != page) {
3478 child.setVisibility(View.INVISIBLE);
3479 }
3480 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003481 final View revealView = fromView.findViewById(R.id.fake_page);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003482
Adam Cohen2854d252014-08-27 16:04:07 -07003483 // hideAppsCustomizeHelper is called in some cases when it is already hidden
3484 // don't perform all these no-op animations. In particularly, this was causing
3485 // the all-apps button to pop in and out.
3486 if (fromView.getVisibility() == View.VISIBLE) {
3487 AppsCustomizePagedView.ContentType contentType = content.getContentType();
3488 final boolean isWidgetTray =
3489 contentType == AppsCustomizePagedView.ContentType.Widgets;
Adam Cohen63f1ec02014-08-12 09:23:13 -07003490
Adam Cohen2854d252014-08-27 16:04:07 -07003491 if (isWidgetTray) {
3492 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3493 } else {
3494 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
Adam Cohen63f1ec02014-08-12 09:23:13 -07003495 }
Adam Cohen6c5891a2014-07-09 23:53:15 -07003496
Adam Cohen2854d252014-08-27 16:04:07 -07003497 int width = revealView.getMeasuredWidth();
3498 int height = revealView.getMeasuredHeight();
3499 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
3500
3501 // Hide the real page background, and swap in the fake one
3502 revealView.setVisibility(View.VISIBLE);
3503 content.setPageBackgroundsVisible(false);
3504
3505 final View allAppsButton = getAllAppsButton();
3506 revealView.setTranslationY(0);
3507 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3508 allAppsButton, null);
3509
3510 float xDrift = 0;
3511 float yDrift = 0;
3512 if (material) {
3513 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3514 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3515 } else {
3516 yDrift = 5 * height / 4;
3517 xDrift = 0;
3518 }
3519
3520 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3521 TimeInterpolator decelerateInterpolator = material ?
3522 new LogDecelerateInterpolator(100, 0) :
3523 new LogDecelerateInterpolator(30, 0);
3524
3525 // The vertical motion of the apps panel should be delayed by one frame
3526 // from the conceal animation in order to give the right feel. We correpsondingly
3527 // shorten the duration so that the slide and conceal end at the same time.
3528 ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY",
3529 0, yDrift);
3530 panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3531 panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3532 panelDriftY.setInterpolator(decelerateInterpolator);
3533 mStateAnimation.play(panelDriftY);
3534
3535 ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX",
3536 0, xDrift);
3537 panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3538 panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3539 panelDriftX.setInterpolator(decelerateInterpolator);
3540 mStateAnimation.play(panelDriftX);
3541
3542 if (isWidgetTray || !material) {
3543 float finalAlpha = material ? 0.4f : 0f;
3544 revealView.setAlpha(1f);
3545 ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha",
3546 1f, finalAlpha);
3547 panelAlpha.setDuration(revealDuration);
3548 panelAlpha.setInterpolator(material ? decelerateInterpolator :
3549 new AccelerateInterpolator(1.5f));
3550 mStateAnimation.play(panelAlpha);
3551 }
3552
3553 if (page != null) {
3554 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3555
3556 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
3557 0, yDrift);
3558 page.setTranslationY(0);
3559 pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3560 pageDrift.setInterpolator(decelerateInterpolator);
3561 pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3562 mStateAnimation.play(pageDrift);
3563
3564 page.setAlpha(1f);
3565 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
3566 itemsAlpha.setDuration(100);
3567 itemsAlpha.setInterpolator(decelerateInterpolator);
3568 mStateAnimation.play(itemsAlpha);
3569 }
3570
3571 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
3572 pageIndicators.setAlpha(1f);
3573 ObjectAnimator indicatorsAlpha =
3574 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
3575 indicatorsAlpha.setDuration(revealDuration);
3576 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3577 mStateAnimation.play(indicatorsAlpha);
3578
3579 width = revealView.getMeasuredWidth();
3580
3581 if (material) {
3582 if (!isWidgetTray) {
3583 allAppsButton.setVisibility(View.INVISIBLE);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003584 }
Adam Cohen2854d252014-08-27 16:04:07 -07003585 int allAppsButtonSize = LauncherAppState.getInstance().
3586 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3587 float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
3588 Animator reveal =
3589 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3590 height / 2, revealRadius, finalRadius);
3591 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3592 reveal.setDuration(revealDuration);
3593 reveal.setStartDelay(itemsAlphaStagger);
Adam Cohen6c5891a2014-07-09 23:53:15 -07003594
Adam Cohen2854d252014-08-27 16:04:07 -07003595 reveal.addListener(new AnimatorListenerAdapter() {
3596 public void onAnimationEnd(Animator animation) {
3597 revealView.setVisibility(View.INVISIBLE);
3598 if (!isWidgetTray) {
3599 allAppsButton.setVisibility(View.VISIBLE);
3600 }
3601 }
3602 });
Adam Cohen9bfdb762014-07-21 17:44:06 -07003603
Adam Cohen2854d252014-08-27 16:04:07 -07003604 mStateAnimation.play(reveal);
3605 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003606
Adam Cohen2854d252014-08-27 16:04:07 -07003607 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3608 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3609 mAppsCustomizeContent.stopScrolling();
Adam Cohen6c5891a2014-07-09 23:53:15 -07003610 }
Michael Jurkabed61d22012-02-14 22:51:29 -08003611
3612 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07003613 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08003614 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003615 fromView.setVisibility(View.GONE);
Michael Jurkabed61d22012-02-14 22:51:29 -08003616 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3617 dispatchOnLauncherTransitionEnd(toView, animated, true);
Adam Cohened66b2b2012-01-23 17:28:51 -08003618 if (onCompleteRunnable != null) {
3619 onCompleteRunnable.run();
3620 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003621
3622 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
Adam Cohen4e243a22014-08-10 18:30:55 -07003623 if (page != null) {
3624 page.setLayerType(View.LAYER_TYPE_NONE, null);
3625 }
Adam Cohen9bfdb762014-07-21 17:44:06 -07003626 content.setPageBackgroundsVisible(true);
Adam Cohen8e894fa2014-09-08 19:45:43 +02003627 // Unhide side pages
3628 int count = content.getChildCount();
3629 for (int i = 0; i < count; i++) {
3630 View child = content.getChildAt(i);
3631 child.setVisibility(View.VISIBLE);
3632 }
3633
3634 // Reset page transforms
3635 page.setTranslationX(0);
3636 page.setTranslationY(0);
3637 page.setAlpha(1);
3638 content.setCurrentPage(content.getNextPage());
3639
Chet Haasebc2f0822012-10-26 17:59:53 -07003640 mAppsCustomizeContent.updateCurrentPageScroll();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003641 }
3642 });
3643
Adam Cohen2854d252014-08-27 16:04:07 -07003644 final AnimatorSet stateAnimation = mStateAnimation;
3645 final Runnable startAnimRunnable = new Runnable() {
3646 public void run() {
3647 // Check that mStateAnimation hasn't changed while
3648 // we waited for a layout/draw pass
3649 if (mStateAnimation != stateAnimation)
3650 return;
3651 dispatchOnLauncherTransitionStart(fromView, animated, false);
3652 dispatchOnLauncherTransitionStart(toView, animated, false);
3653
3654 if (Utilities.isLmp()) {
3655 for (int i = 0; i < layerViews.size(); i++) {
3656 View v = layerViews.get(i);
Adam Cohen0f668f32014-09-08 19:54:17 +02003657 if (v != null) {
3658 boolean attached = true;
3659 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
3660 attached = v.isAttachedToWindow();
3661 }
3662 if (attached) v.buildLayer();
3663 }
Adam Cohen2854d252014-08-27 16:04:07 -07003664 }
3665 }
3666 mStateAnimation.start();
3667 }
3668 };
3669 fromView.post(startAnimRunnable);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003670 } else {
3671 fromView.setVisibility(View.GONE);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003672 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003673 dispatchOnLauncherTransitionStart(fromView, animated, true);
3674 dispatchOnLauncherTransitionEnd(fromView, animated, true);
Michael Jurkaa35e35a2012-04-26 15:04:28 -07003675 dispatchOnLauncherTransitionPrepare(toView, animated, true);
Michael Jurkabed61d22012-02-14 22:51:29 -08003676 dispatchOnLauncherTransitionStart(toView, animated, true);
3677 dispatchOnLauncherTransitionEnd(toView, animated, true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07003678 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07003679 }
3680
Michael Jurkae326f182011-11-21 14:05:46 -08003681 @Override
3682 public void onTrimMemory(int level) {
3683 super.onTrimMemory(level);
Winson Chungc7450e32012-04-17 17:34:08 -07003684 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
Michael Jurkae326f182011-11-21 14:05:46 -08003685 mAppsCustomizeTabHost.onTrimMemory();
3686 }
3687 }
3688
Adam Cohened307df2013-10-02 09:37:31 -07003689 protected void showWorkspace(boolean animated) {
Adam Cohened66b2b2012-01-23 17:28:51 -08003690 showWorkspace(animated, null);
3691 }
3692
Adam Cohened307df2013-10-02 09:37:31 -07003693 protected void showWorkspace() {
3694 showWorkspace(true);
3695 }
3696
Adam Cohened66b2b2012-01-23 17:28:51 -08003697 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
Adam Cohene25c5d12014-06-18 10:34:58 -07003698 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
Winson Chung2d75f122013-09-23 16:53:31 -07003699 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003700 mWorkspace.setVisibility(View.VISIBLE);
Adam Cohened307df2013-10-02 09:37:31 -07003701 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003702
Winson Chungc7d2b602012-05-16 17:02:20 -07003703 // Show the search bar (only animate if we were showing the drop target bar in spring
3704 // loaded mode)
Winson Chungadf0c182012-08-23 14:59:07 -07003705 if (mSearchDropTargetBar != null) {
Winson Chung04c0a5c2013-10-08 17:13:12 -07003706 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
Winson Chungadf0c182012-08-23 14:59:07 -07003707 }
Winson Chungc7d2b602012-05-16 17:02:20 -07003708
Michael Jurkab3e22d92011-10-31 15:58:33 -07003709 // Set focus to the AppsCustomize button
3710 if (mAllAppsButton != null) {
3711 mAllAppsButton.requestFocus();
3712 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003713 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07003714
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003715 // Change the state *after* we've called all the transition code
3716 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08003717
Winson Chung5fb63472011-02-02 17:03:37 -08003718 // Resume the auto-advance of widgets
3719 mUserPresent = true;
3720 updateRunning();
3721
alanv1d4fde62012-10-17 13:15:47 -07003722 // Send an accessibility event to announce the context change
3723 getWindow().getDecorView()
3724 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003725
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003726 onWorkspaceShown(animated);
Bjorn Bringertc459e522013-06-07 19:36:01 +01003727 }
3728
Adam Cohened307df2013-10-02 09:37:31 -07003729 void showOverviewMode(boolean animated) {
3730 mWorkspace.setVisibility(View.VISIBLE);
3731 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3732 mState = State.WORKSPACE;
3733 onWorkspaceShown(animated);
3734 }
3735
Bjorn Bringert69688aa2013-06-11 20:26:38 +01003736 public void onWorkspaceShown(boolean animated) {
Joe Onorato00acb122009-08-04 16:04:30 -04003737 }
3738
Winson Chung82963d52013-10-09 11:20:57 -07003739 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3740 boolean resetPageToZero) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003741 if (mState != State.WORKSPACE) return;
3742
Winson Chung82963d52013-10-09 11:20:57 -07003743 if (resetPageToZero) {
3744 mAppsCustomizeTabHost.reset();
3745 }
Winson Chungc58497e2013-09-03 17:48:37 -07003746 showAppsCustomizeHelper(animated, false, contentType);
Adam Cohendcc5e712014-06-23 15:38:55 -04003747 mAppsCustomizeTabHost.post(new Runnable() {
3748 @Override
3749 public void run() {
3750 // We post this in-case the all apps view isn't yet constructed.
3751 mAppsCustomizeTabHost.requestFocus();
3752 }
3753 });
Michael Jurkab3e22d92011-10-31 15:58:33 -07003754
Michael Jurkab3e22d92011-10-31 15:58:33 -07003755 // Change the state *after* we've called all the transition code
3756 mState = State.APPS_CUSTOMIZE;
3757
3758 // Pause the auto-advance of widgets until we are out of AllApps
3759 mUserPresent = false;
3760 updateRunning();
3761 closeFolder();
3762
3763 // Send an accessibility event to announce the context change
alanv1d4fde62012-10-17 13:15:47 -07003764 getWindow().getDecorView()
3765 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07003766 }
3767
Adam Cohen7777d962011-08-18 18:58:38 -07003768 void enterSpringLoadedDragMode() {
Winson Chungc93e5ae2012-07-23 20:48:26 -07003769 if (isAllAppsVisible()) {
Adam Cohened307df2013-10-02 09:37:31 -07003770 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
Winson Chungc07918d2011-07-01 15:35:26 -07003771 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07003772 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003773 }
Adam Cohen7777d962011-08-18 18:58:38 -07003774
Adam Cohenad4e15c2013-10-17 16:21:35 -07003775 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
Adam Cohened66b2b2012-01-23 17:28:51 -08003776 final Runnable onCompleteRunnable) {
Winson Chung09bfc452011-09-09 11:30:20 -07003777 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3778
Winson Chunge7a03942011-08-05 15:05:12 -07003779 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07003780 @Override
3781 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003782 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07003783 // Before we show workspace, hide all apps again because
3784 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3785 // clean up our state transition functions
3786 mAppsCustomizeTabHost.setVisibility(View.GONE);
Adam Cohened66b2b2012-01-23 17:28:51 -08003787 showWorkspace(true, onCompleteRunnable);
Adam Cohen7777d962011-08-18 18:58:38 -07003788 } else {
3789 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07003790 }
Winson Chung557d6ed2011-07-08 15:34:52 -07003791 }
Adam Cohenad4e15c2013-10-17 16:21:35 -07003792 }, delay);
Winson Chung557d6ed2011-07-08 15:34:52 -07003793 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07003794
Michael Jurkad3ef3062010-11-23 16:23:58 -08003795 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07003796 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07003797 final boolean animated = true;
3798 final boolean springLoaded = true;
3799 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07003800 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07003801 }
3802 // Otherwise, we are not in spring loaded mode, so don't do anything.
3803 }
3804
Michael Jurkab3e22d92011-10-31 15:58:33 -07003805 void lockAllApps() {
3806 // TODO
3807 }
3808
3809 void unlockAllApps() {
3810 // TODO
3811 }
3812
Winson Chungf0ea4d32011-06-06 14:27:16 -07003813 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07003814 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07003815 */
Winson Chung3d503fb2011-07-13 17:25:49 -07003816 void hideHotseat(boolean animated) {
Daniel Sandlere4f98912013-06-25 15:13:26 -04003817 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07003818 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08003819 if (mHotseat.getAlpha() != 0f) {
Winson Chungadf0c182012-08-23 14:59:07 -07003820 int duration = 0;
3821 if (mSearchDropTargetBar != null) {
3822 duration = mSearchDropTargetBar.getTransitionOutDuration();
3823 }
Michael Jurka7407d2a2011-12-12 21:48:38 -08003824 mHotseat.animate().alpha(0f).setDuration(duration);
3825 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003826 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07003827 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003828 }
Winson Chungb26f3d62011-06-02 10:49:29 -07003829 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08003830 }
3831
Patrick Dubroy5f445422011-02-18 14:35:21 -08003832 /**
3833 * Add an item from all apps or customize onto the given workspace screen.
3834 * If layout is null, add to the current screen.
3835 */
3836 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003837 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
Winson Chung93eef082012-03-23 15:59:27 -07003838 showOutOfSpaceMessage(isHotseatLayout(layout));
Michael Jurka213d9632010-07-28 11:29:25 -07003839 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07003840 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003841
Winson Chungdff8ebb2011-09-08 17:25:31 -07003842 /** Maps the current orientation to an index for referencing orientation correct global icons */
3843 private int getCurrentOrientationIndexForGlobalIcons() {
3844 // default - 0, landscape - 1
3845 switch (getResources().getConfiguration().orientation) {
3846 case Configuration.ORIENTATION_LANDSCAPE:
3847 return 1;
3848 default:
3849 return 0;
3850 }
3851 }
3852
Michael Jurkaae65ee32012-04-30 11:45:54 -07003853 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003854 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003855 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07003856 // Look for the toolbar icon specified in the activity meta-data
3857 Bundle metaData = packageManager.getActivityInfo(
3858 activityName, PackageManager.GET_META_DATA).metaData;
3859 if (metaData != null) {
Michael Jurkaae65ee32012-04-30 11:45:54 -07003860 int iconResId = metaData.getInt(resourceName);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003861 if (iconResId != 0) {
3862 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003863 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003864 }
3865 }
3866 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07003867 // This can happen if the activity defines an invalid drawable
3868 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3869 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01003870 } catch (Resources.NotFoundException nfe) {
3871 // This can happen if the activity defines an invalid drawable
3872 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3873 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07003874 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003875 return null;
3876 }
3877
3878 // if successful in getting icon, return it; otherwise, set button to use default drawable
3879 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003880 int buttonId, ComponentName activityName, int fallbackDrawableId,
3881 String toolbarResourceName) {
3882 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chung128bbcd2011-08-31 16:58:52 -07003883 Resources r = getResources();
3884 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3885 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003886
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003887 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003888 // If we were unable to find the icon via the meta-data, use a generic one
3889 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07003890 toolbarIcon = r.getDrawable(fallbackDrawableId);
3891 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003892 if (button != null) {
3893 button.setCompoundDrawables(toolbarIcon, null, null, null);
3894 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003895 return null;
3896 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07003897 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07003898 if (button != null) {
3899 button.setCompoundDrawables(toolbarIcon, null, null, null);
3900 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003901 return toolbarIcon.getConstantState();
3902 }
3903 }
3904
3905 // if successful in getting icon, return it; otherwise, set button to use default drawable
3906 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003907 int buttonId, ComponentName activityName, int fallbackDrawableId,
3908 String toolbarResourceName) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003909 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkaae65ee32012-04-30 11:45:54 -07003910 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003911
Michael Jurka19e0fc52011-07-22 18:00:21 -07003912 if (button != null) {
3913 // If we were unable to find the icon via the meta-data, use a
3914 // generic one
3915 if (toolbarIcon == null) {
3916 button.setImageResource(fallbackDrawableId);
3917 } else {
3918 button.setImageDrawable(toolbarIcon);
3919 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07003920 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07003921
3922 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3923
Michael Jurka0423dcf2010-10-05 14:56:18 -07003924 }
3925
Winson Chung1b884092012-06-08 17:13:02 -07003926 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003927 TextView button = (TextView) findViewById(buttonId);
Winson Chung1b884092012-06-08 17:13:02 -07003928 button.setCompoundDrawables(d, null, null, null);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08003929 }
3930
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003931 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08003932 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08003933 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08003934 }
3935
Winson Chungbb185bd2011-11-21 12:31:42 -08003936 private void invalidatePressedFocusedStates(View container, View button) {
3937 if (container instanceof HolographicLinearLayout) {
3938 HolographicLinearLayout layout = (HolographicLinearLayout) container;
3939 layout.invalidatePressedFocusedStates();
3940 } else if (button instanceof HolographicImageView) {
3941 HolographicImageView view = (HolographicImageView) button;
3942 view.invalidatePressedFocusedStates();
3943 }
3944 }
3945
Cristina Stancu476493b2013-08-07 17:20:14 +01003946 public View getQsbBar() {
Adam Cohen24ce0b32014-01-14 16:18:14 -08003947 if (mQsb == null) {
3948 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
3949 mSearchDropTargetBar.addView(mQsb);
Cristina Stancu476493b2013-08-07 17:20:14 +01003950 }
Adam Cohen24ce0b32014-01-14 16:18:14 -08003951 return mQsb;
Cristina Stancu476493b2013-08-07 17:20:14 +01003952 }
3953
3954 protected boolean updateGlobalSearchIcon() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003955 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003956 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
Winson Chungc51db6a2011-10-05 11:44:49 -07003957 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003958 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003959
Winson Chung1cad91e2011-05-25 17:41:01 -07003960 final SearchManager searchManager =
3961 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
3962 ComponentName activityName = searchManager.getGlobalSearchActivity();
3963 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07003964 int coi = getCurrentOrientationIndexForGlobalIcons();
3965 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07003966 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3967 TOOLBAR_SEARCH_ICON_METADATA_NAME);
3968 if (sGlobalSearchIcon[coi] == null) {
3969 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
3970 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
3971 TOOLBAR_ICON_METADATA_NAME);
3972 }
3973
Winson Chungc51db6a2011-10-05 11:44:49 -07003974 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
3975 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08003976 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07003977 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07003978 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07003979 // We disable both search and voice search when there is no global search provider
Winson Chungc51db6a2011-10-05 11:44:49 -07003980 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
3981 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04003982 if (searchButton != null) searchButton.setVisibility(View.GONE);
3983 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07003984 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07003985 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003986 }
3987 }
3988
Cristina Stancu476493b2013-08-07 17:20:14 +01003989 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08003990 final View searchButtonContainer = findViewById(R.id.search_button_container);
3991 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003992 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08003993 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08003994 }
3995
Cristina Stancu476493b2013-08-07 17:20:14 +01003996 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chungc51db6a2011-10-05 11:44:49 -07003997 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07003998 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07003999
Winson Chungc51db6a2011-10-05 11:44:49 -07004000 // We only show/update the voice search icon if the search icon is enabled as well
Michael Jurkaae65ee32012-04-30 11:45:54 -07004001 final SearchManager searchManager =
4002 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
4003 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
4004
4005 ComponentName activityName = null;
4006 if (globalSearchActivity != null) {
4007 // Check if the global search activity handles voice search
4008 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
4009 intent.setPackage(globalSearchActivity.getPackageName());
4010 activityName = intent.resolveActivity(getPackageManager());
4011 }
4012
4013 if (activityName == null) {
4014 // Fallback: check if an activity other than the global search activity
4015 // resolves this
4016 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
4017 activityName = intent.resolveActivity(getPackageManager());
4018 }
Winson Chungc51db6a2011-10-05 11:44:49 -07004019 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07004020 int coi = getCurrentOrientationIndexForGlobalIcons();
4021 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Michael Jurkaae65ee32012-04-30 11:45:54 -07004022 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
4023 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
4024 if (sVoiceSearchIcon[coi] == null) {
4025 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
4026 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
4027 TOOLBAR_ICON_METADATA_NAME);
4028 }
Winson Chungc51db6a2011-10-05 11:44:49 -07004029 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07004030 voiceButton.setVisibility(View.VISIBLE);
Winson Chung5841efa2013-09-30 18:06:44 -07004031 updateVoiceButtonProxyVisible(false);
Winson Chungbb185bd2011-11-21 12:31:42 -08004032 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07004033 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07004034 } else {
Winson Chungc51db6a2011-10-05 11:44:49 -07004035 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
John Spurlock2c38e702013-09-18 10:48:25 -04004036 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07004037 updateVoiceButtonProxyVisible(false);
Winson Chungc51db6a2011-10-05 11:44:49 -07004038 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004039 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07004040 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07004041
Cristina Stancu476493b2013-08-07 17:20:14 +01004042 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08004043 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
4044 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08004045 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08004046 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08004047 }
4048
Winson Chung5841efa2013-09-30 18:06:44 -07004049 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
Bjorn Bringertecf33e42013-06-11 15:46:07 +01004050 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
4051 if (voiceButtonProxy != null) {
Winson Chung5841efa2013-09-30 18:06:44 -07004052 boolean visible = !forceDisableVoiceButtonProxy &&
4053 mWorkspace.shouldVoiceButtonProxyBeVisible();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01004054 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
Winson Chung5841efa2013-09-30 18:06:44 -07004055 voiceButtonProxy.bringToFront();
Bjorn Bringertecf33e42013-06-11 15:46:07 +01004056 }
4057 }
Winson Chung5841efa2013-09-30 18:06:44 -07004058
4059 /**
4060 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button proxy
4061 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
4062 */
4063 public void disableVoiceButtonProxy(boolean disabled) {
4064 updateVoiceButtonProxyVisible(disabled);
4065 }
Michael Jurka4ef207b2010-11-29 17:05:45 -08004066
Michael Jurkad7c28052012-04-27 15:43:36 -07004067 @Override
4068 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
alanv1d4fde62012-10-17 13:15:47 -07004069 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
Michael Jurkad7c28052012-04-27 15:43:36 -07004070 final List<CharSequence> text = event.getText();
4071 text.clear();
alanv1d4fde62012-10-17 13:15:47 -07004072 // Populate event with a fake title based on the current state.
4073 if (mState == State.APPS_CUSTOMIZE) {
Adam Cohen6c5891a2014-07-09 23:53:15 -07004074 text.add(mAppsCustomizeTabHost.getContentTag());
alanv1d4fde62012-10-17 13:15:47 -07004075 } else {
4076 text.add(getString(R.string.all_apps_home_button_label));
4077 }
Michael Jurkad7c28052012-04-27 15:43:36 -07004078 return result;
4079 }
4080
Patrick Dubroyceae05d2010-08-30 10:40:53 -07004081 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07004082 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004083 */
4084 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4085 @Override
4086 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08004087 closeSystemDialogs();
4088 }
4089 }
4090
4091 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08004092 * Receives notifications whenever the appwidgets are reset.
4093 */
4094 private class AppWidgetResetObserver extends ContentObserver {
4095 public AppWidgetResetObserver() {
4096 super(new Handler());
4097 }
4098
4099 @Override
4100 public void onChange(boolean selfChange) {
4101 onAppWidgetReset();
4102 }
4103 }
4104
4105 /**
Michael Jurka7607c2f2013-04-03 14:33:19 -07004106 * If the activity is currently paused, signal that we need to run the passed Runnable
4107 * in onResume.
4108 *
4109 * This needs to be called from incoming places where resources might have been loaded
4110 * while we are paused. That is becaues the Configuration might be wrong
4111 * when we're not running, and if it comes back to what it was when we
4112 * were paused, we are not restarted.
4113 *
4114 * Implementation of the method from LauncherModel.Callbacks.
4115 *
4116 * @return true if we are currently paused. The caller might be able to
4117 * skip some work in that case since we will come back again.
4118 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004119 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004120 if (mPaused) {
4121 Log.i(TAG, "Deferring update until onResume");
Michael Jurkac402cd92013-05-20 15:49:32 +02004122 if (deletePreviousRunnables) {
Michael Jurka1e2f4652013-07-08 18:03:46 -07004123 while (mBindOnResumeCallbacks.remove(run)) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004124 }
4125 }
Michael Jurka1e2f4652013-07-08 18:03:46 -07004126 mBindOnResumeCallbacks.add(run);
Michael Jurka7607c2f2013-04-03 14:33:19 -07004127 return true;
4128 } else {
4129 return false;
4130 }
4131 }
4132
Michael Jurkac402cd92013-05-20 15:49:32 +02004133 private boolean waitUntilResume(Runnable run) {
4134 return waitUntilResume(run, false);
4135 }
4136
Michael Jurka1e2f4652013-07-08 18:03:46 -07004137 public void addOnResumeCallback(Runnable run) {
Michael Jurka54554252013-08-01 12:52:23 +02004138 mOnResumeCallbacks.add(run);
Michael Jurka1e2f4652013-07-08 18:03:46 -07004139 }
4140
Michael Jurka7607c2f2013-04-03 14:33:19 -07004141 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004142 * If the activity is currently paused, signal that we need to re-run the loader
4143 * in onResume.
4144 *
4145 * This needs to be called from incoming places where resources might have been loaded
4146 * while we are paused. That is becaues the Configuration might be wrong
4147 * when we're not running, and if it comes back to what it was when we
4148 * were paused, we are not restarted.
4149 *
4150 * Implementation of the method from LauncherModel.Callbacks.
4151 *
4152 * @return true if we are currently paused. The caller might be able to
4153 * skip some work in that case since we will come back again.
4154 */
4155 public boolean setLoadOnResume() {
4156 if (mPaused) {
4157 Log.i(TAG, "setLoadOnResume");
4158 mOnResumeNeedsLoad = true;
4159 return true;
4160 } else {
4161 return false;
4162 }
4163 }
4164
4165 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004166 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004167 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04004168 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07004169 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07004170 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07004171 } else {
4172 return SCREEN_COUNT / 2;
4173 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004174 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07004175
Joe Onorato9c1289c2009-08-17 11:03:03 -04004176 /**
4177 * Refreshes the shortcuts shown on the workspace.
4178 *
4179 * Implementation of the method from LauncherModel.Callbacks.
4180 */
4181 public void startBinding() {
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004182 setWorkspaceLoading(true);
Adam Cohen517a7f52014-03-01 12:12:59 -08004183
Michael Jurka7607c2f2013-04-03 14:33:19 -07004184 // If we're starting binding all over again, clear any bind calls we'd postponed in
4185 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4186 // from scratch again
Michael Jurka1e2f4652013-07-08 18:03:46 -07004187 mBindOnResumeCallbacks.clear();
Adam Cohendf035382011-04-11 17:22:04 -07004188
Winson Chungd64d1762013-08-20 14:37:16 -07004189 // Clear the workspace because it's going to be rebound
Adam Cohendf035382011-04-11 17:22:04 -07004190 mWorkspace.clearDropTargets();
Winson Chung9e6a0a22013-08-27 11:58:12 -07004191 mWorkspace.removeAllWorkspaceScreens();
Winson Chungd64d1762013-08-20 14:37:16 -07004192
Michael Jurka05bf6442011-11-30 20:28:53 -08004193 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07004194 if (mHotseat != null) {
4195 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004196 }
4197 }
4198
Adam Cohendcd297f2013-06-18 13:13:40 -07004199 @Override
4200 public void bindScreens(ArrayList<Long> orderedScreenIds) {
Winson Chung64359a52013-07-08 17:17:08 -07004201 bindAddScreens(orderedScreenIds);
Winson Chung0e6a7132013-08-23 12:55:10 -07004202
Adam Cohen5084cba2013-09-03 12:01:16 -07004203 // If there are no screens, we need to have an empty screen
4204 if (orderedScreenIds.size() == 0) {
4205 mWorkspace.addExtraEmptyScreen();
4206 }
Winson Chung0e6a7132013-08-23 12:55:10 -07004207
4208 // Create the custom content page (this call updates mDefaultScreen which calls
Dave Hawkeya8881582013-09-17 15:55:33 -06004209 // setCurrentPage() so ensure that all pages are added before calling this).
Derek Prothrodadd9842014-01-17 13:43:50 -05004210 if (hasCustomContentToLeft()) {
4211 mWorkspace.createCustomContentContainer();
4212 populateCustomContentContainer();
Winson Chung0e6a7132013-08-23 12:55:10 -07004213 }
Winson Chung64359a52013-07-08 17:17:08 -07004214 }
4215
4216 @Override
4217 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
Winson Chunga90303b2013-11-15 13:05:06 -08004218 // Log to disk
4219 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4220 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4221 TextUtils.join(", ", orderedScreenIds), true);
Adam Cohendcd297f2013-06-18 13:13:40 -07004222 int count = orderedScreenIds.size();
4223 for (int i = 0; i < count; i++) {
Adam Cohen89bddfa2013-08-20 11:57:13 -07004224 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
Adam Cohendcd297f2013-06-18 13:13:40 -07004225 }
Adam Cohendcd297f2013-06-18 13:13:40 -07004226 }
4227
Adam Cohen39a06042013-07-19 14:30:12 -07004228 private boolean shouldShowWeightWatcher() {
4229 String spKey = LauncherAppState.getSharedPreferencesKey();
4230 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
Daniel Sandler6053b802013-08-15 15:44:26 -07004231 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
Adam Cohen39a06042013-07-19 14:30:12 -07004232
4233 return show;
4234 }
4235
4236 private void toggleShowWeightWatcher() {
4237 String spKey = LauncherAppState.getSharedPreferencesKey();
4238 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4239 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4240
4241 show = !show;
4242
4243 SharedPreferences.Editor editor = sp.edit();
4244 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4245 editor.commit();
4246
4247 if (mWeightWatcher != null) {
4248 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4249 }
4250 }
4251
Winson Chungd64d1762013-08-20 14:37:16 -07004252 public void bindAppsAdded(final ArrayList<Long> newScreens,
4253 final ArrayList<ItemInfo> addNotAnimated,
Winson Chungc58497e2013-09-03 17:48:37 -07004254 final ArrayList<ItemInfo> addAnimated,
4255 final ArrayList<AppInfo> addedApps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004256 Runnable r = new Runnable() {
4257 public void run() {
Winson Chungc58497e2013-09-03 17:48:37 -07004258 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
Winson Chungd64d1762013-08-20 14:37:16 -07004259 }
4260 };
4261 if (waitUntilResume(r)) {
4262 return;
4263 }
4264
Winson Chungd64d1762013-08-20 14:37:16 -07004265 // Add the new screens
Adam Cohen76a47a12014-02-05 11:47:43 -08004266 if (newScreens != null) {
4267 bindAddScreens(newScreens);
4268 }
Winson Chungd64d1762013-08-20 14:37:16 -07004269
4270 // We add the items without animation on non-visible pages, and with
4271 // animations on the new page (which we will try and snap to).
Adam Cohen76a47a12014-02-05 11:47:43 -08004272 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004273 bindItems(addNotAnimated, 0,
4274 addNotAnimated.size(), false);
4275 }
Adam Cohen76a47a12014-02-05 11:47:43 -08004276 if (addAnimated != null && !addAnimated.isEmpty()) {
Winson Chungd64d1762013-08-20 14:37:16 -07004277 bindItems(addAnimated, 0,
4278 addAnimated.size(), true);
4279 }
Winson Chungc58497e2013-09-03 17:48:37 -07004280
Winson Chung87412982013-10-03 18:34:14 -07004281 // Remove the extra empty screen
Adam Cohen689ff162014-05-08 17:27:56 -07004282 mWorkspace.removeExtraEmptyScreen(false, false);
Winson Chung87412982013-10-03 18:34:14 -07004283
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004284 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004285 addedApps != null && mAppsCustomizeContent != null) {
4286 mAppsCustomizeContent.addApps(addedApps);
4287 }
Winson Chungd64d1762013-08-20 14:37:16 -07004288 }
4289
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004290 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004291 * Bind the items start-end from the list.
4292 *
4293 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004294 */
Winson Chung64359a52013-07-08 17:17:08 -07004295 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4296 final boolean forceAnimateIcons) {
Winson Chungd64d1762013-08-20 14:37:16 -07004297 Runnable r = new Runnable() {
4298 public void run() {
4299 bindItems(shortcuts, start, end, forceAnimateIcons);
4300 }
4301 };
4302 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004303 return;
4304 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004305
Winson Chungf0c6ae02012-03-21 16:10:31 -07004306 // Get the list of added shortcuts and intersect them with the set of shortcuts here
Winson Chung64359a52013-07-08 17:17:08 -07004307 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4308 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
Winson Chung997a9232013-07-24 15:33:46 -07004309 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004310 Workspace workspace = mWorkspace;
Winson Chung997a9232013-07-24 15:33:46 -07004311 long newShortcutsScreenId = -1;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004312 for (int i = start; i < end; i++) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04004313 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07004314
4315 // Short circuit if we are loading dock items for a configuration which has no dock
4316 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4317 mHotseat == null) {
4318 continue;
4319 }
4320
Joe Onorato9c1289c2009-08-17 11:03:03 -04004321 switch (item.itemType) {
4322 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4323 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chungf0c6ae02012-03-21 16:10:31 -07004324 ShortcutInfo info = (ShortcutInfo) item;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004325 View shortcut = createShortcut(info);
Adam Cohendcd297f2013-06-18 13:13:40 -07004326
Winson Chung64359a52013-07-08 17:17:08 -07004327 /*
4328 * TODO: FIX collision case
4329 */
Winson Chungce376632013-07-11 16:12:41 -07004330 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4331 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4332 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
Adam Cohen8f006ed2014-04-03 18:12:34 -07004333 View v = cl.getChildAt(item.cellX, item.cellY);
4334 Object tag = v.getTag();
4335 String desc = "Collision while binding workspace item: " + item
4336 + ". Collides with " + tag;
4337 if (LauncherAppState.isDogfoodBuild()) {
4338 throw (new RuntimeException(desc));
4339 } else {
4340 Log.d(TAG, desc);
4341 }
Winson Chungce376632013-07-11 16:12:41 -07004342 }
Winson Chung64359a52013-07-08 17:17:08 -07004343 }
4344
Adam Cohendcd297f2013-06-18 13:13:40 -07004345 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4346 item.cellY, 1, 1);
Winson Chung997a9232013-07-24 15:33:46 -07004347 if (animateIcons) {
Winson Chung64359a52013-07-08 17:17:08 -07004348 // Animate all the applications up now
4349 shortcut.setAlpha(0f);
4350 shortcut.setScaleX(0f);
4351 shortcut.setScaleY(0f);
4352 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
Winson Chung997a9232013-07-24 15:33:46 -07004353 newShortcutsScreenId = item.screenId;
Winson Chungf0c6ae02012-03-21 16:10:31 -07004354 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004355 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07004356 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07004357 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07004358 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07004359 (FolderInfo) item, mIconCache);
Adam Cohendcd297f2013-06-18 13:13:40 -07004360 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4361 item.cellY, 1, 1);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004362 break;
Winson Chungc763c4e2013-07-19 13:49:06 -07004363 default:
4364 throw new RuntimeException("Invalid Item Type");
Joe Onorato9c1289c2009-08-17 11:03:03 -04004365 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004366 }
Winson Chungf0c6ae02012-03-21 16:10:31 -07004367
Winson Chung997a9232013-07-24 15:33:46 -07004368 if (animateIcons) {
4369 // Animate to the correct page
4370 if (newShortcutsScreenId > -1) {
4371 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
Winson Chung94d67682013-09-25 16:29:40 -07004372 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
Winson Chungb2323832013-10-03 15:22:09 -07004373 final Runnable startBounceAnimRunnable = new Runnable() {
4374 public void run() {
4375 anim.playTogether(bounceAnims);
4376 anim.start();
4377 }
4378 };
Winson Chung997a9232013-07-24 15:33:46 -07004379 if (newShortcutsScreenId != currentScreenId) {
Winson Chung94d67682013-09-25 16:29:40 -07004380 // We post the animation slightly delayed to prevent slowdowns
4381 // when we are loading right after we return to launcher.
4382 mWorkspace.postDelayed(new Runnable() {
4383 public void run() {
Ian Parkinson94449152014-01-21 13:09:59 +00004384 if (mWorkspace != null) {
4385 mWorkspace.snapToPage(newScreenIndex);
4386 mWorkspace.postDelayed(startBounceAnimRunnable,
4387 NEW_APPS_ANIMATION_DELAY);
4388 }
Winson Chung94d67682013-09-25 16:29:40 -07004389 }
4390 }, NEW_APPS_PAGE_MOVE_DELAY);
Winson Chungb2323832013-10-03 15:22:09 -07004391 } else {
4392 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
Winson Chung997a9232013-07-24 15:33:46 -07004393 }
4394 }
Winson Chung64359a52013-07-08 17:17:08 -07004395 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004396 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004397 }
4398
Joe Onorato9c1289c2009-08-17 11:03:03 -04004399 /**
4400 * Implementation of the method from LauncherModel.Callbacks.
4401 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004402 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
Winson Chungd64d1762013-08-20 14:37:16 -07004403 Runnable r = new Runnable() {
4404 public void run() {
4405 bindFolders(folders);
4406 }
4407 };
4408 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004409 return;
4410 }
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07004411 sFolders.clear();
4412 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08004413 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004414
4415 /**
4416 * Add the views for a widget to the workspace.
4417 *
4418 * Implementation of the method from LauncherModel.Callbacks.
4419 */
Michael Jurka7607c2f2013-04-03 14:33:19 -07004420 public void bindAppWidget(final LauncherAppWidgetInfo item) {
Winson Chungd64d1762013-08-20 14:37:16 -07004421 Runnable r = new Runnable() {
4422 public void run() {
4423 bindAppWidget(item);
4424 }
4425 };
4426 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004427 return;
4428 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -07004429
Daniel Sandler843e8602010-06-07 14:59:01 -04004430 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4431 if (DEBUG_WIDGETS) {
4432 Log.d(TAG, "bindAppWidget: " + item);
4433 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004434 final Workspace workspace = mWorkspace;
4435
Sunny Goyalff572272014-07-23 13:58:07 -07004436 AppWidgetProviderInfo appWidgetInfo;
4437 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4438 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4439
4440 appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
4441 if (appWidgetInfo == null) {
4442 if (DEBUG_WIDGETS) {
4443 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4444 + " belongs to component " + item.providerName
4445 + ", as the povider is null");
4446 }
4447 LauncherModel.deleteItemFromDatabase(this, item);
4448 return;
4449 }
4450 // Note: This assumes that the id remap broadcast is received before this step.
4451 // If that is not the case, the id remap will be ignored and user may see the
4452 // click to setup view.
4453 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4454 pendingInfo.spanX = item.spanX;
4455 pendingInfo.spanY = item.spanY;
4456 pendingInfo.minSpanX = item.minSpanX;
4457 pendingInfo.minSpanY = item.minSpanY;
4458 Bundle options =
4459 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4460
Sunny Goyalff572272014-07-23 13:58:07 -07004461 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
Sunny Goyalffe83f12014-08-14 17:39:34 -07004462 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4463 newWidgetId, appWidgetInfo, options);
Sunny Goyalff572272014-07-23 13:58:07 -07004464
4465 // TODO consider showing a permission dialog when the widget is clicked.
4466 if (!success) {
4467 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4468 if (DEBUG_WIDGETS) {
4469 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4470 + " belongs to component " + item.providerName
4471 + ", as the launcher is unable to bing a new widget id");
4472 }
4473 LauncherModel.deleteItemFromDatabase(this, item);
4474 return;
4475 }
4476
4477 item.appWidgetId = newWidgetId;
4478
4479 // If the widget has a configure activity, it is still needs to set it up, otherwise
4480 // the widget is ready to go.
4481 item.restoreStatus = (appWidgetInfo.configure == null)
4482 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4483 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4484
4485 LauncherModel.updateItemInDatabase(this, item);
4486 }
4487
Sunny Goyal651077b2014-06-30 14:15:31 -07004488 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4489 final int appWidgetId = item.appWidgetId;
4490 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4491 if (DEBUG_WIDGETS) {
4492 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
4493 }
Daniel Sandler843e8602010-06-07 14:59:01 -04004494
Sunny Goyal651077b2014-06-30 14:15:31 -07004495 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4496 } else {
4497 appWidgetInfo = null;
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004498 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item);
4499 view.updateIcon(mIconCache);
4500 item.hostView = view;
Sunny Goyal651077b2014-06-30 14:15:31 -07004501 item.hostView.updateAppWidget(null);
Sunny Goyalff572272014-07-23 13:58:07 -07004502 item.hostView.setOnClickListener(this);
Sunny Goyal651077b2014-06-30 14:15:31 -07004503 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004504
Joe Onorato9c1289c2009-08-17 11:03:03 -04004505 item.hostView.setTag(item);
Winson Chung211bac32012-05-15 13:43:57 -07004506 item.onBindAppWidget(this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04004507
Adam Cohendcd297f2013-06-18 13:13:40 -07004508 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04004509 item.cellY, item.spanX, item.spanY, false);
Adam Cohended9f8d2010-11-03 13:25:16 -07004510 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4511
Joe Onorato9c1289c2009-08-17 11:03:03 -04004512 workspace.requestLayout();
4513
Daniel Sandler843e8602010-06-07 14:59:01 -04004514 if (DEBUG_WIDGETS) {
4515 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4516 + (SystemClock.uptimeMillis()-start) + "ms");
4517 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004518 }
4519
Sunny Goyalff572272014-07-23 13:58:07 -07004520 /**
4521 * Restores a pending widget.
4522 *
4523 * @param appWidgetId The app widget id
4524 * @param cellInfo The position on screen where to create the widget.
4525 */
4526 private void completeRestoreAppWidget(final int appWidgetId) {
4527 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4528 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4529 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4530 return;
4531 }
4532
Sunny Goyal0fc1be12014-08-11 17:05:23 -07004533 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
Sunny Goyalff572272014-07-23 13:58:07 -07004534 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4535
4536 mWorkspace.reinflateWidgetsIfNecessary();
4537 LauncherModel.updateItemInDatabase(this, info);
4538 }
4539
Adam Cohen1462de32012-07-24 22:34:36 -07004540 public void onPageBoundSynchronously(int page) {
4541 mSynchronouslyBoundPages.add(page);
4542 }
4543
Joe Onorato9c1289c2009-08-17 11:03:03 -04004544 /**
4545 * Callback saying that there aren't any more items to bind.
4546 *
4547 * Implementation of the method from LauncherModel.Callbacks.
4548 */
Adam Cohene25af792013-06-06 23:08:25 -07004549 public void finishBindingItems(final boolean upgradePath) {
Winson Chungd64d1762013-08-20 14:37:16 -07004550 Runnable r = new Runnable() {
4551 public void run() {
4552 finishBindingItems(upgradePath);
4553 }
4554 };
4555 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004556 return;
4557 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004558 if (mSavedState != null) {
4559 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07004560 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004561 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004562 mSavedState = null;
4563 }
4564
Adam Cohen1462de32012-07-24 22:34:36 -07004565 mWorkspace.restoreInstanceStateForRemainingPages();
Joe Onorato9c1289c2009-08-17 11:03:03 -04004566
Anjali Koppalff7ceff2014-05-01 18:26:37 -07004567 setWorkspaceLoading(false);
Adam Cohen3ed316a2014-07-23 18:21:20 -07004568 sendLoadingCompleteBroadcastIfNecessary();
Adam Cohendb364c32014-05-20 14:23:40 -07004569
4570 // If we received the result of any pending adds while the loader was running (e.g. the
4571 // widget configuration forced an orientation change), process them now.
4572 if (sPendingAddItem != null) {
4573 final long screenId = completeAdd(sPendingAddItem);
4574
4575 // TODO: this moves the user to the page where the pending item was added. Ideally,
4576 // the screen would be guaranteed to exist after bind, and the page would be set through
4577 // the workspace restore process.
4578 mWorkspace.post(new Runnable() {
4579 @Override
4580 public void run() {
4581 mWorkspace.snapToScreenId(screenId);
4582 }
4583 });
4584 sPendingAddItem = null;
4585 }
4586
Adam Cohene25af792013-06-06 23:08:25 -07004587 if (upgradePath) {
Adam Cohen4caf2982013-08-20 18:54:31 -07004588 mWorkspace.getUniqueComponents(true, null);
4589 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
Adam Cohene25af792013-06-06 23:08:25 -07004590 }
Sunny Goyale755d462014-07-22 13:48:29 -07004591 PackageInstallerCompat.getInstance(this).onFinishBind();
Winson Chungf0c6ae02012-03-21 16:10:31 -07004592 }
4593
Adam Cohen3ed316a2014-07-23 18:21:20 -07004594 private void sendLoadingCompleteBroadcastIfNecessary() {
4595 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4596 String permission =
4597 getResources().getString(R.string.receive_first_load_broadcast_permission);
4598 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4599 sendBroadcast(intent, permission);
4600 SharedPreferences.Editor editor = mSharedPrefs.edit();
4601 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4602 editor.apply();
4603 }
4604 }
4605
Winson Chunga0b7e862013-09-05 16:03:15 -07004606 public boolean isAllAppsButtonRank(int rank) {
4607 if (mHotseat != null) {
4608 return mHotseat.isAllAppsButtonRank(rank);
4609 }
4610 return false;
4611 }
4612
Winson Chunga2413752012-04-03 14:22:34 -07004613 private boolean canRunNewAppsAnimation() {
4614 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4615 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4616 }
4617
Winson Chungc9168342013-06-26 14:54:55 -07004618 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4619 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4620 PropertyValuesHolder.ofFloat("alpha", 1f),
4621 PropertyValuesHolder.ofFloat("scaleX", 1f),
4622 PropertyValuesHolder.ofFloat("scaleY", 1f));
4623 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4624 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4625 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4626 return bounceAnim;
4627 }
4628
Adam Cohen27772732013-11-11 14:00:56 +00004629 public boolean useVerticalBarLayout() {
4630 return LauncherAppState.getInstance().getDynamicGrid().
4631 getDeviceProfile().isVerticalBarLayout();
4632 }
4633
Mac Duy Hai6def4f92013-11-28 16:17:33 +00004634 protected Rect getSearchBarBounds() {
4635 return LauncherAppState.getInstance().getDynamicGrid().
4636 getDeviceProfile().getSearchBarBounds();
4637 }
4638
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004639 @Override
4640 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07004641 boolean searchVisible = updateGlobalSearchIcon();
4642 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungadf0c182012-08-23 14:59:07 -07004643 if (mSearchDropTargetBar != null) {
4644 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4645 }
Narayan Kamathcb1a4772011-06-28 13:46:59 +01004646 }
4647
Amith Yamasani6d7fe502010-11-16 09:05:07 -08004648 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04004649 * Add the icons for all apps.
4650 *
4651 * Implementation of the method from LauncherModel.Callbacks.
4652 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004653 public void bindAllApplications(final ArrayList<AppInfo> apps) {
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004654 if (LauncherAppState.isDisableAllApps()) {
Winson Chungc58497e2013-09-03 17:48:37 -07004655 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4656 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4657 getHotseat().addAllAppsFolder(mIconCache, apps,
4658 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4659 }
4660 mIntentsOnWorkspaceFromUpgradePath = null;
Daniel Sandler8707e0f2013-08-15 15:54:18 -07004661 }
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004662 if (mAppsCustomizeContent != null) {
4663 mAppsCustomizeContent.onPackagesUpdated(
4664 LauncherModel.getSortedWidgetsAndShortcuts(this));
4665 }
Winson Chungc58497e2013-09-03 17:48:37 -07004666 } else {
Winson Chungad7db6e2013-10-08 14:01:06 -07004667 if (mAppsCustomizeContent != null) {
Winson Chungc58497e2013-09-03 17:48:37 -07004668 mAppsCustomizeContent.setApps(apps);
Winson Chung6e1c0d32013-10-25 15:24:24 -07004669 mAppsCustomizeContent.onPackagesUpdated(
4670 LauncherModel.getSortedWidgetsAndShortcuts(this));
Winson Chungc58497e2013-09-03 17:48:37 -07004671 }
Winson Chung785d2eb2011-04-14 16:08:02 -07004672 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004673 }
4674
4675 /**
4676 * A package was updated.
4677 *
4678 * Implementation of the method from LauncherModel.Callbacks.
4679 */
Michael Jurkaeadbfc52013-09-04 00:45:37 +02004680 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
Winson Chungd64d1762013-08-20 14:37:16 -07004681 Runnable r = new Runnable() {
4682 public void run() {
4683 bindAppsUpdated(apps);
4684 }
4685 };
4686 if (waitUntilResume(r)) {
Michael Jurka7607c2f2013-04-03 14:33:19 -07004687 return;
4688 }
4689
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004690 if (mWorkspace != null) {
Sunny Goyal651077b2014-06-30 14:15:31 -07004691 mWorkspace.updateShortcutsAndWidgets(apps);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08004692 }
Winson Chungc58497e2013-09-03 17:48:37 -07004693
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004694 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004695 mAppsCustomizeContent != null) {
4696 mAppsCustomizeContent.updateApps(apps);
4697 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004698 }
4699
4700 /**
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004701 * Update the state of a package, typically related to install state.
4702 *
4703 * Implementation of the method from LauncherModel.Callbacks.
4704 */
Sunny Goyale755d462014-07-22 13:48:29 -07004705 @Override
4706 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004707 if (mWorkspace != null) {
Sunny Goyale755d462014-07-22 13:48:29 -07004708 mWorkspace.updatePackageState(installInfo);
Chris Wrenaeff7ea2014-02-14 16:59:24 -05004709 }
4710 }
4711
4712 /**
Sunny Goyala22666f2014-09-18 13:25:15 -07004713 * Update the label and icon of all the icons in a package
4714 *
4715 * Implementation of the method from LauncherModel.Callbacks.
4716 */
4717 @Override
4718 public void updatePackageBadge(String packageName) {
4719 if (mWorkspace != null) {
4720 mWorkspace.updatePackageBadge(packageName, UserHandleCompat.myUserHandle());
4721 }
4722 }
4723
4724 /**
Winson Chung83892cc2013-05-01 16:53:33 -07004725 * A package was uninstalled. We take both the super set of packageNames
4726 * in addition to specific applications to remove, the reason being that
4727 * this can be called when a package is updated as well. In that scenario,
4728 * we only remove specific components from the workspace, where as
4729 * package-removal should clear all items by package name.
Joe Onorato9c1289c2009-08-17 11:03:03 -04004730 *
4731 * Implementation of the method from LauncherModel.Callbacks.
4732 */
Winson Chung83892cc2013-05-01 16:53:33 -07004733 public void bindComponentsRemoved(final ArrayList<String> packageNames,
Kenny Guyed131872014-04-30 03:02:21 +01004734 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
Winson Chungd64d1762013-08-20 14:37:16 -07004735 Runnable r = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004736 public void run() {
Kenny Guyed131872014-04-30 03:02:21 +01004737 bindComponentsRemoved(packageNames, appInfos, user);
Winson Chung83892cc2013-05-01 16:53:33 -07004738 }
Winson Chungd64d1762013-08-20 14:37:16 -07004739 };
4740 if (waitUntilResume(r)) {
Winson Chung83892cc2013-05-01 16:53:33 -07004741 return;
4742 }
4743
Winson Chungdf95eb12013-10-16 14:57:07 -07004744 if (!packageNames.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004745 mWorkspace.removeItemsByPackageName(packageNames, user);
Winson Chungdf95eb12013-10-16 14:57:07 -07004746 }
4747 if (!appInfos.isEmpty()) {
Kenny Guyed131872014-04-30 03:02:21 +01004748 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
Joe Onorato36115782010-06-17 13:28:48 -04004749 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07004750
Winson Chunga1820962011-10-03 16:31:06 -07004751 // Notify the drag controller
Winson Chungdf95eb12013-10-16 14:57:07 -07004752 mDragController.onAppsRemoved(packageNames, appInfos);
Winson Chungc58497e2013-09-03 17:48:37 -07004753
Winson Chungdf95eb12013-10-16 14:57:07 -07004754 // Update AllApps
Nilesh Agrawal16f3ea82014-01-09 17:14:01 -08004755 if (!LauncherAppState.isDisableAllApps() &&
Winson Chungc58497e2013-09-03 17:48:37 -07004756 mAppsCustomizeContent != null) {
4757 mAppsCustomizeContent.removeApps(appInfos);
4758 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04004759 }
Joe Onoratobe386092009-11-17 17:32:16 -08004760
4761 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07004762 * A number of packages were updated.
4763 */
Michael Jurkac402cd92013-05-20 15:49:32 +02004764 private ArrayList<Object> mWidgetsAndShortcuts;
4765 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
Winson Chung83892cc2013-05-01 16:53:33 -07004766 public void run() {
Michael Jurkac402cd92013-05-20 15:49:32 +02004767 bindPackagesUpdated(mWidgetsAndShortcuts);
4768 mWidgetsAndShortcuts = null;
Winson Chung83892cc2013-05-01 16:53:33 -07004769 }
Michael Jurkac402cd92013-05-20 15:49:32 +02004770 };
Michael Jurkac402cd92013-05-20 15:49:32 +02004771 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4772 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4773 mWidgetsAndShortcuts = widgetsAndShortcuts;
Winson Chung83892cc2013-05-01 16:53:33 -07004774 return;
4775 }
4776
Winson Chung64359a52013-07-08 17:17:08 -07004777 // Update the widgets pane
Nilesh Agrawal306c1cf2013-12-12 14:56:00 -08004778 if (mAppsCustomizeContent != null) {
Michael Jurkac402cd92013-05-20 15:49:32 +02004779 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
Winson Chung785d2eb2011-04-14 16:08:02 -07004780 }
Winson Chung80baf5a2010-08-09 16:03:15 -07004781 }
4782
Winson Chung400438b2011-01-16 17:53:48 -08004783 private int mapConfigurationOriActivityInfoOri(int configOri) {
4784 final Display d = getWindowManager().getDefaultDisplay();
4785 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4786 switch (d.getRotation()) {
4787 case Surface.ROTATION_0:
4788 case Surface.ROTATION_180:
4789 // We are currently in the same basic orientation as the natural orientation
4790 naturalOri = configOri;
4791 break;
4792 case Surface.ROTATION_90:
4793 case Surface.ROTATION_270:
4794 // We are currently in the other basic orientation to the natural orientation
4795 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4796 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4797 break;
4798 }
4799
4800 int[] oriMap = {
4801 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4802 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4803 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4804 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4805 };
4806 // Since the map starts at portrait, we need to offset if this device's natural orientation
4807 // is landscape.
4808 int indexOffset = 0;
4809 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4810 indexOffset = 1;
4811 }
4812 return oriMap[(d.getRotation() + indexOffset) % 4];
4813 }
Adam Cohen446e9402011-09-15 18:21:21 -07004814
Winson Chung4b919f82012-05-01 10:44:08 -07004815 public boolean isRotationEnabled() {
Michael Jurka0a457bf2012-11-19 14:05:05 -08004816 boolean enableRotation = sForceEnableRotation ||
Winson Chung4b919f82012-05-01 10:44:08 -07004817 getResources().getBoolean(R.bool.allow_rotation);
4818 return enableRotation;
Winson Chung400438b2011-01-16 17:53:48 -08004819 }
Winson Chung4b919f82012-05-01 10:44:08 -07004820 public void lockScreenOrientation() {
4821 if (isRotationEnabled()) {
4822 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4823 .getConfiguration().orientation));
4824 }
4825 }
4826 public void unlockScreenOrientation(boolean immediate) {
4827 if (isRotationEnabled()) {
4828 if (immediate) {
Winson Chung641d71d2012-04-26 15:58:01 -07004829 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Winson Chung4b919f82012-05-01 10:44:08 -07004830 } else {
4831 mHandler.postDelayed(new Runnable() {
4832 public void run() {
4833 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4834 }
4835 }, mRestoreScreenOrientationDelay);
Winson Chung641d71d2012-04-26 15:58:01 -07004836 }
Winson Chung4b919f82012-05-01 10:44:08 -07004837 }
Winson Chung400438b2011-01-16 17:53:48 -08004838 }
4839
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004840 /**
4841 * Called when the SearchBar hint should be changed.
4842 *
4843 * @param hint the hint to be displayed in the search bar.
4844 */
4845 protected void onSearchBarHintChanged(String hint) {
Sunny Goyal424418b2014-08-22 16:09:37 -07004846
Sandeep Siddharthad4d3d082013-12-26 15:42:52 -08004847 }
4848
Winson Chunge43a1e72014-01-15 10:33:02 -08004849 protected boolean isLauncherPreinstalled() {
4850 PackageManager pm = getPackageManager();
4851 try {
4852 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4853 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4854 return true;
4855 } else {
4856 return false;
4857 }
4858 } catch (NameNotFoundException e) {
4859 e.printStackTrace();
4860 return false;
4861 }
4862 }
4863
Adam Cohenea90f832014-05-21 15:03:34 -07004864 /**
4865 * This method indicates whether or not we should suggest default wallpaper dimensions
4866 * when our wallpaper cropper was not yet used to set a wallpaper.
4867 */
4868 protected boolean overrideWallpaperDimensions() {
4869 return true;
4870 }
4871
Adam Cohen5eed5d82014-05-19 13:12:13 -07004872 protected boolean shouldClingFocusHotseatApp() {
4873 return false;
4874 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004875 protected String getFirstRunClingSearchBarHint() {
4876 return "";
4877 }
4878 protected String getFirstRunCustomContentHint() {
4879 return "";
4880 }
Winson Chung3a6e7f32013-10-09 15:50:52 -07004881 protected int getFirstRunFocusedHotseatAppDrawableId() {
4882 return -1;
4883 }
4884 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
4885 return null;
4886 }
4887 protected int getFirstRunFocusedHotseatAppRank() {
4888 return -1;
4889 }
4890 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
4891 return "";
4892 }
4893 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
4894 return "";
4895 }
Winson Chunge6eabff2013-09-24 11:01:23 -07004896
Adam Cohen432609a2014-03-13 17:03:22 -07004897 /**
4898 * To be overridden by subclasses to indicate that there is an activity to launch
4899 * before showing the standard launcher experience.
4900 */
4901 protected boolean hasFirstRunActivity() {
4902 return false;
4903 }
4904
4905 /**
4906 * To be overridden by subclasses to launch any first run activity
4907 */
4908 protected Intent getFirstRunActivity() {
4909 return null;
4910 }
4911
Winson Chunga6945242014-01-08 14:04:34 -08004912 private boolean shouldRunFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004913 return !ActivityManager.isRunningInTestHarness() &&
4914 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
Winson Chunga6945242014-01-08 14:04:34 -08004915 }
4916
Adam Cohen4a9423d2014-03-28 14:22:31 -07004917 protected boolean hasRunFirstRunActivity() {
4918 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
4919 }
4920
Adam Cohen432609a2014-03-13 17:03:22 -07004921 public boolean showFirstRunActivity() {
Adam Cohenbc4539d2014-01-14 14:05:32 -08004922 if (shouldRunFirstRunActivity() &&
4923 hasFirstRunActivity()) {
Winson Chunga6945242014-01-08 14:04:34 -08004924 Intent firstRunIntent = getFirstRunActivity();
4925 if (firstRunIntent != null) {
4926 startActivity(firstRunIntent);
4927 markFirstRunActivityShown();
Adam Cohen432609a2014-03-13 17:03:22 -07004928 return true;
Winson Chunga6945242014-01-08 14:04:34 -08004929 }
4930 }
Adam Cohen432609a2014-03-13 17:03:22 -07004931 return false;
Winson Chunga6945242014-01-08 14:04:34 -08004932 }
4933
4934 private void markFirstRunActivityShown() {
4935 SharedPreferences.Editor editor = mSharedPrefs.edit();
4936 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
4937 editor.apply();
4938 }
4939
Adam Cohen432609a2014-03-13 17:03:22 -07004940 /**
4941 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
4942 * screen that must be displayed and dismissed.
4943 */
4944 protected boolean hasDismissableIntroScreen() {
4945 return false;
4946 }
4947
4948 /**
4949 * Full screen intro screen to be shown and dismissed before the launcher can be used.
4950 */
4951 protected View getIntroScreen() {
4952 return null;
4953 }
4954
4955 /**
4956 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
4957 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
4958 */
4959 private boolean shouldShowIntroScreen() {
4960 return hasDismissableIntroScreen() &&
4961 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
4962 }
4963
4964 protected void showIntroScreen() {
4965 View introScreen = getIntroScreen();
4966 changeWallpaperVisiblity(false);
4967 if (introScreen != null) {
4968 mDragLayer.showOverlayView(introScreen);
4969 }
4970 }
4971
4972 public void dismissIntroScreen() {
4973 markIntroScreenDismissed();
4974 if (showFirstRunActivity()) {
4975 // We delay hiding the intro view until the first run activity is showing. This
4976 // avoids a blip.
4977 mWorkspace.postDelayed(new Runnable() {
4978 @Override
4979 public void run() {
4980 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004981 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004982 }
4983 }, ACTIVITY_START_DELAY);
4984 } else {
4985 mDragLayer.dismissOverlayView();
Sunny Goyal88d60f12014-09-08 03:47:29 -07004986 showFirstRunClings();
Adam Cohen432609a2014-03-13 17:03:22 -07004987 }
4988 changeWallpaperVisiblity(true);
4989 }
4990
4991 private void markIntroScreenDismissed() {
4992 SharedPreferences.Editor editor = mSharedPrefs.edit();
4993 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
4994 editor.apply();
4995 }
4996
Sunny Goyal88d60f12014-09-08 03:47:29 -07004997 private void showFirstRunClings() {
4998 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
4999 // on the device, then we always show the first run cling experience (or if there is no
5000 // launcher2). Otherwise, we prompt the user upon started for migration
5001 LauncherClings launcherClings = new LauncherClings(this);
5002 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
5003 if (mModel.canMigrateFromOldLauncherDb(this)) {
5004 launcherClings.showMigrationCling();
5005 } else {
5006 launcherClings.showLongPressCling(false);
5007 }
5008 }
5009 }
5010
Winson Chunga6945242014-01-08 14:04:34 -08005011 void showWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08005012 if (mWorkspace != null) mWorkspace.setAlpha(1f);
5013 if (mHotseat != null) mHotseat.setAlpha(1f);
5014 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
5015 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08005016 }
5017
5018 void hideWorkspaceSearchAndHotseat() {
Winson Chung205cd772014-01-15 14:31:59 -08005019 if (mWorkspace != null) mWorkspace.setAlpha(0f);
5020 if (mHotseat != null) mHotseat.setAlpha(0f);
5021 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
5022 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
Winson Chunga6945242014-01-08 14:04:34 -08005023 }
5024
Mathew Inwood72fbec12013-11-19 15:45:07 +00005025 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
Kenny Guyed131872014-04-30 03:02:21 +01005026 // Called from search suggestion, not supported in other profiles.
5027 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
5028 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
5029 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
5030 myUser);
5031 if (activityInfo == null) {
Mathew Inwood72fbec12013-11-19 15:45:07 +00005032 return null;
5033 }
Kenny Guyed131872014-04-30 03:02:21 +01005034 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005035 }
5036
5037 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5038 Bitmap icon) {
Kenny Guyed131872014-04-30 03:02:21 +01005039 // Called from search suggestion, not supported in other profiles.
5040 return createShortcutDragInfo(shortcutIntent, caption, icon,
5041 UserHandleCompat.myUserHandle());
5042 }
5043
5044 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5045 Bitmap icon, UserHandleCompat user) {
Kenny Guyc2bd8102014-06-30 12:30:31 +01005046 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
Kenny Guyd6fe5262014-07-21 17:11:41 +01005047 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
Kenny Guyc2bd8102014-06-30 12:30:31 +01005048 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005049 }
5050
Mathew Inwoodb90860a2014-04-11 17:17:39 +01005051 protected void moveWorkspaceToDefaultScreen() {
5052 mWorkspace.moveToDefaultScreen(false);
5053 }
5054
Mathew Inwood72fbec12013-11-19 15:45:07 +00005055 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
5056 dragView.setTag(dragInfo);
Winson Chungbabb53e2014-04-14 17:12:49 -07005057 mWorkspace.onExternalDragStartedWithItem(dragView);
5058 mWorkspace.beginExternalDragShared(dragView, source);
Mathew Inwood72fbec12013-11-19 15:45:07 +00005059 }
5060
Anjali Koppalf5d29132014-02-28 13:33:27 -08005061 @Override
5062 public void onPageSwitch(View newPage, int newPageIndex) {
5063 }
5064
Winson Chung80baf5a2010-08-09 16:03:15 -07005065 /**
Joe Onoratobe386092009-11-17 17:32:16 -08005066 * Prints out out state for debugging.
5067 */
5068 public void dumpState() {
Daniel Sandler325dc232013-06-05 22:57:57 -04005069 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08005070 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08005071 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
5072 Log.d(TAG, "mRestoring=" + mRestoring);
5073 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
5074 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07005075 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08005076 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07005077
Winson Chung785d2eb2011-04-14 16:08:02 -07005078 if (mAppsCustomizeContent != null) {
5079 mAppsCustomizeContent.dumpState();
5080 }
Daniel Sandler325dc232013-06-05 22:57:57 -04005081 Log.d(TAG, "END launcher3 dump state");
Joe Onoratobe386092009-11-17 17:32:16 -08005082 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005083
5084 @Override
5085 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5086 super.dump(prefix, fd, writer, args);
Adam Cohen4caf2982013-08-20 18:54:31 -07005087 synchronized (sDumpLogs) {
5088 writer.println(" ");
5089 writer.println("Debug logs: ");
5090 for (int i = 0; i < sDumpLogs.size(); i++) {
5091 writer.println(" " + sDumpLogs.get(i));
5092 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07005093 }
5094 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005095
5096 public static void dumpDebugLogsToConsole() {
Winson Chungede41292013-09-19 16:27:36 -07005097 if (DEBUG_DUMP_LOG) {
5098 synchronized (sDumpLogs) {
5099 Log.d(TAG, "");
5100 Log.d(TAG, "*********************");
5101 Log.d(TAG, "Launcher debug logs: ");
5102 for (int i = 0; i < sDumpLogs.size(); i++) {
5103 Log.d(TAG, " " + sDumpLogs.get(i));
5104 }
5105 Log.d(TAG, "*********************");
5106 Log.d(TAG, "");
Adam Cohen4caf2982013-08-20 18:54:31 -07005107 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005108 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005109 }
5110
5111 public static void addDumpLog(String tag, String log, boolean debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005112 addDumpLog(tag, log, null, debugLog);
5113 }
5114
5115 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
Adam Cohen4caf2982013-08-20 18:54:31 -07005116 if (debugLog) {
Dan Sandler295ae182013-12-10 16:05:47 -05005117 if (e != null) {
5118 Log.d(tag, log, e);
5119 } else {
5120 Log.d(tag, log);
5121 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005122 }
Winson Chungede41292013-09-19 16:27:36 -07005123 if (DEBUG_DUMP_LOG) {
5124 sDateStamp.setTime(System.currentTimeMillis());
5125 synchronized (sDumpLogs) {
Dan Sandler295ae182013-12-10 16:05:47 -05005126 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5127 + (e == null ? "" : (", Exception: " + e)));
Adam Cohen4caf2982013-08-20 18:54:31 -07005128 }
Winson Chungede41292013-09-19 16:27:36 -07005129 }
Adam Cohen4caf2982013-08-20 18:54:31 -07005130 }
5131
Winson Chungede41292013-09-19 16:27:36 -07005132 public void dumpLogsToLocalData() {
5133 if (DEBUG_DUMP_LOG) {
Michael Jurka43467462013-11-14 12:03:58 +01005134 new AsyncTask<Void, Void, Void>() {
5135 public Void doInBackground(Void ... args) {
Winson Chungede41292013-09-19 16:27:36 -07005136 boolean success = false;
5137 sDateStamp.setTime(sRunStart);
5138 String FILENAME = sDateStamp.getMonth() + "-"
5139 + sDateStamp.getDay() + "_"
5140 + sDateStamp.getHours() + "-"
5141 + sDateStamp.getMinutes() + "_"
5142 + sDateStamp.getSeconds() + ".txt";
5143
5144 FileOutputStream fos = null;
5145 File outFile = null;
5146 try {
5147 outFile = new File(getFilesDir(), FILENAME);
5148 outFile.createNewFile();
5149 fos = new FileOutputStream(outFile);
5150 } catch (Exception e) {
5151 e.printStackTrace();
5152 }
5153 if (fos != null) {
5154 PrintWriter writer = new PrintWriter(fos);
5155
5156 writer.println(" ");
5157 writer.println("Debug logs: ");
5158 synchronized (sDumpLogs) {
5159 for (int i = 0; i < sDumpLogs.size(); i++) {
5160 writer.println(" " + sDumpLogs.get(i));
5161 }
5162 }
5163 writer.close();
5164 }
5165 try {
5166 if (fos != null) {
5167 fos.close();
5168 success = true;
5169 }
5170 } catch (IOException e) {
5171 e.printStackTrace();
5172 }
Michael Jurka43467462013-11-14 12:03:58 +01005173 return null;
Winson Chungede41292013-09-19 16:27:36 -07005174 }
Michael Jurka43467462013-11-14 12:03:58 +01005175 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
Adam Cohen4caf2982013-08-20 18:54:31 -07005176 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07005177 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08005178}
Michael Jurka2763be32011-02-24 11:19:57 -08005179
Michael Jurkaabded662011-03-04 12:06:57 -08005180interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08005181 View getContent();
Michael Jurkaa35e35a2012-04-26 15:04:28 -07005182 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurkabed61d22012-02-14 22:51:29 -08005183 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
Winson Chung70442722012-02-10 15:43:22 -08005184 void onLauncherTransitionStep(Launcher l, float t);
Michael Jurkabed61d22012-02-14 22:51:29 -08005185 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08005186}
Dan Sandlerd5024042014-01-09 15:01:33 -05005187
5188interface DebugIntents {
5189 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5190 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
Adam Cohen8b5b05b2014-01-10 21:42:39 +00005191}