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 | 2e5c432 | 2009-10-06 12:34:42 -0700 | [diff] [blame^] | 49 | ApplicationInfo item = (ApplicationInfo) dragInfo; |
| 50 | if (item.container == NO_ID) { |
| 51 | // Came from all apps -- make a copy |
| 52 | item = new ApplicationInfo((ApplicationInfo)item); |
| 53 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 54 | //noinspection unchecked |
| 55 | ((ArrayAdapter<ApplicationInfo>) mContent.getAdapter()).add((ApplicationInfo) dragInfo); |
| 56 | LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0); |
| 57 | } |
| 58 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 59 | public void onDragEnter(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 onDragOver(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 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 67 | public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, |
| 68 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public void onDropCompleted(View target, boolean success) { |
| 73 | if (success) { |
| 74 | //noinspection unchecked |
| 75 | ArrayAdapter<ApplicationInfo> adapter = |
| 76 | (ArrayAdapter<ApplicationInfo>) mContent.getAdapter(); |
| 77 | adapter.remove(mDragItem); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | void bind(FolderInfo info) { |
| 82 | super.bind(info); |
| 83 | setContentAdapter(new ApplicationsAdapter(mContext, ((UserFolderInfo) info).contents)); |
| 84 | } |
| 85 | |
| 86 | // When the folder opens, we need to refresh the GridView's selection by |
| 87 | // forcing a layout |
| 88 | @Override |
| 89 | void onOpen() { |
| 90 | super.onOpen(); |
| 91 | requestFocus(); |
| 92 | } |
| 93 | } |