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 
17 package com.android.systemui.statusbar;
18 
19 import android.annotation.ColorInt;
20 import android.content.Context;
21 import android.content.res.Configuration;
22 import android.util.AttributeSet;
23 import android.view.View;
24 
25 import com.android.systemui.R;
26 import com.android.systemui.statusbar.stack.ExpandableViewState;
27 import com.android.systemui.statusbar.stack.StackScrollState;
28 
29 public class FooterView extends StackScrollerDecorView {
30     private final int mClearAllTopPadding;
31     private FooterViewButton mDismissButton;
32     private FooterViewButton mManageButton;
33 
FooterView(Context context, AttributeSet attrs)34     public FooterView(Context context, AttributeSet attrs) {
35         super(context, attrs);
36         mClearAllTopPadding = context.getResources().getDimensionPixelSize(
37                 R.dimen.clear_all_padding_top);
38     }
39 
40     @Override
findContentView()41     protected View findContentView() {
42         return findViewById(R.id.content);
43     }
44 
findSecondaryView()45     protected View findSecondaryView() {
46         return findViewById(R.id.dismiss_text);
47     }
48 
49     @Override
onFinishInflate()50     protected void onFinishInflate() {
51         super.onFinishInflate();
52         mDismissButton = (FooterViewButton) findSecondaryView();
53         mManageButton = findViewById(R.id.manage_text);
54     }
55 
setTextColor(@olorInt int color)56     public void setTextColor(@ColorInt int color) {
57         mManageButton.setTextColor(color);
58         mDismissButton.setTextColor(color);
59     }
60 
setManageButtonClickListener(OnClickListener listener)61     public void setManageButtonClickListener(OnClickListener listener) {
62         mManageButton.setOnClickListener(listener);
63     }
64 
setDismissButtonClickListener(OnClickListener listener)65     public void setDismissButtonClickListener(OnClickListener listener) {
66         mDismissButton.setOnClickListener(listener);
67     }
68 
isOnEmptySpace(float touchX, float touchY)69     public boolean isOnEmptySpace(float touchX, float touchY) {
70         return touchX < mContent.getX()
71                 || touchX > mContent.getX() + mContent.getWidth()
72                 || touchY < mContent.getY()
73                 || touchY > mContent.getY() + mContent.getHeight();
74     }
75 
76     @Override
onConfigurationChanged(Configuration newConfig)77     protected void onConfigurationChanged(Configuration newConfig) {
78         super.onConfigurationChanged(newConfig);
79         mDismissButton.setText(R.string.clear_all_notifications_text);
80         mDismissButton.setContentDescription(
81                 mContext.getString(R.string.accessibility_clear_all));
82         mManageButton.setText(R.string.manage_notifications_text);
83     }
84 
isButtonVisible()85     public boolean isButtonVisible() {
86         return mManageButton.getAlpha() != 0.0f;
87     }
88 
89     @Override
createNewViewState(StackScrollState stackScrollState)90     public ExpandableViewState createNewViewState(StackScrollState stackScrollState) {
91         return new FooterViewState();
92     }
93 
94     public class FooterViewState extends ExpandableViewState {
95         @Override
applyToView(View view)96         public void applyToView(View view) {
97             super.applyToView(view);
98             if (view instanceof FooterView) {
99                 FooterView footerView = (FooterView) view;
100                 boolean visible = this.clipTopAmount < mClearAllTopPadding;
101                 footerView.setContentVisible(visible && footerView.isVisible());
102             }
103         }
104     }
105 }
106