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