2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.launcher;
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;
28 * An icon that can appear on in the workspace representing an {@link UserFolder}.
30 public class FolderIcon extends BubbleTextView implements DropTarget {
31 private UserFolderInfo mInfo;
32 private Launcher mLauncher;
33 private Drawable mCloseIcon;
34 private Drawable mOpenIcon;
36 public FolderIcon(Context context, AttributeSet attrs) {
37 super(context, attrs);
40 public FolderIcon(Context context) {
44 static FolderIcon fromXml(int resId, Launcher launcher, ViewGroup group,
45 UserFolderInfo folderInfo) {
47 FolderIcon icon = (FolderIcon) LayoutInflater.from(launcher).inflate(resId, group, false);
49 final Resources resources = launcher.getResources();
50 Drawable d = resources.getDrawable(R.drawable.ic_launcher_folder);
51 d = Utilities.createIconThumbnail(d, launcher);
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;
64 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
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;
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
77 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
80 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
82 setCompoundDrawablesWithIntrinsicBounds(null, mOpenIcon, null, null);
85 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
89 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
91 setCompoundDrawablesWithIntrinsicBounds(null, mCloseIcon, null, null);