Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 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 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 18 | |
| 19 | import android.app.Notification; |
| 20 | import android.content.Context; |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 21 | import android.content.res.Resources; |
| 22 | import android.util.TypedValue; |
| 23 | import android.view.ContextThemeWrapper; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 24 | import android.view.LayoutInflater; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 25 | import android.view.ViewGroup; |
| 26 | import android.widget.TextView; |
| 27 | |
| 28 | import com.android.systemui.R; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 29 | import com.android.systemui.statusbar.notification.NotificationDozeHelper; |
| 30 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 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; |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 39 | private final ViewGroup mParent; |
| 40 | |
dongwan0605.kim | 11e7dec | 2018-05-06 18:04:52 +0900 | [diff] [blame] | 41 | private float mOverflowNumberSize; |
| 42 | private int mOverflowNumberPadding; |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 43 | |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 44 | private int mOverflowNumberColor; |
| 45 | |
| 46 | public HybridGroupManager(Context ctx, ViewGroup parent) { |
| 47 | mContext = ctx; |
| 48 | mParent = parent; |
dongwan0605.kim | 11e7dec | 2018-05-06 18:04:52 +0900 | [diff] [blame] | 49 | initDimens(); |
| 50 | } |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 51 | |
dongwan0605.kim | 11e7dec | 2018-05-06 18:04:52 +0900 | [diff] [blame] | 52 | public void initDimens() { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 53 | Resources res = mContext.getResources(); |
| 54 | mOverflowNumberSize = res.getDimensionPixelSize( |
| 55 | R.dimen.group_overflow_number_size); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 56 | mOverflowNumberPadding = res.getDimensionPixelSize( |
| 57 | R.dimen.group_overflow_number_padding); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 60 | private HybridNotificationView inflateHybridViewWithStyle(int style) { |
| 61 | LayoutInflater inflater = new ContextThemeWrapper(mContext, style) |
| 62 | .getSystemService(LayoutInflater.class); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 63 | 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 Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 79 | numberView.setTextColor(mOverflowNumberColor); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 82 | public void setOverflowNumberColor(TextView numberView, int colorRegular) { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 83 | mOverflowNumberColor = colorRegular; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 84 | if (numberView != null) { |
| 85 | updateOverFlowNumberColor(numberView); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | public HybridNotificationView bindFromNotification(HybridNotificationView reusableView, |
| 90 | Notification notification) { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 91 | return bindFromNotificationWithStyle(reusableView, notification, |
| 92 | R.style.HybridNotification); |
| 93 | } |
| 94 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 95 | private HybridNotificationView bindFromNotificationWithStyle( |
| 96 | HybridNotificationView reusableView, Notification notification, int style) { |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 97 | if (reusableView == null) { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 98 | reusableView = inflateHybridViewWithStyle(style); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 99 | } |
| 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 Cinek | ddf1b39 | 2016-05-27 16:33:10 -0700 | [diff] [blame] | 131 | String contentDescription = String.format(mContext.getResources().getQuantityString( |
| 132 | R.plurals.notification_group_overflow_description, number), number); |
| 133 | |
| 134 | reusableView.setContentDescription(contentDescription); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 135 | reusableView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mOverflowNumberSize); |
| 136 | reusableView.setPaddingRelative(reusableView.getPaddingStart(), |
| 137 | reusableView.getPaddingTop(), mOverflowNumberPadding, |
| 138 | reusableView.getPaddingBottom()); |
| 139 | updateOverFlowNumberColor(reusableView); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 140 | return reusableView; |
| 141 | } |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 142 | } |