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