OSDN Git Service

auto import from //depot/cupcake/@135843
[android-x86/packages-apps-Launcher.git] / src / com / android / launcher / UserFolder.java
1 package com.android.launcher;
2
3 import android.content.Context;
4 import android.util.AttributeSet;
5 import android.view.LayoutInflater;
6 import android.view.View;
7 import android.widget.ArrayAdapter;
8
9 /**
10  * Folder which contains applications or shortcuts chosen by the user.
11  *
12  */
13 public 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;
33         return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
34                 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) && item.container != mInfo.id;
35     }
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
54     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
63     void bind(FolderInfo info) {
64         super.bind(info);
65         setContentAdapter(new ApplicationsAdapter(mContext, ((UserFolderInfo) info).contents));
66     }
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 }