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; |
Joe Onorato | 2e5c432 | 2009-10-06 12:34:42 -0700 | [diff] [blame] | 6 | import android.util.Log; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 7 | import android.view.LayoutInflater; |
| 8 | import android.view.View; |
| 9 | import android.widget.ArrayAdapter; |
| 10 | |
| 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 | } |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 41 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 42 | public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset, |
| 43 | DragView dragView, Object dragInfo, Rect recycle) { |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 44 | return null; |
| 45 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 46 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 47 | public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, |
| 48 | DragView dragView, Object dragInfo) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 49 | ShortcutInfo item; |
| 50 | if (dragInfo instanceof ApplicationInfo) { |
Joe Onorato | 2e5c432 | 2009-10-06 12:34:42 -0700 | [diff] [blame] | 51 | // Came from all apps -- make a copy |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 52 | item = ((ApplicationInfo)dragInfo).makeShortcut(); |
| 53 | } else { |
| 54 | item = (ShortcutInfo)dragInfo; |
Joe Onorato | 2e5c432 | 2009-10-06 12:34:42 -0700 | [diff] [blame] | 55 | } |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 56 | ((ShortcutsAdapter)mContent.getAdapter()).add(item); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 57 | LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0); |
| 58 | } |
| 59 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 60 | public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, |
| 61 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 64 | public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, |
| 65 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 68 | public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, |
| 69 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public void onDropCompleted(View target, boolean success) { |
| 74 | if (success) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 75 | ShortcutsAdapter adapter = (ShortcutsAdapter)mContent.getAdapter(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 76 | adapter.remove(mDragItem); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | void bind(FolderInfo info) { |
| 81 | super.bind(info); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame^] | 82 | setContentAdapter(new ShortcutsAdapter(mContext, ((UserFolderInfo) info).contents)); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | // When the folder opens, we need to refresh the GridView's selection by |
| 86 | // forcing a layout |
| 87 | @Override |
| 88 | void onOpen() { |
| 89 | super.onOpen(); |
| 90 | requestFocus(); |
| 91 | } |
| 92 | } |