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