1 /* 2 * Copyright (C) 2019 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.stack; 18 19 import android.annotation.ColorInt; 20 import android.annotation.Nullable; 21 import android.annotation.StringRes; 22 import android.content.Context; 23 import android.content.res.ColorStateList; 24 import android.util.AttributeSet; 25 import android.view.MotionEvent; 26 import android.view.View; 27 import android.view.ViewGroup; 28 import android.widget.ImageView; 29 import android.widget.TextView; 30 31 import com.android.systemui.R; 32 import com.android.systemui.statusbar.notification.row.StackScrollerDecorView; 33 34 /** 35 * Header displayed above a notification section in the shade. Currently used for Alerting and 36 * Silent sections. 37 */ 38 public class SectionHeaderView extends StackScrollerDecorView { 39 40 private ViewGroup mContents; 41 private TextView mLabelView; 42 private ImageView mClearAllButton; 43 @StringRes @Nullable private Integer mLabelTextId; 44 @Nullable private View.OnClickListener mLabelClickListener = null; 45 @Nullable private View.OnClickListener mOnClearClickListener = null; 46 SectionHeaderView(Context context, AttributeSet attrs)47 public SectionHeaderView(Context context, AttributeSet attrs) { 48 super(context, attrs); 49 } 50 51 @Override onFinishInflate()52 protected void onFinishInflate() { 53 mContents = requireViewById(R.id.content); 54 bindContents(); 55 super.onFinishInflate(); 56 setVisible(true /* nowVisible */, false /* animate */); 57 } 58 bindContents()59 private void bindContents() { 60 mLabelView = requireViewById(R.id.header_label); 61 mClearAllButton = requireViewById(R.id.btn_clear_all); 62 if (mOnClearClickListener != null) { 63 mClearAllButton.setOnClickListener(mOnClearClickListener); 64 } 65 if (mLabelClickListener != null) { 66 mLabelView.setOnClickListener(mLabelClickListener); 67 } 68 if (mLabelTextId != null) { 69 mLabelView.setText(mLabelTextId); 70 } 71 } 72 73 @Override findContentView()74 protected View findContentView() { 75 return mContents; 76 } 77 78 @Override findSecondaryView()79 protected View findSecondaryView() { 80 return null; 81 } 82 83 @Override isTransparent()84 public boolean isTransparent() { 85 return true; 86 } 87 setAreThereDismissableGentleNotifs(boolean areThereDismissableGentleNotifs)88 void setAreThereDismissableGentleNotifs(boolean areThereDismissableGentleNotifs) { 89 mClearAllButton.setVisibility(areThereDismissableGentleNotifs ? View.VISIBLE : View.GONE); 90 } 91 92 @Override onInterceptTouchEvent(MotionEvent ev)93 public boolean onInterceptTouchEvent(MotionEvent ev) { 94 return super.onInterceptTouchEvent(ev); 95 } 96 97 /** 98 * Fired whenever the user clicks on the body of the header (e.g. no sub-buttons or anything). 99 */ setOnHeaderClickListener(View.OnClickListener listener)100 void setOnHeaderClickListener(View.OnClickListener listener) { 101 mLabelClickListener = listener; 102 mLabelView.setOnClickListener(listener); 103 } 104 105 @Override applyContentTransformation(float contentAlpha, float translationY)106 protected void applyContentTransformation(float contentAlpha, float translationY) { 107 super.applyContentTransformation(contentAlpha, translationY); 108 mLabelView.setAlpha(contentAlpha); 109 mLabelView.setTranslationY(translationY); 110 mClearAllButton.setAlpha(contentAlpha); 111 mClearAllButton.setTranslationY(translationY); 112 } 113 114 /** Fired when the user clicks on the "X" button on the far right of the header. */ setOnClearAllClickListener(View.OnClickListener listener)115 void setOnClearAllClickListener(View.OnClickListener listener) { 116 mOnClearClickListener = listener; 117 mClearAllButton.setOnClickListener(listener); 118 } 119 120 @Override needsClippingToShelf()121 public boolean needsClippingToShelf() { 122 return true; 123 } 124 setHeaderText(@tringRes int resId)125 void setHeaderText(@StringRes int resId) { 126 mLabelTextId = resId; 127 mLabelView.setText(resId); 128 } 129 setForegroundColor(@olorInt int color)130 void setForegroundColor(@ColorInt int color) { 131 mLabelView.setTextColor(color); 132 mClearAllButton.setImageTintList(ColorStateList.valueOf(color)); 133 } 134 } 135