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