Home | History | Annotate | Download | only in list
      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.view.DragEvent;
      8 import android.widget.ImageView;
      9 import android.widget.LinearLayout;
     10 import android.widget.TextView;
     11 
     12 import com.android.dialer.R;
     13 
     14 public class RemoveView extends LinearLayout {
     15 
     16     DragDropController mDragDropController;
     17     TextView mRemoveText;
     18     ImageView mRemoveIcon;
     19     int mUnhighlightedColor;
     20     int mHighlightedColor;
     21     Drawable mRemoveDrawable;
     22     Drawable mRemoveHighlightedDrawable;
     23 
     24     public RemoveView(Context context) {
     25       super(context);
     26     }
     27 
     28     public RemoveView(Context context, AttributeSet attrs) {
     29         this(context, attrs, -1);
     30     }
     31 
     32     public RemoveView(Context context, AttributeSet attrs, int defStyle) {
     33         super(context, attrs, defStyle);
     34     }
     35 
     36     @Override
     37     protected void onFinishInflate() {
     38         mRemoveText = (TextView) findViewById(R.id.remove_view_text);
     39         mRemoveIcon = (ImageView) findViewById(R.id.remove_view_icon);
     40         final Resources r = getResources();
     41         mUnhighlightedColor = r.getColor(R.color.remove_text_color);
     42         mHighlightedColor = r.getColor(R.color.remove_highlighted_text_color);
     43         mRemoveDrawable = r.getDrawable(R.drawable.ic_remove);
     44         mRemoveHighlightedDrawable = r.getDrawable(R.drawable.ic_remove_highlight);
     45     }
     46 
     47     public void setDragDropController(DragDropController controller) {
     48         mDragDropController = controller;
     49     }
     50 
     51     @Override
     52     public boolean dispatchDragEvent(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((int) event.getX(),
     64                         // the true y-coordinate of the event with respect to the listview is
     65                         // offset by the height of the remove view
     66                         (int) event.getY() - getHeight(), null);
     67             }
     68             break;
     69         case DragEvent.ACTION_DROP:
     70             if (mDragDropController != null) {
     71                 mDragDropController.handleDragFinished((int) event.getX(), (int) event.getY(), true);
     72             }
     73             setAppearanceNormal();
     74             break;
     75       }
     76       return true;
     77     }
     78 
     79     private void setAppearanceNormal() {
     80         mRemoveText.setTextColor(mUnhighlightedColor);
     81         mRemoveIcon.setImageDrawable(mRemoveDrawable);
     82         invalidate();
     83     }
     84 
     85     private void setAppearanceHighlighted() {
     86         mRemoveText.setTextColor(mHighlightedColor);
     87         mRemoveIcon.setImageDrawable(mRemoveHighlightedDrawable);
     88         invalidate();
     89     }
     90 }
     91