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