• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.content.res.Resources;
23 import android.util.AttributeSet;
24 import android.view.View;
25 
26 import com.android.systemui.R;
27 import com.android.systemui.statusbar.notification.stack.ExpandableViewState;
28 import com.android.systemui.statusbar.notification.stack.ViewState;
29 
30 public class FooterView extends StackScrollerDecorView {
31     private final int mClearAllTopPadding;
32     private FooterViewButton mDismissButton;
33     private FooterViewButton mManageButton;
34     private boolean mShowHistory;
35 
FooterView(Context context, AttributeSet attrs)36     public FooterView(Context context, AttributeSet attrs) {
37         super(context, attrs);
38         mClearAllTopPadding = context.getResources().getDimensionPixelSize(
39                 R.dimen.clear_all_padding_top);
40     }
41 
42     @Override
findContentView()43     protected View findContentView() {
44         return findViewById(R.id.content);
45     }
46 
findSecondaryView()47     protected View findSecondaryView() {
48         return findViewById(R.id.dismiss_text);
49     }
50 
51     @Override
onFinishInflate()52     protected void onFinishInflate() {
53         super.onFinishInflate();
54         mDismissButton = (FooterViewButton) findSecondaryView();
55         mManageButton = findViewById(R.id.manage_text);
56     }
57 
setTextColor(@olorInt int color)58     public void setTextColor(@ColorInt int color) {
59         mManageButton.setTextColor(color);
60         mDismissButton.setTextColor(color);
61     }
62 
setManageButtonClickListener(OnClickListener listener)63     public void setManageButtonClickListener(OnClickListener listener) {
64         mManageButton.setOnClickListener(listener);
65     }
66 
setDismissButtonClickListener(OnClickListener listener)67     public void setDismissButtonClickListener(OnClickListener listener) {
68         mDismissButton.setOnClickListener(listener);
69     }
70 
isOnEmptySpace(float touchX, float touchY)71     public boolean isOnEmptySpace(float touchX, float touchY) {
72         return touchX < mContent.getX()
73                 || touchX > mContent.getX() + mContent.getWidth()
74                 || touchY < mContent.getY()
75                 || touchY > mContent.getY() + mContent.getHeight();
76     }
77 
showHistory(boolean showHistory)78     public void showHistory(boolean showHistory) {
79         mShowHistory = showHistory;
80         if (mShowHistory) {
81             mManageButton.setText(R.string.manage_notifications_history_text);
82             mManageButton.setContentDescription(
83                     mContext.getString(R.string.manage_notifications_history_text));
84         } else {
85             mManageButton.setText(R.string.manage_notifications_text);
86             mManageButton.setContentDescription(
87                     mContext.getString(R.string.manage_notifications_text));
88         }
89     }
90 
isHistoryShown()91     public boolean isHistoryShown() {
92         return mShowHistory;
93     }
94 
95     @Override
onConfigurationChanged(Configuration newConfig)96     protected void onConfigurationChanged(Configuration newConfig) {
97         super.onConfigurationChanged(newConfig);
98         int textColor = getResources().getColor(R.color.notif_pill_text);
99         Resources.Theme theme = getContext().getTheme();
100         mDismissButton.setBackground(
101                 getResources().getDrawable(R.drawable.notif_footer_btn_background, theme));
102         mDismissButton.setTextColor(textColor);
103         mManageButton.setBackground(
104                 getResources().getDrawable(R.drawable.notif_footer_btn_background, theme));
105         mManageButton = findViewById(R.id.manage_text);
106         mDismissButton.setText(R.string.clear_all_notifications_text);
107         mManageButton.setTextColor(textColor);
108         mDismissButton.setContentDescription(
109                 mContext.getString(R.string.accessibility_clear_all));
110         showHistory(mShowHistory);
111     }
112 
113     @Override
createExpandableViewState()114     public ExpandableViewState createExpandableViewState() {
115         return new FooterViewState();
116     }
117 
118     public class FooterViewState extends ExpandableViewState {
119         /**
120          * used to hide the content of the footer to animate.
121          * #hide is applied without animation, but #hideContent has animation.
122          */
123         public boolean hideContent;
124 
125         @Override
copyFrom(ViewState viewState)126         public void copyFrom(ViewState viewState) {
127             super.copyFrom(viewState);
128             if (viewState instanceof FooterViewState) {
129                 hideContent = ((FooterViewState) viewState).hideContent;
130             }
131         }
132 
133         @Override
applyToView(View view)134         public void applyToView(View view) {
135             super.applyToView(view);
136             if (view instanceof FooterView) {
137                 FooterView footerView = (FooterView) view;
138                 footerView.setContentVisible(!hideContent);
139             }
140         }
141     }
142 }
143