blob: d49c27aea1c22023336164cb2aa63461368e9c13 [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
Romain Guyedcce092010-03-04 13:03:17 -080011import com.android.launcher.R;
12
The Android Open Source Project31dd5032009-03-03 19:32:27 -080013/**
14 * Folder which contains applications or shortcuts chosen by the user.
15 *
16 */
17public class UserFolder extends Folder implements DropTarget {
Joe Onorato2e5c4322009-10-06 12:34:42 -070018 private static final String TAG = "Launcher.UserFolder";
19
The Android Open Source Project31dd5032009-03-03 19:32:27 -080020 public UserFolder(Context context, AttributeSet attrs) {
21 super(context, attrs);
22 }
23
24 /**
25 * Creates a new UserFolder, inflated from R.layout.user_folder.
26 *
27 * @param context The application's context.
28 *
29 * @return A new UserFolder.
30 */
31 static UserFolder fromXml(Context context) {
32 return (UserFolder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
33 }
34
35 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
Joe Onorato00acb122009-08-04 16:04:30 -040036 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080037 final ItemInfo item = (ItemInfo) dragInfo;
38 final int itemType = item.itemType;
39 return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
Joe Onorato2e5c4322009-10-06 12:34:42 -070040 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT)
41 && item.container != mInfo.id;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042 }
Jeff Sharkey70864282009-04-07 21:08:40 -070043
Joe Onorato00acb122009-08-04 16:04:30 -040044 public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset,
45 DragView dragView, Object dragInfo, Rect recycle) {
Jeff Sharkey70864282009-04-07 21:08:40 -070046 return null;
47 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048
Joe Onorato00acb122009-08-04 16:04:30 -040049 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
50 DragView dragView, Object dragInfo) {
Joe Onorato0589f0f2010-02-08 13:44:00 -080051 ShortcutInfo item;
52 if (dragInfo instanceof ApplicationInfo) {
Joe Onorato2e5c4322009-10-06 12:34:42 -070053 // Came from all apps -- make a copy
Joe Onorato0589f0f2010-02-08 13:44:00 -080054 item = ((ApplicationInfo)dragInfo).makeShortcut();
55 } else {
56 item = (ShortcutInfo)dragInfo;
Joe Onorato2e5c4322009-10-06 12:34:42 -070057 }
Joe Onorato0589f0f2010-02-08 13:44:00 -080058 ((ShortcutsAdapter)mContent.getAdapter()).add(item);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
60 }
61
Joe Onorato00acb122009-08-04 16:04:30 -040062 public void onDragEnter(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
Joe Onorato00acb122009-08-04 16:04:30 -040066 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
67 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068 }
69
Joe Onorato00acb122009-08-04 16:04:30 -040070 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
71 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072 }
73
74 @Override
75 public void onDropCompleted(View target, boolean success) {
76 if (success) {
Joe Onorato0589f0f2010-02-08 13:44:00 -080077 ShortcutsAdapter adapter = (ShortcutsAdapter)mContent.getAdapter();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080078 adapter.remove(mDragItem);
79 }
80 }
81
82 void bind(FolderInfo info) {
83 super.bind(info);
Joe Onorato0589f0f2010-02-08 13:44:00 -080084 setContentAdapter(new ShortcutsAdapter(mContext, ((UserFolderInfo) info).contents));
The Android Open Source Project31dd5032009-03-03 19:32:27 -080085 }
86
87 // When the folder opens, we need to refresh the GridView's selection by
88 // forcing a layout
89 @Override
90 void onOpen() {
91 super.onOpen();
92 requestFocus();
93 }
94}