1 package com.android.dialer.list; 2 3 import android.content.Context; 4 import android.content.res.Resources; 5 import android.graphics.drawable.Drawable; 6 import android.util.AttributeSet; 7 import android.util.Log; 8 import android.view.DragEvent; 9 import android.widget.FrameLayout; 10 import android.widget.ImageView; 11 import android.widget.LinearLayout; 12 import android.widget.TextView; 13 14 import com.android.dialer.R; 15 16 public class RemoveView extends FrameLayout { 17 18 DragDropController mDragDropController; 19 TextView mRemoveText; 20 ImageView mRemoveIcon; 21 int mUnhighlightedColor; 22 int mHighlightedColor; 23 Drawable mRemoveDrawable; 24 RemoveView(Context context)25 public RemoveView(Context context) { 26 super(context); 27 } 28 RemoveView(Context context, AttributeSet attrs)29 public RemoveView(Context context, AttributeSet attrs) { 30 this(context, attrs, -1); 31 } 32 RemoveView(Context context, AttributeSet attrs, int defStyle)33 public RemoveView(Context context, AttributeSet attrs, int defStyle) { 34 super(context, attrs, defStyle); 35 } 36 37 @Override onFinishInflate()38 protected void onFinishInflate() { 39 mRemoveText = (TextView) findViewById(R.id.remove_view_text); 40 mRemoveIcon = (ImageView) findViewById(R.id.remove_view_icon); 41 final Resources r = getResources(); 42 mUnhighlightedColor = r.getColor(R.color.remove_text_color); 43 mHighlightedColor = r.getColor(R.color.remove_highlighted_text_color); 44 mRemoveDrawable = r.getDrawable(R.drawable.ic_remove); 45 } 46 setDragDropController(DragDropController controller)47 public void setDragDropController(DragDropController controller) { 48 mDragDropController = controller; 49 } 50 51 @Override onDragEvent(DragEvent event)52 public boolean onDragEvent(DragEvent event) { 53 final int action = event.getAction(); 54 switch (action) { 55 case DragEvent.ACTION_DRAG_ENTERED: 56 setAppearanceHighlighted(); 57 break; 58 case DragEvent.ACTION_DRAG_EXITED: 59 setAppearanceNormal(); 60 break; 61 case DragEvent.ACTION_DRAG_LOCATION: 62 if (mDragDropController != null) { 63 mDragDropController.handleDragHovered(this, (int) event.getX(), 64 (int) event.getY()); 65 } 66 break; 67 case DragEvent.ACTION_DROP: 68 if (mDragDropController != null) { 69 mDragDropController.handleDragFinished((int) event.getX(), (int) event.getY(), 70 true); 71 } 72 setAppearanceNormal(); 73 break; 74 } 75 return true; 76 } 77 setAppearanceNormal()78 private void setAppearanceNormal() { 79 mRemoveText.setTextColor(mUnhighlightedColor); 80 mRemoveIcon.setColorFilter(mUnhighlightedColor); 81 invalidate(); 82 } 83 setAppearanceHighlighted()84 private void setAppearanceHighlighted() { 85 mRemoveText.setTextColor(mHighlightedColor); 86 mRemoveIcon.setColorFilter(mHighlightedColor); 87 invalidate(); 88 } 89 } 90