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 | |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 20 | import com.android.common.Search; |
| 21 | import com.android.launcher.R; |
| 22 | import com.android.launcher2.Workspace.ShrinkState; |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 23 | |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 24 | import android.animation.Animator; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 25 | import android.animation.AnimatorSet; |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 26 | import android.animation.ObjectAnimator; |
Patrick Dubroy | 07a0de4 | 2010-08-26 11:48:35 -0700 | [diff] [blame] | 27 | import android.animation.PropertyValuesHolder; |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 28 | import android.animation.ValueAnimator; |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 29 | import android.app.Activity; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 30 | import android.app.AlertDialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 31 | import android.app.Dialog; |
| 32 | import android.app.SearchManager; |
| 33 | import android.app.StatusBarManager; |
Dianne Hackborn | 107f839 | 2009-08-05 21:32:16 -0700 | [diff] [blame] | 34 | import android.app.WallpaperManager; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 35 | import android.appwidget.AppWidgetManager; |
| 36 | import android.appwidget.AppWidgetProviderInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 37 | import android.content.ActivityNotFoundException; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 38 | import android.content.BroadcastReceiver; |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 39 | import android.content.ClipData; |
| 40 | import android.content.ClipDescription; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 41 | import android.content.ComponentName; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 42 | import android.content.ContentResolver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 43 | import android.content.Context; |
| 44 | import android.content.DialogInterface; |
| 45 | import android.content.Intent; |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 46 | import android.content.IntentFilter; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 47 | import android.content.Intent.ShortcutIconResource; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 48 | import android.content.pm.ActivityInfo; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 49 | import android.content.pm.PackageManager; |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 50 | import android.content.pm.ResolveInfo; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 51 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 52 | import android.content.res.Configuration; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 53 | import android.content.res.Resources; |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 54 | import android.content.res.TypedArray; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 55 | import android.database.ContentObserver; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 56 | import android.graphics.Bitmap; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 57 | import android.graphics.Canvas; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 58 | import android.graphics.Rect; |
Romain Guy | ff0c2e2 | 2009-11-10 12:09:59 -0800 | [diff] [blame] | 59 | import android.graphics.drawable.ColorDrawable; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 60 | import android.graphics.drawable.Drawable; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 61 | import android.net.Uri; |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 62 | import android.os.AsyncTask; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 63 | import android.os.Bundle; |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 64 | import android.os.Environment; |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 65 | import android.os.Handler; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 66 | import android.os.Message; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 67 | import android.os.Parcelable; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 68 | import android.os.SystemClock; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 69 | import android.os.SystemProperties; |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 70 | import android.provider.LiveFolders; |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 71 | import android.provider.Settings; |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 72 | import android.speech.RecognizerIntent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 73 | import android.text.Selection; |
| 74 | import android.text.SpannableStringBuilder; |
| 75 | import android.text.TextUtils; |
| 76 | import android.text.method.TextKeyListener; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 77 | import android.util.Log; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 78 | import android.view.Display; |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 79 | import android.view.HapticFeedbackConstants; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 80 | import android.view.KeyEvent; |
| 81 | import android.view.LayoutInflater; |
| 82 | import android.view.Menu; |
| 83 | import android.view.MenuItem; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 84 | import android.view.MotionEvent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 85 | import android.view.View; |
| 86 | import android.view.ViewGroup; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 87 | import android.view.WindowManager; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 88 | import android.view.View.OnLongClickListener; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 89 | import android.view.inputmethod.InputMethodManager; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 90 | import android.widget.Advanceable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 91 | import android.widget.EditText; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 92 | import android.widget.ImageView; |
| 93 | import android.widget.LinearLayout; |
| 94 | import android.widget.PopupWindow; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 95 | import android.widget.TabHost; |
Winson Chung | 49767ae | 2010-11-29 14:48:30 -0800 | [diff] [blame] | 96 | import android.widget.TabWidget; |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 97 | import android.widget.TextView; |
| 98 | import android.widget.Toast; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 99 | import android.widget.TabHost.OnTabChangeListener; |
| 100 | import android.widget.TabHost.TabContentFactory; |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 101 | |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 102 | import java.io.DataInputStream; |
| 103 | import java.io.DataOutputStream; |
| 104 | import java.io.FileNotFoundException; |
| 105 | import java.io.IOException; |
| 106 | import java.util.ArrayList; |
| 107 | import java.util.HashMap; |
| 108 | import java.util.List; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 109 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 110 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 111 | /** |
| 112 | * Default launcher application. |
| 113 | */ |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 114 | public final class Launcher extends Activity |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 115 | implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, |
| 116 | AllAppsView.Watcher, View.OnTouchListener { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 117 | static final String TAG = "Launcher"; |
Joe Onorato | cc67f47 | 2010-06-08 10:54:30 -0700 | [diff] [blame] | 118 | static final boolean LOGD = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 119 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 120 | static final boolean PROFILE_STARTUP = false; |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 121 | static final boolean DEBUG_WIDGETS = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 122 | static final boolean DEBUG_USER_INTERFACE = false; |
Romain Guy | 6fefcf1 | 2009-06-11 13:07:43 -0700 | [diff] [blame] | 123 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 124 | private static final int MENU_GROUP_ADD = 1; |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 125 | private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1; |
| 126 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 127 | private static final int MENU_ADD = Menu.FIRST + 1; |
Winson Chung | 7ad0141 | 2010-09-27 11:33:03 -0700 | [diff] [blame] | 128 | private static final int MENU_MANAGE_APPS = MENU_ADD + 1; |
| 129 | private static final int MENU_WALLPAPER_SETTINGS = MENU_MANAGE_APPS + 1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 130 | private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1; |
| 131 | private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1; |
Romain Guy | 94dabf1 | 2009-07-21 10:55:43 -0700 | [diff] [blame] | 132 | private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 133 | |
| 134 | private static final int REQUEST_CREATE_SHORTCUT = 1; |
| 135 | private static final int REQUEST_CREATE_LIVE_FOLDER = 4; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 136 | private static final int REQUEST_CREATE_APPWIDGET = 5; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 137 | private static final int REQUEST_PICK_APPLICATION = 6; |
| 138 | private static final int REQUEST_PICK_SHORTCUT = 7; |
| 139 | private static final int REQUEST_PICK_LIVE_FOLDER = 8; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 140 | private static final int REQUEST_PICK_APPWIDGET = 9; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 141 | private static final int REQUEST_PICK_WALLPAPER = 10; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 142 | |
| 143 | static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; |
| 144 | |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 145 | static final int SCREEN_COUNT = 5; |
| 146 | static final int DEFAULT_SCREEN = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 147 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 148 | static final int DIALOG_CREATE_SHORTCUT = 1; |
| 149 | static final int DIALOG_RENAME_FOLDER = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 150 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 151 | private static final String PREFERENCES = "launcher.preferences"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 152 | |
| 153 | // Type: int |
| 154 | private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 155 | // Type: int |
| 156 | private static final String RUNTIME_STATE = "launcher.state"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 157 | // Type: long |
| 158 | private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder"; |
| 159 | // Type: int |
| 160 | private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; |
| 161 | // Type: int |
| 162 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX"; |
| 163 | // Type: int |
| 164 | private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 165 | // Type: boolean |
| 166 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; |
| 167 | // Type: long |
| 168 | private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id"; |
| 169 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 170 | // tags for the customization tabs |
| 171 | private static final String WIDGETS_TAG = "widgets"; |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 172 | private static final String APPLICATIONS_TAG = "applications"; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 173 | private static final String SHORTCUTS_TAG = "shortcuts"; |
| 174 | private static final String WALLPAPERS_TAG = "wallpapers"; |
| 175 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 176 | private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon"; |
| 177 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 178 | /** The different states that Launcher can be in. */ |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 179 | private enum State { WORKSPACE, ALL_APPS, CUSTOMIZE, OVERVIEW, |
| 180 | CUSTOMIZE_SPRING_LOADED, ALL_APPS_SPRING_LOADED }; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 181 | private State mState = State.WORKSPACE; |
| 182 | private AnimatorSet mStateAnimation; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 183 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 184 | static final int APPWIDGET_HOST_ID = 1024; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 185 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 186 | private static final Object sLock = new Object(); |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 187 | private static int sScreen = DEFAULT_SCREEN; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 188 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 189 | private final BroadcastReceiver mCloseSystemDialogsReceiver |
| 190 | = new CloseSystemDialogsIntentReceiver(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 191 | private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); |
| 192 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 193 | private LayoutInflater mInflater; |
| 194 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 195 | private DragController mDragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 196 | private Workspace mWorkspace; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 197 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 198 | private AppWidgetManager mAppWidgetManager; |
| 199 | private LauncherAppWidgetHost mAppWidgetHost; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 200 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 201 | private int mAddScreen = -1; |
| 202 | private int mAddIntersectCellX = -1; |
| 203 | private int mAddIntersectCellY = -1; |
| 204 | private int[] mAddDropPosition; |
| 205 | private int[] mTmpAddItemCellCoordinates = new int[2]; |
| 206 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 207 | private FolderInfo mFolderInfo; |
| 208 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 209 | private DeleteZone mDeleteZone; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 210 | private HandleView mHandleView; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 211 | private AllAppsView mAllAppsGrid; |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 212 | private TabHost mHomeCustomizationDrawer; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 213 | private boolean mAutoAdvanceRunning = false; |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 214 | |
| 215 | private PagedView mAllAppsPagedView = null; |
| 216 | private CustomizePagedView mCustomizePagedView = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 217 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 218 | private Bundle mSavedState; |
| 219 | |
| 220 | private SpannableStringBuilder mDefaultKeySsb = null; |
| 221 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 222 | private boolean mWorkspaceLoading = true; |
| 223 | |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 224 | private boolean mPaused = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 225 | private boolean mRestoring; |
| 226 | private boolean mWaitingForResult; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 227 | private boolean mOnResumeNeedsLoad; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 228 | |
| 229 | private Bundle mSavedInstanceState; |
| 230 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 231 | private LauncherModel mModel; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 232 | private IconCache mIconCache; |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 233 | private boolean mUserPresent = true; |
| 234 | private boolean mVisible = false; |
| 235 | private boolean mAttached = false; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 236 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 237 | private static LocaleConfiguration sLocaleConfiguration = null; |
| 238 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 239 | private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>(); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 240 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 241 | private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 242 | |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 243 | private ImageView mPreviousView; |
| 244 | private ImageView mNextView; |
Joe Onorato | 080d9b6 | 2009-11-02 12:01:11 -0500 | [diff] [blame] | 245 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 246 | // Hotseats (quick-launch icons next to AllApps) |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 247 | private String[] mHotseatConfig = null; |
| 248 | private Intent[] mHotseats = null; |
| 249 | private Drawable[] mHotseatIcons = null; |
| 250 | private CharSequence[] mHotseatLabels = null; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 251 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 252 | private Intent mAppMarketIntent = null; |
| 253 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 254 | // Related to the auto-advancing of widgets |
| 255 | private final int ADVANCE_MSG = 1; |
| 256 | private final int mAdvanceInterval = 20000; |
| 257 | private final int mAdvanceStagger = 250; |
| 258 | private long mAutoAdvanceSentTime; |
| 259 | private long mAutoAdvanceTimeLeft = -1; |
| 260 | private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = |
| 261 | new HashMap<View, AppWidgetProviderInfo>(); |
| 262 | |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 263 | // External icons saved in case of resource changes, orientation, etc. |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 264 | private static Drawable.ConstantState sGlobalSearchIcon; |
| 265 | private static Drawable.ConstantState sVoiceSearchIcon; |
| 266 | private static Drawable.ConstantState sAppMarketIcon; |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 267 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 268 | @Override |
| 269 | protected void onCreate(Bundle savedInstanceState) { |
| 270 | super.onCreate(savedInstanceState); |
Romain Guy | b1b69f5 | 2009-08-10 15:10:15 -0700 | [diff] [blame] | 271 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 272 | if (LauncherApplication.isInPlaceRotationEnabled()) { |
| 273 | // hide the status bar (temporary until we get the status bar design figured out) |
| 274 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 275 | this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); |
| 276 | } |
| 277 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 278 | LauncherApplication app = ((LauncherApplication)getApplication()); |
| 279 | mModel = app.setLauncher(this); |
| 280 | mIconCache = app.getIconCache(); |
Joe Onorato | 41a12d2 | 2009-10-31 18:30:00 -0400 | [diff] [blame] | 281 | mDragController = new DragController(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 282 | mInflater = getLayoutInflater(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 283 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 284 | mAppWidgetManager = AppWidgetManager.getInstance(this); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 285 | mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); |
| 286 | mAppWidgetHost.startListening(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 287 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 288 | if (PROFILE_STARTUP) { |
Christian Mehlmauer | 0fbe7bc | 2010-08-02 20:27:46 +0200 | [diff] [blame] | 289 | android.os.Debug.startMethodTracing( |
| 290 | Environment.getExternalStorageDirectory() + "/launcher"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 291 | } |
| 292 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 293 | loadHotseats(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 294 | checkForLocaleChange(); |
| 295 | setWallpaperDimension(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 296 | setContentView(R.layout.launcher); |
Winson Chung | 8812703 | 2010-12-13 12:11:33 -0800 | [diff] [blame] | 297 | mHomeCustomizationDrawer = (TabHost) findViewById(R.id.customization_drawer); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 298 | if (mHomeCustomizationDrawer != null) { |
| 299 | mHomeCustomizationDrawer.setup(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 300 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 301 | // share the same customization workspace across all the tabs |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 302 | mCustomizePagedView = (CustomizePagedView) mInflater.inflate( |
| 303 | R.layout.customization_drawer, mHomeCustomizationDrawer, false); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 304 | TabContentFactory contentFactory = new TabContentFactory() { |
| 305 | public View createTabContent(String tag) { |
| 306 | return mCustomizePagedView; |
| 307 | } |
| 308 | }; |
| 309 | |
Winson Chung | 49767ae | 2010-11-29 14:48:30 -0800 | [diff] [blame] | 310 | |
| 311 | TextView tabView; |
| 312 | TabWidget tabWidget = (TabWidget) |
| 313 | mHomeCustomizationDrawer.findViewById(com.android.internal.R.id.tabs); |
| 314 | |
| 315 | tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); |
| 316 | tabView.setText(getString(R.string.widgets_tab_label)); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 317 | mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG) |
Winson Chung | 49767ae | 2010-11-29 14:48:30 -0800 | [diff] [blame] | 318 | .setIndicator(tabView).setContent(contentFactory)); |
| 319 | tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); |
| 320 | tabView.setText(getString(R.string.applications_tab_label)); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 321 | mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(APPLICATIONS_TAG) |
Winson Chung | 49767ae | 2010-11-29 14:48:30 -0800 | [diff] [blame] | 322 | .setIndicator(tabView).setContent(contentFactory)); |
| 323 | tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); |
| 324 | tabView.setText(getString(R.string.wallpapers_tab_label)); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 325 | mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG) |
Winson Chung | 49767ae | 2010-11-29 14:48:30 -0800 | [diff] [blame] | 326 | .setIndicator(tabView).setContent(contentFactory)); |
| 327 | tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false); |
| 328 | tabView.setText(getString(R.string.shortcuts_tab_label)); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 329 | mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG) |
Winson Chung | 49767ae | 2010-11-29 14:48:30 -0800 | [diff] [blame] | 330 | .setIndicator(tabView).setContent(contentFactory)); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 331 | mHomeCustomizationDrawer.setOnTabChangedListener(new OnTabChangeListener() { |
| 332 | public void onTabChanged(String tabId) { |
| 333 | // animate the changing of the tab content by fading pages in and out |
Winson Chung | bbc60d8 | 2010-11-11 16:34:41 -0800 | [diff] [blame] | 334 | final Resources res = getResources(); |
| 335 | final int duration = res.getInteger(R.integer.config_tabTransitionTime); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 336 | final float alpha = mCustomizePagedView.getAlpha(); |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 337 | ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mCustomizePagedView, |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 338 | "alpha", alpha, 0.0f); |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 339 | alphaAnim.setDuration(duration); |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 340 | alphaAnim.addListener(new LauncherAnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 341 | @Override |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 342 | public void onAnimationEndOrCancel(Animator animation) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 343 | String tag = mHomeCustomizationDrawer.getCurrentTabTag(); |
| 344 | if (tag == WIDGETS_TAG) { |
| 345 | mCustomizePagedView.setCustomizationFilter( |
| 346 | CustomizePagedView.CustomizationType.WidgetCustomization); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 347 | } else if (tag == APPLICATIONS_TAG) { |
| 348 | mCustomizePagedView.setCustomizationFilter( |
| 349 | CustomizePagedView.CustomizationType.ApplicationCustomization); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 350 | } else if (tag == WALLPAPERS_TAG) { |
| 351 | mCustomizePagedView.setCustomizationFilter( |
| 352 | CustomizePagedView.CustomizationType.WallpaperCustomization); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 353 | } else if (tag == SHORTCUTS_TAG) { |
| 354 | mCustomizePagedView.setCustomizationFilter( |
| 355 | CustomizePagedView.CustomizationType.ShortcutCustomization); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | final float alpha = mCustomizePagedView.getAlpha(); |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 359 | ValueAnimator alphaAnim = ObjectAnimator.ofFloat( |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame] | 360 | mCustomizePagedView, "alpha", alpha, 1.0f); |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 361 | alphaAnim.setDuration(duration); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 362 | alphaAnim.start(); |
| 363 | } |
| 364 | }); |
| 365 | alphaAnim.start(); |
| 366 | } |
| 367 | }); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 368 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 369 | setupViews(); |
| 370 | |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 371 | registerContentObservers(); |
| 372 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 373 | lockAllApps(); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 374 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 375 | mSavedState = savedInstanceState; |
| 376 | restoreState(mSavedState); |
| 377 | |
| 378 | if (PROFILE_STARTUP) { |
| 379 | android.os.Debug.stopMethodTracing(); |
| 380 | } |
| 381 | |
| 382 | if (!mRestoring) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 383 | mModel.startLoader(this, true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | // For handling default keys |
| 387 | mDefaultKeySsb = new SpannableStringBuilder(); |
| 388 | Selection.setSelection(mDefaultKeySsb, 0); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 389 | |
| 390 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 391 | registerReceiver(mCloseSystemDialogsReceiver, filter); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 392 | |
| 393 | // If we have a saved version of these external icons, we load them up immediately |
| 394 | if (LauncherApplication.isScreenXLarge()) { |
| 395 | if (sGlobalSearchIcon != null) { |
| 396 | updateGlobalSearchIcon(sGlobalSearchIcon); |
| 397 | } |
| 398 | if (sVoiceSearchIcon != null) { |
| 399 | updateVoiceSearchIcon(sVoiceSearchIcon); |
| 400 | } |
| 401 | if (sAppMarketIcon != null) { |
| 402 | updateAppMarketIcon(sAppMarketIcon); |
| 403 | } |
| 404 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 405 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 406 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 407 | private void checkForLocaleChange() { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 408 | if (sLocaleConfiguration == null) { |
| 409 | new AsyncTask<Void, Void, LocaleConfiguration>() { |
| 410 | @Override |
| 411 | protected LocaleConfiguration doInBackground(Void... unused) { |
| 412 | LocaleConfiguration localeConfiguration = new LocaleConfiguration(); |
| 413 | readConfiguration(Launcher.this, localeConfiguration); |
| 414 | return localeConfiguration; |
| 415 | } |
| 416 | |
| 417 | @Override |
| 418 | protected void onPostExecute(LocaleConfiguration result) { |
| 419 | sLocaleConfiguration = result; |
| 420 | checkForLocaleChange(); // recursive, but now with a locale configuration |
| 421 | } |
| 422 | }.execute(); |
| 423 | return; |
| 424 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 425 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 426 | final Configuration configuration = getResources().getConfiguration(); |
| 427 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 428 | final String previousLocale = sLocaleConfiguration.locale; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 429 | final String locale = configuration.locale.toString(); |
| 430 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 431 | final int previousMcc = sLocaleConfiguration.mcc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 432 | final int mcc = configuration.mcc; |
| 433 | |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 434 | final int previousMnc = sLocaleConfiguration.mnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 435 | final int mnc = configuration.mnc; |
| 436 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 437 | boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 438 | |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 439 | if (localeChanged) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 440 | sLocaleConfiguration.locale = locale; |
| 441 | sLocaleConfiguration.mcc = mcc; |
| 442 | sLocaleConfiguration.mnc = mnc; |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 443 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 444 | mIconCache.flush(); |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 445 | loadHotseats(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 446 | |
| 447 | final LocaleConfiguration localeConfiguration = sLocaleConfiguration; |
| 448 | new Thread("WriteLocaleConfiguration") { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 449 | @Override |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 450 | public void run() { |
| 451 | writeConfiguration(Launcher.this, localeConfiguration); |
| 452 | } |
| 453 | }.start(); |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | |
| 457 | private static class LocaleConfiguration { |
| 458 | public String locale; |
| 459 | public int mcc = -1; |
| 460 | public int mnc = -1; |
| 461 | } |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 462 | |
Romain Guy | 98d0165 | 2009-06-30 16:21:04 -0700 | [diff] [blame] | 463 | private static void readConfiguration(Context context, LocaleConfiguration configuration) { |
| 464 | DataInputStream in = null; |
| 465 | try { |
| 466 | in = new DataInputStream(context.openFileInput(PREFERENCES)); |
| 467 | configuration.locale = in.readUTF(); |
| 468 | configuration.mcc = in.readInt(); |
| 469 | configuration.mnc = in.readInt(); |
| 470 | } catch (FileNotFoundException e) { |
| 471 | // Ignore |
| 472 | } catch (IOException e) { |
| 473 | // Ignore |
| 474 | } finally { |
| 475 | if (in != null) { |
| 476 | try { |
| 477 | in.close(); |
| 478 | } catch (IOException e) { |
| 479 | // Ignore |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | private static void writeConfiguration(Context context, LocaleConfiguration configuration) { |
| 486 | DataOutputStream out = null; |
| 487 | try { |
| 488 | out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE)); |
| 489 | out.writeUTF(configuration.locale); |
| 490 | out.writeInt(configuration.mcc); |
| 491 | out.writeInt(configuration.mnc); |
| 492 | out.flush(); |
| 493 | } catch (FileNotFoundException e) { |
| 494 | // Ignore |
| 495 | } catch (IOException e) { |
| 496 | //noinspection ResultOfMethodCallIgnored |
| 497 | context.getFileStreamPath(PREFERENCES).delete(); |
| 498 | } finally { |
| 499 | if (out != null) { |
| 500 | try { |
| 501 | out.close(); |
| 502 | } catch (IOException e) { |
| 503 | // Ignore |
| 504 | } |
| 505 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
| 509 | static int getScreen() { |
| 510 | synchronized (sLock) { |
| 511 | return sScreen; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | static void setScreen(int screen) { |
| 516 | synchronized (sLock) { |
| 517 | sScreen = screen; |
| 518 | } |
| 519 | } |
| 520 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 521 | private void setWallpaperDimension() { |
Dianne Hackborn | 107f839 | 2009-08-05 21:32:16 -0700 | [diff] [blame] | 522 | WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 523 | |
| 524 | Display display = getWindowManager().getDefaultDisplay(); |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 525 | // TODO: Put back when we decide about scrolling the wallpaper |
| 526 | // boolean isPortrait = display.getWidth() < display.getHeight(); |
| 527 | // final int width = isPortrait ? display.getWidth() : display.getHeight(); |
| 528 | // final int height = isPortrait ? display.getHeight() : display.getWidth(); |
| 529 | wpm.suggestDesiredDimensions(Math.max(display.getWidth(), display.getHeight()), |
| 530 | Math.max(display.getWidth(), display.getHeight())); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 531 | } |
| 532 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 533 | // Note: This doesn't do all the client-id magic that BrowserProvider does |
| 534 | // in Browser. (http://b/2425179) |
| 535 | private Uri getDefaultBrowserUri() { |
| 536 | String url = getString(R.string.default_browser_url); |
| 537 | if (url.indexOf("{CID}") != -1) { |
| 538 | url = url.replace("{CID}", "android-google"); |
| 539 | } |
| 540 | return Uri.parse(url); |
| 541 | } |
| 542 | |
| 543 | // Load the Intent templates from arrays.xml to populate the hotseats. For |
| 544 | // each Intent, if it resolves to a single app, use that as the launch |
| 545 | // intent & use that app's label as the contentDescription. Otherwise, |
| 546 | // retain the ResolveActivity so the user can pick an app. |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 547 | private void loadHotseats() { |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 548 | if (mHotseatConfig == null) { |
| 549 | mHotseatConfig = getResources().getStringArray(R.array.hotseats); |
| 550 | if (mHotseatConfig.length > 0) { |
| 551 | mHotseats = new Intent[mHotseatConfig.length]; |
| 552 | mHotseatLabels = new CharSequence[mHotseatConfig.length]; |
| 553 | mHotseatIcons = new Drawable[mHotseatConfig.length]; |
| 554 | } else { |
| 555 | mHotseats = null; |
| 556 | mHotseatIcons = null; |
| 557 | mHotseatLabels = null; |
| 558 | } |
| 559 | |
| 560 | TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons); |
| 561 | for (int i=0; i<mHotseatConfig.length; i++) { |
| 562 | // load icon for this slot; currently unrelated to the actual activity |
| 563 | try { |
| 564 | mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i); |
| 565 | } catch (ArrayIndexOutOfBoundsException ex) { |
| 566 | Log.w(TAG, "Missing hotseat_icons array item #" + i); |
| 567 | mHotseatIcons[i] = null; |
| 568 | } |
| 569 | } |
| 570 | hotseatIconDrawables.recycle(); |
| 571 | } |
| 572 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 573 | PackageManager pm = getPackageManager(); |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 574 | for (int i=0; i<mHotseatConfig.length; i++) { |
| 575 | Intent intent = null; |
| 576 | if (mHotseatConfig[i].equals("*BROWSER*")) { |
| 577 | // magic value meaning "launch user's default web browser" |
| 578 | // replace it with a generic web request so we can see if there is indeed a default |
| 579 | String defaultUri = getString(R.string.default_browser_url); |
| 580 | intent = new Intent( |
| 581 | Intent.ACTION_VIEW, |
| 582 | ((defaultUri != null) |
| 583 | ? Uri.parse(defaultUri) |
| 584 | : getDefaultBrowserUri()) |
| 585 | ).addCategory(Intent.CATEGORY_BROWSABLE); |
| 586 | // note: if the user launches this without a default set, she |
| 587 | // will always be taken to the default URL above; this is |
| 588 | // unavoidable as we must specify a valid URL in order for the |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 589 | // chooser to appear, and once the user selects something, that |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 590 | // URL is unavoidably sent to the chosen app. |
| 591 | } else { |
| 592 | try { |
| 593 | intent = Intent.parseUri(mHotseatConfig[i], 0); |
| 594 | } catch (java.net.URISyntaxException ex) { |
| 595 | Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]); |
| 596 | // bogus; leave intent=null |
| 597 | } |
| 598 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 599 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 600 | if (intent == null) { |
| 601 | mHotseats[i] = null; |
| 602 | mHotseatLabels[i] = getText(R.string.activity_not_found); |
| 603 | continue; |
| 604 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 605 | |
| 606 | if (LOGD) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 607 | Log.d(TAG, "loadHotseats: hotseat " + i |
| 608 | + " initial intent=[" |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 609 | + intent.toUri(Intent.URI_INTENT_SCHEME) |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 610 | + "]"); |
| 611 | } |
| 612 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 613 | ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); |
| 614 | List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 615 | if (LOGD) { |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 616 | Log.d(TAG, "Best match for intent: " + bestMatch); |
| 617 | Log.d(TAG, "All matches: "); |
| 618 | for (ResolveInfo ri : allMatches) { |
| 619 | Log.d(TAG, " --> " + ri); |
| 620 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 621 | } |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 622 | // did this resolve to a single app, or the resolver? |
| 623 | if (allMatches.size() == 0 || bestMatch == null) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 624 | // can't find any activity to handle this. let's leave the |
| 625 | // intent as-is and let Launcher show a toast when it fails |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 626 | // to launch. |
| 627 | mHotseats[i] = intent; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 628 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 629 | // set accessibility text to "Not installed" |
| 630 | mHotseatLabels[i] = getText(R.string.activity_not_found); |
| 631 | } else { |
| 632 | boolean found = false; |
| 633 | for (ResolveInfo ri : allMatches) { |
| 634 | if (bestMatch.activityInfo.name.equals(ri.activityInfo.name) |
| 635 | && bestMatch.activityInfo.applicationInfo.packageName |
| 636 | .equals(ri.activityInfo.applicationInfo.packageName)) { |
| 637 | found = true; |
| 638 | break; |
| 639 | } |
| 640 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 641 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 642 | if (!found) { |
| 643 | if (LOGD) Log.d(TAG, "Multiple options, no default yet"); |
| 644 | // the bestMatch is probably the ResolveActivity, meaning the |
| 645 | // user has not yet selected a default |
| 646 | // so: we'll keep the original intent for now |
| 647 | mHotseats[i] = intent; |
| 648 | |
| 649 | // set the accessibility text to "Select shortcut" |
| 650 | mHotseatLabels[i] = getText(R.string.title_select_shortcut); |
| 651 | } else { |
| 652 | // we have an app! |
| 653 | // now reconstruct the intent to launch it through the front |
| 654 | // door |
| 655 | ComponentName com = new ComponentName( |
| 656 | bestMatch.activityInfo.applicationInfo.packageName, |
| 657 | bestMatch.activityInfo.name); |
| 658 | mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com); |
| 659 | |
| 660 | // load the app label for accessibility |
| 661 | mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm); |
| 662 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | if (LOGD) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 666 | Log.d(TAG, "loadHotseats: hotseat " + i |
| 667 | + " final intent=[" |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 668 | + ((mHotseats[i] == null) |
| 669 | ? "null" |
| 670 | : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME)) |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 671 | + "] label=[" + mHotseatLabels[i] |
| 672 | + "]" |
| 673 | ); |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 678 | @Override |
| 679 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
Romain Guy | aad5ef4 | 2009-06-10 02:48:37 -0700 | [diff] [blame] | 680 | mWaitingForResult = false; |
| 681 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 682 | // The pattern used here is that a user PICKs a specific application, |
| 683 | // which, depending on the target, might need to CREATE the actual target. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 684 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 685 | // For example, the user would PICK_SHORTCUT for "Music playlist", and we |
| 686 | // launch over to the Music app to actually CREATE_SHORTCUT. |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 687 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 688 | if (resultCode == RESULT_OK && mAddScreen != -1) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 689 | switch (requestCode) { |
| 690 | case REQUEST_PICK_APPLICATION: |
Michael Jurka | 28750fb | 2010-09-24 17:43:49 -0700 | [diff] [blame] | 691 | completeAddApplication( |
| 692 | this, data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 693 | break; |
| 694 | case REQUEST_PICK_SHORTCUT: |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 695 | processShortcut(data); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 696 | break; |
| 697 | case REQUEST_CREATE_SHORTCUT: |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 698 | completeAddShortcut(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 699 | break; |
| 700 | case REQUEST_PICK_LIVE_FOLDER: |
| 701 | addLiveFolder(data); |
| 702 | break; |
| 703 | case REQUEST_CREATE_LIVE_FOLDER: |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 704 | completeAddLiveFolder(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 705 | break; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 706 | case REQUEST_PICK_APPWIDGET: |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 707 | addAppWidgetFromPick(data); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 708 | break; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 709 | case REQUEST_CREATE_APPWIDGET: |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 710 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 711 | completeAddAppWidget(appWidgetId, mAddScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 712 | break; |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 713 | case REQUEST_PICK_WALLPAPER: |
| 714 | // We just wanted the activity result here so we can clear mWaitingForResult |
| 715 | break; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 716 | } |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 717 | } else if ((requestCode == REQUEST_PICK_APPWIDGET || |
| 718 | requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED && |
| 719 | data != null) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 720 | // Clean up the appWidgetId if we canceled |
| 721 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
| 722 | if (appWidgetId != -1) { |
| 723 | mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 724 | } |
| 725 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | @Override |
| 729 | protected void onResume() { |
| 730 | super.onResume(); |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 731 | mPaused = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 732 | if (mRestoring || mOnResumeNeedsLoad) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 733 | mWorkspaceLoading = true; |
| 734 | mModel.startLoader(this, true); |
| 735 | mRestoring = false; |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 736 | mOnResumeNeedsLoad = false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 737 | } |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 738 | // When we resume Launcher, a different Activity might be responsible for the app |
| 739 | // market intent, so refresh the icon |
| 740 | updateAppMarketIcon(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | @Override |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 744 | protected void onPause() { |
| 745 | super.onPause(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 746 | // Some launcher layouts don't have a previous and next view |
| 747 | if (mPreviousView != null) { |
| 748 | dismissPreview(mPreviousView); |
Patrick Dubroy | ab962b7 | 2010-07-26 12:10:10 -0700 | [diff] [blame] | 749 | } |
| 750 | if (mNextView != null) { |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 751 | dismissPreview(mNextView); |
| 752 | } |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 753 | mPaused = true; |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 754 | mDragController.cancelDrag(); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 755 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 756 | |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 757 | @Override |
| 758 | public Object onRetainNonConfigurationInstance() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 759 | // Flag the loader to stop early before switching |
| 760 | mModel.stopLoader(); |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 761 | mAllAppsGrid.surrender(); |
Romain Guy | 13c2e7b | 2010-03-10 19:45:00 -0800 | [diff] [blame] | 762 | return Boolean.TRUE; |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 763 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 764 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 765 | // We can't hide the IME if it was forced open. So don't bother |
| 766 | /* |
| 767 | @Override |
| 768 | public void onWindowFocusChanged(boolean hasFocus) { |
| 769 | super.onWindowFocusChanged(hasFocus); |
| 770 | |
| 771 | if (hasFocus) { |
| 772 | final InputMethodManager inputManager = (InputMethodManager) |
| 773 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 774 | WindowManager.LayoutParams lp = getWindow().getAttributes(); |
| 775 | inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new |
| 776 | android.os.Handler()) { |
| 777 | protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 778 | Log.d(TAG, "ResultReceiver got resultCode=" + resultCode); |
| 779 | } |
| 780 | }); |
| 781 | Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged"); |
| 782 | } |
| 783 | } |
| 784 | */ |
| 785 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 786 | private boolean acceptFilter() { |
| 787 | final InputMethodManager inputManager = (InputMethodManager) |
| 788 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 789 | return !inputManager.isFullscreenMode(); |
| 790 | } |
| 791 | |
| 792 | @Override |
| 793 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 794 | boolean handled = super.onKeyDown(keyCode, event); |
| 795 | if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) { |
| 796 | boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, |
| 797 | keyCode, event); |
| 798 | if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 799 | // something usable has been typed - start a search |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 800 | // the typed text will be retrieved and cleared by |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 801 | // showSearchDialog() |
| 802 | // If there are multiple keystrokes before the search dialog takes focus, |
| 803 | // onSearchRequested() will be called for every keystroke, |
| 804 | // but it is idempotent, so it's fine. |
| 805 | return onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | |
Joe Onorato | 8a9625e | 2010-01-28 15:55:35 -0800 | [diff] [blame] | 809 | // Eat the long press event so the keyboard doesn't come up. |
| 810 | if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { |
| 811 | return true; |
| 812 | } |
| 813 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 814 | return handled; |
| 815 | } |
| 816 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 817 | private String getTypedText() { |
| 818 | return mDefaultKeySsb.toString(); |
| 819 | } |
| 820 | |
| 821 | private void clearTypedText() { |
| 822 | mDefaultKeySsb.clear(); |
| 823 | mDefaultKeySsb.clearSpans(); |
| 824 | Selection.setSelection(mDefaultKeySsb, 0); |
| 825 | } |
| 826 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 827 | /** |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 828 | * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type |
| 829 | * State |
| 830 | */ |
| 831 | private static State intToState(int stateOrdinal) { |
| 832 | State state = State.WORKSPACE; |
| 833 | final State[] stateValues = State.values(); |
| 834 | for (int i = 0; i < stateValues.length; i++) { |
| 835 | if (stateValues[i].ordinal() == stateOrdinal) { |
| 836 | state = stateValues[i]; |
| 837 | break; |
| 838 | } |
| 839 | } |
| 840 | return state; |
| 841 | } |
| 842 | |
| 843 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 844 | * Restores the previous state, if it exists. |
| 845 | * |
| 846 | * @param savedState The previous state. |
| 847 | */ |
| 848 | private void restoreState(Bundle savedState) { |
| 849 | if (savedState == null) { |
| 850 | return; |
| 851 | } |
| 852 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 853 | State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal())); |
| 854 | |
| 855 | if (state == State.ALL_APPS) { |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 856 | showAllApps(false); |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 857 | } else if (state == State.CUSTOMIZE) { |
| 858 | showCustomizationDrawer(false); |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 859 | } |
| 860 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 861 | final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1); |
| 862 | if (currentScreen > -1) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 863 | mWorkspace.setCurrentPage(currentScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 867 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 868 | if (addScreen > -1) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 869 | mAddScreen = addScreen; |
| 870 | mAddIntersectCellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); |
| 871 | mAddIntersectCellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 872 | mRestoring = true; |
| 873 | } |
| 874 | |
| 875 | boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); |
| 876 | if (renameFolder) { |
| 877 | long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 878 | mFolderInfo = mModel.getFolderById(this, sFolders, id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 879 | mRestoring = true; |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | /** |
| 884 | * Finds all the views we need and configure them properly. |
| 885 | */ |
| 886 | private void setupViews() { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 887 | final DragController dragController = mDragController; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 888 | |
Romain Guy | b1b69f5 | 2009-08-10 15:10:15 -0700 | [diff] [blame] | 889 | DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 890 | dragLayer.setDragController(dragController); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 891 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 892 | mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 893 | mAllAppsGrid.setLauncher(this); |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 894 | mAllAppsGrid.setDragController(dragController); |
Romain Guy | c16fea7 | 2010-03-12 17:17:56 -0800 | [diff] [blame] | 895 | ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 896 | // Manage focusability manually since this thing is always visible (in non-xlarge) |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 897 | ((View) mAllAppsGrid).setFocusable(false); |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 898 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 899 | if (LauncherApplication.isScreenXLarge()) { |
| 900 | // They need to be INVISIBLE initially so that they will be measured in the layout. |
| 901 | // Otherwise the animations are messed up when we show them for the first time. |
| 902 | ((View) mAllAppsGrid).setVisibility(View.INVISIBLE); |
| 903 | mHomeCustomizationDrawer.setVisibility(View.INVISIBLE); |
| 904 | } |
| 905 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 906 | mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 907 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 908 | final Workspace workspace = mWorkspace; |
Joe Onorato | f0dde09 | 2010-02-16 18:25:23 -0500 | [diff] [blame] | 909 | workspace.setHapticFeedbackEnabled(false); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 910 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 911 | DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone); |
| 912 | mDeleteZone = deleteZone; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 913 | |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 914 | View handleView = findViewById(R.id.all_apps_button); |
| 915 | if (handleView != null && handleView instanceof HandleView) { |
| 916 | // we don't use handle view in xlarge mode |
Michael Jurka | 7ef4f75 | 2010-08-03 16:04:26 -0700 | [diff] [blame] | 917 | mHandleView = (HandleView)handleView; |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 918 | mHandleView.setLauncher(this); |
| 919 | mHandleView.setOnClickListener(this); |
| 920 | mHandleView.setOnLongClickListener(this); |
| 921 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 922 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 923 | if (mCustomizePagedView != null) { |
| 924 | mCustomizePagedView.setLauncher(this); |
| 925 | mCustomizePagedView.setDragController(dragController); |
| 926 | mCustomizePagedView.update(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 927 | } else { |
| 928 | ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left); |
| 929 | hotseatLeft.setContentDescription(mHotseatLabels[0]); |
| 930 | hotseatLeft.setImageDrawable(mHotseatIcons[0]); |
| 931 | ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right); |
| 932 | hotseatRight.setContentDescription(mHotseatLabels[1]); |
| 933 | hotseatRight.setImageDrawable(mHotseatIcons[1]); |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 934 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 935 | mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen); |
| 936 | mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 937 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 938 | Drawable previous = mPreviousView.getDrawable(); |
| 939 | Drawable next = mNextView.getDrawable(); |
| 940 | mWorkspace.setIndicators(previous, next); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 941 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 942 | mPreviousView.setHapticFeedbackEnabled(false); |
| 943 | mPreviousView.setOnLongClickListener(this); |
| 944 | mNextView.setHapticFeedbackEnabled(false); |
| 945 | mNextView.setOnLongClickListener(this); |
| 946 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 947 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 948 | workspace.setOnLongClickListener(this); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 949 | workspace.setDragController(dragController); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 950 | workspace.setLauncher(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 951 | |
| 952 | deleteZone.setLauncher(this); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 953 | deleteZone.setDragController(dragController); |
Michael Jurka | 54f7ac3 | 2010-08-02 13:56:46 -0700 | [diff] [blame] | 954 | int deleteZoneHandleId; |
| 955 | if (LauncherApplication.isScreenXLarge()) { |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 956 | deleteZoneHandleId = R.id.all_apps_button; |
Michael Jurka | 54f7ac3 | 2010-08-02 13:56:46 -0700 | [diff] [blame] | 957 | } else { |
| 958 | deleteZoneHandleId = R.id.all_apps_button_cluster; |
| 959 | } |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 960 | deleteZone.setHandle(findViewById(deleteZoneHandleId)); |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 961 | dragController.addDragListener(deleteZone); |
| 962 | |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 963 | DeleteZone allAppsDeleteZone = (DeleteZone) findViewById(R.id.all_apps_delete_zone); |
| 964 | if (allAppsDeleteZone != null) { |
| 965 | allAppsDeleteZone.setLauncher(this); |
| 966 | allAppsDeleteZone.setDragController(dragController); |
| 967 | allAppsDeleteZone.setDragAndDropEnabled(false); |
| 968 | dragController.addDragListener(allAppsDeleteZone); |
| 969 | dragController.addDropTarget(allAppsDeleteZone); |
| 970 | } |
| 971 | |
| 972 | ApplicationInfoDropTarget allAppsInfoTarget = (ApplicationInfoDropTarget) |
| 973 | findViewById(R.id.all_apps_info_target); |
| 974 | if (allAppsInfoTarget != null) { |
| 975 | allAppsInfoTarget.setLauncher(this); |
| 976 | dragController.addDragListener(allAppsInfoTarget); |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 977 | allAppsInfoTarget.setDragAndDropEnabled(false); |
| 978 | View marketButton = findViewById(R.id.market_button); |
| 979 | if (marketButton != null) { |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 980 | allAppsInfoTarget.setHandle(marketButton); |
| 981 | } |
| 982 | } |
| 983 | |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 984 | ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button); |
| 985 | if (infoButton != null) { |
| 986 | infoButton.setLauncher(this); |
| 987 | infoButton.setHandle(findViewById(R.id.configure_button)); |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 988 | dragController.addDragListener(infoButton); |
| 989 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 990 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 991 | dragController.setDragScoller(workspace); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 992 | dragController.setScrollView(dragLayer); |
Romain Guy | ea3763c | 2010-01-11 18:02:04 -0800 | [diff] [blame] | 993 | dragController.setMoveTarget(workspace); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 994 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 995 | // The order here is bottom to top. |
| 996 | dragController.addDropTarget(workspace); |
| 997 | dragController.addDropTarget(deleteZone); |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 998 | if (infoButton != null) { |
| 999 | dragController.addDropTarget(infoButton); |
| 1000 | } |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 1001 | if (allAppsInfoTarget != null) { |
| 1002 | dragController.addDropTarget(allAppsInfoTarget); |
| 1003 | } |
| 1004 | if (allAppsDeleteZone != null) { |
| 1005 | dragController.addDropTarget(allAppsDeleteZone); |
| 1006 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1007 | } |
| 1008 | |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 1009 | @SuppressWarnings({"UnusedDeclaration"}) |
| 1010 | public void previousScreen(View v) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1011 | if (mState != State.ALL_APPS) { |
Joe Onorato | 61597bd | 2009-11-19 12:51:57 -0800 | [diff] [blame] | 1012 | mWorkspace.scrollLeft(); |
| 1013 | } |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | @SuppressWarnings({"UnusedDeclaration"}) |
| 1017 | public void nextScreen(View v) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1018 | if (mState != State.ALL_APPS) { |
Joe Onorato | 61597bd | 2009-11-19 12:51:57 -0800 | [diff] [blame] | 1019 | mWorkspace.scrollRight(); |
| 1020 | } |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 1021 | } |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 1022 | |
| 1023 | @SuppressWarnings({"UnusedDeclaration"}) |
| 1024 | public void launchHotSeat(View v) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1025 | if (mState == State.ALL_APPS) return; |
Daniel Sandler | 3e9454a | 2010-05-24 11:22:41 -0400 | [diff] [blame] | 1026 | |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 1027 | int index = -1; |
| 1028 | if (v.getId() == R.id.hotseat_left) { |
| 1029 | index = 0; |
| 1030 | } else if (v.getId() == R.id.hotseat_right) { |
| 1031 | index = 1; |
| 1032 | } |
| 1033 | |
Daniel Sandler | ab1ebd7 | 2010-04-27 16:57:25 -0400 | [diff] [blame] | 1034 | // reload these every tap; you never know when they might change |
| 1035 | loadHotseats(); |
| 1036 | if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) { |
| 1037 | Intent intent = mHotseats[index]; |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 1038 | startActivitySafely( |
| 1039 | mHotseats[index], |
| 1040 | "hotseat" |
| 1041 | ); |
| 1042 | } |
| 1043 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1044 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1045 | /** |
| 1046 | * Creates a view representing a shortcut. |
| 1047 | * |
| 1048 | * @param info The data structure describing the shortcut. |
| 1049 | * |
| 1050 | * @return A View inflated from R.layout.application. |
| 1051 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1052 | View createShortcut(ShortcutInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1053 | return createShortcut(R.layout.application, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1054 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | /** |
| 1058 | * Creates a view representing a shortcut inflated from the specified resource. |
| 1059 | * |
| 1060 | * @param layoutResId The id of the XML layout used to create the shortcut. |
| 1061 | * @param parent The group the shortcut belongs to. |
| 1062 | * @param info The data structure describing the shortcut. |
| 1063 | * |
| 1064 | * @return A View inflated from layoutResId. |
| 1065 | */ |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1066 | View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { |
Michael Jurka | 67b2f6c | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 1067 | BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); |
| 1068 | favorite.applyFromShortcutInfo(info, mIconCache); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1069 | favorite.setOnClickListener(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1070 | return favorite; |
| 1071 | } |
| 1072 | |
| 1073 | /** |
| 1074 | * Add an application shortcut to the workspace. |
| 1075 | * |
| 1076 | * @param data The intent describing the application. |
| 1077 | * @param cellInfo The position on screen where to create the shortcut. |
| 1078 | */ |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1079 | void completeAddApplication(Context context, Intent data, int screen, |
| 1080 | int intersectCellX, int intersectCellY) { |
| 1081 | final int[] cellXY = mTmpAddItemCellCoordinates; |
| 1082 | final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1083 | |
| 1084 | if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) { |
| 1085 | showOutOfSpaceMessage(); |
| 1086 | return; |
| 1087 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1088 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1089 | final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(), |
| 1090 | data, context); |
| 1091 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 1092 | if (info != null) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1093 | info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1094 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1095 | info.container = ItemInfo.NO_ID; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1096 | mWorkspace.addApplicationShortcut(info, screen, cellXY[0], cellXY[1], |
| 1097 | isWorkspaceLocked(), mAddIntersectCellX, mAddIntersectCellY); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1098 | } else { |
| 1099 | 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] | 1100 | } |
| 1101 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1102 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1103 | /** |
| 1104 | * Add a shortcut to the workspace. |
| 1105 | * |
| 1106 | * @param data The intent describing the shortcut. |
| 1107 | * @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] | 1108 | */ |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1109 | private void completeAddShortcut(Intent data, int screen, |
| 1110 | int intersectCellX, int intersectCellY) { |
| 1111 | final int[] cellXY = mTmpAddItemCellCoordinates; |
| 1112 | final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1113 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1114 | int[] touchXY = null; |
| 1115 | if (mAddDropPosition != null && mAddDropPosition[0] > -1 && mAddDropPosition[1] > -1) { |
| 1116 | touchXY = mAddDropPosition; |
| 1117 | } |
| 1118 | boolean foundCellSpan = false; |
| 1119 | if (touchXY != null) { |
| 1120 | // when dragging and dropping, just find the closest free spot |
| 1121 | CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1122 | int[] result = screenLayout.findNearestVacantArea( |
| 1123 | touchXY[0], touchXY[1], 1, 1, cellXY); |
| 1124 | foundCellSpan = (result != null); |
| 1125 | } else { |
| 1126 | foundCellSpan = layout.findCellForSpanThatIntersects( |
| 1127 | cellXY, 1, 1, intersectCellX, intersectCellY); |
| 1128 | } |
| 1129 | |
| 1130 | if (!foundCellSpan) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1131 | showOutOfSpaceMessage(); |
| 1132 | return; |
| 1133 | } |
| 1134 | |
| 1135 | final ShortcutInfo info = mModel.addShortcut( |
| 1136 | this, data, screen, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1137 | |
| 1138 | if (!mRestoring) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1139 | final View view = createShortcut(info); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1140 | mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1141 | } |
| 1142 | } |
| 1143 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1144 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1145 | * Add a widget to the workspace. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1146 | * |
Romain Guy | 5bbc91b | 2010-08-18 11:38:46 -0700 | [diff] [blame] | 1147 | * @param appWidgetId The app widget id |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1148 | * @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] | 1149 | */ |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1150 | private void completeAddAppWidget(int appWidgetId, int screen) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1151 | AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1152 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1153 | // Calculate the grid spans needed to fit this widget |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1154 | CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1155 | int[] spanXY = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1156 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1157 | // Try finding open space on Launcher screen |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1158 | // We have saved the position to which the widget was dragged-- this really only matters |
| 1159 | // if we are placing widgets on a "spring-loaded" screen |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1160 | final int[] cellXY = mTmpAddItemCellCoordinates; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1161 | |
| 1162 | // For now, we don't save the coordinate where we dropped the icon because we're not |
| 1163 | // supporting spring-loaded mini-screens; however, leaving the ability to directly place |
| 1164 | // a widget on the home screen in case we want to add it in the future |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1165 | int[] touchXY = null; |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1166 | if (mAddDropPosition != null && mAddDropPosition[0] > -1 && mAddDropPosition[1] > -1) { |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1167 | touchXY = mAddDropPosition; |
| 1168 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1169 | boolean foundCellSpan = false; |
| 1170 | if (touchXY != null) { |
| 1171 | // when dragging and dropping, just find the closest free spot |
| 1172 | CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1173 | int[] result = screenLayout.findNearestVacantArea( |
| 1174 | touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1175 | foundCellSpan = (result != null); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1176 | } else { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1177 | // if we long pressed on an empty cell to bring up a menu, |
| 1178 | // make sure we intersect the empty cell |
| 1179 | // if mAddIntersectCellX/Y are -1 (e.g. we used menu -> add) then |
| 1180 | // findCellForSpanThatIntersects will just ignore them |
| 1181 | foundCellSpan = layout.findCellForSpanThatIntersects(cellXY, spanXY[0], spanXY[1], |
| 1182 | mAddIntersectCellX, mAddIntersectCellY); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1185 | if (!foundCellSpan) { |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 1186 | if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1187 | showOutOfSpaceMessage(); |
Romain Guy | 18042c8 | 2009-11-06 11:44:55 -0800 | [diff] [blame] | 1188 | return; |
| 1189 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1190 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1191 | // Build Launcher-specific widget info and save to database |
| 1192 | LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1193 | launcherInfo.spanX = spanXY[0]; |
| 1194 | launcherInfo.spanY = spanXY[1]; |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1195 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1196 | LauncherModel.addItemToDatabase(this, launcherInfo, |
| 1197 | LauncherSettings.Favorites.CONTAINER_DESKTOP, |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1198 | screen, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1199 | |
| 1200 | if (!mRestoring) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1201 | mDesktopItems.add(launcherInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1202 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1203 | // Perform actual inflation because we're live |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1204 | launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1205 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1206 | launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1207 | launcherInfo.hostView.setTag(launcherInfo); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1208 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1209 | mWorkspace.addInScreen(launcherInfo.hostView, screen, cellXY[0], cellXY[1], |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1210 | launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1211 | |
| 1212 | addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1213 | } |
| 1214 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1215 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1216 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 1217 | @Override |
| 1218 | public void onReceive(Context context, Intent intent) { |
| 1219 | final String action = intent.getAction(); |
| 1220 | if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1221 | mUserPresent = false; |
| 1222 | updateRunning(); |
| 1223 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 1224 | mUserPresent = true; |
| 1225 | updateRunning(); |
| 1226 | } |
| 1227 | } |
| 1228 | }; |
| 1229 | |
| 1230 | @Override |
| 1231 | public void onAttachedToWindow() { |
| 1232 | super.onAttachedToWindow(); |
| 1233 | |
| 1234 | // Listen for broadcasts related to user-presence |
| 1235 | final IntentFilter filter = new IntentFilter(); |
| 1236 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 1237 | filter.addAction(Intent.ACTION_USER_PRESENT); |
| 1238 | registerReceiver(mReceiver, filter); |
| 1239 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1240 | mAttached = true; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1241 | mVisible = true; |
| 1242 | } |
| 1243 | |
| 1244 | @Override |
| 1245 | public void onDetachedFromWindow() { |
| 1246 | super.onDetachedFromWindow(); |
| 1247 | mVisible = false; |
| 1248 | |
Adam Cohen | d113e0c | 2010-11-11 10:48:05 -0800 | [diff] [blame] | 1249 | if (mAttached) { |
| 1250 | unregisterReceiver(mReceiver); |
| 1251 | mAttached = false; |
| 1252 | } |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1253 | updateRunning(); |
| 1254 | } |
| 1255 | |
| 1256 | public void onWindowVisibilityChanged(int visibility) { |
| 1257 | mVisible = visibility == View.VISIBLE; |
| 1258 | updateRunning(); |
| 1259 | } |
| 1260 | |
| 1261 | private void sendAdvanceMessage(long delay) { |
| 1262 | mHandler.removeMessages(ADVANCE_MSG); |
| 1263 | Message msg = mHandler.obtainMessage(ADVANCE_MSG); |
| 1264 | mHandler.sendMessageDelayed(msg, delay); |
| 1265 | mAutoAdvanceSentTime = System.currentTimeMillis(); |
| 1266 | } |
| 1267 | |
| 1268 | private void updateRunning() { |
| 1269 | boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty(); |
| 1270 | if (autoAdvanceRunning != mAutoAdvanceRunning) { |
| 1271 | mAutoAdvanceRunning = autoAdvanceRunning; |
| 1272 | if (autoAdvanceRunning) { |
| 1273 | long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft; |
| 1274 | sendAdvanceMessage(delay); |
| 1275 | } else { |
| 1276 | if (!mWidgetsToAdvance.isEmpty()) { |
| 1277 | mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval - |
| 1278 | (System.currentTimeMillis() - mAutoAdvanceSentTime)); |
| 1279 | } |
| 1280 | mHandler.removeMessages(ADVANCE_MSG); |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | private final Handler mHandler = new Handler() { |
| 1286 | @Override |
| 1287 | public void handleMessage(Message msg) { |
| 1288 | if (msg.what == ADVANCE_MSG) { |
| 1289 | int i = 0; |
| 1290 | for (View key: mWidgetsToAdvance.keySet()) { |
| 1291 | final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId); |
| 1292 | final int delay = mAdvanceStagger * i; |
| 1293 | if (v instanceof Advanceable) { |
| 1294 | postDelayed(new Runnable() { |
| 1295 | public void run() { |
| 1296 | ((Advanceable) v).advance(); |
| 1297 | } |
| 1298 | }, delay); |
| 1299 | } |
| 1300 | i++; |
| 1301 | } |
| 1302 | sendAdvanceMessage(mAdvanceInterval); |
| 1303 | } |
| 1304 | } |
| 1305 | }; |
| 1306 | |
| 1307 | void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) { |
| 1308 | if (appWidgetInfo.autoAdvanceViewId == -1) return; |
| 1309 | View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId); |
| 1310 | if (v instanceof Advanceable) { |
| 1311 | mWidgetsToAdvance.put(hostView, appWidgetInfo); |
| 1312 | ((Advanceable) v).willBeAdvancedByHost(); |
| 1313 | updateRunning(); |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | void removeWidgetToAutoAdvance(View hostView) { |
| 1318 | if (mWidgetsToAdvance.containsKey(hostView)) { |
| 1319 | mWidgetsToAdvance.remove(hostView); |
| 1320 | updateRunning(); |
| 1321 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1324 | public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { |
| 1325 | mDesktopItems.remove(launcherInfo); |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1326 | removeWidgetToAutoAdvance(launcherInfo.hostView); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1327 | launcherInfo.hostView = null; |
| 1328 | } |
| 1329 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1330 | void showOutOfSpaceMessage() { |
| 1331 | Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show(); |
| 1332 | } |
| 1333 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1334 | public LauncherAppWidgetHost getAppWidgetHost() { |
| 1335 | return mAppWidgetHost; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1336 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1337 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 1338 | public LauncherModel getModel() { |
| 1339 | return mModel; |
| 1340 | } |
| 1341 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1342 | void closeSystemDialogs() { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1343 | getWindow().closeAllPanels(); |
| 1344 | |
| 1345 | try { |
| 1346 | dismissDialog(DIALOG_CREATE_SHORTCUT); |
| 1347 | // Unlock the workspace if the dialog was showing |
| 1348 | } catch (Exception e) { |
| 1349 | // An exception is thrown if the dialog is not visible, which is fine |
| 1350 | } |
| 1351 | |
| 1352 | try { |
| 1353 | dismissDialog(DIALOG_RENAME_FOLDER); |
| 1354 | // Unlock the workspace if the dialog was showing |
| 1355 | } catch (Exception e) { |
| 1356 | // An exception is thrown if the dialog is not visible, which is fine |
| 1357 | } |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1358 | |
| 1359 | // Whatever we were doing is hereby canceled. |
| 1360 | mWaitingForResult = false; |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1361 | } |
| 1362 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1363 | @Override |
| 1364 | protected void onNewIntent(Intent intent) { |
| 1365 | super.onNewIntent(intent); |
| 1366 | |
| 1367 | // Close the menu |
| 1368 | if (Intent.ACTION_MAIN.equals(intent.getAction())) { |
Joe Onorato | a5c32d6 | 2009-11-19 10:28:49 -0800 | [diff] [blame] | 1369 | // also will cancel mWaitingForResult. |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1370 | closeSystemDialogs(); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 1371 | |
Joe Onorato | 14f122b | 2009-11-19 14:06:36 -0800 | [diff] [blame] | 1372 | boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) |
| 1373 | != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); |
Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1374 | |
Michael Jurka | 4cb3724 | 2010-08-09 21:05:32 -0700 | [diff] [blame] | 1375 | // in all these cases, only animate if we're already on home |
| 1376 | if (LauncherApplication.isScreenXLarge()) { |
Michael Jurka | 99229f6 | 2010-09-09 11:49:32 -0700 | [diff] [blame] | 1377 | mWorkspace.unshrink(alreadyOnHome); |
| 1378 | } |
| 1379 | if (!mWorkspace.isDefaultPageShowing()) { |
Michael Jurka | 4cb3724 | 2010-08-09 21:05:32 -0700 | [diff] [blame] | 1380 | // on the phone, we don't animate the change to the workspace if all apps is visible |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1381 | mWorkspace.moveToDefaultScreen(alreadyOnHome && |
| 1382 | (LauncherApplication.isScreenXLarge() || mState != State.ALL_APPS)); |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1383 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1384 | showWorkspace(alreadyOnHome); |
Romain Guy | 1dd3a07 | 2009-07-16 13:21:01 -0700 | [diff] [blame] | 1385 | |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1386 | final View v = getWindow().peekDecorView(); |
| 1387 | if (v != null && v.getWindowToken() != null) { |
| 1388 | InputMethodManager imm = (InputMethodManager)getSystemService( |
| 1389 | INPUT_METHOD_SERVICE); |
| 1390 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1391 | } |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | @Override |
| 1396 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 1397 | // Do not call super here |
| 1398 | mSavedInstanceState = savedInstanceState; |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1399 | |
Winson Chung | 43b119d | 2010-12-06 16:45:05 -0800 | [diff] [blame] | 1400 | // Restore the current AllApps drawer tab |
| 1401 | if (mAllAppsGrid != null && mAllAppsGrid instanceof AllAppsTabbed) { |
| 1402 | String cur = savedInstanceState.getString("allapps_currentTab"); |
| 1403 | if (cur != null) { |
| 1404 | AllAppsTabbed tabhost = (AllAppsTabbed) mAllAppsGrid; |
| 1405 | tabhost.setCurrentTabByTag(cur); |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | // Restore the current customization drawer tab |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1410 | if (mHomeCustomizationDrawer != null) { |
Winson Chung | 43b119d | 2010-12-06 16:45:05 -0800 | [diff] [blame] | 1411 | String cur = savedInstanceState.getString("customize_currentTab"); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1412 | if (cur != null) { |
| 1413 | mHomeCustomizationDrawer.setCurrentTabByTag(cur); |
| 1414 | } |
| 1415 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | @Override |
| 1419 | protected void onSaveInstanceState(Bundle outState) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1420 | outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1421 | |
| 1422 | final ArrayList<Folder> folders = mWorkspace.getOpenFolders(); |
| 1423 | if (folders.size() > 0) { |
| 1424 | final int count = folders.size(); |
| 1425 | long[] ids = new long[count]; |
| 1426 | for (int i = 0; i < count; i++) { |
| 1427 | final FolderInfo info = folders.get(i).getInfo(); |
| 1428 | ids[i] = info.id; |
| 1429 | } |
| 1430 | outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids); |
| 1431 | } else { |
| 1432 | super.onSaveInstanceState(outState); |
| 1433 | } |
| 1434 | |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1435 | outState.putInt(RUNTIME_STATE, mState.ordinal()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1436 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1437 | if (mAddScreen > -1 && mWaitingForResult) { |
| 1438 | outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mAddScreen); |
| 1439 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mAddIntersectCellX); |
| 1440 | outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mAddIntersectCellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | if (mFolderInfo != null && mWaitingForResult) { |
| 1444 | outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); |
| 1445 | outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); |
| 1446 | } |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1447 | |
Winson Chung | 43b119d | 2010-12-06 16:45:05 -0800 | [diff] [blame] | 1448 | // Save the current AllApps drawer tab |
| 1449 | if (mAllAppsGrid != null && mAllAppsGrid instanceof AllAppsTabbed) { |
| 1450 | AllAppsTabbed tabhost = (AllAppsTabbed) mAllAppsGrid; |
| 1451 | String currentTabTag = tabhost.getCurrentTabTag(); |
| 1452 | if (currentTabTag != null) { |
| 1453 | outState.putString("allapps_currentTab", currentTabTag); |
| 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | // Save the current customization drawer tab |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1458 | if (mHomeCustomizationDrawer != null) { |
| 1459 | String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag(); |
| 1460 | if (currentTabTag != null) { |
Winson Chung | 43b119d | 2010-12-06 16:45:05 -0800 | [diff] [blame] | 1461 | outState.putString("customize_currentTab", currentTabTag); |
Michael Jurka | 946ad47 | 2010-07-09 18:05:18 -0700 | [diff] [blame] | 1462 | } |
| 1463 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | @Override |
| 1467 | public void onDestroy() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1468 | super.onDestroy(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1469 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1470 | try { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1471 | mAppWidgetHost.stopListening(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1472 | } catch (NullPointerException ex) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1473 | 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] | 1474 | } |
| 1475 | |
| 1476 | TextKeyListener.getInstance().release(); |
| 1477 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1478 | mModel.stopLoader(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1479 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1480 | unbindDesktopItems(); |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1481 | |
| 1482 | getContentResolver().unregisterContentObserver(mWidgetObserver); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1483 | |
Patrick Dubroy | ab962b7 | 2010-07-26 12:10:10 -0700 | [diff] [blame] | 1484 | // Some launcher layouts don't have a previous and next view |
| 1485 | if (mPreviousView != null) { |
| 1486 | dismissPreview(mPreviousView); |
| 1487 | } |
| 1488 | if (mNextView != null) { |
| 1489 | dismissPreview(mNextView); |
| 1490 | } |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 1491 | |
| 1492 | unregisterReceiver(mCloseSystemDialogsReceiver); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | @Override |
| 1496 | public void startActivityForResult(Intent intent, int requestCode) { |
Romain Guy | 08f9749 | 2009-06-29 14:41:20 -0700 | [diff] [blame] | 1497 | if (requestCode >= 0) mWaitingForResult = true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1498 | super.startActivityForResult(intent, requestCode); |
| 1499 | } |
| 1500 | |
| 1501 | @Override |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1502 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1503 | Bundle appSearchData, boolean globalSearch) { |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1504 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1505 | showWorkspace(true); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1506 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1507 | if (initialQuery == null) { |
| 1508 | // Use any text typed in the launcher as the initial query |
| 1509 | initialQuery = getTypedText(); |
| 1510 | clearTypedText(); |
| 1511 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1512 | if (appSearchData == null) { |
| 1513 | appSearchData = new Bundle(); |
Bjorn Bringert | 3e244cf | 2010-02-10 14:17:35 +0000 | [diff] [blame] | 1514 | appSearchData.putString(Search.SOURCE, "launcher-search"); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1515 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1516 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1517 | final SearchManager searchManager = |
| 1518 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1519 | searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1520 | appSearchData, globalSearch); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | @Override |
| 1524 | public boolean onCreateOptionsMenu(Menu menu) { |
Patrick Dubroy | 5905bca | 2010-09-08 22:43:38 -0700 | [diff] [blame] | 1525 | if (isWorkspaceLocked()) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1526 | return false; |
| 1527 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1528 | |
| 1529 | super.onCreateOptionsMenu(menu); |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1530 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1531 | menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add) |
| 1532 | .setIcon(android.R.drawable.ic_menu_add) |
| 1533 | .setAlphabeticShortcut('A'); |
Winson Chung | 7ad0141 | 2010-09-27 11:33:03 -0700 | [diff] [blame] | 1534 | menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps) |
| 1535 | .setIcon(android.R.drawable.ic_menu_manage) |
| 1536 | .setAlphabeticShortcut('M'); |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1537 | menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper) |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1538 | .setIcon(android.R.drawable.ic_menu_gallery) |
| 1539 | .setAlphabeticShortcut('W'); |
| 1540 | menu.add(0, MENU_SEARCH, 0, R.string.menu_search) |
| 1541 | .setIcon(android.R.drawable.ic_search_category_default) |
| 1542 | .setAlphabeticShortcut(SearchManager.MENU_KEY); |
| 1543 | menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications) |
| 1544 | .setIcon(com.android.internal.R.drawable.ic_menu_notifications) |
| 1545 | .setAlphabeticShortcut('N'); |
| 1546 | |
| 1547 | final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS); |
Romain Guy | 5a94139 | 2009-04-28 15:18:25 -0700 | [diff] [blame] | 1548 | settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 1549 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1550 | |
| 1551 | menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings) |
| 1552 | .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P') |
| 1553 | .setIntent(settings); |
| 1554 | |
| 1555 | return true; |
| 1556 | } |
| 1557 | |
| 1558 | @Override |
| 1559 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 1560 | super.onPrepareOptionsMenu(menu); |
| 1561 | |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1562 | // If all apps is animating, don't show the menu, because we don't know |
| 1563 | // which one to show. |
Patrick Dubroy | ff5f040 | 2010-07-26 15:23:26 -0700 | [diff] [blame] | 1564 | if (mAllAppsGrid.isAnimating()) { |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1565 | return false; |
| 1566 | } |
| 1567 | |
| 1568 | // Only show the add and wallpaper options when we're not in all apps. |
Patrick Dubroy | ff5f040 | 2010-07-26 15:23:26 -0700 | [diff] [blame] | 1569 | boolean visible = !mAllAppsGrid.isVisible(); |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1570 | menu.setGroupVisible(MENU_GROUP_ADD, visible); |
| 1571 | menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible); |
| 1572 | |
| 1573 | // Disable add if the workspace is full. |
| 1574 | if (visible) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1575 | CellLayout layout = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage()); |
| 1576 | menu.setGroupEnabled(MENU_GROUP_ADD, layout.existsEmptyCell()); |
Joe Onorato | 2d7e7d0 | 2010-01-29 15:57:19 -0800 | [diff] [blame] | 1577 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1578 | |
| 1579 | return true; |
| 1580 | } |
| 1581 | |
| 1582 | @Override |
| 1583 | public boolean onOptionsItemSelected(MenuItem item) { |
| 1584 | switch (item.getItemId()) { |
| 1585 | case MENU_ADD: |
| 1586 | addItems(); |
| 1587 | return true; |
Winson Chung | 7ad0141 | 2010-09-27 11:33:03 -0700 | [diff] [blame] | 1588 | case MENU_MANAGE_APPS: |
| 1589 | manageApps(); |
| 1590 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1591 | case MENU_WALLPAPER_SETTINGS: |
| 1592 | startWallpaper(); |
| 1593 | return true; |
| 1594 | case MENU_SEARCH: |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1595 | onSearchRequested(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1596 | return true; |
| 1597 | case MENU_NOTIFICATIONS: |
| 1598 | showNotifications(); |
| 1599 | return true; |
| 1600 | } |
| 1601 | |
| 1602 | return super.onOptionsItemSelected(item); |
| 1603 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1604 | |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1605 | /** |
| 1606 | * Indicates that we want global search for this activity by setting the globalSearch |
| 1607 | * argument for {@link #startSearch} to true. |
| 1608 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1609 | |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1610 | @Override |
| 1611 | public boolean onSearchRequested() { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1612 | startSearch(null, false, null, true); |
Karl Rosaen | 138a041 | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 1613 | return true; |
The Android Open Source Project | ca9475f | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1616 | public boolean isWorkspaceLocked() { |
| 1617 | return mWorkspaceLoading || mWaitingForResult; |
| 1618 | } |
| 1619 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1620 | private void addItems() { |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1621 | if (LauncherApplication.isScreenXLarge()) { |
| 1622 | // Animate the widget chooser up from the bottom of the screen |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1623 | if (mState != State.CUSTOMIZE) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 1624 | showCustomizationDrawer(true); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1625 | } |
| 1626 | } else { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1627 | showWorkspace(true); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1628 | showAddDialog(-1, -1); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 1629 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1630 | } |
| 1631 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1632 | private void resetAddInfo() { |
| 1633 | mAddScreen = -1; |
| 1634 | mAddIntersectCellX = -1; |
| 1635 | mAddIntersectCellY = -1; |
| 1636 | mAddDropPosition = null; |
| 1637 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 1638 | |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1639 | void addAppWidgetFromDrop(PendingAddWidgetInfo info, int screen, int[] position) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1640 | resetAddInfo(); |
| 1641 | mAddScreen = screen; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1642 | mAddDropPosition = position; |
| 1643 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1644 | int appWidgetId = getAppWidgetHost().allocateAppWidgetId(); |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1645 | AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName); |
| 1646 | addAppWidgetImpl(appWidgetId, info); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1647 | } |
| 1648 | |
Winson Chung | 7ad0141 | 2010-09-27 11:33:03 -0700 | [diff] [blame] | 1649 | private void manageApps() { |
| 1650 | startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS)); |
| 1651 | } |
| 1652 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1653 | void addAppWidgetFromPick(Intent data) { |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 1654 | // TODO: catch bad widget exception when sent |
| 1655 | int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1656 | // TODO: Is this log message meaningful? |
| 1657 | if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras()); |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1658 | addAppWidgetImpl(appWidgetId, null); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1659 | } |
| 1660 | |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1661 | void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1662 | AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1663 | |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1664 | if (appWidget.configure != null) { |
| 1665 | // Launch over to configure widget, if needed |
| 1666 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); |
| 1667 | intent.setComponent(appWidget.configure); |
| 1668 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1669 | if (info != null) { |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 1670 | if (info.mimeType != null && !info.mimeType.isEmpty()) { |
| 1671 | intent.putExtra( |
| 1672 | InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE, |
| 1673 | info.mimeType); |
| 1674 | |
| 1675 | final String mimeType = info.mimeType; |
| 1676 | final ClipData clipData = (ClipData) info.configurationData; |
| 1677 | final ClipDescription clipDesc = clipData.getDescription(); |
| 1678 | for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) { |
| 1679 | if (clipDesc.getMimeType(i).equals(mimeType)) { |
| 1680 | final ClipData.Item item = clipData.getItem(i); |
| 1681 | final CharSequence stringData = item.getText(); |
| 1682 | final Uri uriData = item.getUri(); |
| 1683 | final Intent intentData = item.getIntent(); |
| 1684 | final String key = |
| 1685 | InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA; |
| 1686 | if (uriData != null) { |
| 1687 | intent.putExtra(key, uriData); |
| 1688 | } else if (intentData != null) { |
| 1689 | intent.putExtra(key, intentData); |
| 1690 | } else if (stringData != null) { |
| 1691 | intent.putExtra(key, stringData); |
| 1692 | } |
| 1693 | break; |
| 1694 | } |
| 1695 | } |
| 1696 | } |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 1697 | } |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1698 | |
Romain Guy | 8e633c5 | 2010-03-04 12:51:36 -0800 | [diff] [blame] | 1699 | startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1700 | } else { |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1701 | // Otherwise just add it |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1702 | completeAddAppWidget(appWidgetId, mAddScreen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1703 | } |
| 1704 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1705 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1706 | void processShortcutFromDrop(ComponentName componentName, int screen, int[] position) { |
| 1707 | resetAddInfo(); |
| 1708 | mAddScreen = screen; |
| 1709 | mAddDropPosition = position; |
| 1710 | |
| 1711 | Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 1712 | createShortcutIntent.setComponent(componentName); |
| 1713 | processShortcut(createShortcutIntent); |
| 1714 | } |
| 1715 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 1716 | void processShortcut(Intent intent) { |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1717 | // Handle case where user selected "Applications" |
| 1718 | String applicationName = getResources().getString(R.string.group_applications); |
| 1719 | String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1720 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1721 | if (applicationName != null && applicationName.equals(shortcutName)) { |
| 1722 | Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1723 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1724 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1725 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 1726 | pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent); |
Winson Chung | 58f2088 | 2010-10-01 13:44:56 -0700 | [diff] [blame] | 1727 | pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application)); |
Joe Onorato | 4a79a04 | 2010-09-24 16:17:21 -0700 | [diff] [blame] | 1728 | startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1729 | } else { |
Joe Onorato | 4a79a04 | 2010-09-24 16:17:21 -0700 | [diff] [blame] | 1730 | startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1731 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1732 | } |
| 1733 | |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 1734 | void processWallpaper(Intent intent) { |
| 1735 | startActivityForResult(intent, REQUEST_PICK_WALLPAPER); |
| 1736 | } |
| 1737 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1738 | void addLiveFolderFromDrop(ComponentName componentName, int screen, int[] position) { |
| 1739 | resetAddInfo(); |
| 1740 | mAddScreen = screen; |
| 1741 | mAddDropPosition = position; |
| 1742 | |
| 1743 | Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER); |
| 1744 | createFolderIntent.setComponent(componentName); |
| 1745 | |
| 1746 | addLiveFolder(createFolderIntent); |
| 1747 | } |
| 1748 | |
| 1749 | void addLiveFolder(Intent intent) { // YYY add screen intersect etc. parameters here |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1750 | // Handle case where user selected "Folder" |
Jeffrey Sharkey | c4bbd0a | 2009-03-24 22:47:52 -0700 | [diff] [blame] | 1751 | String folderName = getResources().getString(R.string.group_folder); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1752 | String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1753 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1754 | if (folderName != null && folderName.equals(shortcutName)) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1755 | addFolder(mAddScreen, mAddIntersectCellX, mAddIntersectCellY); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1756 | } else { |
Joe Onorato | 4a79a04 | 2010-09-24 16:17:21 -0700 | [diff] [blame] | 1757 | startActivityForResultSafely(intent, REQUEST_CREATE_LIVE_FOLDER); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 1758 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1759 | } |
| 1760 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1761 | void addFolder(int screen, int intersectCellX, int intersectCellY) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1762 | UserFolderInfo folderInfo = new UserFolderInfo(); |
| 1763 | folderInfo.title = getText(R.string.folder_name); |
| 1764 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1765 | final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1766 | final int[] cellXY = mTmpAddItemCellCoordinates; |
| 1767 | if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) { |
| 1768 | showOutOfSpaceMessage(); |
| 1769 | return; |
| 1770 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1771 | |
| 1772 | // Update the model |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1773 | LauncherModel.addItemToDatabase(this, folderInfo, |
| 1774 | LauncherSettings.Favorites.CONTAINER_DESKTOP, |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1775 | screen, cellXY[0], cellXY[1], false); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1776 | sFolders.put(folderInfo.id, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1777 | |
| 1778 | // Create the view |
| 1779 | FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | c9a9619 | 2010-11-01 11:52:08 -0700 | [diff] [blame] | 1780 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), |
| 1781 | folderInfo, mIconCache); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1782 | mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1783 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 1784 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1785 | void removeFolder(FolderInfo folder) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1786 | sFolders.remove(folder.id); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1787 | } |
| 1788 | |
Michael Jurka | 28750fb | 2010-09-24 17:43:49 -0700 | [diff] [blame] | 1789 | private void completeAddLiveFolder( |
| 1790 | Intent data, int screen, int intersectCellX, int intersectCellY) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1791 | final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen); |
| 1792 | final int[] cellXY = mTmpAddItemCellCoordinates; |
| 1793 | if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) { |
| 1794 | showOutOfSpaceMessage(); |
| 1795 | return; |
| 1796 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1797 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1798 | final LiveFolderInfo info = addLiveFolder(this, data, screen, cellXY[0], cellXY[1], false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1799 | |
| 1800 | if (!mRestoring) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1801 | final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1802 | (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1803 | mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | static LiveFolderInfo addLiveFolder(Context context, Intent data, |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1808 | int screen, int cellX, int cellY, boolean notify) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1809 | |
| 1810 | Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT); |
| 1811 | String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME); |
| 1812 | |
| 1813 | Drawable icon = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1814 | Intent.ShortcutIconResource iconResource = null; |
| 1815 | |
| 1816 | Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON); |
| 1817 | if (extra != null && extra instanceof Intent.ShortcutIconResource) { |
| 1818 | try { |
| 1819 | iconResource = (Intent.ShortcutIconResource) extra; |
| 1820 | final PackageManager packageManager = context.getPackageManager(); |
| 1821 | Resources resources = packageManager.getResourcesForApplication( |
| 1822 | iconResource.packageName); |
| 1823 | final int id = resources.getIdentifier(iconResource.resourceName, null, null); |
| 1824 | icon = resources.getDrawable(id); |
| 1825 | } catch (Exception e) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 1826 | Log.w(TAG, "Could not load live folder icon: " + extra); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1827 | } |
| 1828 | } |
| 1829 | |
| 1830 | if (icon == null) { |
| 1831 | icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder); |
| 1832 | } |
| 1833 | |
| 1834 | final LiveFolderInfo info = new LiveFolderInfo(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1835 | info.icon = Utilities.createIconBitmap(icon, context); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1836 | info.title = name; |
| 1837 | info.iconResource = iconResource; |
| 1838 | info.uri = data.getData(); |
| 1839 | info.baseIntent = baseIntent; |
| 1840 | info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, |
| 1841 | LiveFolders.DISPLAY_MODE_GRID); |
| 1842 | |
| 1843 | LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP, |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1844 | screen, cellX, cellY, notify); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 1845 | sFolders.put(info.id, info); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1846 | |
| 1847 | return info; |
| 1848 | } |
| 1849 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1850 | private void showNotifications() { |
| 1851 | final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE); |
| 1852 | if (statusBar != null) { |
| 1853 | statusBar.expand(); |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | private void startWallpaper() { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1858 | showWorkspace(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1859 | final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); |
Dianne Hackborn | 8355ae3 | 2009-09-07 21:47:51 -0700 | [diff] [blame] | 1860 | Intent chooser = Intent.createChooser(pickWallpaper, |
| 1861 | getText(R.string.chooser_wallpaper)); |
Romain Guy | f2826c7 | 2009-11-12 17:39:34 -0800 | [diff] [blame] | 1862 | // NOTE: Adds a configure option to the chooser if the wallpaper supports it |
| 1863 | // Removed in Eclair MR1 |
| 1864 | // WallpaperManager wm = (WallpaperManager) |
| 1865 | // getSystemService(Context.WALLPAPER_SERVICE); |
| 1866 | // WallpaperInfo wi = wm.getWallpaperInfo(); |
| 1867 | // if (wi != null && wi.getSettingsActivity() != null) { |
| 1868 | // LabeledIntent li = new LabeledIntent(getPackageName(), |
| 1869 | // R.string.configure_wallpaper, 0); |
| 1870 | // li.setClassName(wi.getPackageName(), wi.getSettingsActivity()); |
| 1871 | // chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li }); |
| 1872 | // } |
Mike Cleron | a0618e4 | 2009-10-22 13:55:21 -0700 | [diff] [blame] | 1873 | startActivityForResult(chooser, REQUEST_PICK_WALLPAPER); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1874 | } |
| 1875 | |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 1876 | /** |
| 1877 | * Registers various content observers. The current implementation registers |
| 1878 | * only a favorites observer to keep track of the favorites applications. |
| 1879 | */ |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1880 | private void registerContentObservers() { |
| 1881 | ContentResolver resolver = getContentResolver(); |
| 1882 | resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, |
| 1883 | true, mWidgetObserver); |
| 1884 | } |
| 1885 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1886 | @Override |
| 1887 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 1888 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 1889 | switch (event.getKeyCode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1890 | case KeyEvent.KEYCODE_HOME: |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1891 | return true; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1892 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jason Sams | eb5615d | 2009-11-30 11:50:10 -0800 | [diff] [blame] | 1893 | if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) { |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1894 | dumpState(); |
| 1895 | return true; |
| 1896 | } |
| 1897 | break; |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1898 | } |
| 1899 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 1900 | switch (event.getKeyCode()) { |
Dianne Hackborn | 6780086 | 2009-07-24 17:15:20 -0700 | [diff] [blame] | 1901 | case KeyEvent.KEYCODE_HOME: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1902 | return true; |
| 1903 | } |
| 1904 | } |
| 1905 | |
| 1906 | return super.dispatchKeyEvent(event); |
| 1907 | } |
| 1908 | |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1909 | @Override |
| 1910 | public void onBackPressed() { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1911 | if (mState == State.ALL_APPS || mState == State.CUSTOMIZE) { |
| 1912 | showWorkspace(true); |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1913 | } else { |
| 1914 | closeFolder(); |
| 1915 | } |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1916 | // Some launcher layouts don't have a previous and next view |
| 1917 | if (mPreviousView != null) { |
| 1918 | dismissPreview(mPreviousView); |
| 1919 | dismissPreview(mNextView); |
| 1920 | } |
Joe Onorato | 88ec099 | 2009-11-19 13:16:06 -0800 | [diff] [blame] | 1921 | } |
| 1922 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1923 | private void closeFolder() { |
| 1924 | Folder folder = mWorkspace.getOpenFolder(); |
| 1925 | if (folder != null) { |
| 1926 | closeFolder(folder); |
| 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | void closeFolder(Folder folder) { |
| 1931 | folder.getInfo().opened = false; |
| 1932 | ViewGroup parent = (ViewGroup) folder.getParent(); |
| 1933 | if (parent != null) { |
Michael Jurka | f3ca3ab | 2010-10-20 17:08:24 -0700 | [diff] [blame] | 1934 | CellLayout cl = (CellLayout) parent; |
| 1935 | cl.removeViewWithoutMarkingCells(folder); |
Joe Onorato | b6341e9 | 2009-11-02 10:41:48 -0500 | [diff] [blame] | 1936 | if (folder instanceof DropTarget) { |
| 1937 | // Live folders aren't DropTargets. |
| 1938 | mDragController.removeDropTarget((DropTarget)folder); |
| 1939 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1940 | } |
| 1941 | folder.onClose(); |
| 1942 | } |
| 1943 | |
| 1944 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 1945 | * Re-listen when widgets are reset. |
| 1946 | */ |
| 1947 | private void onAppWidgetReset() { |
| 1948 | mAppWidgetHost.startListening(); |
| 1949 | } |
| 1950 | |
| 1951 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1952 | * Go through the and disconnect any of the callbacks in the drawables and the views or we |
| 1953 | * leak the previous Home screen on orientation change. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1954 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1955 | private void unbindDesktopItems() { |
| 1956 | for (ItemInfo item: mDesktopItems) { |
| 1957 | item.unbind(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1958 | } |
| 1959 | } |
Jeffrey Sharkey | 99c8758 | 2009-03-24 17:59:43 -0700 | [diff] [blame] | 1960 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1961 | /** |
| 1962 | * Launches the intent referred by the clicked shortcut. |
| 1963 | * |
| 1964 | * @param v The view representing the clicked shortcut. |
| 1965 | */ |
| 1966 | public void onClick(View v) { |
| 1967 | Object tag = v.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 1968 | if (tag instanceof ShortcutInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1969 | // Open shortcut |
Romain Guy | fb5411e | 2010-02-24 10:04:17 -0800 | [diff] [blame] | 1970 | final Intent intent = ((ShortcutInfo) tag).intent; |
Joe Onorato | 13724ea | 2009-12-02 21:16:35 -0800 | [diff] [blame] | 1971 | int[] pos = new int[2]; |
| 1972 | v.getLocationOnScreen(pos); |
Romain Guy | fb5411e | 2010-02-24 10:04:17 -0800 | [diff] [blame] | 1973 | intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 1974 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 1975 | startActivitySafely(intent, tag); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1976 | } else if (tag instanceof FolderInfo) { |
| 1977 | handleFolderClick((FolderInfo) tag); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1978 | } else if (v == mHandleView) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1979 | if (mState == State.ALL_APPS) { |
| 1980 | showWorkspace(true); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1981 | } else { |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1982 | showAllApps(true); |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 1983 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1984 | } |
| 1985 | } |
| 1986 | |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 1987 | public boolean onTouch(View v, MotionEvent event) { |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1988 | // this is an intercepted event being forwarded from mWorkspace; |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1989 | // clicking anywhere on the workspace causes the customization drawer to slide down |
| 1990 | showWorkspace(true); |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 1991 | return false; |
| 1992 | } |
| 1993 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 1994 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 1995 | * Event handler for the search button |
| 1996 | * |
| 1997 | * @param v The view that was clicked. |
| 1998 | */ |
| 1999 | public void onClickSearchButton(View v) { |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 2000 | startSearch(null, false, null, true); |
Amith Yamasani | 1f878a1 | 2010-11-22 14:58:22 -0800 | [diff] [blame] | 2001 | // Use a custom animation for launching search |
| 2002 | overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast); |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | /** |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2006 | * Event handler for the voice button |
| 2007 | * |
| 2008 | * @param v The view that was clicked. |
| 2009 | */ |
| 2010 | public void onClickVoiceButton(View v) { |
| 2011 | startVoiceSearch(); |
| 2012 | } |
| 2013 | |
| 2014 | private void startVoiceSearch() { |
| 2015 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 2016 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2017 | startActivity(intent); |
| 2018 | } |
| 2019 | |
| 2020 | /** |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2021 | * Event handler for the "gear" button that appears on the home screen, which |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2022 | * enters home screen customization mode. |
| 2023 | * |
| 2024 | * @param v The view that was clicked. |
| 2025 | */ |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2026 | public void onClickConfigureButton(View v) { |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2027 | addItems(); |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
Michael Jurka | 2c3af5f | 2010-08-03 13:53:20 -0700 | [diff] [blame] | 2030 | /** |
| 2031 | * Event handler for the "grid" button that appears on the home screen, which |
| 2032 | * enters all apps mode. |
| 2033 | * |
| 2034 | * @param v The view that was clicked. |
| 2035 | */ |
| 2036 | public void onClickAllAppsButton(View v) { |
| 2037 | showAllApps(true); |
| 2038 | } |
| 2039 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 2040 | public void onClickAppMarketButton(View v) { |
| 2041 | if (mAppMarketIntent != null) { |
| 2042 | startActivitySafely(mAppMarketIntent, "app market"); |
| 2043 | } |
| 2044 | } |
| 2045 | |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2046 | void startApplicationDetailsActivity(ComponentName componentName) { |
| 2047 | String packageName = componentName.getPackageName(); |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 2048 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
| 2049 | Uri.fromParts("package", packageName, null)); |
| 2050 | startActivity(intent); |
| 2051 | } |
| 2052 | |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 2053 | void startApplicationUninstallActivity(ApplicationInfo appInfo) { |
| 2054 | if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) { |
| 2055 | // System applications cannot be installed. For now, show a toast explaining that. |
| 2056 | // We may give them the option of disabling apps this way. |
| 2057 | int messageId = R.string.uninstall_system_app_text; |
| 2058 | Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); |
| 2059 | } else { |
| 2060 | String packageName = appInfo.componentName.getPackageName(); |
| 2061 | String className = appInfo.componentName.getClassName(); |
| 2062 | Intent intent = new Intent( |
| 2063 | Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); |
| 2064 | startActivity(intent); |
| 2065 | } |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 2068 | void startActivitySafely(Intent intent, Object tag) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2069 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2070 | try { |
| 2071 | startActivity(intent); |
| 2072 | } catch (ActivityNotFoundException e) { |
| 2073 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Daniel Sandler | c9b1877 | 2010-04-22 14:37:59 -0400 | [diff] [blame] | 2074 | 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] | 2075 | } catch (SecurityException e) { |
| 2076 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 2077 | 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] | 2078 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
Joe Onorato | f984e85 | 2010-03-25 09:47:45 -0700 | [diff] [blame] | 2079 | "or use the exported attribute for this activity. " |
| 2080 | + "tag="+ tag + " intent=" + intent, e); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2081 | } |
| 2082 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2083 | |
Romain Guy | 8e633c5 | 2010-03-04 12:51:36 -0800 | [diff] [blame] | 2084 | void startActivityForResultSafely(Intent intent, int requestCode) { |
| 2085 | try { |
| 2086 | startActivityForResult(intent, requestCode); |
| 2087 | } catch (ActivityNotFoundException e) { |
| 2088 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2089 | } catch (SecurityException e) { |
| 2090 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 2091 | Log.e(TAG, "Launcher does not have the permission to launch " + intent + |
| 2092 | ". Make sure to create a MAIN intent-filter for the corresponding activity " + |
| 2093 | "or use the exported attribute for this activity.", e); |
| 2094 | } |
| 2095 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2096 | |
| 2097 | private void handleFolderClick(FolderInfo folderInfo) { |
| 2098 | if (!folderInfo.opened) { |
| 2099 | // Close any open folder |
| 2100 | closeFolder(); |
| 2101 | // Open the requested folder |
| 2102 | openFolder(folderInfo); |
| 2103 | } else { |
| 2104 | // Find the open folder... |
| 2105 | Folder openFolder = mWorkspace.getFolderForTag(folderInfo); |
| 2106 | int folderScreen; |
| 2107 | if (openFolder != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2108 | folderScreen = mWorkspace.getPageForView(openFolder); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2109 | // .. and close it |
| 2110 | closeFolder(openFolder); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2111 | if (folderScreen != mWorkspace.getCurrentPage()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2112 | // Close any folder open on the current screen |
| 2113 | closeFolder(); |
| 2114 | // Pull the folder onto this screen |
| 2115 | openFolder(folderInfo); |
| 2116 | } |
| 2117 | } |
| 2118 | } |
| 2119 | } |
| 2120 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2121 | /** |
Michael Jurka | 774bd37 | 2010-10-22 13:40:50 -0700 | [diff] [blame] | 2122 | * 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] | 2123 | * is animated relative to the specified View. If the View is null, no animation |
| 2124 | * is played. |
| 2125 | * |
| 2126 | * @param folderInfo The FolderInfo describing the folder to open. |
| 2127 | */ |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2128 | public void openFolder(FolderInfo folderInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2129 | Folder openFolder; |
| 2130 | |
| 2131 | if (folderInfo instanceof UserFolderInfo) { |
| 2132 | openFolder = UserFolder.fromXml(this); |
| 2133 | } else if (folderInfo instanceof LiveFolderInfo) { |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 2134 | openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2135 | } else { |
| 2136 | return; |
| 2137 | } |
| 2138 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 2139 | openFolder.setDragController(mDragController); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2140 | openFolder.setLauncher(this); |
| 2141 | |
| 2142 | openFolder.bind(folderInfo); |
| 2143 | folderInfo.opened = true; |
| 2144 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2145 | mWorkspace.addInFullScreen(openFolder, folderInfo.screen); |
| 2146 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2147 | openFolder.onOpen(); |
| 2148 | } |
| 2149 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2150 | public boolean onLongClick(View v) { |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2151 | switch (v.getId()) { |
| 2152 | case R.id.previous_screen: |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2153 | if (mState != State.ALL_APPS) { |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 2154 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2155 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2156 | showPreviews(v); |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 2157 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2158 | return true; |
| 2159 | case R.id.next_screen: |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2160 | if (mState != State.ALL_APPS) { |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 2161 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2162 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2163 | showPreviews(v); |
| 2164 | } |
| 2165 | return true; |
| 2166 | case R.id.all_apps_button: |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2167 | if (mState != State.ALL_APPS) { |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2168 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2169 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
| 2170 | showPreviews(v); |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 2171 | } |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2172 | return true; |
| 2173 | } |
| 2174 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2175 | if (isWorkspaceLocked()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2176 | return false; |
| 2177 | } |
| 2178 | |
| 2179 | if (!(v instanceof CellLayout)) { |
| 2180 | v = (View) v.getParent(); |
| 2181 | } |
| 2182 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2183 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2184 | resetAddInfo(); |
| 2185 | CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2186 | // This happens when long clicking an item with the dpad/trackball |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2187 | if (longClickCellInfo == null || !longClickCellInfo.valid) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2188 | return true; |
| 2189 | } |
| 2190 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2191 | final View itemUnderLongClick = longClickCellInfo.cell; |
| 2192 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2193 | if (mWorkspace.allowLongPress()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2194 | if (itemUnderLongClick == null) { |
| 2195 | // User long pressed on empty space |
| 2196 | mWorkspace.setAllowLongPress(false); |
| 2197 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2198 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Michael Jurka | 5617056 | 2010-10-05 14:14:56 -0700 | [diff] [blame] | 2199 | if (!LauncherApplication.isScreenXLarge()) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2200 | showAddDialog(longClickCellInfo.cellX, longClickCellInfo.cellY); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2201 | } |
| 2202 | } else { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2203 | if (!(itemUnderLongClick instanceof Folder)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2204 | // User long pressed on an item |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 2205 | mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, |
| 2206 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2207 | mAddIntersectCellX = longClickCellInfo.cellX; |
| 2208 | mAddIntersectCellY = longClickCellInfo.cellY; |
| 2209 | mWorkspace.startDrag(longClickCellInfo); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2210 | } |
| 2211 | } |
| 2212 | } |
| 2213 | return true; |
| 2214 | } |
| 2215 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2216 | @SuppressWarnings({"unchecked"}) |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2217 | private void dismissPreview(final View v) { |
| 2218 | final PopupWindow window = (PopupWindow) v.getTag(); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2219 | if (window != null) { |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2220 | window.setOnDismissListener(new PopupWindow.OnDismissListener() { |
| 2221 | public void onDismiss() { |
| 2222 | ViewGroup group = (ViewGroup) v.getTag(R.id.workspace); |
| 2223 | int count = group.getChildCount(); |
| 2224 | for (int i = 0; i < count; i++) { |
| 2225 | ((ImageView) group.getChildAt(i)).setImageDrawable(null); |
| 2226 | } |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2227 | ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon); |
| 2228 | for (Bitmap bitmap : bitmaps) bitmap.recycle(); |
| 2229 | |
| 2230 | v.setTag(R.id.workspace, null); |
| 2231 | v.setTag(R.id.icon, null); |
| 2232 | window.setOnDismissListener(null); |
| 2233 | } |
| 2234 | }); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2235 | window.dismiss(); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2236 | } |
| 2237 | v.setTag(null); |
| 2238 | } |
| 2239 | |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2240 | private void showPreviews(View anchor) { |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2241 | showPreviews(anchor, 0, mWorkspace.getChildCount()); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2242 | } |
| 2243 | |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2244 | private void showPreviews(final View anchor, int start, int end) { |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2245 | final Resources resources = getResources(); |
| 2246 | final Workspace workspace = mWorkspace; |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2247 | |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2248 | CellLayout cell = ((CellLayout) workspace.getChildAt(start)); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2249 | |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2250 | float max = workspace.getChildCount(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2251 | |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2252 | final Rect r = new Rect(); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2253 | resources.getDrawable(R.drawable.preview_background).getPadding(r); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2254 | int extraW = (int) ((r.left + r.right) * max); |
| 2255 | int extraH = r.top + r.bottom; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2256 | |
| 2257 | int aW = cell.getWidth() - extraW; |
| 2258 | float w = aW / max; |
| 2259 | |
| 2260 | int width = cell.getWidth(); |
| 2261 | int height = cell.getHeight(); |
| 2262 | int x = cell.getLeftPadding(); |
| 2263 | int y = cell.getTopPadding(); |
| 2264 | width -= (x + cell.getRightPadding()); |
| 2265 | height -= (y + cell.getBottomPadding()); |
| 2266 | |
| 2267 | float scale = w / width; |
| 2268 | |
| 2269 | int count = end - start; |
| 2270 | |
| 2271 | final float sWidth = width * scale; |
| 2272 | float sHeight = height * scale; |
| 2273 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2274 | LinearLayout preview = new LinearLayout(this); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2275 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2276 | PreviewTouchHandler handler = new PreviewTouchHandler(anchor); |
| 2277 | ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2278 | |
| 2279 | for (int i = start; i < end; i++) { |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2280 | ImageView image = new ImageView(this); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2281 | cell = (CellLayout) workspace.getChildAt(i); |
| 2282 | |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2283 | final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight, |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2284 | Bitmap.Config.ARGB_8888); |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2285 | |
| 2286 | final Canvas c = new Canvas(bitmap); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2287 | c.scale(scale, scale); |
| 2288 | c.translate(-cell.getLeftPadding(), -cell.getTopPadding()); |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 2289 | cell.drawChildren(c); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2290 | |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2291 | image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background)); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2292 | image.setImageBitmap(bitmap); |
| 2293 | image.setTag(i); |
| 2294 | image.setOnClickListener(handler); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2295 | image.setOnFocusChangeListener(handler); |
| 2296 | image.setFocusable(true); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2297 | if (i == mWorkspace.getCurrentPage()) image.requestFocus(); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2298 | |
| 2299 | preview.addView(image, |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2300 | LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
| 2301 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2302 | bitmaps.add(bitmap); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2303 | } |
Romain Guy | f8e6a80 | 2009-12-07 17:48:02 -0800 | [diff] [blame] | 2304 | |
| 2305 | final PopupWindow p = new PopupWindow(this); |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2306 | p.setContentView(preview); |
| 2307 | p.setWidth((int) (sWidth * count + extraW)); |
| 2308 | p.setHeight((int) (sHeight + extraH)); |
| 2309 | p.setAnimationStyle(R.style.AnimationPreview); |
| 2310 | p.setOutsideTouchable(true); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2311 | p.setFocusable(true); |
Romain Guy | ff0c2e2 | 2009-11-10 12:09:59 -0800 | [diff] [blame] | 2312 | p.setBackgroundDrawable(new ColorDrawable(0)); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2313 | p.showAsDropDown(anchor, 0, 0); |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2314 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2315 | p.setOnDismissListener(new PopupWindow.OnDismissListener() { |
| 2316 | public void onDismiss() { |
| 2317 | dismissPreview(anchor); |
| 2318 | } |
| 2319 | }); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2320 | |
| 2321 | anchor.setTag(p); |
| 2322 | anchor.setTag(R.id.workspace, preview); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2323 | anchor.setTag(R.id.icon, bitmaps); |
Romain Guy | 1fbc1c8 | 2009-11-09 20:43:08 -0800 | [diff] [blame] | 2324 | } |
| 2325 | |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2326 | class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener { |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2327 | private final View mAnchor; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2328 | |
Romain Guy | e6b8e2f | 2009-11-10 11:56:55 -0800 | [diff] [blame] | 2329 | public PreviewTouchHandler(View anchor) { |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2330 | mAnchor = anchor; |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | public void onClick(View v) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2334 | mWorkspace.snapToPage((Integer) v.getTag()); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2335 | v.post(this); |
| 2336 | } |
| 2337 | |
| 2338 | public void run() { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2339 | dismissPreview(mAnchor); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | public void onFocusChange(View v, boolean hasFocus) { |
| 2343 | if (hasFocus) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2344 | mWorkspace.snapToPage((Integer) v.getTag()); |
Romain Guy | 9d31e9f | 2009-11-11 18:54:28 -0800 | [diff] [blame] | 2345 | } |
Romain Guy | a6abce8 | 2009-11-10 02:54:41 -0800 | [diff] [blame] | 2346 | } |
| 2347 | } |
| 2348 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2349 | Workspace getWorkspace() { |
| 2350 | return mWorkspace; |
| 2351 | } |
| 2352 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2353 | @Override |
| 2354 | protected Dialog onCreateDialog(int id) { |
| 2355 | switch (id) { |
| 2356 | case DIALOG_CREATE_SHORTCUT: |
| 2357 | return new CreateShortcut().createDialog(); |
| 2358 | case DIALOG_RENAME_FOLDER: |
| 2359 | return new RenameFolder().createDialog(); |
| 2360 | } |
| 2361 | |
| 2362 | return super.onCreateDialog(id); |
| 2363 | } |
| 2364 | |
| 2365 | @Override |
| 2366 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 2367 | switch (id) { |
| 2368 | case DIALOG_CREATE_SHORTCUT: |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2369 | break; |
| 2370 | case DIALOG_RENAME_FOLDER: |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2371 | if (mFolderInfo != null) { |
| 2372 | EditText input = (EditText) dialog.findViewById(R.id.folder_name); |
| 2373 | final CharSequence text = mFolderInfo.title; |
| 2374 | input.setText(text); |
| 2375 | input.setSelection(0, text.length()); |
| 2376 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2377 | break; |
| 2378 | } |
| 2379 | } |
| 2380 | |
| 2381 | void showRenameDialog(FolderInfo info) { |
| 2382 | mFolderInfo = info; |
| 2383 | mWaitingForResult = true; |
| 2384 | showDialog(DIALOG_RENAME_FOLDER); |
| 2385 | } |
| 2386 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2387 | private void showAddDialog(int intersectX, int intersectY) { |
| 2388 | resetAddInfo(); |
| 2389 | mAddIntersectCellX = intersectX; |
| 2390 | mAddIntersectCellY = intersectY; |
| 2391 | mAddScreen = mWorkspace.getCurrentPage(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2392 | mWaitingForResult = true; |
| 2393 | showDialog(DIALOG_CREATE_SHORTCUT); |
| 2394 | } |
| 2395 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2396 | private void pickShortcut() { |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 2397 | // Insert extra item to handle picking application |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2398 | Bundle bundle = new Bundle(); |
| 2399 | |
| 2400 | ArrayList<String> shortcutNames = new ArrayList<String>(); |
| 2401 | shortcutNames.add(getString(R.string.group_applications)); |
| 2402 | bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); |
| 2403 | |
| 2404 | ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>(); |
| 2405 | shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, |
| 2406 | R.drawable.ic_launcher_application)); |
| 2407 | bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); |
| 2408 | |
| 2409 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 2410 | pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT)); |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2411 | pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut)); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2412 | pickIntent.putExtras(bundle); |
| 2413 | |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 2414 | startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT); |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 2415 | } |
| 2416 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2417 | private class RenameFolder { |
| 2418 | private EditText mInput; |
| 2419 | |
| 2420 | Dialog createDialog() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2421 | final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null); |
| 2422 | mInput = (EditText) layout.findViewById(R.id.folder_name); |
| 2423 | |
| 2424 | AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); |
| 2425 | builder.setIcon(0); |
| 2426 | builder.setTitle(getString(R.string.rename_folder_title)); |
| 2427 | builder.setCancelable(true); |
| 2428 | builder.setOnCancelListener(new Dialog.OnCancelListener() { |
| 2429 | public void onCancel(DialogInterface dialog) { |
| 2430 | cleanup(); |
| 2431 | } |
| 2432 | }); |
| 2433 | builder.setNegativeButton(getString(R.string.cancel_action), |
| 2434 | new Dialog.OnClickListener() { |
| 2435 | public void onClick(DialogInterface dialog, int which) { |
| 2436 | cleanup(); |
| 2437 | } |
| 2438 | } |
| 2439 | ); |
| 2440 | builder.setPositiveButton(getString(R.string.rename_action), |
| 2441 | new Dialog.OnClickListener() { |
| 2442 | public void onClick(DialogInterface dialog, int which) { |
| 2443 | changeFolderName(); |
| 2444 | } |
| 2445 | } |
| 2446 | ); |
| 2447 | builder.setView(layout); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2448 | |
| 2449 | final AlertDialog dialog = builder.create(); |
| 2450 | dialog.setOnShowListener(new DialogInterface.OnShowListener() { |
| 2451 | public void onShow(DialogInterface dialog) { |
Joe Onorato | 7018d8e | 2010-04-13 20:25:47 -0700 | [diff] [blame] | 2452 | mWaitingForResult = true; |
Joe Onorato | d753b42 | 2009-11-08 13:31:11 -0500 | [diff] [blame] | 2453 | mInput.requestFocus(); |
| 2454 | InputMethodManager inputManager = (InputMethodManager) |
| 2455 | getSystemService(Context.INPUT_METHOD_SERVICE); |
| 2456 | inputManager.showSoftInput(mInput, 0); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 2457 | } |
| 2458 | }); |
| 2459 | |
| 2460 | return dialog; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | private void changeFolderName() { |
| 2464 | final String name = mInput.getText().toString(); |
| 2465 | if (!TextUtils.isEmpty(name)) { |
| 2466 | // Make sure we have the right folder info |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 2467 | mFolderInfo = sFolders.get(mFolderInfo.id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2468 | mFolderInfo.title = name; |
| 2469 | LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo); |
| 2470 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2471 | if (mWorkspaceLoading) { |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 2472 | lockAllApps(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2473 | mModel.startLoader(Launcher.this, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2474 | } else { |
| 2475 | final FolderIcon folderIcon = (FolderIcon) |
| 2476 | mWorkspace.getViewForTag(mFolderInfo); |
| 2477 | if (folderIcon != null) { |
| 2478 | folderIcon.setText(name); |
| 2479 | getWorkspace().requestLayout(); |
| 2480 | } else { |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 2481 | lockAllApps(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 2482 | mWorkspaceLoading = true; |
| 2483 | mModel.startLoader(Launcher.this, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2484 | } |
| 2485 | } |
| 2486 | } |
| 2487 | cleanup(); |
| 2488 | } |
| 2489 | |
| 2490 | private void cleanup() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2491 | dismissDialog(DIALOG_RENAME_FOLDER); |
| 2492 | mWaitingForResult = false; |
| 2493 | mFolderInfo = null; |
| 2494 | } |
| 2495 | } |
| 2496 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 2497 | // Now a part of LauncherModel.Callbacks. Used to reorder loading steps. |
| 2498 | public boolean isAllAppsVisible() { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2499 | return mState == State.ALL_APPS; |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 2500 | } |
| 2501 | |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2502 | // AllAppsView.Watcher |
| 2503 | public void zoomed(float zoom) { |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 2504 | // In XLarge view, we zoom down the workspace below all apps so it's still visible |
| 2505 | if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) { |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2506 | mWorkspace.setVisibility(View.GONE); |
| 2507 | } |
| 2508 | } |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2509 | |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2510 | private void showToolbarButton(View button) { |
| 2511 | button.setAlpha(1.0f); |
| 2512 | button.setVisibility(View.VISIBLE); |
| 2513 | button.setFocusable(true); |
| 2514 | button.setClickable(true); |
| 2515 | } |
| 2516 | |
| 2517 | private void hideToolbarButton(View button) { |
| 2518 | button.setAlpha(0.0f); |
| 2519 | // We can't set it to GONE, otherwise the RelativeLayout gets screwed up |
| 2520 | button.setVisibility(View.INVISIBLE); |
| 2521 | button.setFocusable(false); |
| 2522 | button.setClickable(false); |
| 2523 | } |
| 2524 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2525 | /** |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2526 | * Helper function for showing or hiding a toolbar button, possibly animated. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2527 | * |
| 2528 | * @param show If true, create an animation to the show the item. Otherwise, hide it. |
| 2529 | * @param view The toolbar button to be animated |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2530 | * @param seq A AnimatorSet that will be used to animate the transition. If null, the |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2531 | * transition will not be animated. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2532 | */ |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2533 | private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2534 | final boolean showing = show; |
| 2535 | final boolean hiding = !show; |
| 2536 | |
| 2537 | final int duration = show ? |
| 2538 | getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) : |
| 2539 | getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime); |
| 2540 | |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2541 | if (seq != null) { |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 2542 | Animator anim = ObjectAnimator.ofFloat(view, "alpha", show ? 1.0f : 0.0f); |
| 2543 | anim.setDuration(duration); |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2544 | anim.addListener(new LauncherAnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 2545 | @Override |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2546 | public void onAnimationStart(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2547 | if (showing) showToolbarButton(view); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2548 | } |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 2549 | @Override |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2550 | public void onAnimationEndOrCancel(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2551 | if (hiding) hideToolbarButton(view); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2552 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2553 | }); |
| 2554 | seq.play(anim); |
| 2555 | } else { |
| 2556 | if (showing) { |
| 2557 | showToolbarButton(view); |
| 2558 | } else { |
| 2559 | hideToolbarButton(view); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2560 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2561 | } |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | /** |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2565 | * Show/hide the appropriate toolbar buttons for newState. |
| 2566 | * If showSeq or hideSeq is null, the transition will be done immediately (not animated). |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2567 | * |
| 2568 | * @param newState The state that is being switched to |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2569 | * @param showSeq AnimatorSet in which to put "show" animations, or null. |
| 2570 | * @param hideSeq AnimatorSet in which to put "hide" animations, or null. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2571 | */ |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2572 | private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) { |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 2573 | final View searchButton = findViewById(R.id.search_button_cluster); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2574 | final View allAppsButton = findViewById(R.id.all_apps_button); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2575 | final View configureButton = findViewById(R.id.configure_button); |
| 2576 | |
| 2577 | switch (newState) { |
| 2578 | case WORKSPACE: |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2579 | hideOrShowToolbarButton(true, searchButton, showSeq); |
| 2580 | hideOrShowToolbarButton(true, allAppsButton, showSeq); |
| 2581 | hideOrShowToolbarButton(true, configureButton, showSeq); |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2582 | mDeleteZone.setHandle(allAppsButton); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2583 | break; |
| 2584 | case ALL_APPS: |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 2585 | hideOrShowToolbarButton(false, configureButton, hideSeq); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2586 | hideOrShowToolbarButton(false, searchButton, hideSeq); |
| 2587 | hideOrShowToolbarButton(false, allAppsButton, hideSeq); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2588 | break; |
| 2589 | case CUSTOMIZE: |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 2590 | hideOrShowToolbarButton(false, allAppsButton, hideSeq); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2591 | hideOrShowToolbarButton(false, searchButton, hideSeq); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2592 | hideOrShowToolbarButton(false, configureButton, hideSeq); |
Patrick Dubroy | bc6840b | 2010-09-01 11:54:27 -0700 | [diff] [blame] | 2593 | mDeleteZone.setHandle(allAppsButton); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2594 | break; |
| 2595 | } |
| 2596 | } |
| 2597 | |
| 2598 | /** |
| 2599 | * Helper method for the cameraZoomIn/cameraZoomOut animations |
| 2600 | * @param view The view being animated |
| 2601 | * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE |
| 2602 | * @param scaleFactor The scale factor used for the zoom |
| 2603 | */ |
| 2604 | private void setPivotsForZoom(View view, State state, float scaleFactor) { |
| 2605 | final int height = view.getHeight(); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2606 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2607 | view.setPivotX(view.getWidth() / 2.0f); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2608 | // Set pivotY so that at the starting zoom factor, the view is partially |
| 2609 | // visible. Modifying initialHeightFactor changes how much of the view is |
| 2610 | // initially showing, and hence the perceived angle from which the view enters. |
| 2611 | final float initialHeightFactor = 0.2f; |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2612 | if (state == State.ALL_APPS) { |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2613 | view.setPivotY((1 + initialHeightFactor) * height); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2614 | } else { |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2615 | view.setPivotY(-initialHeightFactor * height); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2616 | } |
| 2617 | } |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2618 | |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2619 | /** |
| 2620 | * Zoom the camera out from the workspace to reveal 'toView'. |
| 2621 | * Assumes that the view to show is anchored at either the very top or very bottom |
| 2622 | * of the screen. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2623 | * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2624 | */ |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2625 | private void cameraZoomOut(State toState, boolean animated) { |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2626 | final Resources res = getResources(); |
| 2627 | final int duration = res.getInteger(R.integer.config_allAppsZoomInTime); |
| 2628 | final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2629 | final boolean toAllApps = (toState == State.ALL_APPS); |
| 2630 | final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2631 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2632 | setPivotsForZoom(toView, toState, scale); |
| 2633 | |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2634 | if (toAllApps) { |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2635 | mWorkspace.shrink(ShrinkState.BOTTOM_HIDDEN, animated); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2636 | } else { |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2637 | mWorkspace.shrink(ShrinkState.TOP, animated); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2638 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2639 | |
| 2640 | if (animated) { |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 2641 | ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(toView, |
| 2642 | PropertyValuesHolder.ofFloat("scaleX", scale, 1.0f), |
| 2643 | PropertyValuesHolder.ofFloat("scaleY", scale, 1.0f)); |
| 2644 | scaleAnim.setDuration(duration); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2645 | |
| 2646 | scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator()); |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2647 | scaleAnim.addListener(new LauncherAnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 2648 | @Override |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2649 | public void onAnimationStart(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2650 | // Prepare the position |
| 2651 | toView.setTranslationX(0.0f); |
| 2652 | toView.setTranslationY(0.0f); |
| 2653 | toView.setVisibility(View.VISIBLE); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2654 | toView.setAlpha(1.0f); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2655 | } |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2656 | @Override |
| 2657 | public void onAnimationEndOrCancel(Animator animation) { |
| 2658 | // If we don't set the final scale values here, if this animation is cancelled |
| 2659 | // it will have the wrong scale value and subsequent cameraPan animations will |
| 2660 | // not fix that |
| 2661 | toView.setScaleX(1.0f); |
| 2662 | toView.setScaleY(1.0f); |
| 2663 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2664 | }); |
| 2665 | |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2666 | AnimatorSet toolbarHideAnim = new AnimatorSet(); |
| 2667 | AnimatorSet toolbarShowAnim = new AnimatorSet(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2668 | hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim); |
| 2669 | |
| 2670 | // toView should appear right at the end of the workspace shrink animation |
| 2671 | final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration; |
| 2672 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2673 | if (mStateAnimation != null) mStateAnimation.cancel(); |
| 2674 | mStateAnimation = new AnimatorSet(); |
| 2675 | mStateAnimation.playTogether(scaleAnim, toolbarHideAnim); |
| 2676 | mStateAnimation.play(scaleAnim).after(startDelay); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2677 | |
| 2678 | // Show the new toolbar buttons just as the main animation is ending |
| 2679 | final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime); |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2680 | mStateAnimation.play(toolbarShowAnim).after(duration + startDelay - fadeInTime); |
| 2681 | mStateAnimation.start(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2682 | } else { |
| 2683 | toView.setTranslationX(0.0f); |
| 2684 | toView.setTranslationY(0.0f); |
| 2685 | toView.setScaleX(1.0f); |
| 2686 | toView.setScaleY(1.0f); |
| 2687 | toView.setVisibility(View.VISIBLE); |
| 2688 | hideAndShowToolbarButtons(toState, null, null); |
| 2689 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | /** |
| 2693 | * Zoom the camera back into the workspace, hiding 'fromView'. |
| 2694 | * This is the opposite of cameraZoomOut. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2695 | * @param fromState The current state (must be ALL_APPS or CUSTOMIZE). |
| 2696 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2697 | */ |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2698 | private void cameraZoomIn(State fromState, boolean animated) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2699 | cameraZoomIn(fromState, animated, false); |
| 2700 | } |
| 2701 | |
| 2702 | private void cameraZoomIn(State fromState, boolean animated, boolean springLoaded) { |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2703 | Resources res = getResources(); |
| 2704 | int duration = res.getInteger(R.integer.config_allAppsZoomOutTime); |
| 2705 | float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2706 | final View fromView = |
| 2707 | (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer; |
| 2708 | |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2709 | mCustomizePagedView.endChoiceMode(); |
| 2710 | mAllAppsPagedView.endChoiceMode(); |
| 2711 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2712 | setPivotsForZoom(fromView, fromState, scaleFactor); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2713 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2714 | if (!springLoaded) { |
| 2715 | mWorkspace.unshrink(animated); |
| 2716 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2717 | |
| 2718 | if (animated) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2719 | if (mStateAnimation != null) mStateAnimation.cancel(); |
| 2720 | mStateAnimation = new AnimatorSet(); |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 2721 | ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(fromView, |
| 2722 | PropertyValuesHolder.ofFloat("scaleX", scaleFactor), |
| 2723 | PropertyValuesHolder.ofFloat("scaleY", scaleFactor)); |
| 2724 | scaleAnim.setDuration(duration); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2725 | scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator()); |
| 2726 | |
| 2727 | ValueAnimator alphaAnim = ObjectAnimator.ofPropertyValuesHolder(fromView, |
| 2728 | PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.0f)); |
| 2729 | alphaAnim.setDuration(res.getInteger(R.integer.config_allAppsFadeOutTime)); |
| 2730 | alphaAnim.addListener(new LauncherAnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 2731 | @Override |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2732 | public void onAnimationEndOrCancel(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2733 | fromView.setVisibility(View.GONE); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2734 | } |
| 2735 | }); |
| 2736 | |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2737 | AnimatorSet toolbarHideAnim = new AnimatorSet(); |
| 2738 | AnimatorSet toolbarShowAnim = new AnimatorSet(); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2739 | if (!springLoaded) { |
| 2740 | hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim); |
| 2741 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2742 | |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2743 | mStateAnimation.playTogether(scaleAnim, toolbarHideAnim, alphaAnim); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2744 | |
| 2745 | // Show the new toolbar buttons at the very end of the whole animation |
| 2746 | final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime); |
| 2747 | final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime); |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2748 | mStateAnimation.play(toolbarShowAnim).after(unshrinkTime - fadeInTime); |
| 2749 | mStateAnimation.start(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2750 | } else { |
| 2751 | fromView.setVisibility(View.GONE); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2752 | if (!springLoaded) { |
| 2753 | hideAndShowToolbarButtons(State.WORKSPACE, null, null); |
| 2754 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2755 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | /** |
| 2759 | * Pan the camera in the vertical plane between 'fromView' and 'toView'. |
| 2760 | * This is the transition used on xlarge screens to go between all apps and |
| 2761 | * the home customization drawer. |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2762 | * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE. |
| 2763 | * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE. |
| 2764 | * @param animated If true, the transition will be animated. |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2765 | */ |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2766 | private void cameraPan(State fromState, State toState, boolean animated) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2767 | final Resources res = getResources(); |
| 2768 | final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2769 | final int workspaceHeight = mWorkspace.getHeight(); |
| 2770 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2771 | final boolean fromAllApps = (fromState == State.ALL_APPS); |
| 2772 | final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer; |
| 2773 | final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid; |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2774 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2775 | final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY(); |
| 2776 | final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2; |
| 2777 | final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2; |
| 2778 | final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f; |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2779 | |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2780 | mCustomizePagedView.endChoiceMode(); |
| 2781 | mAllAppsPagedView.endChoiceMode(); |
| 2782 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2783 | if (toState == State.ALL_APPS) { |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2784 | mWorkspace.shrink(Workspace.ShrinkState.BOTTOM_HIDDEN, animated); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2785 | } else { |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2786 | mWorkspace.shrink(Workspace.ShrinkState.TOP, animated); |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2787 | } |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2788 | |
| 2789 | if (animated) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2790 | if (mStateAnimation != null) mStateAnimation.cancel(); |
| 2791 | mStateAnimation = new AnimatorSet(); |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2792 | mStateAnimation.addListener(new LauncherAnimatorListenerAdapter() { |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 2793 | @Override |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2794 | public void onAnimationStart(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2795 | toView.setVisibility(View.VISIBLE); |
| 2796 | toView.setY(toViewStartY); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2797 | toView.setAlpha(1.0f); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2798 | } |
Gilles Debunne | dd6c992 | 2010-10-25 11:23:41 -0700 | [diff] [blame] | 2799 | @Override |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2800 | public void onAnimationEndOrCancel(Animator animation) { |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2801 | fromView.setVisibility(View.GONE); |
| 2802 | } |
| 2803 | }); |
| 2804 | |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 2805 | AnimatorSet toolbarHideAnim = new AnimatorSet(); |
| 2806 | AnimatorSet toolbarShowAnim = new AnimatorSet(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2807 | hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim); |
| 2808 | |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 2809 | ObjectAnimator fromAnim = ObjectAnimator.ofFloat(fromView, "y", |
| 2810 | fromViewStartY, fromViewEndY); |
| 2811 | fromAnim.setDuration(duration); |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2812 | ObjectAnimator toAnim = ObjectAnimator.ofPropertyValuesHolder(toView, |
| 2813 | PropertyValuesHolder.ofFloat("y", toViewStartY, toViewEndY), |
| 2814 | PropertyValuesHolder.ofFloat("scaleX", toView.getScaleX(), 1.0f), |
| 2815 | PropertyValuesHolder.ofFloat("scaleY", toView.getScaleY(), 1.0f) |
| 2816 | ); |
Chet Haase | 472b281 | 2010-10-14 07:02:04 -0700 | [diff] [blame] | 2817 | fromAnim.setDuration(duration); |
| 2818 | mStateAnimation.playTogether(toolbarHideAnim, fromAnim, toAnim); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2819 | |
| 2820 | // Show the new toolbar buttons just as the main animation is ending |
| 2821 | final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime); |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2822 | mStateAnimation.play(toolbarShowAnim).after(duration - fadeInTime); |
| 2823 | mStateAnimation.start(); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2824 | } else { |
| 2825 | fromView.setY(fromViewEndY); |
| 2826 | fromView.setVisibility(View.GONE); |
| 2827 | toView.setY(toViewEndY); |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 2828 | toView.setScaleX(1.0f); |
| 2829 | toView.setScaleY(1.0f); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2830 | toView.setVisibility(View.VISIBLE); |
| 2831 | hideAndShowToolbarButtons(toState, null, null); |
| 2832 | } |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | void showAllApps(boolean animated) { |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 2836 | if (mState == State.ALL_APPS) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 2837 | return; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 2838 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 2839 | |
Michael Jurka | 79212d8 | 2010-07-30 16:36:20 -0700 | [diff] [blame] | 2840 | if (LauncherApplication.isScreenXLarge()) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2841 | if (mState == State.CUSTOMIZE) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2842 | cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2843 | } else { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2844 | cameraZoomOut(State.ALL_APPS, animated); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2845 | } |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2846 | } else { |
| 2847 | mAllAppsGrid.zoom(1.0f, animated); |
| 2848 | } |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 2849 | |
Romain Guy | c16fea7 | 2010-03-12 17:17:56 -0800 | [diff] [blame] | 2850 | ((View) mAllAppsGrid).setFocusable(true); |
| 2851 | ((View) mAllAppsGrid).requestFocus(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2852 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 2853 | // TODO: fade these two too |
| 2854 | mDeleteZone.setVisibility(View.GONE); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 2855 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2856 | // Change the state *after* we've called all the transition code |
| 2857 | mState = State.ALL_APPS; |
| 2858 | } |
| 2859 | |
| 2860 | |
| 2861 | void showWorkspace(boolean animated) { |
| 2862 | showWorkspace(animated, null); |
| 2863 | } |
| 2864 | |
| 2865 | void showWorkspace(boolean animated, CellLayout layout) { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2866 | if (layout != null) { |
| 2867 | // always animated, but that's ok since we never specify a layout and |
| 2868 | // want no animation |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2869 | mWorkspace.unshrink(layout); |
| 2870 | } else { |
| 2871 | mWorkspace.unshrink(animated); |
| 2872 | } |
| 2873 | if (mState == State.ALL_APPS) { |
| 2874 | closeAllApps(animated); |
| 2875 | } else if (mState == State.CUSTOMIZE) { |
| 2876 | hideCustomizationDrawer(animated); |
| 2877 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 2878 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2879 | // Change the state *after* we've called all the transition code |
| 2880 | mState = State.WORKSPACE; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 2881 | } |
| 2882 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2883 | void enterSpringLoadedDragMode(CellLayout layout) { |
| 2884 | mWorkspace.enterSpringLoadedDragMode(layout); |
| 2885 | if (mState == State.ALL_APPS) { |
| 2886 | cameraZoomIn(State.ALL_APPS, true, true); |
| 2887 | mState = State.ALL_APPS_SPRING_LOADED; |
| 2888 | } else if (mState == State.CUSTOMIZE) { |
| 2889 | cameraZoomIn(State.CUSTOMIZE, true, true); |
| 2890 | mState = State.CUSTOMIZE_SPRING_LOADED; |
| 2891 | }/* else { |
| 2892 | // we're already in spring loaded mode; don't do anything |
| 2893 | }*/ |
| 2894 | } |
| 2895 | |
| 2896 | void exitSpringLoadedDragMode() { |
| 2897 | if (mState == State.ALL_APPS_SPRING_LOADED) { |
| 2898 | mWorkspace.exitSpringLoadedDragMode(Workspace.ShrinkState.BOTTOM_VISIBLE); |
| 2899 | cameraZoomOut(State.ALL_APPS, true); |
| 2900 | mState = State.ALL_APPS; |
| 2901 | } else if (mState == State.CUSTOMIZE_SPRING_LOADED) { |
| 2902 | mWorkspace.exitSpringLoadedDragMode(Workspace.ShrinkState.TOP); |
| 2903 | cameraZoomOut(State.CUSTOMIZE, true); |
| 2904 | mState = State.CUSTOMIZE; |
| 2905 | }/* else { |
| 2906 | // we're not in spring loaded mode; don't do anything |
| 2907 | }*/ |
| 2908 | } |
| 2909 | |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2910 | /** |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 2911 | * Things to test when changing this code. |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2912 | * - Home from workspace |
| 2913 | * - from center screen |
| 2914 | * - from other screens |
| 2915 | * - Home from all apps |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2916 | * - from center screen |
| 2917 | * - from other screens |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2918 | * - Back from all apps |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2919 | * - from center screen |
| 2920 | * - from other screens |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2921 | * - Launch app from workspace and quit |
| 2922 | * - with back |
| 2923 | * - with home |
| 2924 | * - Launch app from all apps and quit |
| 2925 | * - with back |
| 2926 | * - with home |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 2927 | * - Go to a screen that's not the default, then all |
| 2928 | * apps, and launch and app, and go back |
| 2929 | * - with back |
| 2930 | * -with home |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2931 | * - On workspace, long press power and go back |
| 2932 | * - with back |
| 2933 | * - with home |
| 2934 | * - On all apps, long press power and go back |
| 2935 | * - with back |
| 2936 | * - with home |
| 2937 | * - On workspace, power off |
| 2938 | * - On all apps, power off |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 2939 | * - Launch an app and turn off the screen while in that app |
| 2940 | * - Go back with home key |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 2941 | * - Go back with back key TODO: make this not go to workspace |
Joe Onorato | 7e4ed99 | 2009-12-03 13:10:49 -0800 | [diff] [blame] | 2942 | * - From all apps |
| 2943 | * - From workspace |
Joe Onorato | effc4a8 | 2010-04-15 11:48:13 -0700 | [diff] [blame] | 2944 | * - Enter and exit car mode (becuase it causes an extra configuration changed) |
| 2945 | * - From all apps |
| 2946 | * - From the center workspace |
| 2947 | * - From another workspace |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 2948 | */ |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 2949 | void closeAllApps(boolean animated) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2950 | if (mState == State.ALL_APPS || mState == State.ALL_APPS_SPRING_LOADED) { |
Daniel Sandler | c351eb8 | 2010-03-03 15:05:19 -0500 | [diff] [blame] | 2951 | mWorkspace.setVisibility(View.VISIBLE); |
Patrick Dubroy | df7c3a7 | 2010-08-26 17:52:56 -0700 | [diff] [blame] | 2952 | if (LauncherApplication.isScreenXLarge()) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2953 | cameraZoomIn(State.ALL_APPS, animated); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2954 | } else { |
| 2955 | mAllAppsGrid.zoom(0.0f, animated); |
| 2956 | } |
Daniel Sandler | 388f679 | 2010-03-02 14:08:08 -0500 | [diff] [blame] | 2957 | ((View)mAllAppsGrid).setFocusable(false); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 2958 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | e77c08d | 2009-08-01 00:01:20 -0700 | [diff] [blame] | 2959 | } |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 2960 | } |
| 2961 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 2962 | void lockAllApps() { |
| 2963 | // TODO |
| 2964 | } |
| 2965 | |
| 2966 | void unlockAllApps() { |
| 2967 | // TODO |
| 2968 | } |
| 2969 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2970 | // Show the customization drawer (only exists in x-large configuration) |
| 2971 | private void showCustomizationDrawer(boolean animated) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2972 | if (mState == State.ALL_APPS) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2973 | cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated); |
Patrick Dubroy | 3ec8bdd | 2010-08-06 16:01:33 -0700 | [diff] [blame] | 2974 | } else { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2975 | cameraZoomOut(State.CUSTOMIZE, animated); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2976 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2977 | // Change the state *after* we've called all the transition code |
| 2978 | mState = State.CUSTOMIZE; |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2979 | } |
| 2980 | |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2981 | // Hide the customization drawer (only exists in x-large configuration) |
| 2982 | void hideCustomizationDrawer(boolean animated) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2983 | if (mState == State.CUSTOMIZE || mState == State.CUSTOMIZE_SPRING_LOADED) { |
Patrick Dubroy | 6b509c1 | 2010-08-23 15:08:16 -0700 | [diff] [blame] | 2984 | cameraZoomIn(State.CUSTOMIZE, animated); |
Patrick Dubroy | 558654c | 2010-07-23 16:48:11 -0700 | [diff] [blame] | 2985 | } |
| 2986 | } |
| 2987 | |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 2988 | void addExternalItemToScreen(ItemInfo itemInfo, CellLayout layout) { |
| 2989 | if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) { |
| 2990 | showOutOfSpaceMessage(); |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 2991 | } |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 2992 | } |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2993 | |
Michael Jurka | 6b4b25d | 2010-10-20 18:19:45 -0700 | [diff] [blame] | 2994 | void onWorkspaceClick(CellLayout layout) { |
| 2995 | showWorkspace(true, layout); |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 2996 | } |
| 2997 | |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 2998 | // if successful in getting icon, return it; otherwise, set button to use default drawable |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 2999 | private Drawable.ConstantState updateButtonWithIconFromExternalActivity( |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3000 | int buttonId, ComponentName activityName, int fallbackDrawableId) { |
| 3001 | ImageView button = (ImageView) findViewById(buttonId); |
| 3002 | Drawable toolbarIcon = null; |
| 3003 | try { |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3004 | PackageManager packageManager = getPackageManager(); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3005 | // Look for the toolbar icon specified in the activity meta-data |
| 3006 | Bundle metaData = packageManager.getActivityInfo( |
| 3007 | activityName, PackageManager.GET_META_DATA).metaData; |
| 3008 | if (metaData != null) { |
| 3009 | int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME); |
| 3010 | if (iconResId != 0) { |
| 3011 | Resources res = packageManager.getResourcesForActivity(activityName); |
| 3012 | toolbarIcon = res.getDrawable(iconResId); |
| 3013 | } |
| 3014 | } |
| 3015 | } catch (NameNotFoundException e) { |
| 3016 | // Do nothing |
| 3017 | } |
| 3018 | // If we were unable to find the icon via the meta-data, use a generic one |
| 3019 | if (toolbarIcon == null) { |
| 3020 | button.setImageResource(fallbackDrawableId); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3021 | return null; |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3022 | } else { |
| 3023 | button.setImageDrawable(toolbarIcon); |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3024 | return toolbarIcon.getConstantState(); |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3025 | } |
| 3026 | } |
| 3027 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3028 | private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3029 | ImageView button = (ImageView) findViewById(buttonId); |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3030 | button.setImageDrawable(d.newDrawable(getResources())); |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3031 | } |
| 3032 | |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3033 | private void updateGlobalSearchIcon() { |
| 3034 | if (LauncherApplication.isScreenXLarge()) { |
| 3035 | final SearchManager searchManager = |
| 3036 | (SearchManager) getSystemService(Context.SEARCH_SERVICE); |
| 3037 | ComponentName activityName = searchManager.getGlobalSearchActivity(); |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3038 | if (activityName != null) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3039 | sGlobalSearchIcon = updateButtonWithIconFromExternalActivity( |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3040 | R.id.search_button, activityName, R.drawable.search_button_generic); |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3041 | } else { |
| 3042 | findViewById(R.id.search_button).setVisibility(View.GONE); |
| 3043 | } |
| 3044 | } |
| 3045 | } |
| 3046 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3047 | private void updateGlobalSearchIcon(Drawable.ConstantState d) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3048 | updateButtonWithDrawable(R.id.search_button, d); |
| 3049 | } |
| 3050 | |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3051 | private void updateVoiceSearchIcon() { |
| 3052 | if (LauncherApplication.isScreenXLarge()) { |
| 3053 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3054 | ComponentName activityName = intent.resolveActivity(getPackageManager()); |
| 3055 | if (activityName != null) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3056 | sVoiceSearchIcon = updateButtonWithIconFromExternalActivity( |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3057 | R.id.voice_button, activityName, R.drawable.ic_voice_search); |
| 3058 | } else { |
| 3059 | findViewById(R.id.voice_button).setVisibility(View.GONE); |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3060 | } |
| 3061 | } |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 3062 | } |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3063 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3064 | private void updateVoiceSearchIcon(Drawable.ConstantState d) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3065 | updateButtonWithDrawable(R.id.voice_button, d); |
| 3066 | } |
| 3067 | |
Michael Jurka | 6ae0fcf | 2010-10-01 12:23:12 -0700 | [diff] [blame] | 3068 | /** |
| 3069 | * Sets the app market icon (shown when all apps is visible on x-large screens) |
| 3070 | */ |
| 3071 | private void updateAppMarketIcon() { |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3072 | if (LauncherApplication.isScreenXLarge()) { |
| 3073 | Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET); |
| 3074 | // Find the app market activity by resolving an intent. |
| 3075 | // (If multiple app markets are installed, it will return the ResolverActivity.) |
| 3076 | ComponentName activityName = intent.resolveActivity(getPackageManager()); |
| 3077 | if (activityName != null) { |
| 3078 | mAppMarketIntent = intent; |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3079 | sAppMarketIcon = updateButtonWithIconFromExternalActivity( |
Michael Jurka | 0423dcf | 2010-10-05 14:56:18 -0700 | [diff] [blame] | 3080 | R.id.market_button, activityName, R.drawable.app_market_generic); |
| 3081 | } |
| 3082 | } |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3083 | } |
| 3084 | |
Michael Jurka | e7bf83b | 2010-12-14 18:02:21 -0800 | [diff] [blame] | 3085 | private void updateAppMarketIcon(Drawable.ConstantState d) { |
Michael Jurka | 4ef207b | 2010-11-29 17:05:45 -0800 | [diff] [blame] | 3086 | updateButtonWithDrawable(R.id.market_button, d); |
| 3087 | } |
| 3088 | |
Patrick Dubroy | ceae05d | 2010-08-30 10:40:53 -0700 | [diff] [blame] | 3089 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3090 | * Displays the shortcut creation dialog and launches, if necessary, the |
| 3091 | * appropriate activity. |
| 3092 | */ |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3093 | private class CreateShortcut implements DialogInterface.OnClickListener, |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 3094 | DialogInterface.OnCancelListener, DialogInterface.OnDismissListener, |
| 3095 | DialogInterface.OnShowListener { |
| 3096 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3097 | private AddAdapter mAdapter; |
Romain Guy | 9ffb543 | 2009-03-24 21:04:15 -0700 | [diff] [blame] | 3098 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3099 | Dialog createDialog() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3100 | mAdapter = new AddAdapter(Launcher.this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3101 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3102 | final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); |
| 3103 | builder.setTitle(getString(R.string.menu_item_add_item)); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3104 | builder.setAdapter(mAdapter, this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3105 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3106 | builder.setInverseBackgroundForced(true); |
| 3107 | |
| 3108 | AlertDialog dialog = builder.create(); |
| 3109 | dialog.setOnCancelListener(this); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3110 | dialog.setOnDismissListener(this); |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 3111 | dialog.setOnShowListener(this); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3112 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3113 | return dialog; |
| 3114 | } |
| 3115 | |
| 3116 | public void onCancel(DialogInterface dialog) { |
| 3117 | mWaitingForResult = false; |
| 3118 | cleanup(); |
| 3119 | } |
| 3120 | |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3121 | public void onDismiss(DialogInterface dialog) { |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3122 | } |
| 3123 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3124 | private void cleanup() { |
Joe Onorato | cc19a53 | 2009-11-19 14:19:17 -0800 | [diff] [blame] | 3125 | try { |
| 3126 | dismissDialog(DIALOG_CREATE_SHORTCUT); |
| 3127 | } catch (Exception e) { |
| 3128 | // An exception is thrown if the dialog is not visible, which is fine |
| 3129 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3130 | } |
| 3131 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3132 | /** |
| 3133 | * Handle the action clicked in the "Add to home" dialog. |
| 3134 | */ |
| 3135 | public void onClick(DialogInterface dialog, int which) { |
| 3136 | Resources res = getResources(); |
| 3137 | cleanup(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3138 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3139 | switch (which) { |
| 3140 | case AddAdapter.ITEM_SHORTCUT: { |
Joe Onorato | deb98af | 2010-02-19 14:59:39 -0800 | [diff] [blame] | 3141 | pickShortcut(); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3142 | break; |
| 3143 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3144 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3145 | case AddAdapter.ITEM_APPWIDGET: { |
| 3146 | int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3147 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3148 | Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK); |
| 3149 | pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3150 | // start the pick activity |
| 3151 | startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET); |
| 3152 | break; |
| 3153 | } |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3154 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3155 | case AddAdapter.ITEM_LIVE_FOLDER: { |
| 3156 | // Insert extra item to handle inserting folder |
| 3157 | Bundle bundle = new Bundle(); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3158 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3159 | ArrayList<String> shortcutNames = new ArrayList<String>(); |
| 3160 | shortcutNames.add(res.getString(R.string.group_folder)); |
| 3161 | bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3162 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3163 | ArrayList<ShortcutIconResource> shortcutIcons = |
| 3164 | new ArrayList<ShortcutIconResource>(); |
| 3165 | shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, |
| 3166 | R.drawable.ic_launcher_folder)); |
| 3167 | bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); |
| 3168 | |
| 3169 | Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); |
| 3170 | pickIntent.putExtra(Intent.EXTRA_INTENT, |
| 3171 | new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER)); |
| 3172 | pickIntent.putExtra(Intent.EXTRA_TITLE, |
| 3173 | getText(R.string.title_select_live_folder)); |
| 3174 | pickIntent.putExtras(bundle); |
Romain Guy | cbb89e4 | 2009-06-08 15:52:54 -0700 | [diff] [blame] | 3175 | |
Jeffrey Sharkey | c7fdae1 | 2009-03-24 20:41:22 -0700 | [diff] [blame] | 3176 | startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER); |
| 3177 | break; |
| 3178 | } |
| 3179 | |
| 3180 | case AddAdapter.ITEM_WALLPAPER: { |
| 3181 | startWallpaper(); |
| 3182 | break; |
| 3183 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3184 | } |
| 3185 | } |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 3186 | |
| 3187 | public void onShow(DialogInterface dialog) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3188 | mWaitingForResult = true; |
Romain Guy | 7b4ef33 | 2009-07-14 13:58:08 -0700 | [diff] [blame] | 3189 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | /** |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 3193 | * Receives notifications when applications are added/removed. |
| 3194 | */ |
| 3195 | private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { |
| 3196 | @Override |
| 3197 | public void onReceive(Context context, Intent intent) { |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 3198 | closeSystemDialogs(); |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 3199 | String reason = intent.getStringExtra("reason"); |
| 3200 | if (!"homekey".equals(reason)) { |
| 3201 | boolean animate = true; |
Joe Onorato | 34a0e1b | 2009-12-14 17:44:51 -0800 | [diff] [blame] | 3202 | if (mPaused || "lock".equals(reason)) { |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 3203 | animate = false; |
| 3204 | } |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3205 | showWorkspace(animate); |
Joe Onorato | b206121 | 2009-11-24 16:13:54 -0500 | [diff] [blame] | 3206 | } |
Joe Onorato | 2ca0ae7 | 2009-11-10 13:14:13 -0800 | [diff] [blame] | 3207 | } |
| 3208 | } |
| 3209 | |
| 3210 | /** |
Jeff Sharkey | 1e2efc8 | 2009-11-06 15:17:59 -0800 | [diff] [blame] | 3211 | * Receives notifications whenever the appwidgets are reset. |
| 3212 | */ |
| 3213 | private class AppWidgetResetObserver extends ContentObserver { |
| 3214 | public AppWidgetResetObserver() { |
| 3215 | super(new Handler()); |
| 3216 | } |
| 3217 | |
| 3218 | @Override |
| 3219 | public void onChange(boolean selfChange) { |
| 3220 | onAppWidgetReset(); |
| 3221 | } |
| 3222 | } |
| 3223 | |
| 3224 | /** |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3225 | * If the activity is currently paused, signal that we need to re-run the loader |
| 3226 | * in onResume. |
| 3227 | * |
| 3228 | * This needs to be called from incoming places where resources might have been loaded |
| 3229 | * while we are paused. That is becaues the Configuration might be wrong |
| 3230 | * when we're not running, and if it comes back to what it was when we |
| 3231 | * were paused, we are not restarted. |
| 3232 | * |
| 3233 | * Implementation of the method from LauncherModel.Callbacks. |
| 3234 | * |
| 3235 | * @return true if we are currently paused. The caller might be able to |
| 3236 | * skip some work in that case since we will come back again. |
| 3237 | */ |
| 3238 | public boolean setLoadOnResume() { |
| 3239 | if (mPaused) { |
| 3240 | Log.i(TAG, "setLoadOnResume"); |
| 3241 | mOnResumeNeedsLoad = true; |
| 3242 | return true; |
| 3243 | } else { |
| 3244 | return false; |
| 3245 | } |
| 3246 | } |
| 3247 | |
| 3248 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3249 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3250 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3251 | public int getCurrentWorkspaceScreen() { |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 3252 | if (mWorkspace != null) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3253 | return mWorkspace.getCurrentPage(); |
Joe Onorato | d0afc87 | 2010-06-11 00:03:15 -0700 | [diff] [blame] | 3254 | } else { |
| 3255 | return SCREEN_COUNT / 2; |
| 3256 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3257 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3258 | |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3259 | void setAllAppsPagedView(PagedView view) { |
| 3260 | mAllAppsPagedView = view; |
| 3261 | } |
| 3262 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3263 | /** |
| 3264 | * Refreshes the shortcuts shown on the workspace. |
| 3265 | * |
| 3266 | * Implementation of the method from LauncherModel.Callbacks. |
| 3267 | */ |
| 3268 | public void startBinding() { |
| 3269 | final Workspace workspace = mWorkspace; |
| 3270 | int count = workspace.getChildCount(); |
| 3271 | for (int i = 0; i < count; i++) { |
Joe Onorato | 3c2f7e1 | 2009-10-31 19:17:31 -0400 | [diff] [blame] | 3272 | // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate(). |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3273 | ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout(); |
| 3274 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3275 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3276 | if (DEBUG_USER_INTERFACE) { |
| 3277 | android.widget.Button finishButton = new android.widget.Button(this); |
| 3278 | finishButton.setText("Finish"); |
| 3279 | workspace.addInScreen(finishButton, 1, 0, 0, 1, 1); |
| 3280 | |
| 3281 | finishButton.setOnClickListener(new android.widget.Button.OnClickListener() { |
| 3282 | public void onClick(View v) { |
| 3283 | finish(); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3284 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3285 | }); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3286 | } |
| 3287 | } |
| 3288 | |
| 3289 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3290 | * Bind the items start-end from the list. |
| 3291 | * |
| 3292 | * Implementation of the method from LauncherModel.Callbacks. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3293 | */ |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3294 | public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) { |
| 3295 | |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3296 | setLoadOnResume(); |
| 3297 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3298 | final Workspace workspace = mWorkspace; |
| 3299 | |
| 3300 | for (int i=start; i<end; i++) { |
| 3301 | final ItemInfo item = shortcuts.get(i); |
| 3302 | mDesktopItems.add(item); |
| 3303 | switch (item.itemType) { |
| 3304 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 3305 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3306 | final View shortcut = createShortcut((ShortcutInfo)item); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3307 | workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1, |
| 3308 | false); |
| 3309 | break; |
| 3310 | case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER: |
| 3311 | final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3312 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Michael Jurka | c9a9619 | 2010-11-01 11:52:08 -0700 | [diff] [blame] | 3313 | (UserFolderInfo) item, mIconCache); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3314 | workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1, |
| 3315 | false); |
| 3316 | break; |
| 3317 | case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER: |
| 3318 | final FolderIcon newLiveFolder = LiveFolderIcon.fromXml( |
| 3319 | R.layout.live_folder_icon, this, |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3320 | (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3321 | (LiveFolderInfo) item); |
| 3322 | workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1, |
| 3323 | false); |
| 3324 | break; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3325 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3326 | } |
| 3327 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3328 | workspace.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3329 | } |
| 3330 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3331 | /** |
| 3332 | * Implementation of the method from LauncherModel.Callbacks. |
| 3333 | */ |
Joe Onorato | ad72e17 | 2009-11-06 16:25:04 -0500 | [diff] [blame] | 3334 | public void bindFolders(HashMap<Long, FolderInfo> folders) { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3335 | setLoadOnResume(); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 3336 | sFolders.clear(); |
| 3337 | sFolders.putAll(folders); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3338 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3339 | |
| 3340 | /** |
| 3341 | * Add the views for a widget to the workspace. |
| 3342 | * |
| 3343 | * Implementation of the method from LauncherModel.Callbacks. |
| 3344 | */ |
| 3345 | public void bindAppWidget(LauncherAppWidgetInfo item) { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3346 | setLoadOnResume(); |
| 3347 | |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3348 | final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; |
| 3349 | if (DEBUG_WIDGETS) { |
| 3350 | Log.d(TAG, "bindAppWidget: " + item); |
| 3351 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3352 | final Workspace workspace = mWorkspace; |
| 3353 | |
| 3354 | final int appWidgetId = item.appWidgetId; |
| 3355 | final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3356 | if (DEBUG_WIDGETS) { |
| 3357 | Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); |
| 3358 | } |
| 3359 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3360 | item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); |
| 3361 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3362 | item.hostView.setAppWidget(appWidgetId, appWidgetInfo); |
| 3363 | item.hostView.setTag(item); |
| 3364 | |
| 3365 | workspace.addInScreen(item.hostView, item.screen, item.cellX, |
| 3366 | item.cellY, item.spanX, item.spanY, false); |
| 3367 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 3368 | addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); |
| 3369 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3370 | workspace.requestLayout(); |
| 3371 | |
| 3372 | mDesktopItems.add(item); |
Daniel Sandler | 843e860 | 2010-06-07 14:59:01 -0400 | [diff] [blame] | 3373 | |
| 3374 | if (DEBUG_WIDGETS) { |
| 3375 | Log.d(TAG, "bound widget id="+item.appWidgetId+" in " |
| 3376 | + (SystemClock.uptimeMillis()-start) + "ms"); |
| 3377 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3378 | } |
| 3379 | |
| 3380 | /** |
| 3381 | * Callback saying that there aren't any more items to bind. |
| 3382 | * |
| 3383 | * Implementation of the method from LauncherModel.Callbacks. |
| 3384 | */ |
| 3385 | public void finishBindingItems() { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3386 | setLoadOnResume(); |
| 3387 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3388 | if (mSavedState != null) { |
| 3389 | if (!mWorkspace.hasFocus()) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3390 | mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS); |
| 3394 | if (userFolders != null) { |
| 3395 | for (long folderId : userFolders) { |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 3396 | final FolderInfo info = sFolders.get(folderId); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3397 | if (info != null) { |
| 3398 | openFolder(info); |
| 3399 | } |
| 3400 | } |
| 3401 | final Folder openFolder = mWorkspace.getOpenFolder(); |
| 3402 | if (openFolder != null) { |
| 3403 | openFolder.requestFocus(); |
| 3404 | } |
| 3405 | } |
| 3406 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3407 | mSavedState = null; |
| 3408 | } |
| 3409 | |
| 3410 | if (mSavedInstanceState != null) { |
| 3411 | super.onRestoreInstanceState(mSavedInstanceState); |
| 3412 | mSavedInstanceState = null; |
| 3413 | } |
| 3414 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3415 | mWorkspaceLoading = false; |
| 3416 | } |
| 3417 | |
| 3418 | /** |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3419 | * Updates the icons on the launcher that are affected by changes to the package list |
| 3420 | * on the device. |
| 3421 | */ |
| 3422 | private void updateIconsAffectedByPackageManagerChanges() { |
| 3423 | updateAppMarketIcon(); |
| 3424 | updateGlobalSearchIcon(); |
| 3425 | updateVoiceSearchIcon(); |
| 3426 | } |
| 3427 | |
| 3428 | /** |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3429 | * Add the icons for all apps. |
| 3430 | * |
| 3431 | * Implementation of the method from LauncherModel.Callbacks. |
| 3432 | */ |
| 3433 | public void bindAllApplications(ArrayList<ApplicationInfo> apps) { |
Romain Guy | 84f296c | 2009-11-04 15:00:44 -0800 | [diff] [blame] | 3434 | mAllAppsGrid.setApps(apps); |
Andrew Stadler | 959f603 | 2010-09-27 11:42:53 -0700 | [diff] [blame] | 3435 | if (mCustomizePagedView != null) { |
| 3436 | mCustomizePagedView.setApps(apps); |
| 3437 | } |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3438 | updateIconsAffectedByPackageManagerChanges(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | /** |
| 3442 | * A package was installed. |
| 3443 | * |
| 3444 | * Implementation of the method from LauncherModel.Callbacks. |
| 3445 | */ |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3446 | public void bindAppsAdded(ArrayList<ApplicationInfo> apps) { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3447 | setLoadOnResume(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3448 | removeDialog(DIALOG_CREATE_SHORTCUT); |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 3449 | mAllAppsGrid.addApps(apps); |
Andrew Stadler | 959f603 | 2010-09-27 11:42:53 -0700 | [diff] [blame] | 3450 | if (mCustomizePagedView != null) { |
| 3451 | mCustomizePagedView.addApps(apps); |
| 3452 | } |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3453 | updateIconsAffectedByPackageManagerChanges(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3454 | } |
| 3455 | |
| 3456 | /** |
| 3457 | * A package was updated. |
| 3458 | * |
| 3459 | * Implementation of the method from LauncherModel.Callbacks. |
| 3460 | */ |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3461 | public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) { |
Joe Onorato | ef2efcf | 2010-10-27 13:21:00 -0700 | [diff] [blame] | 3462 | setLoadOnResume(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3463 | removeDialog(DIALOG_CREATE_SHORTCUT); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3464 | mWorkspace.updateShortcuts(apps); |
| 3465 | mAllAppsGrid.updateApps(apps); |
Andrew Stadler | 959f603 | 2010-09-27 11:42:53 -0700 | [diff] [blame] | 3466 | if (mCustomizePagedView != null) { |
| 3467 | mCustomizePagedView.updateApps(apps); |
| 3468 | } |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3469 | updateIconsAffectedByPackageManagerChanges(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3470 | } |
| 3471 | |
| 3472 | /** |
| 3473 | * A package was uninstalled. |
| 3474 | * |
| 3475 | * Implementation of the method from LauncherModel.Callbacks. |
| 3476 | */ |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3477 | public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3478 | removeDialog(DIALOG_CREATE_SHORTCUT); |
Joe Onorato | 3611578 | 2010-06-17 13:28:48 -0400 | [diff] [blame] | 3479 | if (permanent) { |
| 3480 | mWorkspace.removeItems(apps); |
| 3481 | } |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 3482 | mAllAppsGrid.removeApps(apps); |
Andrew Stadler | 959f603 | 2010-09-27 11:42:53 -0700 | [diff] [blame] | 3483 | if (mCustomizePagedView != null) { |
| 3484 | mCustomizePagedView.removeApps(apps); |
| 3485 | } |
Amith Yamasani | 6d7fe50 | 2010-11-16 09:05:07 -0800 | [diff] [blame] | 3486 | updateIconsAffectedByPackageManagerChanges(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 3487 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3488 | |
| 3489 | /** |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 3490 | * A number of packages were updated. |
| 3491 | */ |
| 3492 | public void bindPackagesUpdated() { |
| 3493 | // update the customization drawer contents |
Winson Chung | 5f94172 | 2010-09-28 16:36:43 -0700 | [diff] [blame] | 3494 | if (mCustomizePagedView != null) { |
Winson Chung | b3347bb | 2010-08-19 14:51:28 -0700 | [diff] [blame] | 3495 | mCustomizePagedView.update(); |
Winson Chung | 5f94172 | 2010-09-28 16:36:43 -0700 | [diff] [blame] | 3496 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | /** |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3500 | * Prints out out state for debugging. |
| 3501 | */ |
| 3502 | public void dumpState() { |
| 3503 | Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 3504 | Log.d(TAG, "mSavedState=" + mSavedState); |
Joe Onorato | 39bfc13 | 2009-11-18 17:22:01 -0800 | [diff] [blame] | 3505 | Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); |
| 3506 | Log.d(TAG, "mRestoring=" + mRestoring); |
| 3507 | Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); |
| 3508 | Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); |
| 3509 | Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size()); |
Brad Fitzpatrick | 319226a | 2010-09-01 13:45:16 -0700 | [diff] [blame] | 3510 | Log.d(TAG, "sFolders.size=" + sFolders.size()); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 3511 | mModel.dumpState(); |
| 3512 | mAllAppsGrid.dumpState(); |
| 3513 | Log.d(TAG, "END launcher2 dump state"); |
| 3514 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3515 | } |