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