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 dragDropController; 33 TextView removeText; 34 ImageView removeIcon; 35 int unhighlightedColor; 36 int highlightedColor; 37 Drawable removeDrawable; 38 RemoveView(Context context)39 public RemoveView(Context context) { 40 super(context); 41 } 42 RemoveView(Context context, AttributeSet attrs)43 public RemoveView(Context context, AttributeSet attrs) { 44 this(context, attrs, 0); 45 } 46 RemoveView(Context context, AttributeSet attrs, int defStyle)47 public RemoveView(Context context, AttributeSet attrs, int defStyle) { 48 super(context, attrs, defStyle); 49 } 50 51 @Override onFinishInflate()52 protected void onFinishInflate() { 53 removeText = (TextView) findViewById(R.id.remove_view_text); 54 removeIcon = (ImageView) findViewById(R.id.remove_view_icon); 55 final Resources r = getResources(); 56 unhighlightedColor = r.getColor(android.R.color.white); 57 highlightedColor = r.getColor(R.color.remove_highlighted_text_color); 58 removeDrawable = r.getDrawable(R.drawable.ic_remove); 59 } 60 setDragDropController(DragDropController controller)61 public void setDragDropController(DragDropController controller) { 62 dragDropController = controller; 63 } 64 65 @Override onDragEvent(DragEvent event)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(a bug). 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 (dragDropController != null) { 80 dragDropController.handleDragHovered(this, (int) event.getX(), (int) event.getY()); 81 } 82 break; 83 case DragEvent.ACTION_DROP: 84 sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT); 85 if (dragDropController != null) { 86 dragDropController.handleDragFinished((int) event.getX(), (int) event.getY(), true); 87 } 88 setAppearanceNormal(); 89 break; 90 } 91 return true; 92 } 93 setAppearanceNormal()94 private void setAppearanceNormal() { 95 removeText.setTextColor(unhighlightedColor); 96 removeIcon.setColorFilter(unhighlightedColor); 97 invalidate(); 98 } 99 setAppearanceHighlighted()100 private void setAppearanceHighlighted() { 101 removeText.setTextColor(highlightedColor); 102 removeIcon.setColorFilter(highlightedColor); 103 invalidate(); 104 } 105 } 106