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.widget.ImageView;
24import android.widget.RemoteViews;
25
26/**
27 * An expand button in a notification
28 */
29@RemoteViews.RemoteView
30public class NotificationExpandButton extends ImageView {
31    public NotificationExpandButton(Context context) {
32        super(context);
33    }
34
35    public NotificationExpandButton(Context context, @Nullable AttributeSet attrs) {
36        super(context, attrs);
37    }
38
39    public NotificationExpandButton(Context context, @Nullable AttributeSet attrs,
40            int defStyleAttr) {
41        super(context, attrs, defStyleAttr);
42    }
43
44    public NotificationExpandButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
45            int defStyleRes) {
46        super(context, attrs, defStyleAttr, defStyleRes);
47    }
48
49    @Override
50    public void getBoundsOnScreen(Rect outRect, boolean clipToParent) {
51        super.getBoundsOnScreen(outRect, clipToParent);
52        extendRectToMinTouchSize(outRect);
53    }
54
55    private void extendRectToMinTouchSize(Rect rect) {
56        int touchTargetSize = (int) (getResources().getDisplayMetrics().density * 48);
57        rect.left = rect.centerX() - touchTargetSize / 2;
58        rect.right = rect.left + touchTargetSize;
59        rect.top = rect.centerY() - touchTargetSize / 2;
60        rect.bottom = rect.top + touchTargetSize;
61    }
62}
63