blob: 42101eb4ca1b91e2d958fd5986001c4d3f2c0e43 [file] [log] [blame]
Winson Chung321e9ee2010-08-09 13:37:56 -07001/*
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
17package com.android.launcher2;
18
Winson Chung96785572010-10-14 13:37:13 -070019import java.util.ArrayList;
20import java.util.Collections;
Winson Chung321e9ee2010-08-09 13:37:56 -070021
22import android.content.ComponentName;
23import android.content.Context;
24import android.content.res.TypedArray;
Winson Chung96785572010-10-14 13:37:13 -070025import android.graphics.drawable.Drawable;
Winson Chung321e9ee2010-08-09 13:37:56 -070026import android.util.AttributeSet;
Winson Chung5f2aa4e2010-08-20 14:49:25 -070027import android.view.ActionMode;
Winson Chung96785572010-10-14 13:37:13 -070028import android.view.Gravity;
Winson Chung321e9ee2010-08-09 13:37:56 -070029import android.view.LayoutInflater;
Winson Chung5f2aa4e2010-08-20 14:49:25 -070030import android.view.Menu;
31import android.view.MenuItem;
Winson Chung321e9ee2010-08-09 13:37:56 -070032import android.view.View;
Patrick Dubroydea9e932010-09-22 15:04:29 -070033import android.view.ViewGroup;
Winson Chung321e9ee2010-08-09 13:37:56 -070034import android.view.animation.AnimationUtils;
Winson Chung5f2aa4e2010-08-20 14:49:25 -070035import android.widget.Checkable;
Winson Chung321e9ee2010-08-09 13:37:56 -070036import android.widget.TextView;
37
Winson Chung96785572010-10-14 13:37:13 -070038import com.android.launcher.R;
Winson Chung321e9ee2010-08-09 13:37:56 -070039
40/**
41 * An implementation of PagedView that populates the pages of the workspace
42 * with all of the user's applications.
43 */
44public class AllAppsPagedView extends PagedView
Winson Chung5f2aa4e2010-08-20 14:49:25 -070045 implements AllAppsView, View.OnClickListener, View.OnLongClickListener, DragSource,
46 DropTarget, ActionMode.Callback {
Winson Chung321e9ee2010-08-09 13:37:56 -070047
48 private static final String TAG = "AllAppsPagedView";
49 private static final boolean DEBUG = false;
50
Patrick Dubroy9f7aec82010-09-06 11:03:37 -070051 private static final int MENU_DELETE_APP = 1;
52 private static final int MENU_APP_INFO = 2;
53
Winson Chung321e9ee2010-08-09 13:37:56 -070054 private Launcher mLauncher;
55 private DragController mDragController;
56
57 // preserve compatibility with 3D all apps:
58 // 0.0 -> hidden
59 // 1.0 -> shown and opaque
60 // intermediate values -> partially shown & partially opaque
61 private float mZoom;
62
63 // set of all applications
64 private ArrayList<ApplicationInfo> mApps;
65 private ArrayList<ApplicationInfo> mFilteredApps;
66
67 // the types of applications to filter
68 static final int ALL_APPS_FLAG = -1;
69 private int mAppFilter = ALL_APPS_FLAG;
70
Winson Chung321e9ee2010-08-09 13:37:56 -070071 private final LayoutInflater mInflater;
72
Patrick Dubroydea9e932010-09-22 15:04:29 -070073 private ViewGroup mOrigInfoButtonParent;
74 private LayoutParams mOrigInfoButtonLayoutParams;
75
76 private ViewGroup mOrigDeleteZoneParent;
77 private LayoutParams mOrigDeleteZoneLayoutParams;
78
Winson Chung321e9ee2010-08-09 13:37:56 -070079 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);
90 mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 6);
91 mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4);
92 mInflater = LayoutInflater.from(context);
93 a.recycle();
94 setSoundEffectsEnabled(false);
95 }
96
97 @Override
98 public void setLauncher(Launcher launcher) {
99 mLauncher = launcher;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700100 mLauncher.setAllAppsPagedView(this);
Winson Chung321e9ee2010-08-09 13:37:56 -0700101 }
102
103 @Override
104 public void setDragController(DragController dragger) {
105 mDragController = dragger;
106 }
107
108 public void setAppFilter(int filterType) {
109 mAppFilter = filterType;
Winson Chung80baf5a2010-08-09 16:03:15 -0700110 if (mApps != null) {
111 mFilteredApps = rebuildFilteredApps(mApps);
Winson Chung86f77532010-08-24 11:08:22 -0700112 setCurrentPage(0);
Winson Chung80baf5a2010-08-09 16:03:15 -0700113 invalidatePageData();
114 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700115 }
116
117 @Override
118 public void zoom(float zoom, boolean animate) {
119 mZoom = zoom;
120 cancelLongPress();
121
122 if (isVisible()) {
123 getParent().bringChildToFront(this);
124 setVisibility(View.VISIBLE);
125 if (animate) {
126 startAnimation(AnimationUtils.loadAnimation(getContext(),
127 R.anim.all_apps_2d_fade_in));
128 } else {
129 onAnimationEnd();
130 }
131 } else {
132 if (animate) {
133 startAnimation(AnimationUtils.loadAnimation(getContext(),
134 R.anim.all_apps_2d_fade_out));
135 } else {
136 onAnimationEnd();
137 }
138 }
139 }
140
141 protected void onAnimationEnd() {
142 if (!isVisible()) {
143 setVisibility(View.GONE);
144 mZoom = 0.0f;
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700145
146 endChoiceMode();
Winson Chung321e9ee2010-08-09 13:37:56 -0700147 } else {
148 mZoom = 1.0f;
149 }
150
151 if (mLauncher != null)
152 mLauncher.zoomed(mZoom);
153 }
154
155 private int getChildIndexForGrandChild(View v) {
156 final int childCount = getChildCount();
157 for (int i = 0; i < childCount; ++i) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700158 final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i);
Winson Chung321e9ee2010-08-09 13:37:56 -0700159 if (layout.indexOfChild(v) > -1) {
160 return i;
161 }
162 }
163 return -1;
164 }
165
166 @Override
167 public void onClick(View v) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700168 // if we are already in a choice mode, then just change the selection
169 if (v instanceof Checkable) {
170 if (!isChoiceMode(CHOICE_MODE_NONE)) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700171 Checkable c = (Checkable) v;
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700172 if (isChoiceMode(CHOICE_MODE_SINGLE)) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700173 // Uncheck all the other grandchildren, and toggle the clicked one
174 boolean wasChecked = c.isChecked();
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700175 resetCheckedGrandchildren();
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700176 c.setChecked(!wasChecked);
177 } else {
178 c.toggle();
179 }
180 if (getCheckedGrandchildren().size() == 0) {
181 endChoiceMode();
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700182 }
183
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700184 return;
185 }
186 }
187
188 // otherwise continue and launch the application
Winson Chung321e9ee2010-08-09 13:37:56 -0700189 int childIndex = getChildIndexForGrandChild(v);
Winson Chung86f77532010-08-24 11:08:22 -0700190 if (childIndex == getCurrentPage()) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700191 final ApplicationInfo app = (ApplicationInfo) v.getTag();
192
Winson Chung80baf5a2010-08-09 16:03:15 -0700193 // animate some feedback to the click
194 animateClickFeedback(v, new Runnable() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700195 @Override
Winson Chung80baf5a2010-08-09 16:03:15 -0700196 public void run() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700197 mLauncher.startActivitySafely(app.intent, app);
198 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700199 });
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700200
201 endChoiceMode();
Winson Chung321e9ee2010-08-09 13:37:56 -0700202 }
203 }
204
205 @Override
206 public boolean onLongClick(View v) {
207 if (!v.isInTouchMode()) {
208 return false;
209 }
210
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700211 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 Chung5f2aa4e2010-08-20 14:49:25 -0700220
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700221 // Start choice mode AFTER the item is selected
222 if (isChoiceMode(CHOICE_MODE_NONE)) {
223 startChoiceMode(CHOICE_MODE_SINGLE, this);
224 }
225
Winson Chung321e9ee2010-08-09 13:37:56 -0700226 ApplicationInfo app = (ApplicationInfo) v.getTag();
227 app = new ApplicationInfo(app);
228
Michael Jurka3e7c7632010-10-02 16:01:03 -0700229 mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1);
Winson Chung321e9ee2010-08-09 13:37:56 -0700230 mDragController.startDrag(v, this, app, DragController.DRAG_ACTION_COPY);
Winson Chung321e9ee2010-08-09 13:37:56 -0700231 return true;
232 }
233
234 @Override
235 public void onDropCompleted(View target, boolean success) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700236 // close the choice action mode if we have a proper drop
237 if (target != this) {
238 endChoiceMode();
239 }
Michael Jurka3e7c7632010-10-02 16:01:03 -0700240 mLauncher.getWorkspace().onDragStopped();
Winson Chung321e9ee2010-08-09 13:37:56 -0700241 }
242
243 @Override
244 public boolean isVisible() {
245 return mZoom > 0.001f;
246 }
247
248 @Override
249 public boolean isAnimating() {
250 return (getAnimation() != null);
251 }
252
253 private ArrayList<ApplicationInfo> rebuildFilteredApps(ArrayList<ApplicationInfo> apps) {
254 ArrayList<ApplicationInfo> filteredApps = new ArrayList<ApplicationInfo>();
255 if (mAppFilter == ALL_APPS_FLAG) {
256 return apps;
257 } else {
258 final int length = apps.size();
259 for (int i = 0; i < length; ++i) {
260 ApplicationInfo info = apps.get(i);
261 if ((info.flags & mAppFilter) > 0) {
262 filteredApps.add(info);
263 }
264 }
265 }
266 return filteredApps;
267 }
268
269 @Override
270 public void setApps(ArrayList<ApplicationInfo> list) {
271 mApps = list;
Winson Chung80baf5a2010-08-09 16:03:15 -0700272 Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
Winson Chung321e9ee2010-08-09 13:37:56 -0700273 mFilteredApps = rebuildFilteredApps(mApps);
Winson Chung241c3b42010-08-25 16:53:03 -0700274 mPageViewIconCache.clear();
Winson Chung321e9ee2010-08-09 13:37:56 -0700275 invalidatePageData();
276 }
277
Winson Chung80baf5a2010-08-09 16:03:15 -0700278 private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
279 // we add it in place, in alphabetical order
280 final int count = list.size();
281 for (int i = 0; i < count; ++i) {
282 final ApplicationInfo info = list.get(i);
283 final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR);
284 if (index < 0) {
285 mApps.add(-(index + 1), info);
286 }
287 }
288 mFilteredApps = rebuildFilteredApps(mApps);
289 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700290 @Override
291 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700292 addAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700293 invalidatePageData();
294 }
295
Winson Chung80baf5a2010-08-09 16:03:15 -0700296 private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700297 // loop through all the apps and remove apps that have the same component
298 final int length = list.size();
299 for (int i = 0; i < length; ++i) {
Winson Chung241c3b42010-08-25 16:53:03 -0700300 final ApplicationInfo info = list.get(i);
301 int removeIndex = findAppByComponent(mApps, info);
Winson Chung321e9ee2010-08-09 13:37:56 -0700302 if (removeIndex > -1) {
303 mApps.remove(removeIndex);
Winson Chung241c3b42010-08-25 16:53:03 -0700304 mPageViewIconCache.removeOutline(info);
Winson Chung321e9ee2010-08-09 13:37:56 -0700305 }
306 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700307 mFilteredApps = rebuildFilteredApps(mApps);
308 }
309 @Override
310 public void removeApps(ArrayList<ApplicationInfo> list) {
311 removeAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700312 invalidatePageData();
313 }
314
315 @Override
316 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700317 removeAppsWithoutInvalidate(list);
318 addAppsWithoutInvalidate(list);
319 invalidatePageData();
Winson Chung321e9ee2010-08-09 13:37:56 -0700320 }
321
322 private int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
323 ComponentName removeComponent = item.intent.getComponent();
324 final int length = list.size();
325 for (int i = 0; i < length; ++i) {
326 ApplicationInfo info = list.get(i);
327 if (info.intent.getComponent().equals(removeComponent)) {
328 return i;
329 }
330 }
331 return -1;
332 }
333
334 @Override
335 public void dumpState() {
336 ApplicationInfo.dumpApplicationInfoList(TAG, "mApps", mApps);
337 }
338
339 @Override
340 public void surrender() {
341 // do nothing?
342 }
343
344 @Override
345 public void syncPages() {
Winson Chung96785572010-10-14 13:37:13 -0700346 // ensure that we have the right number of pages (min of 1, since we have placeholders)
347 int numPages = Math.max(1,
348 (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY)));
Winson Chung321e9ee2010-08-09 13:37:56 -0700349 int curNumPages = getChildCount();
350 // remove any extra pages after the "last" page
351 int extraPageDiff = curNumPages - numPages;
352 for (int i = 0; i < extraPageDiff; ++i) {
353 removeViewAt(numPages);
354 }
355 // add any necessary pages
356 for (int i = curNumPages; i < numPages; ++i) {
357 PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
358 layout.setCellCount(mCellCountX, mCellCountY);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700359 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
360 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
Winson Chung321e9ee2010-08-09 13:37:56 -0700361 addView(layout);
362 }
363
364 // bound the current page
Winson Chung86f77532010-08-24 11:08:22 -0700365 setCurrentPage(Math.max(0, Math.min(numPages - 1, getCurrentPage())));
Winson Chung321e9ee2010-08-09 13:37:56 -0700366 }
367
368 @Override
369 public void syncPageItems(int page) {
Winson Chung96785572010-10-14 13:37:13 -0700370 // Ensure that we have the right number of items on the pages
Winson Chung80baf5a2010-08-09 16:03:15 -0700371 final int cellsPerPage = mCellCountX * mCellCountY;
372 final int startIndex = page * cellsPerPage;
373 final int endIndex = Math.min(startIndex + cellsPerPage, mFilteredApps.size());
Winson Chung321e9ee2010-08-09 13:37:56 -0700374 PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
Winson Chung80baf5a2010-08-09 16:03:15 -0700375
Winson Chung96785572010-10-14 13:37:13 -0700376 if (!mFilteredApps.isEmpty()) {
377 int curNumPageItems = layout.getChildCount();
378 int numPageItems = endIndex - startIndex;
Winson Chung80baf5a2010-08-09 16:03:15 -0700379
Winson Chung96785572010-10-14 13:37:13 -0700380 // If we were previously an empty page, then restart anew
381 boolean wasEmptyPage = false;
382 if (curNumPageItems == 1) {
383 View icon = layout.getChildAt(0);
384 if (icon.getTag() == null) {
385 wasEmptyPage = true;
386 }
387 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700388
Winson Chung96785572010-10-14 13:37:13 -0700389 if (wasEmptyPage) {
390 // Remove all the previous items
391 curNumPageItems = 0;
392 layout.removeAllViews();
393 } else {
394 // Remove any extra items
395 int extraPageItemsDiff = curNumPageItems - numPageItems;
396 for (int i = 0; i < extraPageItemsDiff; ++i) {
397 layout.removeViewAt(numPageItems);
398 }
399 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700400
Winson Chung96785572010-10-14 13:37:13 -0700401 // Add any necessary items
402 for (int i = curNumPageItems; i < numPageItems; ++i) {
403 TextView text = (TextView) mInflater.inflate(
404 R.layout.all_apps_paged_view_application, layout, false);
405 text.setOnClickListener(this);
406 text.setOnLongClickListener(this);
Winson Chung321e9ee2010-08-09 13:37:56 -0700407
Winson Chung96785572010-10-14 13:37:13 -0700408 layout.addViewToCellLayout(text, -1, i,
409 new PagedViewCellLayout.LayoutParams(0, 0, 1, 1));
410 }
411
412 // Actually reapply to the existing text views
413 for (int i = startIndex; i < endIndex; ++i) {
414 final int index = i - startIndex;
415 final ApplicationInfo info = mFilteredApps.get(i);
416 PagedViewIcon icon = (PagedViewIcon) layout.getChildAt(index);
417 icon.applyFromApplicationInfo(info, mPageViewIconCache);
418
419 PagedViewCellLayout.LayoutParams params =
420 (PagedViewCellLayout.LayoutParams) icon.getLayoutParams();
421 params.cellX = index % mCellCountX;
422 params.cellY = index / mCellCountX;
423 }
424
425 // Default to left-aligned icons
426 layout.enableCenteredContent(false);
427 } else {
428 // There are no items, so show the user a small message
429 TextView icon = (TextView) mInflater.inflate(
430 R.layout.all_apps_no_items_placeholder, layout, false);
431 switch (mAppFilter) {
432 case ApplicationInfo.GAME_FLAG:
433 icon.setText(mContext.getString(R.string.all_apps_no_games));
434 break;
435 case ApplicationInfo.DOWNLOADED_FLAG:
436 icon.setText(mContext.getString(R.string.all_apps_no_downloads));
437 break;
438 default: break;
439 }
440
441 // Center-align the message
442 layout.enableCenteredContent(true);
443 layout.removeAllViews();
444 layout.addViewToCellLayout(icon, -1, 0,
445 new PagedViewCellLayout.LayoutParams(0, 0, 2, 1));
Winson Chung321e9ee2010-08-09 13:37:56 -0700446 }
447 }
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700448
449 @Override
450 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
Michael Jurka3125d9d2010-09-27 11:30:20 -0700451 mode.setTitle(R.string.cab_app_selection_text);
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700452
Patrick Dubroydea9e932010-09-22 15:04:29 -0700453 // Until the workspace has a selection mode and the CAB supports drag-and-drop, we
454 // take a hybrid approach: grab the views from the workspace and stuff them into the CAB.
455 // When the action mode is done, restore the views to their original place in the toolbar.
456
457 ApplicationInfoDropTarget infoButton =
458 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
459 mOrigInfoButtonParent = (ViewGroup) infoButton.getParent();
460 mOrigInfoButtonLayoutParams = infoButton.getLayoutParams();
461 mOrigInfoButtonParent.removeView(infoButton);
462 infoButton.setManageVisibility(false);
463 infoButton.setVisibility(View.VISIBLE);
464
465 DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
466 mOrigDeleteZoneParent = (ViewGroup) deleteZone.getParent();
467 mOrigDeleteZoneLayoutParams = deleteZone.getLayoutParams();
468 mOrigDeleteZoneParent.removeView(deleteZone);
469 deleteZone.setManageVisibility(false);
470 deleteZone.setVisibility(View.VISIBLE);
471
472 menu.add(0, MENU_APP_INFO, 0, R.string.cab_menu_app_info).setActionView(infoButton);
473 menu.add(0, MENU_DELETE_APP, 0, R.string.cab_menu_delete_app).setActionView(deleteZone);
474
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700475 return true;
476 }
477
478 @Override
479 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700480 mDragController.addDropTarget(this);
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700481 return true;
482 }
483
484 @Override
485 public void onDestroyActionMode(ActionMode mode) {
Patrick Dubroydea9e932010-09-22 15:04:29 -0700486 // Re-parent the drop targets into the toolbar, and restore their layout params
487 ApplicationInfoDropTarget infoButton =
488 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
489 ((ViewGroup) infoButton.getParent()).removeView(infoButton);
490 mOrigInfoButtonParent.addView(infoButton, mOrigInfoButtonLayoutParams);
491 infoButton.setVisibility(View.GONE);
492 infoButton.setManageVisibility(true);
493
494 DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
495 ((ViewGroup) deleteZone.getParent()).removeView(deleteZone);
496 mOrigDeleteZoneParent.addView(deleteZone, mOrigDeleteZoneLayoutParams);
497 deleteZone.setVisibility(View.GONE);
498 deleteZone.setManageVisibility(true);
499
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700500 mDragController.removeDropTarget(this);
501 endChoiceMode();
502 }
503
504 @Override
505 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700506 final int id = item.getItemId();
507
508 // Assumes that we are in CHOICE_MODE_SINGLE
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700509 final ApplicationInfo appInfo = (ApplicationInfo) getChosenItem();
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700510
511 if (id == MENU_APP_INFO) {
512 mLauncher.startApplicationDetailsActivity(appInfo.componentName);
513 } else if (id == MENU_DELETE_APP) {
Patrick Dubroy5539af72010-09-07 15:22:01 -0700514 mLauncher.startApplicationUninstallActivity(appInfo);
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700515 }
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700516 return false;
517 }
518
519 /*
520 * We don't actually use AllAppsPagedView as a drop target... it's only used to intercept a drop
521 * to the workspace.
522 */
523 @Override
524 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
525 DragView dragView, Object dragInfo) {
526 return false;
527 }
528 @Override
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700529 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset,
530 int yOffset, DragView dragView, Object dragInfo) {
531 return null;
532 }
533 @Override
534 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
535 DragView dragView, Object dragInfo) {}
536 @Override
537 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
538 DragView dragView, Object dragInfo) {}
539 @Override
540 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
541 DragView dragView, Object dragInfo) {}
542 @Override
543 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
544 DragView dragView, Object dragInfo) {}
Michael Jurka0280c3b2010-09-17 15:00:07 -0700545
546 public boolean isDropEnabled() {
547 return true;
548 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700549}