blob: a5e90587e2fe7cc83bbe7ee8cc1a8d84f6ea09b5 [file] [log] [blame]
Joe Onoratoa5902522009-07-30 13:37:37 -07001package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002
3import android.content.Context;
Jeff Sharkey70864282009-04-07 21:08:40 -07004import android.graphics.Rect;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08005import android.util.AttributeSet;
6import android.view.LayoutInflater;
7import android.view.View;
8import android.widget.ArrayAdapter;
9
10/**
11 * Folder which contains applications or shortcuts chosen by the user.
12 *
13 */
14public class UserFolder extends Folder implements DropTarget {
15 public UserFolder(Context context, AttributeSet attrs) {
16 super(context, attrs);
17 }
18
19 /**
20 * Creates a new UserFolder, inflated from R.layout.user_folder.
21 *
22 * @param context The application's context.
23 *
24 * @return A new UserFolder.
25 */
26 static UserFolder fromXml(Context context) {
27 return (UserFolder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
28 }
29
30 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
31 Object dragInfo) {
32 final ItemInfo item = (ItemInfo) dragInfo;
33 final int itemType = item.itemType;
34 return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
35 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) && item.container != mInfo.id;
36 }
Jeff Sharkey70864282009-04-07 21:08:40 -070037
38 public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo, Rect recycle) {
39 return null;
40 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041
42 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) {
43 final ApplicationInfo item = (ApplicationInfo) dragInfo;
44 //noinspection unchecked
45 ((ArrayAdapter<ApplicationInfo>) mContent.getAdapter()).add((ApplicationInfo) dragInfo);
46 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
47 }
48
49 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) {
50 }
51
52 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) {
53 }
54
55 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) {
56 }
57
58 @Override
59 public void onDropCompleted(View target, boolean success) {
60 if (success) {
61 //noinspection unchecked
62 ArrayAdapter<ApplicationInfo> adapter =
63 (ArrayAdapter<ApplicationInfo>) mContent.getAdapter();
64 adapter.remove(mDragItem);
65 }
66 }
67
68 void bind(FolderInfo info) {
69 super.bind(info);
70 setContentAdapter(new ApplicationsAdapter(mContext, ((UserFolderInfo) info).contents));
71 }
72
73 // When the folder opens, we need to refresh the GridView's selection by
74 // forcing a layout
75 @Override
76 void onOpen() {
77 super.onOpen();
78 requestFocus();
79 }
80}