blob: 0013644abcb0528756a2c133e58938e2479a07d9 [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
Romain Guyedcce092010-03-04 13:03:17 -080027import com.android.launcher.R;
28
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029/**
30 * An icon that can appear on in the workspace representing an {@link UserFolder}.
31 */
32public class FolderIcon extends BubbleTextView implements DropTarget {
33 private UserFolderInfo mInfo;
34 private Launcher mLauncher;
35 private Drawable mCloseIcon;
36 private Drawable mOpenIcon;
37
38 public FolderIcon(Context context, AttributeSet attrs) {
39 super(context, attrs);
40 }
41
42 public FolderIcon(Context context) {
43 super(context);
44 }
45
46 static FolderIcon fromXml(int resId, Launcher launcher, ViewGroup group,
47 UserFolderInfo folderInfo) {
48
49 FolderIcon icon = (FolderIcon) LayoutInflater.from(launcher).inflate(resId, group, false);
50
51 final Resources resources = launcher.getResources();
52 Drawable d = resources.getDrawable(R.drawable.ic_launcher_folder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080053 icon.mCloseIcon = d;
54 icon.mOpenIcon = resources.getDrawable(R.drawable.ic_launcher_folder_open);
55 icon.setCompoundDrawablesWithIntrinsicBounds(null, d, null, null);
56 icon.setText(folderInfo.title);
57 icon.setTag(folderInfo);
58 icon.setOnClickListener(launcher);
59 icon.mInfo = folderInfo;
60 icon.mLauncher = launcher;
61
62 return icon;
63 }
64
65 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
Joe Onorato00acb122009-08-04 16:04:30 -040066 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067 final ItemInfo item = (ItemInfo) dragInfo;
68 final int itemType = item.itemType;
69 return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
70 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT)
71 && item.container != mInfo.id;
72 }
73
Joe Onorato00acb122009-08-04 16:04:30 -040074 public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset,
75 DragView dragView, Object dragInfo, Rect recycle) {
Jeff Sharkey70864282009-04-07 21:08:40 -070076 return null;
77 }
78
Joe Onorato00acb122009-08-04 16:04:30 -040079 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
80 DragView dragView, Object dragInfo) {
Joe Onorato0589f0f2010-02-08 13:44:00 -080081 ShortcutInfo item;
82 if (dragInfo instanceof ApplicationInfo) {
83 // Came from all apps -- make a copy
84 item = ((ApplicationInfo)dragInfo).makeShortcut();
85 } else {
86 item = (ShortcutInfo)dragInfo;
87 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088 mInfo.add(item);
89 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
90 }
91
92 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
Joe Onorato00acb122009-08-04 16:04:30 -040093 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080094 setCompoundDrawablesWithIntrinsicBounds(null, mOpenIcon, null, null);
95 }
96
97 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
Joe Onorato00acb122009-08-04 16:04:30 -040098 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080099 }
100
101 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
Joe Onorato00acb122009-08-04 16:04:30 -0400102 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800103 setCompoundDrawablesWithIntrinsicBounds(null, mCloseIcon, null, null);
104 }
105}