blob: 254d9bfe8f2d0e76bbc837aa6d33750c8b79f736 [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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
Winson Chung4c98d922011-05-31 16:50:48 -070018
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;
Adam Cohened11c142014-06-03 18:03:29 -070024import android.graphics.drawable.Drawable;
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
Winson Chung61fa4192011-06-12 15:15:29 -070030public class InfoDropTarget extends ButtonDropTarget {
Winson Chung4c98d922011-05-31 16:50:48 -070031
Winson Chunga62e9fd2011-07-11 15:20:48 -070032 private ColorStateList mOriginalTextColor;
Winson Chung967289b2011-06-30 18:09:30 -070033 private TransitionDrawable mDrawable;
Winson Chung4c98d922011-05-31 16:50:48 -070034
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
Winson Chunga6427b12011-07-27 10:53:39 -070047 mOriginalTextColor = getTextColors();
Winson Chung201bc822011-06-20 15:41:53 -070048
Winson Chung4c98d922011-05-31 16:50:48 -070049 // Get the hover color
50 Resources r = getResources();
Winson Chung4c98d922011-05-31 16:50:48 -070051 mHoverColor = r.getColor(R.color.info_target_hover_tint);
Winson Chung947245b2012-05-15 16:34:19 -070052 mDrawable = (TransitionDrawable) getCurrentDrawable();
Adam Cohened11c142014-06-03 18:03:29 -070053
54 if (mDrawable == null) {
55 System.out.println("onFinishInflate -- drawable null");
56 }
57
58 // DEBUG CODE:
59 Drawable normal = r.getDrawable(R.drawable.ic_launcher_info_normal_holo);
60 Drawable active = r.getDrawable(R.drawable.ic_launcher_info_active_holo);
61 Drawable selector = r.getDrawable(R.drawable.info_target_selector);
62 System.out.println("Normal: " + normal);
63 System.out.println("Active: " + active);
64 System.out.println("Selector: " + selector);
65
Fabrice Di Megliocc11f742012-12-18 16:25:49 -080066 if (null != mDrawable) {
67 mDrawable.setCrossFadeEnabled(true);
68 }
Winson Chung201bc822011-06-20 15:41:53 -070069
70 // Remove the text in the Phone UI in landscape
71 int orientation = getResources().getConfiguration().orientation;
72 if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
Daniel Sandlere4f98912013-06-25 15:13:26 -040073 if (!LauncherAppState.getInstance().isScreenLarge()) {
Winson Chunga6427b12011-07-27 10:53:39 -070074 setText("");
Winson Chung201bc822011-06-20 15:41:53 -070075 }
76 }
Winson Chung4c98d922011-05-31 16:50:48 -070077 }
78
Winson Chung4c98d922011-05-31 16:50:48 -070079 @Override
80 public boolean acceptDrop(DragObject d) {
81 // acceptDrop is called just before onDrop. We do the work here, rather than
82 // in onDrop, because it allows us to reject the drop (by returning false)
83 // so that the object being dragged isn't removed from the drag source.
84 ComponentName componentName = null;
Michael Jurkaeadbfc52013-09-04 00:45:37 +020085 if (d.dragInfo instanceof AppInfo) {
86 componentName = ((AppInfo) d.dragInfo).componentName;
Winson Chung4c98d922011-05-31 16:50:48 -070087 } else if (d.dragInfo instanceof ShortcutInfo) {
88 componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent();
Winson Chung11a49372012-04-27 15:12:38 -070089 } else if (d.dragInfo instanceof PendingAddItemInfo) {
90 componentName = ((PendingAddItemInfo) d.dragInfo).componentName;
Winson Chung4c98d922011-05-31 16:50:48 -070091 }
92 if (componentName != null) {
93 mLauncher.startApplicationDetailsActivity(componentName);
94 }
Winson Chung7bd1bbb2012-02-13 18:29:29 -080095
96 // There is no post-drop animation, so clean up the DragView now
97 d.deferDragViewCleanupPostAnimation = false;
Winson Chung4c98d922011-05-31 16:50:48 -070098 return false;
99 }
100
101 @Override
102 public void onDragStart(DragSource source, Object info, int dragAction) {
Winson Chung4c98d922011-05-31 16:50:48 -0700103 boolean isVisible = true;
104
Winson Chung11a49372012-04-27 15:12:38 -0700105 // Hide this button unless we are dragging something from AllApps
Mathew Inwood1eeb3fc2013-11-25 17:01:34 +0000106 if (!source.supportsAppInfoDropTarget()) {
Winson Chung4c98d922011-05-31 16:50:48 -0700107 isVisible = false;
108 }
109
Adam Cohened11c142014-06-03 18:03:29 -0700110 if (mDrawable == null) {
111 System.out.println("onDragStart -- drawable null");
112 }
113
Winson Chung4c98d922011-05-31 16:50:48 -0700114 mActive = isVisible;
Adam Cohened11c142014-06-03 18:03:29 -0700115 if (mDrawable != null) {
116 mDrawable.resetTransition();
117 }
Winson Chunga6427b12011-07-27 10:53:39 -0700118 setTextColor(mOriginalTextColor);
119 ((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE);
Winson Chung4c98d922011-05-31 16:50:48 -0700120 }
121
122 @Override
123 public void onDragEnd() {
124 super.onDragEnd();
125 mActive = false;
126 }
127
128 public void onDragEnter(DragObject d) {
129 super.onDragEnter(d);
130
Adam Cohened11c142014-06-03 18:03:29 -0700131 if (mDrawable != null) {
132 mDrawable.startTransition(mTransitionDuration);
133 }
Winson Chunga6427b12011-07-27 10:53:39 -0700134 setTextColor(mHoverColor);
Winson Chung4c98d922011-05-31 16:50:48 -0700135 }
136
137 public void onDragExit(DragObject d) {
138 super.onDragExit(d);
139
Winson Chungaaa530a2011-07-11 21:06:30 -0700140 if (!d.dragComplete) {
141 mDrawable.resetTransition();
Winson Chunga6427b12011-07-27 10:53:39 -0700142 setTextColor(mOriginalTextColor);
Winson Chungaaa530a2011-07-11 21:06:30 -0700143 }
Winson Chung4c98d922011-05-31 16:50:48 -0700144 }
145}