blob: 1531538fb9fc3ff24dfcd70f378a33cec5df5f9f [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
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
19import android.content.Context;
20import android.content.res.Resources;
Jeff Sharkey70864282009-04-07 21:08:40 -070021import android.graphics.Rect;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080022import android.graphics.drawable.Drawable;
23import android.util.AttributeSet;
24import android.view.LayoutInflater;
25import android.view.ViewGroup;
26
27/**
28 * An icon that can appear on in the workspace representing an {@link UserFolder}.
29 */
30public 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 == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
69 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT)
70 && item.container != mInfo.id;
71 }
72
Jeff Sharkey70864282009-04-07 21:08:40 -070073 public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo, Rect recycle) {
74 return null;
75 }
76
The Android Open Source Project31dd5032009-03-03 19:32:27 -080077 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) {
78 final ApplicationInfo item = (ApplicationInfo) dragInfo;
79 // TODO: update open folder that is looking at this data
80 mInfo.add(item);
81 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
82 }
83
84 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
85 Object dragInfo) {
86 setCompoundDrawablesWithIntrinsicBounds(null, mOpenIcon, null, null);
87 }
88
89 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
90 Object dragInfo) {
91 }
92
93 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
94 Object dragInfo) {
95 setCompoundDrawablesWithIntrinsicBounds(null, mCloseIcon, null, null);
96 }
97}