blob: 251b3f95ab12ba70769224418eca3e16592dc023 [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;
4import android.util.AttributeSet;
5import android.view.LayoutInflater;
6import android.view.View;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08007
Romain Guyedcce092010-03-04 13:03:17 -08008import com.android.launcher.R;
9
The Android Open Source Project31dd5032009-03-03 19:32:27 -080010/**
11 * Folder which contains applications or shortcuts chosen by the user.
12 *
13 */
14public class UserFolder extends Folder implements DropTarget {
Joe Onorato2e5c4322009-10-06 12:34:42 -070015 private static final String TAG = "Launcher.UserFolder";
16
The Android Open Source Project31dd5032009-03-03 19:32:27 -080017 public UserFolder(Context context, AttributeSet attrs) {
18 super(context, attrs);
19 }
20
21 /**
22 * Creates a new UserFolder, inflated from R.layout.user_folder.
23 *
24 * @param context The application's context.
25 *
26 * @return A new UserFolder.
27 */
28 static UserFolder fromXml(Context context) {
29 return (UserFolder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
30 }
31
32 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
Joe Onorato00acb122009-08-04 16:04:30 -040033 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034 final ItemInfo item = (ItemInfo) dragInfo;
35 final int itemType = item.itemType;
36 return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
Joe Onorato2e5c4322009-10-06 12:34:42 -070037 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT)
38 && item.container != mInfo.id;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040
Joe Onorato00acb122009-08-04 16:04:30 -040041 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
42 DragView dragView, Object dragInfo) {
Joe Onorato0589f0f2010-02-08 13:44:00 -080043 ShortcutInfo item;
44 if (dragInfo instanceof ApplicationInfo) {
Joe Onorato2e5c4322009-10-06 12:34:42 -070045 // Came from all apps -- make a copy
Joe Onorato0589f0f2010-02-08 13:44:00 -080046 item = ((ApplicationInfo)dragInfo).makeShortcut();
47 } else {
48 item = (ShortcutInfo)dragInfo;
Joe Onorato2e5c4322009-10-06 12:34:42 -070049 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080050 ((ShortcutsAdapter)mContent.getAdapter()).add(item);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
52 }
53
Joe Onorato00acb122009-08-04 16:04:30 -040054 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
55 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080056 }
57
Joe Onorato00acb122009-08-04 16:04:30 -040058 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
59 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060 }
61
Joe Onorato00acb122009-08-04 16:04:30 -040062 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
63 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064 }
65
66 @Override
Patrick Dubroy5f445422011-02-18 14:35:21 -080067 public void onDropCompleted(View target, Object dragInfo, boolean success) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068 if (success) {
Joe Onorato0589f0f2010-02-08 13:44:00 -080069 ShortcutsAdapter adapter = (ShortcutsAdapter)mContent.getAdapter();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070 adapter.remove(mDragItem);
71 }
72 }
73
Michael Jurka0280c3b2010-09-17 15:00:07 -070074 public boolean isDropEnabled() {
75 return true;
76 }
77
The Android Open Source Project31dd5032009-03-03 19:32:27 -080078 void bind(FolderInfo info) {
79 super.bind(info);
Joe Onorato0589f0f2010-02-08 13:44:00 -080080 setContentAdapter(new ShortcutsAdapter(mContext, ((UserFolderInfo) info).contents));
The Android Open Source Project31dd5032009-03-03 19:32:27 -080081 }
82
83 // When the folder opens, we need to refresh the GridView's selection by
84 // forcing a layout
85 @Override
86 void onOpen() {
87 super.onOpen();
88 requestFocus();
89 }
Patrick Dubroy440c3602010-07-13 17:50:32 -070090
91 @Override
92 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset,
93 DragView dragView, Object dragInfo) {
94 return null;
95 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080096}