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;
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.graphics.drawable.Drawable;
26 import android.util.AttributeSet;
27 import android.view.View;
28 import android.widget.TextView;
29 
30 import androidx.annotation.NonNull;
31 
32 import com.android.systemui.res.R;
33 import com.android.systemui.statusbar.notification.row.StackScrollerDecorView;
34 import com.android.systemui.statusbar.notification.stack.ExpandableViewState;
35 
36 public class EmptyShadeView extends StackScrollerDecorView {
37 
38     private TextView mEmptyText;
39     private TextView mEmptyFooterText;
40 
41     private @StringRes int mText = R.string.empty_shade_text;
42 
43     private @DrawableRes int mFooterIcon = R.drawable.ic_friction_lock_closed;
44     private @StringRes int mFooterText = R.string.unlock_to_see_notif_text;
45     private @Visibility int mFooterVisibility = View.GONE;
46     private int mSize;
47 
EmptyShadeView(Context context, AttributeSet attrs)48     public EmptyShadeView(Context context, AttributeSet attrs) {
49         super(context, attrs);
50         mSize = getResources().getDimensionPixelSize(
51                 R.dimen.notifications_unseen_footer_icon_size);
52     }
53 
54     @Override
onConfigurationChanged(Configuration newConfig)55     protected void onConfigurationChanged(Configuration newConfig) {
56         super.onConfigurationChanged(newConfig);
57         mSize = getResources().getDimensionPixelSize(
58                 R.dimen.notifications_unseen_footer_icon_size);
59         mEmptyText.setText(mText);
60         mEmptyFooterText.setVisibility(mFooterVisibility);
61         setFooterText(mFooterText);
62         setFooterIcon(mFooterIcon);
63     }
64 
65     @Override
findContentView()66     protected View findContentView() {
67         return findViewById(R.id.no_notifications);
68     }
69 
70     @Override
findSecondaryView()71     protected View findSecondaryView() {
72         return findViewById(R.id.no_notifications_footer);
73     }
74 
setTextColors(@olorInt int onSurface, @ColorInt int onSurfaceVariant)75     public void setTextColors(@ColorInt int onSurface, @ColorInt int onSurfaceVariant) {
76         mEmptyText.setTextColor(onSurfaceVariant);
77         mEmptyFooterText.setTextColor(onSurface);
78         mEmptyFooterText.setCompoundDrawableTintList(ColorStateList.valueOf(onSurface));
79     }
80 
setText(@tringRes int text)81     public void setText(@StringRes int text) {
82         mText = text;
83         mEmptyText.setText(mText);
84     }
85 
setFooterVisibility(@isibility int visibility)86     public void setFooterVisibility(@Visibility int visibility) {
87         mFooterVisibility = visibility;
88         setSecondaryVisible(/* visible = */ visibility == View.VISIBLE,
89                 /* animate = */false,
90                 /* onAnimationEnded = */ null);
91     }
92 
setFooterText(@tringRes int text)93     public void setFooterText(@StringRes int text) {
94         mFooterText = text;
95         if (text != 0) {
96             mEmptyFooterText.setText(mFooterText);
97         } else {
98             mEmptyFooterText.setText(null);
99         }
100     }
101 
setFooterIcon(@rawableRes int icon)102     public void setFooterIcon(@DrawableRes int icon) {
103         mFooterIcon = icon;
104         Drawable drawable;
105         if (icon == 0) {
106             drawable = null;
107         } else {
108             drawable = getResources().getDrawable(icon);
109             drawable.setBounds(0, 0, mSize, mSize);
110         }
111         mEmptyFooterText.setCompoundDrawablesRelative(drawable, null, null, null);
112     }
113 
114     @StringRes
getTextResource()115     public int getTextResource() {
116         return mText;
117     }
118 
119     @StringRes
getFooterTextResource()120     public int getFooterTextResource() {
121         return mFooterText;
122     }
123 
124     @DrawableRes
getFooterIconResource()125     public int getFooterIconResource() {
126         return mFooterIcon;
127     }
128 
129     @Override
onFinishInflate()130     protected void onFinishInflate() {
131         super.onFinishInflate();
132         mEmptyText = (TextView) findContentView();
133         mEmptyFooterText = (TextView) findSecondaryView();
134         mEmptyFooterText.setCompoundDrawableTintList(mEmptyFooterText.getTextColors());
135     }
136 
137     @Override
138     @NonNull
createExpandableViewState()139     public ExpandableViewState createExpandableViewState() {
140         return new EmptyShadeViewState();
141     }
142 
143     public class EmptyShadeViewState extends ExpandableViewState {
144         @Override
applyToView(View view)145         public void applyToView(View view) {
146             super.applyToView(view);
147             if (view instanceof EmptyShadeView) {
148                 EmptyShadeView emptyShadeView = (EmptyShadeView) view;
149                 boolean visible = this.clipTopAmount <= mEmptyText.getPaddingTop() * 0.6f;
150                 emptyShadeView.setContentVisibleAnimated(visible && emptyShadeView.isVisible());
151             }
152         }
153     }
154 }
155