1/*
2 * Copyright (C) 2014 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.systemui.statusbar;
18
19import android.content.Context;
20import android.graphics.Rect;
21import android.util.AttributeSet;
22import android.view.ViewGroup;
23
24import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
25
26public class DismissViewButton extends AlphaOptimizedButton {
27
28    public DismissViewButton(Context context) {
29        this(context, null);
30    }
31
32    public DismissViewButton(Context context, AttributeSet attrs) {
33        this(context, attrs, 0);
34    }
35
36    public DismissViewButton(Context context, AttributeSet attrs, int defStyleAttr) {
37        this(context, attrs, defStyleAttr, 0);
38    }
39
40    public DismissViewButton(Context context, AttributeSet attrs, int defStyleAttr,
41            int defStyleRes) {
42        super(context, attrs, defStyleAttr, defStyleRes);
43    }
44
45    /**
46     * This method returns the drawing rect for the view which is different from the regular
47     * drawing rect, since we layout all children in the {@link NotificationStackScrollLayout} at
48     * position 0 and usually the translation is neglected. The standard implementation doesn't
49     * account for translation.
50     *
51     * @param outRect The (scrolled) drawing bounds of the view.
52     */
53    @Override
54    public void getDrawingRect(Rect outRect) {
55        super.getDrawingRect(outRect);
56        float translationX = ((ViewGroup) mParent).getTranslationX();
57        float translationY = ((ViewGroup) mParent).getTranslationY();
58        outRect.left += translationX;
59        outRect.right += translationX;
60        outRect.top += translationY;
61        outRect.bottom += translationY;
62    }
63}
64