blob: 351384f93d94f64f6c5720791ecb009a8f4f2ef3 [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 Chung10fefb12010-11-01 11:57:06 -070021import java.util.HashSet;
Winson Chung321e9ee2010-08-09 13:37:56 -070022
23import android.content.ComponentName;
24import android.content.Context;
25import android.content.res.TypedArray;
Winson Chung321e9ee2010-08-09 13:37:56 -070026import android.util.AttributeSet;
Winson Chung5f2aa4e2010-08-20 14:49:25 -070027import android.view.ActionMode;
Winson Chung321e9ee2010-08-09 13:37:56 -070028import android.view.LayoutInflater;
Winson Chung5f2aa4e2010-08-20 14:49:25 -070029import android.view.Menu;
30import android.view.MenuItem;
Winson Chung321e9ee2010-08-09 13:37:56 -070031import android.view.View;
Patrick Dubroydea9e932010-09-22 15:04:29 -070032import android.view.ViewGroup;
Winson Chung321e9ee2010-08-09 13:37:56 -070033import android.view.animation.AnimationUtils;
Winson Chung5f2aa4e2010-08-20 14:49:25 -070034import android.widget.Checkable;
Winson Chung321e9ee2010-08-09 13:37:56 -070035import android.widget.TextView;
36
Winson Chung96785572010-10-14 13:37:13 -070037import com.android.launcher.R;
Winson Chung321e9ee2010-08-09 13:37:56 -070038
39/**
40 * An implementation of PagedView that populates the pages of the workspace
41 * with all of the user's applications.
42 */
43public class AllAppsPagedView extends PagedView
Winson Chung5f2aa4e2010-08-20 14:49:25 -070044 implements AllAppsView, View.OnClickListener, View.OnLongClickListener, DragSource,
45 DropTarget, ActionMode.Callback {
Winson Chung321e9ee2010-08-09 13:37:56 -070046
47 private static final String TAG = "AllAppsPagedView";
48 private static final boolean DEBUG = false;
49
Patrick Dubroy9f7aec82010-09-06 11:03:37 -070050 private static final int MENU_DELETE_APP = 1;
51 private static final int MENU_APP_INFO = 2;
52
Winson Chung321e9ee2010-08-09 13:37:56 -070053 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
Winson Chung321e9ee2010-08-09 13:37:56 -070070 private final LayoutInflater mInflater;
71
Patrick Dubroydea9e932010-09-22 15:04:29 -070072 private ViewGroup mOrigInfoButtonParent;
73 private LayoutParams mOrigInfoButtonLayoutParams;
74
75 private ViewGroup mOrigDeleteZoneParent;
76 private LayoutParams mOrigDeleteZoneLayoutParams;
77
Winson Chung321e9ee2010-08-09 13:37:56 -070078 public AllAppsPagedView(Context context) {
79 this(context, null);
80 }
81
82 public AllAppsPagedView(Context context, AttributeSet attrs) {
83 this(context, attrs, 0);
84 }
85
86 public AllAppsPagedView(Context context, AttributeSet attrs, int defStyle) {
87 super(context, attrs, defStyle);
88 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0);
89 mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 6);
90 mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4);
91 mInflater = LayoutInflater.from(context);
92 a.recycle();
93 setSoundEffectsEnabled(false);
94 }
95
96 @Override
Winson Chung7da10252010-10-28 16:07:04 -070097 protected void init() {
98 super.init();
99 mCenterPagesVertically = false;
100 }
101
102 @Override
Winson Chung321e9ee2010-08-09 13:37:56 -0700103 public void setLauncher(Launcher launcher) {
104 mLauncher = launcher;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700105 mLauncher.setAllAppsPagedView(this);
Winson Chung321e9ee2010-08-09 13:37:56 -0700106 }
107
108 @Override
109 public void setDragController(DragController dragger) {
110 mDragController = dragger;
111 }
112
113 public void setAppFilter(int filterType) {
114 mAppFilter = filterType;
Winson Chung80baf5a2010-08-09 16:03:15 -0700115 if (mApps != null) {
116 mFilteredApps = rebuildFilteredApps(mApps);
Winson Chung86f77532010-08-24 11:08:22 -0700117 setCurrentPage(0);
Winson Chung80baf5a2010-08-09 16:03:15 -0700118 invalidatePageData();
119 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700120 }
121
122 @Override
123 public void zoom(float zoom, boolean animate) {
124 mZoom = zoom;
125 cancelLongPress();
126
127 if (isVisible()) {
128 getParent().bringChildToFront(this);
129 setVisibility(View.VISIBLE);
130 if (animate) {
131 startAnimation(AnimationUtils.loadAnimation(getContext(),
132 R.anim.all_apps_2d_fade_in));
133 } else {
134 onAnimationEnd();
135 }
136 } else {
137 if (animate) {
138 startAnimation(AnimationUtils.loadAnimation(getContext(),
139 R.anim.all_apps_2d_fade_out));
140 } else {
141 onAnimationEnd();
142 }
143 }
144 }
145
146 protected void onAnimationEnd() {
147 if (!isVisible()) {
148 setVisibility(View.GONE);
149 mZoom = 0.0f;
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700150
151 endChoiceMode();
Winson Chung321e9ee2010-08-09 13:37:56 -0700152 } else {
153 mZoom = 1.0f;
154 }
155
156 if (mLauncher != null)
157 mLauncher.zoomed(mZoom);
158 }
159
160 private int getChildIndexForGrandChild(View v) {
161 final int childCount = getChildCount();
162 for (int i = 0; i < childCount; ++i) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700163 final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i);
Winson Chung321e9ee2010-08-09 13:37:56 -0700164 if (layout.indexOfChild(v) > -1) {
165 return i;
166 }
167 }
168 return -1;
169 }
170
171 @Override
172 public void onClick(View v) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700173 // if we are already in a choice mode, then just change the selection
174 if (v instanceof Checkable) {
175 if (!isChoiceMode(CHOICE_MODE_NONE)) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700176 Checkable c = (Checkable) v;
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700177 if (isChoiceMode(CHOICE_MODE_SINGLE)) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700178 // Uncheck all the other grandchildren, and toggle the clicked one
179 boolean wasChecked = c.isChecked();
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700180 resetCheckedGrandchildren();
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700181 c.setChecked(!wasChecked);
182 } else {
183 c.toggle();
184 }
185 if (getCheckedGrandchildren().size() == 0) {
186 endChoiceMode();
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700187 }
188
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700189 return;
190 }
191 }
192
193 // otherwise continue and launch the application
Winson Chung321e9ee2010-08-09 13:37:56 -0700194 int childIndex = getChildIndexForGrandChild(v);
Winson Chung86f77532010-08-24 11:08:22 -0700195 if (childIndex == getCurrentPage()) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700196 final ApplicationInfo app = (ApplicationInfo) v.getTag();
197
Winson Chung80baf5a2010-08-09 16:03:15 -0700198 // animate some feedback to the click
199 animateClickFeedback(v, new Runnable() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700200 @Override
Winson Chung80baf5a2010-08-09 16:03:15 -0700201 public void run() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700202 mLauncher.startActivitySafely(app.intent, app);
203 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700204 });
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700205
206 endChoiceMode();
Winson Chung321e9ee2010-08-09 13:37:56 -0700207 }
208 }
209
210 @Override
211 public boolean onLongClick(View v) {
212 if (!v.isInTouchMode()) {
213 return false;
214 }
215
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700216 if (v instanceof Checkable) {
217 // In preparation for drag, we always reset the checked grand children regardless of
218 // what choice mode we are in
219 resetCheckedGrandchildren();
220
221 // Toggle the selection on the dragged app
222 Checkable c = (Checkable) v;
223 c.toggle();
224 }
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700225
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700226 // Start choice mode AFTER the item is selected
227 if (isChoiceMode(CHOICE_MODE_NONE)) {
228 startChoiceMode(CHOICE_MODE_SINGLE, this);
229 }
230
Winson Chung321e9ee2010-08-09 13:37:56 -0700231 ApplicationInfo app = (ApplicationInfo) v.getTag();
232 app = new ApplicationInfo(app);
233
Michael Jurka3e7c7632010-10-02 16:01:03 -0700234 mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1);
Winson Chung321e9ee2010-08-09 13:37:56 -0700235 mDragController.startDrag(v, this, app, DragController.DRAG_ACTION_COPY);
Winson Chung321e9ee2010-08-09 13:37:56 -0700236 return true;
237 }
238
239 @Override
240 public void onDropCompleted(View target, boolean success) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700241 // close the choice action mode if we have a proper drop
242 if (target != this) {
243 endChoiceMode();
244 }
Michael Jurka3e7c7632010-10-02 16:01:03 -0700245 mLauncher.getWorkspace().onDragStopped();
Winson Chung321e9ee2010-08-09 13:37:56 -0700246 }
247
248 @Override
249 public boolean isVisible() {
250 return mZoom > 0.001f;
251 }
252
253 @Override
254 public boolean isAnimating() {
255 return (getAnimation() != null);
256 }
257
258 private ArrayList<ApplicationInfo> rebuildFilteredApps(ArrayList<ApplicationInfo> apps) {
259 ArrayList<ApplicationInfo> filteredApps = new ArrayList<ApplicationInfo>();
260 if (mAppFilter == ALL_APPS_FLAG) {
261 return apps;
262 } else {
263 final int length = apps.size();
264 for (int i = 0; i < length; ++i) {
265 ApplicationInfo info = apps.get(i);
266 if ((info.flags & mAppFilter) > 0) {
267 filteredApps.add(info);
268 }
269 }
270 }
271 return filteredApps;
272 }
273
274 @Override
275 public void setApps(ArrayList<ApplicationInfo> list) {
276 mApps = list;
Winson Chung80baf5a2010-08-09 16:03:15 -0700277 Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
Winson Chung321e9ee2010-08-09 13:37:56 -0700278 mFilteredApps = rebuildFilteredApps(mApps);
Winson Chung241c3b42010-08-25 16:53:03 -0700279 mPageViewIconCache.clear();
Winson Chung321e9ee2010-08-09 13:37:56 -0700280 invalidatePageData();
281 }
282
Winson Chung80baf5a2010-08-09 16:03:15 -0700283 private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
284 // we add it in place, in alphabetical order
285 final int count = list.size();
286 for (int i = 0; i < count; ++i) {
287 final ApplicationInfo info = list.get(i);
288 final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR);
289 if (index < 0) {
290 mApps.add(-(index + 1), info);
291 }
292 }
293 mFilteredApps = rebuildFilteredApps(mApps);
294 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700295 @Override
296 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700297 addAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700298 invalidatePageData();
299 }
300
Winson Chung80baf5a2010-08-09 16:03:15 -0700301 private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
Winson Chung10fefb12010-11-01 11:57:06 -0700302 // End the choice mode if any of the items in the list that are being removed are
303 // currently selected
304 ArrayList<Checkable> checkedList = getCheckedGrandchildren();
305 HashSet<ApplicationInfo> checkedAppInfos = new HashSet<ApplicationInfo>();
306 for (Checkable checked : checkedList) {
307 PagedViewIcon icon = (PagedViewIcon) checked;
308 checkedAppInfos.add((ApplicationInfo) icon.getTag());
309 }
310 for (ApplicationInfo info : list) {
311 if (checkedAppInfos.contains(info)) {
312 endChoiceMode();
313 break;
314 }
315 }
316
317 // Loop through all the apps and remove apps that have the same component
Winson Chung321e9ee2010-08-09 13:37:56 -0700318 final int length = list.size();
319 for (int i = 0; i < length; ++i) {
Winson Chung241c3b42010-08-25 16:53:03 -0700320 final ApplicationInfo info = list.get(i);
321 int removeIndex = findAppByComponent(mApps, info);
Winson Chung321e9ee2010-08-09 13:37:56 -0700322 if (removeIndex > -1) {
323 mApps.remove(removeIndex);
Winson Chung241c3b42010-08-25 16:53:03 -0700324 mPageViewIconCache.removeOutline(info);
Winson Chung321e9ee2010-08-09 13:37:56 -0700325 }
326 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700327 mFilteredApps = rebuildFilteredApps(mApps);
328 }
329 @Override
330 public void removeApps(ArrayList<ApplicationInfo> list) {
331 removeAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700332 invalidatePageData();
333 }
334
335 @Override
336 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700337 removeAppsWithoutInvalidate(list);
338 addAppsWithoutInvalidate(list);
339 invalidatePageData();
Winson Chung321e9ee2010-08-09 13:37:56 -0700340 }
341
342 private int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
343 ComponentName removeComponent = item.intent.getComponent();
344 final int length = list.size();
345 for (int i = 0; i < length; ++i) {
346 ApplicationInfo info = list.get(i);
347 if (info.intent.getComponent().equals(removeComponent)) {
348 return i;
349 }
350 }
351 return -1;
352 }
353
354 @Override
355 public void dumpState() {
356 ApplicationInfo.dumpApplicationInfoList(TAG, "mApps", mApps);
357 }
358
359 @Override
360 public void surrender() {
361 // do nothing?
362 }
363
364 @Override
365 public void syncPages() {
Winson Chung96785572010-10-14 13:37:13 -0700366 // ensure that we have the right number of pages (min of 1, since we have placeholders)
367 int numPages = Math.max(1,
368 (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY)));
Winson Chung321e9ee2010-08-09 13:37:56 -0700369 int curNumPages = getChildCount();
370 // remove any extra pages after the "last" page
371 int extraPageDiff = curNumPages - numPages;
372 for (int i = 0; i < extraPageDiff; ++i) {
373 removeViewAt(numPages);
374 }
375 // add any necessary pages
376 for (int i = curNumPages; i < numPages; ++i) {
377 PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
378 layout.setCellCount(mCellCountX, mCellCountY);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700379 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
380 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
Winson Chungdf4b83d2010-10-20 17:49:27 -0700381 layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
Winson Chung321e9ee2010-08-09 13:37:56 -0700382 addView(layout);
383 }
384
385 // bound the current page
Winson Chung86f77532010-08-24 11:08:22 -0700386 setCurrentPage(Math.max(0, Math.min(numPages - 1, getCurrentPage())));
Winson Chung321e9ee2010-08-09 13:37:56 -0700387 }
388
389 @Override
390 public void syncPageItems(int page) {
Winson Chung96785572010-10-14 13:37:13 -0700391 // Ensure that we have the right number of items on the pages
Winson Chung80baf5a2010-08-09 16:03:15 -0700392 final int cellsPerPage = mCellCountX * mCellCountY;
393 final int startIndex = page * cellsPerPage;
394 final int endIndex = Math.min(startIndex + cellsPerPage, mFilteredApps.size());
Winson Chung321e9ee2010-08-09 13:37:56 -0700395 PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
Winson Chung80baf5a2010-08-09 16:03:15 -0700396
Winson Chung96785572010-10-14 13:37:13 -0700397 if (!mFilteredApps.isEmpty()) {
398 int curNumPageItems = layout.getChildCount();
399 int numPageItems = endIndex - startIndex;
Winson Chung80baf5a2010-08-09 16:03:15 -0700400
Winson Chung96785572010-10-14 13:37:13 -0700401 // If we were previously an empty page, then restart anew
402 boolean wasEmptyPage = false;
403 if (curNumPageItems == 1) {
404 View icon = layout.getChildAt(0);
405 if (icon.getTag() == null) {
406 wasEmptyPage = true;
407 }
408 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700409
Winson Chung96785572010-10-14 13:37:13 -0700410 if (wasEmptyPage) {
411 // Remove all the previous items
412 curNumPageItems = 0;
413 layout.removeAllViews();
414 } else {
415 // Remove any extra items
416 int extraPageItemsDiff = curNumPageItems - numPageItems;
417 for (int i = 0; i < extraPageItemsDiff; ++i) {
418 layout.removeViewAt(numPageItems);
419 }
420 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700421
Winson Chung96785572010-10-14 13:37:13 -0700422 // Add any necessary items
423 for (int i = curNumPageItems; i < numPageItems; ++i) {
424 TextView text = (TextView) mInflater.inflate(
425 R.layout.all_apps_paged_view_application, layout, false);
426 text.setOnClickListener(this);
427 text.setOnLongClickListener(this);
Winson Chung321e9ee2010-08-09 13:37:56 -0700428
Winson Chung96785572010-10-14 13:37:13 -0700429 layout.addViewToCellLayout(text, -1, i,
430 new PagedViewCellLayout.LayoutParams(0, 0, 1, 1));
431 }
432
433 // Actually reapply to the existing text views
434 for (int i = startIndex; i < endIndex; ++i) {
435 final int index = i - startIndex;
436 final ApplicationInfo info = mFilteredApps.get(i);
437 PagedViewIcon icon = (PagedViewIcon) layout.getChildAt(index);
Winson Chungdf4b83d2010-10-20 17:49:27 -0700438 icon.applyFromApplicationInfo(info, mPageViewIconCache, true);
Winson Chung96785572010-10-14 13:37:13 -0700439
440 PagedViewCellLayout.LayoutParams params =
441 (PagedViewCellLayout.LayoutParams) icon.getLayoutParams();
442 params.cellX = index % mCellCountX;
443 params.cellY = index / mCellCountX;
444 }
445
446 // Default to left-aligned icons
447 layout.enableCenteredContent(false);
448 } else {
449 // There are no items, so show the user a small message
450 TextView icon = (TextView) mInflater.inflate(
451 R.layout.all_apps_no_items_placeholder, layout, false);
452 switch (mAppFilter) {
Winson Chung96785572010-10-14 13:37:13 -0700453 case ApplicationInfo.DOWNLOADED_FLAG:
454 icon.setText(mContext.getString(R.string.all_apps_no_downloads));
455 break;
456 default: break;
457 }
458
459 // Center-align the message
460 layout.enableCenteredContent(true);
461 layout.removeAllViews();
462 layout.addViewToCellLayout(icon, -1, 0,
463 new PagedViewCellLayout.LayoutParams(0, 0, 2, 1));
Winson Chung321e9ee2010-08-09 13:37:56 -0700464 }
465 }
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700466 @Override
467 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
Michael Jurka3125d9d2010-09-27 11:30:20 -0700468 mode.setTitle(R.string.cab_app_selection_text);
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700469
Patrick Dubroydea9e932010-09-22 15:04:29 -0700470 // Until the workspace has a selection mode and the CAB supports drag-and-drop, we
471 // take a hybrid approach: grab the views from the workspace and stuff them into the CAB.
472 // When the action mode is done, restore the views to their original place in the toolbar.
473
474 ApplicationInfoDropTarget infoButton =
475 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
476 mOrigInfoButtonParent = (ViewGroup) infoButton.getParent();
477 mOrigInfoButtonLayoutParams = infoButton.getLayoutParams();
478 mOrigInfoButtonParent.removeView(infoButton);
479 infoButton.setManageVisibility(false);
480 infoButton.setVisibility(View.VISIBLE);
Patrick Dubroyb3c81cc2010-10-25 18:00:59 -0700481 infoButton.setOnClickListener(new View.OnClickListener() {
482 public void onClick(View v) {
483 final ApplicationInfo appInfo = (ApplicationInfo) getChosenItem();
484 mLauncher.startApplicationDetailsActivity(appInfo.componentName);
485 }
486 });
Patrick Dubroydea9e932010-09-22 15:04:29 -0700487
488 DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
489 mOrigDeleteZoneParent = (ViewGroup) deleteZone.getParent();
490 mOrigDeleteZoneLayoutParams = deleteZone.getLayoutParams();
491 mOrigDeleteZoneParent.removeView(deleteZone);
492 deleteZone.setManageVisibility(false);
493 deleteZone.setVisibility(View.VISIBLE);
Patrick Dubroyb3c81cc2010-10-25 18:00:59 -0700494 deleteZone.setOnClickListener(new View.OnClickListener() {
495 public void onClick(View v) {
496 final ApplicationInfo appInfo = (ApplicationInfo) getChosenItem();
497 mLauncher.startApplicationUninstallActivity(appInfo);
498 }
499 });
Patrick Dubroydea9e932010-09-22 15:04:29 -0700500
501 menu.add(0, MENU_APP_INFO, 0, R.string.cab_menu_app_info).setActionView(infoButton);
502 menu.add(0, MENU_DELETE_APP, 0, R.string.cab_menu_delete_app).setActionView(deleteZone);
503
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700504 return true;
505 }
506
507 @Override
508 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700509 mDragController.addDropTarget(this);
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700510 return true;
511 }
512
513 @Override
514 public void onDestroyActionMode(ActionMode mode) {
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700515 final Menu menu = mode.getMenu();
516
Patrick Dubroydea9e932010-09-22 15:04:29 -0700517 // Re-parent the drop targets into the toolbar, and restore their layout params
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700518
Patrick Dubroydea9e932010-09-22 15:04:29 -0700519 ApplicationInfoDropTarget infoButton =
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700520 (ApplicationInfoDropTarget) menu.findItem(MENU_APP_INFO).getActionView();
Patrick Dubroydea9e932010-09-22 15:04:29 -0700521 ((ViewGroup) infoButton.getParent()).removeView(infoButton);
522 mOrigInfoButtonParent.addView(infoButton, mOrigInfoButtonLayoutParams);
523 infoButton.setVisibility(View.GONE);
524 infoButton.setManageVisibility(true);
525
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700526 DeleteZone deleteZone = (DeleteZone) menu.findItem(MENU_DELETE_APP).getActionView();
Patrick Dubroydea9e932010-09-22 15:04:29 -0700527 ((ViewGroup) deleteZone.getParent()).removeView(deleteZone);
528 mOrigDeleteZoneParent.addView(deleteZone, mOrigDeleteZoneLayoutParams);
529 deleteZone.setVisibility(View.GONE);
530 deleteZone.setManageVisibility(true);
531
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700532 mDragController.removeDropTarget(this);
533 endChoiceMode();
534 }
535
536 @Override
537 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
Patrick Dubroyb3c81cc2010-10-25 18:00:59 -0700538 // This is never called. Because we use setActionView(), we handle our own click events.
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700539 return false;
540 }
541
542 /*
543 * We don't actually use AllAppsPagedView as a drop target... it's only used to intercept a drop
544 * to the workspace.
545 */
546 @Override
547 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
548 DragView dragView, Object dragInfo) {
549 return false;
550 }
551 @Override
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700552 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset,
553 int yOffset, DragView dragView, Object dragInfo) {
554 return null;
555 }
556 @Override
557 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
558 DragView dragView, Object dragInfo) {}
559 @Override
560 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
561 DragView dragView, Object dragInfo) {}
562 @Override
563 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
564 DragView dragView, Object dragInfo) {}
565 @Override
566 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
567 DragView dragView, Object dragInfo) {}
Michael Jurka0280c3b2010-09-17 15:00:07 -0700568
569 public boolean isDropEnabled() {
570 return true;
571 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700572}