• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.app.Notification;
20 import android.content.Context;
21 import android.content.res.Resources;
22 import android.util.TypedValue;
23 import android.view.ContextThemeWrapper;
24 import android.view.LayoutInflater;
25 import android.view.ViewGroup;
26 import android.widget.TextView;
27 
28 import com.android.systemui.R;
29 import com.android.systemui.statusbar.notification.NotificationDozeHelper;
30 import com.android.systemui.statusbar.notification.NotificationUtils;
31 
32 /**
33  * A class managing hybrid groups that include {@link HybridNotificationView} and the notification
34  * group overflow.
35  */
36 public class HybridGroupManager {
37 
38     private final Context mContext;
39     private final ViewGroup mParent;
40 
41     private float mOverflowNumberSize;
42     private int mOverflowNumberPadding;
43 
44     private int mOverflowNumberColor;
45 
HybridGroupManager(Context ctx, ViewGroup parent)46     public HybridGroupManager(Context ctx, ViewGroup parent) {
47         mContext = ctx;
48         mParent = parent;
49         initDimens();
50     }
51 
initDimens()52     public void initDimens() {
53         Resources res = mContext.getResources();
54         mOverflowNumberSize = res.getDimensionPixelSize(
55                 R.dimen.group_overflow_number_size);
56         mOverflowNumberPadding = res.getDimensionPixelSize(
57                 R.dimen.group_overflow_number_padding);
58     }
59 
inflateHybridViewWithStyle(int style)60     private HybridNotificationView inflateHybridViewWithStyle(int style) {
61         LayoutInflater inflater = new ContextThemeWrapper(mContext, style)
62                 .getSystemService(LayoutInflater.class);
63         HybridNotificationView hybrid = (HybridNotificationView) inflater.inflate(
64                 R.layout.hybrid_notification, mParent, false);
65         mParent.addView(hybrid);
66         return hybrid;
67     }
68 
inflateOverflowNumber()69     private TextView inflateOverflowNumber() {
70         LayoutInflater inflater = mContext.getSystemService(LayoutInflater.class);
71         TextView numberView = (TextView) inflater.inflate(
72                 R.layout.hybrid_overflow_number, mParent, false);
73         mParent.addView(numberView);
74         updateOverFlowNumberColor(numberView);
75         return numberView;
76     }
77 
updateOverFlowNumberColor(TextView numberView)78     private void updateOverFlowNumberColor(TextView numberView) {
79         numberView.setTextColor(mOverflowNumberColor);
80     }
81 
setOverflowNumberColor(TextView numberView, int colorRegular)82     public void setOverflowNumberColor(TextView numberView, int colorRegular) {
83         mOverflowNumberColor = colorRegular;
84         if (numberView != null) {
85             updateOverFlowNumberColor(numberView);
86         }
87     }
88 
bindFromNotification(HybridNotificationView reusableView, Notification notification)89     public HybridNotificationView bindFromNotification(HybridNotificationView reusableView,
90             Notification notification) {
91         return bindFromNotificationWithStyle(reusableView, notification,
92                 R.style.HybridNotification);
93     }
94 
bindFromNotificationWithStyle( HybridNotificationView reusableView, Notification notification, int style)95     private HybridNotificationView bindFromNotificationWithStyle(
96             HybridNotificationView reusableView, Notification notification, int style) {
97         if (reusableView == null) {
98             reusableView = inflateHybridViewWithStyle(style);
99         }
100         CharSequence titleText = resolveTitle(notification);
101         CharSequence contentText = resolveText(notification);
102         reusableView.bind(titleText, contentText);
103         return reusableView;
104     }
105 
resolveText(Notification notification)106     private CharSequence resolveText(Notification notification) {
107         CharSequence contentText = notification.extras.getCharSequence(Notification.EXTRA_TEXT);
108         if (contentText == null) {
109             contentText = notification.extras.getCharSequence(Notification.EXTRA_BIG_TEXT);
110         }
111         return contentText;
112     }
113 
resolveTitle(Notification notification)114     private CharSequence resolveTitle(Notification notification) {
115         CharSequence titleText = notification.extras.getCharSequence(Notification.EXTRA_TITLE);
116         if (titleText == null) {
117             titleText = notification.extras.getCharSequence(Notification.EXTRA_TITLE_BIG);
118         }
119         return titleText;
120     }
121 
bindOverflowNumber(TextView reusableView, int number)122     public TextView bindOverflowNumber(TextView reusableView, int number) {
123         if (reusableView == null) {
124             reusableView = inflateOverflowNumber();
125         }
126         String text = mContext.getResources().getString(
127                 R.string.notification_group_overflow_indicator, number);
128         if (!text.equals(reusableView.getText())) {
129             reusableView.setText(text);
130         }
131         String contentDescription = String.format(mContext.getResources().getQuantityString(
132                 R.plurals.notification_group_overflow_description, number), number);
133 
134         reusableView.setContentDescription(contentDescription);
135         reusableView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mOverflowNumberSize);
136         reusableView.setPaddingRelative(reusableView.getPaddingStart(),
137                 reusableView.getPaddingTop(), mOverflowNumberPadding,
138                 reusableView.getPaddingBottom());
139         updateOverFlowNumberColor(reusableView);
140         return reusableView;
141     }
142 }
143