1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.systemui.statusbar.notification.row;
import android.annotation.ColorInt;
import android.annotation.DrawableRes;
import android.annotation.StringRes;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.IndentingPrintWriter;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.android.settingslib.Utils;
import com.android.systemui.R;
import com.android.systemui.statusbar.notification.stack.ExpandableViewState;
import com.android.systemui.statusbar.notification.stack.ViewState;
import com.android.systemui.util.DumpUtilsKt;
import java.io.PrintWriter;
public class FooterView extends StackScrollerDecorView {
private FooterViewButton mClearAllButton;
private FooterViewButton mManageButton;
private boolean mShowHistory;
// String cache, for performance reasons.
// Reading them from a Resources object can be quite slow sometimes.
private String mManageNotificationText;
private String mManageNotificationHistoryText;
// Footer label
private TextView mSeenNotifsFooterTextView;
private @StringRes int mSeenNotifsFilteredText;
private int mUnlockIconSize;
public FooterView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected View findContentView() {
return findViewById(R.id.content);
}
protected View findSecondaryView() {
return findViewById(R.id.dismiss_text);
}
@Override
public void dump(PrintWriter pwOriginal, String[] args) {
IndentingPrintWriter pw = DumpUtilsKt.asIndenting(pwOriginal);
super.dump(pw, args);
DumpUtilsKt.withIncreasedIndent(pw, () -> {
pw.println("visibility: " + DumpUtilsKt.visibilityString(getVisibility()));
pw.println("manageButton showHistory: " + mShowHistory);
pw.println("manageButton visibility: "
+ DumpUtilsKt.visibilityString(mClearAllButton.getVisibility()));
pw.println("dismissButton visibility: "
+ DumpUtilsKt.visibilityString(mClearAllButton.getVisibility()));
});
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mClearAllButton = (FooterViewButton) findSecondaryView();
mManageButton = findViewById(R.id.manage_text);
mSeenNotifsFooterTextView = findViewById(R.id.unlock_prompt_footer);
updateResources();
updateText();
updateColors();
}
public void setFooterLabelTextAndIcon(@StringRes int text, @DrawableRes int icon) {
mSeenNotifsFilteredText = text;
if (mSeenNotifsFilteredText != 0) {
mSeenNotifsFooterTextView.setText(mSeenNotifsFilteredText);
} else {
mSeenNotifsFooterTextView.setText(null);
}
Drawable drawable;
if (icon == 0) {
drawable = null;
} else {
drawable = getResources().getDrawable(icon);
drawable.setBounds(0, 0, mUnlockIconSize, mUnlockIconSize);
}
mSeenNotifsFooterTextView.setCompoundDrawablesRelative(drawable, null, null, null);
updateFooterVisibilityMode();
}
private void updateFooterVisibilityMode() {
if (mSeenNotifsFilteredText != 0) {
mManageButton.setVisibility(View.GONE);
mClearAllButton.setVisibility(View.GONE);
mSeenNotifsFooterTextView.setVisibility(View.VISIBLE);
} else {
mManageButton.setVisibility(View.VISIBLE);
mClearAllButton.setVisibility(View.VISIBLE);
mSeenNotifsFooterTextView.setVisibility(View.GONE);
}
}
public void setManageButtonClickListener(OnClickListener listener) {
mManageButton.setOnClickListener(listener);
}
public void setClearAllButtonClickListener(OnClickListener listener) {
mClearAllButton.setOnClickListener(listener);
}
public boolean isOnEmptySpace(float touchX, float touchY) {
return touchX < mContent.getX()
|| touchX > mContent.getX() + mContent.getWidth()
|| touchY < mContent.getY()
|| touchY > mContent.getY() + mContent.getHeight();
}
public void showHistory(boolean showHistory) {
if (mShowHistory == showHistory) {
return;
}
mShowHistory = showHistory;
updateText();
}
private void updateText() {
if (mShowHistory) {
mManageButton.setText(mManageNotificationHistoryText);
mManageButton.setContentDescription(mManageNotificationHistoryText);
} else {
mManageButton.setText(mManageNotificationText);
mManageButton.setContentDescription(mManageNotificationText);
}
}
public boolean isHistoryShown() {
return mShowHistory;
}
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
updateColors();
mClearAllButton.setText(R.string.clear_all_notifications_text);
mClearAllButton.setContentDescription(
mContext.getString(R.string.accessibility_clear_all));
updateResources();
updateText();
}
/**
* Update the text and background colors for the current color palette and night mode setting.
*/
public void updateColors() {
Resources.Theme theme = mContext.getTheme();
int textColor = getResources().getColor(R.color.notif_pill_text, theme);
mClearAllButton.setBackground(theme.getDrawable(R.drawable.notif_footer_btn_background));
mClearAllButton.setTextColor(textColor);
mManageButton.setBackground(theme.getDrawable(R.drawable.notif_footer_btn_background));
mManageButton.setTextColor(textColor);
final @ColorInt int labelTextColor =
Utils.getColorAttrDefaultColor(mContext, android.R.attr.textColorPrimary);
mSeenNotifsFooterTextView.setTextColor(labelTextColor);
mSeenNotifsFooterTextView.setCompoundDrawableTintList(
ColorStateList.valueOf(labelTextColor));
}
private void updateResources() {
mManageNotificationText = getContext().getString(R.string.manage_notifications_text);
mManageNotificationHistoryText = getContext()
.getString(R.string.manage_notifications_history_text);
mUnlockIconSize = getResources()
.getDimensionPixelSize(R.dimen.notifications_unseen_footer_icon_size);
}
@Override
@NonNull
public ExpandableViewState createExpandableViewState() {
return new FooterViewState();
}
public class FooterViewState extends ExpandableViewState {
/**
* used to hide the content of the footer to animate.
* #hide is applied without animation, but #hideContent has animation.
*/
public boolean hideContent;
@Override
public void copyFrom(ViewState viewState) {
super.copyFrom(viewState);
if (viewState instanceof FooterViewState) {
hideContent = ((FooterViewState) viewState).hideContent;
}
}
@Override
public void applyToView(View view) {
super.applyToView(view);
if (view instanceof FooterView) {
FooterView footerView = (FooterView) view;
footerView.setContentVisible(!hideContent);
}
}
}
}
|