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 | |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame^] | 27 | import com.android.launcher.R; |
| 28 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 29 | /** |
| 30 | * An icon that can appear on in the workspace representing an {@link UserFolder}. |
| 31 | */ |
| 32 | public 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 Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 53 | 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 Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 66 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 67 | 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 Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 74 | public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset, |
| 75 | DragView dragView, Object dragInfo, Rect recycle) { |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 76 | return null; |
| 77 | } |
| 78 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 79 | public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, |
| 80 | DragView dragView, Object dragInfo) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 81 | 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 Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 88 | 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 Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 93 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 94 | setCompoundDrawablesWithIntrinsicBounds(null, mOpenIcon, null, null); |
| 95 | } |
| 96 | |
| 97 | 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] | 98 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | 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] | 102 | DragView dragView, Object dragInfo) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 103 | setCompoundDrawablesWithIntrinsicBounds(null, mCloseIcon, null, null); |
| 104 | } |
| 105 | } |