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