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.notification.row;
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.notification.stack.ExpandableViewState;
27 
28 public class FooterView extends StackScrollerDecorView {
29     private final int mClearAllTopPadding;
30     private FooterViewButton mDismissButton;
31     private FooterViewButton mManageButton;
32     private boolean mShowHistory;
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 
showHistory(boolean showHistory)76     public void showHistory(boolean showHistory) {
77         mShowHistory = showHistory;
78         if (mShowHistory) {
79             mManageButton.setText(R.string.manage_notifications_history_text);
80             mManageButton.setContentDescription(
81                     mContext.getString(R.string.manage_notifications_history_text));
82         } else {
83             mManageButton.setText(R.string.manage_notifications_text);
84             mManageButton.setContentDescription(
85                     mContext.getString(R.string.manage_notifications_text));
86         }
87     }
88 
isHistoryShown()89     public boolean isHistoryShown() {
90         return mShowHistory;
91     }
92 
93     @Override
onConfigurationChanged(Configuration newConfig)94     protected void onConfigurationChanged(Configuration newConfig) {
95         super.onConfigurationChanged(newConfig);
96         mDismissButton.setText(R.string.clear_all_notifications_text);
97         mDismissButton.setContentDescription(
98                 mContext.getString(R.string.accessibility_clear_all));
99         showHistory(mShowHistory);
100     }
101 
isButtonVisible()102     public boolean isButtonVisible() {
103         return mManageButton.getAlpha() != 0.0f;
104     }
105 
106     @Override
createExpandableViewState()107     public ExpandableViewState createExpandableViewState() {
108         return new FooterViewState();
109     }
110 
111     public class FooterViewState extends ExpandableViewState {
112         @Override
applyToView(View view)113         public void applyToView(View view) {
114             super.applyToView(view);
115             if (view instanceof FooterView) {
116                 FooterView footerView = (FooterView) view;
117                 boolean visible = this.clipTopAmount < mClearAllTopPadding;
118                 footerView.setContentVisible(visible && footerView.isVisible());
119             }
120         }
121     }
122 }
123