The Android Open Source Project | c8f00b6 | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | package com.android.launcher; |
| 2 | |
| 3 | import android.content.Context; |
| 4 | import com.android.internal.provider.Settings; |
| 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, |
| 31 | Object dragInfo) { |
| 32 | final ItemInfo item = (ItemInfo) dragInfo; |
| 33 | final int itemType = item.itemType; |
| 34 | return (itemType == Settings.Favorites.ITEM_TYPE_APPLICATION || |
| 35 | itemType == Settings.Favorites.ITEM_TYPE_SHORTCUT) && item.container != mInfo.id; |
| 36 | } |
| 37 | |
| 38 | public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) { |
| 39 | final ApplicationInfo item = (ApplicationInfo) dragInfo; |
| 40 | //noinspection unchecked |
| 41 | ((ArrayAdapter<ApplicationInfo>) mContent.getAdapter()).add((ApplicationInfo) dragInfo); |
| 42 | LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0); |
| 43 | } |
| 44 | |
| 45 | public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) { |
| 46 | } |
| 47 | |
| 48 | public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) { |
| 49 | } |
| 50 | |
| 51 | public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) { |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public boolean onLongClick(View v) { |
| 56 | mLauncher.closeFolder(this); |
| 57 | mLauncher.showRenameDialog((UserFolderInfo) mInfo); |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public void onDropCompleted(View target, boolean success) { |
| 63 | if (success) { |
| 64 | //noinspection unchecked |
| 65 | ArrayAdapter<ApplicationInfo> adapter = |
| 66 | (ArrayAdapter<ApplicationInfo>) mContent.getAdapter(); |
| 67 | adapter.remove(mDragItem); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | void bind(UserFolderInfo info) { |
| 72 | mInfo = info; |
| 73 | setContentAdapter(new ApplicationsAdapter(mContext, info.contents)); |
| 74 | mCloseButton.setText(info.title); |
| 75 | } |
| 76 | |
| 77 | // When the folder opens, we need to refresh the GridView's selection by |
| 78 | // forcing a layout |
| 79 | @Override |
| 80 | void onOpen() { |
| 81 | super.onOpen(); |
| 82 | requestFocus(); |
| 83 | } |
| 84 | } |