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