blob: 99a52582e9e693f66da5fb1e6514b0f478b92074 [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
Patrick Dubroybc6840b2010-09-01 11:54:27 -070019import android.content.ComponentName;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070020import android.content.Context;
21import android.graphics.Paint;
22import android.graphics.PorterDuff;
23import android.graphics.PorterDuffColorFilter;
24import android.graphics.Rect;
25import android.util.AttributeSet;
26import android.view.View;
27import android.widget.ImageView;
28
29/**
30 * Implements a DropTarget which allows applications to be dropped on it,
31 * in order to launch the application info for that app.
32 */
33public class ApplicationInfoDropTarget extends ImageView implements DropTarget, DragController.DragListener {
34 private Launcher mLauncher;
35 private DragController mDragController;
36 private boolean mActive = false;
37
38 private View mHandle;
39
40 private final Paint mPaint = new Paint();
41
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);
48 }
49
50 @Override
51 protected void onFinishInflate() {
52 super.onFinishInflate();
53 }
54
55 /**
56 * Set the color that will be used as a filter over objects dragged over this object.
57 */
58 public void setDragColor(int color) {
59 mPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
60 }
61
62 public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
63 DragView dragView, Object dragInfo) {
64
65 // acceptDrop is called just before onDrop. We do the work here, rather than
66 // in onDrop, because it allows us to reject the drop (by returning false)
67 // so that the object being dragged isn't removed from the home screen.
68
Patrick Dubroybc6840b2010-09-01 11:54:27 -070069 ComponentName componentName = null;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070070 if (dragInfo instanceof ApplicationInfo) {
Patrick Dubroybc6840b2010-09-01 11:54:27 -070071 componentName = ((ApplicationInfo)dragInfo).componentName;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070072 } else if (dragInfo instanceof ShortcutInfo) {
Patrick Dubroybc6840b2010-09-01 11:54:27 -070073 componentName = ((ShortcutInfo)dragInfo).intent.getComponent();
Patrick Dubroy4ed62782010-08-17 15:11:18 -070074 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -070075 mLauncher.startApplicationDetailsActivity(componentName);
Patrick Dubroy4ed62782010-08-17 15:11:18 -070076 return false;
77 }
78
Patrick Dubroy4ed62782010-08-17 15:11:18 -070079 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
80 DragView dragView, Object dragInfo) {
81
82 }
83
84 public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
85 DragView dragView, Object dragInfo) {
86 dragView.setPaint(mPaint);
87 }
88
89 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
90 DragView dragView, Object dragInfo) {
91 }
92
93 public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
94 DragView dragView, Object dragInfo) {
95 // TODO: Animate out
96 dragView.setPaint(null);
97 }
98
99 public void onDragStart(DragSource source, Object info, int dragAction) {
100 if (info != null) {
101 mActive = true;
102
103 // TODO: Animate these in and out
104
105 // Only show the info icon when an application is selected
106 if (((ItemInfo)info).itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
107 setVisibility(VISIBLE);
108 }
109 mHandle.setVisibility(INVISIBLE);
110 }
111 }
112
113 public void onDragEnd() {
114 if (mActive) {
115 mActive = false;
116 // TODO: Animate these in and out
117 setVisibility(GONE);
118 mHandle.setVisibility(VISIBLE);
119 }
120 }
121
122 void setLauncher(Launcher launcher) {
123 mLauncher = launcher;
124 }
125
126 void setDragController(DragController dragController) {
127 mDragController = dragController;
128 }
129
130 void setHandle(View view) {
131 mHandle = view;
132 }
133
134 @Override
135 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset,
136 DragView dragView, Object dragInfo) {
137 return null;
138 }
139}