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