blob: 4ca5b474e21b89985d41ba21850cf0dfb530a702 [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
Patrick Dubroya669d792010-11-23 14:40:33 -0800240 public void onDragViewVisible() {
241 }
242
243 @Override
Winson Chung321e9ee2010-08-09 13:37:56 -0700244 public void onDropCompleted(View target, boolean success) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700245 // close the choice action mode if we have a proper drop
246 if (target != this) {
247 endChoiceMode();
248 }
Michael Jurka3e7c7632010-10-02 16:01:03 -0700249 mLauncher.getWorkspace().onDragStopped();
Winson Chung321e9ee2010-08-09 13:37:56 -0700250 }
251
252 @Override
253 public boolean isVisible() {
254 return mZoom > 0.001f;
255 }
256
257 @Override
258 public boolean isAnimating() {
259 return (getAnimation() != null);
260 }
261
262 private ArrayList<ApplicationInfo> rebuildFilteredApps(ArrayList<ApplicationInfo> apps) {
263 ArrayList<ApplicationInfo> filteredApps = new ArrayList<ApplicationInfo>();
264 if (mAppFilter == ALL_APPS_FLAG) {
265 return apps;
266 } else {
267 final int length = apps.size();
268 for (int i = 0; i < length; ++i) {
269 ApplicationInfo info = apps.get(i);
270 if ((info.flags & mAppFilter) > 0) {
271 filteredApps.add(info);
272 }
273 }
274 }
275 return filteredApps;
276 }
277
278 @Override
279 public void setApps(ArrayList<ApplicationInfo> list) {
280 mApps = list;
Winson Chung80baf5a2010-08-09 16:03:15 -0700281 Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
Winson Chung321e9ee2010-08-09 13:37:56 -0700282 mFilteredApps = rebuildFilteredApps(mApps);
Winson Chung241c3b42010-08-25 16:53:03 -0700283 mPageViewIconCache.clear();
Winson Chung321e9ee2010-08-09 13:37:56 -0700284 invalidatePageData();
285 }
286
Winson Chung80baf5a2010-08-09 16:03:15 -0700287 private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
288 // we add it in place, in alphabetical order
289 final int count = list.size();
290 for (int i = 0; i < count; ++i) {
291 final ApplicationInfo info = list.get(i);
292 final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR);
293 if (index < 0) {
294 mApps.add(-(index + 1), info);
295 }
296 }
297 mFilteredApps = rebuildFilteredApps(mApps);
298 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700299 @Override
300 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700301 addAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700302 invalidatePageData();
303 }
304
Winson Chung80baf5a2010-08-09 16:03:15 -0700305 private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
Winson Chung10fefb12010-11-01 11:57:06 -0700306 // End the choice mode if any of the items in the list that are being removed are
307 // currently selected
308 ArrayList<Checkable> checkedList = getCheckedGrandchildren();
309 HashSet<ApplicationInfo> checkedAppInfos = new HashSet<ApplicationInfo>();
310 for (Checkable checked : checkedList) {
311 PagedViewIcon icon = (PagedViewIcon) checked;
312 checkedAppInfos.add((ApplicationInfo) icon.getTag());
313 }
314 for (ApplicationInfo info : list) {
315 if (checkedAppInfos.contains(info)) {
316 endChoiceMode();
317 break;
318 }
319 }
320
321 // Loop through all the apps and remove apps that have the same component
Winson Chung321e9ee2010-08-09 13:37:56 -0700322 final int length = list.size();
323 for (int i = 0; i < length; ++i) {
Winson Chung241c3b42010-08-25 16:53:03 -0700324 final ApplicationInfo info = list.get(i);
325 int removeIndex = findAppByComponent(mApps, info);
Winson Chung321e9ee2010-08-09 13:37:56 -0700326 if (removeIndex > -1) {
327 mApps.remove(removeIndex);
Winson Chung241c3b42010-08-25 16:53:03 -0700328 mPageViewIconCache.removeOutline(info);
Winson Chung321e9ee2010-08-09 13:37:56 -0700329 }
330 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700331 mFilteredApps = rebuildFilteredApps(mApps);
332 }
333 @Override
334 public void removeApps(ArrayList<ApplicationInfo> list) {
335 removeAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700336 invalidatePageData();
337 }
338
339 @Override
340 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700341 removeAppsWithoutInvalidate(list);
342 addAppsWithoutInvalidate(list);
343 invalidatePageData();
Winson Chung321e9ee2010-08-09 13:37:56 -0700344 }
345
346 private int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
347 ComponentName removeComponent = item.intent.getComponent();
348 final int length = list.size();
349 for (int i = 0; i < length; ++i) {
350 ApplicationInfo info = list.get(i);
351 if (info.intent.getComponent().equals(removeComponent)) {
352 return i;
353 }
354 }
355 return -1;
356 }
357
358 @Override
359 public void dumpState() {
360 ApplicationInfo.dumpApplicationInfoList(TAG, "mApps", mApps);
361 }
362
363 @Override
364 public void surrender() {
365 // do nothing?
366 }
367
368 @Override
369 public void syncPages() {
Winson Chung96785572010-10-14 13:37:13 -0700370 // ensure that we have the right number of pages (min of 1, since we have placeholders)
371 int numPages = Math.max(1,
372 (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY)));
Winson Chung321e9ee2010-08-09 13:37:56 -0700373 int curNumPages = getChildCount();
374 // remove any extra pages after the "last" page
375 int extraPageDiff = curNumPages - numPages;
376 for (int i = 0; i < extraPageDiff; ++i) {
377 removeViewAt(numPages);
378 }
379 // add any necessary pages
380 for (int i = curNumPages; i < numPages; ++i) {
381 PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
382 layout.setCellCount(mCellCountX, mCellCountY);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700383 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
384 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
Winson Chungdf4b83d2010-10-20 17:49:27 -0700385 layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
Winson Chung321e9ee2010-08-09 13:37:56 -0700386 addView(layout);
387 }
388
389 // bound the current page
Winson Chung86f77532010-08-24 11:08:22 -0700390 setCurrentPage(Math.max(0, Math.min(numPages - 1, getCurrentPage())));
Winson Chung321e9ee2010-08-09 13:37:56 -0700391 }
392
393 @Override
394 public void syncPageItems(int page) {
Winson Chung96785572010-10-14 13:37:13 -0700395 // Ensure that we have the right number of items on the pages
Winson Chung80baf5a2010-08-09 16:03:15 -0700396 final int cellsPerPage = mCellCountX * mCellCountY;
397 final int startIndex = page * cellsPerPage;
398 final int endIndex = Math.min(startIndex + cellsPerPage, mFilteredApps.size());
Winson Chung321e9ee2010-08-09 13:37:56 -0700399 PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
Winson Chung80baf5a2010-08-09 16:03:15 -0700400
Winson Chung96785572010-10-14 13:37:13 -0700401 if (!mFilteredApps.isEmpty()) {
402 int curNumPageItems = layout.getChildCount();
403 int numPageItems = endIndex - startIndex;
Winson Chung80baf5a2010-08-09 16:03:15 -0700404
Winson Chung96785572010-10-14 13:37:13 -0700405 // If we were previously an empty page, then restart anew
406 boolean wasEmptyPage = false;
407 if (curNumPageItems == 1) {
408 View icon = layout.getChildAt(0);
409 if (icon.getTag() == null) {
410 wasEmptyPage = true;
411 }
412 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700413
Winson Chung96785572010-10-14 13:37:13 -0700414 if (wasEmptyPage) {
415 // Remove all the previous items
416 curNumPageItems = 0;
417 layout.removeAllViews();
418 } else {
419 // Remove any extra items
420 int extraPageItemsDiff = curNumPageItems - numPageItems;
421 for (int i = 0; i < extraPageItemsDiff; ++i) {
422 layout.removeViewAt(numPageItems);
423 }
424 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700425
Winson Chung96785572010-10-14 13:37:13 -0700426 // Add any necessary items
427 for (int i = curNumPageItems; i < numPageItems; ++i) {
428 TextView text = (TextView) mInflater.inflate(
429 R.layout.all_apps_paged_view_application, layout, false);
430 text.setOnClickListener(this);
431 text.setOnLongClickListener(this);
Winson Chung321e9ee2010-08-09 13:37:56 -0700432
Winson Chung96785572010-10-14 13:37:13 -0700433 layout.addViewToCellLayout(text, -1, i,
434 new PagedViewCellLayout.LayoutParams(0, 0, 1, 1));
435 }
436
437 // Actually reapply to the existing text views
438 for (int i = startIndex; i < endIndex; ++i) {
439 final int index = i - startIndex;
440 final ApplicationInfo info = mFilteredApps.get(i);
441 PagedViewIcon icon = (PagedViewIcon) layout.getChildAt(index);
Winson Chungdf4b83d2010-10-20 17:49:27 -0700442 icon.applyFromApplicationInfo(info, mPageViewIconCache, true);
Winson Chung96785572010-10-14 13:37:13 -0700443
444 PagedViewCellLayout.LayoutParams params =
445 (PagedViewCellLayout.LayoutParams) icon.getLayoutParams();
446 params.cellX = index % mCellCountX;
447 params.cellY = index / mCellCountX;
448 }
449
450 // Default to left-aligned icons
451 layout.enableCenteredContent(false);
452 } else {
453 // There are no items, so show the user a small message
454 TextView icon = (TextView) mInflater.inflate(
455 R.layout.all_apps_no_items_placeholder, layout, false);
456 switch (mAppFilter) {
Winson Chung96785572010-10-14 13:37:13 -0700457 case ApplicationInfo.DOWNLOADED_FLAG:
458 icon.setText(mContext.getString(R.string.all_apps_no_downloads));
459 break;
460 default: break;
461 }
462
463 // Center-align the message
464 layout.enableCenteredContent(true);
465 layout.removeAllViews();
466 layout.addViewToCellLayout(icon, -1, 0,
467 new PagedViewCellLayout.LayoutParams(0, 0, 2, 1));
Winson Chung321e9ee2010-08-09 13:37:56 -0700468 }
469 }
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700470 @Override
471 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
Michael Jurka3125d9d2010-09-27 11:30:20 -0700472 mode.setTitle(R.string.cab_app_selection_text);
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700473
Patrick Dubroydea9e932010-09-22 15:04:29 -0700474 // Until the workspace has a selection mode and the CAB supports drag-and-drop, we
475 // take a hybrid approach: grab the views from the workspace and stuff them into the CAB.
476 // When the action mode is done, restore the views to their original place in the toolbar.
477
478 ApplicationInfoDropTarget infoButton =
479 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
480 mOrigInfoButtonParent = (ViewGroup) infoButton.getParent();
481 mOrigInfoButtonLayoutParams = infoButton.getLayoutParams();
482 mOrigInfoButtonParent.removeView(infoButton);
483 infoButton.setManageVisibility(false);
484 infoButton.setVisibility(View.VISIBLE);
Patrick Dubroyb3c81cc2010-10-25 18:00:59 -0700485 infoButton.setOnClickListener(new View.OnClickListener() {
486 public void onClick(View v) {
487 final ApplicationInfo appInfo = (ApplicationInfo) getChosenItem();
488 mLauncher.startApplicationDetailsActivity(appInfo.componentName);
489 }
490 });
Patrick Dubroydea9e932010-09-22 15:04:29 -0700491
492 DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
493 mOrigDeleteZoneParent = (ViewGroup) deleteZone.getParent();
494 mOrigDeleteZoneLayoutParams = deleteZone.getLayoutParams();
495 mOrigDeleteZoneParent.removeView(deleteZone);
496 deleteZone.setManageVisibility(false);
497 deleteZone.setVisibility(View.VISIBLE);
Patrick Dubroyb3c81cc2010-10-25 18:00:59 -0700498 deleteZone.setOnClickListener(new View.OnClickListener() {
499 public void onClick(View v) {
500 final ApplicationInfo appInfo = (ApplicationInfo) getChosenItem();
501 mLauncher.startApplicationUninstallActivity(appInfo);
502 }
503 });
Patrick Dubroydea9e932010-09-22 15:04:29 -0700504
Patrick Dubroydea9e932010-09-22 15:04:29 -0700505 menu.add(0, MENU_DELETE_APP, 0, R.string.cab_menu_delete_app).setActionView(deleteZone);
Adam Lesinski6b879f02010-11-04 16:15:23 -0700506 menu.add(0, MENU_APP_INFO, 0, R.string.cab_menu_app_info).setActionView(infoButton);
507
508 mLauncher.getWorkspace().shrinkToBottomVisible();
Patrick Dubroydea9e932010-09-22 15:04:29 -0700509
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700510 return true;
511 }
512
513 @Override
514 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700515 mDragController.addDropTarget(this);
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700516 return true;
517 }
518
519 @Override
520 public void onDestroyActionMode(ActionMode mode) {
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700521 final Menu menu = mode.getMenu();
522
Patrick Dubroydea9e932010-09-22 15:04:29 -0700523 // Re-parent the drop targets into the toolbar, and restore their layout params
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700524
Patrick Dubroydea9e932010-09-22 15:04:29 -0700525 ApplicationInfoDropTarget infoButton =
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700526 (ApplicationInfoDropTarget) menu.findItem(MENU_APP_INFO).getActionView();
Patrick Dubroydea9e932010-09-22 15:04:29 -0700527 ((ViewGroup) infoButton.getParent()).removeView(infoButton);
528 mOrigInfoButtonParent.addView(infoButton, mOrigInfoButtonLayoutParams);
529 infoButton.setVisibility(View.GONE);
530 infoButton.setManageVisibility(true);
531
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700532 DeleteZone deleteZone = (DeleteZone) menu.findItem(MENU_DELETE_APP).getActionView();
Patrick Dubroydea9e932010-09-22 15:04:29 -0700533 ((ViewGroup) deleteZone.getParent()).removeView(deleteZone);
534 mOrigDeleteZoneParent.addView(deleteZone, mOrigDeleteZoneLayoutParams);
535 deleteZone.setVisibility(View.GONE);
536 deleteZone.setManageVisibility(true);
537
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700538 mDragController.removeDropTarget(this);
539 endChoiceMode();
540 }
541
542 @Override
543 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
Patrick Dubroyb3c81cc2010-10-25 18:00:59 -0700544 // This is never called. Because we use setActionView(), we handle our own click events.
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700545 return false;
546 }
547
548 /*
549 * We don't actually use AllAppsPagedView as a drop target... it's only used to intercept a drop
550 * to the workspace.
551 */
552 @Override
553 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
554 DragView dragView, Object dragInfo) {
555 return false;
556 }
557 @Override
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700558 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset,
559 int yOffset, DragView dragView, Object dragInfo) {
560 return null;
561 }
562 @Override
563 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
564 DragView dragView, Object dragInfo) {}
565 @Override
566 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
567 DragView dragView, Object dragInfo) {}
568 @Override
569 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
570 DragView dragView, Object dragInfo) {}
571 @Override
572 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
573 DragView dragView, Object dragInfo) {}
Michael Jurka0280c3b2010-09-17 15:00:07 -0700574
575 public boolean isDropEnabled() {
576 return true;
577 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700578}