blob: 1379be6d09ebab75033dd8d2d0437e10f0565873 [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,
Joe Onorato00acb122009-08-04 16:04:30 -040031 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032 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
Joe Onorato00acb122009-08-04 16:04:30 -040038 public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset,
39 DragView dragView, Object dragInfo, Rect recycle) {
Jeff Sharkey70864282009-04-07 21:08:40 -070040 return null;
41 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042
Joe Onorato00acb122009-08-04 16:04:30 -040043 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
44 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045 final ApplicationInfo item = (ApplicationInfo) dragInfo;
46 //noinspection unchecked
47 ((ArrayAdapter<ApplicationInfo>) mContent.getAdapter()).add((ApplicationInfo) dragInfo);
48 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
49 }
50
Joe Onorato00acb122009-08-04 16:04:30 -040051 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
52 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080053 }
54
Joe Onorato00acb122009-08-04 16:04:30 -040055 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
56 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057 }
58
Joe Onorato00acb122009-08-04 16:04:30 -040059 public void onDragExit(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
63 @Override
64 public void onDropCompleted(View target, boolean success) {
65 if (success) {
66 //noinspection unchecked
67 ArrayAdapter<ApplicationInfo> adapter =
68 (ArrayAdapter<ApplicationInfo>) mContent.getAdapter();
69 adapter.remove(mDragItem);
70 }
71 }
72
73 void bind(FolderInfo info) {
74 super.bind(info);
75 setContentAdapter(new ApplicationsAdapter(mContext, ((UserFolderInfo) info).contents));
76 }
77
78 // When the folder opens, we need to refresh the GridView's selection by
79 // forcing a layout
80 @Override
81 void onOpen() {
82 super.onOpen();
83 requestFocus();
84 }
85}