blob: e2cef0e6932e7a00c1f4e4297e1a61532538b784 [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 void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
75 DragView dragView, Object dragInfo) {
Joe Onorato0589f0f2010-02-08 13:44:00 -080076 ShortcutInfo item;
77 if (dragInfo instanceof ApplicationInfo) {
78 // Came from all apps -- make a copy
79 item = ((ApplicationInfo)dragInfo).makeShortcut();
80 } else {
81 item = (ShortcutInfo)dragInfo;
82 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080083 mInfo.add(item);
84 LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
85 }
86
87 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
Joe Onorato00acb122009-08-04 16:04:30 -040088 DragView dragView, Object dragInfo) {
Patrick Dubroy379f1602010-07-14 11:29:09 -070089 if (acceptDrop(source, x, y, xOffset, yOffset, dragView, dragInfo)) {
90 setCompoundDrawablesWithIntrinsicBounds(null, mOpenIcon, null, null);
91 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080092 }
93
94 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
Joe Onorato00acb122009-08-04 16:04:30 -040095 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080096 }
97
98 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
Joe Onorato00acb122009-08-04 16:04:30 -040099 DragView dragView, Object dragInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800100 setCompoundDrawablesWithIntrinsicBounds(null, mCloseIcon, null, null);
101 }
Patrick Dubroy440c3602010-07-13 17:50:32 -0700102
103 @Override
104 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset,
105 DragView dragView, Object dragInfo) {
106 return null;
107 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800108}