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 | |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 19 | import com.android.launcher.R; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 20 | |
| 21 | import android.content.ComponentName; |
| 22 | import android.content.Context; |
| 23 | import android.content.res.TypedArray; |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 24 | import android.graphics.Rect; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 25 | import android.util.AttributeSet; |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 26 | import android.util.Log; |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 27 | import android.view.ActionMode; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 28 | import android.view.LayoutInflater; |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 29 | import android.view.Menu; |
| 30 | import android.view.MenuItem; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 31 | import android.view.View; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 32 | import android.view.animation.AnimationUtils; |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 33 | import android.widget.Checkable; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 34 | import android.widget.TextView; |
| 35 | |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 36 | import java.util.ArrayList; |
| 37 | import java.util.Collections; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * An implementation of PagedView that populates the pages of the workspace |
| 41 | * with all of the user's applications. |
| 42 | */ |
| 43 | public class AllAppsPagedView extends PagedView |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 44 | implements AllAppsView, View.OnClickListener, View.OnLongClickListener, DragSource, |
| 45 | DropTarget, ActionMode.Callback { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 46 | |
| 47 | private static final String TAG = "AllAppsPagedView"; |
| 48 | private static final boolean DEBUG = false; |
| 49 | |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 50 | private static final int MENU_DELETE_APP = 1; |
| 51 | private static final int MENU_APP_INFO = 2; |
| 52 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 53 | private Launcher mLauncher; |
| 54 | private DragController mDragController; |
| 55 | |
| 56 | // preserve compatibility with 3D all apps: |
| 57 | // 0.0 -> hidden |
| 58 | // 1.0 -> shown and opaque |
| 59 | // intermediate values -> partially shown & partially opaque |
| 60 | private float mZoom; |
| 61 | |
| 62 | // set of all applications |
| 63 | private ArrayList<ApplicationInfo> mApps; |
| 64 | private ArrayList<ApplicationInfo> mFilteredApps; |
| 65 | |
| 66 | // the types of applications to filter |
| 67 | static final int ALL_APPS_FLAG = -1; |
| 68 | private int mAppFilter = ALL_APPS_FLAG; |
| 69 | |
| 70 | private int mCellCountX; |
| 71 | private int mCellCountY; |
| 72 | |
| 73 | private final LayoutInflater mInflater; |
| 74 | |
| 75 | public AllAppsPagedView(Context context) { |
| 76 | this(context, null); |
| 77 | } |
| 78 | |
| 79 | public AllAppsPagedView(Context context, AttributeSet attrs) { |
| 80 | this(context, attrs, 0); |
| 81 | } |
| 82 | |
| 83 | public AllAppsPagedView(Context context, AttributeSet attrs, int defStyle) { |
| 84 | super(context, attrs, defStyle); |
| 85 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0); |
| 86 | mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 6); |
| 87 | mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4); |
| 88 | mInflater = LayoutInflater.from(context); |
| 89 | a.recycle(); |
| 90 | setSoundEffectsEnabled(false); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public void setLauncher(Launcher launcher) { |
| 95 | mLauncher = launcher; |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 96 | mLauncher.setAllAppsPagedView(this); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public void setDragController(DragController dragger) { |
| 101 | mDragController = dragger; |
| 102 | } |
| 103 | |
| 104 | public void setAppFilter(int filterType) { |
| 105 | mAppFilter = filterType; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 106 | if (mApps != null) { |
| 107 | mFilteredApps = rebuildFilteredApps(mApps); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 108 | setCurrentPage(0); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 109 | invalidatePageData(); |
| 110 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public void zoom(float zoom, boolean animate) { |
| 115 | mZoom = zoom; |
| 116 | cancelLongPress(); |
| 117 | |
| 118 | if (isVisible()) { |
| 119 | getParent().bringChildToFront(this); |
| 120 | setVisibility(View.VISIBLE); |
| 121 | if (animate) { |
| 122 | startAnimation(AnimationUtils.loadAnimation(getContext(), |
| 123 | R.anim.all_apps_2d_fade_in)); |
| 124 | } else { |
| 125 | onAnimationEnd(); |
| 126 | } |
| 127 | } else { |
| 128 | if (animate) { |
| 129 | startAnimation(AnimationUtils.loadAnimation(getContext(), |
| 130 | R.anim.all_apps_2d_fade_out)); |
| 131 | } else { |
| 132 | onAnimationEnd(); |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | protected void onAnimationEnd() { |
| 138 | if (!isVisible()) { |
| 139 | setVisibility(View.GONE); |
| 140 | mZoom = 0.0f; |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 141 | |
| 142 | endChoiceMode(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 143 | } else { |
| 144 | mZoom = 1.0f; |
| 145 | } |
| 146 | |
| 147 | if (mLauncher != null) |
| 148 | mLauncher.zoomed(mZoom); |
| 149 | } |
| 150 | |
| 151 | private int getChildIndexForGrandChild(View v) { |
| 152 | final int childCount = getChildCount(); |
| 153 | for (int i = 0; i < childCount; ++i) { |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 154 | final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 155 | if (layout.indexOfChild(v) > -1) { |
| 156 | return i; |
| 157 | } |
| 158 | } |
| 159 | return -1; |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public void onClick(View v) { |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 164 | // if we are already in a choice mode, then just change the selection |
| 165 | if (v instanceof Checkable) { |
| 166 | if (!isChoiceMode(CHOICE_MODE_NONE)) { |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 167 | Checkable c = (Checkable) v; |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 168 | if (isChoiceMode(CHOICE_MODE_SINGLE)) { |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 169 | // Uncheck all the other grandchildren, and toggle the clicked one |
| 170 | boolean wasChecked = c.isChecked(); |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 171 | resetCheckedGrandchildren(); |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 172 | c.setChecked(!wasChecked); |
| 173 | } else { |
| 174 | c.toggle(); |
| 175 | } |
| 176 | if (getCheckedGrandchildren().size() == 0) { |
| 177 | endChoiceMode(); |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 180 | return; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | // otherwise continue and launch the application |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 185 | int childIndex = getChildIndexForGrandChild(v); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 186 | if (childIndex == getCurrentPage()) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 187 | final ApplicationInfo app = (ApplicationInfo) v.getTag(); |
| 188 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 189 | // animate some feedback to the click |
| 190 | animateClickFeedback(v, new Runnable() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 191 | @Override |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 192 | public void run() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 193 | mLauncher.startActivitySafely(app.intent, app); |
| 194 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 195 | }); |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 196 | |
| 197 | endChoiceMode(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public boolean onLongClick(View v) { |
| 203 | if (!v.isInTouchMode()) { |
| 204 | return false; |
| 205 | } |
| 206 | |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 207 | // start the choice mode, and select the item that was long-pressed |
| 208 | if (isChoiceMode(CHOICE_MODE_NONE)) { |
| 209 | startChoiceMode(CHOICE_MODE_SINGLE, this); |
| 210 | } |
| 211 | |
| 212 | if (v instanceof Checkable) { |
| 213 | // In preparation for drag, we always reset the checked grand children regardless of |
| 214 | // what choice mode we are in |
| 215 | resetCheckedGrandchildren(); |
| 216 | |
| 217 | // Toggle the selection on the dragged app |
| 218 | Checkable c = (Checkable) v; |
| 219 | c.toggle(); |
| 220 | } |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 221 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 222 | ApplicationInfo app = (ApplicationInfo) v.getTag(); |
| 223 | app = new ApplicationInfo(app); |
| 224 | |
| 225 | mDragController.startDrag(v, this, app, DragController.DRAG_ACTION_COPY); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 226 | return true; |
| 227 | } |
| 228 | |
| 229 | @Override |
| 230 | public void onDropCompleted(View target, boolean success) { |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 231 | // close the choice action mode if we have a proper drop |
| 232 | if (target != this) { |
| 233 | endChoiceMode(); |
| 234 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | @Override |
| 238 | public boolean isVisible() { |
| 239 | return mZoom > 0.001f; |
| 240 | } |
| 241 | |
| 242 | @Override |
| 243 | public boolean isAnimating() { |
| 244 | return (getAnimation() != null); |
| 245 | } |
| 246 | |
| 247 | private ArrayList<ApplicationInfo> rebuildFilteredApps(ArrayList<ApplicationInfo> apps) { |
| 248 | ArrayList<ApplicationInfo> filteredApps = new ArrayList<ApplicationInfo>(); |
| 249 | if (mAppFilter == ALL_APPS_FLAG) { |
| 250 | return apps; |
| 251 | } else { |
| 252 | final int length = apps.size(); |
| 253 | for (int i = 0; i < length; ++i) { |
| 254 | ApplicationInfo info = apps.get(i); |
| 255 | if ((info.flags & mAppFilter) > 0) { |
| 256 | filteredApps.add(info); |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | return filteredApps; |
| 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public void setApps(ArrayList<ApplicationInfo> list) { |
| 265 | mApps = list; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 266 | Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 267 | mFilteredApps = rebuildFilteredApps(mApps); |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 268 | mPageViewIconCache.clear(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 269 | invalidatePageData(); |
| 270 | } |
| 271 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 272 | private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { |
| 273 | // we add it in place, in alphabetical order |
| 274 | final int count = list.size(); |
| 275 | for (int i = 0; i < count; ++i) { |
| 276 | final ApplicationInfo info = list.get(i); |
| 277 | final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR); |
| 278 | if (index < 0) { |
| 279 | mApps.add(-(index + 1), info); |
| 280 | } |
| 281 | } |
| 282 | mFilteredApps = rebuildFilteredApps(mApps); |
| 283 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 284 | @Override |
| 285 | public void addApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 286 | addAppsWithoutInvalidate(list); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 287 | invalidatePageData(); |
| 288 | } |
| 289 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 290 | private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 291 | // loop through all the apps and remove apps that have the same component |
| 292 | final int length = list.size(); |
| 293 | for (int i = 0; i < length; ++i) { |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 294 | final ApplicationInfo info = list.get(i); |
| 295 | int removeIndex = findAppByComponent(mApps, info); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 296 | if (removeIndex > -1) { |
| 297 | mApps.remove(removeIndex); |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 298 | mPageViewIconCache.removeOutline(info); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 301 | mFilteredApps = rebuildFilteredApps(mApps); |
| 302 | } |
| 303 | @Override |
| 304 | public void removeApps(ArrayList<ApplicationInfo> list) { |
| 305 | removeAppsWithoutInvalidate(list); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 306 | invalidatePageData(); |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public void updateApps(ArrayList<ApplicationInfo> list) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 311 | removeAppsWithoutInvalidate(list); |
| 312 | addAppsWithoutInvalidate(list); |
| 313 | invalidatePageData(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | private int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) { |
| 317 | ComponentName removeComponent = item.intent.getComponent(); |
| 318 | final int length = list.size(); |
| 319 | for (int i = 0; i < length; ++i) { |
| 320 | ApplicationInfo info = list.get(i); |
| 321 | if (info.intent.getComponent().equals(removeComponent)) { |
| 322 | return i; |
| 323 | } |
| 324 | } |
| 325 | return -1; |
| 326 | } |
| 327 | |
| 328 | @Override |
| 329 | public void dumpState() { |
| 330 | ApplicationInfo.dumpApplicationInfoList(TAG, "mApps", mApps); |
| 331 | } |
| 332 | |
| 333 | @Override |
| 334 | public void surrender() { |
| 335 | // do nothing? |
| 336 | } |
| 337 | |
| 338 | @Override |
| 339 | public void syncPages() { |
| 340 | // ensure that we have the right number of pages |
| 341 | int numPages = (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY)); |
| 342 | int curNumPages = getChildCount(); |
| 343 | // remove any extra pages after the "last" page |
| 344 | int extraPageDiff = curNumPages - numPages; |
| 345 | for (int i = 0; i < extraPageDiff; ++i) { |
| 346 | removeViewAt(numPages); |
| 347 | } |
| 348 | // add any necessary pages |
| 349 | for (int i = curNumPages; i < numPages; ++i) { |
| 350 | PagedViewCellLayout layout = new PagedViewCellLayout(getContext()); |
| 351 | layout.setCellCount(mCellCountX, mCellCountY); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 352 | addView(layout); |
| 353 | } |
| 354 | |
| 355 | // bound the current page |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 356 | setCurrentPage(Math.max(0, Math.min(numPages - 1, getCurrentPage()))); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | @Override |
| 360 | public void syncPageItems(int page) { |
| 361 | // ensure that we have the right number of items on the pages |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 362 | final int cellsPerPage = mCellCountX * mCellCountY; |
| 363 | final int startIndex = page * cellsPerPage; |
| 364 | final int endIndex = Math.min(startIndex + cellsPerPage, mFilteredApps.size()); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 365 | PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 366 | |
| 367 | final int curNumPageItems = layout.getChildCount(); |
| 368 | final int numPageItems = endIndex - startIndex; |
| 369 | |
| 370 | // remove any extra items |
| 371 | int extraPageItemsDiff = curNumPageItems - numPageItems; |
| 372 | for (int i = 0; i < extraPageItemsDiff; ++i) { |
| 373 | layout.removeViewAt(numPageItems); |
| 374 | } |
| 375 | // add any necessary items |
| 376 | for (int i = curNumPageItems; i < numPageItems; ++i) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 377 | TextView text = (TextView) mInflater.inflate(R.layout.all_apps_paged_view_application, layout, false); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 378 | text.setOnClickListener(this); |
| 379 | text.setOnLongClickListener(this); |
| 380 | |
| 381 | layout.addViewToCellLayout(text, -1, i, |
| 382 | new PagedViewCellLayout.LayoutParams(0, 0, 1, 1)); |
| 383 | } |
| 384 | |
| 385 | // actually reapply to the existing text views |
| 386 | for (int i = startIndex; i < endIndex; ++i) { |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 387 | final int index = i - startIndex; |
| 388 | final ApplicationInfo info = mFilteredApps.get(i); |
| 389 | PagedViewIcon icon = (PagedViewIcon) layout.getChildAt(index); |
| 390 | icon.applyFromApplicationInfo(info, mPageViewIconCache); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 391 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 392 | PagedViewCellLayout.LayoutParams params = |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 393 | (PagedViewCellLayout.LayoutParams) icon.getLayoutParams(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 394 | params.cellX = index % mCellCountX; |
| 395 | params.cellY = index / mCellCountX; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 396 | } |
| 397 | } |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 398 | |
| 399 | @Override |
| 400 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) { |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 401 | mode.setTitle(R.string.cab_selection_text); |
| 402 | menu.add(0, MENU_APP_INFO, 0, R.string.cab_menu_app_info) |
| 403 | .setIcon(R.drawable.info_button); |
| 404 | menu.add(0, MENU_DELETE_APP, 0, R.string.cab_menu_delete_app) |
| 405 | .setIcon(R.drawable.delete_zone_selector); |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 406 | return true; |
| 407 | } |
| 408 | |
| 409 | @Override |
| 410 | public boolean onCreateActionMode(ActionMode mode, Menu menu) { |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 411 | mDragController.addDropTarget(this); |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 412 | return true; |
| 413 | } |
| 414 | |
| 415 | @Override |
| 416 | public void onDestroyActionMode(ActionMode mode) { |
| 417 | mDragController.removeDropTarget(this); |
| 418 | endChoiceMode(); |
| 419 | } |
| 420 | |
| 421 | @Override |
| 422 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) { |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 423 | final int id = item.getItemId(); |
| 424 | |
| 425 | // Assumes that we are in CHOICE_MODE_SINGLE |
| 426 | final View chosenView = (View) getSingleCheckedGrandchild(); |
| 427 | final ApplicationInfo appInfo = (ApplicationInfo) chosenView.getTag(); |
| 428 | |
| 429 | if (id == MENU_APP_INFO) { |
| 430 | mLauncher.startApplicationDetailsActivity(appInfo.componentName); |
| 431 | } else if (id == MENU_DELETE_APP) { |
Patrick Dubroy | 5539af7 | 2010-09-07 15:22:01 -0700 | [diff] [blame] | 432 | mLauncher.startApplicationUninstallActivity(appInfo); |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 433 | } |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 434 | return false; |
| 435 | } |
| 436 | |
| 437 | /* |
| 438 | * We don't actually use AllAppsPagedView as a drop target... it's only used to intercept a drop |
| 439 | * to the workspace. |
| 440 | */ |
| 441 | @Override |
| 442 | public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset, |
| 443 | DragView dragView, Object dragInfo) { |
| 444 | return false; |
| 445 | } |
| 446 | @Override |
| 447 | public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset, |
| 448 | DragView dragView, Object dragInfo, Rect recycle) { |
| 449 | return null; |
| 450 | } |
| 451 | @Override |
| 452 | public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, |
| 453 | int yOffset, DragView dragView, Object dragInfo) { |
| 454 | return null; |
| 455 | } |
| 456 | @Override |
| 457 | public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, |
| 458 | DragView dragView, Object dragInfo) {} |
| 459 | @Override |
| 460 | public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, |
| 461 | DragView dragView, Object dragInfo) {} |
| 462 | @Override |
| 463 | public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, |
| 464 | DragView dragView, Object dragInfo) {} |
| 465 | @Override |
| 466 | public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, |
| 467 | DragView dragView, Object dragInfo) {} |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 468 | } |