The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 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 Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.res.Resources; |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 21 | import android.graphics.Rect; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 22 | import android.graphics.drawable.Drawable; |
| 23 | import android.util.AttributeSet; |
| 24 | import android.view.LayoutInflater; |
| 25 | import android.view.ViewGroup; |
| 26 | |
| 27 | /** |
| 28 | * An icon that can appear on in the workspace representing an {@link UserFolder}. |
| 29 | */ |
| 30 | public 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 Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 51 | 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 Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 64 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 65 | 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 Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 72 | public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset, |
| 73 | DragView dragView, Object dragInfo, Rect recycle) { |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 74 | return null; |
| 75 | } |
| 76 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 77 | public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, |
| 78 | DragView dragView, Object dragInfo) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 79 | 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 Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 86 | 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 Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 91 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 92 | setCompoundDrawablesWithIntrinsicBounds(null, mOpenIcon, null, null); |
| 93 | } |
| 94 | |
| 95 | public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 96 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 100 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 101 | setCompoundDrawablesWithIntrinsicBounds(null, mCloseIcon, null, null); |
| 102 | } |
| 103 | } |