blob: 2e0b5c82761e6eb916cdfc186bf5c23a129f9b25 [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
19import android.content.ComponentName;
20import android.content.Context;
Winson Chunga62e9fd2011-07-11 15:20:48 -070021import android.content.res.ColorStateList;
Winson Chung201bc822011-06-20 15:41:53 -070022import android.content.res.Configuration;
Winson Chung4c98d922011-05-31 16:50:48 -070023import android.content.res.Resources;
Winson Chung967289b2011-06-30 18:09:30 -070024import android.graphics.drawable.TransitionDrawable;
Winson Chung4c98d922011-05-31 16:50:48 -070025import android.util.AttributeSet;
26import android.view.View;
Winson Chunga6427b12011-07-27 10:53:39 -070027import android.view.ViewGroup;
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 Chunga62e9fd2011-07-11 15:20:48 -070033 private ColorStateList mOriginalTextColor;
Winson Chung967289b2011-06-30 18:09:30 -070034 private TransitionDrawable mDrawable;
Winson Chung4c98d922011-05-31 16:50:48 -070035
36 public InfoDropTarget(Context context, AttributeSet attrs) {
37 this(context, attrs, 0);
38 }
39
40 public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) {
41 super(context, attrs, defStyle);
42 }
43
44 @Override
45 protected void onFinishInflate() {
46 super.onFinishInflate();
47
Winson Chunga6427b12011-07-27 10:53:39 -070048 mOriginalTextColor = getTextColors();
Winson Chung201bc822011-06-20 15:41:53 -070049
Winson Chung4c98d922011-05-31 16:50:48 -070050 // Get the hover color
51 Resources r = getResources();
Winson Chung4c98d922011-05-31 16:50:48 -070052 mHoverColor = r.getColor(R.color.info_target_hover_tint);
Winson Chunga6427b12011-07-27 10:53:39 -070053 mDrawable = (TransitionDrawable) getCompoundDrawables()[0];
Winson Chung967289b2011-06-30 18:09:30 -070054 mDrawable.setCrossFadeEnabled(true);
Winson Chung201bc822011-06-20 15:41:53 -070055
56 // Remove the text in the Phone UI in landscape
57 int orientation = getResources().getConfiguration().orientation;
58 if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
59 if (!LauncherApplication.isScreenLarge()) {
Winson Chunga6427b12011-07-27 10:53:39 -070060 setText("");
Winson Chung201bc822011-06-20 15:41:53 -070061 }
62 }
Winson Chung4c98d922011-05-31 16:50:48 -070063 }
64
Winson Chung201bc822011-06-20 15:41:53 -070065 private boolean isAllAppsApplication(DragSource source, Object info) {
66 return (source instanceof AppsCustomizePagedView) && (info instanceof ApplicationInfo);
Winson Chung4c98d922011-05-31 16:50:48 -070067 }
68
69 @Override
70 public boolean acceptDrop(DragObject d) {
71 // acceptDrop is called just before onDrop. We do the work here, rather than
72 // in onDrop, because it allows us to reject the drop (by returning false)
73 // so that the object being dragged isn't removed from the drag source.
74 ComponentName componentName = null;
75 if (d.dragInfo instanceof ApplicationInfo) {
76 componentName = ((ApplicationInfo) d.dragInfo).componentName;
77 } else if (d.dragInfo instanceof ShortcutInfo) {
78 componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent();
79 }
80 if (componentName != null) {
81 mLauncher.startApplicationDetailsActivity(componentName);
82 }
Winson Chung7bd1bbb2012-02-13 18:29:29 -080083
84 // There is no post-drop animation, so clean up the DragView now
85 d.deferDragViewCleanupPostAnimation = false;
Winson Chung4c98d922011-05-31 16:50:48 -070086 return false;
87 }
88
89 @Override
90 public void onDragStart(DragSource source, Object info, int dragAction) {
Winson Chung4c98d922011-05-31 16:50:48 -070091 boolean isVisible = true;
92
93 // If we are dragging a widget or shortcut, hide the info target
Winson Chung201bc822011-06-20 15:41:53 -070094 if (!isAllAppsApplication(source, info)) {
Winson Chung4c98d922011-05-31 16:50:48 -070095 isVisible = false;
96 }
97
98 mActive = isVisible;
Winson Chungaaa530a2011-07-11 21:06:30 -070099 mDrawable.resetTransition();
Winson Chunga6427b12011-07-27 10:53:39 -0700100 setTextColor(mOriginalTextColor);
101 ((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE);
Winson Chung4c98d922011-05-31 16:50:48 -0700102 }
103
104 @Override
105 public void onDragEnd() {
106 super.onDragEnd();
107 mActive = false;
108 }
109
110 public void onDragEnter(DragObject d) {
111 super.onDragEnter(d);
112
Winson Chung967289b2011-06-30 18:09:30 -0700113 mDrawable.startTransition(mTransitionDuration);
Winson Chunga6427b12011-07-27 10:53:39 -0700114 setTextColor(mHoverColor);
Winson Chung4c98d922011-05-31 16:50:48 -0700115 }
116
117 public void onDragExit(DragObject d) {
118 super.onDragExit(d);
119
Winson Chungaaa530a2011-07-11 21:06:30 -0700120 if (!d.dragComplete) {
121 mDrawable.resetTransition();
Winson Chunga6427b12011-07-27 10:53:39 -0700122 setTextColor(mOriginalTextColor);
Winson Chungaaa530a2011-07-11 21:06:30 -0700123 }
Winson Chung4c98d922011-05-31 16:50:48 -0700124 }
125}