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