Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher2; |
| 18 | |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 19 | import com.android.launcher.R; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 20 | |
| 21 | import android.content.ComponentName; |
| 22 | import android.content.Context; |
Michael Jurka | 72b079e | 2010-12-10 01:03:53 -0800 | [diff] [blame] | 23 | import android.content.res.Resources; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 24 | import android.content.res.TypedArray; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 25 | import android.graphics.Bitmap; |
| 26 | import android.graphics.Canvas; |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 27 | import android.graphics.Rect; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 28 | import android.graphics.drawable.Drawable; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 29 | import android.util.AttributeSet; |
| 30 | import android.view.LayoutInflater; |
| 31 | import android.view.View; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 32 | import android.view.animation.AnimationUtils; |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 33 | import android.widget.Checkable; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 34 | import android.widget.TextView; |
| 35 | |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 36 | import java.util.ArrayList; |
| 37 | import java.util.Collections; |
| 38 | import java.util.HashSet; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * An implementation of PagedView that populates the pages of the workspace |
| 42 | * with all of the user's applications. |
| 43 | */ |
Michael Jurka | 72b079e | 2010-12-10 01:03:53 -0800 | [diff] [blame] | 44 | public class AllAppsPagedView extends PagedViewWithDraggableItems implements AllAppsView, |
| 45 | View.OnClickListener, DragSource, DropTarget { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 46 | |
| 47 | private static final String TAG = "AllAppsPagedView"; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 48 | |
| 49 | private Launcher mLauncher; |
| 50 | private DragController mDragController; |
| 51 | |
| 52 | // preserve compatibility with 3D all apps: |
| 53 | // 0.0 -> hidden |
| 54 | // 1.0 -> shown and opaque |
| 55 | // intermediate values -> partially shown & partially opaque |
| 56 | private float mZoom; |
| 57 | |
| 58 | // set of all applications |
| 59 | private ArrayList<ApplicationInfo> mApps; |
| 60 | private ArrayList<ApplicationInfo> mFilteredApps; |
| 61 | |
| 62 | // the types of applications to filter |
| 63 | static final int ALL_APPS_FLAG = -1; |
| 64 | private int mAppFilter = ALL_APPS_FLAG; |
| 65 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 66 | private final LayoutInflater mInflater; |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 67 | private boolean mAllowHardwareLayerCreation; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 68 | |
Michael Jurka | 7ef959b | 2011-02-23 11:48:32 -0800 | [diff] [blame] | 69 | private int mPageContentWidth; |
Winson Chung | 20f7111 | 2011-04-06 14:22:04 -0700 | [diff] [blame] | 70 | private boolean mHasMadeSuccessfulDrop; |
Patrick Dubroy | dea9e93 | 2010-09-22 15:04:29 -0700 | [diff] [blame] | 71 | |
Patrick Dubroy | 244d74c | 2011-05-19 16:48:48 -0700 | [diff] [blame] | 72 | private int mLastMeasureWidth = -1; |
| 73 | private int mLastMeasureHeight = -1; |
| 74 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 75 | public AllAppsPagedView(Context context) { |
| 76 | this(context, null); |
| 77 | } |
| 78 | |
| 79 | public AllAppsPagedView(Context context, AttributeSet attrs) { |
| 80 | this(context, attrs, 0); |
| 81 | } |
| 82 | |
| 83 | public AllAppsPagedView(Context context, AttributeSet attrs, int defStyle) { |
| 84 | super(context, attrs, defStyle); |
| 85 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 86 | mInflater = LayoutInflater.from(context); |
Winson Chung | 8b53478 | 2011-02-23 13:43:59 -0800 | [diff] [blame] | 87 | mApps = new ArrayList<ApplicationInfo>(); |
| 88 | mFilteredApps = new ArrayList<ApplicationInfo>(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 89 | a.recycle(); |
| 90 | setSoundEffectsEnabled(false); |
Michael Jurka | 72b079e | 2010-12-10 01:03:53 -0800 | [diff] [blame] | 91 | |
| 92 | Resources r = context.getResources(); |
| 93 | setDragSlopeThreshold( |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 94 | r.getInteger(R.integer.config_appsCustomizeDragSlopeThreshold) / 100.0f); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Override |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 98 | protected void init() { |
| 99 | super.init(); |
| 100 | mCenterPagesVertically = false; |
| 101 | } |
| 102 | |
Michael Jurka | 4c6016f | 2011-05-17 18:21:03 -0700 | [diff] [blame] | 103 | @Override |
| 104 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Patrick Dubroy | 244d74c | 2011-05-19 16:48:48 -0700 | [diff] [blame] | 105 | final int width = MeasureSpec.getSize(widthMeasureSpec); |
| 106 | final int height = MeasureSpec.getSize(heightMeasureSpec); |
Michael Jurka | 4c6016f | 2011-05-17 18:21:03 -0700 | [diff] [blame] | 107 | |
Patrick Dubroy | 244d74c | 2011-05-19 16:48:48 -0700 | [diff] [blame] | 108 | if (mLastMeasureWidth != width || mLastMeasureHeight != height) { |
Michael Jurka | 4c6016f | 2011-05-17 18:21:03 -0700 | [diff] [blame] | 109 | // Create a dummy page and set it up to find out the content width (used by our parent) |
| 110 | PagedViewCellLayout layout = new PagedViewCellLayout(getContext()); |
| 111 | setupPage(layout); |
| 112 | mPageContentWidth = layout.getContentWidth(); |
Patrick Dubroy | 244d74c | 2011-05-19 16:48:48 -0700 | [diff] [blame] | 113 | |
| 114 | mCellCountX = determineCellCountX(width, layout); |
| 115 | mCellCountY = determineCellCountY(height, layout); |
| 116 | mLastMeasureWidth = width; |
| 117 | mLastMeasureHeight = height; |
Michael Jurka | 4c6016f | 2011-05-17 18:21:03 -0700 | [diff] [blame] | 118 | } |
Patrick Dubroy | 244d74c | 2011-05-19 16:48:48 -0700 | [diff] [blame] | 119 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 124 | if (mFirstLayout) { |
| 125 | invalidatePageData(); |
| 126 | |
| 127 | // invalidatePageData() is what causes the child pages to be created. We need the |
| 128 | // children to be measured before layout, so force a new measure here. |
| 129 | measure(MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY), |
| 130 | MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY)); |
| 131 | } |
| 132 | super.onLayout(changed, left, top, right, bottom); |
| 133 | } |
| 134 | |
| 135 | private int determineCellCountX(int availableWidth, PagedViewCellLayout layout) { |
| 136 | int cellCountX = 0; |
| 137 | final int cellWidth = layout.getCellWidth(); |
| 138 | |
| 139 | // Subtract padding for current page and adjacent pages |
| 140 | availableWidth -= mPageLayoutPaddingLeft * 2 + mPageLayoutPaddingRight * 2; |
| 141 | |
| 142 | availableWidth -= cellWidth; // Assume at least one column |
| 143 | cellCountX = 1 + availableWidth / (cellWidth + mPageLayoutWidthGap); |
| 144 | availableWidth = availableWidth % (cellWidth + mPageLayoutWidthGap); |
| 145 | |
| 146 | // Ensures that we show at least 30% of the holo icons on each side |
| 147 | final int minLeftoverWidth = (int) (cellWidth * 0.6f); |
| 148 | |
| 149 | // Reserve room for the holo outlines |
| 150 | if (cellCountX <= 4) { |
| 151 | // When we're really tight on space, just pack the icons a bit closer together |
| 152 | final int missingWidth = minLeftoverWidth - availableWidth; |
| 153 | if (missingWidth > 0) { |
| 154 | mPageLayoutWidthGap -= Math.ceil(missingWidth * 1.0f / (cellCountX - 1)); |
| 155 | } |
| 156 | } else { |
| 157 | if (cellCountX >= 8) { |
| 158 | // Carve out a few extra columns for very large widths |
| 159 | cellCountX = (int) (cellCountX * 0.9f); |
| 160 | } else if (availableWidth < minLeftoverWidth) { |
| 161 | cellCountX -= 1; |
| 162 | } |
| 163 | } |
| 164 | return cellCountX; |
| 165 | } |
| 166 | |
| 167 | private int determineCellCountY(int availableHeight, PagedViewCellLayout layout) { |
| 168 | final int cellHeight = layout.getCellHeight(); |
| 169 | final int screenHeight = mLauncher.getResources().getDisplayMetrics().heightPixels; |
| 170 | |
| 171 | availableHeight -= mPageLayoutPaddingTop + mPageLayoutPaddingBottom; |
| 172 | availableHeight -= cellHeight; // Assume at least one row |
| 173 | availableHeight -= screenHeight * 0.16f; |
| 174 | return (1 + availableHeight / (cellHeight + mPageLayoutHeightGap)); |
Michael Jurka | 4c6016f | 2011-05-17 18:21:03 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 177 | void allowHardwareLayerCreation() { |
| 178 | // This is called after the first time we launch into All Apps. Before that point, |
| 179 | // there's no need for hardware layers here since there's a hardware layer set on the |
| 180 | // parent, AllAppsTabbed, during the AllApps transition -- creating hardware layers here |
| 181 | // before the animation is done slows down the animation |
| 182 | if (mAllowHardwareLayerCreation) { |
| 183 | return; |
| 184 | } |
| 185 | mAllowHardwareLayerCreation = true; |
| 186 | int childCount = getChildCount(); |
| 187 | for (int i = 0; i < childCount; i++) { |
| 188 | PagedViewCellLayout page = (PagedViewCellLayout) getChildAt(i); |
| 189 | page.allowHardwareLayerCreation(); |
| 190 | } |
| 191 | } |
| 192 | |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 193 | @Override |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 194 | public void setup(Launcher launcher, DragController dragController) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 195 | mLauncher = launcher; |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 196 | mLauncher.setAllAppsPagedView(this); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 197 | mDragController = dragController; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | public void setAppFilter(int filterType) { |
| 201 | mAppFilter = filterType; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 202 | if (mApps != null) { |
| 203 | mFilteredApps = rebuildFilteredApps(mApps); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 204 | setCurrentPage(0); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 205 | invalidatePageData(); |
| 206 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Winson Chung | 20f7111 | 2011-04-06 14:22:04 -0700 | [diff] [blame] | 209 | void resetSuccessfulDropFlag() { |
| 210 | mHasMadeSuccessfulDrop = false; |
| 211 | } |
| 212 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 213 | @Override |
| 214 | public void zoom(float zoom, boolean animate) { |
| 215 | mZoom = zoom; |
| 216 | cancelLongPress(); |
| 217 | |
| 218 | if (isVisible()) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 219 | if (animate) { |
| 220 | startAnimation(AnimationUtils.loadAnimation(getContext(), |
| 221 | R.anim.all_apps_2d_fade_in)); |
| 222 | } else { |
| 223 | onAnimationEnd(); |
| 224 | } |
| 225 | } else { |
| 226 | if (animate) { |
| 227 | startAnimation(AnimationUtils.loadAnimation(getContext(), |
| 228 | R.anim.all_apps_2d_fade_out)); |
| 229 | } else { |
| 230 | onAnimationEnd(); |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | protected void onAnimationEnd() { |
| 236 | if (!isVisible()) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 237 | mZoom = 0.0f; |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 238 | |
| 239 | endChoiceMode(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 240 | } else { |
| 241 | mZoom = 1.0f; |
| 242 | } |
| 243 | |
| 244 | if (mLauncher != null) |
| 245 | mLauncher.zoomed(mZoom); |
| 246 | } |
| 247 | |
| 248 | private int getChildIndexForGrandChild(View v) { |
| 249 | final int childCount = getChildCount(); |
| 250 | for (int i = 0; i < childCount; ++i) { |
Michael Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 251 | final Page layout = (Page) getChildAt(i); |
| 252 | if (layout.indexOfChildOnPage(v) > -1) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 253 | return i; |
| 254 | } |
| 255 | } |
| 256 | return -1; |
| 257 | } |
| 258 | |
| 259 | @Override |
| 260 | public void onClick(View v) { |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 261 | // if we are already in a choice mode, then just change the selection |
| 262 | if (v instanceof Checkable) { |
| 263 | if (!isChoiceMode(CHOICE_MODE_NONE)) { |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 264 | Checkable c = (Checkable) v; |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 265 | if (isChoiceMode(CHOICE_MODE_SINGLE)) { |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 266 | // Uncheck all the other grandchildren, and toggle the clicked one |
| 267 | boolean wasChecked = c.isChecked(); |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 268 | resetCheckedGrandchildren(); |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 269 | c.setChecked(!wasChecked); |
| 270 | } else { |
| 271 | c.toggle(); |
| 272 | } |
| 273 | if (getCheckedGrandchildren().size() == 0) { |
| 274 | endChoiceMode(); |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 277 | return; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | // otherwise continue and launch the application |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 282 | int childIndex = getChildIndexForGrandChild(v); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 283 | if (childIndex == getCurrentPage()) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 284 | final ApplicationInfo app = (ApplicationInfo) v.getTag(); |
| 285 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 286 | // animate some feedback to the click |
| 287 | animateClickFeedback(v, new Runnable() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 288 | @Override |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 289 | public void run() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 290 | mLauncher.startActivitySafely(app.intent, app); |
| 291 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 292 | }); |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 293 | |
| 294 | endChoiceMode(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
Patrick Dubroy | cd95371 | 2011-02-28 15:16:42 -0800 | [diff] [blame] | 298 | private void setupDragMode(ApplicationInfo info) { |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 299 | mLauncher.getWorkspace().shrink(Workspace.ShrinkState.BOTTOM_VISIBLE); |
Patrick Dubroy | cd95371 | 2011-02-28 15:16:42 -0800 | [diff] [blame] | 300 | |
| 301 | // Only show the uninstall button if the app is uninstallable. |
| 302 | if ((info.flags & ApplicationInfo.DOWNLOADED_FLAG) != 0) { |
| 303 | DeleteZone allAppsDeleteZone = (DeleteZone) |
| 304 | mLauncher.findViewById(R.id.all_apps_delete_zone); |
| 305 | allAppsDeleteZone.setDragAndDropEnabled(true); |
| 306 | |
| 307 | if ((info.flags & ApplicationInfo.UPDATED_SYSTEM_APP_FLAG) != 0) { |
| 308 | allAppsDeleteZone.setText(R.string.delete_zone_label_all_apps_system_app); |
| 309 | } else { |
| 310 | allAppsDeleteZone.setText(R.string.delete_zone_label_all_apps); |
| 311 | } |
| 312 | } |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 313 | |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 314 | ApplicationInfoDropTarget allAppsInfoButton = |
| 315 | (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target); |
| 316 | allAppsInfoButton.setDragAndDropEnabled(true); |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | private void tearDownDragMode() { |
| 320 | post(new Runnable() { |
| 321 | // Once the drag operation has fully completed, hence the post, we want to disable the |
| 322 | // deleteZone and the appInfoButton in all apps, and re-enable the instance which |
| 323 | // live in the workspace |
| 324 | public void run() { |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 325 | DeleteZone allAppsDeleteZone = |
| 326 | (DeleteZone) mLauncher.findViewById(R.id.all_apps_delete_zone); |
Michael Jurka | c31820d | 2011-01-16 16:57:05 -0800 | [diff] [blame] | 327 | // if onDestroy was called on Launcher, we might have already deleted the |
| 328 | // all apps delete zone / info button, so check if they are null |
| 329 | if (allAppsDeleteZone != null) allAppsDeleteZone.setDragAndDropEnabled(false); |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 330 | |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 331 | ApplicationInfoDropTarget allAppsInfoButton = |
| 332 | (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target); |
Michael Jurka | c31820d | 2011-01-16 16:57:05 -0800 | [diff] [blame] | 333 | if (allAppsInfoButton != null) allAppsInfoButton.setDragAndDropEnabled(false); |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 334 | } |
| 335 | }); |
| 336 | resetCheckedGrandchildren(); |
| 337 | mDragController.removeDropTarget(this); |
| 338 | } |
| 339 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 340 | @Override |
Michael Jurka | 72b079e | 2010-12-10 01:03:53 -0800 | [diff] [blame] | 341 | protected boolean beginDragging(View v) { |
Winson Chung | 304dcde | 2011-01-07 11:17:23 -0800 | [diff] [blame] | 342 | if (!v.isInTouchMode()) return false; |
| 343 | if (!super.beginDragging(v)) return false; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 344 | |
| 345 | ApplicationInfo app = (ApplicationInfo) v.getTag(); |
| 346 | app = new ApplicationInfo(app); |
| 347 | |
Patrick Dubroy | cd95371 | 2011-02-28 15:16:42 -0800 | [diff] [blame] | 348 | // Start drag mode after the item is selected |
| 349 | setupDragMode(app); |
| 350 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 351 | // get icon (top compound drawable, index is 1) |
Winson Chung | cd4bc49 | 2010-12-09 18:52:32 -0800 | [diff] [blame] | 352 | final TextView tv = (TextView) v; |
| 353 | final Drawable icon = tv.getCompoundDrawables()[1]; |
| 354 | Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 355 | Bitmap.Config.ARGB_8888); |
| 356 | Canvas c = new Canvas(b); |
Winson Chung | cd4bc49 | 2010-12-09 18:52:32 -0800 | [diff] [blame] | 357 | c.translate((v.getWidth() - icon.getIntrinsicWidth()) / 2, v.getPaddingTop()); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 358 | icon.draw(c); |
Winson Chung | cd4bc49 | 2010-12-09 18:52:32 -0800 | [diff] [blame] | 359 | |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 360 | Rect dragRect = null; |
| 361 | if (v instanceof TextView) { |
| 362 | int iconSize = getResources().getDimensionPixelSize(R.dimen.app_icon_size); |
| 363 | int top = v.getPaddingTop(); |
| 364 | int left = (b.getWidth() - iconSize) / 2; |
| 365 | int right = left + iconSize; |
| 366 | int bottom = top + iconSize; |
| 367 | dragRect = new Rect(left, top, right, bottom); |
| 368 | } |
| 369 | |
Winson Chung | cd4bc49 | 2010-12-09 18:52:32 -0800 | [diff] [blame] | 370 | // We toggle the checked state _after_ we create the view for the drag in case toggling the |
| 371 | // checked state changes the view's look |
| 372 | if (v instanceof Checkable) { |
| 373 | // In preparation for drag, we always reset the checked grand children regardless of |
| 374 | // what choice mode we are in |
| 375 | resetCheckedGrandchildren(); |
| 376 | |
| 377 | // Toggle the selection on the dragged app |
| 378 | Checkable checkable = (Checkable) v; |
Winson Chung | 59e1f9a | 2010-12-21 11:31:54 -0800 | [diff] [blame] | 379 | |
| 380 | // Note: we toggle the checkable state to actually cause an alpha fade for the duration |
| 381 | // of the drag of the item. (The fade-in will occur when all checked states are |
| 382 | // disabled when dragging ends) |
Winson Chung | cd4bc49 | 2010-12-09 18:52:32 -0800 | [diff] [blame] | 383 | checkable.toggle(); |
| 384 | } |
| 385 | |
| 386 | // Start the drag |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 387 | mLauncher.lockScreenOrientation(); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 388 | mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 389 | mDragController.startDrag(v, b, this, app, DragController.DRAG_ACTION_COPY, dragRect); |
Winson Chung | cd4bc49 | 2010-12-09 18:52:32 -0800 | [diff] [blame] | 390 | b.recycle(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 391 | return true; |
| 392 | } |
| 393 | |
| 394 | @Override |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 395 | public void onDragViewVisible() { |
| 396 | } |
| 397 | |
| 398 | @Override |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 399 | public void onDropCompleted(View target, Object dragInfo, boolean success) { |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 400 | // close the choice action mode if we have a proper drop |
| 401 | if (target != this) { |
| 402 | endChoiceMode(); |
| 403 | } |
Adam Cohen | cdc30d5 | 2010-12-01 15:09:47 -0800 | [diff] [blame] | 404 | tearDownDragMode(); |
Patrick Dubroy | 7bccb42 | 2011-01-20 14:50:55 -0800 | [diff] [blame] | 405 | mLauncher.getWorkspace().onDragStopped(success); |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 406 | mLauncher.unlockScreenOrientation(); |
Winson Chung | 20f7111 | 2011-04-06 14:22:04 -0700 | [diff] [blame] | 407 | |
| 408 | if (!success && !mHasMadeSuccessfulDrop) { |
| 409 | mLauncher.getWorkspace().shrink(Workspace.ShrinkState.BOTTOM_HIDDEN); |
| 410 | } else { |
| 411 | mHasMadeSuccessfulDrop |= success; |
| 412 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Michael Jurka | 7ef959b | 2011-02-23 11:48:32 -0800 | [diff] [blame] | 415 | int getPageContentWidth() { |
| 416 | return mPageContentWidth; |
| 417 | } |
| 418 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 419 | @Override |
| 420 | public boolean isVisible() { |
| 421 | return mZoom > 0.001f; |
| 422 | } |
| 423 | |
| 424 | @Override |
| 425 | public boolean isAnimating() { |
| 426 | return (getAnimation() != null); |
| 427 | } |
| 428 | |
| 429 | private ArrayList<ApplicationInfo> rebuildFilteredApps(ArrayList<ApplicationInfo> apps) { |
| 430 | ArrayList<ApplicationInfo> filteredApps = new ArrayList<ApplicationInfo>(); |
| 431 | if (mAppFilter == ALL_APPS_FLAG) { |
| 432 | return apps; |
| 433 | } else { |
| 434 | final int length = apps.size(); |
| 435 | for (int i = 0; i < length; ++i) { |
| 436 | ApplicationInfo info = apps.get(i); |
| 437 | if ((info.flags & mAppFilter) > 0) { |
| 438 | filteredApps.add(info); |
| 439 | } |
| 440 | } |
Winson Chung | 78403fe | 2011-01-21 15:38:02 -0800 | [diff] [blame] | 441 | Collections.sort(filteredApps, LauncherModel.APP_INSTALL_TIME_COMPARATOR); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 442 | } |
| 443 | return filteredApps; |
| 444 | } |
| 445 | |
| 446 | @Override |
| 447 | public void setApps(ArrayList<ApplicationInfo> list) { |
| 448 | mApps = list; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 449 | Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 450 | mFilteredApps = rebuildFilteredApps(mApps); |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 451 | mPageViewIconCache.retainAllApps(list); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 452 | invalidatePageData(); |
| 453 | } |
| 454 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 455 | private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { |
| 456 | // we add it in place, in alphabetical order |
| 457 | final int count = list.size(); |
| 458 | for (int i = 0; i < count; ++i) { |
| 459 | final ApplicationInfo info = list.get(i); |
| 460 | final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR); |
| 461 | if (index < 0) { |
| 462 | mApps.add(-(index + 1), info); |
Winson Chung | 452821f | 2011-01-14 16:39:47 -0800 | [diff] [blame] | 463 | } else { |
| 464 | mApps.add(index, info); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | mFilteredApps = rebuildFilteredApps(mApps); |
| 468 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 469 | @Override |
| 470 | public void addApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 471 | addAppsWithoutInvalidate(list); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 472 | invalidatePageData(); |
| 473 | } |
| 474 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 475 | private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { |
Winson Chung | 10fefb1 | 2010-11-01 11:57:06 -0700 | [diff] [blame] | 476 | // End the choice mode if any of the items in the list that are being removed are |
| 477 | // currently selected |
| 478 | ArrayList<Checkable> checkedList = getCheckedGrandchildren(); |
| 479 | HashSet<ApplicationInfo> checkedAppInfos = new HashSet<ApplicationInfo>(); |
| 480 | for (Checkable checked : checkedList) { |
| 481 | PagedViewIcon icon = (PagedViewIcon) checked; |
| 482 | checkedAppInfos.add((ApplicationInfo) icon.getTag()); |
| 483 | } |
| 484 | for (ApplicationInfo info : list) { |
| 485 | if (checkedAppInfos.contains(info)) { |
| 486 | endChoiceMode(); |
| 487 | break; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | // Loop through all the apps and remove apps that have the same component |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 492 | final int length = list.size(); |
| 493 | for (int i = 0; i < length; ++i) { |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 494 | final ApplicationInfo info = list.get(i); |
| 495 | int removeIndex = findAppByComponent(mApps, info); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 496 | if (removeIndex > -1) { |
| 497 | mApps.remove(removeIndex); |
Winson Chung | 0499834 | 2011-01-05 13:54:43 -0800 | [diff] [blame] | 498 | mPageViewIconCache.removeOutline(new PagedViewIconCache.Key(info)); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 499 | } |
| 500 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 501 | mFilteredApps = rebuildFilteredApps(mApps); |
| 502 | } |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 503 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 504 | @Override |
| 505 | public void removeApps(ArrayList<ApplicationInfo> list) { |
| 506 | removeAppsWithoutInvalidate(list); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 507 | invalidatePageData(); |
| 508 | } |
| 509 | |
| 510 | @Override |
| 511 | public void updateApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 512 | removeAppsWithoutInvalidate(list); |
| 513 | addAppsWithoutInvalidate(list); |
| 514 | invalidatePageData(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | private int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) { |
Winson Chung | 8b53478 | 2011-02-23 13:43:59 -0800 | [diff] [blame] | 518 | if (item != null && item.intent != null) { |
| 519 | ComponentName removeComponent = item.intent.getComponent(); |
| 520 | final int length = list.size(); |
| 521 | for (int i = 0; i < length; ++i) { |
| 522 | ApplicationInfo info = list.get(i); |
| 523 | if (info.intent.getComponent().equals(removeComponent)) { |
| 524 | return i; |
| 525 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | return -1; |
| 529 | } |
| 530 | |
| 531 | @Override |
| 532 | public void dumpState() { |
| 533 | ApplicationInfo.dumpApplicationInfoList(TAG, "mApps", mApps); |
| 534 | } |
| 535 | |
| 536 | @Override |
| 537 | public void surrender() { |
| 538 | // do nothing? |
| 539 | } |
| 540 | |
Winson Chung | 337cd9d | 2011-03-30 10:39:30 -0700 | [diff] [blame] | 541 | public void reset() { |
| 542 | setCurrentPage(0); |
| 543 | invalidatePageData(); |
| 544 | } |
| 545 | |
Michael Jurka | 7ef959b | 2011-02-23 11:48:32 -0800 | [diff] [blame] | 546 | private void setupPage(PagedViewCellLayout layout) { |
| 547 | layout.setCellCount(mCellCountX, mCellCountY); |
| 548 | layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, mPageLayoutPaddingRight, |
| 549 | mPageLayoutPaddingBottom); |
| 550 | layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap); |
| 551 | } |
| 552 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 553 | @Override |
| 554 | public void syncPages() { |
Patrick Dubroy | 244d74c | 2011-05-19 16:48:48 -0700 | [diff] [blame] | 555 | if (mCellCountX <= 0 || mCellCountY <= 0) { |
Michael Jurka | 4c6016f | 2011-05-17 18:21:03 -0700 | [diff] [blame] | 556 | // We don't know our size yet, which means we haven't calculated cell count x/y; |
| 557 | // onMeasure will call us once we figure out our size |
| 558 | return; |
| 559 | } |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 560 | // ensure that we have the right number of pages (min of 1, since we have placeholders) |
| 561 | int numPages = Math.max(1, |
| 562 | (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY))); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 563 | int curNumPages = getChildCount(); |
| 564 | // remove any extra pages after the "last" page |
| 565 | int extraPageDiff = curNumPages - numPages; |
| 566 | for (int i = 0; i < extraPageDiff; ++i) { |
| 567 | removeViewAt(numPages); |
| 568 | } |
| 569 | // add any necessary pages |
| 570 | for (int i = curNumPages; i < numPages; ++i) { |
| 571 | PagedViewCellLayout layout = new PagedViewCellLayout(getContext()); |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 572 | if (mAllowHardwareLayerCreation) { |
| 573 | layout.allowHardwareLayerCreation(); |
| 574 | } |
Michael Jurka | 7ef959b | 2011-02-23 11:48:32 -0800 | [diff] [blame] | 575 | setupPage(layout); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 576 | addView(layout); |
| 577 | } |
| 578 | |
| 579 | // bound the current page |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 580 | setCurrentPage(Math.max(0, Math.min(numPages - 1, getCurrentPage()))); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | @Override |
| 584 | public void syncPageItems(int page) { |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 585 | // Ensure that we have the right number of items on the pages |
Winson Chung | 63257c1 | 2011-05-05 17:06:13 -0700 | [diff] [blame] | 586 | final int numPages = getPageCount(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 587 | final int cellsPerPage = mCellCountX * mCellCountY; |
| 588 | final int startIndex = page * cellsPerPage; |
| 589 | final int endIndex = Math.min(startIndex + cellsPerPage, mFilteredApps.size()); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 590 | PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 591 | |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 592 | if (!mFilteredApps.isEmpty()) { |
Michael Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 593 | int curNumPageItems = layout.getPageChildCount(); |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 594 | int numPageItems = endIndex - startIndex; |
Winson Chung | 6a70e9f | 2011-05-17 16:24:49 -0700 | [diff] [blame] | 595 | boolean createHolographicOutlines = (numPages > 1); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 596 | |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 597 | // If we were previously an empty page, then restart anew |
| 598 | boolean wasEmptyPage = false; |
| 599 | if (curNumPageItems == 1) { |
Michael Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 600 | View icon = layout.getChildOnPageAt(0); |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 601 | if (icon.getTag() == null) { |
| 602 | wasEmptyPage = true; |
| 603 | } |
| 604 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 605 | |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 606 | if (wasEmptyPage) { |
| 607 | // Remove all the previous items |
| 608 | curNumPageItems = 0; |
Michael Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 609 | layout.removeAllViewsOnPage(); |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 610 | } else { |
| 611 | // Remove any extra items |
| 612 | int extraPageItemsDiff = curNumPageItems - numPageItems; |
| 613 | for (int i = 0; i < extraPageItemsDiff; ++i) { |
Michael Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 614 | layout.removeViewOnPageAt(numPageItems); |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 615 | } |
| 616 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 617 | |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 618 | // Add any necessary items |
| 619 | for (int i = curNumPageItems; i < numPageItems; ++i) { |
| 620 | TextView text = (TextView) mInflater.inflate( |
| 621 | R.layout.all_apps_paged_view_application, layout, false); |
| 622 | text.setOnClickListener(this); |
| 623 | text.setOnLongClickListener(this); |
Michael Jurka | 72b079e | 2010-12-10 01:03:53 -0800 | [diff] [blame] | 624 | text.setOnTouchListener(this); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 625 | |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 626 | layout.addViewToCellLayout(text, -1, i, |
Winson Chung | 6a70e9f | 2011-05-17 16:24:49 -0700 | [diff] [blame] | 627 | new PagedViewCellLayout.LayoutParams(0, 0, 1, 1)); |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | // Actually reapply to the existing text views |
| 631 | for (int i = startIndex; i < endIndex; ++i) { |
| 632 | final int index = i - startIndex; |
| 633 | final ApplicationInfo info = mFilteredApps.get(i); |
Michael Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 634 | PagedViewIcon icon = (PagedViewIcon) layout.getChildOnPageAt(index); |
Michael Jurka | b9b8ce9 | 2011-05-05 15:05:07 -0700 | [diff] [blame] | 635 | icon.applyFromApplicationInfo( |
Winson Chung | 63257c1 | 2011-05-05 17:06:13 -0700 | [diff] [blame] | 636 | info, mPageViewIconCache, true, createHolographicOutlines); |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 637 | |
| 638 | PagedViewCellLayout.LayoutParams params = |
| 639 | (PagedViewCellLayout.LayoutParams) icon.getLayoutParams(); |
| 640 | params.cellX = index % mCellCountX; |
| 641 | params.cellY = index / mCellCountX; |
| 642 | } |
| 643 | |
Winson Chung | 6a70e9f | 2011-05-17 16:24:49 -0700 | [diff] [blame] | 644 | // We should try and sync all the holographic icons after adding/removing new items |
| 645 | layout.reloadHolographicIcons(createHolographicOutlines); |
| 646 | |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 647 | // Default to left-aligned icons |
| 648 | layout.enableCenteredContent(false); |
| 649 | } else { |
| 650 | // There are no items, so show the user a small message |
| 651 | TextView icon = (TextView) mInflater.inflate( |
| 652 | R.layout.all_apps_no_items_placeholder, layout, false); |
| 653 | switch (mAppFilter) { |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 654 | case ApplicationInfo.DOWNLOADED_FLAG: |
| 655 | icon.setText(mContext.getString(R.string.all_apps_no_downloads)); |
| 656 | break; |
| 657 | default: break; |
| 658 | } |
| 659 | |
| 660 | // Center-align the message |
Winson Chung | dd25902 | 2011-05-10 15:59:42 -0700 | [diff] [blame] | 661 | final boolean createHolographicOutlines = (numPages > 1); |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 662 | layout.enableCenteredContent(true); |
Michael Jurka | 8245a86 | 2011-02-01 17:53:59 -0800 | [diff] [blame] | 663 | layout.removeAllViewsOnPage(); |
Winson Chung | 9678557 | 2010-10-14 13:37:13 -0700 | [diff] [blame] | 664 | layout.addViewToCellLayout(icon, -1, 0, |
Winson Chung | 6a70e9f | 2011-05-17 16:24:49 -0700 | [diff] [blame] | 665 | new PagedViewCellLayout.LayoutParams(0, 0, 4, 1)); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 666 | } |
Michael Jurka | c5e4902 | 2011-02-16 12:04:02 -0800 | [diff] [blame] | 667 | layout.createHardwareLayers(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 668 | } |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 669 | |
| 670 | /* |
| 671 | * We don't actually use AllAppsPagedView as a drop target... it's only used to intercept a drop |
| 672 | * to the workspace. |
| 673 | */ |
| 674 | @Override |
| 675 | public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset, |
| 676 | DragView dragView, Object dragInfo) { |
| 677 | return false; |
| 678 | } |
| 679 | @Override |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 680 | public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, |
| 681 | int yOffset, DragView dragView, Object dragInfo) { |
| 682 | return null; |
| 683 | } |
| 684 | @Override |
| 685 | public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, |
| 686 | DragView dragView, Object dragInfo) {} |
| 687 | @Override |
| 688 | public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, |
| 689 | DragView dragView, Object dragInfo) {} |
| 690 | @Override |
| 691 | public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, |
| 692 | DragView dragView, Object dragInfo) {} |
| 693 | @Override |
| 694 | public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, |
| 695 | DragView dragView, Object dragInfo) {} |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 696 | |
| 697 | public boolean isDropEnabled() { |
| 698 | return true; |
| 699 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 700 | } |