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