blob: 7e6b700df25ae67b1a3fb18ffd062809a7c2d5d8 [file] [log] [blame]
Winson Chung4c98d922011-05-31 16:50:48 -07001/*
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
17package com.android.launcher2;
18
Winson Chung61fa4192011-06-12 15:15:29 -070019import android.animation.ObjectAnimator;
Winson Chung4c98d922011-05-31 16:50:48 -070020import android.content.ComponentName;
21import android.content.Context;
22import android.content.res.Resources;
Winson Chung61fa4192011-06-12 15:15:29 -070023import android.graphics.Color;
Winson Chung4c98d922011-05-31 16:50:48 -070024import android.graphics.PorterDuff;
25import android.graphics.PorterDuffColorFilter;
26import android.util.AttributeSet;
27import android.view.View;
Winson Chung4c98d922011-05-31 16:50:48 -070028
29import com.android.launcher.R;
30
Winson Chung61fa4192011-06-12 15:15:29 -070031public class InfoDropTarget extends ButtonDropTarget {
Winson Chung4c98d922011-05-31 16:50:48 -070032
Winson Chung4c98d922011-05-31 16:50:48 -070033 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();
Winson Chung4c98d922011-05-31 16:50:48 -070049 mHoverColor = r.getColor(R.color.info_target_hover_tint);
50 mHoverPaint.setColorFilter(new PorterDuffColorFilter(
51 mHoverColor, PorterDuff.Mode.SRC_ATOP));
Winson Chung61fa4192011-06-12 15:15:29 -070052 setBackgroundColor(mHoverColor);
53 getBackground().setAlpha(0);
Winson Chung4c98d922011-05-31 16:50:48 -070054 }
55
56 private boolean isApplication(Object info) {
57 if (info instanceof ApplicationInfo) return true;
58 return (((ItemInfo) info).itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION);
59 }
60
61 @Override
62 public boolean acceptDrop(DragObject d) {
63 // acceptDrop is called just before onDrop. We do the work here, rather than
64 // in onDrop, because it allows us to reject the drop (by returning false)
65 // so that the object being dragged isn't removed from the drag source.
66 ComponentName componentName = null;
67 if (d.dragInfo instanceof ApplicationInfo) {
68 componentName = ((ApplicationInfo) d.dragInfo).componentName;
69 } else if (d.dragInfo instanceof ShortcutInfo) {
70 componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent();
71 }
72 if (componentName != null) {
73 mLauncher.startApplicationDetailsActivity(componentName);
74 }
75 return false;
76 }
77
78 @Override
79 public void onDragStart(DragSource source, Object info, int dragAction) {
80 ItemInfo item = (ItemInfo) info;
81 boolean isVisible = true;
82
83 // If we are dragging a widget or shortcut, hide the info target
84 if (!isApplication(info)) {
85 isVisible = false;
86 }
87
88 mActive = isVisible;
Winson Chung61fa4192011-06-12 15:15:29 -070089 setVisibility(isVisible ? View.VISIBLE : View.GONE);
Winson Chung4c98d922011-05-31 16:50:48 -070090 }
91
92 @Override
93 public void onDragEnd() {
94 super.onDragEnd();
95 mActive = false;
96 }
97
98 public void onDragEnter(DragObject d) {
99 super.onDragEnter(d);
100
Winson Chung61fa4192011-06-12 15:15:29 -0700101 ObjectAnimator anim = ObjectAnimator.ofInt(getBackground(), "alpha",
102 Color.alpha(mHoverColor));
103 anim.setDuration(mTransitionDuration);
104 anim.start();
Winson Chung4c98d922011-05-31 16:50:48 -0700105 }
106
107 public void onDragExit(DragObject d) {
108 super.onDragExit(d);
109
Winson Chung61fa4192011-06-12 15:15:29 -0700110 ObjectAnimator anim = ObjectAnimator.ofInt(getBackground(), "alpha", 0);
111 anim.setDuration(mTransitionDuration);
112 anim.start();
Winson Chung4c98d922011-05-31 16:50:48 -0700113 }
114}