blob: 4a9727dd58b85ee98ee8cbcd08c8cc82a344f011 [file] [log] [blame]
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001/*
2 * Copyright (C) 2010 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 Chung760e5372010-12-15 13:14:23 -080019import android.animation.Animator;
Michael Jurka800242b2010-12-16 11:39:26 -080020import android.animation.AnimatorSet;
Winson Chung760e5372010-12-15 13:14:23 -080021import android.animation.ObjectAnimator;
Michael Jurka800242b2010-12-16 11:39:26 -080022import android.animation.Animator.AnimatorListener;
Patrick Dubroybc6840b2010-09-01 11:54:27 -070023import android.content.ComponentName;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070024import android.content.Context;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070025import android.graphics.PorterDuff;
26import android.graphics.PorterDuffColorFilter;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070027import android.util.AttributeSet;
Michael Jurka800242b2010-12-16 11:39:26 -080028import android.view.View;
Adam Cohencdc30d52010-12-01 15:09:47 -080029
Adam Cohenc0dcf592011-06-01 15:30:43 -070030import com.android.launcher.R;
31
Patrick Dubroy4ed62782010-08-17 15:11:18 -070032/**
33 * Implements a DropTarget which allows applications to be dropped on it,
34 * in order to launch the application info for that app.
35 */
Winson Chung760e5372010-12-15 13:14:23 -080036public class ApplicationInfoDropTarget extends IconDropTarget {
37 private static final int sFadeInAnimationDuration = 200;
38 private static final int sFadeOutAnimationDuration = 100;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070039
Michael Jurka800242b2010-12-16 11:39:26 -080040 private AnimatorSet mFadeAnimator;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070041
42 public ApplicationInfoDropTarget(Context context, AttributeSet attrs) {
43 this(context, attrs, 0);
44 }
45
46 public ApplicationInfoDropTarget(Context context, AttributeSet attrs, int defStyle) {
47 super(context, attrs, defStyle);
Patrick Dubroy4ed62782010-08-17 15:11:18 -070048
Winson Chung760e5372010-12-15 13:14:23 -080049 // Set the hover paint colour
Winson Chung4c98d922011-05-31 16:50:48 -070050 int colour = getContext().getResources().getColor(R.color.info_target_hover_tint);
Winson Chung760e5372010-12-15 13:14:23 -080051 mHoverPaint.setColorFilter(new PorterDuffColorFilter(colour, PorterDuff.Mode.SRC_ATOP));
Winson Chungbe5212b2010-12-20 11:36:33 -080052
Winson Chungf0ea4d32011-06-06 14:27:16 -070053 // For the application info drop target, we just ignore the left padding since we don't want
54 // to overlap with the delete zone padding
55 int tb = getResources().getDimensionPixelSize(
56 R.dimen.delete_zone_vertical_drag_padding);
57 int lr = getResources().getDimensionPixelSize(
58 R.dimen.delete_zone_horizontal_drag_padding);
59 setDragPadding(tb, lr, tb, 0);
Patrick Dubroy4ed62782010-08-17 15:11:18 -070060 }
61
Adam Cohencb3382b2011-05-24 14:07:08 -070062 public boolean acceptDrop(DragObject d) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -070063 // acceptDrop is called just before onDrop. We do the work here, rather than
64 // in onDrop, because it allows us to reject the drop (by returning false)
65 // so that the object being dragged isn't removed from the home screen.
Adam Cohencdc30d52010-12-01 15:09:47 -080066 if (getVisibility() != VISIBLE) return false;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070067
Patrick Dubroybc6840b2010-09-01 11:54:27 -070068 ComponentName componentName = null;
Adam Cohencb3382b2011-05-24 14:07:08 -070069 if (d.dragInfo instanceof ApplicationInfo) {
70 componentName = ((ApplicationInfo) d.dragInfo).componentName;
71 } else if (d.dragInfo instanceof ShortcutInfo) {
72 componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent();
Patrick Dubroy4ed62782010-08-17 15:11:18 -070073 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -070074 mLauncher.startApplicationDetailsActivity(componentName);
Patrick Dubroy4ed62782010-08-17 15:11:18 -070075 return false;
76 }
77
Adam Cohencb3382b2011-05-24 14:07:08 -070078 public void onDragEnter(DragObject d) {
Adam Cohencdc30d52010-12-01 15:09:47 -080079 if (!mDragAndDropEnabled) return;
Adam Cohencb3382b2011-05-24 14:07:08 -070080 d.dragView.setPaint(mHoverPaint);
Patrick Dubroy4ed62782010-08-17 15:11:18 -070081 }
82
Adam Cohencb3382b2011-05-24 14:07:08 -070083 public void onDragExit(DragObject d) {
Adam Cohencdc30d52010-12-01 15:09:47 -080084 if (!mDragAndDropEnabled) return;
Adam Cohencb3382b2011-05-24 14:07:08 -070085 d.dragView.setPaint(null);
Patrick Dubroy4ed62782010-08-17 15:11:18 -070086 }
87
88 public void onDragStart(DragSource source, Object info, int dragAction) {
Adam Cohencdc30d52010-12-01 15:09:47 -080089 if (info != null && mDragAndDropEnabled) {
Michael Jurka774bd372010-10-22 13:40:50 -070090 final int itemType = ((ItemInfo)info).itemType;
91 mActive = (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION);
Adam Cohencdc30d52010-12-01 15:09:47 -080092 if (mActive) {
Winson Chung760e5372010-12-15 13:14:23 -080093 // Fade in this icon
94 if (mFadeAnimator != null) mFadeAnimator.cancel();
Michael Jurka800242b2010-12-16 11:39:26 -080095 mFadeAnimator = new AnimatorSet();
96 Animator infoButtonAnimator = ObjectAnimator.ofFloat(this, "alpha", 0.0f, 1.0f);
97 infoButtonAnimator.setDuration(sFadeInAnimationDuration);
98
Michael Jurkab8e14472010-12-20 16:06:10 -080099 mFadeAnimator.play(infoButtonAnimator);
100
Adam Cohencdc30d52010-12-01 15:09:47 -0800101 setVisibility(VISIBLE);
Winson Chung760e5372010-12-15 13:14:23 -0800102
Michael Jurkab8e14472010-12-20 16:06:10 -0800103 // Fade out the overlapping views
104 if (mOverlappingViews != null) {
105 for (View view : mOverlappingViews) {
106 ObjectAnimator oa = ObjectAnimator.ofFloat(view, "alpha", 0.0f);
107 oa.setDuration(sFadeOutAnimationDuration);
108 mFadeAnimator.play(oa);
109 }
110 mFadeAnimator.addListener(new AnimatorListener() {
Winson Chung760e5372010-12-15 13:14:23 -0800111 public void onAnimationStart(Animator animation) {}
112 public void onAnimationRepeat(Animator animation) {}
113 public void onAnimationEnd(Animator animation) {
114 onEndOrCancel();
115 }
116 public void onAnimationCancel(Animator animation) {
117 onEndOrCancel();
118 }
119 private void onEndOrCancel() {
Michael Jurkab8e14472010-12-20 16:06:10 -0800120 for (View view : mOverlappingViews) {
121 view.setVisibility(INVISIBLE);
122 }
123 mFadeAnimator = null;
Winson Chung760e5372010-12-15 13:14:23 -0800124 }
125 });
Winson Chung760e5372010-12-15 13:14:23 -0800126 }
Michael Jurkab8e14472010-12-20 16:06:10 -0800127 mFadeAnimator.start();
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700128 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700129 }
130 }
131
132 public void onDragEnd() {
Adam Cohencdc30d52010-12-01 15:09:47 -0800133 if (!mDragAndDropEnabled) return;
Winson Chung760e5372010-12-15 13:14:23 -0800134 if (mActive) mActive = false;
Adam Cohencdc30d52010-12-01 15:09:47 -0800135
Winson Chung760e5372010-12-15 13:14:23 -0800136 // Fade out this icon
137 if (mFadeAnimator != null) mFadeAnimator.cancel();
Michael Jurka800242b2010-12-16 11:39:26 -0800138 mFadeAnimator = new AnimatorSet();
139 Animator infoButtonAnimator = ObjectAnimator.ofFloat(this, "alpha", 0.0f);
140 infoButtonAnimator.setDuration(sFadeOutAnimationDuration);
Winson Chung760e5372010-12-15 13:14:23 -0800141 mFadeAnimator.addListener(new AnimatorListener() {
142 public void onAnimationStart(Animator animation) {}
143 public void onAnimationRepeat(Animator animation) {}
144 public void onAnimationEnd(Animator animation) {
145 onEndOrCancel();
146 }
147 public void onAnimationCancel(Animator animation) {
148 onEndOrCancel();
149 }
150 private void onEndOrCancel() {
151 setVisibility(GONE);
152 mFadeAnimator = null;
153 }
154 });
Michael Jurkab8e14472010-12-20 16:06:10 -0800155 mFadeAnimator.play(infoButtonAnimator);
Winson Chung760e5372010-12-15 13:14:23 -0800156
Michael Jurkab8e14472010-12-20 16:06:10 -0800157 // Fade in the overlapping views
158 if (mOverlappingViews != null) {
159 for (View view : mOverlappingViews) {
Winson Chung785d2eb2011-04-14 16:08:02 -0700160 // Check whether the views are enabled first, before trying to fade them in
161 if (view.isEnabled()) {
162 ObjectAnimator oa = ObjectAnimator.ofFloat(view, "alpha", 1.0f);
163 oa.setDuration(sFadeInAnimationDuration);
164 mFadeAnimator.play(oa);
165 view.setVisibility(VISIBLE);
166 }
Michael Jurkab8e14472010-12-20 16:06:10 -0800167 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700168 }
Michael Jurkab8e14472010-12-20 16:06:10 -0800169 mFadeAnimator.start();
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700170 }
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700171}