• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static com.android.internal.util.Preconditions.checkNotNull;
20 
21 import android.annotation.Nullable;
22 import android.content.Context;
23 import android.graphics.RectF;
24 import android.util.AttributeSet;
25 import android.view.LayoutInflater;
26 import android.view.MotionEvent;
27 import android.view.View;
28 import android.view.ViewGroup;
29 import android.widget.ImageView;
30 import android.widget.TextView;
31 
32 import com.android.systemui.R;
33 import com.android.systemui.statusbar.notification.row.ActivatableNotificationView;
34 
35 /**
36  * Similar in size and appearance to the NotificationShelf, appears at the beginning of some
37  * notification sections. Currently only used for gentle notifications.
38  */
39 public class SectionHeaderView extends ActivatableNotificationView {
40     private ViewGroup mContents;
41     private TextView mLabelView;
42     private ImageView mClearAllButton;
43     @Nullable private View.OnClickListener mOnClearClickListener = null;
44 
45     private final RectF mTmpRect = new RectF();
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         super.onFinishInflate();
54         mContents = checkNotNull(findViewById(R.id.content));
55         bindContents();
56     }
57 
bindContents()58     private void bindContents() {
59         mLabelView = checkNotNull(findViewById(R.id.header_label));
60         mClearAllButton = checkNotNull(findViewById(R.id.btn_clear_all));
61         if (mOnClearClickListener != null) {
62             mClearAllButton.setOnClickListener(mOnClearClickListener);
63         }
64     }
65 
66     @Override
getContentView()67     protected View getContentView() {
68         return mContents;
69     }
70 
71     /**
72      * Destroys and reinflates the visible contents of the section header. For use on configuration
73      * changes or any other time that layout values might need to be re-evaluated.
74      *
75      * Does not reinflate the base content view itself ({@link #getContentView()} or any of the
76      * decorator views, such as the background view or shadow view.
77      */
reinflateContents()78     void reinflateContents() {
79         mContents.removeAllViews();
80         LayoutInflater.from(getContext()).inflate(
81                 R.layout.status_bar_notification_section_header_contents,
82                 mContents);
83         bindContents();
84     }
85 
86     /** Must be called whenever the UI mode changes (i.e. when we enter night mode). */
onUiModeChanged()87     void onUiModeChanged() {
88         updateBackgroundColors();
89         mLabelView.setTextColor(
90                 getContext().getColor(R.color.notification_section_header_label_color));
91         mClearAllButton.setImageResource(
92                 R.drawable.status_bar_notification_section_header_clear_btn);
93     }
94 
setAreThereDismissableGentleNotifs(boolean areThereDismissableGentleNotifs)95     void setAreThereDismissableGentleNotifs(boolean areThereDismissableGentleNotifs) {
96         mClearAllButton.setVisibility(areThereDismissableGentleNotifs ? View.VISIBLE : View.GONE);
97     }
98 
99     @Override
disallowSingleClick(MotionEvent event)100     protected boolean disallowSingleClick(MotionEvent event) {
101         // Disallow single click on lockscreen if user is tapping on clear all button
102         mTmpRect.set(
103                 mClearAllButton.getLeft(),
104                 mClearAllButton.getTop(),
105                 mClearAllButton.getLeft() + mClearAllButton.getWidth(),
106                 mClearAllButton.getTop() + mClearAllButton.getHeight());
107         return mTmpRect.contains(event.getX(), event.getY());
108     }
109 
110     /**
111      * Fired whenever the user clicks on the body of the header (e.g. no sub-buttons or anything).
112      */
setOnHeaderClickListener(View.OnClickListener listener)113     void setOnHeaderClickListener(View.OnClickListener listener) {
114         mContents.setOnClickListener(listener);
115     }
116 
117     /** Fired when the user clicks on the "X" button on the far right of the header. */
setOnClearAllClickListener(View.OnClickListener listener)118     void setOnClearAllClickListener(View.OnClickListener listener) {
119         mOnClearClickListener = listener;
120         mClearAllButton.setOnClickListener(listener);
121     }
122 }
123