Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2 | /* |
| 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 | |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 18 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 19 | |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 20 | import android.animation.Animator; |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 21 | import android.animation.AnimatorListenerAdapter; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 22 | import android.animation.AnimatorSet; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 23 | import android.animation.ObjectAnimator; |
| 24 | import android.animation.PropertyValuesHolder; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 25 | import android.animation.ValueAnimator; |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 26 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 27 | import android.app.Activity; |
Brett Chabot | 2a9e228 | 2011-08-23 15:03:13 -0700 | [diff] [blame] | 28 | import android.app.ActivityManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 29 | import android.app.SearchManager; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 30 | import android.appwidget.AppWidgetHostView; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 31 | import android.appwidget.AppWidgetManager; |
| 32 | import android.appwidget.AppWidgetProviderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 33 | import android.content.ActivityNotFoundException; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 34 | import android.content.BroadcastReceiver; |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 35 | import android.content.ClipData; |
| 36 | import android.content.ClipDescription; |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 37 | import android.content.ComponentCallbacks2; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 38 | import android.content.ComponentName; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 39 | import android.content.ContentResolver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 40 | import android.content.Context; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 41 | import android.content.Intent; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 42 | import android.content.IntentFilter; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 43 | import android.content.SharedPreferences; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 44 | import android.content.pm.ActivityInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 45 | import android.content.pm.PackageManager; |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 46 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 47 | import android.content.res.Configuration; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 48 | import android.content.res.Resources; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 49 | import android.database.ContentObserver; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 50 | import android.graphics.Rect; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 51 | import android.graphics.drawable.Drawable; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 52 | import android.net.Uri; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 53 | import android.os.AsyncTask; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 54 | import android.os.Bundle; |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 55 | import android.os.Environment; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 56 | import android.os.Handler; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 57 | import android.os.Message; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 58 | import android.os.StrictMode; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 59 | import android.os.SystemClock; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 60 | import android.os.SystemProperties; |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 61 | import android.provider.Settings; |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 62 | import android.speech.RecognizerIntent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 63 | import android.text.Selection; |
| 64 | import android.text.SpannableStringBuilder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 65 | import android.text.method.TextKeyListener; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 66 | import android.util.Log; |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 67 | import android.view.Display; |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 68 | import android.view.HapticFeedbackConstants; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 69 | import android.view.KeyEvent; |
| 70 | import android.view.LayoutInflater; |
| 71 | import android.view.Menu; |
| 72 | import android.view.MenuItem; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 73 | import android.view.MotionEvent; |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 74 | import android.view.Surface; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 75 | import android.view.View; |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 76 | import android.view.View.OnLongClickListener; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 77 | import android.view.ViewGroup; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 78 | import android.view.ViewTreeObserver; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 79 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 80 | import android.view.WindowManager; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 81 | import android.view.accessibility.AccessibilityEvent; |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 82 | import android.view.animation.AccelerateDecelerateInterpolator; |
Winson Chung | 7a74ac9 | 2011-09-20 17:43:51 -0700 | [diff] [blame] | 83 | import android.view.animation.AccelerateInterpolator; |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 84 | import android.view.animation.DecelerateInterpolator; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 85 | import android.view.inputmethod.InputMethodManager; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 86 | import android.widget.Advanceable; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 87 | import android.widget.ImageView; |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 88 | import android.widget.TextView; |
| 89 | import android.widget.Toast; |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 90 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 91 | import com.android.common.Search; |
| 92 | import com.android.launcher.R; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 93 | import com.android.launcher2.DropTarget.DragObject; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 94 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 95 | import java.io.DataInputStream; |
| 96 | import java.io.DataOutputStream; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 97 | import java.io.FileDescriptor; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 98 | import java.io.FileNotFoundException; |
| 99 | import java.io.IOException; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 100 | import java.io.PrintWriter; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 101 | import java.util.ArrayList; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 102 | import java.util.Collection; |
| 103 | import java.util.Collections; |
| 104 | import java.util.Comparator; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 105 | import java.util.HashMap; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 106 | import java.util.HashSet; |
| 107 | import java.util.Set; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 108 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 109 | /** |
| 110 | * Default launcher application. |
| 111 | */ |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 112 | public final class Launcher extends Activity |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 113 | implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, |
| 114 | AllAppsView.Watcher, View.OnTouchListener { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 115 | static final String TAG = "Launcher"; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 116 | static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 117 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 118 | static final boolean PROFILE_STARTUP = false; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 119 | static final boolean DEBUG_WIDGETS = false; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 120 | static final boolean DEBUG_STRICT_MODE = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 121 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 122 | private static final int MENU_GROUP_WALLPAPER = 1; |
| 123 | private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1; |
| 124 | private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1; |
Winson Chung | 236d431 | 2011-08-22 15:12:27 -0700 | [diff] [blame] | 125 | private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1; |
| 126 | private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 127 | |
| 128 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 129 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 130 | private static final int REQUEST_PICK_APPLICATION = 6; |
| 131 | private static final int REQUEST_PICK_SHORTCUT = 7; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 132 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 133 | private static final int REQUEST_PICK_WALLPAPER = 10; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 134 | |
| 135 | static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; |
| 136 | |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 137 | static final int SCREEN_COUNT = 5; |
| 138 | static final int DEFAULT_SCREEN = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 139 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 140 | private static final String PREFERENCES = "launcher.preferences"; |
Adam Cohen | 23a4d30 | 2011-12-01 17:26:44 -0800 | [diff] [blame] | 141 | static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher.force_enable_rotation"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 142 | |
| 143 | // Type: int |
| 144 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 145 | // Type: int |
| 146 | private static final String RUNTIME_STATE = "launcher.state"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 147 | // Type: int |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 148 | private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container"; |
| 149 | // Type: int |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 150 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 151 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 152 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 153 | // Type: int |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 154 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 155 | // Type: boolean |
| 156 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 157 | // Type: long |
| 158 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id"; |
| 159 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 160 | private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon"; |
| 161 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 162 | /** The different states that Launcher can be in. */ |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 163 | private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED }; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 164 | private State mState = State.WORKSPACE; |
| 165 | private AnimatorSet mStateAnimation; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 166 | private AnimatorSet mDividerAnimator; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 167 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 168 | static final int APPWIDGET_HOST_ID = 1024; |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 169 | private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300; |
| 170 | private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600; |
Winson Chung | 7a74ac9 | 2011-09-20 17:43:51 -0700 | [diff] [blame] | 171 | private static final int SHOW_CLING_DURATION = 550; |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 172 | private static final int DISMISS_CLING_DURATION = 250; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 173 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 174 | private static final Object sLock = new Object(); |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 175 | private static int sScreen = DEFAULT_SCREEN; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 176 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 177 | // How long to wait before the new-shortcut animation automatically pans the workspace |
| 178 | private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10; |
| 179 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 180 | private final BroadcastReceiver mCloseSystemDialogsReceiver |
| 181 | = new CloseSystemDialogsIntentReceiver(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 182 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 183 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 184 | private LayoutInflater mInflater; |
| 185 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 186 | private Workspace mWorkspace; |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 187 | private View mQsbDivider; |
| 188 | private View mDockDivider; |
| 189 | private DragLayer mDragLayer; |
| 190 | private DragController mDragController; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 191 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 192 | private AppWidgetManager mAppWidgetManager; |
| 193 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 194 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 195 | private ItemInfo mPendingAddInfo = new ItemInfo(); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 196 | private int[] mTmpAddItemCellCoordinates = new int[2]; |
| 197 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 198 | private FolderInfo mFolderInfo; |
| 199 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 200 | private Hotseat mHotseat; |
Michael Jurka | 838a4ca | 2011-02-07 13:33:06 -0800 | [diff] [blame] | 201 | private View mAllAppsButton; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 202 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 203 | private SearchDropTargetBar mSearchDropTargetBar; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 204 | private AppsCustomizeTabHost mAppsCustomizeTabHost; |
| 205 | private AppsCustomizePagedView mAppsCustomizeContent; |
| 206 | private boolean mAutoAdvanceRunning = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 207 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 208 | private Bundle mSavedState; |
| 209 | |
| 210 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 211 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 212 | private boolean mWorkspaceLoading = true; |
| 213 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 214 | private boolean mPaused = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 215 | private boolean mRestoring; |
| 216 | private boolean mWaitingForResult; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 217 | private boolean mOnResumeNeedsLoad; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 218 | |
| 219 | private Bundle mSavedInstanceState; |
| 220 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 221 | private LauncherModel mModel; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 222 | private IconCache mIconCache; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 223 | private boolean mUserPresent = true; |
| 224 | private boolean mVisible = false; |
| 225 | private boolean mAttached = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 226 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 227 | private static LocaleConfiguration sLocaleConfiguration = null; |
| 228 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 229 | private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 230 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 231 | private Intent mAppMarketIntent = null; |
| 232 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 233 | // Related to the auto-advancing of widgets |
| 234 | private final int ADVANCE_MSG = 1; |
| 235 | private final int mAdvanceInterval = 20000; |
| 236 | private final int mAdvanceStagger = 250; |
| 237 | private long mAutoAdvanceSentTime; |
| 238 | private long mAutoAdvanceTimeLeft = -1; |
| 239 | private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = |
| 240 | new HashMap<View, AppWidgetProviderInfo>(); |
| 241 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 242 | // Determines how long to wait after a rotation before restoring the screen orientation to |
| 243 | // match the sensor state. |
| 244 | private final int mRestoreScreenOrientationDelay = 500; |
| 245 | |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 246 | // External icons saved in case of resource changes, orientation, etc. |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 247 | private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2]; |
| 248 | private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2]; |
| 249 | private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2]; |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 250 | |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 251 | static final ArrayList<String> sDumpLogs = new ArrayList<String>(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 252 | PendingAddWidgetInfo mWidgetBeingConfigured = null; |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 253 | |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 254 | // We only want to get the SharedPreferences once since it does an FS stat each time we get |
| 255 | // it from the context. |
| 256 | private SharedPreferences mSharedPrefs; |
| 257 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 258 | // Holds the page that we need to animate to, and the icon views that we need to animate up |
| 259 | // when we scroll to that page on resume. |
| 260 | private int mNewShortcutAnimatePage = -1; |
| 261 | private ArrayList<View> mNewShortcutAnimateViews = new ArrayList<View>(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 262 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 263 | private BubbleTextView mWaitingForResume; |
| 264 | |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 265 | private Runnable mBuildLayersRunnable = new Runnable() { |
| 266 | public void run() { |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 267 | if (mWorkspace != null) { |
| 268 | mWorkspace.buildPageHardwareLayers(); |
| 269 | } |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 270 | } |
| 271 | }; |
| 272 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 273 | private static ArrayList<PendingAddArguments> sPendingAddList |
| 274 | = new ArrayList<PendingAddArguments>(); |
| 275 | |
| 276 | private static class PendingAddArguments { |
| 277 | int requestCode; |
| 278 | Intent intent; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 279 | long container; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 280 | int screen; |
| 281 | int cellX; |
| 282 | int cellY; |
| 283 | } |
| 284 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 285 | @Override |
| 286 | protected void onCreate(Bundle savedInstanceState) { |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 287 | if (DEBUG_STRICT_MODE) { |
| 288 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() |
| 289 | .detectDiskReads() |
| 290 | .detectDiskWrites() |
| 291 | .detectNetwork() // or .detectAll() for all detectable problems |
| 292 | .penaltyLog() |
| 293 | .build()); |
| 294 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
| 295 | .detectLeakedSqlLiteObjects() |
| 296 | .detectLeakedClosableObjects() |
| 297 | .penaltyLog() |
| 298 | .penaltyDeath() |
| 299 | .build()); |
| 300 | } |
| 301 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 302 | super.onCreate(savedInstanceState); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 303 | LauncherApplication app = ((LauncherApplication)getApplication()); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 304 | mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(), |
| 305 | Context.MODE_PRIVATE); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 306 | mModel = app.setLauncher(this); |
| 307 | mIconCache = app.getIconCache(); |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 308 | mDragController = new DragController(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 309 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 310 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 311 | mAppWidgetManager = AppWidgetManager.getInstance(this); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 312 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 313 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 314 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 315 | if (PROFILE_STARTUP) { |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 316 | android.os.Debug.startMethodTracing( |
| 317 | Environment.getExternalStorageDirectory() + "/launcher"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | checkForLocaleChange(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 321 | setContentView(R.layout.launcher); |
| 322 | setupViews(); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 323 | showFirstRunWorkspaceCling(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 324 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 325 | registerContentObservers(); |
| 326 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 327 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 328 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 329 | mSavedState = savedInstanceState; |
| 330 | restoreState(mSavedState); |
| 331 | |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 332 | // Update customization drawer _after_ restoring the states |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 333 | if (mAppsCustomizeContent != null) { |
| 334 | mAppsCustomizeContent.onPackagesUpdated(); |
| 335 | } |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 336 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 337 | if (PROFILE_STARTUP) { |
| 338 | android.os.Debug.stopMethodTracing(); |
| 339 | } |
| 340 | |
| 341 | if (!mRestoring) { |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 342 | mModel.startLoader(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 343 | } |
| 344 | |
Michael Jurka | c57b7a8 | 2011-08-09 22:02:20 -0700 | [diff] [blame] | 345 | if (!mModel.isAllAppsLoaded()) { |
| 346 | ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent(); |
| 347 | mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent); |
| 348 | } |
| 349 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 350 | // For handling default keys |
| 351 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 352 | Selection.setSelection(mDefaultKeySsb, 0); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 353 | |
| 354 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 355 | registerReceiver(mCloseSystemDialogsReceiver, filter); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 356 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 357 | boolean searchVisible = false; |
| 358 | boolean voiceVisible = false; |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 359 | // If we have a saved version of these external icons, we load them up immediately |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 360 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 361 | if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null || |
| 362 | sAppMarketIcon[coi] == null) { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 363 | updateAppMarketIcon(); |
| 364 | searchVisible = updateGlobalSearchIcon(); |
| 365 | voiceVisible = updateVoiceSearchIcon(searchVisible); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 366 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 367 | if (sGlobalSearchIcon[coi] != null) { |
| 368 | updateGlobalSearchIcon(sGlobalSearchIcon[coi]); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 369 | searchVisible = true; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 370 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 371 | if (sVoiceSearchIcon[coi] != null) { |
| 372 | updateVoiceSearchIcon(sVoiceSearchIcon[coi]); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 373 | voiceVisible = true; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 374 | } |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 375 | if (sAppMarketIcon[coi] != null) { |
| 376 | updateAppMarketIcon(sAppMarketIcon[coi]); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 377 | } |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 378 | mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 379 | |
Adam Cohen | 23a4d30 | 2011-12-01 17:26:44 -0800 | [diff] [blame] | 380 | final String forceEnableRotation = |
| 381 | SystemProperties.get(FORCE_ENABLE_ROTATION_PROPERTY, "false"); |
| 382 | |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 383 | // On large interfaces, we want the screen to auto-rotate based on the current orientation |
Adam Cohen | 23a4d30 | 2011-12-01 17:26:44 -0800 | [diff] [blame] | 384 | if (LauncherApplication.isScreenLarge() || "true".equalsIgnoreCase(forceEnableRotation)) { |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 385 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 386 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 387 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 388 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 389 | private void checkForLocaleChange() { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 390 | if (sLocaleConfiguration == null) { |
| 391 | new AsyncTask<Void, Void, LocaleConfiguration>() { |
| 392 | @Override |
| 393 | protected LocaleConfiguration doInBackground(Void... unused) { |
| 394 | LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
| 395 | readConfiguration(Launcher.this, localeConfiguration); |
| 396 | return localeConfiguration; |
| 397 | } |
| 398 | |
| 399 | @Override |
| 400 | protected void onPostExecute(LocaleConfiguration result) { |
| 401 | sLocaleConfiguration = result; |
| 402 | checkForLocaleChange(); // recursive, but now with a locale configuration |
| 403 | } |
| 404 | }.execute(); |
| 405 | return; |
| 406 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 407 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 408 | final Configuration configuration = getResources().getConfiguration(); |
| 409 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 410 | final String previousLocale = sLocaleConfiguration.locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 411 | final String locale = configuration.locale.toString(); |
| 412 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 413 | final int previousMcc = sLocaleConfiguration.mcc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 414 | final int mcc = configuration.mcc; |
| 415 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 416 | final int previousMnc = sLocaleConfiguration.mnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 417 | final int mnc = configuration.mnc; |
| 418 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 419 | boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 420 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 421 | if (localeChanged) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 422 | sLocaleConfiguration.locale = locale; |
| 423 | sLocaleConfiguration.mcc = mcc; |
| 424 | sLocaleConfiguration.mnc = mnc; |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 425 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 426 | mIconCache.flush(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 427 | |
| 428 | final LocaleConfiguration localeConfiguration = sLocaleConfiguration; |
| 429 | new Thread("WriteLocaleConfiguration") { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 430 | @Override |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 431 | public void run() { |
| 432 | writeConfiguration(Launcher.this, localeConfiguration); |
| 433 | } |
| 434 | }.start(); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | |
| 438 | private static class LocaleConfiguration { |
| 439 | public String locale; |
| 440 | public int mcc = -1; |
| 441 | public int mnc = -1; |
| 442 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 443 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 444 | private static void readConfiguration(Context context, LocaleConfiguration configuration) { |
| 445 | DataInputStream in = null; |
| 446 | try { |
| 447 | in = new DataInputStream(context.openFileInput(PREFERENCES)); |
| 448 | configuration.locale = in.readUTF(); |
| 449 | configuration.mcc = in.readInt(); |
| 450 | configuration.mnc = in.readInt(); |
| 451 | } catch (FileNotFoundException e) { |
| 452 | // Ignore |
| 453 | } catch (IOException e) { |
| 454 | // Ignore |
| 455 | } finally { |
| 456 | if (in != null) { |
| 457 | try { |
| 458 | in.close(); |
| 459 | } catch (IOException e) { |
| 460 | // Ignore |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | private static void writeConfiguration(Context context, LocaleConfiguration configuration) { |
| 467 | DataOutputStream out = null; |
| 468 | try { |
| 469 | out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE)); |
| 470 | out.writeUTF(configuration.locale); |
| 471 | out.writeInt(configuration.mcc); |
| 472 | out.writeInt(configuration.mnc); |
| 473 | out.flush(); |
| 474 | } catch (FileNotFoundException e) { |
| 475 | // Ignore |
| 476 | } catch (IOException e) { |
| 477 | //noinspection ResultOfMethodCallIgnored |
| 478 | context.getFileStreamPath(PREFERENCES).delete(); |
| 479 | } finally { |
| 480 | if (out != null) { |
| 481 | try { |
| 482 | out.close(); |
| 483 | } catch (IOException e) { |
| 484 | // Ignore |
| 485 | } |
| 486 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 490 | public DragLayer getDragLayer() { |
| 491 | return mDragLayer; |
| 492 | } |
| 493 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 494 | static int getScreen() { |
| 495 | synchronized (sLock) { |
| 496 | return sScreen; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | static void setScreen(int screen) { |
| 501 | synchronized (sLock) { |
| 502 | sScreen = screen; |
| 503 | } |
| 504 | } |
| 505 | |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 506 | /** |
| 507 | * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have |
| 508 | * a configuration step, this allows the proper animations to run after other transitions. |
| 509 | */ |
| 510 | private boolean completeAdd(PendingAddArguments args) { |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 511 | boolean result = false; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 512 | switch (args.requestCode) { |
| 513 | case REQUEST_PICK_APPLICATION: |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 514 | completeAddApplication(args.intent, args.container, args.screen, args.cellX, |
| 515 | args.cellY); |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 516 | break; |
| 517 | case REQUEST_PICK_SHORTCUT: |
| 518 | processShortcut(args.intent); |
| 519 | break; |
| 520 | case REQUEST_CREATE_SHORTCUT: |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 521 | completeAddShortcut(args.intent, args.container, args.screen, args.cellX, |
| 522 | args.cellY); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 523 | result = true; |
| 524 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 525 | case REQUEST_PICK_APPWIDGET: |
| 526 | addAppWidgetFromPick(args.intent); |
| 527 | break; |
| 528 | case REQUEST_CREATE_APPWIDGET: |
| 529 | int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 530 | completeAddAppWidget(appWidgetId, args.container, args.screen, null, null); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 531 | result = true; |
| 532 | break; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 533 | case REQUEST_PICK_WALLPAPER: |
| 534 | // We just wanted the activity result here so we can clear mWaitingForResult |
| 535 | break; |
| 536 | } |
Michael Jurka | 27614d2 | 2012-04-02 06:40:22 -0700 | [diff] [blame] | 537 | // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen, |
| 538 | // if you turned the screen off and then back while in All Apps, Launcher would not |
| 539 | // return to the workspace. Clearing mAddInfo.container here fixes this issue |
| 540 | resetAddInfo(); |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 541 | return result; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 542 | } |
| 543 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 544 | @Override |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 545 | protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 546 | boolean delayExitSpringLoadedMode = false; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 547 | boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || |
| 548 | requestCode == REQUEST_CREATE_APPWIDGET); |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 549 | mWaitingForResult = false; |
| 550 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 551 | // We have special handling for widgets |
| 552 | if (isWidgetDrop) { |
| 553 | int appWidgetId = data != null ? |
| 554 | data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; |
| 555 | completeTwoStageWidgetDrop(resultCode, appWidgetId); |
| 556 | return; |
| 557 | } |
| 558 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 559 | // The pattern used here is that a user PICKs a specific application, |
| 560 | // which, depending on the target, might need to CREATE the actual target. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 561 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 562 | // For example, the user would PICK_SHORTCUT for "Music playlist", and we |
| 563 | // launch over to the Music app to actually CREATE_SHORTCUT. |
Winson Chung | c7da555 | 2011-08-10 15:28:45 -0700 | [diff] [blame] | 564 | if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) { |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 565 | final PendingAddArguments args = new PendingAddArguments(); |
| 566 | args.requestCode = requestCode; |
| 567 | args.intent = data; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 568 | args.container = mPendingAddInfo.container; |
| 569 | args.screen = mPendingAddInfo.screen; |
| 570 | args.cellX = mPendingAddInfo.cellX; |
| 571 | args.cellY = mPendingAddInfo.cellY; |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 572 | if (isWorkspaceLocked()) { |
| 573 | sPendingAddList.add(args); |
| 574 | } else { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 575 | delayExitSpringLoadedMode = completeAdd(args); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 576 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 577 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 578 | mDragLayer.clearAnimatedView(); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 579 | // Exit spring loaded mode if necessary after cancelling the configuration of a widget |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 580 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode, |
| 581 | null); |
| 582 | } |
| 583 | |
| 584 | private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) { |
| 585 | CellLayout cellLayout = (CellLayout) mWorkspace.getChildAt(mWidgetBeingConfigured.screen); |
| 586 | Runnable onCompleteRunnable = null; |
| 587 | int animationType = 0; |
| 588 | |
| 589 | if (resultCode == RESULT_OK) { |
| 590 | animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; |
| 591 | final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, |
| 592 | mWidgetBeingConfigured.info); |
| 593 | mWidgetBeingConfigured.boundWidget = layout; |
| 594 | onCompleteRunnable = new Runnable() { |
| 595 | @Override |
| 596 | public void run() { |
| 597 | completeAddAppWidget(appWidgetId, mPendingAddInfo.container, |
| 598 | mPendingAddInfo.screen, layout, null); |
| 599 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false, |
| 600 | null); |
| 601 | } |
| 602 | }; |
| 603 | } else if (resultCode == RESULT_CANCELED) { |
| 604 | animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION; |
| 605 | onCompleteRunnable = new Runnable() { |
| 606 | @Override |
| 607 | public void run() { |
| 608 | exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false, |
| 609 | null); |
| 610 | } |
| 611 | }; |
| 612 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 613 | mWorkspace.animateWidgetDrop(mWidgetBeingConfigured, cellLayout, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 614 | (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 615 | animationType, mWidgetBeingConfigured.boundWidget, true); |
Adam Cohen | 1b36dc3 | 2012-02-13 19:27:37 -0800 | [diff] [blame] | 616 | mWidgetBeingConfigured = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | @Override |
| 620 | protected void onResume() { |
| 621 | super.onResume(); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 622 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 623 | mPaused = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 624 | if (mRestoring || mOnResumeNeedsLoad) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 625 | mWorkspaceLoading = true; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 626 | mModel.startLoader(true); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 627 | mRestoring = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 628 | mOnResumeNeedsLoad = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 629 | } |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 630 | |
| 631 | // Reset the pressed state of icons that were locked in the press state while activities |
| 632 | // were launching |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 633 | if (mWaitingForResume != null) { |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 634 | // Resets the previous workspace icon press state |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 635 | mWaitingForResume.setStayPressed(false); |
| 636 | } |
Winson Chung | e4e5066 | 2012-01-23 14:45:13 -0800 | [diff] [blame] | 637 | if (mAppsCustomizeContent != null) { |
| 638 | // Resets the previous all apps icon press state |
| 639 | mAppsCustomizeContent.resetDrawableState(); |
| 640 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 644 | protected void onPause() { |
| 645 | super.onPause(); |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 646 | mPaused = true; |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 647 | mDragController.cancelDrag(); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 648 | mDragController.resetLastGestureUpTime(); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 649 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 650 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 651 | @Override |
| 652 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 653 | // Flag the loader to stop early before switching |
| 654 | mModel.stopLoader(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 655 | if (mAppsCustomizeContent != null) { |
| 656 | mAppsCustomizeContent.surrender(); |
| 657 | } |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 658 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 659 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 660 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 661 | // We can't hide the IME if it was forced open. So don't bother |
| 662 | /* |
| 663 | @Override |
| 664 | public void onWindowFocusChanged(boolean hasFocus) { |
| 665 | super.onWindowFocusChanged(hasFocus); |
| 666 | |
| 667 | if (hasFocus) { |
| 668 | final InputMethodManager inputManager = (InputMethodManager) |
| 669 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 670 | WindowManager.LayoutParams lp = getWindow().getAttributes(); |
| 671 | inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new |
| 672 | android.os.Handler()) { |
| 673 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 674 | Log.d(TAG, "ResultReceiver got resultCode=" + resultCode); |
| 675 | } |
| 676 | }); |
| 677 | Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged"); |
| 678 | } |
| 679 | } |
| 680 | */ |
| 681 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 682 | private boolean acceptFilter() { |
| 683 | final InputMethodManager inputManager = (InputMethodManager) |
| 684 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 685 | return !inputManager.isFullscreenMode(); |
| 686 | } |
| 687 | |
| 688 | @Override |
| 689 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 690 | final int uniChar = event.getUnicodeChar(); |
| 691 | final boolean handled = super.onKeyDown(keyCode, event); |
| 692 | final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar); |
| 693 | if (!handled && acceptFilter() && isKeyNotWhitespace) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 694 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 695 | keyCode, event); |
| 696 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 697 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 698 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 699 | // showSearchDialog() |
| 700 | // If there are multiple keystrokes before the search dialog takes focus, |
| 701 | // onSearchRequested() will be called for every keystroke, |
| 702 | // but it is idempotent, so it's fine. |
| 703 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 707 | // Eat the long press event so the keyboard doesn't come up. |
| 708 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 709 | return true; |
| 710 | } |
| 711 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 712 | return handled; |
| 713 | } |
| 714 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 715 | private String getTypedText() { |
| 716 | return mDefaultKeySsb.toString(); |
| 717 | } |
| 718 | |
| 719 | private void clearTypedText() { |
| 720 | mDefaultKeySsb.clear(); |
| 721 | mDefaultKeySsb.clearSpans(); |
| 722 | Selection.setSelection(mDefaultKeySsb, 0); |
| 723 | } |
| 724 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 725 | /** |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 726 | * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type |
| 727 | * State |
| 728 | */ |
| 729 | private static State intToState(int stateOrdinal) { |
| 730 | State state = State.WORKSPACE; |
| 731 | final State[] stateValues = State.values(); |
| 732 | for (int i = 0; i < stateValues.length; i++) { |
| 733 | if (stateValues[i].ordinal() == stateOrdinal) { |
| 734 | state = stateValues[i]; |
| 735 | break; |
| 736 | } |
| 737 | } |
| 738 | return state; |
| 739 | } |
| 740 | |
| 741 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 742 | * Restores the previous state, if it exists. |
| 743 | * |
| 744 | * @param savedState The previous state. |
| 745 | */ |
| 746 | private void restoreState(Bundle savedState) { |
| 747 | if (savedState == null) { |
| 748 | return; |
| 749 | } |
| 750 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 751 | State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal())); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 752 | if (state == State.APPS_CUSTOMIZE) { |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 753 | showAllApps(false); |
| 754 | } |
| 755 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 756 | int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 757 | if (currentScreen > -1) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 758 | mWorkspace.setCurrentPage(currentScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 759 | } |
| 760 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 761 | final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1); |
| 762 | final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 763 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 764 | if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) { |
| 765 | mPendingAddInfo.container = pendingAddContainer; |
| 766 | mPendingAddInfo.screen = pendingAddScreen; |
| 767 | mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 768 | mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 769 | mRestoring = true; |
| 770 | } |
| 771 | |
| 772 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 773 | if (renameFolder) { |
| 774 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 775 | mFolderInfo = mModel.getFolderById(this, sFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 776 | mRestoring = true; |
| 777 | } |
Winson Chung | a12a250 | 2010-12-20 14:41:35 -0800 | [diff] [blame] | 778 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 779 | |
| 780 | // Restore the AppsCustomize tab |
| 781 | if (mAppsCustomizeTabHost != null) { |
| 782 | String curTab = savedState.getString("apps_customize_currentTab"); |
| 783 | if (curTab != null) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 784 | // We set this directly so that there is no delay before the tab is set |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 785 | mAppsCustomizeContent.setContentType( |
| 786 | mAppsCustomizeTabHost.getContentTypeForTabTag(curTab)); |
| 787 | mAppsCustomizeTabHost.setCurrentTabByTag(curTab); |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 788 | mAppsCustomizeContent.loadAssociatedPages( |
| 789 | mAppsCustomizeContent.getCurrentPage()); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 792 | int currentIndex = savedState.getInt("apps_customize_currentIndex"); |
| 793 | mAppsCustomizeContent.restorePageForIndex(currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 794 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | /** |
| 798 | * Finds all the views we need and configure them properly. |
| 799 | */ |
| 800 | private void setupViews() { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 801 | final DragController dragController = mDragController; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 802 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 803 | mDragLayer = (DragLayer) findViewById(R.id.drag_layer); |
| 804 | mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace); |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 805 | mQsbDivider = (ImageView) findViewById(R.id.qsb_divider); |
| 806 | mDockDivider = (ImageView) findViewById(R.id.dock_divider); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 807 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 808 | // Setup the drag layer |
| 809 | mDragLayer.setup(this, dragController); |
| 810 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 811 | // Setup the hotseat |
| 812 | mHotseat = (Hotseat) findViewById(R.id.hotseat); |
| 813 | if (mHotseat != null) { |
| 814 | mHotseat.setup(this); |
| 815 | } |
| 816 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 817 | // Setup the workspace |
| 818 | mWorkspace.setHapticFeedbackEnabled(false); |
| 819 | mWorkspace.setOnLongClickListener(this); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 820 | mWorkspace.setup(dragController); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 821 | dragController.addDragListener(mWorkspace); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 822 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 823 | // Get the search/delete bar |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 824 | mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 825 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 826 | // Setup AppsCustomize |
| 827 | mAppsCustomizeTabHost = (AppsCustomizeTabHost) |
| 828 | findViewById(R.id.apps_customize_pane); |
| 829 | mAppsCustomizeContent = (AppsCustomizePagedView) |
| 830 | mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content); |
| 831 | mAppsCustomizeContent.setup(this, dragController); |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 832 | |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 833 | // Get the all apps button |
| 834 | mAllAppsButton = findViewById(R.id.all_apps_button); |
| 835 | if (mAllAppsButton != null) { |
| 836 | mAllAppsButton.setOnTouchListener(new View.OnTouchListener() { |
| 837 | @Override |
| 838 | public boolean onTouch(View v, MotionEvent event) { |
| 839 | if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { |
| 840 | onTouchDownAllAppsButton(v); |
| 841 | } |
| 842 | return false; |
| 843 | } |
| 844 | }); |
| 845 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 846 | // Setup the drag controller (drop targets have to be added in reverse order in priority) |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 847 | dragController.setDragScoller(mWorkspace); |
| 848 | dragController.setScrollView(mDragLayer); |
| 849 | dragController.setMoveTarget(mWorkspace); |
| 850 | dragController.addDropTarget(mWorkspace); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 851 | if (mSearchDropTargetBar != null) { |
| 852 | mSearchDropTargetBar.setup(this, dragController); |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 853 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | /** |
| 857 | * Creates a view representing a shortcut. |
| 858 | * |
| 859 | * @param info The data structure describing the shortcut. |
| 860 | * |
| 861 | * @return A View inflated from R.layout.application. |
| 862 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 863 | View createShortcut(ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 864 | return createShortcut(R.layout.application, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 865 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | /** |
| 869 | * Creates a view representing a shortcut inflated from the specified resource. |
| 870 | * |
| 871 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 872 | * @param parent The group the shortcut belongs to. |
| 873 | * @param info The data structure describing the shortcut. |
| 874 | * |
| 875 | * @return A View inflated from layoutResId. |
| 876 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 877 | View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 878 | BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); |
| 879 | favorite.applyFromShortcutInfo(info, mIconCache); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 880 | favorite.setOnClickListener(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 881 | return favorite; |
| 882 | } |
| 883 | |
| 884 | /** |
| 885 | * Add an application shortcut to the workspace. |
| 886 | * |
| 887 | * @param data The intent describing the application. |
| 888 | * @param cellInfo The position on screen where to create the shortcut. |
| 889 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 890 | void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 891 | final int[] cellXY = mTmpAddItemCellCoordinates; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 892 | final CellLayout layout = getCellLayout(container, screen); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 893 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 894 | // First we check if we already know the exact location where we want to add this item. |
| 895 | if (cellX >= 0 && cellY >= 0) { |
| 896 | cellXY[0] = cellX; |
| 897 | cellXY[1] = cellY; |
| 898 | } else if (!layout.findCellForSpan(cellXY, 1, 1)) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 899 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 900 | return; |
| 901 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 902 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 903 | final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 904 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 905 | if (info != null) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 906 | info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 907 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 908 | info.container = ItemInfo.NO_ID; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 909 | mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1], |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 910 | isWorkspaceLocked(), cellX, cellY); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 911 | } else { |
| 912 | Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 913 | } |
| 914 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 915 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 916 | /** |
| 917 | * Add a shortcut to the workspace. |
| 918 | * |
| 919 | * @param data The intent describing the shortcut. |
| 920 | * @param cellInfo The position on screen where to create the shortcut. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 921 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 922 | private void completeAddShortcut(Intent data, long container, int screen, int cellX, |
| 923 | int cellY) { |
| 924 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 925 | int[] touchXY = mPendingAddInfo.dropPos; |
| 926 | CellLayout layout = getCellLayout(container, screen); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 927 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 928 | boolean foundCellSpan = false; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 929 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 930 | ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null); |
Adam Cohen | d919882 | 2011-11-22 16:42:47 -0800 | [diff] [blame] | 931 | if (info == null) { |
| 932 | return; |
| 933 | } |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 934 | final View view = createShortcut(info); |
| 935 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 936 | // First we check if we already know the exact location where we want to add this item. |
| 937 | if (cellX >= 0 && cellY >= 0) { |
| 938 | cellXY[0] = cellX; |
| 939 | cellXY[1] = cellY; |
| 940 | foundCellSpan = true; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 941 | |
| 942 | // If appropriate, either create a folder or add to an existing folder |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 943 | if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 944 | true, null,null)) { |
| 945 | return; |
| 946 | } |
| 947 | DragObject dragObject = new DragObject(); |
| 948 | dragObject.dragInfo = info; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 949 | if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, |
| 950 | true)) { |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 951 | return; |
| 952 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 953 | } else if (touchXY != null) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 954 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 955 | int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 956 | foundCellSpan = (result != null); |
| 957 | } else { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 958 | foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | if (!foundCellSpan) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 962 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 963 | return; |
| 964 | } |
| 965 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 966 | LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 967 | |
| 968 | if (!mRestoring) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 969 | mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1, |
| 970 | isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 971 | } |
| 972 | } |
| 973 | |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 974 | int[] getSpanForWidget(ComponentName component, int minWidth, int minHeight) { |
Adam Cohen | 0cf2a7c | 2011-11-08 15:07:01 -0800 | [diff] [blame] | 975 | Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(this, component, null); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 976 | // We want to account for the extra amount of padding that we are adding to the widget |
| 977 | // to ensure that it gets the full amount of space that it has requested |
| 978 | int requiredWidth = minWidth + padding.left + padding.right; |
| 979 | int requiredHeight = minHeight + padding.top + padding.bottom; |
| 980 | return CellLayout.rectToCell(getResources(), requiredWidth, requiredHeight, null); |
| 981 | } |
| 982 | |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 983 | int[] getSpanForWidget(AppWidgetProviderInfo info) { |
| 984 | return getSpanForWidget(info.provider, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 985 | } |
| 986 | |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 987 | int[] getMinSpanForWidget(AppWidgetProviderInfo info) { |
| 988 | return getSpanForWidget(info.provider, info.minResizeWidth, info.minResizeHeight); |
Adam Cohen | cbf47e3 | 2011-09-16 17:32:37 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 991 | int[] getSpanForWidget(PendingAddWidgetInfo info) { |
| 992 | return getSpanForWidget(info.componentName, info.minWidth, info.minHeight); |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 995 | int[] getMinSpanForWidget(PendingAddWidgetInfo info) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 996 | return getSpanForWidget(info.componentName, info.minResizeWidth, |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 997 | info.minResizeHeight); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 998 | } |
| 999 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1000 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1001 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1002 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1003 | * @param appWidgetId The app widget id |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1004 | * @param cellInfo The position on screen where to create the widget. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1005 | */ |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1006 | private void completeAddAppWidget(final int appWidgetId, long container, int screen, |
| 1007 | AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) { |
| 1008 | if (appWidgetInfo == null) { |
| 1009 | appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
| 1010 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1011 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1012 | // Calculate the grid spans needed to fit this widget |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1013 | CellLayout layout = getCellLayout(container, screen); |
Adam Cohen | 0935386 | 2011-07-14 16:10:03 -0700 | [diff] [blame] | 1014 | |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 1015 | int[] minSpanXY = getMinSpanForWidget(appWidgetInfo); |
| 1016 | int[] spanXY = getSpanForWidget(appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1017 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1018 | // Try finding open space on Launcher screen |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1019 | // We have saved the position to which the widget was dragged-- this really only matters |
| 1020 | // if we are placing widgets on a "spring-loaded" screen |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1021 | int[] cellXY = mTmpAddItemCellCoordinates; |
| 1022 | int[] touchXY = mPendingAddInfo.dropPos; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1023 | int[] finalSpan = new int[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1024 | boolean foundCellSpan = false; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1025 | if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) { |
| 1026 | cellXY[0] = mPendingAddInfo.cellX; |
| 1027 | cellXY[1] = mPendingAddInfo.cellY; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1028 | spanXY[0] = mPendingAddInfo.spanX; |
| 1029 | spanXY[1] = mPendingAddInfo.spanY; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1030 | foundCellSpan = true; |
| 1031 | } else if (touchXY != null) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1032 | // when dragging and dropping, just find the closest free spot |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1033 | int[] result = layout.findNearestVacantArea( |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1034 | touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0], |
| 1035 | spanXY[1], cellXY, finalSpan); |
| 1036 | spanXY[0] = finalSpan[0]; |
| 1037 | spanXY[1] = finalSpan[1]; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1038 | foundCellSpan = (result != null); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1039 | } else { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1040 | foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1043 | if (!foundCellSpan) { |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1044 | if (appWidgetId != -1) { |
| 1045 | // Deleting an app widget ID is a void call but writes to disk before returning |
| 1046 | // to the caller... |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 1047 | new Thread("deleteAppWidgetId") { |
| 1048 | public void run() { |
| 1049 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
| 1050 | } |
| 1051 | }.start(); |
| 1052 | } |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1053 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 1054 | return; |
| 1055 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1056 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1057 | // Build Launcher-specific widget info and save to database |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 1058 | LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1059 | launcherInfo.spanX = spanXY[0]; |
| 1060 | launcherInfo.spanY = spanXY[1]; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1061 | launcherInfo.minSpanX = mPendingAddInfo.minSpanX; |
| 1062 | launcherInfo.minSpanY = mPendingAddInfo.minSpanY; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1063 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1064 | LauncherModel.addItemToDatabase(this, launcherInfo, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1065 | container, screen, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1066 | |
| 1067 | if (!mRestoring) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1068 | if (hostView == null) { |
| 1069 | // Perform actual inflation because we're live |
| 1070 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 1071 | launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
| 1072 | } else { |
| 1073 | // The AppWidgetHostView has already been inflated and instantiated |
| 1074 | launcherInfo.hostView = hostView; |
| 1075 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1076 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1077 | launcherInfo.hostView.setTag(launcherInfo); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1078 | launcherInfo.hostView.setVisibility(View.VISIBLE); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1079 | mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1], |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1080 | launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1081 | |
| 1082 | addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1083 | } |
Adam Cohen | 6af9af0 | 2012-02-02 15:41:45 -0800 | [diff] [blame] | 1084 | resetAddInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1085 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1086 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1087 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 1088 | @Override |
| 1089 | public void onReceive(Context context, Intent intent) { |
| 1090 | final String action = intent.getAction(); |
| 1091 | if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1092 | mUserPresent = false; |
Adam Cohen | bec6ac5 | 2011-07-19 20:50:27 -0700 | [diff] [blame] | 1093 | mDragLayer.clearAllResizeFrames(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1094 | updateRunning(); |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 1095 | |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1096 | // Reset AllApps to its initial state only if we are not in the middle of |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 1097 | // processing a multi-step drop |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1098 | if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) { |
| 1099 | mAppsCustomizeTabHost.reset(); |
| 1100 | showWorkspace(false); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1101 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1102 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 1103 | mUserPresent = true; |
| 1104 | updateRunning(); |
| 1105 | } |
| 1106 | } |
| 1107 | }; |
| 1108 | |
| 1109 | @Override |
| 1110 | public void onAttachedToWindow() { |
| 1111 | super.onAttachedToWindow(); |
| 1112 | |
| 1113 | // Listen for broadcasts related to user-presence |
| 1114 | final IntentFilter filter = new IntentFilter(); |
| 1115 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 1116 | filter.addAction(Intent.ACTION_USER_PRESENT); |
| 1117 | registerReceiver(mReceiver, filter); |
| 1118 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1119 | mAttached = true; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1120 | mVisible = true; |
| 1121 | } |
| 1122 | |
| 1123 | @Override |
| 1124 | public void onDetachedFromWindow() { |
| 1125 | super.onDetachedFromWindow(); |
| 1126 | mVisible = false; |
Adam Cohen | bec6ac5 | 2011-07-19 20:50:27 -0700 | [diff] [blame] | 1127 | mDragLayer.clearAllResizeFrames(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1128 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1129 | if (mAttached) { |
| 1130 | unregisterReceiver(mReceiver); |
| 1131 | mAttached = false; |
| 1132 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1133 | updateRunning(); |
| 1134 | } |
| 1135 | |
| 1136 | public void onWindowVisibilityChanged(int visibility) { |
| 1137 | mVisible = visibility == View.VISIBLE; |
| 1138 | updateRunning(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1139 | // The following code used to be in onResume, but it turns out onResume is called when |
| 1140 | // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged |
| 1141 | // is a more appropriate event to handle |
| 1142 | if (mVisible) { |
| 1143 | mAppsCustomizeTabHost.onWindowVisible(); |
| 1144 | if (!mWorkspaceLoading) { |
| 1145 | final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1146 | // We want to let Launcher draw itself at least once before we force it to build |
| 1147 | // layers on all the workspace pages, so that transitioning to Launcher from other |
| 1148 | // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to |
| 1149 | // a true draw so we wait until the second preDraw call to be safe |
| 1150 | observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1151 | public boolean onPreDraw() { |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1152 | // We delay the layer building a bit in order to give |
| 1153 | // other message processing a time to run. In particular |
| 1154 | // this avoids a delay in hiding the IME if it was |
| 1155 | // currently shown, because doing that may involve |
| 1156 | // some communication back with the app. |
Winson Chung | aeae56b | 2012-02-24 15:47:27 -0800 | [diff] [blame] | 1157 | mWorkspace.postDelayed(mBuildLayersRunnable, 500); |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1158 | observer.removeOnPreDrawListener(this); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1159 | return true; |
| 1160 | } |
| 1161 | }); |
| 1162 | } |
Michael Jurka | 6ee21d2 | 2012-02-21 18:20:27 -0800 | [diff] [blame] | 1163 | // When Launcher comes back to foreground, a different Activity might be responsible for |
| 1164 | // the app market intent, so refresh the icon |
| 1165 | updateAppMarketIcon(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1166 | clearTypedText(); |
| 1167 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | private void sendAdvanceMessage(long delay) { |
| 1171 | mHandler.removeMessages(ADVANCE_MSG); |
| 1172 | Message msg = mHandler.obtainMessage(ADVANCE_MSG); |
| 1173 | mHandler.sendMessageDelayed(msg, delay); |
| 1174 | mAutoAdvanceSentTime = System.currentTimeMillis(); |
| 1175 | } |
| 1176 | |
| 1177 | private void updateRunning() { |
| 1178 | boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty(); |
| 1179 | if (autoAdvanceRunning != mAutoAdvanceRunning) { |
| 1180 | mAutoAdvanceRunning = autoAdvanceRunning; |
| 1181 | if (autoAdvanceRunning) { |
| 1182 | long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft; |
| 1183 | sendAdvanceMessage(delay); |
| 1184 | } else { |
| 1185 | if (!mWidgetsToAdvance.isEmpty()) { |
| 1186 | mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval - |
| 1187 | (System.currentTimeMillis() - mAutoAdvanceSentTime)); |
| 1188 | } |
| 1189 | mHandler.removeMessages(ADVANCE_MSG); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1190 | mHandler.removeMessages(0); // Remove messages sent using postDelayed() |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | private final Handler mHandler = new Handler() { |
| 1196 | @Override |
| 1197 | public void handleMessage(Message msg) { |
| 1198 | if (msg.what == ADVANCE_MSG) { |
| 1199 | int i = 0; |
| 1200 | for (View key: mWidgetsToAdvance.keySet()) { |
| 1201 | final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId); |
| 1202 | final int delay = mAdvanceStagger * i; |
| 1203 | if (v instanceof Advanceable) { |
| 1204 | postDelayed(new Runnable() { |
| 1205 | public void run() { |
| 1206 | ((Advanceable) v).advance(); |
| 1207 | } |
| 1208 | }, delay); |
| 1209 | } |
| 1210 | i++; |
| 1211 | } |
| 1212 | sendAdvanceMessage(mAdvanceInterval); |
| 1213 | } |
| 1214 | } |
| 1215 | }; |
| 1216 | |
| 1217 | void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) { |
Adam Cohen | 292c025 | 2011-07-18 13:55:17 -0700 | [diff] [blame] | 1218 | if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1219 | View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId); |
| 1220 | if (v instanceof Advanceable) { |
| 1221 | mWidgetsToAdvance.put(hostView, appWidgetInfo); |
Adam Cohen | 2ddf13e | 2011-01-19 21:26:33 -0800 | [diff] [blame] | 1222 | ((Advanceable) v).fyiWillBeAdvancedByHostKThx(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1223 | updateRunning(); |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | void removeWidgetToAutoAdvance(View hostView) { |
| 1228 | if (mWidgetsToAdvance.containsKey(hostView)) { |
| 1229 | mWidgetsToAdvance.remove(hostView); |
| 1230 | updateRunning(); |
| 1231 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1234 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1235 | removeWidgetToAutoAdvance(launcherInfo.hostView); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1236 | launcherInfo.hostView = null; |
| 1237 | } |
| 1238 | |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1239 | void showOutOfSpaceMessage(boolean isHotseatLayout) { |
| 1240 | int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space); |
| 1241 | Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1244 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1245 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1246 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1247 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1248 | public LauncherModel getModel() { |
| 1249 | return mModel; |
| 1250 | } |
| 1251 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1252 | void closeSystemDialogs() { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1253 | getWindow().closeAllPanels(); |
| 1254 | |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1255 | // Whatever we were doing is hereby canceled. |
| 1256 | mWaitingForResult = false; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1257 | } |
| 1258 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1259 | @Override |
| 1260 | protected void onNewIntent(Intent intent) { |
| 1261 | super.onNewIntent(intent); |
| 1262 | |
| 1263 | // Close the menu |
| 1264 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1265 | // also will cancel mWaitingForResult. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1266 | closeSystemDialogs(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1267 | |
Joe Onorato | 14f122b | 2009-11-19 14:06:36 -0800 | [diff] [blame] | 1268 | boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1269 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1270 | |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 1271 | Folder openFolder = mWorkspace.getOpenFolder(); |
Patrick Dubroy | 6ec2e18 | 2011-02-23 13:31:16 -0800 | [diff] [blame] | 1272 | // In all these cases, only animate if we're already on home |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 1273 | mWorkspace.exitWidgetResizeMode(); |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 1274 | if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && |
| 1275 | openFolder == null) { |
Patrick Dubroy | 6ec2e18 | 2011-02-23 13:31:16 -0800 | [diff] [blame] | 1276 | mWorkspace.moveToDefaultScreen(true); |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1277 | } |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 1278 | |
| 1279 | closeFolder(); |
Winson Chung | de1af76 | 2011-07-21 16:44:07 -0700 | [diff] [blame] | 1280 | exitSpringLoadedDragMode(); |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1281 | showWorkspace(alreadyOnHome); |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 1282 | |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1283 | final View v = getWindow().peekDecorView(); |
| 1284 | if (v != null && v.getWindowToken() != null) { |
| 1285 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 1286 | INPUT_METHOD_SERVICE); |
| 1287 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1288 | } |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 1289 | |
Michael Jurka | 35aa14d | 2011-07-07 17:01:08 -0700 | [diff] [blame] | 1290 | // Reset AllApps to its initial state |
Adam Cohen | b64d36e | 2011-10-17 21:48:02 -0700 | [diff] [blame] | 1291 | if (!alreadyOnHome && mAppsCustomizeTabHost != null) { |
Winson Chung | c100e8e | 2011-08-09 16:02:43 -0700 | [diff] [blame] | 1292 | mAppsCustomizeTabHost.reset(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1293 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | @Override |
| 1298 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 1299 | // Do not call super here |
| 1300 | mSavedInstanceState = savedInstanceState; |
| 1301 | } |
| 1302 | |
| 1303 | @Override |
| 1304 | protected void onSaveInstanceState(Bundle outState) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1305 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage()); |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 1306 | super.onSaveInstanceState(outState); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1307 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1308 | outState.putInt(RUNTIME_STATE, mState.ordinal()); |
Adam Cohen | 51e9503 | 2011-07-11 14:44:19 -0700 | [diff] [blame] | 1309 | // We close any open folder since it will not be re-opened, and we need to make sure |
| 1310 | // this state is reflected. |
| 1311 | closeFolder(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1312 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1313 | if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 && |
| 1314 | mWaitingForResult) { |
| 1315 | outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container); |
| 1316 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen); |
| 1317 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX); |
| 1318 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | if (mFolderInfo != null && mWaitingForResult) { |
| 1322 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 1323 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 1324 | } |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1325 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1326 | // Save the current AppsCustomize tab |
| 1327 | if (mAppsCustomizeTabHost != null) { |
| 1328 | String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag(); |
| 1329 | if (currentTabTag != null) { |
| 1330 | outState.putString("apps_customize_currentTab", currentTabTag); |
| 1331 | } |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 1332 | int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex(); |
| 1333 | outState.putInt("apps_customize_currentIndex", currentIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1334 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | @Override |
| 1338 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1339 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1340 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 1341 | // Remove all pending runnables |
| 1342 | mHandler.removeMessages(ADVANCE_MSG); |
| 1343 | mHandler.removeMessages(0); |
Michael Jurka | 9d906c7 | 2011-10-14 06:25:36 -0700 | [diff] [blame] | 1344 | mWorkspace.removeCallbacks(mBuildLayersRunnable); |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 1345 | |
Winson Chung | cd2b014 | 2011-06-08 16:02:26 -0700 | [diff] [blame] | 1346 | // Stop callbacks from LauncherModel |
| 1347 | LauncherApplication app = ((LauncherApplication) getApplication()); |
| 1348 | mModel.stopLoader(); |
| 1349 | app.setLauncher(null); |
| 1350 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1351 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1352 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1353 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1354 | Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1355 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1356 | mAppWidgetHost = null; |
| 1357 | |
| 1358 | mWidgetsToAdvance.clear(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1359 | |
| 1360 | TextKeyListener.getInstance().release(); |
| 1361 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1362 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1363 | unbindWorkspaceAndHotseatItems(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1364 | |
| 1365 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 1366 | unregisterReceiver(mCloseSystemDialogsReceiver); |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 1367 | |
| 1368 | ((ViewGroup) mWorkspace.getParent()).removeAllViews(); |
| 1369 | mWorkspace.removeAllViews(); |
| 1370 | mWorkspace = null; |
| 1371 | mDragController = null; |
Patrick Dubroy | 60b7c53 | 2011-01-16 17:19:32 -0800 | [diff] [blame] | 1372 | |
| 1373 | ValueAnimator.clearAllAnimations(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1374 | } |
| 1375 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1376 | public DragController getDragController() { |
| 1377 | return mDragController; |
| 1378 | } |
| 1379 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1380 | @Override |
| 1381 | public void startActivityForResult(Intent intent, int requestCode) { |
Romain Guy | 08f9749 | 2009-06-29 14:41:20 -0700 | [diff] [blame] | 1382 | if (requestCode >= 0) mWaitingForResult = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1383 | super.startActivityForResult(intent, requestCode); |
| 1384 | } |
| 1385 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 1386 | /** |
| 1387 | * Indicates that we want global search for this activity by setting the globalSearch |
| 1388 | * argument for {@link #startSearch} to true. |
| 1389 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1390 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1391 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1392 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1393 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1394 | showWorkspace(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1395 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1396 | if (initialQuery == null) { |
| 1397 | // Use any text typed in the launcher as the initial query |
| 1398 | initialQuery = getTypedText(); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1399 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1400 | if (appSearchData == null) { |
| 1401 | appSearchData = new Bundle(); |
Bjorn Bringert | 3e244cf | 2010-02-10 14:17:35 +0000 | [diff] [blame] | 1402 | appSearchData.putString(Search.SOURCE, "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1403 | } |
Mathew Inwood | cf7f63b | 2011-10-13 11:31:38 +0100 | [diff] [blame] | 1404 | Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1405 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1406 | final SearchManager searchManager = |
| 1407 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1408 | searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), |
Mathew Inwood | cf7f63b | 2011-10-13 11:31:38 +0100 | [diff] [blame] | 1409 | appSearchData, globalSearch, sourceBounds); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1410 | } |
| 1411 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 1412 | @Override |
| 1413 | public boolean onCreateOptionsMenu(Menu menu) { |
| 1414 | if (isWorkspaceLocked()) { |
| 1415 | return false; |
| 1416 | } |
| 1417 | |
| 1418 | super.onCreateOptionsMenu(menu); |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 1419 | |
| 1420 | Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS); |
| 1421 | manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1422 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Winson Chung | 236d431 | 2011-08-22 15:12:27 -0700 | [diff] [blame] | 1423 | Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS); |
| 1424 | settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1425 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Michael Jurka | b964f9c | 2011-09-27 22:10:05 -0700 | [diff] [blame] | 1426 | String helpUrl = getString(R.string.help_url); |
| 1427 | Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl)); |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 1428 | help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1429 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 1430 | |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 1431 | menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper) |
| 1432 | .setIcon(android.R.drawable.ic_menu_gallery) |
| 1433 | .setAlphabeticShortcut('W'); |
| 1434 | menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps) |
| 1435 | .setIcon(android.R.drawable.ic_menu_manage) |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 1436 | .setIntent(manageApps) |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 1437 | .setAlphabeticShortcut('M'); |
Winson Chung | 236d431 | 2011-08-22 15:12:27 -0700 | [diff] [blame] | 1438 | menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings) |
| 1439 | .setIcon(android.R.drawable.ic_menu_preferences) |
| 1440 | .setIntent(settings) |
| 1441 | .setAlphabeticShortcut('P'); |
Michael Jurka | b964f9c | 2011-09-27 22:10:05 -0700 | [diff] [blame] | 1442 | if (!helpUrl.isEmpty()) { |
| 1443 | menu.add(0, MENU_HELP, 0, R.string.menu_help) |
| 1444 | .setIcon(android.R.drawable.ic_menu_help) |
| 1445 | .setIntent(help) |
| 1446 | .setAlphabeticShortcut('H'); |
| 1447 | } |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 1448 | return true; |
| 1449 | } |
| 1450 | |
| 1451 | @Override |
| 1452 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 1453 | super.onPrepareOptionsMenu(menu); |
| 1454 | |
| 1455 | if (mAppsCustomizeTabHost.isTransitioning()) { |
| 1456 | return false; |
| 1457 | } |
| 1458 | boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE); |
| 1459 | menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible); |
| 1460 | |
| 1461 | return true; |
| 1462 | } |
| 1463 | |
| 1464 | @Override |
| 1465 | public boolean onOptionsItemSelected(MenuItem item) { |
| 1466 | switch (item.getItemId()) { |
| 1467 | case MENU_WALLPAPER_SETTINGS: |
| 1468 | startWallpaper(); |
| 1469 | return true; |
Winson Chung | 70d7210 | 2011-08-12 11:24:35 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | return super.onOptionsItemSelected(item); |
| 1473 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1474 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1475 | @Override |
| 1476 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1477 | startSearch(null, false, null, true); |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 1478 | // Use a custom animation for launching search |
| 1479 | overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1480 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1481 | } |
| 1482 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1483 | public boolean isWorkspaceLocked() { |
| 1484 | return mWorkspaceLoading || mWaitingForResult; |
| 1485 | } |
| 1486 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1487 | private void resetAddInfo() { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1488 | mPendingAddInfo.container = ItemInfo.NO_ID; |
| 1489 | mPendingAddInfo.screen = -1; |
| 1490 | mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1; |
| 1491 | mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1492 | mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1493 | mPendingAddInfo.dropPos = null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1494 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1495 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1496 | void addAppWidgetFromPick(Intent data) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1497 | // TODO: catch bad widget exception when sent |
| 1498 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1499 | // TODO: Is this log message meaningful? |
| 1500 | if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras()); |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1501 | addAppWidgetImpl(appWidgetId, null); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1504 | void addAppWidgetImpl(final int appWidgetId, final PendingAddWidgetInfo info) { |
| 1505 | final AppWidgetProviderInfo appWidget = info.info; |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1506 | if (appWidget.configure != null) { |
| 1507 | // Launch over to configure widget, if needed |
| 1508 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); |
| 1509 | intent.setComponent(appWidget.configure); |
| 1510 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1511 | if (info != null) { |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 1512 | if (info.mimeType != null && !info.mimeType.isEmpty()) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1513 | intent.putExtra(InstallWidgetReceiver. |
| 1514 | EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE, info.mimeType); |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 1515 | |
| 1516 | final String mimeType = info.mimeType; |
| 1517 | final ClipData clipData = (ClipData) info.configurationData; |
| 1518 | final ClipDescription clipDesc = clipData.getDescription(); |
| 1519 | for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) { |
| 1520 | if (clipDesc.getMimeType(i).equals(mimeType)) { |
Dianne Hackborn | 0d5aad7 | 2011-01-17 15:28:58 -0800 | [diff] [blame] | 1521 | final ClipData.Item item = clipData.getItemAt(i); |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 1522 | final CharSequence stringData = item.getText(); |
| 1523 | final Uri uriData = item.getUri(); |
| 1524 | final Intent intentData = item.getIntent(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1525 | final String key = InstallWidgetReceiver. |
| 1526 | EXTRA_APPWIDGET_CONFIGURATION_DATA; |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 1527 | if (uriData != null) { |
| 1528 | intent.putExtra(key, uriData); |
| 1529 | } else if (intentData != null) { |
| 1530 | intent.putExtra(key, intentData); |
| 1531 | } else if (stringData != null) { |
| 1532 | intent.putExtra(key, stringData); |
| 1533 | } |
| 1534 | break; |
| 1535 | } |
| 1536 | } |
| 1537 | } |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1538 | } |
Romain Guy | 8e633c5 | 2010-03-04 12:51:36 -0800 | [diff] [blame] | 1539 | startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1540 | mWidgetBeingConfigured = info; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1541 | } else { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1542 | // Otherwise just add it |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1543 | completeAddAppWidget(appWidgetId, info.container, info.screen, info.boundWidget, appWidget); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 1544 | // Exit spring loaded mode if necessary after adding the widget |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1545 | exitSpringLoadedDragModeDelayed(true, false, null); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1546 | } |
| 1547 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1548 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1549 | /** |
| 1550 | * Process a shortcut drop. |
| 1551 | * |
| 1552 | * @param componentName The name of the component |
| 1553 | * @param screen The screen where it should be added |
| 1554 | * @param cell The cell it should be added to, optional |
| 1555 | * @param position The location on the screen where it was dropped, optional |
| 1556 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1557 | void processShortcutFromDrop(ComponentName componentName, long container, int screen, |
| 1558 | int[] cell, int[] loc) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1559 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1560 | mPendingAddInfo.container = container; |
| 1561 | mPendingAddInfo.screen = screen; |
| 1562 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1563 | |
| 1564 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1565 | mPendingAddInfo.cellX = cell[0]; |
| 1566 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1567 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1568 | |
| 1569 | Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 1570 | createShortcutIntent.setComponent(componentName); |
| 1571 | processShortcut(createShortcutIntent); |
| 1572 | } |
| 1573 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1574 | /** |
| 1575 | * Process a widget drop. |
| 1576 | * |
| 1577 | * @param info The PendingAppWidgetInfo of the widget being added. |
| 1578 | * @param screen The screen where it should be added |
| 1579 | * @param cell The cell it should be added to, optional |
| 1580 | * @param position The location on the screen where it was dropped, optional |
| 1581 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1582 | void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen, |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1583 | int[] cell, int[] span, int[] loc) { |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1584 | resetAddInfo(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1585 | mPendingAddInfo.container = info.container = container; |
| 1586 | mPendingAddInfo.screen = info.screen = screen; |
| 1587 | mPendingAddInfo.dropPos = loc; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1588 | mPendingAddInfo.minSpanX = info.minSpanX; |
| 1589 | mPendingAddInfo.minSpanY = info.minSpanY; |
| 1590 | |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1591 | if (cell != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1592 | mPendingAddInfo.cellX = cell[0]; |
| 1593 | mPendingAddInfo.cellY = cell[1]; |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1594 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1595 | if (span != null) { |
| 1596 | mPendingAddInfo.spanX = span[0]; |
| 1597 | mPendingAddInfo.spanY = span[1]; |
| 1598 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1599 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1600 | AppWidgetHostView hostView = info.boundWidget; |
| 1601 | int appWidgetId; |
| 1602 | if (hostView != null) { |
| 1603 | appWidgetId = hostView.getAppWidgetId(); |
| 1604 | } else { |
| 1605 | appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
| 1606 | AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName); |
| 1607 | } |
Adam Cohen | fbba09b | 2011-07-18 21:43:05 -0700 | [diff] [blame] | 1608 | addAppWidgetImpl(appWidgetId, info); |
| 1609 | } |
| 1610 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 1611 | void processShortcut(Intent intent) { |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1612 | // Handle case where user selected "Applications" |
| 1613 | String applicationName = getResources().getString(R.string.group_applications); |
| 1614 | String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1615 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1616 | if (applicationName != null && applicationName.equals(shortcutName)) { |
| 1617 | Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1618 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1619 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1620 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 1621 | pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent); |
Winson Chung | 58f2088 | 2010-10-01 13:44:56 -0700 | [diff] [blame] | 1622 | pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application)); |
Joe Onorato | 4a79a04 | 2010-09-24 16:17:21 -0700 | [diff] [blame] | 1623 | startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1624 | } else { |
Joe Onorato | 4a79a04 | 2010-09-24 16:17:21 -0700 | [diff] [blame] | 1625 | startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1626 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1627 | } |
| 1628 | |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 1629 | void processWallpaper(Intent intent) { |
| 1630 | startActivityForResult(intent, REQUEST_PICK_WALLPAPER); |
| 1631 | } |
| 1632 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1633 | FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX, |
| 1634 | int cellY) { |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 1635 | final FolderInfo folderInfo = new FolderInfo(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1636 | folderInfo.title = getText(R.string.folder_name); |
| 1637 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1638 | // Update the model |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1639 | LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY, |
| 1640 | false); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1641 | sFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1642 | |
| 1643 | // Create the view |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1644 | FolderIcon newFolder = |
| 1645 | FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache); |
| 1646 | mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1, |
| 1647 | isWorkspaceLocked()); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 1648 | return newFolder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1649 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1650 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1651 | void removeFolder(FolderInfo folder) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1652 | sFolders.remove(folder.id); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1653 | } |
| 1654 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1655 | private void startWallpaper() { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1656 | showWorkspace(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1657 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
Dianne Hackborn | 8355ae3 | 2009-09-07 21:47:51 -0700 | [diff] [blame] | 1658 | Intent chooser = Intent.createChooser(pickWallpaper, |
| 1659 | getText(R.string.chooser_wallpaper)); |
Romain Guy | f2826c7 | 2009-11-12 17:39:34 -0800 | [diff] [blame] | 1660 | // NOTE: Adds a configure option to the chooser if the wallpaper supports it |
| 1661 | // Removed in Eclair MR1 |
| 1662 | // WallpaperManager wm = (WallpaperManager) |
| 1663 | // getSystemService(Context.WALLPAPER_SERVICE); |
| 1664 | // WallpaperInfo wi = wm.getWallpaperInfo(); |
| 1665 | // if (wi != null && wi.getSettingsActivity() != null) { |
| 1666 | // LabeledIntent li = new LabeledIntent(getPackageName(), |
| 1667 | // R.string.configure_wallpaper, 0); |
| 1668 | // li.setClassName(wi.getPackageName(), wi.getSettingsActivity()); |
| 1669 | // chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li }); |
| 1670 | // } |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 1671 | startActivityForResult(chooser, REQUEST_PICK_WALLPAPER); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1672 | } |
| 1673 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1674 | /** |
| 1675 | * Registers various content observers. The current implementation registers |
| 1676 | * only a favorites observer to keep track of the favorites applications. |
| 1677 | */ |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1678 | private void registerContentObservers() { |
| 1679 | ContentResolver resolver = getContentResolver(); |
| 1680 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 1681 | true, mWidgetObserver); |
| 1682 | } |
| 1683 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1684 | @Override |
| 1685 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 1686 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 1687 | switch (event.getKeyCode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1688 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1689 | return true; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1690 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jason Sams | eb5615d | 2009-11-30 11:50:10 -0800 | [diff] [blame] | 1691 | if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1692 | dumpState(); |
| 1693 | return true; |
| 1694 | } |
| 1695 | break; |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1696 | } |
| 1697 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 1698 | switch (event.getKeyCode()) { |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1699 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1700 | return true; |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | return super.dispatchKeyEvent(event); |
| 1705 | } |
| 1706 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1707 | @Override |
| 1708 | public void onBackPressed() { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1709 | if (mState == State.APPS_CUSTOMIZE) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1710 | showWorkspace(true); |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1711 | } else if (mWorkspace.getOpenFolder() != null) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 1712 | Folder openFolder = mWorkspace.getOpenFolder(); |
| 1713 | if (openFolder.isEditingName()) { |
| 1714 | openFolder.dismissEditingName(); |
| 1715 | } else { |
| 1716 | closeFolder(); |
| 1717 | } |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1718 | } else { |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 1719 | mWorkspace.exitWidgetResizeMode(); |
| 1720 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1721 | // Back button is a no-op here, but give at least some feedback for the button press |
| 1722 | mWorkspace.showOutlinesTemporarily(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1723 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1724 | } |
| 1725 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1726 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1727 | * Re-listen when widgets are reset. |
| 1728 | */ |
| 1729 | private void onAppWidgetReset() { |
Michael Jurka | bbbad6b | 2011-02-07 13:04:09 -0800 | [diff] [blame] | 1730 | if (mAppWidgetHost != null) { |
| 1731 | mAppWidgetHost.startListening(); |
| 1732 | } |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1736 | * Go through the and disconnect any of the callbacks in the drawables and the views or we |
| 1737 | * leak the previous Home screen on orientation change. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1738 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1739 | private void unbindWorkspaceAndHotseatItems() { |
Winson Chung | 603bcb9 | 2011-09-02 11:45:39 -0700 | [diff] [blame] | 1740 | if (mModel != null) { |
| 1741 | mModel.unbindWorkspaceItems(); |
| 1742 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1743 | } |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1744 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1745 | /** |
| 1746 | * Launches the intent referred by the clicked shortcut. |
| 1747 | * |
| 1748 | * @param v The view representing the clicked shortcut. |
| 1749 | */ |
| 1750 | public void onClick(View v) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 1751 | // Make sure that rogue clicks don't get through while allapps is launching, or after the |
| 1752 | // view has detached (it's possible for this to happen if the view is removed mid touch). |
| 1753 | if (v.getWindowToken() == null) { |
| 1754 | return; |
| 1755 | } |
| 1756 | |
Winson Chung | 9b0b2fe | 2012-02-24 13:03:34 -0800 | [diff] [blame] | 1757 | if (!mWorkspace.isFinishedSwitchingState()) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 1758 | return; |
| 1759 | } |
Adam Cohen | 2f84ef2 | 2011-07-26 17:16:44 -0700 | [diff] [blame] | 1760 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1761 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1762 | if (tag instanceof ShortcutInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1763 | // Open shortcut |
Romain Guy | fb5411e | 2010-02-24 10:04:17 -0800 | [diff] [blame] | 1764 | final Intent intent = ((ShortcutInfo) tag).intent; |
Joe Onorato | 13724ea | 2009-12-02 21:16:35 -0800 | [diff] [blame] | 1765 | int[] pos = new int[2]; |
| 1766 | v.getLocationOnScreen(pos); |
Romain Guy | fb5411e | 2010-02-24 10:04:17 -0800 | [diff] [blame] | 1767 | intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 1768 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1769 | boolean success = startActivitySafely(intent, tag); |
| 1770 | |
| 1771 | if (success && v instanceof BubbleTextView) { |
| 1772 | mWaitingForResume = (BubbleTextView) v; |
| 1773 | mWaitingForResume.setStayPressed(true); |
| 1774 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1775 | } else if (tag instanceof FolderInfo) { |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1776 | if (v instanceof FolderIcon) { |
| 1777 | FolderIcon fi = (FolderIcon) v; |
| 1778 | handleFolderClick(fi); |
| 1779 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1780 | } else if (v == mAllAppsButton) { |
| 1781 | if (mState == State.APPS_CUSTOMIZE) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1782 | showWorkspace(true); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1783 | } else { |
Michael Jurka | 2a55232 | 2011-10-11 15:22:05 -0700 | [diff] [blame] | 1784 | onClickAllAppsButton(v); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1785 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1786 | } |
| 1787 | } |
| 1788 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 1789 | public boolean onTouch(View v, MotionEvent event) { |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1790 | // this is an intercepted event being forwarded from mWorkspace; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1791 | // clicking anywhere on the workspace causes the customization drawer to slide down |
| 1792 | showWorkspace(true); |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 1793 | return false; |
| 1794 | } |
| 1795 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1796 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 1797 | * Event handler for the search button |
| 1798 | * |
| 1799 | * @param v The view that was clicked. |
| 1800 | */ |
| 1801 | public void onClickSearchButton(View v) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 1802 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
| 1803 | |
Amith Yamasani | a135ba8 | 2011-08-09 17:42:01 -0700 | [diff] [blame] | 1804 | onSearchRequested(); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | /** |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 1808 | * Event handler for the voice button |
| 1809 | * |
| 1810 | * @param v The view that was clicked. |
| 1811 | */ |
| 1812 | public void onClickVoiceButton(View v) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 1813 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 1814 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 1815 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 1816 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Winson Chung | e3fbfa9 | 2012-04-24 14:34:28 -0700 | [diff] [blame^] | 1817 | startActivitySafely(intent, "onClickVoiceButton"); |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 1821 | * Event handler for the "grid" button that appears on the home screen, which |
| 1822 | * enters all apps mode. |
| 1823 | * |
| 1824 | * @param v The view that was clicked. |
| 1825 | */ |
| 1826 | public void onClickAllAppsButton(View v) { |
Michael Jurka | 5130e40 | 2011-10-13 04:55:35 -0700 | [diff] [blame] | 1827 | showAllApps(true); |
| 1828 | } |
| 1829 | |
| 1830 | public void onTouchDownAllAppsButton(View v) { |
Michael Jurka | 2a55232 | 2011-10-11 15:22:05 -0700 | [diff] [blame] | 1831 | // Provide the same haptic feedback that the system offers for virtual keys. |
| 1832 | v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 1835 | public void onClickAppMarketButton(View v) { |
| 1836 | if (mAppMarketIntent != null) { |
| 1837 | startActivitySafely(mAppMarketIntent, "app market"); |
Winson Chung | 4f916f4 | 2012-03-26 15:30:59 -0700 | [diff] [blame] | 1838 | } else { |
| 1839 | Log.e(TAG, "Invalid app market intent."); |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 1840 | } |
| 1841 | } |
| 1842 | |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 1843 | void startApplicationDetailsActivity(ComponentName componentName) { |
| 1844 | String packageName = componentName.getPackageName(); |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 1845 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
| 1846 | Uri.fromParts("package", packageName, null)); |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 1847 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Winson Chung | e3fbfa9 | 2012-04-24 14:34:28 -0700 | [diff] [blame^] | 1848 | startActivitySafely(intent, "startApplicationDetailsActivity"); |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 1851 | void startApplicationUninstallActivity(ApplicationInfo appInfo) { |
| 1852 | if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) { |
| 1853 | // System applications cannot be installed. For now, show a toast explaining that. |
| 1854 | // We may give them the option of disabling apps this way. |
| 1855 | int messageId = R.string.uninstall_system_app_text; |
| 1856 | Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); |
| 1857 | } else { |
| 1858 | String packageName = appInfo.componentName.getPackageName(); |
| 1859 | String className = appInfo.componentName.getClassName(); |
| 1860 | Intent intent = new Intent( |
| 1861 | Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 1862 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 1863 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 1864 | startActivity(intent); |
| 1865 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1868 | boolean startActivitySafely(Intent intent, Object tag) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1869 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1870 | try { |
| 1871 | startActivity(intent); |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1872 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1873 | } catch (ActivityNotFoundException e) { |
| 1874 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 1875 | Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1876 | } catch (SecurityException e) { |
| 1877 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1878 | Log.e(TAG, "Launcher does not have the permission to launch " + intent + |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1879 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 1880 | "or use the exported attribute for this activity. " |
| 1881 | + "tag="+ tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1882 | } |
Michael Jurka | ddd62e9 | 2011-02-16 17:49:14 -0800 | [diff] [blame] | 1883 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1884 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1885 | |
Romain Guy | 8e633c5 | 2010-03-04 12:51:36 -0800 | [diff] [blame] | 1886 | void startActivityForResultSafely(Intent intent, int requestCode) { |
| 1887 | try { |
| 1888 | startActivityForResult(intent, requestCode); |
| 1889 | } catch (ActivityNotFoundException e) { |
| 1890 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 1891 | } catch (SecurityException e) { |
| 1892 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 1893 | Log.e(TAG, "Launcher does not have the permission to launch " + intent + |
| 1894 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
| 1895 | "or use the exported attribute for this activity.", e); |
| 1896 | } |
| 1897 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1898 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1899 | private void handleFolderClick(FolderIcon folderIcon) { |
| 1900 | final FolderInfo info = folderIcon.mInfo; |
Adam Cohen | 3c81a38 | 2011-08-31 22:25:51 -0700 | [diff] [blame] | 1901 | Folder openFolder = mWorkspace.getFolderForTag(info); |
| 1902 | |
| 1903 | // If the folder info reports that the associated folder is open, then verify that |
| 1904 | // it is actually opened. There have been a few instances where this gets out of sync. |
| 1905 | if (info.opened && openFolder == null) { |
| 1906 | Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: " |
| 1907 | + info.screen + " (" + info.cellX + ", " + info.cellY + ")"); |
| 1908 | info.opened = false; |
| 1909 | } |
| 1910 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1911 | if (!info.opened) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1912 | // Close any open folder |
| 1913 | closeFolder(); |
| 1914 | // Open the requested folder |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1915 | openFolder(folderIcon); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1916 | } else { |
| 1917 | // Find the open folder... |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1918 | int folderScreen; |
| 1919 | if (openFolder != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1920 | folderScreen = mWorkspace.getPageForView(openFolder); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1921 | // .. and close it |
| 1922 | closeFolder(openFolder); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1923 | if (folderScreen != mWorkspace.getCurrentPage()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1924 | // Close any folder open on the current screen |
| 1925 | closeFolder(); |
| 1926 | // Pull the folder onto this screen |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1927 | openFolder(folderIcon); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1928 | } |
| 1929 | } |
| 1930 | } |
| 1931 | } |
| 1932 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1933 | private void growAndFadeOutFolderIcon(FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 1934 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1935 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); |
| 1936 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f); |
| 1937 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f); |
| 1938 | |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 1939 | FolderInfo info = (FolderInfo) fi.getTag(); |
| 1940 | if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 1941 | CellLayout cl = (CellLayout) fi.getParent().getParent(); |
Winson Chung | e50adee | 2011-08-11 16:12:00 -0700 | [diff] [blame] | 1942 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams(); |
| 1943 | cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1946 | ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY); |
| 1947 | oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration)); |
| 1948 | oa.start(); |
| 1949 | } |
| 1950 | |
| 1951 | private void shrinkAndFadeInFolderIcon(FolderIcon fi) { |
Adam Cohen | 9932a9b | 2011-08-02 22:14:07 -0700 | [diff] [blame] | 1952 | if (fi == null) return; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1953 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f); |
| 1954 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); |
| 1955 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); |
| 1956 | |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 1957 | FolderInfo info = (FolderInfo) fi.getTag(); |
| 1958 | CellLayout cl = null; |
| 1959 | if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 1960 | cl = (CellLayout) fi.getParent().getParent(); |
| 1961 | } |
| 1962 | |
| 1963 | final CellLayout layout = cl; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1964 | ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY); |
| 1965 | oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration)); |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 1966 | oa.addListener(new AnimatorListenerAdapter() { |
| 1967 | @Override |
| 1968 | public void onAnimationEnd(Animator animation) { |
| 1969 | if (layout != null) { |
| 1970 | layout.clearFolderLeaveBehind(); |
| 1971 | } |
| 1972 | } |
| 1973 | }); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1974 | oa.start(); |
| 1975 | } |
| 1976 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1977 | /** |
Michael Jurka | 774bd37 | 2010-10-22 13:40:50 -0700 | [diff] [blame] | 1978 | * Opens the user folder described by the specified tag. The opening of the folder |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1979 | * is animated relative to the specified View. If the View is null, no animation |
| 1980 | * is played. |
| 1981 | * |
| 1982 | * @param folderInfo The FolderInfo describing the folder to open. |
| 1983 | */ |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1984 | public void openFolder(FolderIcon folderIcon) { |
| 1985 | Folder folder = folderIcon.mFolder; |
| 1986 | FolderInfo info = folder.mInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1987 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1988 | growAndFadeOutFolderIcon(folderIcon); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1989 | info.opened = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1990 | |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 1991 | // Just verify that the folder hasn't already been added to the DragLayer. |
| 1992 | // There was a one-off crash where the folder had a parent already. |
| 1993 | if (folder.getParent() == null) { |
| 1994 | mDragLayer.addView(folder); |
| 1995 | mDragController.addDropTarget((DropTarget) folder); |
| 1996 | } else { |
| 1997 | Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" + |
| 1998 | folder.getParent() + ")."); |
| 1999 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2000 | folder.animateOpen(); |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | public void closeFolder() { |
| 2004 | Folder folder = mWorkspace.getOpenFolder(); |
| 2005 | if (folder != null) { |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 2006 | if (folder.isEditingName()) { |
| 2007 | folder.dismissEditingName(); |
| 2008 | } |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2009 | closeFolder(folder); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 2010 | |
| 2011 | // Dismiss the folder cling |
| 2012 | dismissFolderCling(null); |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | void closeFolder(Folder folder) { |
| 2017 | folder.getInfo().opened = false; |
| 2018 | |
| 2019 | ViewGroup parent = (ViewGroup) folder.getParent().getParent(); |
| 2020 | if (parent != null) { |
| 2021 | FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo); |
| 2022 | shrinkAndFadeInFolderIcon(fi); |
| 2023 | } |
| 2024 | folder.animateClosed(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2025 | } |
| 2026 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2027 | public boolean onLongClick(View v) { |
Winson Chung | eecf02d | 2012-03-02 17:14:58 -0800 | [diff] [blame] | 2028 | |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 2029 | if (mState != State.WORKSPACE) { |
| 2030 | return false; |
| 2031 | } |
| 2032 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2033 | if (isWorkspaceLocked()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2034 | return false; |
| 2035 | } |
| 2036 | |
| 2037 | if (!(v instanceof CellLayout)) { |
Michael Jurka | 8c920dd | 2011-01-20 14:16:56 -0800 | [diff] [blame] | 2038 | v = (View) v.getParent().getParent(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2039 | } |
| 2040 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2041 | resetAddInfo(); |
| 2042 | CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2043 | // This happens when long clicking an item with the dpad/trackball |
Adam Cohen | faea1f8 | 2011-07-21 16:23:57 -0700 | [diff] [blame] | 2044 | if (longClickCellInfo == null) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2045 | return true; |
| 2046 | } |
| 2047 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2048 | // The hotseat touch handling does not go through Workspace, and we always allow long press |
| 2049 | // on hotseat items. |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2050 | final View itemUnderLongClick = longClickCellInfo.cell; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2051 | boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress(); |
| 2052 | if (allowLongPress && !mDragController.isDragging()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2053 | if (itemUnderLongClick == null) { |
| 2054 | // User long pressed on empty space |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2055 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2056 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 2057 | startWallpaper(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2058 | } else { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2059 | if (!(itemUnderLongClick instanceof Folder)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2060 | // User long pressed on an item |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2061 | mWorkspace.startDrag(longClickCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2062 | } |
| 2063 | } |
| 2064 | } |
| 2065 | return true; |
| 2066 | } |
| 2067 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2068 | boolean isHotseatLayout(View layout) { |
| 2069 | return mHotseat != null && layout != null && |
| 2070 | (layout instanceof CellLayout) && (layout == mHotseat.getLayout()); |
| 2071 | } |
| 2072 | Hotseat getHotseat() { |
| 2073 | return mHotseat; |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2074 | } |
Adam Cohen | ebea84d | 2011-11-09 17:20:41 -0800 | [diff] [blame] | 2075 | SearchDropTargetBar getSearchBar() { |
| 2076 | return mSearchDropTargetBar; |
| 2077 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2078 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2079 | /** |
| 2080 | * Returns the CellLayout of the specified container at the specified screen. |
| 2081 | */ |
| 2082 | CellLayout getCellLayout(long container, int screen) { |
| 2083 | if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 2084 | if (mHotseat != null) { |
| 2085 | return mHotseat.getLayout(); |
| 2086 | } else { |
| 2087 | return null; |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2088 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2089 | } else { |
| 2090 | return (CellLayout) mWorkspace.getChildAt(screen); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2091 | } |
| 2092 | } |
| 2093 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2094 | Workspace getWorkspace() { |
| 2095 | return mWorkspace; |
| 2096 | } |
| 2097 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2098 | // Now a part of LauncherModel.Callbacks. Used to reorder loading steps. |
| 2099 | public boolean isAllAppsVisible() { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2100 | return (mState == State.APPS_CUSTOMIZE); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 2101 | } |
| 2102 | |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 2103 | public boolean isAllAppsButtonRank(int rank) { |
| 2104 | return mHotseat.isAllAppsButtonRank(rank); |
| 2105 | } |
| 2106 | |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2107 | // AllAppsView.Watcher |
| 2108 | public void zoomed(float zoom) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2109 | if (zoom == 1.0f) { |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2110 | mWorkspace.setVisibility(View.GONE); |
| 2111 | } |
| 2112 | } |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2113 | |
| 2114 | /** |
| 2115 | * Helper method for the cameraZoomIn/cameraZoomOut animations |
| 2116 | * @param view The view being animated |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2117 | * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE) |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2118 | * @param scaleFactor The scale factor used for the zoom |
| 2119 | */ |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2120 | private void setPivotsForZoom(View view, float scaleFactor) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2121 | view.setPivotX(view.getWidth() / 2.0f); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2122 | view.setPivotY(view.getHeight() / 2.0f); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2123 | } |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2124 | |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 2125 | void updateWallpaperVisibility(boolean visible) { |
| 2126 | int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; |
| 2127 | int curflags = getWindow().getAttributes().flags |
| 2128 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 2129 | if (wpflags != curflags) { |
| 2130 | getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); |
| 2131 | } |
| 2132 | } |
| 2133 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2134 | private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) { |
| 2135 | if (v instanceof LauncherTransitionable) { |
| 2136 | ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace); |
| 2137 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 2138 | |
| 2139 | // Update the workspace transition step as well |
| 2140 | dispatchOnLauncherTransitionStep(v, 0f); |
| 2141 | } |
| 2142 | |
| 2143 | private void dispatchOnLauncherTransitionStep(View v, float t) { |
| 2144 | if (v instanceof LauncherTransitionable) { |
| 2145 | ((LauncherTransitionable) v).onLauncherTransitionStep(this, t); |
| 2146 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) { |
| 2150 | if (v instanceof LauncherTransitionable) { |
| 2151 | ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace); |
| 2152 | } |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 2153 | |
| 2154 | // Update the workspace transition step as well |
| 2155 | dispatchOnLauncherTransitionStep(v, 1f); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2156 | } |
| 2157 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2158 | /** |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2159 | * Things to test when changing the following seven functions. |
| 2160 | * - Home from workspace |
| 2161 | * - from center screen |
| 2162 | * - from other screens |
| 2163 | * - Home from all apps |
| 2164 | * - from center screen |
| 2165 | * - from other screens |
| 2166 | * - Back from all apps |
| 2167 | * - from center screen |
| 2168 | * - from other screens |
| 2169 | * - Launch app from workspace and quit |
| 2170 | * - with back |
| 2171 | * - with home |
| 2172 | * - Launch app from all apps and quit |
| 2173 | * - with back |
| 2174 | * - with home |
| 2175 | * - Go to a screen that's not the default, then all |
| 2176 | * apps, and launch and app, and go back |
| 2177 | * - with back |
| 2178 | * -with home |
| 2179 | * - On workspace, long press power and go back |
| 2180 | * - with back |
| 2181 | * - with home |
| 2182 | * - On all apps, long press power and go back |
| 2183 | * - with back |
| 2184 | * - with home |
| 2185 | * - On workspace, power off |
| 2186 | * - On all apps, power off |
| 2187 | * - Launch an app and turn off the screen while in that app |
| 2188 | * - Go back with home key |
| 2189 | * - Go back with back key TODO: make this not go to workspace |
| 2190 | * - From all apps |
| 2191 | * - From workspace |
| 2192 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 2193 | * - From all apps |
| 2194 | * - From the center workspace |
| 2195 | * - From another workspace |
| 2196 | */ |
| 2197 | |
| 2198 | /** |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2199 | * Zoom the camera out from the workspace to reveal 'toView'. |
| 2200 | * Assumes that the view to show is anchored at either the very top or very bottom |
| 2201 | * of the screen. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2202 | */ |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2203 | private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2204 | if (mStateAnimation != null) { |
| 2205 | mStateAnimation.cancel(); |
| 2206 | mStateAnimation = null; |
| 2207 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2208 | final Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2209 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2210 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime); |
| 2211 | final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime); |
| 2212 | final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2213 | final View fromView = mWorkspace; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2214 | final View toView = mAppsCustomizeTabHost; |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 2215 | final int startDelay = |
| 2216 | res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2217 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2218 | setPivotsForZoom(toView, scale); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2219 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 2220 | // Shrink workspaces away if going to AppsCustomize from workspace |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2221 | Animator workspaceAnim = |
| 2222 | mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2223 | |
| 2224 | if (animated) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 2225 | toView.setScaleX(scale); |
| 2226 | toView.setScaleY(scale); |
| 2227 | final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView); |
| 2228 | scaleAnim. |
| 2229 | scaleX(1f).scaleY(1f). |
| 2230 | setDuration(duration). |
| 2231 | setInterpolator(new Workspace.ZoomOutInterpolator()); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2232 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2233 | toView.setVisibility(View.VISIBLE); |
Adam Cohen | c00f0b9 | 2011-12-06 19:45:06 -0800 | [diff] [blame] | 2234 | toView.setAlpha(0f); |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 2235 | final ObjectAnimator alphaAnim = ObjectAnimator |
| 2236 | .ofFloat(toView, "alpha", 0f, 1f) |
| 2237 | .setDuration(fadeDuration); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2238 | alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f)); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 2239 | alphaAnim.addUpdateListener(new AnimatorUpdateListener() { |
| 2240 | @Override |
| 2241 | public void onAnimationUpdate(ValueAnimator animation) { |
| 2242 | float t = (Float) animation.getAnimatedValue(); |
| 2243 | dispatchOnLauncherTransitionStep(fromView, t); |
| 2244 | dispatchOnLauncherTransitionStep(toView, t); |
| 2245 | } |
| 2246 | }); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2247 | |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2248 | // toView should appear right at the end of the workspace shrink |
| 2249 | // animation |
| 2250 | mStateAnimation = new AnimatorSet(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2251 | mStateAnimation.play(scaleAnim).after(startDelay); |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 2252 | mStateAnimation.play(alphaAnim).after(startDelay); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2253 | |
| 2254 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
Adam Cohen | f4ddea3 | 2011-09-12 13:46:42 -0700 | [diff] [blame] | 2255 | boolean animationCancelled = false; |
| 2256 | |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 2257 | @Override |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2258 | public void onAnimationStart(Animator animation) { |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 2259 | updateWallpaperVisibility(true); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2260 | // Prepare the position |
| 2261 | toView.setTranslationX(0.0f); |
| 2262 | toView.setTranslationY(0.0f); |
| 2263 | toView.setVisibility(View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2264 | toView.bringToFront(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2265 | } |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2266 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 2267 | public void onAnimationEnd(Animator animation) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2268 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
| 2269 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
Winson Chung | 32174c8 | 2011-07-19 15:47:55 -0700 | [diff] [blame] | 2270 | |
| 2271 | if (!springLoaded && !LauncherApplication.isScreenLarge()) { |
| 2272 | // Hide the workspace scrollbar |
| 2273 | mWorkspace.hideScrollingIndicator(true); |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 2274 | hideDockDivider(); |
Winson Chung | 32174c8 | 2011-07-19 15:47:55 -0700 | [diff] [blame] | 2275 | } |
Adam Cohen | f4ddea3 | 2011-09-12 13:46:42 -0700 | [diff] [blame] | 2276 | if (!animationCancelled) { |
| 2277 | updateWallpaperVisibility(false); |
| 2278 | } |
| 2279 | } |
| 2280 | |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 2281 | @Override |
Adam Cohen | f4ddea3 | 2011-09-12 13:46:42 -0700 | [diff] [blame] | 2282 | public void onAnimationCancel(Animator animation) { |
| 2283 | animationCancelled = true; |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2284 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2285 | }); |
| 2286 | |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2287 | if (workspaceAnim != null) { |
| 2288 | mStateAnimation.play(workspaceAnim); |
| 2289 | } |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 2290 | |
| 2291 | boolean delayAnim = false; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2292 | final ViewTreeObserver observer; |
| 2293 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2294 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 2295 | dispatchOnLauncherTransitionStart(toView, animated, false); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2296 | |
| 2297 | // If any of the objects being animated haven't been measured/laid out |
| 2298 | // yet, delay the animation until we get a layout pass |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2299 | if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) || |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2300 | (mWorkspace.getMeasuredWidth() == 0) || |
| 2301 | (toView.getMeasuredWidth() == 0)) { |
| 2302 | observer = mWorkspace.getViewTreeObserver(); |
| 2303 | delayAnim = true; |
| 2304 | } else { |
| 2305 | observer = null; |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 2306 | } |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2307 | |
| 2308 | if (delayAnim) { |
Michael Jurka | 49779a1 | 2012-01-16 04:10:08 -0800 | [diff] [blame] | 2309 | final AnimatorSet stateAnimation = mStateAnimation; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2310 | final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() { |
| 2311 | public void onGlobalLayout() { |
| 2312 | mWorkspace.post(new Runnable() { |
| 2313 | public void run() { |
Michael Jurka | 49779a1 | 2012-01-16 04:10:08 -0800 | [diff] [blame] | 2314 | // Check that mStateAnimation hasn't changed while |
| 2315 | // we waited for a layout pass |
| 2316 | if (mStateAnimation == stateAnimation) { |
| 2317 | // Need to update pivots for zoom if layout changed |
| 2318 | setPivotsForZoom(toView, scale); |
| 2319 | mStateAnimation.start(); |
| 2320 | } |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2321 | } |
| 2322 | }); |
Michael Jurka | 3a9fced | 2012-04-13 14:44:29 -0700 | [diff] [blame] | 2323 | observer.removeOnGlobalLayoutListener(this); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2324 | } |
| 2325 | }; |
| 2326 | observer.addOnGlobalLayoutListener(delayedStart); |
| 2327 | } else { |
| 2328 | setPivotsForZoom(toView, scale); |
Michael Jurka | 1899a36 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 2329 | mStateAnimation.start(); |
| 2330 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2331 | } else { |
| 2332 | toView.setTranslationX(0.0f); |
| 2333 | toView.setTranslationY(0.0f); |
| 2334 | toView.setScaleX(1.0f); |
| 2335 | toView.setScaleY(1.0f); |
| 2336 | toView.setVisibility(View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2337 | toView.bringToFront(); |
Winson Chung | 3ac74c5 | 2011-06-30 17:39:37 -0700 | [diff] [blame] | 2338 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2339 | if (!springLoaded && !LauncherApplication.isScreenLarge()) { |
| 2340 | // Hide the workspace scrollbar |
| 2341 | mWorkspace.hideScrollingIndicator(true); |
| 2342 | hideDockDivider(); |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 2343 | } |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2344 | dispatchOnLauncherTransitionStart(fromView, animated, false); |
| 2345 | dispatchOnLauncherTransitionEnd(fromView, animated, false); |
| 2346 | dispatchOnLauncherTransitionStart(toView, animated, false); |
| 2347 | dispatchOnLauncherTransitionEnd(toView, animated, false); |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 2348 | updateWallpaperVisibility(false); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2349 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | /** |
| 2353 | * Zoom the camera back into the workspace, hiding 'fromView'. |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2354 | * This is the opposite of showAppsCustomizeHelper. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2355 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2356 | */ |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2357 | private void hideAppsCustomizeHelper(State toState, final boolean animated, |
| 2358 | final boolean springLoaded, final Runnable onCompleteRunnable) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2359 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2360 | if (mStateAnimation != null) { |
| 2361 | mStateAnimation.cancel(); |
| 2362 | mStateAnimation = null; |
| 2363 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2364 | Resources res = getResources(); |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 2365 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2366 | final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime); |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 2367 | final int fadeOutDuration = |
| 2368 | res.getInteger(R.integer.config_appsCustomizeFadeOutTime); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2369 | final float scaleFactor = (float) |
| 2370 | res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); |
| 2371 | final View fromView = mAppsCustomizeTabHost; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2372 | final View toView = mWorkspace; |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2373 | Animator workspaceAnim = null; |
| 2374 | |
| 2375 | if (toState == State.WORKSPACE) { |
| 2376 | int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger); |
| 2377 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
| 2378 | Workspace.State.NORMAL, animated, stagger); |
| 2379 | } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) { |
| 2380 | workspaceAnim = mWorkspace.getChangeStateAnimation( |
| 2381 | Workspace.State.SPRING_LOADED, animated); |
| 2382 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2383 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2384 | setPivotsForZoom(fromView, scaleFactor); |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 2385 | updateWallpaperVisibility(true); |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 2386 | showHotseat(animated); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2387 | if (animated) { |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 2388 | final LauncherViewPropertyAnimator scaleAnim = |
| 2389 | new LauncherViewPropertyAnimator(fromView); |
| 2390 | scaleAnim. |
| 2391 | scaleX(scaleFactor).scaleY(scaleFactor). |
| 2392 | setDuration(duration). |
| 2393 | setInterpolator(new Workspace.ZoomInInterpolator()); |
| 2394 | |
| 2395 | final ObjectAnimator alphaAnim = ObjectAnimator |
| 2396 | .ofFloat(fromView, "alpha", 1f, 0f) |
| 2397 | .setDuration(fadeOutDuration); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 2398 | alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator()); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 2399 | alphaAnim.addUpdateListener(new AnimatorUpdateListener() { |
| 2400 | @Override |
| 2401 | public void onAnimationUpdate(ValueAnimator animation) { |
| 2402 | float t = 1f - (Float) animation.getAnimatedValue(); |
| 2403 | dispatchOnLauncherTransitionStep(fromView, t); |
| 2404 | dispatchOnLauncherTransitionStep(toView, t); |
| 2405 | } |
| 2406 | }); |
Michael Jurka | 159b4cc | 2012-01-17 03:00:35 -0800 | [diff] [blame] | 2407 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2408 | mStateAnimation = new AnimatorSet(); |
| 2409 | |
| 2410 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 2411 | dispatchOnLauncherTransitionStart(toView, animated, true); |
| 2412 | |
| 2413 | mStateAnimation.addListener(new AnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 2414 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 2415 | public void onAnimationEnd(Animator animation) { |
Dianne Hackborn | bb003a5 | 2011-08-30 14:40:07 -0700 | [diff] [blame] | 2416 | updateWallpaperVisibility(true); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2417 | fromView.setVisibility(View.GONE); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2418 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
| 2419 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Michael Jurka | 430e8a5 | 2011-08-08 15:52:14 -0700 | [diff] [blame] | 2420 | mWorkspace.hideScrollingIndicator(false); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2421 | if (onCompleteRunnable != null) { |
| 2422 | onCompleteRunnable.run(); |
| 2423 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2424 | } |
| 2425 | }); |
| 2426 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2427 | mStateAnimation.playTogether(scaleAnim, alphaAnim); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2428 | if (workspaceAnim != null) { |
| 2429 | mStateAnimation.play(workspaceAnim); |
| 2430 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2431 | mStateAnimation.start(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2432 | } else { |
| 2433 | fromView.setVisibility(View.GONE); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2434 | dispatchOnLauncherTransitionStart(fromView, animated, true); |
| 2435 | dispatchOnLauncherTransitionEnd(fromView, animated, true); |
| 2436 | dispatchOnLauncherTransitionStart(toView, animated, true); |
| 2437 | dispatchOnLauncherTransitionEnd(toView, animated, true); |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 2438 | mWorkspace.hideScrollingIndicator(false); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2439 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 2442 | @Override |
| 2443 | public void onTrimMemory(int level) { |
| 2444 | super.onTrimMemory(level); |
Dianne Hackborn | 4f560ce | 2012-03-06 19:07:47 -0800 | [diff] [blame] | 2445 | if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) { |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 2446 | mAppsCustomizeTabHost.onTrimMemory(); |
| 2447 | } |
| 2448 | } |
| 2449 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2450 | void showWorkspace(boolean animated) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2451 | showWorkspace(animated, null); |
| 2452 | } |
| 2453 | |
| 2454 | void showWorkspace(boolean animated, Runnable onCompleteRunnable) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2455 | if (mState != State.WORKSPACE) { |
| 2456 | mWorkspace.setVisibility(View.VISIBLE); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2457 | hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2458 | |
| 2459 | // Show the search bar and hotseat |
| 2460 | mSearchDropTargetBar.showSearchBar(animated); |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 2461 | // We only need to animate in the dock divider if we're going from spring loaded mode |
| 2462 | showDockDivider(animated && mState == State.APPS_CUSTOMIZE_SPRING_LOADED); |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2463 | |
| 2464 | // Set focus to the AppsCustomize button |
| 2465 | if (mAllAppsButton != null) { |
| 2466 | mAllAppsButton.requestFocus(); |
| 2467 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2468 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 2469 | |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 2470 | mWorkspace.flashScrollingIndicator(animated); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2471 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2472 | // Change the state *after* we've called all the transition code |
| 2473 | mState = State.WORKSPACE; |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 2474 | |
Winson Chung | 5fb6347 | 2011-02-02 17:03:37 -0800 | [diff] [blame] | 2475 | // Resume the auto-advance of widgets |
| 2476 | mUserPresent = true; |
| 2477 | updateRunning(); |
| 2478 | |
Svetoslav Ganov | 815ba2d | 2011-01-07 14:55:17 -0800 | [diff] [blame] | 2479 | // send an accessibility event to announce the context change |
| 2480 | getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 2481 | } |
| 2482 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2483 | void showAllApps(boolean animated) { |
| 2484 | if (mState != State.WORKSPACE) return; |
| 2485 | |
| 2486 | showAppsCustomizeHelper(animated, false); |
| 2487 | mAppsCustomizeTabHost.requestFocus(); |
| 2488 | |
| 2489 | // Hide the search bar and hotseat |
| 2490 | mSearchDropTargetBar.hideSearchBar(animated); |
| 2491 | |
| 2492 | // Change the state *after* we've called all the transition code |
| 2493 | mState = State.APPS_CUSTOMIZE; |
| 2494 | |
| 2495 | // Pause the auto-advance of widgets until we are out of AllApps |
| 2496 | mUserPresent = false; |
| 2497 | updateRunning(); |
| 2498 | closeFolder(); |
| 2499 | |
| 2500 | // Send an accessibility event to announce the context change |
| 2501 | getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); |
| 2502 | } |
| 2503 | |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2504 | void enterSpringLoadedDragMode() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 2505 | if (mState == State.APPS_CUSTOMIZE) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2506 | hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null); |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 2507 | hideDockDivider(); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2508 | mState = State.APPS_CUSTOMIZE_SPRING_LOADED; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 2509 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2510 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2511 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2512 | void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay, |
| 2513 | final Runnable onCompleteRunnable) { |
Winson Chung | 09bfc45 | 2011-09-09 11:30:20 -0700 | [diff] [blame] | 2514 | if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return; |
| 2515 | |
Winson Chung | e7a0394 | 2011-08-05 15:05:12 -0700 | [diff] [blame] | 2516 | mHandler.postDelayed(new Runnable() { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 2517 | @Override |
| 2518 | public void run() { |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 2519 | if (successfulDrop) { |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 2520 | // Before we show workspace, hide all apps again because |
| 2521 | // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should |
| 2522 | // clean up our state transition functions |
| 2523 | mAppsCustomizeTabHost.setVisibility(View.GONE); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2524 | mSearchDropTargetBar.showSearchBar(true); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2525 | showWorkspace(true, onCompleteRunnable); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2526 | } else { |
| 2527 | exitSpringLoadedDragMode(); |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 2528 | } |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 2529 | } |
| 2530 | }, (extendedDelay ? |
| 2531 | EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT : |
| 2532 | EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT)); |
| 2533 | } |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2534 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2535 | void exitSpringLoadedDragMode() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 2536 | if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) { |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2537 | final boolean animated = true; |
| 2538 | final boolean springLoaded = true; |
| 2539 | showAppsCustomizeHelper(animated, springLoaded); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 2540 | mState = State.APPS_CUSTOMIZE; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2541 | } |
| 2542 | // Otherwise, we are not in spring loaded mode, so don't do anything. |
| 2543 | } |
| 2544 | |
Michael Jurka | b737ee6 | 2011-11-15 15:57:22 -0800 | [diff] [blame] | 2545 | void hideDockDivider() { |
| 2546 | if (mQsbDivider != null && mDockDivider != null) { |
| 2547 | mQsbDivider.setVisibility(View.INVISIBLE); |
| 2548 | mDockDivider.setVisibility(View.INVISIBLE); |
| 2549 | } |
| 2550 | } |
| 2551 | |
| 2552 | void showDockDivider(boolean animated) { |
| 2553 | if (mQsbDivider != null && mDockDivider != null) { |
| 2554 | mQsbDivider.setVisibility(View.VISIBLE); |
| 2555 | mDockDivider.setVisibility(View.VISIBLE); |
| 2556 | if (mDividerAnimator != null) { |
| 2557 | mDividerAnimator.cancel(); |
| 2558 | mQsbDivider.setAlpha(1f); |
| 2559 | mDockDivider.setAlpha(1f); |
| 2560 | mDividerAnimator = null; |
| 2561 | } |
| 2562 | if (animated) { |
| 2563 | mDividerAnimator = new AnimatorSet(); |
| 2564 | mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f), |
| 2565 | ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f)); |
| 2566 | mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration()); |
| 2567 | mDividerAnimator.start(); |
| 2568 | } |
| 2569 | } |
| 2570 | } |
| 2571 | |
Michael Jurka | b3e22d9 | 2011-10-31 15:58:33 -0700 | [diff] [blame] | 2572 | void lockAllApps() { |
| 2573 | // TODO |
| 2574 | } |
| 2575 | |
| 2576 | void unlockAllApps() { |
| 2577 | // TODO |
| 2578 | } |
| 2579 | |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 2580 | public boolean isAllAppsCustomizeOpen() { |
| 2581 | return mState == State.APPS_CUSTOMIZE; |
| 2582 | } |
| 2583 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2584 | /** |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2585 | * Shows the hotseat area. |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2586 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2587 | void showHotseat(boolean animated) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2588 | if (!LauncherApplication.isScreenLarge()) { |
| 2589 | if (animated) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 2590 | if (mHotseat.getAlpha() != 1f) { |
| 2591 | int duration = mSearchDropTargetBar.getTransitionInDuration(); |
| 2592 | mHotseat.animate().alpha(1f).setDuration(duration); |
| 2593 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2594 | } else { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2595 | mHotseat.setAlpha(1f); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2596 | } |
| 2597 | } |
| 2598 | } |
| 2599 | |
| 2600 | /** |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2601 | * Hides the hotseat area. |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2602 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2603 | void hideHotseat(boolean animated) { |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2604 | if (!LauncherApplication.isScreenLarge()) { |
| 2605 | if (animated) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 2606 | if (mHotseat.getAlpha() != 0f) { |
| 2607 | int duration = mSearchDropTargetBar.getTransitionOutDuration(); |
| 2608 | mHotseat.animate().alpha(0f).setDuration(duration); |
| 2609 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2610 | } else { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2611 | mHotseat.setAlpha(0f); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 2612 | } |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 2613 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2614 | } |
| 2615 | |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 2616 | /** |
| 2617 | * Add an item from all apps or customize onto the given workspace screen. |
| 2618 | * If layout is null, add to the current screen. |
| 2619 | */ |
| 2620 | void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) { |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 2621 | if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 2622 | showOutOfSpaceMessage(isHotseatLayout(layout)); |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 2623 | } |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 2624 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2625 | |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 2626 | /** Maps the current orientation to an index for referencing orientation correct global icons */ |
| 2627 | private int getCurrentOrientationIndexForGlobalIcons() { |
| 2628 | // default - 0, landscape - 1 |
| 2629 | switch (getResources().getConfiguration().orientation) { |
| 2630 | case Configuration.ORIENTATION_LANDSCAPE: |
| 2631 | return 1; |
| 2632 | default: |
| 2633 | return 0; |
| 2634 | } |
| 2635 | } |
| 2636 | |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 2637 | private Drawable getExternalPackageToolbarIcon(ComponentName activityName) { |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 2638 | try { |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 2639 | PackageManager packageManager = getPackageManager(); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 2640 | // Look for the toolbar icon specified in the activity meta-data |
| 2641 | Bundle metaData = packageManager.getActivityInfo( |
| 2642 | activityName, PackageManager.GET_META_DATA).metaData; |
| 2643 | if (metaData != null) { |
| 2644 | int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME); |
| 2645 | if (iconResId != 0) { |
| 2646 | Resources res = packageManager.getResourcesForActivity(activityName); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 2647 | return res.getDrawable(iconResId); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 2648 | } |
| 2649 | } |
| 2650 | } catch (NameNotFoundException e) { |
Michael Jurka | b6052a9 | 2011-07-12 17:02:45 -0700 | [diff] [blame] | 2651 | // This can happen if the activity defines an invalid drawable |
| 2652 | Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() + |
| 2653 | " not found", e); |
Mathew Inwood | 70d5102 | 2011-07-12 13:41:41 +0100 | [diff] [blame] | 2654 | } catch (Resources.NotFoundException nfe) { |
| 2655 | // This can happen if the activity defines an invalid drawable |
| 2656 | Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(), |
| 2657 | nfe); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 2658 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 2659 | return null; |
| 2660 | } |
| 2661 | |
| 2662 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 2663 | private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity( |
| 2664 | int buttonId, ComponentName activityName, int fallbackDrawableId) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 2665 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName); |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 2666 | Resources r = getResources(); |
| 2667 | int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width); |
| 2668 | int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 2669 | |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 2670 | TextView button = (TextView) findViewById(buttonId); |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 2671 | // If we were unable to find the icon via the meta-data, use a generic one |
| 2672 | if (toolbarIcon == null) { |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 2673 | toolbarIcon = r.getDrawable(fallbackDrawableId); |
| 2674 | toolbarIcon.setBounds(0, 0, w, h); |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 2675 | if (button != null) { |
| 2676 | button.setCompoundDrawables(toolbarIcon, null, null, null); |
| 2677 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 2678 | return null; |
| 2679 | } else { |
Winson Chung | 128bbcd | 2011-08-31 16:58:52 -0700 | [diff] [blame] | 2680 | toolbarIcon.setBounds(0, 0, w, h); |
Michael Jurka | 4da7a3e | 2011-10-28 15:04:35 -0700 | [diff] [blame] | 2681 | if (button != null) { |
| 2682 | button.setCompoundDrawables(toolbarIcon, null, null, null); |
| 2683 | } |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 2684 | return toolbarIcon.getConstantState(); |
| 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
| 2689 | private Drawable.ConstantState updateButtonWithIconFromExternalActivity( |
| 2690 | int buttonId, ComponentName activityName, int fallbackDrawableId) { |
| 2691 | ImageView button = (ImageView) findViewById(buttonId); |
| 2692 | Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName); |
| 2693 | |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 2694 | if (button != null) { |
| 2695 | // If we were unable to find the icon via the meta-data, use a |
| 2696 | // generic one |
| 2697 | if (toolbarIcon == null) { |
| 2698 | button.setImageResource(fallbackDrawableId); |
| 2699 | } else { |
| 2700 | button.setImageDrawable(toolbarIcon); |
| 2701 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 2702 | } |
Michael Jurka | 19e0fc5 | 2011-07-22 18:00:21 -0700 | [diff] [blame] | 2703 | |
| 2704 | return toolbarIcon != null ? toolbarIcon.getConstantState() : null; |
| 2705 | |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 2706 | } |
| 2707 | |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 2708 | private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) { |
| 2709 | TextView button = (TextView) findViewById(buttonId); |
| 2710 | button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null); |
| 2711 | } |
| 2712 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 2713 | private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 2714 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 2715 | button.setImageDrawable(d.newDrawable(getResources())); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 2716 | } |
| 2717 | |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2718 | private void invalidatePressedFocusedStates(View container, View button) { |
| 2719 | if (container instanceof HolographicLinearLayout) { |
| 2720 | HolographicLinearLayout layout = (HolographicLinearLayout) container; |
| 2721 | layout.invalidatePressedFocusedStates(); |
| 2722 | } else if (button instanceof HolographicImageView) { |
| 2723 | HolographicImageView view = (HolographicImageView) button; |
| 2724 | view.invalidatePressedFocusedStates(); |
| 2725 | } |
| 2726 | } |
| 2727 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2728 | private boolean updateGlobalSearchIcon() { |
| 2729 | final View searchButtonContainer = findViewById(R.id.search_button_container); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 2730 | final ImageView searchButton = (ImageView) findViewById(R.id.search_button); |
| 2731 | final View searchDivider = findViewById(R.id.search_divider); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2732 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 2733 | final View voiceButton = findViewById(R.id.voice_button); |
Winson Chung | e3fbfa9 | 2012-04-24 14:34:28 -0700 | [diff] [blame^] | 2734 | final View voiceButtonProxy = findViewById(R.id.voice_button_proxy); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 2735 | |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 2736 | final SearchManager searchManager = |
| 2737 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 2738 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
| 2739 | if (activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 2740 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 2741 | sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
Winson Chung | c7aef8c | 2011-09-15 18:53:04 -0700 | [diff] [blame] | 2742 | R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo); |
Winson Chung | 649723c | 2011-07-06 20:41:23 -0700 | [diff] [blame] | 2743 | if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2744 | if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE); |
| 2745 | searchButton.setVisibility(View.VISIBLE); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2746 | invalidatePressedFocusedStates(searchButtonContainer, searchButton); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2747 | return true; |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 2748 | } else { |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 2749 | // We disable both search and voice search when there is no global search provider |
Winson Chung | 649723c | 2011-07-06 20:41:23 -0700 | [diff] [blame] | 2750 | if (searchDivider != null) searchDivider.setVisibility(View.GONE); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2751 | if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE); |
| 2752 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); |
| 2753 | searchButton.setVisibility(View.GONE); |
Winson Chung | cbf7c4d | 2011-08-23 11:58:54 -0700 | [diff] [blame] | 2754 | voiceButton.setVisibility(View.GONE); |
Winson Chung | e3fbfa9 | 2012-04-24 14:34:28 -0700 | [diff] [blame^] | 2755 | voiceButtonProxy.setVisibility(View.GONE); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2756 | return false; |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2757 | } |
| 2758 | } |
| 2759 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 2760 | private void updateGlobalSearchIcon(Drawable.ConstantState d) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2761 | final View searchButtonContainer = findViewById(R.id.search_button_container); |
| 2762 | final View searchButton = (ImageView) findViewById(R.id.search_button); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 2763 | updateButtonWithDrawable(R.id.search_button, d); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2764 | invalidatePressedFocusedStates(searchButtonContainer, searchButton); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 2765 | } |
| 2766 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2767 | private boolean updateVoiceSearchIcon(boolean searchVisible) { |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 2768 | final View searchDivider = findViewById(R.id.search_divider); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2769 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 2770 | final View voiceButton = findViewById(R.id.voice_button); |
Winson Chung | e3fbfa9 | 2012-04-24 14:34:28 -0700 | [diff] [blame^] | 2771 | final View voiceButtonProxy = findViewById(R.id.voice_button_proxy); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 2772 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2773 | // We only show/update the voice search icon if the search icon is enabled as well |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 2774 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 2775 | ComponentName activityName = intent.resolveActivity(getPackageManager()); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2776 | if (searchVisible && activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 2777 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
| 2778 | sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( |
Winson Chung | c7aef8c | 2011-09-15 18:53:04 -0700 | [diff] [blame] | 2779 | R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo); |
Winson Chung | 649723c | 2011-07-06 20:41:23 -0700 | [diff] [blame] | 2780 | if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2781 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 2782 | voiceButton.setVisibility(View.VISIBLE); |
Winson Chung | e3fbfa9 | 2012-04-24 14:34:28 -0700 | [diff] [blame^] | 2783 | voiceButtonProxy.setVisibility(View.VISIBLE); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2784 | invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2785 | return true; |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 2786 | } else { |
Winson Chung | 649723c | 2011-07-06 20:41:23 -0700 | [diff] [blame] | 2787 | if (searchDivider != null) searchDivider.setVisibility(View.GONE); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2788 | if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); |
Winson Chung | 1cad91e | 2011-05-25 17:41:01 -0700 | [diff] [blame] | 2789 | voiceButton.setVisibility(View.GONE); |
Winson Chung | e3fbfa9 | 2012-04-24 14:34:28 -0700 | [diff] [blame^] | 2790 | voiceButtonProxy.setVisibility(View.GONE); |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 2791 | return false; |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 2792 | } |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 2793 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 2794 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 2795 | private void updateVoiceSearchIcon(Drawable.ConstantState d) { |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2796 | final View voiceButtonContainer = findViewById(R.id.voice_button_container); |
| 2797 | final View voiceButton = findViewById(R.id.voice_button); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 2798 | updateButtonWithDrawable(R.id.voice_button, d); |
Winson Chung | bb185bd | 2011-11-21 12:31:42 -0800 | [diff] [blame] | 2799 | invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 2800 | } |
| 2801 | |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 2802 | /** |
Winson Chung | eb66b14 | 2011-06-16 13:14:22 -0700 | [diff] [blame] | 2803 | * Sets the app market icon |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 2804 | */ |
| 2805 | private void updateAppMarketIcon() { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2806 | final View marketButton = findViewById(R.id.market_button); |
| 2807 | Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET); |
| 2808 | // Find the app market activity by resolving an intent. |
| 2809 | // (If multiple app markets are installed, it will return the ResolverActivity.) |
| 2810 | ComponentName activityName = intent.resolveActivity(getPackageManager()); |
Winson Chung | 6a26e5b | 2011-05-26 14:36:06 -0700 | [diff] [blame] | 2811 | if (activityName != null) { |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 2812 | int coi = getCurrentOrientationIndexForGlobalIcons(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2813 | mAppMarketIntent = intent; |
Winson Chung | dff8ebb | 2011-09-08 17:25:31 -0700 | [diff] [blame] | 2814 | sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity( |
Winson Chung | 967289b | 2011-06-30 18:09:30 -0700 | [diff] [blame] | 2815 | R.id.market_button, activityName, R.drawable.ic_launcher_market_holo); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2816 | marketButton.setVisibility(View.VISIBLE); |
| 2817 | } else { |
| 2818 | // We should hide and disable the view so that we don't try and restore the visibility |
| 2819 | // of it when we swap between drag & normal states from IconDropTarget subclasses. |
| 2820 | marketButton.setVisibility(View.GONE); |
| 2821 | marketButton.setEnabled(false); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 2822 | } |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 2823 | } |
| 2824 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 2825 | private void updateAppMarketIcon(Drawable.ConstantState d) { |
Winson Chung | fbb3d9b | 2011-03-01 12:43:02 -0800 | [diff] [blame] | 2826 | updateTextButtonWithDrawable(R.id.market_button, d); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 2827 | } |
| 2828 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 2829 | /** |
Winson Chung | b8472bb | 2011-08-05 13:49:21 -0700 | [diff] [blame] | 2830 | * Receives notifications when system dialogs are to be closed. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2831 | */ |
| 2832 | private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { |
| 2833 | @Override |
| 2834 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 2835 | closeSystemDialogs(); |
| 2836 | } |
| 2837 | } |
| 2838 | |
| 2839 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 2840 | * Receives notifications whenever the appwidgets are reset. |
| 2841 | */ |
| 2842 | private class AppWidgetResetObserver extends ContentObserver { |
| 2843 | public AppWidgetResetObserver() { |
| 2844 | super(new Handler()); |
| 2845 | } |
| 2846 | |
| 2847 | @Override |
| 2848 | public void onChange(boolean selfChange) { |
| 2849 | onAppWidgetReset(); |
| 2850 | } |
| 2851 | } |
| 2852 | |
| 2853 | /** |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 2854 | * If the activity is currently paused, signal that we need to re-run the loader |
| 2855 | * in onResume. |
| 2856 | * |
| 2857 | * This needs to be called from incoming places where resources might have been loaded |
| 2858 | * while we are paused. That is becaues the Configuration might be wrong |
| 2859 | * when we're not running, and if it comes back to what it was when we |
| 2860 | * were paused, we are not restarted. |
| 2861 | * |
| 2862 | * Implementation of the method from LauncherModel.Callbacks. |
| 2863 | * |
| 2864 | * @return true if we are currently paused. The caller might be able to |
| 2865 | * skip some work in that case since we will come back again. |
| 2866 | */ |
| 2867 | public boolean setLoadOnResume() { |
| 2868 | if (mPaused) { |
| 2869 | Log.i(TAG, "setLoadOnResume"); |
| 2870 | mOnResumeNeedsLoad = true; |
| 2871 | return true; |
| 2872 | } else { |
| 2873 | return false; |
| 2874 | } |
| 2875 | } |
| 2876 | |
| 2877 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2878 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2879 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2880 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 2881 | if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2882 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 2883 | } else { |
| 2884 | return SCREEN_COUNT / 2; |
| 2885 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2886 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 2887 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2888 | /** |
| 2889 | * Refreshes the shortcuts shown on the workspace. |
| 2890 | * |
| 2891 | * Implementation of the method from LauncherModel.Callbacks. |
| 2892 | */ |
| 2893 | public void startBinding() { |
| 2894 | final Workspace workspace = mWorkspace; |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2895 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 2896 | mNewShortcutAnimatePage = -1; |
| 2897 | mNewShortcutAnimateViews.clear(); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2898 | mWorkspace.clearDropTargets(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2899 | int count = workspace.getChildCount(); |
| 2900 | for (int i = 0; i < count; i++) { |
Joe Onorato | 3c2f7e1 | 2009-10-31 19:17:31 -0400 | [diff] [blame] | 2901 | // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate(). |
Winson Chung | 7a25a9e | 2011-01-30 13:33:56 -0800 | [diff] [blame] | 2902 | final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i); |
| 2903 | layoutParent.removeAllViewsInLayout(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2904 | } |
Michael Jurka | 05bf644e | 2011-11-30 20:28:53 -0800 | [diff] [blame] | 2905 | mWidgetsToAdvance.clear(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2906 | if (mHotseat != null) { |
| 2907 | mHotseat.resetLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2908 | } |
| 2909 | } |
| 2910 | |
| 2911 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2912 | * Bind the items start-end from the list. |
| 2913 | * |
| 2914 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2915 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2916 | public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 2917 | setLoadOnResume(); |
| 2918 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 2919 | // Get the list of added shortcuts and intersect them with the set of shortcuts here |
| 2920 | Set<String> newApps = new HashSet<String>(); |
| 2921 | newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps); |
| 2922 | |
| 2923 | Workspace workspace = mWorkspace; |
| 2924 | for (int i = start; i < end; i++) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2925 | final ItemInfo item = shortcuts.get(i); |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 2926 | |
| 2927 | // Short circuit if we are loading dock items for a configuration which has no dock |
| 2928 | if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 2929 | mHotseat == null) { |
| 2930 | continue; |
| 2931 | } |
| 2932 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2933 | switch (item.itemType) { |
| 2934 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 2935 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 2936 | ShortcutInfo info = (ShortcutInfo) item; |
| 2937 | String uri = info.intent.toUri(0).toString(); |
| 2938 | View shortcut = createShortcut(info); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2939 | workspace.addInScreen(shortcut, item.container, item.screen, item.cellX, |
| 2940 | item.cellY, 1, 1, false); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 2941 | if (newApps.contains(uri)) { |
| 2942 | newApps.remove(uri); |
| 2943 | |
| 2944 | // Prepare the view to be animated up |
| 2945 | shortcut.setAlpha(0f); |
| 2946 | shortcut.setScaleX(0f); |
| 2947 | shortcut.setScaleY(0f); |
| 2948 | mNewShortcutAnimatePage = item.screen; |
| 2949 | if (!mNewShortcutAnimateViews.contains(shortcut)) { |
| 2950 | mNewShortcutAnimateViews.add(shortcut); |
| 2951 | } |
| 2952 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2953 | break; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 2954 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2955 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2956 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 2957 | (FolderInfo) item, mIconCache); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2958 | workspace.addInScreen(newFolder, item.container, item.screen, item.cellX, |
| 2959 | item.cellY, 1, 1, false); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2960 | break; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2961 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2962 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 2963 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2964 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2965 | } |
| 2966 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2967 | /** |
| 2968 | * Implementation of the method from LauncherModel.Callbacks. |
| 2969 | */ |
Joe Onorato | ad72e17 | 2009-11-06 16:25:04 -0500 | [diff] [blame] | 2970 | public void bindFolders(HashMap<Long, FolderInfo> folders) { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 2971 | setLoadOnResume(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2972 | sFolders.clear(); |
| 2973 | sFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2974 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2975 | |
| 2976 | /** |
| 2977 | * Add the views for a widget to the workspace. |
| 2978 | * |
| 2979 | * Implementation of the method from LauncherModel.Callbacks. |
| 2980 | */ |
| 2981 | public void bindAppWidget(LauncherAppWidgetInfo item) { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 2982 | setLoadOnResume(); |
| 2983 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2984 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 2985 | if (DEBUG_WIDGETS) { |
| 2986 | Log.d(TAG, "bindAppWidget: " + item); |
| 2987 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2988 | final Workspace workspace = mWorkspace; |
| 2989 | |
| 2990 | final int appWidgetId = item.appWidgetId; |
| 2991 | final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2992 | if (DEBUG_WIDGETS) { |
| 2993 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); |
| 2994 | } |
| 2995 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2996 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 2997 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2998 | item.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
| 2999 | item.hostView.setTag(item); |
| 3000 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3001 | workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX, |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3002 | item.cellY, item.spanX, item.spanY, false); |
| 3003 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 3004 | addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); |
| 3005 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3006 | workspace.requestLayout(); |
| 3007 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3008 | if (DEBUG_WIDGETS) { |
| 3009 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 3010 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 3011 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | /** |
| 3015 | * Callback saying that there aren't any more items to bind. |
| 3016 | * |
| 3017 | * Implementation of the method from LauncherModel.Callbacks. |
| 3018 | */ |
| 3019 | public void finishBindingItems() { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3020 | setLoadOnResume(); |
| 3021 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3022 | if (mSavedState != null) { |
| 3023 | if (!mWorkspace.hasFocus()) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3024 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3025 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3026 | mSavedState = null; |
| 3027 | } |
| 3028 | |
| 3029 | if (mSavedInstanceState != null) { |
| 3030 | super.onRestoreInstanceState(mSavedInstanceState); |
| 3031 | mSavedInstanceState = null; |
| 3032 | } |
| 3033 | |
Patrick Dubroy | 002cbf4 | 2011-03-03 16:36:21 -0800 | [diff] [blame] | 3034 | // If we received the result of any pending adds while the loader was running (e.g. the |
| 3035 | // widget configuration forced an orientation change), process them now. |
| 3036 | for (int i = 0; i < sPendingAddList.size(); i++) { |
| 3037 | completeAdd(sPendingAddList.get(i)); |
| 3038 | } |
| 3039 | sPendingAddList.clear(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3040 | |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3041 | // Update the market app icon as necessary (the other icons will be managed in response to |
| 3042 | // package changes in bindSearchablesChanged() |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3043 | updateAppMarketIcon(); |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 3044 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3045 | // Animate up any icons as necessary |
| 3046 | if (mVisible || mWorkspaceLoading) { |
| 3047 | Runnable newAppsRunnable = new Runnable() { |
| 3048 | @Override |
| 3049 | public void run() { |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 3050 | runNewAppsAnimation(false); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3051 | } |
| 3052 | }; |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 3053 | |
| 3054 | boolean willSnapPage = mNewShortcutAnimatePage > -1 && |
| 3055 | mNewShortcutAnimatePage != mWorkspace.getCurrentPage(); |
| 3056 | if (canRunNewAppsAnimation()) { |
| 3057 | // If the user has not interacted recently, then either snap to the new page to show |
| 3058 | // the new-apps animation or just run them if they are to appear on the current page |
| 3059 | if (willSnapPage) { |
| 3060 | mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable); |
| 3061 | } else { |
| 3062 | runNewAppsAnimation(false); |
| 3063 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3064 | } else { |
Winson Chung | 318eee0 | 2012-04-12 10:59:27 -0700 | [diff] [blame] | 3065 | // If the user has interacted recently, then just add the items in place if they |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 3066 | // are on another page (or just normally if they are added to the current page) |
| 3067 | runNewAppsAnimation(willSnapPage); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3068 | } |
| 3069 | } |
| 3070 | |
| 3071 | mWorkspaceLoading = false; |
| 3072 | } |
| 3073 | |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 3074 | private boolean canRunNewAppsAnimation() { |
| 3075 | long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime(); |
| 3076 | return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); |
| 3077 | } |
| 3078 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3079 | /** |
| 3080 | * Runs a new animation that scales up icons that were added while Launcher was in the |
| 3081 | * background. |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 3082 | * |
| 3083 | * @param immediate whether to run the animation or show the results immediately |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3084 | */ |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 3085 | private void runNewAppsAnimation(boolean immediate) { |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3086 | AnimatorSet anim = new AnimatorSet(); |
| 3087 | Collection<Animator> bounceAnims = new ArrayList<Animator>(); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 3088 | |
| 3089 | // Order these new views spatially so that they animate in order |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3090 | Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() { |
| 3091 | @Override |
| 3092 | public int compare(View a, View b) { |
| 3093 | CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams(); |
| 3094 | CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams(); |
| 3095 | int cellCountX = LauncherModel.getCellCountX(); |
| 3096 | return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX); |
| 3097 | } |
| 3098 | }); |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 3099 | |
| 3100 | // Animate each of the views in place (or show them immediately if requested) |
| 3101 | if (immediate) { |
| 3102 | for (View v : mNewShortcutAnimateViews) { |
| 3103 | v.setAlpha(1f); |
| 3104 | v.setScaleX(1f); |
| 3105 | v.setScaleY(1f); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3106 | } |
Winson Chung | a241375 | 2012-04-03 14:22:34 -0700 | [diff] [blame] | 3107 | } else { |
| 3108 | for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) { |
| 3109 | View v = mNewShortcutAnimateViews.get(i); |
| 3110 | ValueAnimator bounceAnim = ObjectAnimator.ofPropertyValuesHolder(v, |
| 3111 | PropertyValuesHolder.ofFloat("alpha", 1f), |
| 3112 | PropertyValuesHolder.ofFloat("scaleX", 1f), |
| 3113 | PropertyValuesHolder.ofFloat("scaleY", 1f)); |
| 3114 | bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION); |
| 3115 | bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY); |
| 3116 | bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator()); |
| 3117 | bounceAnims.add(bounceAnim); |
| 3118 | } |
| 3119 | anim.playTogether(bounceAnims); |
| 3120 | anim.addListener(new AnimatorListenerAdapter() { |
| 3121 | @Override |
| 3122 | public void onAnimationEnd(Animator animation) { |
| 3123 | mWorkspace.postDelayed(mBuildLayersRunnable, 500); |
| 3124 | } |
| 3125 | }); |
| 3126 | anim.start(); |
| 3127 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 3128 | |
| 3129 | // Clean up |
| 3130 | mNewShortcutAnimatePage = -1; |
| 3131 | mNewShortcutAnimateViews.clear(); |
| 3132 | new Thread("clearNewAppsThread") { |
| 3133 | public void run() { |
| 3134 | mSharedPrefs.edit() |
| 3135 | .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1) |
| 3136 | .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null) |
| 3137 | .commit(); |
| 3138 | } |
| 3139 | }.start(); |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3140 | } |
| 3141 | |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 3142 | @Override |
| 3143 | public void bindSearchablesChanged() { |
Winson Chung | c51db6a | 2011-10-05 11:44:49 -0700 | [diff] [blame] | 3144 | boolean searchVisible = updateGlobalSearchIcon(); |
| 3145 | boolean voiceVisible = updateVoiceSearchIcon(searchVisible); |
| 3146 | mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); |
Narayan Kamath | cb1a477 | 2011-06-28 13:46:59 +0100 | [diff] [blame] | 3147 | } |
| 3148 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3149 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3150 | * Add the icons for all apps. |
| 3151 | * |
| 3152 | * Implementation of the method from LauncherModel.Callbacks. |
| 3153 | */ |
Michael Jurka | c57b7a8 | 2011-08-09 22:02:20 -0700 | [diff] [blame] | 3154 | public void bindAllApplications(final ArrayList<ApplicationInfo> apps) { |
| 3155 | // Remove the progress bar entirely; we could also make it GONE |
| 3156 | // but better to remove it since we know it's not going to be used |
| 3157 | View progressBar = mAppsCustomizeTabHost. |
| 3158 | findViewById(R.id.apps_customize_progress_bar); |
| 3159 | if (progressBar != null) { |
| 3160 | ((ViewGroup)progressBar.getParent()).removeView(progressBar); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3161 | } |
Michael Jurka | c57b7a8 | 2011-08-09 22:02:20 -0700 | [diff] [blame] | 3162 | // We just post the call to setApps so the user sees the progress bar |
| 3163 | // disappear-- otherwise, it just looks like the progress bar froze |
| 3164 | // which doesn't look great |
| 3165 | mAppsCustomizeTabHost.post(new Runnable() { |
| 3166 | public void run() { |
| 3167 | if (mAppsCustomizeContent != null) { |
| 3168 | mAppsCustomizeContent.setApps(apps); |
| 3169 | } |
| 3170 | } |
| 3171 | }); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | /** |
| 3175 | * A package was installed. |
| 3176 | * |
| 3177 | * Implementation of the method from LauncherModel.Callbacks. |
| 3178 | */ |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3179 | public void bindAppsAdded(ArrayList<ApplicationInfo> apps) { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3180 | setLoadOnResume(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3181 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3182 | if (mAppsCustomizeContent != null) { |
| 3183 | mAppsCustomizeContent.addApps(apps); |
| 3184 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | /** |
| 3188 | * A package was updated. |
| 3189 | * |
| 3190 | * Implementation of the method from LauncherModel.Callbacks. |
| 3191 | */ |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3192 | public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3193 | setLoadOnResume(); |
Patrick Dubroy | f5afda7 | 2011-02-28 12:04:18 -0800 | [diff] [blame] | 3194 | if (mWorkspace != null) { |
| 3195 | mWorkspace.updateShortcuts(apps); |
| 3196 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3197 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3198 | if (mAppsCustomizeContent != null) { |
| 3199 | mAppsCustomizeContent.updateApps(apps); |
| 3200 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | /** |
| 3204 | * A package was uninstalled. |
| 3205 | * |
| 3206 | * Implementation of the method from LauncherModel.Callbacks. |
| 3207 | */ |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3208 | public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) { |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3209 | if (permanent) { |
| 3210 | mWorkspace.removeItems(apps); |
| 3211 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3212 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3213 | if (mAppsCustomizeContent != null) { |
| 3214 | mAppsCustomizeContent.removeApps(apps); |
| 3215 | } |
Winson Chung | a182096 | 2011-10-03 16:31:06 -0700 | [diff] [blame] | 3216 | |
| 3217 | // Notify the drag controller |
| 3218 | mDragController.onAppsRemoved(apps, this); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3219 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3220 | |
| 3221 | /** |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 3222 | * A number of packages were updated. |
| 3223 | */ |
| 3224 | public void bindPackagesUpdated() { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3225 | if (mAppsCustomizeContent != null) { |
| 3226 | mAppsCustomizeContent.onPackagesUpdated(); |
| 3227 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 3228 | } |
| 3229 | |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 3230 | private int mapConfigurationOriActivityInfoOri(int configOri) { |
| 3231 | final Display d = getWindowManager().getDefaultDisplay(); |
| 3232 | int naturalOri = Configuration.ORIENTATION_LANDSCAPE; |
| 3233 | switch (d.getRotation()) { |
| 3234 | case Surface.ROTATION_0: |
| 3235 | case Surface.ROTATION_180: |
| 3236 | // We are currently in the same basic orientation as the natural orientation |
| 3237 | naturalOri = configOri; |
| 3238 | break; |
| 3239 | case Surface.ROTATION_90: |
| 3240 | case Surface.ROTATION_270: |
| 3241 | // We are currently in the other basic orientation to the natural orientation |
| 3242 | naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? |
| 3243 | Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE; |
| 3244 | break; |
| 3245 | } |
| 3246 | |
| 3247 | int[] oriMap = { |
| 3248 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, |
| 3249 | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, |
| 3250 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, |
| 3251 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE |
| 3252 | }; |
| 3253 | // Since the map starts at portrait, we need to offset if this device's natural orientation |
| 3254 | // is landscape. |
| 3255 | int indexOffset = 0; |
| 3256 | if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) { |
| 3257 | indexOffset = 1; |
| 3258 | } |
| 3259 | return oriMap[(d.getRotation() + indexOffset) % 4]; |
| 3260 | } |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 3261 | |
| 3262 | public void lockScreenOrientationOnLargeUI() { |
| 3263 | if (LauncherApplication.isScreenLarge()) { |
| 3264 | setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources() |
| 3265 | .getConfiguration().orientation)); |
| 3266 | } |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 3267 | } |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 3268 | public void unlockScreenOrientationOnLargeUI() { |
| 3269 | if (LauncherApplication.isScreenLarge()) { |
| 3270 | mHandler.postDelayed(new Runnable() { |
| 3271 | public void run() { |
| 3272 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); |
| 3273 | } |
| 3274 | }, mRestoreScreenOrientationDelay); |
| 3275 | } |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 3276 | } |
| 3277 | |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 3278 | /* Cling related */ |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3279 | private boolean isClingsEnabled() { |
Brett Chabot | 2a9e228 | 2011-08-23 15:03:13 -0700 | [diff] [blame] | 3280 | // disable clings when running in a test harness |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3281 | if(ActivityManager.isRunningInTestHarness()) return false; |
Brett Chabot | 2a9e228 | 2011-08-23 15:03:13 -0700 | [diff] [blame] | 3282 | |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3283 | return true; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 3284 | } |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3285 | private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) { |
| 3286 | Cling cling = (Cling) findViewById(clingId); |
| 3287 | if (cling != null) { |
| 3288 | cling.init(this, positionData); |
| 3289 | cling.setVisibility(View.VISIBLE); |
| 3290 | cling.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 3291 | if (animate) { |
| 3292 | cling.buildLayer(); |
| 3293 | cling.setAlpha(0f); |
| 3294 | cling.animate() |
| 3295 | .alpha(1f) |
Winson Chung | 7a74ac9 | 2011-09-20 17:43:51 -0700 | [diff] [blame] | 3296 | .setInterpolator(new AccelerateInterpolator()) |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3297 | .setDuration(SHOW_CLING_DURATION) |
| 3298 | .setStartDelay(delay) |
| 3299 | .start(); |
| 3300 | } else { |
| 3301 | cling.setAlpha(1f); |
| 3302 | } |
| 3303 | } |
| 3304 | return cling; |
| 3305 | } |
| 3306 | private void dismissCling(final Cling cling, final String flag, int duration) { |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 3307 | if (cling != null) { |
| 3308 | ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3309 | anim.setDuration(duration); |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 3310 | anim.addListener(new AnimatorListenerAdapter() { |
| 3311 | public void onAnimationEnd(Animator animation) { |
| 3312 | cling.setVisibility(View.GONE); |
| 3313 | cling.cleanup(); |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 3314 | // We should update the shared preferences on a background thread |
| 3315 | new Thread("dismissClingThread") { |
| 3316 | public void run() { |
| 3317 | SharedPreferences.Editor editor = mSharedPrefs.edit(); |
| 3318 | editor.putBoolean(flag, true); |
| 3319 | editor.commit(); |
| 3320 | } |
| 3321 | }.start(); |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 3322 | }; |
| 3323 | }); |
| 3324 | anim.start(); |
| 3325 | } |
| 3326 | } |
Winson Chung | 9d9d74f | 2011-09-19 11:49:12 -0700 | [diff] [blame] | 3327 | private void removeCling(int id) { |
| 3328 | final View cling = findViewById(id); |
| 3329 | if (cling != null) { |
| 3330 | final ViewGroup parent = (ViewGroup) cling.getParent(); |
| 3331 | parent.post(new Runnable() { |
| 3332 | @Override |
| 3333 | public void run() { |
| 3334 | parent.removeView(cling); |
| 3335 | } |
| 3336 | }); |
| 3337 | } |
| 3338 | } |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3339 | public void showFirstRunWorkspaceCling() { |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3340 | // Enable the clings only if they have not been dismissed before |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 3341 | if (isClingsEnabled() && |
| 3342 | !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) { |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3343 | initCling(R.id.workspace_cling, null, false, 0); |
Winson Chung | 9d9d74f | 2011-09-19 11:49:12 -0700 | [diff] [blame] | 3344 | } else { |
| 3345 | removeCling(R.id.workspace_cling); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3346 | } |
| 3347 | } |
| 3348 | public void showFirstRunAllAppsCling(int[] position) { |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3349 | // Enable the clings only if they have not been dismissed before |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 3350 | if (isClingsEnabled() && |
| 3351 | !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) { |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3352 | initCling(R.id.all_apps_cling, position, true, 0); |
Winson Chung | 9d9d74f | 2011-09-19 11:49:12 -0700 | [diff] [blame] | 3353 | } else { |
| 3354 | removeCling(R.id.all_apps_cling); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3355 | } |
| 3356 | } |
| 3357 | public Cling showFirstRunFoldersCling() { |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3358 | // Enable the clings only if they have not been dismissed before |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 3359 | if (isClingsEnabled() && |
| 3360 | !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) { |
| 3361 | return initCling(R.id.folder_cling, null, true, 0); |
Winson Chung | 9d9d74f | 2011-09-19 11:49:12 -0700 | [diff] [blame] | 3362 | } else { |
| 3363 | removeCling(R.id.folder_cling); |
Winson Chung | 46353de | 2012-02-16 14:05:10 -0800 | [diff] [blame] | 3364 | return null; |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3365 | } |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3366 | } |
| 3367 | public boolean isFolderClingVisible() { |
| 3368 | Cling cling = (Cling) findViewById(R.id.folder_cling); |
Winson Chung | 9d9d74f | 2011-09-19 11:49:12 -0700 | [diff] [blame] | 3369 | if (cling != null) { |
| 3370 | return cling.getVisibility() == View.VISIBLE; |
| 3371 | } |
| 3372 | return false; |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3373 | } |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 3374 | public void dismissWorkspaceCling(View v) { |
| 3375 | Cling cling = (Cling) findViewById(R.id.workspace_cling); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3376 | dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 3377 | } |
| 3378 | public void dismissAllAppsCling(View v) { |
| 3379 | Cling cling = (Cling) findViewById(R.id.all_apps_cling); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 3380 | dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); |
| 3381 | } |
| 3382 | public void dismissFolderCling(View v) { |
| 3383 | Cling cling = (Cling) findViewById(R.id.folder_cling); |
| 3384 | dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 3385 | } |
| 3386 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 3387 | /** |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3388 | * Prints out out state for debugging. |
| 3389 | */ |
| 3390 | public void dumpState() { |
| 3391 | Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 3392 | Log.d(TAG, "mSavedState=" + mSavedState); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 3393 | Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); |
| 3394 | Log.d(TAG, "mRestoring=" + mRestoring); |
| 3395 | Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); |
| 3396 | Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 3397 | Log.d(TAG, "sFolders.size=" + sFolders.size()); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3398 | mModel.dumpState(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 3399 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3400 | if (mAppsCustomizeContent != null) { |
| 3401 | mAppsCustomizeContent.dumpState(); |
| 3402 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3403 | Log.d(TAG, "END launcher2 dump state"); |
| 3404 | } |
Adam Cohen | 16d7ffc | 2011-10-05 17:49:14 -0700 | [diff] [blame] | 3405 | |
| 3406 | @Override |
| 3407 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 3408 | super.dump(prefix, fd, writer, args); |
| 3409 | writer.println(" "); |
| 3410 | writer.println("Debug logs: "); |
| 3411 | for (int i = 0; i < sDumpLogs.size(); i++) { |
| 3412 | writer.println(" " + sDumpLogs.get(i)); |
| 3413 | } |
| 3414 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3415 | } |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 3416 | |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 3417 | interface LauncherTransitionable { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 3418 | View getContent(); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3419 | void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 3420 | void onLauncherTransitionStep(Launcher l, float t); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 3421 | void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace); |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 3422 | } |