blob: 4dcdb818d2e549b6d6bed24b40fef93eb2c7fbad [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 Chungdf4b83d2010-10-20 17:49:27 -0700361 layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
Winson Chung321e9ee2010-08-09 13:37:56 -0700362 addView(layout);
363 }
364
365 // bound the current page
Winson Chung86f77532010-08-24 11:08:22 -0700366 setCurrentPage(Math.max(0, Math.min(numPages - 1, getCurrentPage())));
Winson Chung321e9ee2010-08-09 13:37:56 -0700367 }
368
369 @Override
370 public void syncPageItems(int page) {
Winson Chung96785572010-10-14 13:37:13 -0700371 // Ensure that we have the right number of items on the pages
Winson Chung80baf5a2010-08-09 16:03:15 -0700372 final int cellsPerPage = mCellCountX * mCellCountY;
373 final int startIndex = page * cellsPerPage;
374 final int endIndex = Math.min(startIndex + cellsPerPage, mFilteredApps.size());
Winson Chung321e9ee2010-08-09 13:37:56 -0700375 PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
Winson Chung80baf5a2010-08-09 16:03:15 -0700376
Winson Chung96785572010-10-14 13:37:13 -0700377 if (!mFilteredApps.isEmpty()) {
378 int curNumPageItems = layout.getChildCount();
379 int numPageItems = endIndex - startIndex;
Winson Chung80baf5a2010-08-09 16:03:15 -0700380
Winson Chung96785572010-10-14 13:37:13 -0700381 // If we were previously an empty page, then restart anew
382 boolean wasEmptyPage = false;
383 if (curNumPageItems == 1) {
384 View icon = layout.getChildAt(0);
385 if (icon.getTag() == null) {
386 wasEmptyPage = true;
387 }
388 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700389
Winson Chung96785572010-10-14 13:37:13 -0700390 if (wasEmptyPage) {
391 // Remove all the previous items
392 curNumPageItems = 0;
393 layout.removeAllViews();
394 } else {
395 // Remove any extra items
396 int extraPageItemsDiff = curNumPageItems - numPageItems;
397 for (int i = 0; i < extraPageItemsDiff; ++i) {
398 layout.removeViewAt(numPageItems);
399 }
400 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700401
Winson Chung96785572010-10-14 13:37:13 -0700402 // Add any necessary items
403 for (int i = curNumPageItems; i < numPageItems; ++i) {
404 TextView text = (TextView) mInflater.inflate(
405 R.layout.all_apps_paged_view_application, layout, false);
406 text.setOnClickListener(this);
407 text.setOnLongClickListener(this);
Winson Chung321e9ee2010-08-09 13:37:56 -0700408
Winson Chung96785572010-10-14 13:37:13 -0700409 layout.addViewToCellLayout(text, -1, i,
410 new PagedViewCellLayout.LayoutParams(0, 0, 1, 1));
411 }
412
413 // Actually reapply to the existing text views
414 for (int i = startIndex; i < endIndex; ++i) {
415 final int index = i - startIndex;
416 final ApplicationInfo info = mFilteredApps.get(i);
417 PagedViewIcon icon = (PagedViewIcon) layout.getChildAt(index);
Winson Chungdf4b83d2010-10-20 17:49:27 -0700418 icon.applyFromApplicationInfo(info, mPageViewIconCache, true);
Winson Chung96785572010-10-14 13:37:13 -0700419
420 PagedViewCellLayout.LayoutParams params =
421 (PagedViewCellLayout.LayoutParams) icon.getLayoutParams();
422 params.cellX = index % mCellCountX;
423 params.cellY = index / mCellCountX;
424 }
425
426 // Default to left-aligned icons
427 layout.enableCenteredContent(false);
428 } else {
429 // There are no items, so show the user a small message
430 TextView icon = (TextView) mInflater.inflate(
431 R.layout.all_apps_no_items_placeholder, layout, false);
432 switch (mAppFilter) {
Winson Chung96785572010-10-14 13:37:13 -0700433 case ApplicationInfo.DOWNLOADED_FLAG:
434 icon.setText(mContext.getString(R.string.all_apps_no_downloads));
435 break;
436 default: break;
437 }
438
439 // Center-align the message
440 layout.enableCenteredContent(true);
441 layout.removeAllViews();
442 layout.addViewToCellLayout(icon, -1, 0,
443 new PagedViewCellLayout.LayoutParams(0, 0, 2, 1));
Winson Chung321e9ee2010-08-09 13:37:56 -0700444 }
445 }
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700446 @Override
447 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
Michael Jurka3125d9d2010-09-27 11:30:20 -0700448 mode.setTitle(R.string.cab_app_selection_text);
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700449
Patrick Dubroydea9e932010-09-22 15:04:29 -0700450 // Until the workspace has a selection mode and the CAB supports drag-and-drop, we
451 // take a hybrid approach: grab the views from the workspace and stuff them into the CAB.
452 // When the action mode is done, restore the views to their original place in the toolbar.
453
454 ApplicationInfoDropTarget infoButton =
455 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
456 mOrigInfoButtonParent = (ViewGroup) infoButton.getParent();
457 mOrigInfoButtonLayoutParams = infoButton.getLayoutParams();
458 mOrigInfoButtonParent.removeView(infoButton);
459 infoButton.setManageVisibility(false);
460 infoButton.setVisibility(View.VISIBLE);
Patrick Dubroyb3c81cc2010-10-25 18:00:59 -0700461 infoButton.setOnClickListener(new View.OnClickListener() {
462 public void onClick(View v) {
463 final ApplicationInfo appInfo = (ApplicationInfo) getChosenItem();
464 mLauncher.startApplicationDetailsActivity(appInfo.componentName);
465 }
466 });
Patrick Dubroydea9e932010-09-22 15:04:29 -0700467
468 DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
469 mOrigDeleteZoneParent = (ViewGroup) deleteZone.getParent();
470 mOrigDeleteZoneLayoutParams = deleteZone.getLayoutParams();
471 mOrigDeleteZoneParent.removeView(deleteZone);
472 deleteZone.setManageVisibility(false);
473 deleteZone.setVisibility(View.VISIBLE);
Patrick Dubroyb3c81cc2010-10-25 18:00:59 -0700474 deleteZone.setOnClickListener(new View.OnClickListener() {
475 public void onClick(View v) {
476 final ApplicationInfo appInfo = (ApplicationInfo) getChosenItem();
477 mLauncher.startApplicationUninstallActivity(appInfo);
478 }
479 });
Patrick Dubroydea9e932010-09-22 15:04:29 -0700480
481 menu.add(0, MENU_APP_INFO, 0, R.string.cab_menu_app_info).setActionView(infoButton);
482 menu.add(0, MENU_DELETE_APP, 0, R.string.cab_menu_delete_app).setActionView(deleteZone);
483
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700484 return true;
485 }
486
487 @Override
488 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700489 mDragController.addDropTarget(this);
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700490 return true;
491 }
492
493 @Override
494 public void onDestroyActionMode(ActionMode mode) {
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700495 final Menu menu = mode.getMenu();
496
Patrick Dubroydea9e932010-09-22 15:04:29 -0700497 // Re-parent the drop targets into the toolbar, and restore their layout params
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700498
Patrick Dubroydea9e932010-09-22 15:04:29 -0700499 ApplicationInfoDropTarget infoButton =
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700500 (ApplicationInfoDropTarget) menu.findItem(MENU_APP_INFO).getActionView();
Patrick Dubroydea9e932010-09-22 15:04:29 -0700501 ((ViewGroup) infoButton.getParent()).removeView(infoButton);
502 mOrigInfoButtonParent.addView(infoButton, mOrigInfoButtonLayoutParams);
503 infoButton.setVisibility(View.GONE);
504 infoButton.setManageVisibility(true);
505
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700506 DeleteZone deleteZone = (DeleteZone) menu.findItem(MENU_DELETE_APP).getActionView();
Patrick Dubroydea9e932010-09-22 15:04:29 -0700507 ((ViewGroup) deleteZone.getParent()).removeView(deleteZone);
508 mOrigDeleteZoneParent.addView(deleteZone, mOrigDeleteZoneLayoutParams);
509 deleteZone.setVisibility(View.GONE);
510 deleteZone.setManageVisibility(true);
511
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700512 mDragController.removeDropTarget(this);
513 endChoiceMode();
514 }
515
516 @Override
517 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
Patrick Dubroyb3c81cc2010-10-25 18:00:59 -0700518 // This is never called. Because we use setActionView(), we handle our own click events.
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700519 return false;
520 }
521
522 /*
523 * We don't actually use AllAppsPagedView as a drop target... it's only used to intercept a drop
524 * to the workspace.
525 */
526 @Override
527 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
528 DragView dragView, Object dragInfo) {
529 return false;
530 }
531 @Override
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700532 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset,
533 int yOffset, DragView dragView, Object dragInfo) {
534 return null;
535 }
536 @Override
537 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
538 DragView dragView, Object dragInfo) {}
539 @Override
540 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
541 DragView dragView, Object dragInfo) {}
542 @Override
543 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
544 DragView dragView, Object dragInfo) {}
545 @Override
546 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
547 DragView dragView, Object dragInfo) {}
Michael Jurka0280c3b2010-09-17 15:00:07 -0700548
549 public boolean isDropEnabled() {
550 return true;
551 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700552}