blob: b46e92414e3821e6cddc21ebb672e6f5d87c4de4 [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;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08008
Romain Guyedcce092010-03-04 13:03:17 -08009import com.android.launcher.R;
10
The Android Open Source Project31dd5032009-03-03 19:32:27 -080011/**
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 Onorato0589f0f2010-02-08 13:44:00 -080049 ShortcutInfo item;
50 if (dragInfo instanceof ApplicationInfo) {
Joe Onorato2e5c4322009-10-06 12:34:42 -070051 // Came from all apps -- make a copy
Joe Onorato0589f0f2010-02-08 13:44:00 -080052 item = ((ApplicationInfo)dragInfo).makeShortcut();
53 } else {
54 item = (ShortcutInfo)dragInfo;
Joe Onorato2e5c4322009-10-06 12:34:42 -070055 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080056 ((ShortcutsAdapter)mContent.getAdapter()).add(item);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
58 }
59
Joe Onorato00acb122009-08-04 16:04:30 -040060 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
61 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062 }
63
Joe Onorato00acb122009-08-04 16:04:30 -040064 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
65 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066 }
67
Joe Onorato00acb122009-08-04 16:04:30 -040068 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
69 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070 }
71
72 @Override
73 public void onDropCompleted(View target, boolean success) {
74 if (success) {
Joe Onorato0589f0f2010-02-08 13:44:00 -080075 ShortcutsAdapter adapter = (ShortcutsAdapter)mContent.getAdapter();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076 adapter.remove(mDragItem);
77 }
78 }
79
80 void bind(FolderInfo info) {
81 super.bind(info);
Joe Onorato0589f0f2010-02-08 13:44:00 -080082 setContentAdapter(new ShortcutsAdapter(mContext, ((UserFolderInfo) info).contents));
The Android Open Source Project31dd5032009-03-03 19:32:27 -080083 }
84
85 // When the folder opens, we need to refresh the GridView's selection by
86 // forcing a layout
87 @Override
88 void onOpen() {
89 super.onOpen();
90 requestFocus();
91 }
Patrick Dubroy440c3602010-07-13 17:50:32 -070092
93 @Override
94 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset,
95 DragView dragView, Object dragInfo) {
96 return null;
97 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080098}