blob: 667f92ee1025da0ead54c7a42796317795aa7bb6 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
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
17package com.android.launcher;
18
19import android.content.Context;
20import android.content.res.Resources;
21import android.graphics.drawable.Drawable;
22import android.util.AttributeSet;
23import android.view.LayoutInflater;
24import android.view.ViewGroup;
25
26/**
27 * An icon that can appear on in the workspace representing an {@link UserFolder}.
28 */
29public class FolderIcon extends BubbleTextView implements DropTarget {
30 private UserFolderInfo mInfo;
31 private Launcher mLauncher;
32 private Drawable mCloseIcon;
33 private Drawable mOpenIcon;
34
35 public FolderIcon(Context context, AttributeSet attrs) {
36 super(context, attrs);
37 }
38
39 public FolderIcon(Context context) {
40 super(context);
41 }
42
43 static FolderIcon fromXml(int resId, Launcher launcher, ViewGroup group,
44 UserFolderInfo folderInfo) {
45
46 FolderIcon icon = (FolderIcon) LayoutInflater.from(launcher).inflate(resId, group, false);
47
48 final Resources resources = launcher.getResources();
49 Drawable d = resources.getDrawable(R.drawable.ic_launcher_folder);
50 d = Utilities.createIconThumbnail(d, launcher);
51 icon.mCloseIcon = d;
52 icon.mOpenIcon = resources.getDrawable(R.drawable.ic_launcher_folder_open);
53 icon.setCompoundDrawablesWithIntrinsicBounds(null, d, null, null);
54 icon.setText(folderInfo.title);
55 icon.setTag(folderInfo);
56 icon.setOnClickListener(launcher);
57 icon.mInfo = folderInfo;
58 icon.mLauncher = launcher;
59
60 return icon;
61 }
62
63 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
64 Object dragInfo) {
65 final ItemInfo item = (ItemInfo) dragInfo;
66 final int itemType = item.itemType;
67 return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
68 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT)
69 && item.container != mInfo.id;
70 }
71
72 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) {
73 final ApplicationInfo item = (ApplicationInfo) dragInfo;
74 // TODO: update open folder that is looking at this data
75 mInfo.add(item);
76 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
77 }
78
79 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
80 Object dragInfo) {
81 setCompoundDrawablesWithIntrinsicBounds(null, mOpenIcon, null, null);
82 }
83
84 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
85 Object dragInfo) {
86 }
87
88 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
89 Object dragInfo) {
90 setCompoundDrawablesWithIntrinsicBounds(null, mCloseIcon, null, null);
91 }
92}