blob: f87889cfb76463546331a3ad265e700028251480 [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;
20import android.graphics.Paint;
21import android.util.AttributeSet;
22import android.widget.FrameLayout;
23
24import com.android.launcher.R;
25
26
27/**
28 * Implements a DropTarget.
29 */
30public class ButtonDropTarget extends FrameLayout implements DropTarget, DragController.DragListener {
31
32 protected final int mTransitionDuration;
33
34 protected Launcher mLauncher;
35
36 /** Whether this drop target is active for the current drag */
37 protected boolean mActive;
38
39 /** The paint applied to the drag view on hover */
40 protected final Paint mHoverPaint = new Paint();
41
42 public ButtonDropTarget(Context context, AttributeSet attrs) {
43 this(context, attrs, 0);
44 }
45
46 public ButtonDropTarget(Context context, AttributeSet attrs, int defStyle) {
47 super(context, attrs, defStyle);
48
49 mTransitionDuration =
50 context.getResources().getInteger(R.integer.config_dropTargetBgTransitionDuration);
51 }
52
53 void setLauncher(Launcher launcher) {
54 mLauncher = launcher;
55 }
56
57 public boolean acceptDrop(DragObject d) {
58 return false;
59 }
60
61 public void onDrop(DragObject d) {
62 // Do nothing
63 }
64
65 public void onDragEnter(DragObject d) {
66 d.dragView.setPaint(mHoverPaint);
67 }
68
69 public void onDragOver(DragObject d) {
70 // Do nothing
71 }
72
73 public void onDragExit(DragObject d) {
74 d.dragView.setPaint(null);
75 }
76
77 public void onDragStart(DragSource source, Object info, int dragAction) {
78 // Do nothing
79 }
80
81 public boolean isDropEnabled() {
82 return mActive;
83 }
84
85 public void onDragEnd() {
86 // Do nothing
87 }
88
89 @Override
90 public DropTarget getDropTargetDelegate(DragObject d) {
91 return null;
92 }
Adam Cohen8dfcba42011-07-07 16:38:18 -070093
94 public void getLocationInDragLayer(int[] loc) {
95 mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
96 }
Winson Chung61fa4192011-06-12 15:15:29 -070097}