blob: 1044e969f6bbceb6a717d6de2ef73b2f089eee3e [file] [log] [blame]
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -07001package com.android.launcher;
2
3import android.content.Context;
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -07004import android.util.AttributeSet;
5import android.view.LayoutInflater;
6import android.view.View;
7import android.widget.ArrayAdapter;
8
9/**
10 * Folder which contains applications or shortcuts chosen by the user.
11 *
12 */
13public class UserFolder extends Folder implements DropTarget {
14 public UserFolder(Context context, AttributeSet attrs) {
15 super(context, attrs);
16 }
17
18 /**
19 * Creates a new UserFolder, inflated from R.layout.user_folder.
20 *
21 * @param context The application's context.
22 *
23 * @return A new UserFolder.
24 */
25 static UserFolder fromXml(Context context) {
26 return (UserFolder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
27 }
28
29 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
30 Object dragInfo) {
31 final ItemInfo item = (ItemInfo) dragInfo;
32 final int itemType = item.itemType;
The Android Open Source Projectd097a182008-12-17 18:05:58 -080033 return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
34 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) && item.container != mInfo.id;
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070035 }
36
37 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) {
38 final ApplicationInfo item = (ApplicationInfo) dragInfo;
39 //noinspection unchecked
40 ((ArrayAdapter<ApplicationInfo>) mContent.getAdapter()).add((ApplicationInfo) dragInfo);
41 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
42 }
43
44 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) {
45 }
46
47 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) {
48 }
49
50 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) {
51 }
52
53 @Override
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070054 public void onDropCompleted(View target, boolean success) {
55 if (success) {
56 //noinspection unchecked
57 ArrayAdapter<ApplicationInfo> adapter =
58 (ArrayAdapter<ApplicationInfo>) mContent.getAdapter();
59 adapter.remove(mDragItem);
60 }
61 }
62
The Android Open Source Projectd097a182008-12-17 18:05:58 -080063 void bind(FolderInfo info) {
64 super.bind(info);
65 setContentAdapter(new ApplicationsAdapter(mContext, ((UserFolderInfo) info).contents));
The Android Open Source Projectc8f00b62008-10-21 07:00:00 -070066 }
67
68 // When the folder opens, we need to refresh the GridView's selection by
69 // forcing a layout
70 @Override
71 void onOpen() {
72 super.onOpen();
73 requestFocus();
74 }
75}