OSDN Git Service

Initial Contribution
[android-x86/packages-apps-Launcher.git] / src / com / android / launcher / FolderIcon.java
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.android.launcher;
18
19 import android.content.Context;
20 import android.content.res.Resources;
21 import android.graphics.drawable.Drawable;
22 import com.android.internal.provider.Settings;
23 import android.util.AttributeSet;
24 import android.view.LayoutInflater;
25 import android.view.ViewGroup;
26
27 /**
28  * An icon that can appear on in the workspace representing an {@link UserFolder}.
29  */
30 public class FolderIcon extends BubbleTextView implements DropTarget {
31     private UserFolderInfo mInfo;
32     private Launcher mLauncher;
33     private Drawable mCloseIcon;
34     private Drawable mOpenIcon;
35
36     public FolderIcon(Context context, AttributeSet attrs) {
37         super(context, attrs);
38     }
39
40     public FolderIcon(Context context) {
41         super(context);
42     }
43
44     static FolderIcon fromXml(int resId, Launcher launcher, ViewGroup group,
45             UserFolderInfo folderInfo) {
46
47         FolderIcon icon = (FolderIcon) LayoutInflater.from(launcher).inflate(resId, group, false);
48
49         final Resources resources = launcher.getResources();
50         Drawable d = resources.getDrawable(R.drawable.ic_launcher_folder);
51         d = Utilities.createIconThumbnail(d, launcher);
52         icon.mCloseIcon = d;
53         icon.mOpenIcon = resources.getDrawable(R.drawable.ic_launcher_folder_open);
54         icon.setCompoundDrawablesWithIntrinsicBounds(null, d, null, null);
55         icon.setText(folderInfo.title);
56         icon.setTag(folderInfo);
57         icon.setOnClickListener(launcher);
58         icon.mInfo = folderInfo;
59         icon.mLauncher = launcher;
60         
61         return icon;
62     }
63
64     public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
65             Object dragInfo) {
66         final ItemInfo item = (ItemInfo) dragInfo;
67         final int itemType = item.itemType;
68         return (itemType == Settings.Favorites.ITEM_TYPE_APPLICATION || 
69                 itemType == Settings.Favorites.ITEM_TYPE_SHORTCUT)
70                 && item.container != mInfo.id;
71     }
72
73     public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) {
74         final ApplicationInfo item = (ApplicationInfo) dragInfo;
75         // TODO: update open folder that is looking at this data
76         mInfo.add(item);
77         LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
78     }
79
80     public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
81             Object dragInfo) {
82         setCompoundDrawablesWithIntrinsicBounds(null, mOpenIcon, null, null);
83     }
84
85     public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
86             Object dragInfo) {
87     }
88
89     public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
90             Object dragInfo) {
91         setCompoundDrawablesWithIntrinsicBounds(null, mCloseIcon, null, null);
92     }
93 }