blob: fe819574f3b62c721dc101fafda7cf6b86e8ea61 [file] [log] [blame]
Selim Cinekc897bd32016-03-18 17:32:31 -07001/*
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
Rohan Shah20790b82018-07-02 17:21:04 -070017package com.android.systemui.statusbar.notification.row;
Selim Cinekc897bd32016-03-18 17:32:31 -070018
19import android.app.Notification;
20import android.content.Context;
Adrian Roos6f6e1592017-05-02 16:22:53 -070021import android.content.res.Resources;
22import android.util.TypedValue;
23import android.view.ContextThemeWrapper;
Selim Cinekc897bd32016-03-18 17:32:31 -070024import android.view.LayoutInflater;
Selim Cinekc897bd32016-03-18 17:32:31 -070025import android.view.ViewGroup;
26import android.widget.TextView;
27
28import com.android.systemui.R;
Rohan Shah20790b82018-07-02 17:21:04 -070029import com.android.systemui.statusbar.notification.NotificationDozeHelper;
30import com.android.systemui.statusbar.notification.NotificationUtils;
Selim Cinekc897bd32016-03-18 17:32:31 -070031
32/**
33 * A class managing hybrid groups that include {@link HybridNotificationView} and the notification
34 * group overflow.
35 */
36public class HybridGroupManager {
37
38 private final Context mContext;
Adrian Roos6f6e1592017-05-02 16:22:53 -070039 private final ViewGroup mParent;
40
dongwan0605.kim11e7dec2018-05-06 18:04:52 +090041 private float mOverflowNumberSize;
42 private int mOverflowNumberPadding;
Adrian Roos6f6e1592017-05-02 16:22:53 -070043
Selim Cinekc897bd32016-03-18 17:32:31 -070044 private int mOverflowNumberColor;
45
46 public HybridGroupManager(Context ctx, ViewGroup parent) {
47 mContext = ctx;
48 mParent = parent;
dongwan0605.kim11e7dec2018-05-06 18:04:52 +090049 initDimens();
50 }
Adrian Roos6f6e1592017-05-02 16:22:53 -070051
dongwan0605.kim11e7dec2018-05-06 18:04:52 +090052 public void initDimens() {
Adrian Roos6f6e1592017-05-02 16:22:53 -070053 Resources res = mContext.getResources();
54 mOverflowNumberSize = res.getDimensionPixelSize(
55 R.dimen.group_overflow_number_size);
Adrian Roos6f6e1592017-05-02 16:22:53 -070056 mOverflowNumberPadding = res.getDimensionPixelSize(
57 R.dimen.group_overflow_number_padding);
Selim Cinekc897bd32016-03-18 17:32:31 -070058 }
59
Adrian Roos6f6e1592017-05-02 16:22:53 -070060 private HybridNotificationView inflateHybridViewWithStyle(int style) {
61 LayoutInflater inflater = new ContextThemeWrapper(mContext, style)
62 .getSystemService(LayoutInflater.class);
Selim Cinekc897bd32016-03-18 17:32:31 -070063 HybridNotificationView hybrid = (HybridNotificationView) inflater.inflate(
64 R.layout.hybrid_notification, mParent, false);
65 mParent.addView(hybrid);
66 return hybrid;
67 }
68
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
78 private void updateOverFlowNumberColor(TextView numberView) {
Lucas Dupin00be88f2019-01-03 17:50:52 -080079 numberView.setTextColor(mOverflowNumberColor);
Selim Cinekc897bd32016-03-18 17:32:31 -070080 }
81
Lucas Dupin00be88f2019-01-03 17:50:52 -080082 public void setOverflowNumberColor(TextView numberView, int colorRegular) {
Adrian Roos6f6e1592017-05-02 16:22:53 -070083 mOverflowNumberColor = colorRegular;
Selim Cinekc897bd32016-03-18 17:32:31 -070084 if (numberView != null) {
85 updateOverFlowNumberColor(numberView);
86 }
87 }
88
89 public HybridNotificationView bindFromNotification(HybridNotificationView reusableView,
90 Notification notification) {
Adrian Roos6f6e1592017-05-02 16:22:53 -070091 return bindFromNotificationWithStyle(reusableView, notification,
92 R.style.HybridNotification);
93 }
94
Adrian Roos6f6e1592017-05-02 16:22:53 -070095 private HybridNotificationView bindFromNotificationWithStyle(
96 HybridNotificationView reusableView, Notification notification, int style) {
Selim Cinekc897bd32016-03-18 17:32:31 -070097 if (reusableView == null) {
Adrian Roos6f6e1592017-05-02 16:22:53 -070098 reusableView = inflateHybridViewWithStyle(style);
Selim Cinekc897bd32016-03-18 17:32:31 -070099 }
100 CharSequence titleText = resolveTitle(notification);
101 CharSequence contentText = resolveText(notification);
102 reusableView.bind(titleText, contentText);
103 return reusableView;
104 }
105
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
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
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 }
Selim Cinekddf1b392016-05-27 16:33:10 -0700131 String contentDescription = String.format(mContext.getResources().getQuantityString(
132 R.plurals.notification_group_overflow_description, number), number);
133
134 reusableView.setContentDescription(contentDescription);
Lucas Dupin00be88f2019-01-03 17:50:52 -0800135 reusableView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mOverflowNumberSize);
136 reusableView.setPaddingRelative(reusableView.getPaddingStart(),
137 reusableView.getPaddingTop(), mOverflowNumberPadding,
138 reusableView.getPaddingBottom());
139 updateOverFlowNumberColor(reusableView);
Selim Cinekc897bd32016-03-18 17:32:31 -0700140 return reusableView;
141 }
Selim Cinekc897bd32016-03-18 17:32:31 -0700142}