blob: 374238c49f6288e877f2613120d5d9d6f1d1933c [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;
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
Winson Chung61fa4192011-06-12 15:15:29 -070029public class InfoDropTarget extends ButtonDropTarget {
Winson Chung4c98d922011-05-31 16:50:48 -070030
Winson Chunga62e9fd2011-07-11 15:20:48 -070031 private ColorStateList mOriginalTextColor;
Winson Chung967289b2011-06-30 18:09:30 -070032 private TransitionDrawable mDrawable;
Winson Chung4c98d922011-05-31 16:50:48 -070033
34 public InfoDropTarget(Context context, AttributeSet attrs) {
35 this(context, attrs, 0);
36 }
37
38 public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) {
39 super(context, attrs, defStyle);
40 }
41
42 @Override
43 protected void onFinishInflate() {
44 super.onFinishInflate();
45
Winson Chunga6427b12011-07-27 10:53:39 -070046 mOriginalTextColor = getTextColors();
Winson Chung201bc822011-06-20 15:41:53 -070047
Winson Chung4c98d922011-05-31 16:50:48 -070048 // Get the hover color
49 Resources r = getResources();
Winson Chung4c98d922011-05-31 16:50:48 -070050 mHoverColor = r.getColor(R.color.info_target_hover_tint);
Winson Chung947245b2012-05-15 16:34:19 -070051 mDrawable = (TransitionDrawable) getCurrentDrawable();
Fabrice Di Megliocc11f742012-12-18 16:25:49 -080052 if (null != mDrawable) {
53 mDrawable.setCrossFadeEnabled(true);
54 }
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) {
Daniel Sandlere4f98912013-06-25 15:13:26 -040059 if (!LauncherAppState.getInstance().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 Chung4c98d922011-05-31 16:50:48 -070065 @Override
66 public boolean acceptDrop(DragObject d) {
67 // acceptDrop is called just before onDrop. We do the work here, rather than
68 // in onDrop, because it allows us to reject the drop (by returning false)
69 // so that the object being dragged isn't removed from the drag source.
70 ComponentName componentName = null;
Michael Jurkaeadbfc52013-09-04 00:45:37 +020071 if (d.dragInfo instanceof AppInfo) {
72 componentName = ((AppInfo) d.dragInfo).componentName;
Winson Chung4c98d922011-05-31 16:50:48 -070073 } else if (d.dragInfo instanceof ShortcutInfo) {
74 componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent();
Winson Chung11a49372012-04-27 15:12:38 -070075 } else if (d.dragInfo instanceof PendingAddItemInfo) {
76 componentName = ((PendingAddItemInfo) d.dragInfo).componentName;
Winson Chung4c98d922011-05-31 16:50:48 -070077 }
78 if (componentName != null) {
79 mLauncher.startApplicationDetailsActivity(componentName);
80 }
Winson Chung7bd1bbb2012-02-13 18:29:29 -080081
82 // There is no post-drop animation, so clean up the DragView now
83 d.deferDragViewCleanupPostAnimation = false;
Winson Chung4c98d922011-05-31 16:50:48 -070084 return false;
85 }
86
87 @Override
88 public void onDragStart(DragSource source, Object info, int dragAction) {
Winson Chung4c98d922011-05-31 16:50:48 -070089 boolean isVisible = true;
90
Winson Chung11a49372012-04-27 15:12:38 -070091 // Hide this button unless we are dragging something from AllApps
Mathew Inwood1eeb3fc2013-11-25 17:01:34 +000092 if (!source.supportsAppInfoDropTarget()) {
Winson Chung4c98d922011-05-31 16:50:48 -070093 isVisible = false;
94 }
95
96 mActive = isVisible;
Winson Chungaaa530a2011-07-11 21:06:30 -070097 mDrawable.resetTransition();
Winson Chunga6427b12011-07-27 10:53:39 -070098 setTextColor(mOriginalTextColor);
99 ((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE);
Winson Chung4c98d922011-05-31 16:50:48 -0700100 }
101
102 @Override
103 public void onDragEnd() {
104 super.onDragEnd();
105 mActive = false;
106 }
107
108 public void onDragEnter(DragObject d) {
109 super.onDragEnter(d);
110
Winson Chung967289b2011-06-30 18:09:30 -0700111 mDrawable.startTransition(mTransitionDuration);
Winson Chunga6427b12011-07-27 10:53:39 -0700112 setTextColor(mHoverColor);
Winson Chung4c98d922011-05-31 16:50:48 -0700113 }
114
115 public void onDragExit(DragObject d) {
116 super.onDragExit(d);
117
Winson Chungaaa530a2011-07-11 21:06:30 -0700118 if (!d.dragComplete) {
119 mDrawable.resetTransition();
Winson Chunga6427b12011-07-27 10:53:39 -0700120 setTextColor(mOriginalTextColor);
Winson Chungaaa530a2011-07-11 21:06:30 -0700121 }
Winson Chung4c98d922011-05-31 16:50:48 -0700122 }
123}