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