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