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.content.res.Configuration;
21import android.util.AttributeSet;
22import android.view.View;
23
24import com.android.systemui.R;
25import com.android.systemui.statusbar.stack.ExpandableViewState;
26import com.android.systemui.statusbar.stack.StackScrollState;
27
28public class DismissView extends StackScrollerDecorView {
29    private final int mClearAllTopPadding;
30    private DismissViewButton mDismissButton;
31
32    public DismissView(Context context, AttributeSet attrs) {
33        super(context, attrs);
34        mClearAllTopPadding = context.getResources().getDimensionPixelSize(
35                R.dimen.clear_all_padding_top);
36    }
37
38    @Override
39    protected View findContentView() {
40        return findViewById(R.id.dismiss_text);
41    }
42
43    @Override
44    protected void onFinishInflate() {
45        super.onFinishInflate();
46        mDismissButton = (DismissViewButton) findContentView();
47    }
48
49    public void setOnButtonClickListener(OnClickListener listener) {
50        mContent.setOnClickListener(listener);
51    }
52
53    public boolean isOnEmptySpace(float touchX, float touchY) {
54        return touchX < mContent.getX()
55                || touchX > mContent.getX() + mContent.getWidth()
56                || touchY < mContent.getY()
57                || touchY > mContent.getY() + mContent.getHeight();
58    }
59
60    @Override
61    protected void onConfigurationChanged(Configuration newConfig) {
62        super.onConfigurationChanged(newConfig);
63        mDismissButton.setText(R.string.clear_all_notifications_text);
64        mDismissButton.setContentDescription(
65                mContext.getString(R.string.accessibility_clear_all));
66    }
67
68    public boolean isButtonVisible() {
69        return mDismissButton.getAlpha() != 0.0f;
70    }
71
72    @Override
73    public ExpandableViewState createNewViewState(StackScrollState stackScrollState) {
74        return new DismissViewState();
75    }
76
77    public class DismissViewState extends ExpandableViewState {
78        @Override
79        public void applyToView(View view) {
80            super.applyToView(view);
81            if (view instanceof DismissView) {
82                DismissView dismissView = (DismissView) view;
83                boolean visible = this.clipTopAmount < mClearAllTopPadding;
84                dismissView.performVisibilityAnimation(visible && !dismissView.willBeGone());
85            }
86        }
87    }
88}
89