blob: 149f9fb8a9d99a02e6bcee831823a88f9700c4b9 [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
97 public void setLauncher(Launcher launcher) {
98 mLauncher = launcher;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -070099 mLauncher.setAllAppsPagedView(this);
Winson Chung321e9ee2010-08-09 13:37:56 -0700100 }
101
102 @Override
103 public void setDragController(DragController dragger) {
104 mDragController = dragger;
105 }
106
107 public void setAppFilter(int filterType) {
108 mAppFilter = filterType;
Winson Chung80baf5a2010-08-09 16:03:15 -0700109 if (mApps != null) {
110 mFilteredApps = rebuildFilteredApps(mApps);
Winson Chung86f77532010-08-24 11:08:22 -0700111 setCurrentPage(0);
Winson Chung80baf5a2010-08-09 16:03:15 -0700112 invalidatePageData();
113 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700114 }
115
116 @Override
117 public void zoom(float zoom, boolean animate) {
118 mZoom = zoom;
119 cancelLongPress();
120
121 if (isVisible()) {
122 getParent().bringChildToFront(this);
123 setVisibility(View.VISIBLE);
124 if (animate) {
125 startAnimation(AnimationUtils.loadAnimation(getContext(),
126 R.anim.all_apps_2d_fade_in));
127 } else {
128 onAnimationEnd();
129 }
130 } else {
131 if (animate) {
132 startAnimation(AnimationUtils.loadAnimation(getContext(),
133 R.anim.all_apps_2d_fade_out));
134 } else {
135 onAnimationEnd();
136 }
137 }
138 }
139
140 protected void onAnimationEnd() {
141 if (!isVisible()) {
142 setVisibility(View.GONE);
143 mZoom = 0.0f;
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700144
145 endChoiceMode();
Winson Chung321e9ee2010-08-09 13:37:56 -0700146 } else {
147 mZoom = 1.0f;
148 }
149
150 if (mLauncher != null)
151 mLauncher.zoomed(mZoom);
152 }
153
154 private int getChildIndexForGrandChild(View v) {
155 final int childCount = getChildCount();
156 for (int i = 0; i < childCount; ++i) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700157 final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i);
Winson Chung321e9ee2010-08-09 13:37:56 -0700158 if (layout.indexOfChild(v) > -1) {
159 return i;
160 }
161 }
162 return -1;
163 }
164
165 @Override
166 public void onClick(View v) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700167 // if we are already in a choice mode, then just change the selection
168 if (v instanceof Checkable) {
169 if (!isChoiceMode(CHOICE_MODE_NONE)) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700170 Checkable c = (Checkable) v;
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700171 if (isChoiceMode(CHOICE_MODE_SINGLE)) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700172 // Uncheck all the other grandchildren, and toggle the clicked one
173 boolean wasChecked = c.isChecked();
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700174 resetCheckedGrandchildren();
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700175 c.setChecked(!wasChecked);
176 } else {
177 c.toggle();
178 }
179 if (getCheckedGrandchildren().size() == 0) {
180 endChoiceMode();
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700181 }
182
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700183 return;
184 }
185 }
186
187 // otherwise continue and launch the application
Winson Chung321e9ee2010-08-09 13:37:56 -0700188 int childIndex = getChildIndexForGrandChild(v);
Winson Chung86f77532010-08-24 11:08:22 -0700189 if (childIndex == getCurrentPage()) {
Winson Chung321e9ee2010-08-09 13:37:56 -0700190 final ApplicationInfo app = (ApplicationInfo) v.getTag();
191
Winson Chung80baf5a2010-08-09 16:03:15 -0700192 // animate some feedback to the click
193 animateClickFeedback(v, new Runnable() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700194 @Override
Winson Chung80baf5a2010-08-09 16:03:15 -0700195 public void run() {
Winson Chung321e9ee2010-08-09 13:37:56 -0700196 mLauncher.startActivitySafely(app.intent, app);
197 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700198 });
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700199
200 endChoiceMode();
Winson Chung321e9ee2010-08-09 13:37:56 -0700201 }
202 }
203
204 @Override
205 public boolean onLongClick(View v) {
206 if (!v.isInTouchMode()) {
207 return false;
208 }
209
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700210 if (v instanceof Checkable) {
211 // In preparation for drag, we always reset the checked grand children regardless of
212 // what choice mode we are in
213 resetCheckedGrandchildren();
214
215 // Toggle the selection on the dragged app
216 Checkable c = (Checkable) v;
217 c.toggle();
218 }
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700219
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700220 // Start choice mode AFTER the item is selected
221 if (isChoiceMode(CHOICE_MODE_NONE)) {
222 startChoiceMode(CHOICE_MODE_SINGLE, this);
223 }
224
Winson Chung321e9ee2010-08-09 13:37:56 -0700225 ApplicationInfo app = (ApplicationInfo) v.getTag();
226 app = new ApplicationInfo(app);
227
Michael Jurka3e7c7632010-10-02 16:01:03 -0700228 mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1);
Winson Chung321e9ee2010-08-09 13:37:56 -0700229 mDragController.startDrag(v, this, app, DragController.DRAG_ACTION_COPY);
Winson Chung321e9ee2010-08-09 13:37:56 -0700230 return true;
231 }
232
233 @Override
234 public void onDropCompleted(View target, boolean success) {
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700235 // close the choice action mode if we have a proper drop
236 if (target != this) {
237 endChoiceMode();
238 }
Michael Jurka3e7c7632010-10-02 16:01:03 -0700239 mLauncher.getWorkspace().onDragStopped();
Winson Chung321e9ee2010-08-09 13:37:56 -0700240 }
241
242 @Override
243 public boolean isVisible() {
244 return mZoom > 0.001f;
245 }
246
247 @Override
248 public boolean isAnimating() {
249 return (getAnimation() != null);
250 }
251
252 private ArrayList<ApplicationInfo> rebuildFilteredApps(ArrayList<ApplicationInfo> apps) {
253 ArrayList<ApplicationInfo> filteredApps = new ArrayList<ApplicationInfo>();
254 if (mAppFilter == ALL_APPS_FLAG) {
255 return apps;
256 } else {
257 final int length = apps.size();
258 for (int i = 0; i < length; ++i) {
259 ApplicationInfo info = apps.get(i);
260 if ((info.flags & mAppFilter) > 0) {
261 filteredApps.add(info);
262 }
263 }
264 }
265 return filteredApps;
266 }
267
268 @Override
269 public void setApps(ArrayList<ApplicationInfo> list) {
270 mApps = list;
Winson Chung80baf5a2010-08-09 16:03:15 -0700271 Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
Winson Chung321e9ee2010-08-09 13:37:56 -0700272 mFilteredApps = rebuildFilteredApps(mApps);
Winson Chung241c3b42010-08-25 16:53:03 -0700273 mPageViewIconCache.clear();
Winson Chung321e9ee2010-08-09 13:37:56 -0700274 invalidatePageData();
275 }
276
Winson Chung80baf5a2010-08-09 16:03:15 -0700277 private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
278 // we add it in place, in alphabetical order
279 final int count = list.size();
280 for (int i = 0; i < count; ++i) {
281 final ApplicationInfo info = list.get(i);
282 final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR);
283 if (index < 0) {
284 mApps.add(-(index + 1), info);
285 }
286 }
287 mFilteredApps = rebuildFilteredApps(mApps);
288 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700289 @Override
290 public void addApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700291 addAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700292 invalidatePageData();
293 }
294
Winson Chung80baf5a2010-08-09 16:03:15 -0700295 private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
Winson Chung10fefb12010-11-01 11:57:06 -0700296 // End the choice mode if any of the items in the list that are being removed are
297 // currently selected
298 ArrayList<Checkable> checkedList = getCheckedGrandchildren();
299 HashSet<ApplicationInfo> checkedAppInfos = new HashSet<ApplicationInfo>();
300 for (Checkable checked : checkedList) {
301 PagedViewIcon icon = (PagedViewIcon) checked;
302 checkedAppInfos.add((ApplicationInfo) icon.getTag());
303 }
304 for (ApplicationInfo info : list) {
305 if (checkedAppInfos.contains(info)) {
306 endChoiceMode();
307 break;
308 }
309 }
310
311 // Loop through all the apps and remove apps that have the same component
Winson Chung321e9ee2010-08-09 13:37:56 -0700312 final int length = list.size();
313 for (int i = 0; i < length; ++i) {
Winson Chung241c3b42010-08-25 16:53:03 -0700314 final ApplicationInfo info = list.get(i);
315 int removeIndex = findAppByComponent(mApps, info);
Winson Chung321e9ee2010-08-09 13:37:56 -0700316 if (removeIndex > -1) {
317 mApps.remove(removeIndex);
Winson Chung241c3b42010-08-25 16:53:03 -0700318 mPageViewIconCache.removeOutline(info);
Winson Chung321e9ee2010-08-09 13:37:56 -0700319 }
320 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700321 mFilteredApps = rebuildFilteredApps(mApps);
322 }
323 @Override
324 public void removeApps(ArrayList<ApplicationInfo> list) {
325 removeAppsWithoutInvalidate(list);
Winson Chung321e9ee2010-08-09 13:37:56 -0700326 invalidatePageData();
327 }
328
329 @Override
330 public void updateApps(ArrayList<ApplicationInfo> list) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700331 removeAppsWithoutInvalidate(list);
332 addAppsWithoutInvalidate(list);
333 invalidatePageData();
Winson Chung321e9ee2010-08-09 13:37:56 -0700334 }
335
336 private int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
337 ComponentName removeComponent = item.intent.getComponent();
338 final int length = list.size();
339 for (int i = 0; i < length; ++i) {
340 ApplicationInfo info = list.get(i);
341 if (info.intent.getComponent().equals(removeComponent)) {
342 return i;
343 }
344 }
345 return -1;
346 }
347
348 @Override
349 public void dumpState() {
350 ApplicationInfo.dumpApplicationInfoList(TAG, "mApps", mApps);
351 }
352
353 @Override
354 public void surrender() {
355 // do nothing?
356 }
357
358 @Override
359 public void syncPages() {
Winson Chung96785572010-10-14 13:37:13 -0700360 // ensure that we have the right number of pages (min of 1, since we have placeholders)
361 int numPages = Math.max(1,
362 (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY)));
Winson Chung321e9ee2010-08-09 13:37:56 -0700363 int curNumPages = getChildCount();
364 // remove any extra pages after the "last" page
365 int extraPageDiff = curNumPages - numPages;
366 for (int i = 0; i < extraPageDiff; ++i) {
367 removeViewAt(numPages);
368 }
369 // add any necessary pages
370 for (int i = curNumPages; i < numPages; ++i) {
371 PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
372 layout.setCellCount(mCellCountX, mCellCountY);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700373 layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
374 mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
Winson Chungdf4b83d2010-10-20 17:49:27 -0700375 layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
Winson Chung321e9ee2010-08-09 13:37:56 -0700376 addView(layout);
377 }
378
379 // bound the current page
Winson Chung86f77532010-08-24 11:08:22 -0700380 setCurrentPage(Math.max(0, Math.min(numPages - 1, getCurrentPage())));
Winson Chung321e9ee2010-08-09 13:37:56 -0700381 }
382
383 @Override
384 public void syncPageItems(int page) {
Winson Chung96785572010-10-14 13:37:13 -0700385 // Ensure that we have the right number of items on the pages
Winson Chung80baf5a2010-08-09 16:03:15 -0700386 final int cellsPerPage = mCellCountX * mCellCountY;
387 final int startIndex = page * cellsPerPage;
388 final int endIndex = Math.min(startIndex + cellsPerPage, mFilteredApps.size());
Winson Chung321e9ee2010-08-09 13:37:56 -0700389 PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
Winson Chung80baf5a2010-08-09 16:03:15 -0700390
Winson Chung96785572010-10-14 13:37:13 -0700391 if (!mFilteredApps.isEmpty()) {
392 int curNumPageItems = layout.getChildCount();
393 int numPageItems = endIndex - startIndex;
Winson Chung80baf5a2010-08-09 16:03:15 -0700394
Winson Chung96785572010-10-14 13:37:13 -0700395 // If we were previously an empty page, then restart anew
396 boolean wasEmptyPage = false;
397 if (curNumPageItems == 1) {
398 View icon = layout.getChildAt(0);
399 if (icon.getTag() == null) {
400 wasEmptyPage = true;
401 }
402 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700403
Winson Chung96785572010-10-14 13:37:13 -0700404 if (wasEmptyPage) {
405 // Remove all the previous items
406 curNumPageItems = 0;
407 layout.removeAllViews();
408 } else {
409 // Remove any extra items
410 int extraPageItemsDiff = curNumPageItems - numPageItems;
411 for (int i = 0; i < extraPageItemsDiff; ++i) {
412 layout.removeViewAt(numPageItems);
413 }
414 }
Winson Chung80baf5a2010-08-09 16:03:15 -0700415
Winson Chung96785572010-10-14 13:37:13 -0700416 // Add any necessary items
417 for (int i = curNumPageItems; i < numPageItems; ++i) {
418 TextView text = (TextView) mInflater.inflate(
419 R.layout.all_apps_paged_view_application, layout, false);
420 text.setOnClickListener(this);
421 text.setOnLongClickListener(this);
Winson Chung321e9ee2010-08-09 13:37:56 -0700422
Winson Chung96785572010-10-14 13:37:13 -0700423 layout.addViewToCellLayout(text, -1, i,
424 new PagedViewCellLayout.LayoutParams(0, 0, 1, 1));
425 }
426
427 // Actually reapply to the existing text views
428 for (int i = startIndex; i < endIndex; ++i) {
429 final int index = i - startIndex;
430 final ApplicationInfo info = mFilteredApps.get(i);
431 PagedViewIcon icon = (PagedViewIcon) layout.getChildAt(index);
Winson Chungdf4b83d2010-10-20 17:49:27 -0700432 icon.applyFromApplicationInfo(info, mPageViewIconCache, true);
Winson Chung96785572010-10-14 13:37:13 -0700433
434 PagedViewCellLayout.LayoutParams params =
435 (PagedViewCellLayout.LayoutParams) icon.getLayoutParams();
436 params.cellX = index % mCellCountX;
437 params.cellY = index / mCellCountX;
438 }
439
440 // Default to left-aligned icons
441 layout.enableCenteredContent(false);
442 } else {
443 // There are no items, so show the user a small message
444 TextView icon = (TextView) mInflater.inflate(
445 R.layout.all_apps_no_items_placeholder, layout, false);
446 switch (mAppFilter) {
Winson Chung96785572010-10-14 13:37:13 -0700447 case ApplicationInfo.DOWNLOADED_FLAG:
448 icon.setText(mContext.getString(R.string.all_apps_no_downloads));
449 break;
450 default: break;
451 }
452
453 // Center-align the message
454 layout.enableCenteredContent(true);
455 layout.removeAllViews();
456 layout.addViewToCellLayout(icon, -1, 0,
457 new PagedViewCellLayout.LayoutParams(0, 0, 2, 1));
Winson Chung321e9ee2010-08-09 13:37:56 -0700458 }
459 }
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700460 @Override
461 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
Michael Jurka3125d9d2010-09-27 11:30:20 -0700462 mode.setTitle(R.string.cab_app_selection_text);
Patrick Dubroy430c53b2010-09-08 16:01:19 -0700463
Patrick Dubroydea9e932010-09-22 15:04:29 -0700464 // Until the workspace has a selection mode and the CAB supports drag-and-drop, we
465 // take a hybrid approach: grab the views from the workspace and stuff them into the CAB.
466 // When the action mode is done, restore the views to their original place in the toolbar.
467
468 ApplicationInfoDropTarget infoButton =
469 (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
470 mOrigInfoButtonParent = (ViewGroup) infoButton.getParent();
471 mOrigInfoButtonLayoutParams = infoButton.getLayoutParams();
472 mOrigInfoButtonParent.removeView(infoButton);
473 infoButton.setManageVisibility(false);
474 infoButton.setVisibility(View.VISIBLE);
Patrick Dubroyb3c81cc2010-10-25 18:00:59 -0700475 infoButton.setOnClickListener(new View.OnClickListener() {
476 public void onClick(View v) {
477 final ApplicationInfo appInfo = (ApplicationInfo) getChosenItem();
478 mLauncher.startApplicationDetailsActivity(appInfo.componentName);
479 }
480 });
Patrick Dubroydea9e932010-09-22 15:04:29 -0700481
482 DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
483 mOrigDeleteZoneParent = (ViewGroup) deleteZone.getParent();
484 mOrigDeleteZoneLayoutParams = deleteZone.getLayoutParams();
485 mOrigDeleteZoneParent.removeView(deleteZone);
486 deleteZone.setManageVisibility(false);
487 deleteZone.setVisibility(View.VISIBLE);
Patrick Dubroyb3c81cc2010-10-25 18:00:59 -0700488 deleteZone.setOnClickListener(new View.OnClickListener() {
489 public void onClick(View v) {
490 final ApplicationInfo appInfo = (ApplicationInfo) getChosenItem();
491 mLauncher.startApplicationUninstallActivity(appInfo);
492 }
493 });
Patrick Dubroydea9e932010-09-22 15:04:29 -0700494
495 menu.add(0, MENU_APP_INFO, 0, R.string.cab_menu_app_info).setActionView(infoButton);
496 menu.add(0, MENU_DELETE_APP, 0, R.string.cab_menu_delete_app).setActionView(deleteZone);
497
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700498 return true;
499 }
500
501 @Override
502 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
Patrick Dubroy9f7aec82010-09-06 11:03:37 -0700503 mDragController.addDropTarget(this);
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700504 return true;
505 }
506
507 @Override
508 public void onDestroyActionMode(ActionMode mode) {
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700509 final Menu menu = mode.getMenu();
510
Patrick Dubroydea9e932010-09-22 15:04:29 -0700511 // Re-parent the drop targets into the toolbar, and restore their layout params
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700512
Patrick Dubroydea9e932010-09-22 15:04:29 -0700513 ApplicationInfoDropTarget infoButton =
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700514 (ApplicationInfoDropTarget) menu.findItem(MENU_APP_INFO).getActionView();
Patrick Dubroydea9e932010-09-22 15:04:29 -0700515 ((ViewGroup) infoButton.getParent()).removeView(infoButton);
516 mOrigInfoButtonParent.addView(infoButton, mOrigInfoButtonLayoutParams);
517 infoButton.setVisibility(View.GONE);
518 infoButton.setManageVisibility(true);
519
Patrick Dubroy3c6dbcd2010-10-25 14:24:36 -0700520 DeleteZone deleteZone = (DeleteZone) menu.findItem(MENU_DELETE_APP).getActionView();
Patrick Dubroydea9e932010-09-22 15:04:29 -0700521 ((ViewGroup) deleteZone.getParent()).removeView(deleteZone);
522 mOrigDeleteZoneParent.addView(deleteZone, mOrigDeleteZoneLayoutParams);
523 deleteZone.setVisibility(View.GONE);
524 deleteZone.setManageVisibility(true);
525
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700526 mDragController.removeDropTarget(this);
527 endChoiceMode();
528 }
529
530 @Override
531 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
Patrick Dubroyb3c81cc2010-10-25 18:00:59 -0700532 // This is never called. Because we use setActionView(), we handle our own click events.
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700533 return false;
534 }
535
536 /*
537 * We don't actually use AllAppsPagedView as a drop target... it's only used to intercept a drop
538 * to the workspace.
539 */
540 @Override
541 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
542 DragView dragView, Object dragInfo) {
543 return false;
544 }
545 @Override
Winson Chung5f2aa4e2010-08-20 14:49:25 -0700546 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset,
547 int yOffset, DragView dragView, Object dragInfo) {
548 return null;
549 }
550 @Override
551 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
552 DragView dragView, Object dragInfo) {}
553 @Override
554 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
555 DragView dragView, Object dragInfo) {}
556 @Override
557 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
558 DragView dragView, Object dragInfo) {}
559 @Override
560 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
561 DragView dragView, Object dragInfo) {}
Michael Jurka0280c3b2010-09-17 15:00:07 -0700562
563 public boolean isDropEnabled() {
564 return true;
565 }
Winson Chung321e9ee2010-08-09 13:37:56 -0700566}