Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.launcher2; |
| 18 | |
| 19 | import android.content.Context; |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 20 | import android.content.res.Resources; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 21 | import android.graphics.Paint; |
| 22 | import android.util.AttributeSet; |
| 23 | import android.widget.FrameLayout; |
| 24 | |
| 25 | import com.android.launcher.R; |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | * Implements a DropTarget. |
| 30 | */ |
| 31 | public class ButtonDropTarget extends FrameLayout implements DropTarget, DragController.DragListener { |
| 32 | |
| 33 | protected final int mTransitionDuration; |
| 34 | |
| 35 | protected Launcher mLauncher; |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 36 | private int mBottomDragPadding; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 37 | |
| 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 Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 51 | Resources r = getResources(); |
| 52 | mTransitionDuration = r.getInteger(R.integer.config_dropTargetBgTransitionDuration); |
| 53 | mBottomDragPadding = r.getDimensionPixelSize(R.dimen.drop_target_drag_padding); |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 54 | } |
| 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 Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 93 | public void getHitRect(android.graphics.Rect outRect) { |
| 94 | super.getHitRect(outRect); |
| 95 | outRect.bottom += mBottomDragPadding; |
| 96 | } |
| 97 | |
| 98 | @Override |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 99 | public DropTarget getDropTargetDelegate(DragObject d) { |
| 100 | return null; |
| 101 | } |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 102 | |
| 103 | public void getLocationInDragLayer(int[] loc) { |
| 104 | mLauncher.getDragLayer().getLocationInDragLayer(this, loc); |
| 105 | } |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 106 | } |