blob: 826336c9f322fd96d77505757d88241f198228a7 [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);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051 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,
Joe Onorato00acb122009-08-04 16:04:30 -040064 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065 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
Joe Onorato00acb122009-08-04 16:04:30 -040072 public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset,
73 DragView dragView, Object dragInfo, Rect recycle) {
Jeff Sharkey70864282009-04-07 21:08:40 -070074 return null;
75 }
76
Joe Onorato00acb122009-08-04 16:04:30 -040077 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
78 DragView dragView, Object dragInfo) {
Joe Onorato0589f0f2010-02-08 13:44:00 -080079 ShortcutInfo item;
80 if (dragInfo instanceof ApplicationInfo) {
81 // Came from all apps -- make a copy
82 item = ((ApplicationInfo)dragInfo).makeShortcut();
83 } else {
84 item = (ShortcutInfo)dragInfo;
85 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080086 mInfo.add(item);
87 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
88 }
89
90 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
Joe Onorato00acb122009-08-04 16:04:30 -040091 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080092 setCompoundDrawablesWithIntrinsicBounds(null, mOpenIcon, null, null);
93 }
94
95 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
Joe Onorato00acb122009-08-04 16:04:30 -040096 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097 }
98
99 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
Joe Onorato00acb122009-08-04 16:04:30 -0400100 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800101 setCompoundDrawablesWithIntrinsicBounds(null, mCloseIcon, null, null);
102 }
103}