blob: 3507181e264005aa33c5b8d20146e25f8fa13520 [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;
24import android.graphics.PorterDuff;
25import android.graphics.PorterDuffColorFilter;
Winson Chung967289b2011-06-30 18:09:30 -070026import android.graphics.drawable.TransitionDrawable;
Winson Chung4c98d922011-05-31 16:50:48 -070027import android.util.AttributeSet;
28import android.view.View;
Winson Chung201bc822011-06-20 15:41:53 -070029import android.widget.TextView;
Winson Chung4c98d922011-05-31 16:50:48 -070030
31import com.android.launcher.R;
32
Winson Chung61fa4192011-06-12 15:15:29 -070033public class InfoDropTarget extends ButtonDropTarget {
Winson Chung4c98d922011-05-31 16:50:48 -070034
Winson Chunga62e9fd2011-07-11 15:20:48 -070035 private ColorStateList mOriginalTextColor;
Winson Chung967289b2011-06-30 18:09:30 -070036 private TransitionDrawable mDrawable;
Winson Chung4c98d922011-05-31 16:50:48 -070037 private int mHoverColor = 0xFF0000FF;
38
39 public InfoDropTarget(Context context, AttributeSet attrs) {
40 this(context, attrs, 0);
41 }
42
43 public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) {
44 super(context, attrs, defStyle);
45 }
46
47 @Override
48 protected void onFinishInflate() {
49 super.onFinishInflate();
50
Winson Chung201bc822011-06-20 15:41:53 -070051 mText = (TextView) findViewById(R.id.info_target_text);
Winson Chunga62e9fd2011-07-11 15:20:48 -070052 mOriginalTextColor = mText.getTextColors();
Winson Chung201bc822011-06-20 15:41:53 -070053
Winson Chung4c98d922011-05-31 16:50:48 -070054 // Get the hover color
55 Resources r = getResources();
Winson Chung4c98d922011-05-31 16:50:48 -070056 mHoverColor = r.getColor(R.color.info_target_hover_tint);
57 mHoverPaint.setColorFilter(new PorterDuffColorFilter(
58 mHoverColor, PorterDuff.Mode.SRC_ATOP));
Winson Chung967289b2011-06-30 18:09:30 -070059 mDrawable = (TransitionDrawable) mText.getCompoundDrawables()[0];
60 mDrawable.setCrossFadeEnabled(true);
Winson Chung201bc822011-06-20 15:41:53 -070061
62 // Remove the text in the Phone UI in landscape
63 int orientation = getResources().getConfiguration().orientation;
64 if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
65 if (!LauncherApplication.isScreenLarge()) {
66 mText.setText("");
67 }
68 }
Winson Chung4c98d922011-05-31 16:50:48 -070069 }
70
Winson Chung201bc822011-06-20 15:41:53 -070071 private boolean isAllAppsApplication(DragSource source, Object info) {
72 return (source instanceof AppsCustomizePagedView) && (info instanceof ApplicationInfo);
Winson Chung4c98d922011-05-31 16:50:48 -070073 }
74
75 @Override
76 public boolean acceptDrop(DragObject d) {
77 // acceptDrop is called just before onDrop. We do the work here, rather than
78 // in onDrop, because it allows us to reject the drop (by returning false)
79 // so that the object being dragged isn't removed from the drag source.
80 ComponentName componentName = null;
81 if (d.dragInfo instanceof ApplicationInfo) {
82 componentName = ((ApplicationInfo) d.dragInfo).componentName;
83 } else if (d.dragInfo instanceof ShortcutInfo) {
84 componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent();
85 }
86 if (componentName != null) {
87 mLauncher.startApplicationDetailsActivity(componentName);
88 }
89 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
96 // If we are dragging a widget or shortcut, hide the info target
Winson Chung201bc822011-06-20 15:41:53 -070097 if (!isAllAppsApplication(source, info)) {
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 Chunga62e9fd2011-07-11 15:20:48 -0700103 mText.setTextColor(mOriginalTextColor);
Winson Chung61fa4192011-06-12 15:15:29 -0700104 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 Chunga62e9fd2011-07-11 15:20:48 -0700117 mText.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 Chunga62e9fd2011-07-11 15:20:48 -0700125 mText.setTextColor(mOriginalTextColor);
Winson Chungaaa530a2011-07-11 21:06:30 -0700126 }
Winson Chung4c98d922011-05-31 16:50:48 -0700127 }
128}