blob: d6799f75e48bebcbfae36a4fe7d22e24a9405219 [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 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041
Joe Onorato00acb122009-08-04 16:04:30 -040042 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
43 DragView dragView, Object dragInfo) {
Joe Onorato0589f0f2010-02-08 13:44:00 -080044 ShortcutInfo item;
45 if (dragInfo instanceof ApplicationInfo) {
Joe Onorato2e5c4322009-10-06 12:34:42 -070046 // Came from all apps -- make a copy
Joe Onorato0589f0f2010-02-08 13:44:00 -080047 item = ((ApplicationInfo)dragInfo).makeShortcut();
48 } else {
49 item = (ShortcutInfo)dragInfo;
Joe Onorato2e5c4322009-10-06 12:34:42 -070050 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080051 ((ShortcutsAdapter)mContent.getAdapter()).add(item);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080052 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
53 }
54
Joe Onorato00acb122009-08-04 16:04:30 -040055 public void onDragEnter(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 onDragOver(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 onDragExit(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
67 @Override
68 public void onDropCompleted(View target, boolean success) {
69 if (success) {
Joe Onorato0589f0f2010-02-08 13:44:00 -080070 ShortcutsAdapter adapter = (ShortcutsAdapter)mContent.getAdapter();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071 adapter.remove(mDragItem);
72 }
73 }
74
Michael Jurka0280c3b2010-09-17 15:00:07 -070075 public boolean isDropEnabled() {
76 return true;
77 }
78
The Android Open Source Project31dd5032009-03-03 19:32:27 -080079 void bind(FolderInfo info) {
80 super.bind(info);
Joe Onorato0589f0f2010-02-08 13:44:00 -080081 setContentAdapter(new ShortcutsAdapter(mContext, ((UserFolderInfo) info).contents));
The Android Open Source Project31dd5032009-03-03 19:32:27 -080082 }
83
84 // When the folder opens, we need to refresh the GridView's selection by
85 // forcing a layout
86 @Override
87 void onOpen() {
88 super.onOpen();
89 requestFocus();
90 }
Patrick Dubroy440c3602010-07-13 17:50:32 -070091
92 @Override
93 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset,
94 DragView dragView, Object dragInfo) {
95 return null;
96 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097}