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