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; 20 import android.content.res.Resources; 21 import android.graphics.Paint; 22 import android.util.AttributeSet; 23 import android.widget.TextView; 24 25 import com.android.launcher.R; 26 27 28 /** 29 * Implements a DropTarget. 30 */ 31 public class ButtonDropTarget extends TextView implements DropTarget, DragController.DragListener { 32 33 protected final int mTransitionDuration; 34 35 protected Launcher mLauncher; 36 private int mBottomDragPadding; 37 protected TextView mText; 38 protected SearchDropTargetBar mSearchDropTargetBar; 39 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 53 Resources r = getResources(); 54 mTransitionDuration = r.getInteger(R.integer.config_dropTargetBgTransitionDuration); 55 mBottomDragPadding = r.getDimensionPixelSize(R.dimen.drop_target_drag_padding); 56 } 57 58 void setLauncher(Launcher launcher) { 59 mLauncher = launcher; 60 } 61 62 public boolean acceptDrop(DragObject d) { 63 return false; 64 } 65 66 public void setSearchDropTargetBar(SearchDropTargetBar searchDropTargetBar) { 67 mSearchDropTargetBar = searchDropTargetBar; 68 } 69 70 public void onDrop(DragObject d) { 71 } 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 98 public void getHitRect(android.graphics.Rect outRect) { 99 super.getHitRect(outRect); 100 outRect.bottom += mBottomDragPadding; 101 } 102 103 @Override 104 public DropTarget getDropTargetDelegate(DragObject d) { 105 return null; 106 } 107 108 public void getLocationInDragLayer(int[] loc) { 109 mLauncher.getDragLayer().getLocationInDragLayer(this, loc); 110 } 111 } 112