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