blob: 134f4cb567308f4aff1fa120043965aec60c630a [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 Chung11a49372012-04-27 15:12:38 -070019import android.appwidget.AppWidgetProviderInfo;
Winson Chung4c98d922011-05-31 16:50:48 -070020import android.content.ComponentName;
21import android.content.Context;
Winson Chunga62e9fd2011-07-11 15:20:48 -070022import android.content.res.ColorStateList;
Winson Chung201bc822011-06-20 15:41:53 -070023import android.content.res.Configuration;
Winson Chung4c98d922011-05-31 16:50:48 -070024import android.content.res.Resources;
Winson Chung967289b2011-06-30 18:09:30 -070025import android.graphics.drawable.TransitionDrawable;
Winson Chung4c98d922011-05-31 16:50:48 -070026import android.util.AttributeSet;
27import android.view.View;
Winson Chunga6427b12011-07-27 10:53:39 -070028import android.view.ViewGroup;
Winson Chung4c98d922011-05-31 16:50:48 -070029
30import com.android.launcher.R;
31
Winson Chung61fa4192011-06-12 15:15:29 -070032public class InfoDropTarget extends ButtonDropTarget {
Winson Chung4c98d922011-05-31 16:50:48 -070033
Winson Chunga62e9fd2011-07-11 15:20:48 -070034 private ColorStateList mOriginalTextColor;
Winson Chung967289b2011-06-30 18:09:30 -070035 private TransitionDrawable mDrawable;
Winson Chung4c98d922011-05-31 16:50:48 -070036
37 public InfoDropTarget(Context context, AttributeSet attrs) {
38 this(context, attrs, 0);
39 }
40
41 public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) {
42 super(context, attrs, defStyle);
43 }
44
45 @Override
46 protected void onFinishInflate() {
47 super.onFinishInflate();
48
Winson Chunga6427b12011-07-27 10:53:39 -070049 mOriginalTextColor = getTextColors();
Winson Chung201bc822011-06-20 15:41:53 -070050
Winson Chung4c98d922011-05-31 16:50:48 -070051 // Get the hover color
52 Resources r = getResources();
Winson Chung4c98d922011-05-31 16:50:48 -070053 mHoverColor = r.getColor(R.color.info_target_hover_tint);
Winson Chunga6427b12011-07-27 10:53:39 -070054 mDrawable = (TransitionDrawable) getCompoundDrawables()[0];
Winson Chung967289b2011-06-30 18:09:30 -070055 mDrawable.setCrossFadeEnabled(true);
Winson Chung201bc822011-06-20 15:41:53 -070056
57 // Remove the text in the Phone UI in landscape
58 int orientation = getResources().getConfiguration().orientation;
59 if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
60 if (!LauncherApplication.isScreenLarge()) {
Winson Chunga6427b12011-07-27 10:53:39 -070061 setText("");
Winson Chung201bc822011-06-20 15:41:53 -070062 }
63 }
Winson Chung4c98d922011-05-31 16:50:48 -070064 }
65
Winson Chung11a49372012-04-27 15:12:38 -070066 private boolean isFromAllApps(DragSource source) {
67 return (source instanceof AppsCustomizePagedView);
Winson Chung4c98d922011-05-31 16:50:48 -070068 }
69
70 @Override
71 public boolean acceptDrop(DragObject d) {
72 // acceptDrop is called just before onDrop. We do the work here, rather than
73 // in onDrop, because it allows us to reject the drop (by returning false)
74 // so that the object being dragged isn't removed from the drag source.
75 ComponentName componentName = null;
76 if (d.dragInfo instanceof ApplicationInfo) {
77 componentName = ((ApplicationInfo) d.dragInfo).componentName;
78 } else if (d.dragInfo instanceof ShortcutInfo) {
79 componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent();
Winson Chung11a49372012-04-27 15:12:38 -070080 } else if (d.dragInfo instanceof PendingAddItemInfo) {
81 componentName = ((PendingAddItemInfo) d.dragInfo).componentName;
Winson Chung4c98d922011-05-31 16:50:48 -070082 }
83 if (componentName != null) {
84 mLauncher.startApplicationDetailsActivity(componentName);
85 }
Winson Chung7bd1bbb2012-02-13 18:29:29 -080086
87 // There is no post-drop animation, so clean up the DragView now
88 d.deferDragViewCleanupPostAnimation = false;
Winson Chung4c98d922011-05-31 16:50:48 -070089 return false;
90 }
91
92 @Override
93 public void onDragStart(DragSource source, Object info, int dragAction) {
Winson Chung4c98d922011-05-31 16:50:48 -070094 boolean isVisible = true;
95
Winson Chung11a49372012-04-27 15:12:38 -070096 // Hide this button unless we are dragging something from AllApps
97 if (!isFromAllApps(source)) {
Winson Chung4c98d922011-05-31 16:50:48 -070098 isVisible = false;
99 }
100
101 mActive = isVisible;
Winson Chungaaa530a2011-07-11 21:06:30 -0700102 mDrawable.resetTransition();
Winson Chunga6427b12011-07-27 10:53:39 -0700103 setTextColor(mOriginalTextColor);
104 ((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE);
Winson Chung4c98d922011-05-31 16:50:48 -0700105 }
106
107 @Override
108 public void onDragEnd() {
109 super.onDragEnd();
110 mActive = false;
111 }
112
113 public void onDragEnter(DragObject d) {
114 super.onDragEnter(d);
115
Winson Chung967289b2011-06-30 18:09:30 -0700116 mDrawable.startTransition(mTransitionDuration);
Winson Chunga6427b12011-07-27 10:53:39 -0700117 setTextColor(mHoverColor);
Winson Chung4c98d922011-05-31 16:50:48 -0700118 }
119
120 public void onDragExit(DragObject d) {
121 super.onDragExit(d);
122
Winson Chungaaa530a2011-07-11 21:06:30 -0700123 if (!d.dragComplete) {
124 mDrawable.resetTransition();
Winson Chunga6427b12011-07-27 10:53:39 -0700125 setTextColor(mOriginalTextColor);
Winson Chungaaa530a2011-07-11 21:06:30 -0700126 }
Winson Chung4c98d922011-05-31 16:50:48 -0700127 }
128}