1e9bad242f38bebadae481a22b647cc153f093070Selim Cinek/* 2e9bad242f38bebadae481a22b647cc153f093070Selim Cinek * Copyright (C) 2016 The Android Open Source Project 3e9bad242f38bebadae481a22b647cc153f093070Selim Cinek * 4e9bad242f38bebadae481a22b647cc153f093070Selim Cinek * Licensed under the Apache License, Version 2.0 (the "License"); 5e9bad242f38bebadae481a22b647cc153f093070Selim Cinek * you may not use this file except in compliance with the License. 6e9bad242f38bebadae481a22b647cc153f093070Selim Cinek * You may obtain a copy of the License at 7e9bad242f38bebadae481a22b647cc153f093070Selim Cinek * 8e9bad242f38bebadae481a22b647cc153f093070Selim Cinek * http://www.apache.org/licenses/LICENSE-2.0 9e9bad242f38bebadae481a22b647cc153f093070Selim Cinek * 10e9bad242f38bebadae481a22b647cc153f093070Selim Cinek * Unless required by applicable law or agreed to in writing, software 11e9bad242f38bebadae481a22b647cc153f093070Selim Cinek * distributed under the License is distributed on an "AS IS" BASIS, 12e9bad242f38bebadae481a22b647cc153f093070Selim Cinek * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e9bad242f38bebadae481a22b647cc153f093070Selim Cinek * See the License for the specific language governing permissions and 14e9bad242f38bebadae481a22b647cc153f093070Selim Cinek * limitations under the License 15e9bad242f38bebadae481a22b647cc153f093070Selim Cinek */ 16e9bad242f38bebadae481a22b647cc153f093070Selim Cinek 17e9bad242f38bebadae481a22b647cc153f093070Selim Cinekpackage com.android.internal.widget; 18e9bad242f38bebadae481a22b647cc153f093070Selim Cinek 19e9bad242f38bebadae481a22b647cc153f093070Selim Cinekimport android.annotation.Nullable; 20e9bad242f38bebadae481a22b647cc153f093070Selim Cinekimport android.content.Context; 21e9bad242f38bebadae481a22b647cc153f093070Selim Cinekimport android.graphics.Rect; 22e9bad242f38bebadae481a22b647cc153f093070Selim Cinekimport android.util.AttributeSet; 2369e76f96c2de0ff97bcea97beb562ddcbcda55a7Selim Cinekimport android.view.View; 24c0ac4af13bb18a516e26d2ddb94723ef9f970393Selim Cinekimport android.view.accessibility.AccessibilityNodeInfo; 25c0ac4af13bb18a516e26d2ddb94723ef9f970393Selim Cinekimport android.widget.Button; 26e9bad242f38bebadae481a22b647cc153f093070Selim Cinekimport android.widget.ImageView; 27e9bad242f38bebadae481a22b647cc153f093070Selim Cinekimport android.widget.RemoteViews; 28e9bad242f38bebadae481a22b647cc153f093070Selim Cinek 29e9bad242f38bebadae481a22b647cc153f093070Selim Cinek/** 30e9bad242f38bebadae481a22b647cc153f093070Selim Cinek * An expand button in a notification 31e9bad242f38bebadae481a22b647cc153f093070Selim Cinek */ 32e9bad242f38bebadae481a22b647cc153f093070Selim Cinek@RemoteViews.RemoteView 33e9bad242f38bebadae481a22b647cc153f093070Selim Cinekpublic class NotificationExpandButton extends ImageView { 3469e76f96c2de0ff97bcea97beb562ddcbcda55a7Selim Cinek 35e9bad242f38bebadae481a22b647cc153f093070Selim Cinek public NotificationExpandButton(Context context) { 36e9bad242f38bebadae481a22b647cc153f093070Selim Cinek super(context); 37e9bad242f38bebadae481a22b647cc153f093070Selim Cinek } 38e9bad242f38bebadae481a22b647cc153f093070Selim Cinek 39e9bad242f38bebadae481a22b647cc153f093070Selim Cinek public NotificationExpandButton(Context context, @Nullable AttributeSet attrs) { 40e9bad242f38bebadae481a22b647cc153f093070Selim Cinek super(context, attrs); 41e9bad242f38bebadae481a22b647cc153f093070Selim Cinek } 42e9bad242f38bebadae481a22b647cc153f093070Selim Cinek 43e9bad242f38bebadae481a22b647cc153f093070Selim Cinek public NotificationExpandButton(Context context, @Nullable AttributeSet attrs, 44e9bad242f38bebadae481a22b647cc153f093070Selim Cinek int defStyleAttr) { 45e9bad242f38bebadae481a22b647cc153f093070Selim Cinek super(context, attrs, defStyleAttr); 46e9bad242f38bebadae481a22b647cc153f093070Selim Cinek } 47e9bad242f38bebadae481a22b647cc153f093070Selim Cinek 48e9bad242f38bebadae481a22b647cc153f093070Selim Cinek public NotificationExpandButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr, 49e9bad242f38bebadae481a22b647cc153f093070Selim Cinek int defStyleRes) { 50e9bad242f38bebadae481a22b647cc153f093070Selim Cinek super(context, attrs, defStyleAttr, defStyleRes); 51e9bad242f38bebadae481a22b647cc153f093070Selim Cinek } 52e9bad242f38bebadae481a22b647cc153f093070Selim Cinek 53e9bad242f38bebadae481a22b647cc153f093070Selim Cinek @Override 54e9bad242f38bebadae481a22b647cc153f093070Selim Cinek public void getBoundsOnScreen(Rect outRect, boolean clipToParent) { 55e9bad242f38bebadae481a22b647cc153f093070Selim Cinek super.getBoundsOnScreen(outRect, clipToParent); 56e9bad242f38bebadae481a22b647cc153f093070Selim Cinek extendRectToMinTouchSize(outRect); 57e9bad242f38bebadae481a22b647cc153f093070Selim Cinek } 58e9bad242f38bebadae481a22b647cc153f093070Selim Cinek 59e9bad242f38bebadae481a22b647cc153f093070Selim Cinek private void extendRectToMinTouchSize(Rect rect) { 60e9bad242f38bebadae481a22b647cc153f093070Selim Cinek int touchTargetSize = (int) (getResources().getDisplayMetrics().density * 48); 61e9bad242f38bebadae481a22b647cc153f093070Selim Cinek rect.left = rect.centerX() - touchTargetSize / 2; 62e9bad242f38bebadae481a22b647cc153f093070Selim Cinek rect.right = rect.left + touchTargetSize; 63e9bad242f38bebadae481a22b647cc153f093070Selim Cinek rect.top = rect.centerY() - touchTargetSize / 2; 64e9bad242f38bebadae481a22b647cc153f093070Selim Cinek rect.bottom = rect.top + touchTargetSize; 65e9bad242f38bebadae481a22b647cc153f093070Selim Cinek } 66c0ac4af13bb18a516e26d2ddb94723ef9f970393Selim Cinek 67c0ac4af13bb18a516e26d2ddb94723ef9f970393Selim Cinek @Override 68c0ac4af13bb18a516e26d2ddb94723ef9f970393Selim Cinek public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { 69c0ac4af13bb18a516e26d2ddb94723ef9f970393Selim Cinek super.onInitializeAccessibilityNodeInfo(info); 70c0ac4af13bb18a516e26d2ddb94723ef9f970393Selim Cinek info.setClassName(Button.class.getName()); 71c0ac4af13bb18a516e26d2ddb94723ef9f970393Selim Cinek } 72e9bad242f38bebadae481a22b647cc153f093070Selim Cinek} 73