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.internal.widget; 18 19 import android.annotation.Nullable; 20 import android.content.Context; 21 import android.graphics.Rect; 22 import android.util.AttributeSet; 23 import android.view.RemotableViewMethod; 24 import android.view.accessibility.AccessibilityNodeInfo; 25 import android.widget.Button; 26 import android.widget.ImageView; 27 import android.widget.RemoteViews; 28 29 /** 30 * An expand button in a notification 31 */ 32 @RemoteViews.RemoteView 33 public class NotificationExpandButton extends ImageView { 34 35 private int mOriginalNotificationColor; 36 NotificationExpandButton(Context context)37 public NotificationExpandButton(Context context) { 38 super(context); 39 } 40 NotificationExpandButton(Context context, @Nullable AttributeSet attrs)41 public NotificationExpandButton(Context context, @Nullable AttributeSet attrs) { 42 super(context, attrs); 43 } 44 NotificationExpandButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr)45 public NotificationExpandButton(Context context, @Nullable AttributeSet attrs, 46 int defStyleAttr) { 47 super(context, attrs, defStyleAttr); 48 } 49 NotificationExpandButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes)50 public NotificationExpandButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr, 51 int defStyleRes) { 52 super(context, attrs, defStyleAttr, defStyleRes); 53 } 54 55 @Override getBoundsOnScreen(Rect outRect, boolean clipToParent)56 public void getBoundsOnScreen(Rect outRect, boolean clipToParent) { 57 super.getBoundsOnScreen(outRect, clipToParent); 58 extendRectToMinTouchSize(outRect); 59 } 60 61 @RemotableViewMethod setOriginalNotificationColor(int color)62 public void setOriginalNotificationColor(int color) { 63 mOriginalNotificationColor = color; 64 } 65 getOriginalNotificationColor()66 public int getOriginalNotificationColor() { 67 return mOriginalNotificationColor; 68 } 69 extendRectToMinTouchSize(Rect rect)70 private void extendRectToMinTouchSize(Rect rect) { 71 int touchTargetSize = (int) (getResources().getDisplayMetrics().density * 48); 72 rect.left = rect.centerX() - touchTargetSize / 2; 73 rect.right = rect.left + touchTargetSize; 74 rect.top = rect.centerY() - touchTargetSize / 2; 75 rect.bottom = rect.top + touchTargetSize; 76 } 77 78 @Override onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)79 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { 80 super.onInitializeAccessibilityNodeInfo(info); 81 info.setClassName(Button.class.getName()); 82 } 83 } 84