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; |
| 4 | import android.util.AttributeSet; |
| 5 | import android.view.LayoutInflater; |
| 6 | import android.view.View; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 7 | |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 8 | import com.android.launcher.R; |
| 9 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 10 | /** |
| 11 | * Folder which contains applications or shortcuts chosen by the user. |
| 12 | * |
| 13 | */ |
| 14 | public class UserFolder extends Folder implements DropTarget { |
Joe Onorato | 2e5c432 | 2009-10-06 12:34:42 -0700 | [diff] [blame] | 15 | private static final String TAG = "Launcher.UserFolder"; |
| 16 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 17 | public UserFolder(Context context, AttributeSet attrs) { |
| 18 | super(context, attrs); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Creates a new UserFolder, inflated from R.layout.user_folder. |
| 23 | * |
| 24 | * @param context The application's context. |
| 25 | * |
| 26 | * @return A new UserFolder. |
| 27 | */ |
| 28 | static UserFolder fromXml(Context context) { |
| 29 | return (UserFolder) LayoutInflater.from(context).inflate(R.layout.user_folder, null); |
| 30 | } |
| 31 | |
| 32 | 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] | 33 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 34 | final ItemInfo item = (ItemInfo) dragInfo; |
| 35 | final int itemType = item.itemType; |
| 36 | return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || |
Joe Onorato | 2e5c432 | 2009-10-06 12:34:42 -0700 | [diff] [blame] | 37 | itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) |
| 38 | && item.container != mInfo.id; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 39 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 40 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 41 | public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, |
| 42 | DragView dragView, Object dragInfo) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 43 | ShortcutInfo item; |
| 44 | if (dragInfo instanceof ApplicationInfo) { |
Joe Onorato | 2e5c432 | 2009-10-06 12:34:42 -0700 | [diff] [blame] | 45 | // Came from all apps -- make a copy |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 46 | item = ((ApplicationInfo)dragInfo).makeShortcut(); |
| 47 | } else { |
| 48 | item = (ShortcutInfo)dragInfo; |
Joe Onorato | 2e5c432 | 2009-10-06 12:34:42 -0700 | [diff] [blame] | 49 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 50 | ((ShortcutsAdapter)mContent.getAdapter()).add(item); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 51 | LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0); |
| 52 | } |
| 53 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 54 | public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, |
| 55 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 58 | public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, |
| 59 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 62 | public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, |
| 63 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Override |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame^] | 67 | public void onDropCompleted(View target, Object dragInfo, boolean success) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 68 | if (success) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 69 | ShortcutsAdapter adapter = (ShortcutsAdapter)mContent.getAdapter(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 70 | adapter.remove(mDragItem); |
| 71 | } |
| 72 | } |
| 73 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 74 | public boolean isDropEnabled() { |
| 75 | return true; |
| 76 | } |
| 77 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 78 | void bind(FolderInfo info) { |
| 79 | super.bind(info); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 80 | setContentAdapter(new ShortcutsAdapter(mContext, ((UserFolderInfo) info).contents)); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | // When the folder opens, we need to refresh the GridView's selection by |
| 84 | // forcing a layout |
| 85 | @Override |
| 86 | void onOpen() { |
| 87 | super.onOpen(); |
| 88 | requestFocus(); |
| 89 | } |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 90 | |
| 91 | @Override |
| 92 | public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset, |
| 93 | DragView dragView, Object dragInfo) { |
| 94 | return null; |
| 95 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 96 | } |