blob: 16fe6160ced16b8da5ff2d6b45a84915591a09cf [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;
Joe Onorato2e5c4322009-10-06 12:34:42 -07006import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08007import android.view.LayoutInflater;
8import android.view.View;
9import android.widget.ArrayAdapter;
10
11/**
12 * Folder which contains applications or shortcuts chosen by the user.
13 *
14 */
15public class UserFolder extends Folder implements DropTarget {
Joe Onorato2e5c4322009-10-06 12:34:42 -070016 private static final String TAG = "Launcher.UserFolder";
17
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018 public UserFolder(Context context, AttributeSet attrs) {
19 super(context, attrs);
20 }
21
22 /**
23 * Creates a new UserFolder, inflated from R.layout.user_folder.
24 *
25 * @param context The application's context.
26 *
27 * @return A new UserFolder.
28 */
29 static UserFolder fromXml(Context context) {
30 return (UserFolder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
31 }
32
33 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
Joe Onorato00acb122009-08-04 16:04:30 -040034 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035 final ItemInfo item = (ItemInfo) dragInfo;
36 final int itemType = item.itemType;
37 return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
Joe Onorato2e5c4322009-10-06 12:34:42 -070038 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT)
39 && item.container != mInfo.id;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040 }
Jeff Sharkey70864282009-04-07 21:08:40 -070041
Joe Onorato00acb122009-08-04 16:04:30 -040042 public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset,
43 DragView dragView, Object dragInfo, Rect recycle) {
Jeff Sharkey70864282009-04-07 21:08:40 -070044 return null;
45 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046
Joe Onorato00acb122009-08-04 16:04:30 -040047 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
48 DragView dragView, Object dragInfo) {
Joe Onorato2e5c4322009-10-06 12:34:42 -070049 ApplicationInfo item = (ApplicationInfo) dragInfo;
50 if (item.container == NO_ID) {
51 // Came from all apps -- make a copy
52 item = new ApplicationInfo((ApplicationInfo)item);
53 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080054 //noinspection unchecked
55 ((ArrayAdapter<ApplicationInfo>) mContent.getAdapter()).add((ApplicationInfo) dragInfo);
56 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
57 }
58
Joe Onorato00acb122009-08-04 16:04:30 -040059 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
60 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080061 }
62
Joe Onorato00acb122009-08-04 16:04:30 -040063 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
64 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065 }
66
Joe Onorato00acb122009-08-04 16:04:30 -040067 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
68 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069 }
70
71 @Override
72 public void onDropCompleted(View target, boolean success) {
73 if (success) {
74 //noinspection unchecked
75 ArrayAdapter<ApplicationInfo> adapter =
76 (ArrayAdapter<ApplicationInfo>) mContent.getAdapter();
77 adapter.remove(mDragItem);
78 }
79 }
80
81 void bind(FolderInfo info) {
82 super.bind(info);
83 setContentAdapter(new ApplicationsAdapter(mContext, ((UserFolderInfo) info).contents));
84 }
85
86 // When the folder opens, we need to refresh the GridView's selection by
87 // forcing a layout
88 @Override
89 void onOpen() {
90 super.onOpen();
91 requestFocus();
92 }
93}