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