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