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