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.content.Context;
20 import android.content.res.Configuration;
21 import android.content.res.Resources;
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 import com.android.systemui.statusbar.notification.stack.ViewState;
28 import com.android.systemui.util.DumpUtilsKt;
29 
30 import java.io.FileDescriptor;
31 import java.io.PrintWriter;
32 
33 public class FooterView extends StackScrollerDecorView {
34     private FooterViewButton mDismissButton;
35     private FooterViewButton mManageButton;
36     private boolean mShowHistory;
37 
FooterView(Context context, AttributeSet attrs)38     public FooterView(Context context, AttributeSet attrs) {
39         super(context, attrs);
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
dump(FileDescriptor fd, PrintWriter pw, String[] args)52     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
53         super.dump(fd, pw, args);
54         DumpUtilsKt.withIndenting(pw, ipw -> {
55             ipw.println("visibility: " + DumpUtilsKt.visibilityString(getVisibility()));
56             ipw.println("manageButton showHistory: " + mShowHistory);
57             ipw.println("manageButton visibility: "
58                     + DumpUtilsKt.visibilityString(mDismissButton.getVisibility()));
59             ipw.println("dismissButton visibility: "
60                     + DumpUtilsKt.visibilityString(mDismissButton.getVisibility()));
61         });
62     }
63 
64     @Override
onFinishInflate()65     protected void onFinishInflate() {
66         super.onFinishInflate();
67         mDismissButton = (FooterViewButton) findSecondaryView();
68         mManageButton = findViewById(R.id.manage_text);
69     }
70 
setManageButtonClickListener(OnClickListener listener)71     public void setManageButtonClickListener(OnClickListener listener) {
72         mManageButton.setOnClickListener(listener);
73     }
74 
setDismissButtonClickListener(OnClickListener listener)75     public void setDismissButtonClickListener(OnClickListener listener) {
76         mDismissButton.setOnClickListener(listener);
77     }
78 
isOnEmptySpace(float touchX, float touchY)79     public boolean isOnEmptySpace(float touchX, float touchY) {
80         return touchX < mContent.getX()
81                 || touchX > mContent.getX() + mContent.getWidth()
82                 || touchY < mContent.getY()
83                 || touchY > mContent.getY() + mContent.getHeight();
84     }
85 
showHistory(boolean showHistory)86     public void showHistory(boolean showHistory) {
87         mShowHistory = showHistory;
88         if (mShowHistory) {
89             mManageButton.setText(R.string.manage_notifications_history_text);
90             mManageButton.setContentDescription(
91                     mContext.getString(R.string.manage_notifications_history_text));
92         } else {
93             mManageButton.setText(R.string.manage_notifications_text);
94             mManageButton.setContentDescription(
95                     mContext.getString(R.string.manage_notifications_text));
96         }
97     }
98 
isHistoryShown()99     public boolean isHistoryShown() {
100         return mShowHistory;
101     }
102 
103     @Override
onConfigurationChanged(Configuration newConfig)104     protected void onConfigurationChanged(Configuration newConfig) {
105         super.onConfigurationChanged(newConfig);
106         updateColors();
107         mDismissButton.setText(R.string.clear_all_notifications_text);
108         mDismissButton.setContentDescription(
109                 mContext.getString(R.string.accessibility_clear_all));
110         showHistory(mShowHistory);
111     }
112 
113     /**
114      * Update the text and background colors for the current color palette and night mode setting.
115      */
updateColors()116     public void updateColors() {
117         Resources.Theme theme = mContext.getTheme();
118         int textColor = getResources().getColor(R.color.notif_pill_text, theme);
119         mDismissButton.setBackground(theme.getDrawable(R.drawable.notif_footer_btn_background));
120         mDismissButton.setTextColor(textColor);
121         mManageButton.setBackground(theme.getDrawable(R.drawable.notif_footer_btn_background));
122         mManageButton.setTextColor(textColor);
123     }
124 
125     @Override
createExpandableViewState()126     public ExpandableViewState createExpandableViewState() {
127         return new FooterViewState();
128     }
129 
130     public class FooterViewState extends ExpandableViewState {
131         /**
132          * used to hide the content of the footer to animate.
133          * #hide is applied without animation, but #hideContent has animation.
134          */
135         public boolean hideContent;
136 
137         @Override
copyFrom(ViewState viewState)138         public void copyFrom(ViewState viewState) {
139             super.copyFrom(viewState);
140             if (viewState instanceof FooterViewState) {
141                 hideContent = ((FooterViewState) viewState).hideContent;
142             }
143         }
144 
145         @Override
applyToView(View view)146         public void applyToView(View view) {
147             super.applyToView(view);
148             if (view instanceof FooterView) {
149                 FooterView footerView = (FooterView) view;
150                 footerView.setContentVisible(!hideContent);
151             }
152         }
153     }
154 }
155