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