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