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