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