The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | package com.android.launcher; |
| 2 | |
| 3 | import android.content.Context; |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 4 | import android.util.AttributeSet; |
| 5 | import android.view.LayoutInflater; |
| 6 | import android.view.View; |
| 7 | import android.widget.ArrayAdapter; |
| 8 | |
| 9 | /** |
| 10 | * Folder which contains applications or shortcuts chosen by the user. |
| 11 | * |
| 12 | */ |
| 13 | public class UserFolder extends Folder implements DropTarget { |
| 14 | public UserFolder(Context context, AttributeSet attrs) { |
| 15 | super(context, attrs); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Creates a new UserFolder, inflated from R.layout.user_folder. |
| 20 | * |
| 21 | * @param context The application's context. |
| 22 | * |
| 23 | * @return A new UserFolder. |
| 24 | */ |
| 25 | static UserFolder fromXml(Context context) { |
| 26 | return (UserFolder) LayoutInflater.from(context).inflate(R.layout.user_folder, null); |
| 27 | } |
| 28 | |
| 29 | public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset, |
| 30 | Object dragInfo) { |
| 31 | final ItemInfo item = (ItemInfo) dragInfo; |
| 32 | final int itemType = item.itemType; |
The Android Open Source Project | d097a18 | 2008-12-17 18:05:58 -0800 | [diff] [blame] | 33 | return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || |
| 34 | itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) && item.container != mInfo.id; |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) { |
| 38 | final ApplicationInfo item = (ApplicationInfo) dragInfo; |
| 39 | //noinspection unchecked |
| 40 | ((ArrayAdapter<ApplicationInfo>) mContent.getAdapter()).add((ApplicationInfo) dragInfo); |
| 41 | LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0); |
| 42 | } |
| 43 | |
| 44 | public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) { |
| 45 | } |
| 46 | |
| 47 | public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) { |
| 48 | } |
| 49 | |
| 50 | public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) { |
| 51 | } |
| 52 | |
| 53 | @Override |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 54 | public void onDropCompleted(View target, boolean success) { |
| 55 | if (success) { |
| 56 | //noinspection unchecked |
| 57 | ArrayAdapter<ApplicationInfo> adapter = |
| 58 | (ArrayAdapter<ApplicationInfo>) mContent.getAdapter(); |
| 59 | adapter.remove(mDragItem); |
| 60 | } |
| 61 | } |
| 62 | |
The Android Open Source Project | d097a18 | 2008-12-17 18:05:58 -0800 | [diff] [blame] | 63 | void bind(FolderInfo info) { |
| 64 | super.bind(info); |
| 65 | setContentAdapter(new ApplicationsAdapter(mContext, ((UserFolderInfo) info).contents)); |
The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | // When the folder opens, we need to refresh the GridView's selection by |
| 69 | // forcing a layout |
| 70 | @Override |
| 71 | void onOpen() { |
| 72 | super.onOpen(); |
| 73 | requestFocus(); |
| 74 | } |
| 75 | } |