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