blob: 4ff7c9669f57b9966b5f7cb2865126c34d5876ec [file] [log] [blame]
Winson Chung61fa4192011-06-12 15:15:29 -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
19import android.content.Context;
Winson Chunga62e9fd2011-07-11 15:20:48 -070020import android.content.res.Resources;
Winson Chung61fa4192011-06-12 15:15:29 -070021import android.graphics.Paint;
22import android.util.AttributeSet;
Adam Cohend4d7aa52011-07-19 21:47:37 -070023import android.widget.TextView;
Winson Chung61fa4192011-06-12 15:15:29 -070024
25import com.android.launcher.R;
26
27
28/**
29 * Implements a DropTarget.
30 */
Winson Chunga6427b12011-07-27 10:53:39 -070031public class ButtonDropTarget extends TextView implements DropTarget, DragController.DragListener {
Winson Chung61fa4192011-06-12 15:15:29 -070032
33 protected final int mTransitionDuration;
34
35 protected Launcher mLauncher;
Winson Chunga62e9fd2011-07-11 15:20:48 -070036 private int mBottomDragPadding;
Adam Cohend4d7aa52011-07-19 21:47:37 -070037 protected TextView mText;
38 protected SearchDropTargetBar mSearchDropTargetBar;
Winson Chung61fa4192011-06-12 15:15:29 -070039
40 /** Whether this drop target is active for the current drag */
41 protected boolean mActive;
42
43 /** The paint applied to the drag view on hover */
44 protected final Paint mHoverPaint = new Paint();
45
46 public ButtonDropTarget(Context context, AttributeSet attrs) {
47 this(context, attrs, 0);
48 }
49
50 public ButtonDropTarget(Context context, AttributeSet attrs, int defStyle) {
51 super(context, attrs, defStyle);
52
Winson Chunga62e9fd2011-07-11 15:20:48 -070053 Resources r = getResources();
54 mTransitionDuration = r.getInteger(R.integer.config_dropTargetBgTransitionDuration);
55 mBottomDragPadding = r.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
Winson Chung61fa4192011-06-12 15:15:29 -070056 }
57
58 void setLauncher(Launcher launcher) {
59 mLauncher = launcher;
60 }
61
62 public boolean acceptDrop(DragObject d) {
63 return false;
64 }
65
Adam Cohend4d7aa52011-07-19 21:47:37 -070066 public void setSearchDropTargetBar(SearchDropTargetBar searchDropTargetBar) {
67 mSearchDropTargetBar = searchDropTargetBar;
68 }
69
Winson Chung61fa4192011-06-12 15:15:29 -070070 public void onDrop(DragObject d) {
Winson Chung61fa4192011-06-12 15:15:29 -070071 }
72
73 public void onDragEnter(DragObject d) {
74 d.dragView.setPaint(mHoverPaint);
75 }
76
77 public void onDragOver(DragObject d) {
78 // Do nothing
79 }
80
81 public void onDragExit(DragObject d) {
82 d.dragView.setPaint(null);
83 }
84
85 public void onDragStart(DragSource source, Object info, int dragAction) {
86 // Do nothing
87 }
88
89 public boolean isDropEnabled() {
90 return mActive;
91 }
92
93 public void onDragEnd() {
94 // Do nothing
95 }
96
97 @Override
Winson Chunga62e9fd2011-07-11 15:20:48 -070098 public void getHitRect(android.graphics.Rect outRect) {
99 super.getHitRect(outRect);
100 outRect.bottom += mBottomDragPadding;
101 }
102
103 @Override
Winson Chung61fa4192011-06-12 15:15:29 -0700104 public DropTarget getDropTargetDelegate(DragObject d) {
105 return null;
106 }
Adam Cohen8dfcba42011-07-07 16:38:18 -0700107
108 public void getLocationInDragLayer(int[] loc) {
109 mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
110 }
Winson Chung61fa4192011-06-12 15:15:29 -0700111}