blob: c7812e3de3f4895882a64a12a10459c6f609fb08 [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 Chung201bc822011-06-20 15:41:53 -070021import android.content.res.Configuration;
Winson Chung4c98d922011-05-31 16:50:48 -070022import android.content.res.Resources;
23import android.graphics.PorterDuff;
24import android.graphics.PorterDuffColorFilter;
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 Chung201bc822011-06-20 15:41:53 -070028import android.widget.TextView;
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 Chung201bc822011-06-20 15:41:53 -070034 private TextView mText;
Winson Chung967289b2011-06-30 18:09:30 -070035 private TransitionDrawable mDrawable;
Winson Chung4c98d922011-05-31 16:50:48 -070036 private int mHoverColor = 0xFF0000FF;
37
38 public InfoDropTarget(Context context, AttributeSet attrs) {
39 this(context, attrs, 0);
40 }
41
42 public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) {
43 super(context, attrs, defStyle);
44 }
45
46 @Override
47 protected void onFinishInflate() {
48 super.onFinishInflate();
49
Winson Chung201bc822011-06-20 15:41:53 -070050 mText = (TextView) findViewById(R.id.info_target_text);
51
Winson Chung4c98d922011-05-31 16:50:48 -070052 // Get the hover color
53 Resources r = getResources();
Winson Chung4c98d922011-05-31 16:50:48 -070054 mHoverColor = r.getColor(R.color.info_target_hover_tint);
55 mHoverPaint.setColorFilter(new PorterDuffColorFilter(
56 mHoverColor, PorterDuff.Mode.SRC_ATOP));
Winson Chung967289b2011-06-30 18:09:30 -070057 mDrawable = (TransitionDrawable) mText.getCompoundDrawables()[0];
58 mDrawable.setCrossFadeEnabled(true);
Winson Chung201bc822011-06-20 15:41:53 -070059
60 // Remove the text in the Phone UI in landscape
61 int orientation = getResources().getConfiguration().orientation;
62 if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
63 if (!LauncherApplication.isScreenLarge()) {
64 mText.setText("");
65 }
66 }
Winson Chung4c98d922011-05-31 16:50:48 -070067 }
68
Winson Chung201bc822011-06-20 15:41:53 -070069 private boolean isAllAppsApplication(DragSource source, Object info) {
70 return (source instanceof AppsCustomizePagedView) && (info instanceof ApplicationInfo);
Winson Chung4c98d922011-05-31 16:50:48 -070071 }
72
73 @Override
74 public boolean acceptDrop(DragObject d) {
75 // acceptDrop is called just before onDrop. We do the work here, rather than
76 // in onDrop, because it allows us to reject the drop (by returning false)
77 // so that the object being dragged isn't removed from the drag source.
78 ComponentName componentName = null;
79 if (d.dragInfo instanceof ApplicationInfo) {
80 componentName = ((ApplicationInfo) d.dragInfo).componentName;
81 } else if (d.dragInfo instanceof ShortcutInfo) {
82 componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent();
83 }
84 if (componentName != null) {
85 mLauncher.startApplicationDetailsActivity(componentName);
86 }
87 return false;
88 }
89
90 @Override
91 public void onDragStart(DragSource source, Object info, int dragAction) {
Winson Chung4c98d922011-05-31 16:50:48 -070092 boolean isVisible = true;
93
94 // If we are dragging a widget or shortcut, hide the info target
Winson Chung201bc822011-06-20 15:41:53 -070095 if (!isAllAppsApplication(source, info)) {
Winson Chung4c98d922011-05-31 16:50:48 -070096 isVisible = false;
97 }
98
99 mActive = isVisible;
Winson Chung61fa4192011-06-12 15:15:29 -0700100 setVisibility(isVisible ? View.VISIBLE : View.GONE);
Winson Chung4c98d922011-05-31 16:50:48 -0700101 }
102
103 @Override
104 public void onDragEnd() {
105 super.onDragEnd();
106 mActive = false;
107 }
108
109 public void onDragEnter(DragObject d) {
110 super.onDragEnter(d);
111
Winson Chung967289b2011-06-30 18:09:30 -0700112 mDrawable.startTransition(mTransitionDuration);
Winson Chung4c98d922011-05-31 16:50:48 -0700113 }
114
115 public void onDragExit(DragObject d) {
116 super.onDragExit(d);
117
Winson Chung967289b2011-06-30 18:09:30 -0700118 mDrawable.resetTransition();
Winson Chung4c98d922011-05-31 16:50:48 -0700119 }
120}