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.StringRes;
21 import android.content.Context;
22 import android.content.res.Configuration;
23 import android.util.AttributeSet;
24 import android.view.View;
25 import android.widget.TextView;
26 
27 import com.android.systemui.R;
28 import com.android.systemui.statusbar.notification.row.StackScrollerDecorView;
29 import com.android.systemui.statusbar.notification.stack.ExpandableViewState;
30 
31 public class EmptyShadeView extends StackScrollerDecorView {
32 
33     private TextView mEmptyText;
34     private @StringRes int mText = R.string.empty_shade_text;
35 
EmptyShadeView(Context context, AttributeSet attrs)36     public EmptyShadeView(Context context, AttributeSet attrs) {
37         super(context, attrs);
38     }
39 
40     @Override
onConfigurationChanged(Configuration newConfig)41     protected void onConfigurationChanged(Configuration newConfig) {
42         super.onConfigurationChanged(newConfig);
43         mEmptyText.setText(mText);
44     }
45 
46     @Override
findContentView()47     protected View findContentView() {
48         return findViewById(R.id.no_notifications);
49     }
50 
51     @Override
findSecondaryView()52     protected View findSecondaryView() {
53         return null;
54     }
55 
setTextColor(@olorInt int color)56     public void setTextColor(@ColorInt int color) {
57         mEmptyText.setTextColor(color);
58     }
59 
setText(@tringRes int text)60     public void setText(@StringRes int text) {
61         mText = text;
62         mEmptyText.setText(mText);
63     }
64 
getTextResource()65     public int getTextResource() {
66         return mText;
67     }
68 
69     @Override
onFinishInflate()70     protected void onFinishInflate() {
71         super.onFinishInflate();
72         mEmptyText = (TextView) findContentView();
73     }
74 
75     @Override
createExpandableViewState()76     public ExpandableViewState createExpandableViewState() {
77         return new EmptyShadeViewState();
78     }
79 
80     public class EmptyShadeViewState extends ExpandableViewState {
81         @Override
applyToView(View view)82         public void applyToView(View view) {
83             super.applyToView(view);
84             if (view instanceof EmptyShadeView) {
85                 EmptyShadeView emptyShadeView = (EmptyShadeView) view;
86                 boolean visible = this.clipTopAmount <= mEmptyText.getPaddingTop() * 0.6f;
87                 emptyShadeView.setContentVisible(visible && emptyShadeView.isVisible());
88             }
89         }
90     }
91 }
92