Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
| 17 | package com.android.launcher2; |
| 18 | |
| 19 | import android.content.ComponentName; |
| 20 | import android.content.Context; |
| 21 | import android.content.res.Resources; |
| 22 | import android.graphics.PorterDuff; |
| 23 | import android.graphics.PorterDuffColorFilter; |
| 24 | import android.util.AttributeSet; |
| 25 | import android.view.View; |
| 26 | import android.view.ViewGroup; |
| 27 | |
| 28 | import com.android.launcher.R; |
| 29 | |
| 30 | public class InfoDropTarget extends IconDropTarget { |
| 31 | |
| 32 | private int mDefaultTextColor; |
| 33 | private int mHoverColor = 0xFF0000FF; |
| 34 | |
| 35 | public InfoDropTarget(Context context, AttributeSet attrs) { |
| 36 | this(context, attrs, 0); |
| 37 | } |
| 38 | |
| 39 | public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) { |
| 40 | super(context, attrs, defStyle); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | protected void onFinishInflate() { |
| 45 | super.onFinishInflate(); |
| 46 | |
| 47 | // Get the hover color |
| 48 | Resources r = getResources(); |
| 49 | mDefaultTextColor = getTextColors().getDefaultColor(); |
| 50 | mHoverColor = r.getColor(R.color.info_target_hover_tint); |
| 51 | mHoverPaint.setColorFilter(new PorterDuffColorFilter( |
| 52 | mHoverColor, PorterDuff.Mode.SRC_ATOP)); |
| 53 | } |
| 54 | |
| 55 | private boolean isApplication(Object info) { |
| 56 | if (info instanceof ApplicationInfo) return true; |
| 57 | return (((ItemInfo) info).itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public boolean acceptDrop(DragObject d) { |
| 62 | // acceptDrop is called just before onDrop. We do the work here, rather than |
| 63 | // in onDrop, because it allows us to reject the drop (by returning false) |
| 64 | // so that the object being dragged isn't removed from the drag source. |
| 65 | ComponentName componentName = null; |
| 66 | if (d.dragInfo instanceof ApplicationInfo) { |
| 67 | componentName = ((ApplicationInfo) d.dragInfo).componentName; |
| 68 | } else if (d.dragInfo instanceof ShortcutInfo) { |
| 69 | componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent(); |
| 70 | } |
| 71 | if (componentName != null) { |
| 72 | mLauncher.startApplicationDetailsActivity(componentName); |
| 73 | } |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public void onDragStart(DragSource source, Object info, int dragAction) { |
| 79 | ItemInfo item = (ItemInfo) info; |
| 80 | boolean isVisible = true; |
| 81 | |
| 82 | // If we are dragging a widget or shortcut, hide the info target |
| 83 | if (!isApplication(info)) { |
| 84 | isVisible = false; |
| 85 | } |
| 86 | |
| 87 | mActive = isVisible; |
| 88 | ((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE); |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public void onDragEnd() { |
| 93 | super.onDragEnd(); |
| 94 | mActive = false; |
| 95 | } |
| 96 | |
| 97 | public void onDragEnter(DragObject d) { |
| 98 | super.onDragEnter(d); |
| 99 | |
| 100 | setTextColor(mHoverColor); |
| 101 | } |
| 102 | |
| 103 | public void onDragExit(DragObject d) { |
| 104 | super.onDragExit(d); |
| 105 | |
| 106 | setTextColor(mDefaultTextColor); |
| 107 | } |
| 108 | } |