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, |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame^] | 31 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 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 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame^] | 38 | public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset, |
| 39 | DragView dragView, Object dragInfo, Rect recycle) { |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 40 | return null; |
| 41 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 42 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame^] | 43 | public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, |
| 44 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 45 | final ApplicationInfo item = (ApplicationInfo) dragInfo; |
| 46 | //noinspection unchecked |
| 47 | ((ArrayAdapter<ApplicationInfo>) mContent.getAdapter()).add((ApplicationInfo) dragInfo); |
| 48 | LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0); |
| 49 | } |
| 50 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame^] | 51 | public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, |
| 52 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame^] | 55 | public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, |
| 56 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame^] | 59 | public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, |
| 60 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public void onDropCompleted(View target, boolean success) { |
| 65 | if (success) { |
| 66 | //noinspection unchecked |
| 67 | ArrayAdapter<ApplicationInfo> adapter = |
| 68 | (ArrayAdapter<ApplicationInfo>) mContent.getAdapter(); |
| 69 | adapter.remove(mDragItem); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | void bind(FolderInfo info) { |
| 74 | super.bind(info); |
| 75 | setContentAdapter(new ApplicationsAdapter(mContext, ((UserFolderInfo) info).contents)); |
| 76 | } |
| 77 | |
| 78 | // When the folder opens, we need to refresh the GridView's selection by |
| 79 | // forcing a layout |
| 80 | @Override |
| 81 | void onOpen() { |
| 82 | super.onOpen(); |
| 83 | requestFocus(); |
| 84 | } |
| 85 | } |