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