Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [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.stack; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 18 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 19 | import android.app.Notification; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 20 | import android.content.Context; |
Selim Cinek | a3d3b91 | 2016-02-02 11:22:06 -0800 | [diff] [blame] | 21 | import android.content.res.Configuration; |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 22 | import android.content.res.Resources; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 23 | import android.graphics.drawable.ColorDrawable; |
| 24 | import android.service.notification.StatusBarNotification; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 25 | import android.util.AttributeSet; |
| 26 | import android.view.LayoutInflater; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 27 | import android.view.NotificationHeaderView; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 28 | import android.view.View; |
| 29 | import android.view.ViewGroup; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 30 | import android.widget.RemoteViews; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 31 | import android.widget.TextView; |
Selim Cinek | 817abe7 | 2017-05-24 11:08:55 -0700 | [diff] [blame] | 32 | |
| 33 | import com.android.internal.annotations.VisibleForTesting; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 34 | import com.android.systemui.R; |
Selim Cinek | 7b73a4c | 2016-01-12 18:32:11 -0800 | [diff] [blame] | 35 | import com.android.systemui.statusbar.CrossFadeHelper; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 36 | import com.android.systemui.statusbar.NotificationHeaderUtil; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 37 | import com.android.systemui.statusbar.notification.NotificationUtils; |
| 38 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
| 39 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 40 | import com.android.systemui.statusbar.notification.row.HybridGroupManager; |
| 41 | import com.android.systemui.statusbar.notification.row.HybridNotificationView; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 42 | import com.android.systemui.statusbar.notification.row.wrapper.NotificationViewWrapper; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 43 | |
| 44 | import java.util.ArrayList; |
| 45 | import java.util.List; |
| 46 | |
| 47 | /** |
| 48 | * A container containing child notifications |
| 49 | */ |
| 50 | public class NotificationChildrenContainer extends ViewGroup { |
| 51 | |
Aaron Heuckroth | 17ce40e | 2018-06-19 15:44:40 -0400 | [diff] [blame] | 52 | @VisibleForTesting |
| 53 | static final int NUMBER_OF_CHILDREN_WHEN_COLLAPSED = 2; |
| 54 | @VisibleForTesting |
| 55 | static final int NUMBER_OF_CHILDREN_WHEN_SYSTEM_EXPANDED = 5; |
| 56 | @VisibleForTesting |
| 57 | static final int NUMBER_OF_CHILDREN_WHEN_CHILDREN_EXPANDED = 8; |
| 58 | @VisibleForTesting |
| 59 | static final int NUMBER_OF_CHILDREN_WHEN_AMBIENT = 1; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 60 | private static final AnimationProperties ALPHA_FADE_IN = new AnimationProperties() { |
| 61 | private AnimationFilter mAnimationFilter = new AnimationFilter().animateAlpha(); |
| 62 | |
| 63 | @Override |
| 64 | public AnimationFilter getAnimationFilter() { |
| 65 | return mAnimationFilter; |
| 66 | } |
| 67 | }.setDuration(200); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 68 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 69 | private final List<View> mDividers = new ArrayList<>(); |
| 70 | private final List<ExpandableNotificationRow> mChildren = new ArrayList<>(); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 71 | private final HybridGroupManager mHybridGroupManager; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 72 | private int mChildPadding; |
| 73 | private int mDividerHeight; |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 74 | private float mDividerAlpha; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 75 | private int mNotificationHeaderMargin; |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 76 | |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 77 | private int mNotificatonTopPadding; |
| 78 | private float mCollapsedBottompadding; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 79 | private boolean mChildrenExpanded; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 80 | private ExpandableNotificationRow mContainingNotification; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 81 | private TextView mOverflowNumber; |
| 82 | private ViewState mGroupOverFlowState; |
Selim Cinek | a69f2a6 | 2015-12-11 17:28:12 -0800 | [diff] [blame] | 83 | private int mRealHeight; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 84 | private boolean mUserLocked; |
| 85 | private int mActualHeight; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 86 | private boolean mNeverAppliedGroupState; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 87 | private int mHeaderHeight; |
| 88 | |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 89 | /** |
| 90 | * Whether or not individual notifications that are part of this container will have shadows. |
| 91 | */ |
| 92 | private boolean mEnableShadowOnChildNotifications; |
| 93 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 94 | private NotificationHeaderView mNotificationHeader; |
| 95 | private NotificationViewWrapper mNotificationHeaderWrapper; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 96 | private NotificationHeaderView mNotificationHeaderLowPriority; |
| 97 | private NotificationViewWrapper mNotificationHeaderWrapperLowPriority; |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 98 | private ViewGroup mNotificationHeaderAmbient; |
| 99 | private NotificationViewWrapper mNotificationHeaderWrapperAmbient; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 100 | private NotificationHeaderUtil mHeaderUtil; |
| 101 | private ViewState mHeaderViewState; |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 102 | private int mClipBottomAmount; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 103 | private boolean mIsLowPriority; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 104 | private OnClickListener mHeaderClickListener; |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 105 | private ViewGroup mCurrentHeader; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 106 | |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 107 | private boolean mShowDividersWhenExpanded; |
| 108 | private boolean mHideDividersDuringExpand; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 109 | private int mTranslationForHeader; |
| 110 | private int mCurrentHeaderTranslation = 0; |
| 111 | private float mHeaderVisibleAmount = 1.0f; |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 112 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 113 | public NotificationChildrenContainer(Context context) { |
| 114 | this(context, null); |
| 115 | } |
| 116 | |
| 117 | public NotificationChildrenContainer(Context context, AttributeSet attrs) { |
| 118 | this(context, attrs, 0); |
| 119 | } |
| 120 | |
| 121 | public NotificationChildrenContainer(Context context, AttributeSet attrs, int defStyleAttr) { |
| 122 | this(context, attrs, defStyleAttr, 0); |
| 123 | } |
| 124 | |
| 125 | public NotificationChildrenContainer(Context context, AttributeSet attrs, int defStyleAttr, |
| 126 | int defStyleRes) { |
| 127 | super(context, attrs, defStyleAttr, defStyleRes); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 128 | mHybridGroupManager = new HybridGroupManager(getContext(), this); |
dongwan0605.kim | 11e7dec | 2018-05-06 18:04:52 +0900 | [diff] [blame] | 129 | initDimens(); |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 130 | setClipChildren(false); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | private void initDimens() { |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 134 | Resources res = getResources(); |
| 135 | mChildPadding = res.getDimensionPixelSize(R.dimen.notification_children_padding); |
| 136 | mDividerHeight = res.getDimensionPixelSize( |
| 137 | R.dimen.notification_children_container_divider_height); |
| 138 | mDividerAlpha = res.getFloat(R.dimen.notification_divider_alpha); |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 139 | mNotificationHeaderMargin = res.getDimensionPixelSize( |
| 140 | R.dimen.notification_children_container_margin_top); |
| 141 | mNotificatonTopPadding = res.getDimensionPixelSize( |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 142 | R.dimen.notification_children_container_top_padding); |
Selim Cinek | afeed29 | 2017-12-12 17:32:44 -0800 | [diff] [blame] | 143 | mHeaderHeight = mNotificationHeaderMargin + mNotificatonTopPadding; |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 144 | mCollapsedBottompadding = res.getDimensionPixelSize( |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 145 | com.android.internal.R.dimen.notification_content_margin); |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 146 | mEnableShadowOnChildNotifications = |
| 147 | res.getBoolean(R.bool.config_enableShadowOnChildNotifications); |
| 148 | mShowDividersWhenExpanded = |
| 149 | res.getBoolean(R.bool.config_showDividersWhenGroupNotificationExpanded); |
| 150 | mHideDividersDuringExpand = |
| 151 | res.getBoolean(R.bool.config_hideDividersDuringExpand); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 152 | mTranslationForHeader = res.getDimensionPixelSize( |
| 153 | com.android.internal.R.dimen.notification_content_margin) |
| 154 | - mNotificationHeaderMargin; |
dongwan0605.kim | 11e7dec | 2018-05-06 18:04:52 +0900 | [diff] [blame] | 155 | mHybridGroupManager.initDimens(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | @Override |
| 159 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
Selim Cinek | 471e31a | 2015-12-11 13:39:48 -0800 | [diff] [blame] | 160 | int childCount = Math.min(mChildren.size(), NUMBER_OF_CHILDREN_WHEN_CHILDREN_EXPANDED); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 161 | for (int i = 0; i < childCount; i++) { |
| 162 | View child = mChildren.get(i); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 163 | // We need to layout all children even the GONE ones, such that the heights are |
| 164 | // calculated correctly as they are used to calculate how many we can fit on the screen |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 165 | child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight()); |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 166 | mDividers.get(i).layout(0, 0, getWidth(), mDividerHeight); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 167 | } |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 168 | if (mOverflowNumber != null) { |
Selim Cinek | 09b7dea | 2016-08-30 11:28:19 -0700 | [diff] [blame] | 169 | boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL; |
| 170 | int left = (isRtl ? 0 : getWidth() - mOverflowNumber.getMeasuredWidth()); |
| 171 | int right = left + mOverflowNumber.getMeasuredWidth(); |
| 172 | mOverflowNumber.layout(left, 0, right, mOverflowNumber.getMeasuredHeight()); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 173 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 174 | if (mNotificationHeader != null) { |
| 175 | mNotificationHeader.layout(0, 0, mNotificationHeader.getMeasuredWidth(), |
| 176 | mNotificationHeader.getMeasuredHeight()); |
| 177 | } |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 178 | if (mNotificationHeaderLowPriority != null) { |
| 179 | mNotificationHeaderLowPriority.layout(0, 0, |
| 180 | mNotificationHeaderLowPriority.getMeasuredWidth(), |
| 181 | mNotificationHeaderLowPriority.getMeasuredHeight()); |
| 182 | } |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 183 | if (mNotificationHeaderAmbient != null) { |
| 184 | mNotificationHeaderAmbient.layout(0, 0, |
| 185 | mNotificationHeaderAmbient.getMeasuredWidth(), |
| 186 | mNotificationHeaderAmbient.getMeasuredHeight()); |
| 187 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | @Override |
| 191 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 192 | int heightMode = MeasureSpec.getMode(heightMeasureSpec); |
| 193 | boolean hasFixedHeight = heightMode == MeasureSpec.EXACTLY; |
| 194 | boolean isHeightLimited = heightMode == MeasureSpec.AT_MOST; |
Selim Cinek | a69f2a6 | 2015-12-11 17:28:12 -0800 | [diff] [blame] | 195 | int size = MeasureSpec.getSize(heightMeasureSpec); |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 196 | int newHeightSpec = heightMeasureSpec; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 197 | if (hasFixedHeight || isHeightLimited) { |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 198 | newHeightSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.AT_MOST); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 199 | } |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 200 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 201 | if (mOverflowNumber != null) { |
| 202 | mOverflowNumber.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), |
| 203 | newHeightSpec); |
| 204 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 205 | int dividerHeightSpec = MeasureSpec.makeMeasureSpec(mDividerHeight, MeasureSpec.EXACTLY); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 206 | int height = mNotificationHeaderMargin + mNotificatonTopPadding; |
Selim Cinek | 471e31a | 2015-12-11 13:39:48 -0800 | [diff] [blame] | 207 | int childCount = Math.min(mChildren.size(), NUMBER_OF_CHILDREN_WHEN_CHILDREN_EXPANDED); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 208 | int collapsedChildren = getMaxAllowedVisibleChildren(true /* likeCollapsed */); |
| 209 | int overflowIndex = childCount > collapsedChildren ? collapsedChildren - 1 : -1; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 210 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 211 | ExpandableNotificationRow child = mChildren.get(i); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 212 | // We need to measure all children even the GONE ones, such that the heights are |
| 213 | // calculated correctly as they are used to calculate how many we can fit on the screen. |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 214 | boolean isOverflow = i == overflowIndex; |
Lucas Dupin | 4c797d6 | 2018-05-07 15:32:13 -0700 | [diff] [blame] | 215 | child.setSingleLineWidthIndention(isOverflow && mOverflowNumber != null && |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 216 | !mContainingNotification.isOnAmbient() |
Lucas Dupin | 4c797d6 | 2018-05-07 15:32:13 -0700 | [diff] [blame] | 217 | ? mOverflowNumber.getMeasuredWidth() : 0); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 218 | child.measure(widthMeasureSpec, newHeightSpec); |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 219 | // layout the divider |
| 220 | View divider = mDividers.get(i); |
| 221 | divider.measure(widthMeasureSpec, dividerHeightSpec); |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 222 | if (child.getVisibility() != GONE) { |
| 223 | height += child.getMeasuredHeight() + mDividerHeight; |
| 224 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 225 | } |
Selim Cinek | a69f2a6 | 2015-12-11 17:28:12 -0800 | [diff] [blame] | 226 | mRealHeight = height; |
| 227 | if (heightMode != MeasureSpec.UNSPECIFIED) { |
| 228 | height = Math.min(height, size); |
| 229 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 230 | |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 231 | int headerHeightSpec = MeasureSpec.makeMeasureSpec(mHeaderHeight, MeasureSpec.EXACTLY); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 232 | if (mNotificationHeader != null) { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 233 | mNotificationHeader.measure(widthMeasureSpec, headerHeightSpec); |
| 234 | } |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 235 | if (mNotificationHeaderLowPriority != null) { |
| 236 | headerHeightSpec = MeasureSpec.makeMeasureSpec(mHeaderHeight, MeasureSpec.EXACTLY); |
| 237 | mNotificationHeaderLowPriority.measure(widthMeasureSpec, headerHeightSpec); |
| 238 | } |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 239 | if (mNotificationHeaderAmbient != null) { |
| 240 | headerHeightSpec = MeasureSpec.makeMeasureSpec(mHeaderHeight, MeasureSpec.EXACTLY); |
| 241 | mNotificationHeaderAmbient.measure(widthMeasureSpec, headerHeightSpec); |
| 242 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 243 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 244 | setMeasuredDimension(width, height); |
| 245 | } |
| 246 | |
Selim Cinek | a69f2a6 | 2015-12-11 17:28:12 -0800 | [diff] [blame] | 247 | @Override |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 248 | public boolean hasOverlappingRendering() { |
| 249 | return false; |
| 250 | } |
| 251 | |
| 252 | @Override |
Selim Cinek | a69f2a6 | 2015-12-11 17:28:12 -0800 | [diff] [blame] | 253 | public boolean pointInView(float localX, float localY, float slop) { |
| 254 | return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) && |
| 255 | localY < (mRealHeight + slop); |
| 256 | } |
| 257 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 258 | /** |
| 259 | * Add a child notification to this view. |
| 260 | * |
| 261 | * @param row the row to add |
| 262 | * @param childIndex the index to add it at, if -1 it will be added at the end |
| 263 | */ |
| 264 | public void addNotification(ExpandableNotificationRow row, int childIndex) { |
| 265 | int newIndex = childIndex < 0 ? mChildren.size() : childIndex; |
| 266 | mChildren.add(newIndex, row); |
| 267 | addView(row); |
Selim Cinek | 8e0c498 | 2016-02-29 20:03:08 -0800 | [diff] [blame] | 268 | row.setUserLocked(mUserLocked); |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 269 | |
| 270 | View divider = inflateDivider(); |
| 271 | addView(divider); |
| 272 | mDividers.add(newIndex, divider); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 273 | |
| 274 | updateGroupOverflow(); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 275 | row.setContentTransformationAmount(0, false /* isLastChild */); |
Selim Cinek | f93bf3e | 2018-05-08 14:43:21 -0700 | [diff] [blame] | 276 | // It doesn't make sense to keep old animations around, lets cancel them! |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 277 | ExpandableViewState viewState = row.getViewState(); |
Selim Cinek | f93bf3e | 2018-05-08 14:43:21 -0700 | [diff] [blame] | 278 | if (viewState != null) { |
| 279 | viewState.cancelAnimations(row); |
| 280 | row.cancelAppearDrawing(); |
| 281 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | public void removeNotification(ExpandableNotificationRow row) { |
| 285 | int childIndex = mChildren.indexOf(row); |
| 286 | mChildren.remove(row); |
| 287 | removeView(row); |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 288 | |
Selim Cinek | 7b73a4c | 2016-01-12 18:32:11 -0800 | [diff] [blame] | 289 | final View divider = mDividers.remove(childIndex); |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 290 | removeView(divider); |
Selim Cinek | 7b73a4c | 2016-01-12 18:32:11 -0800 | [diff] [blame] | 291 | getOverlay().add(divider); |
| 292 | CrossFadeHelper.fadeOut(divider, new Runnable() { |
| 293 | @Override |
| 294 | public void run() { |
| 295 | getOverlay().remove(divider); |
| 296 | } |
| 297 | }); |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 298 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 299 | row.setSystemChildExpanded(false); |
Selim Cinek | 8e0c498 | 2016-02-29 20:03:08 -0800 | [diff] [blame] | 300 | row.setUserLocked(false); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 301 | updateGroupOverflow(); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 302 | if (!row.isRemoved()) { |
| 303 | mHeaderUtil.restoreNotificationHeader(row); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * @return The number of notification children in the container. |
| 309 | */ |
| 310 | public int getNotificationChildCount() { |
| 311 | return mChildren.size(); |
| 312 | } |
| 313 | |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 314 | public void recreateNotificationHeader(OnClickListener listener) { |
| 315 | mHeaderClickListener = listener; |
| 316 | StatusBarNotification notification = mContainingNotification.getStatusBarNotification(); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 317 | final Notification.Builder builder = Notification.Builder.recoverBuilder(getContext(), |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 318 | notification.getNotification()); |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 319 | RemoteViews header = builder.makeNotificationHeader(); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 320 | if (mNotificationHeader == null) { |
| 321 | mNotificationHeader = (NotificationHeaderView) header.apply(getContext(), this); |
| 322 | final View expandButton = mNotificationHeader.findViewById( |
| 323 | com.android.internal.R.id.expand_button); |
| 324 | expandButton.setVisibility(VISIBLE); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 325 | mNotificationHeader.setOnClickListener(mHeaderClickListener); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 326 | mNotificationHeaderWrapper = NotificationViewWrapper.wrap(getContext(), |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 327 | mNotificationHeader, mContainingNotification); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 328 | addView(mNotificationHeader, 0); |
| 329 | invalidate(); |
| 330 | } else { |
| 331 | header.reapply(getContext(), mNotificationHeader); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 332 | } |
Selim Cinek | 131f1a4 | 2017-06-05 17:50:19 -0700 | [diff] [blame] | 333 | mNotificationHeaderWrapper.onContentUpdated(mContainingNotification); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 334 | recreateLowPriorityHeader(builder); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 335 | recreateAmbientHeader(builder); |
Lucas Dupin | 6ea2787 | 2017-05-30 12:00:04 -0700 | [diff] [blame] | 336 | updateHeaderVisibility(false /* animate */); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 337 | updateChildrenHeaderAppearance(); |
| 338 | } |
| 339 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 340 | private void recreateAmbientHeader(Notification.Builder builder) { |
| 341 | RemoteViews header; |
| 342 | StatusBarNotification notification = mContainingNotification.getStatusBarNotification(); |
| 343 | if (builder == null) { |
| 344 | builder = Notification.Builder.recoverBuilder(getContext(), |
| 345 | notification.getNotification()); |
| 346 | } |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 347 | header = builder.makeNotificationHeader(); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 348 | if (mNotificationHeaderAmbient == null) { |
| 349 | mNotificationHeaderAmbient = (ViewGroup) header.apply(getContext(), this); |
| 350 | mNotificationHeaderWrapperAmbient = NotificationViewWrapper.wrap(getContext(), |
| 351 | mNotificationHeaderAmbient, mContainingNotification); |
Selim Cinek | 131f1a4 | 2017-06-05 17:50:19 -0700 | [diff] [blame] | 352 | mNotificationHeaderWrapperAmbient.onContentUpdated(mContainingNotification); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 353 | addView(mNotificationHeaderAmbient, 0); |
| 354 | invalidate(); |
| 355 | } else { |
| 356 | header.reapply(getContext(), mNotificationHeaderAmbient); |
| 357 | } |
| 358 | resetHeaderVisibilityIfNeeded(mNotificationHeaderAmbient, calculateDesiredHeader()); |
Selim Cinek | 131f1a4 | 2017-06-05 17:50:19 -0700 | [diff] [blame] | 359 | mNotificationHeaderWrapperAmbient.onContentUpdated(mContainingNotification); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 362 | /** |
| 363 | * Recreate the low-priority header. |
| 364 | * |
| 365 | * @param builder a builder to reuse. Otherwise the builder will be recovered. |
| 366 | */ |
| 367 | private void recreateLowPriorityHeader(Notification.Builder builder) { |
| 368 | RemoteViews header; |
| 369 | StatusBarNotification notification = mContainingNotification.getStatusBarNotification(); |
| 370 | if (mIsLowPriority) { |
| 371 | if (builder == null) { |
| 372 | builder = Notification.Builder.recoverBuilder(getContext(), |
| 373 | notification.getNotification()); |
| 374 | } |
| 375 | header = builder.makeLowPriorityContentView(true /* useRegularSubtext */); |
| 376 | if (mNotificationHeaderLowPriority == null) { |
| 377 | mNotificationHeaderLowPriority = (NotificationHeaderView) header.apply(getContext(), |
| 378 | this); |
| 379 | final View expandButton = mNotificationHeaderLowPriority.findViewById( |
| 380 | com.android.internal.R.id.expand_button); |
| 381 | expandButton.setVisibility(VISIBLE); |
| 382 | mNotificationHeaderLowPriority.setOnClickListener(mHeaderClickListener); |
| 383 | mNotificationHeaderWrapperLowPriority = NotificationViewWrapper.wrap(getContext(), |
| 384 | mNotificationHeaderLowPriority, mContainingNotification); |
| 385 | addView(mNotificationHeaderLowPriority, 0); |
| 386 | invalidate(); |
| 387 | } else { |
| 388 | header.reapply(getContext(), mNotificationHeaderLowPriority); |
| 389 | } |
Selim Cinek | 131f1a4 | 2017-06-05 17:50:19 -0700 | [diff] [blame] | 390 | mNotificationHeaderWrapperLowPriority.onContentUpdated(mContainingNotification); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 391 | resetHeaderVisibilityIfNeeded(mNotificationHeaderLowPriority, calculateDesiredHeader()); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 392 | } else { |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 393 | removeView(mNotificationHeaderLowPriority); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 394 | mNotificationHeaderLowPriority = null; |
| 395 | mNotificationHeaderWrapperLowPriority = null; |
| 396 | } |
| 397 | } |
| 398 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 399 | public void updateChildrenHeaderAppearance() { |
| 400 | mHeaderUtil.updateChildrenHeaderAppearance(); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | public void updateGroupOverflow() { |
| 404 | int childCount = mChildren.size(); |
| 405 | int maxAllowedVisibleChildren = getMaxAllowedVisibleChildren(true /* likeCollapsed */); |
| 406 | if (childCount > maxAllowedVisibleChildren) { |
Lucas Dupin | 4c797d6 | 2018-05-07 15:32:13 -0700 | [diff] [blame] | 407 | int number = childCount - maxAllowedVisibleChildren; |
| 408 | mOverflowNumber = mHybridGroupManager.bindOverflowNumber(mOverflowNumber, number); |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 409 | if (mContainingNotification.isOnAmbient()) { |
Lucas Dupin | 4c797d6 | 2018-05-07 15:32:13 -0700 | [diff] [blame] | 410 | ExpandableNotificationRow overflowView = mChildren.get(0); |
| 411 | HybridNotificationView ambientSingleLineView = overflowView == null ? null |
| 412 | : overflowView.getAmbientSingleLineView(); |
| 413 | if (ambientSingleLineView != null) { |
| 414 | mHybridGroupManager.bindOverflowNumberAmbient( |
| 415 | ambientSingleLineView.getTitleView(), |
| 416 | mContainingNotification.getStatusBarNotification().getNotification(), |
| 417 | number); |
| 418 | } |
| 419 | } |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 420 | if (mGroupOverFlowState == null) { |
| 421 | mGroupOverFlowState = new ViewState(); |
| 422 | mNeverAppliedGroupState = true; |
| 423 | } |
| 424 | } else if (mOverflowNumber != null) { |
| 425 | removeView(mOverflowNumber); |
Eliot Courtney | bb8af1c | 2018-01-11 16:44:45 +0900 | [diff] [blame] | 426 | if (isShown() && isAttachedToWindow()) { |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 427 | final View removedOverflowNumber = mOverflowNumber; |
| 428 | addTransientView(removedOverflowNumber, getTransientViewCount()); |
| 429 | CrossFadeHelper.fadeOut(removedOverflowNumber, new Runnable() { |
| 430 | @Override |
| 431 | public void run() { |
| 432 | removeTransientView(removedOverflowNumber); |
| 433 | } |
| 434 | }); |
| 435 | } |
| 436 | mOverflowNumber = null; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 437 | mGroupOverFlowState = null; |
| 438 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 439 | } |
| 440 | |
Selim Cinek | a3d3b91 | 2016-02-02 11:22:06 -0800 | [diff] [blame] | 441 | @Override |
| 442 | protected void onConfigurationChanged(Configuration newConfig) { |
| 443 | super.onConfigurationChanged(newConfig); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 444 | updateGroupOverflow(); |
Selim Cinek | a3d3b91 | 2016-02-02 11:22:06 -0800 | [diff] [blame] | 445 | } |
| 446 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 447 | private View inflateDivider() { |
| 448 | return LayoutInflater.from(mContext).inflate( |
| 449 | R.layout.notification_children_divider, this, false); |
| 450 | } |
| 451 | |
| 452 | public List<ExpandableNotificationRow> getNotificationChildren() { |
| 453 | return mChildren; |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Apply the order given in the list to the children. |
| 458 | * |
| 459 | * @param childOrder the new list order |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 460 | * @param visualStabilityManager |
| 461 | * @param callback |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 462 | * @return whether the list order has changed |
| 463 | */ |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 464 | public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder, |
| 465 | VisualStabilityManager visualStabilityManager, |
| 466 | VisualStabilityManager.Callback callback) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 467 | if (childOrder == null) { |
| 468 | return false; |
| 469 | } |
| 470 | boolean result = false; |
| 471 | for (int i = 0; i < mChildren.size() && i < childOrder.size(); i++) { |
| 472 | ExpandableNotificationRow child = mChildren.get(i); |
| 473 | ExpandableNotificationRow desiredChild = childOrder.get(i); |
| 474 | if (child != desiredChild) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 475 | if (visualStabilityManager.canReorderNotification(desiredChild)) { |
| 476 | mChildren.remove(desiredChild); |
| 477 | mChildren.add(i, desiredChild); |
| 478 | result = true; |
| 479 | } else { |
| 480 | visualStabilityManager.addReorderingAllowedCallback(callback); |
| 481 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 482 | } |
| 483 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 484 | updateExpansionStates(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 485 | return result; |
| 486 | } |
| 487 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 488 | private void updateExpansionStates() { |
Selim Cinek | 898d173 | 2016-02-29 19:57:35 -0800 | [diff] [blame] | 489 | if (mChildrenExpanded || mUserLocked) { |
| 490 | // we don't modify it the group is expanded or if we are expanding it |
| 491 | return; |
| 492 | } |
| 493 | int size = mChildren.size(); |
| 494 | for (int i = 0; i < size; i++) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 495 | ExpandableNotificationRow child = mChildren.get(i); |
Selim Cinek | 898d173 | 2016-02-29 19:57:35 -0800 | [diff] [blame] | 496 | child.setSystemChildExpanded(i == 0 && size == 1); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * |
| 502 | * @return the intrinsic size of this children container, i.e the natural fully expanded state |
| 503 | */ |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 504 | public int getIntrinsicHeight() { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 505 | int maxAllowedVisibleChildren = getMaxAllowedVisibleChildren(); |
| 506 | return getIntrinsicHeight(maxAllowedVisibleChildren); |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * @return the intrinsic height with a number of children given |
| 511 | * in @param maxAllowedVisibleChildren |
| 512 | */ |
| 513 | private int getIntrinsicHeight(float maxAllowedVisibleChildren) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 514 | if (showingAsLowPriority()) { |
| 515 | return mNotificationHeaderLowPriority.getHeight(); |
| 516 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 517 | int intrinsicHeight = mNotificationHeaderMargin + mCurrentHeaderTranslation; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 518 | int visibleChildren = 0; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 519 | int childCount = mChildren.size(); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 520 | boolean firstChild = true; |
| 521 | float expandFactor = 0; |
| 522 | if (mUserLocked) { |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 523 | expandFactor = getGroupExpandFraction(); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 524 | } |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 525 | boolean childrenExpanded = mChildrenExpanded || mContainingNotification.isOnAmbient(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 526 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 527 | if (visibleChildren >= maxAllowedVisibleChildren) { |
| 528 | break; |
| 529 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 530 | if (!firstChild) { |
| 531 | if (mUserLocked) { |
| 532 | intrinsicHeight += NotificationUtils.interpolate(mChildPadding, mDividerHeight, |
| 533 | expandFactor); |
| 534 | } else { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 535 | intrinsicHeight += childrenExpanded ? mDividerHeight : mChildPadding; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 536 | } |
| 537 | } else { |
| 538 | if (mUserLocked) { |
| 539 | intrinsicHeight += NotificationUtils.interpolate( |
| 540 | 0, |
| 541 | mNotificatonTopPadding + mDividerHeight, |
| 542 | expandFactor); |
| 543 | } else { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 544 | intrinsicHeight += childrenExpanded |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 545 | ? mNotificatonTopPadding + mDividerHeight |
| 546 | : 0; |
| 547 | } |
| 548 | firstChild = false; |
| 549 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 550 | ExpandableNotificationRow child = mChildren.get(i); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 551 | intrinsicHeight += child.getIntrinsicHeight(); |
| 552 | visibleChildren++; |
| 553 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 554 | if (mUserLocked) { |
| 555 | intrinsicHeight += NotificationUtils.interpolate(mCollapsedBottompadding, 0.0f, |
| 556 | expandFactor); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 557 | } else if (!childrenExpanded) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 558 | intrinsicHeight += mCollapsedBottompadding; |
| 559 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 560 | return intrinsicHeight; |
| 561 | } |
| 562 | |
| 563 | /** |
| 564 | * Update the state of all its children based on a linear layout algorithm. |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 565 | * @param parentState the state of the parent |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 566 | * @param ambientState |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 567 | */ |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 568 | public void updateState(ExpandableViewState parentState, AmbientState ambientState) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 569 | int childCount = mChildren.size(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 570 | int yPosition = mNotificationHeaderMargin + mCurrentHeaderTranslation; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 571 | boolean firstChild = true; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 572 | int maxAllowedVisibleChildren = getMaxAllowedVisibleChildren(); |
Selim Cinek | 91c2a15 | 2016-03-17 15:01:38 -0700 | [diff] [blame] | 573 | int lastVisibleIndex = maxAllowedVisibleChildren - 1; |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 574 | int firstOverflowIndex = lastVisibleIndex + 1; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 575 | float expandFactor = 0; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 576 | boolean expandingToExpandedGroup = mUserLocked && !showingAsLowPriority(); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 577 | if (mUserLocked) { |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 578 | expandFactor = getGroupExpandFraction(); |
| 579 | firstOverflowIndex = getMaxAllowedVisibleChildren(true /* likeCollapsed */); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 580 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 581 | |
Adrian Roos | 16fe495 | 2017-05-18 16:10:21 -0700 | [diff] [blame] | 582 | boolean childrenExpandedAndNotAnimating = mChildrenExpanded |
| 583 | && !mContainingNotification.isGroupExpansionChanging(); |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 584 | int launchTransitionCompensation = 0; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 585 | for (int i = 0; i < childCount; i++) { |
| 586 | ExpandableNotificationRow child = mChildren.get(i); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 587 | if (!firstChild) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 588 | if (expandingToExpandedGroup) { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 589 | yPosition += NotificationUtils.interpolate(mChildPadding, mDividerHeight, |
| 590 | expandFactor); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 591 | } else { |
Adrian Roos | 16fe495 | 2017-05-18 16:10:21 -0700 | [diff] [blame] | 592 | yPosition += mChildrenExpanded ? mDividerHeight : mChildPadding; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 593 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 594 | } else { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 595 | if (expandingToExpandedGroup) { |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 596 | yPosition += NotificationUtils.interpolate( |
| 597 | 0, |
| 598 | mNotificatonTopPadding + mDividerHeight, |
| 599 | expandFactor); |
| 600 | } else { |
Adrian Roos | 16fe495 | 2017-05-18 16:10:21 -0700 | [diff] [blame] | 601 | yPosition += mChildrenExpanded ? mNotificatonTopPadding + mDividerHeight : 0; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 602 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 603 | firstChild = false; |
| 604 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 605 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 606 | ExpandableViewState childState = child.getViewState(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 607 | int intrinsicHeight = child.getIntrinsicHeight(); |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 608 | childState.height = intrinsicHeight; |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 609 | childState.yTranslation = yPosition + launchTransitionCompensation; |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 610 | childState.hidden = false; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 611 | // When the group is expanded, the children cast the shadows rather than the parent |
| 612 | // so use the parent's elevation here. |
Adrian Roos | 16fe495 | 2017-05-18 16:10:21 -0700 | [diff] [blame] | 613 | childState.zTranslation = |
| 614 | (childrenExpandedAndNotAnimating && mEnableShadowOnChildNotifications) |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 615 | ? parentState.zTranslation |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 616 | : 0; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 617 | childState.dimmed = parentState.dimmed; |
| 618 | childState.dark = parentState.dark; |
| 619 | childState.hideSensitive = parentState.hideSensitive; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 620 | childState.belowSpeedBump = parentState.belowSpeedBump; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 621 | childState.clipTopAmount = 0; |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 622 | childState.alpha = 0; |
| 623 | if (i < firstOverflowIndex) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 624 | childState.alpha = showingAsLowPriority() ? expandFactor : 1.0f; |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 625 | } else if (expandFactor == 1.0f && i <= lastVisibleIndex) { |
| 626 | childState.alpha = (mActualHeight - childState.yTranslation) / childState.height; |
| 627 | childState.alpha = Math.max(0.0f, Math.min(1.0f, childState.alpha)); |
| 628 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 629 | childState.location = parentState.location; |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 630 | childState.inShelf = parentState.inShelf; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 631 | yPosition += intrinsicHeight; |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 632 | if (child.isExpandAnimationRunning()) { |
| 633 | launchTransitionCompensation = -ambientState.getExpandAnimationTopChange(); |
| 634 | } |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 635 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 636 | } |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 637 | if (mOverflowNumber != null) { |
| 638 | ExpandableNotificationRow overflowView = mChildren.get(Math.min( |
Lucas Dupin | 4c797d6 | 2018-05-07 15:32:13 -0700 | [diff] [blame] | 639 | getMaxAllowedVisibleChildren(true /* likeCollapsed */), childCount) - 1); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 640 | mGroupOverFlowState.copyFrom(overflowView.getViewState()); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 641 | |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 642 | if (mContainingNotification.isOnAmbient()) { |
Lucas Dupin | 4c797d6 | 2018-05-07 15:32:13 -0700 | [diff] [blame] | 643 | mGroupOverFlowState.alpha = 0.0f; |
| 644 | } else if (!mChildrenExpanded) { |
| 645 | HybridNotificationView alignView = overflowView.getSingleLineView(); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 646 | if (alignView != null) { |
| 647 | View mirrorView = alignView.getTextView(); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 648 | if (mirrorView.getVisibility() == GONE) { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 649 | mirrorView = alignView.getTitleView(); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 650 | } |
| 651 | if (mirrorView.getVisibility() == GONE) { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 652 | mirrorView = alignView; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 653 | } |
Lucas Dupin | 4c797d6 | 2018-05-07 15:32:13 -0700 | [diff] [blame] | 654 | mGroupOverFlowState.alpha = mirrorView.getAlpha(); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 655 | mGroupOverFlowState.yTranslation += NotificationUtils.getRelativeYOffset( |
| 656 | mirrorView, overflowView); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 657 | } |
| 658 | } else { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 659 | mGroupOverFlowState.yTranslation += mNotificationHeaderMargin; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 660 | mGroupOverFlowState.alpha = 0.0f; |
| 661 | } |
| 662 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 663 | if (mNotificationHeader != null) { |
| 664 | if (mHeaderViewState == null) { |
| 665 | mHeaderViewState = new ViewState(); |
| 666 | } |
| 667 | mHeaderViewState.initFrom(mNotificationHeader); |
Adrian Roos | 16fe495 | 2017-05-18 16:10:21 -0700 | [diff] [blame] | 668 | mHeaderViewState.zTranslation = childrenExpandedAndNotAnimating |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 669 | ? parentState.zTranslation |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 670 | : 0; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 671 | mHeaderViewState.yTranslation = mCurrentHeaderTranslation; |
| 672 | mHeaderViewState.alpha = mHeaderVisibleAmount; |
| 673 | // The hiding is done automatically by the alpha, otherwise we'll pick it up again |
| 674 | // in the next frame with the initFrom call above and have an invisible header |
| 675 | mHeaderViewState.hidden = false; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * When moving into the bottom stack, the bottom visible child in an expanded group adjusts its |
| 681 | * height, children in the group after this are gone. |
| 682 | * |
| 683 | * @param child the child who's height to adjust. |
| 684 | * @param parentHeight the height of the parent. |
| 685 | * @param childState the state to update. |
| 686 | * @param yPosition the yPosition of the view. |
| 687 | * @return true if children after this one should be hidden. |
| 688 | */ |
| 689 | private boolean updateChildStateForExpandedGroup(ExpandableNotificationRow child, |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 690 | int parentHeight, ExpandableViewState childState, int yPosition) { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 691 | final int top = yPosition + child.getClipTopAmount(); |
| 692 | final int intrinsicHeight = child.getIntrinsicHeight(); |
| 693 | final int bottom = top + intrinsicHeight; |
| 694 | int newHeight = intrinsicHeight; |
| 695 | if (bottom >= parentHeight) { |
| 696 | // Child is either clipped or gone |
| 697 | newHeight = Math.max((parentHeight - top), 0); |
| 698 | } |
| 699 | childState.hidden = newHeight == 0; |
| 700 | childState.height = newHeight; |
| 701 | return childState.height != intrinsicHeight && !childState.hidden; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Aaron Heuckroth | 17ce40e | 2018-06-19 15:44:40 -0400 | [diff] [blame] | 704 | @VisibleForTesting |
| 705 | int getMaxAllowedVisibleChildren() { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 706 | return getMaxAllowedVisibleChildren(false /* likeCollapsed */); |
| 707 | } |
| 708 | |
Aaron Heuckroth | 17ce40e | 2018-06-19 15:44:40 -0400 | [diff] [blame] | 709 | @VisibleForTesting |
| 710 | int getMaxAllowedVisibleChildren(boolean likeCollapsed) { |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 711 | if (mContainingNotification.isOnAmbient()) { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 712 | return NUMBER_OF_CHILDREN_WHEN_AMBIENT; |
| 713 | } |
Aaron Heuckroth | 17ce40e | 2018-06-19 15:44:40 -0400 | [diff] [blame] | 714 | if (!likeCollapsed && (mChildrenExpanded || mContainingNotification.isUserLocked()) |
| 715 | && !showingAsLowPriority()) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 716 | return NUMBER_OF_CHILDREN_WHEN_CHILDREN_EXPANDED; |
| 717 | } |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 718 | if (mIsLowPriority || !mContainingNotification.isOnKeyguard() |
| 719 | && (mContainingNotification.isExpanded() || mContainingNotification.isHeadsUp())) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 720 | return NUMBER_OF_CHILDREN_WHEN_SYSTEM_EXPANDED; |
| 721 | } |
| 722 | return NUMBER_OF_CHILDREN_WHEN_COLLAPSED; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 723 | } |
| 724 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 725 | /** Applies state to children. */ |
| 726 | public void applyState() { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 727 | int childCount = mChildren.size(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 728 | ViewState tmpState = new ViewState(); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 729 | float expandFraction = 0.0f; |
| 730 | if (mUserLocked) { |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 731 | expandFraction = getGroupExpandFraction(); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 732 | } |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 733 | final boolean dividersVisible = mUserLocked && !showingAsLowPriority() |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 734 | || (mChildrenExpanded && mShowDividersWhenExpanded) |
| 735 | || (mContainingNotification.isGroupExpansionChanging() |
| 736 | && !mHideDividersDuringExpand); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 737 | for (int i = 0; i < childCount; i++) { |
| 738 | ExpandableNotificationRow child = mChildren.get(i); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 739 | ExpandableViewState viewState = child.getViewState(); |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 740 | viewState.applyToView(child); |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 741 | |
| 742 | // layout the divider |
| 743 | View divider = mDividers.get(i); |
| 744 | tmpState.initFrom(divider); |
| 745 | tmpState.yTranslation = viewState.yTranslation - mDividerHeight; |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 746 | float alpha = mChildrenExpanded && viewState.alpha != 0 ? mDividerAlpha : 0; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 747 | if (mUserLocked && !showingAsLowPriority() && viewState.alpha != 0) { |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 748 | alpha = NotificationUtils.interpolate(0, 0.5f, |
| 749 | Math.min(viewState.alpha, expandFraction)); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 750 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 751 | tmpState.hidden = !dividersVisible; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 752 | tmpState.alpha = alpha; |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 753 | tmpState.applyToView(divider); |
Selim Cinek | d9a3f8f | 2016-03-17 19:39:00 -0700 | [diff] [blame] | 754 | // There is no fake shadow to be drawn on the children |
| 755 | child.setFakeShadowIntensity(0.0f, 0.0f, 0, 0); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 756 | } |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 757 | if (mGroupOverFlowState != null) { |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 758 | mGroupOverFlowState.applyToView(mOverflowNumber); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 759 | mNeverAppliedGroupState = false; |
| 760 | } |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 761 | if (mHeaderViewState != null) { |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 762 | mHeaderViewState.applyToView(mNotificationHeader); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 763 | } |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 764 | updateChildrenClipping(); |
| 765 | } |
| 766 | |
| 767 | private void updateChildrenClipping() { |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 768 | if (mContainingNotification.hasExpandingChild()) { |
| 769 | return; |
| 770 | } |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 771 | int childCount = mChildren.size(); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 772 | int layoutEnd = mContainingNotification.getActualHeight() - mClipBottomAmount; |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 773 | for (int i = 0; i < childCount; i++) { |
| 774 | ExpandableNotificationRow child = mChildren.get(i); |
| 775 | if (child.getVisibility() == GONE) { |
| 776 | continue; |
| 777 | } |
| 778 | float childTop = child.getTranslationY(); |
| 779 | float childBottom = childTop + child.getActualHeight(); |
| 780 | boolean visible = true; |
| 781 | int clipBottomAmount = 0; |
| 782 | if (childTop > layoutEnd) { |
| 783 | visible = false; |
| 784 | } else if (childBottom > layoutEnd) { |
| 785 | clipBottomAmount = (int) (childBottom - layoutEnd); |
| 786 | } |
| 787 | |
| 788 | boolean isVisible = child.getVisibility() == VISIBLE; |
| 789 | if (visible != isVisible) { |
| 790 | child.setVisibility(visible ? VISIBLE : INVISIBLE); |
| 791 | } |
| 792 | |
| 793 | child.setClipBottomAmount(clipBottomAmount); |
| 794 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 795 | } |
| 796 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 797 | /** |
| 798 | * This is called when the children expansion has changed and positions the children properly |
| 799 | * for an appear animation. |
| 800 | * |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 801 | */ |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 802 | public void prepareExpansionChanged() { |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 803 | // TODO: do something that makes sense, like placing the invisible views correctly |
| 804 | return; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 805 | } |
| 806 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 807 | /** Animate to a given state. */ |
| 808 | public void startAnimationToState(AnimationProperties properties) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 809 | int childCount = mChildren.size(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 810 | ViewState tmpState = new ViewState(); |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 811 | float expandFraction = getGroupExpandFraction(); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 812 | final boolean dividersVisible = mUserLocked && !showingAsLowPriority() |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 813 | || (mChildrenExpanded && mShowDividersWhenExpanded) |
| 814 | || (mContainingNotification.isGroupExpansionChanging() |
| 815 | && !mHideDividersDuringExpand); |
Selim Cinek | e812652 | 2015-12-08 21:21:17 -0800 | [diff] [blame] | 816 | for (int i = childCount - 1; i >= 0; i--) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 817 | ExpandableNotificationRow child = mChildren.get(i); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 818 | ExpandableViewState viewState = child.getViewState(); |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 819 | viewState.animateTo(child, properties); |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 820 | |
| 821 | // layout the divider |
| 822 | View divider = mDividers.get(i); |
| 823 | tmpState.initFrom(divider); |
| 824 | tmpState.yTranslation = viewState.yTranslation - mDividerHeight; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 825 | float alpha = mChildrenExpanded && viewState.alpha != 0 ? 0.5f : 0; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 826 | if (mUserLocked && !showingAsLowPriority() && viewState.alpha != 0) { |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 827 | alpha = NotificationUtils.interpolate(0, 0.5f, |
| 828 | Math.min(viewState.alpha, expandFraction)); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 829 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 830 | tmpState.hidden = !dividersVisible; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 831 | tmpState.alpha = alpha; |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 832 | tmpState.animateTo(divider, properties); |
Selim Cinek | d9a3f8f | 2016-03-17 19:39:00 -0700 | [diff] [blame] | 833 | // There is no fake shadow to be drawn on the children |
| 834 | child.setFakeShadowIntensity(0.0f, 0.0f, 0, 0); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 835 | } |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 836 | if (mOverflowNumber != null) { |
| 837 | if (mNeverAppliedGroupState) { |
| 838 | float alpha = mGroupOverFlowState.alpha; |
| 839 | mGroupOverFlowState.alpha = 0; |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 840 | mGroupOverFlowState.applyToView(mOverflowNumber); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 841 | mGroupOverFlowState.alpha = alpha; |
| 842 | mNeverAppliedGroupState = false; |
| 843 | } |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 844 | mGroupOverFlowState.animateTo(mOverflowNumber, properties); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 845 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 846 | if (mNotificationHeader != null) { |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 847 | mHeaderViewState.applyToView(mNotificationHeader); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 848 | } |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 849 | updateChildrenClipping(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | public ExpandableNotificationRow getViewAtPosition(float y) { |
| 853 | // find the view under the pointer, accounting for GONE views |
| 854 | final int count = mChildren.size(); |
| 855 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 856 | ExpandableNotificationRow slidingChild = mChildren.get(childIdx); |
| 857 | float childTop = slidingChild.getTranslationY(); |
| 858 | float top = childTop + slidingChild.getClipTopAmount(); |
| 859 | float bottom = childTop + slidingChild.getActualHeight(); |
| 860 | if (y >= top && y <= bottom) { |
| 861 | return slidingChild; |
| 862 | } |
| 863 | } |
| 864 | return null; |
| 865 | } |
| 866 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 867 | public void setChildrenExpanded(boolean childrenExpanded) { |
| 868 | mChildrenExpanded = childrenExpanded; |
Selim Cinek | 898d173 | 2016-02-29 19:57:35 -0800 | [diff] [blame] | 869 | updateExpansionStates(); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 870 | if (mNotificationHeader != null) { |
| 871 | mNotificationHeader.setExpanded(childrenExpanded); |
| 872 | } |
Selim Cinek | ddf1b39 | 2016-05-27 16:33:10 -0700 | [diff] [blame] | 873 | final int count = mChildren.size(); |
| 874 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 875 | ExpandableNotificationRow child = mChildren.get(childIdx); |
| 876 | child.setChildrenExpanded(childrenExpanded, false); |
| 877 | } |
Selim Cinek | bc34215 | 2018-12-05 18:45:42 -0800 | [diff] [blame] | 878 | updateHeaderTouchability(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 881 | public void setContainingNotification(ExpandableNotificationRow parent) { |
| 882 | mContainingNotification = parent; |
| 883 | mHeaderUtil = new NotificationHeaderUtil(mContainingNotification); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 886 | public ExpandableNotificationRow getContainingNotification() { |
| 887 | return mContainingNotification; |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 888 | } |
| 889 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 890 | public NotificationHeaderView getHeaderView() { |
| 891 | return mNotificationHeader; |
| 892 | } |
| 893 | |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 894 | public NotificationHeaderView getLowPriorityHeaderView() { |
| 895 | return mNotificationHeaderLowPriority; |
| 896 | } |
| 897 | |
Lucas Dupin | 6ea2787 | 2017-05-30 12:00:04 -0700 | [diff] [blame] | 898 | @VisibleForTesting |
| 899 | public ViewGroup getCurrentHeaderView() { |
| 900 | return mCurrentHeader; |
| 901 | } |
| 902 | |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 903 | public void notifyDozingStateChanged() { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 904 | updateHeaderVisibility(false); |
Lucas Dupin | 4c797d6 | 2018-05-07 15:32:13 -0700 | [diff] [blame] | 905 | updateGroupOverflow(); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 908 | private void updateHeaderVisibility(boolean animate) { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 909 | ViewGroup desiredHeader; |
| 910 | ViewGroup currentHeader = mCurrentHeader; |
| 911 | desiredHeader = calculateDesiredHeader(); |
| 912 | |
| 913 | if (currentHeader == desiredHeader) { |
| 914 | return; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 915 | } |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 916 | if (desiredHeader == mNotificationHeaderAmbient |
| 917 | || currentHeader == mNotificationHeaderAmbient) { |
| 918 | animate = false; |
| 919 | } |
| 920 | |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 921 | if (animate) { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 922 | if (desiredHeader != null && currentHeader != null) { |
| 923 | currentHeader.setVisibility(VISIBLE); |
| 924 | desiredHeader.setVisibility(VISIBLE); |
| 925 | NotificationViewWrapper visibleWrapper = getWrapperForView(desiredHeader); |
| 926 | NotificationViewWrapper hiddenWrapper = getWrapperForView(currentHeader); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 927 | visibleWrapper.transformFrom(hiddenWrapper); |
| 928 | hiddenWrapper.transformTo(visibleWrapper, () -> updateHeaderVisibility(false)); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 929 | startChildAlphaAnimations(desiredHeader == mNotificationHeader); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 930 | } else { |
| 931 | animate = false; |
| 932 | } |
| 933 | } |
| 934 | if (!animate) { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 935 | if (desiredHeader != null) { |
| 936 | getWrapperForView(desiredHeader).setVisible(true); |
| 937 | desiredHeader.setVisibility(VISIBLE); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 938 | } |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 939 | if (currentHeader != null) { |
Lucas Dupin | 6ea2787 | 2017-05-30 12:00:04 -0700 | [diff] [blame] | 940 | // Wrapper can be null if we were a low priority notification |
| 941 | // and just destroyed it by calling setIsLowPriority(false) |
| 942 | NotificationViewWrapper wrapper = getWrapperForView(currentHeader); |
| 943 | if (wrapper != null) { |
| 944 | wrapper.setVisible(false); |
| 945 | } |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 946 | currentHeader.setVisibility(INVISIBLE); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 947 | } |
| 948 | } |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 949 | |
| 950 | resetHeaderVisibilityIfNeeded(mNotificationHeader, desiredHeader); |
| 951 | resetHeaderVisibilityIfNeeded(mNotificationHeaderAmbient, desiredHeader); |
| 952 | resetHeaderVisibilityIfNeeded(mNotificationHeaderLowPriority, desiredHeader); |
| 953 | |
Lucas Dupin | 6ea2787 | 2017-05-30 12:00:04 -0700 | [diff] [blame] | 954 | mCurrentHeader = desiredHeader; |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | private void resetHeaderVisibilityIfNeeded(View header, View desiredHeader) { |
| 958 | if (header == null) { |
| 959 | return; |
| 960 | } |
| 961 | if (header != mCurrentHeader && header != desiredHeader) { |
| 962 | getWrapperForView(header).setVisible(false); |
| 963 | header.setVisibility(INVISIBLE); |
| 964 | } |
| 965 | if (header == desiredHeader && header.getVisibility() != VISIBLE) { |
| 966 | getWrapperForView(header).setVisible(true); |
| 967 | header.setVisibility(VISIBLE); |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | private ViewGroup calculateDesiredHeader() { |
| 972 | ViewGroup desiredHeader; |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 973 | if (mContainingNotification.isOnAmbient()) { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 974 | desiredHeader = mNotificationHeaderAmbient; |
| 975 | } else if (showingAsLowPriority()) { |
| 976 | desiredHeader = mNotificationHeaderLowPriority; |
| 977 | } else { |
| 978 | desiredHeader = mNotificationHeader; |
| 979 | } |
| 980 | return desiredHeader; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | private void startChildAlphaAnimations(boolean toVisible) { |
| 984 | float target = toVisible ? 1.0f : 0.0f; |
| 985 | float start = 1.0f - target; |
| 986 | int childCount = mChildren.size(); |
| 987 | for (int i = 0; i < childCount; i++) { |
| 988 | if (i >= NUMBER_OF_CHILDREN_WHEN_SYSTEM_EXPANDED) { |
| 989 | break; |
| 990 | } |
| 991 | ExpandableNotificationRow child = mChildren.get(i); |
| 992 | child.setAlpha(start); |
| 993 | ViewState viewState = new ViewState(); |
| 994 | viewState.initFrom(child); |
| 995 | viewState.alpha = target; |
| 996 | ALPHA_FADE_IN.setDelay(i * 50); |
| 997 | viewState.animateTo(child, ALPHA_FADE_IN); |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | |
| 1002 | private void updateHeaderTransformation() { |
Selim Cinek | 1826d98 | 2017-03-06 20:47:37 -0800 | [diff] [blame] | 1003 | if (mUserLocked && showingAsLowPriority()) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1004 | float fraction = getGroupExpandFraction(); |
| 1005 | mNotificationHeaderWrapper.transformFrom(mNotificationHeaderWrapperLowPriority, |
| 1006 | fraction); |
| 1007 | mNotificationHeader.setVisibility(VISIBLE); |
| 1008 | mNotificationHeaderWrapperLowPriority.transformTo(mNotificationHeaderWrapper, |
| 1009 | fraction); |
| 1010 | } |
| 1011 | |
| 1012 | } |
| 1013 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 1014 | private NotificationViewWrapper getWrapperForView(View visibleHeader) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1015 | if (visibleHeader == mNotificationHeader) { |
| 1016 | return mNotificationHeaderWrapper; |
| 1017 | } |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 1018 | if (visibleHeader == mNotificationHeaderAmbient) { |
| 1019 | return mNotificationHeaderWrapperAmbient; |
| 1020 | } |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1021 | return mNotificationHeaderWrapperLowPriority; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | /** |
| 1025 | * Called when a groups expansion changes to adjust the background of the header view. |
| 1026 | * |
| 1027 | * @param expanded whether the group is expanded. |
| 1028 | */ |
| 1029 | public void updateHeaderForExpansion(boolean expanded) { |
| 1030 | if (mNotificationHeader != null) { |
| 1031 | if (expanded) { |
| 1032 | ColorDrawable cd = new ColorDrawable(); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1033 | cd.setColor(mContainingNotification.calculateBgColor()); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1034 | mNotificationHeader.setHeaderBackgroundDrawable(cd); |
| 1035 | } else { |
| 1036 | mNotificationHeader.setHeaderBackgroundDrawable(null); |
| 1037 | } |
| 1038 | } |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1041 | public int getMaxContentHeight() { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1042 | if (showingAsLowPriority()) { |
| 1043 | return getMinHeight(NUMBER_OF_CHILDREN_WHEN_SYSTEM_EXPANDED, true |
| 1044 | /* likeHighPriority */); |
| 1045 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1046 | int maxContentHeight = mNotificationHeaderMargin + mCurrentHeaderTranslation |
| 1047 | + mNotificatonTopPadding; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1048 | int visibleChildren = 0; |
| 1049 | int childCount = mChildren.size(); |
| 1050 | for (int i = 0; i < childCount; i++) { |
| 1051 | if (visibleChildren >= NUMBER_OF_CHILDREN_WHEN_CHILDREN_EXPANDED) { |
| 1052 | break; |
| 1053 | } |
| 1054 | ExpandableNotificationRow child = mChildren.get(i); |
Selim Cinek | e81b82b | 2016-03-04 11:22:28 -0800 | [diff] [blame] | 1055 | float childHeight = child.isExpanded(true /* allowOnKeyguard */) |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1056 | ? child.getMaxExpandHeight() |
| 1057 | : child.getShowingLayout().getMinHeight(true /* likeGroupExpanded */); |
| 1058 | maxContentHeight += childHeight; |
| 1059 | visibleChildren++; |
| 1060 | } |
| 1061 | if (visibleChildren > 0) { |
| 1062 | maxContentHeight += visibleChildren * mDividerHeight; |
| 1063 | } |
| 1064 | return maxContentHeight; |
| 1065 | } |
| 1066 | |
| 1067 | public void setActualHeight(int actualHeight) { |
| 1068 | if (!mUserLocked) { |
| 1069 | return; |
| 1070 | } |
| 1071 | mActualHeight = actualHeight; |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 1072 | float fraction = getGroupExpandFraction(); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1073 | boolean showingLowPriority = showingAsLowPriority(); |
| 1074 | updateHeaderTransformation(); |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 1075 | int maxAllowedVisibleChildren = getMaxAllowedVisibleChildren(true /* forceCollapsed */); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1076 | int childCount = mChildren.size(); |
| 1077 | for (int i = 0; i < childCount; i++) { |
| 1078 | ExpandableNotificationRow child = mChildren.get(i); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1079 | float childHeight; |
| 1080 | if (showingLowPriority) { |
| 1081 | childHeight = child.getShowingLayout().getMinHeight(false /* likeGroupExpanded */); |
| 1082 | } else if (child.isExpanded(true /* allowOnKeyguard */)) { |
| 1083 | childHeight = child.getMaxExpandHeight(); |
| 1084 | } else { |
| 1085 | childHeight = child.getShowingLayout().getMinHeight( |
| 1086 | true /* likeGroupExpanded */); |
| 1087 | } |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 1088 | if (i < maxAllowedVisibleChildren) { |
| 1089 | float singleLineHeight = child.getShowingLayout().getMinHeight( |
| 1090 | false /* likeGroupExpanded */); |
| 1091 | child.setActualHeight((int) NotificationUtils.interpolate(singleLineHeight, |
| 1092 | childHeight, fraction), false); |
| 1093 | } else { |
| 1094 | child.setActualHeight((int) childHeight, false); |
| 1095 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 1099 | public float getGroupExpandFraction() { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1100 | int visibleChildrenExpandedHeight = showingAsLowPriority() ? getMaxContentHeight() |
| 1101 | : getVisibleChildrenExpandHeight(); |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 1102 | int minExpandHeight = getCollapsedHeight(); |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 1103 | float factor = (mActualHeight - minExpandHeight) |
| 1104 | / (float) (visibleChildrenExpandedHeight - minExpandHeight); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1105 | return Math.max(0.0f, Math.min(1.0f, factor)); |
| 1106 | } |
| 1107 | |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 1108 | private int getVisibleChildrenExpandHeight() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1109 | int intrinsicHeight = mNotificationHeaderMargin + mCurrentHeaderTranslation |
| 1110 | + mNotificatonTopPadding + mDividerHeight; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1111 | int visibleChildren = 0; |
| 1112 | int childCount = mChildren.size(); |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 1113 | int maxAllowedVisibleChildren = getMaxAllowedVisibleChildren(true /* forceCollapsed */); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1114 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 1115 | if (visibleChildren >= maxAllowedVisibleChildren) { |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1116 | break; |
| 1117 | } |
| 1118 | ExpandableNotificationRow child = mChildren.get(i); |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 1119 | float childHeight = child.isExpanded(true /* allowOnKeyguard */) |
| 1120 | ? child.getMaxExpandHeight() |
| 1121 | : child.getShowingLayout().getMinHeight(true /* likeGroupExpanded */); |
| 1122 | intrinsicHeight += childHeight; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1123 | visibleChildren++; |
| 1124 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1125 | return intrinsicHeight; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | public int getMinHeight() { |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 1129 | return getMinHeight(mContainingNotification.isOnAmbient() |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 1130 | ? NUMBER_OF_CHILDREN_WHEN_AMBIENT |
| 1131 | : NUMBER_OF_CHILDREN_WHEN_COLLAPSED, false /* likeHighPriority */); |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 1132 | } |
| 1133 | |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 1134 | public int getCollapsedHeight() { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1135 | return getMinHeight(getMaxAllowedVisibleChildren(true /* forceCollapsed */), |
| 1136 | false /* likeHighPriority */); |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1139 | /** |
| 1140 | * Get the minimum Height for this group. |
| 1141 | * |
| 1142 | * @param maxAllowedVisibleChildren the number of children that should be visible |
| 1143 | * @param likeHighPriority if the height should be calculated as if it were not low priority |
| 1144 | */ |
| 1145 | private int getMinHeight(int maxAllowedVisibleChildren, boolean likeHighPriority) { |
| 1146 | if (!likeHighPriority && showingAsLowPriority()) { |
| 1147 | return mNotificationHeaderLowPriority.getHeight(); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 1148 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1149 | int minExpandHeight = mNotificationHeaderMargin + mCurrentHeaderTranslation; |
Selim Cinek | 2c58461 | 2016-02-29 16:14:25 -0800 | [diff] [blame] | 1150 | int visibleChildren = 0; |
| 1151 | boolean firstChild = true; |
| 1152 | int childCount = mChildren.size(); |
| 1153 | for (int i = 0; i < childCount; i++) { |
| 1154 | if (visibleChildren >= maxAllowedVisibleChildren) { |
| 1155 | break; |
| 1156 | } |
| 1157 | if (!firstChild) { |
| 1158 | minExpandHeight += mChildPadding; |
| 1159 | } else { |
| 1160 | firstChild = false; |
| 1161 | } |
| 1162 | ExpandableNotificationRow child = mChildren.get(i); |
Selim Cinek | f1f270a | 2016-04-05 19:02:37 -0700 | [diff] [blame] | 1163 | minExpandHeight += child.getSingleLineView().getHeight(); |
Selim Cinek | 2c58461 | 2016-02-29 16:14:25 -0800 | [diff] [blame] | 1164 | visibleChildren++; |
| 1165 | } |
| 1166 | minExpandHeight += mCollapsedBottompadding; |
| 1167 | return minExpandHeight; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1168 | } |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 1169 | |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1170 | public boolean showingAsLowPriority() { |
| 1171 | return mIsLowPriority && !mContainingNotification.isExpanded(); |
| 1172 | } |
| 1173 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1174 | public void reInflateViews(OnClickListener listener, StatusBarNotification notification) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1175 | if (mNotificationHeader != null) { |
| 1176 | removeView(mNotificationHeader); |
| 1177 | mNotificationHeader = null; |
| 1178 | } |
| 1179 | if (mNotificationHeaderLowPriority != null) { |
| 1180 | removeView(mNotificationHeaderLowPriority); |
| 1181 | mNotificationHeaderLowPriority = null; |
| 1182 | } |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 1183 | if (mNotificationHeaderAmbient != null) { |
| 1184 | removeView(mNotificationHeaderAmbient); |
| 1185 | mNotificationHeaderAmbient = null; |
| 1186 | } |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1187 | recreateNotificationHeader(listener); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 1188 | initDimens(); |
| 1189 | for (int i = 0; i < mDividers.size(); i++) { |
| 1190 | View prevDivider = mDividers.get(i); |
| 1191 | int index = indexOfChild(prevDivider); |
| 1192 | removeView(prevDivider); |
| 1193 | View divider = inflateDivider(); |
| 1194 | addView(divider, index); |
| 1195 | mDividers.set(i, divider); |
| 1196 | } |
Selim Cinek | 4bb5934 | 2016-04-08 19:29:35 -0700 | [diff] [blame] | 1197 | removeView(mOverflowNumber); |
| 1198 | mOverflowNumber = null; |
Selim Cinek | 4bb5934 | 2016-04-08 19:29:35 -0700 | [diff] [blame] | 1199 | mGroupOverFlowState = null; |
| 1200 | updateGroupOverflow(); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 1201 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1202 | |
| 1203 | public void setUserLocked(boolean userLocked) { |
| 1204 | mUserLocked = userLocked; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1205 | if (!mUserLocked) { |
| 1206 | updateHeaderVisibility(false /* animate */); |
| 1207 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1208 | int childCount = mChildren.size(); |
| 1209 | for (int i = 0; i < childCount; i++) { |
| 1210 | ExpandableNotificationRow child = mChildren.get(i); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1211 | child.setUserLocked(userLocked && !showingAsLowPriority()); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1212 | } |
Selim Cinek | bc34215 | 2018-12-05 18:45:42 -0800 | [diff] [blame] | 1213 | updateHeaderTouchability(); |
| 1214 | } |
| 1215 | |
| 1216 | private void updateHeaderTouchability() { |
| 1217 | if (mNotificationHeader != null) { |
| 1218 | mNotificationHeader.setAcceptAllTouches(mChildrenExpanded || mUserLocked); |
| 1219 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1220 | } |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 1221 | |
| 1222 | public void onNotificationUpdated() { |
| 1223 | mHybridGroupManager.setOverflowNumberColor(mOverflowNumber, |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 1224 | mContainingNotification.getNotificationColor()); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 1225 | } |
Adrian Roos | d009ab1 | 2016-05-20 17:58:53 -0700 | [diff] [blame] | 1226 | |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1227 | public int getPositionInLinearLayout(View childInGroup) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1228 | int position = mNotificationHeaderMargin + mCurrentHeaderTranslation |
| 1229 | + mNotificatonTopPadding; |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1230 | |
| 1231 | for (int i = 0; i < mChildren.size(); i++) { |
| 1232 | ExpandableNotificationRow child = mChildren.get(i); |
| 1233 | boolean notGone = child.getVisibility() != View.GONE; |
| 1234 | if (notGone) { |
| 1235 | position += mDividerHeight; |
| 1236 | } |
| 1237 | if (child == childInGroup) { |
| 1238 | return position; |
| 1239 | } |
| 1240 | if (notGone) { |
| 1241 | position += child.getIntrinsicHeight(); |
| 1242 | } |
| 1243 | } |
| 1244 | return 0; |
| 1245 | } |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 1246 | |
| 1247 | public void setIconsVisible(boolean iconsVisible) { |
| 1248 | if (mNotificationHeaderWrapper != null) { |
| 1249 | NotificationHeaderView header = mNotificationHeaderWrapper.getNotificationHeader(); |
| 1250 | if (header != null) { |
| 1251 | header.getIcon().setForceHidden(!iconsVisible); |
| 1252 | } |
| 1253 | } |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1254 | if (mNotificationHeaderWrapperLowPriority != null) { |
| 1255 | NotificationHeaderView header |
| 1256 | = mNotificationHeaderWrapperLowPriority.getNotificationHeader(); |
| 1257 | if (header != null) { |
| 1258 | header.getIcon().setForceHidden(!iconsVisible); |
| 1259 | } |
| 1260 | } |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 1261 | } |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 1262 | |
| 1263 | public void setClipBottomAmount(int clipBottomAmount) { |
| 1264 | mClipBottomAmount = clipBottomAmount; |
| 1265 | updateChildrenClipping(); |
| 1266 | } |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 1267 | |
| 1268 | public void setIsLowPriority(boolean isLowPriority) { |
| 1269 | mIsLowPriority = isLowPriority; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1270 | if (mContainingNotification != null) { /* we're not yet set up yet otherwise */ |
| 1271 | recreateLowPriorityHeader(null /* existingBuilder */); |
| 1272 | updateHeaderVisibility(false /* animate */); |
| 1273 | } |
| 1274 | if (mUserLocked) { |
| 1275 | setUserLocked(mUserLocked); |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | public NotificationHeaderView getVisibleHeader() { |
| 1280 | NotificationHeaderView header = mNotificationHeader; |
| 1281 | if (showingAsLowPriority()) { |
| 1282 | header = mNotificationHeaderLowPriority; |
| 1283 | } |
| 1284 | return header; |
| 1285 | } |
| 1286 | |
| 1287 | public void onExpansionChanged() { |
| 1288 | if (mIsLowPriority) { |
| 1289 | if (mUserLocked) { |
| 1290 | setUserLocked(mUserLocked); |
| 1291 | } |
| 1292 | updateHeaderVisibility(true /* animate */); |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | public float getIncreasedPaddingAmount() { |
| 1297 | if (showingAsLowPriority()) { |
| 1298 | return 0.0f; |
| 1299 | } |
| 1300 | return getGroupExpandFraction(); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 1301 | } |
Selim Cinek | 817abe7 | 2017-05-24 11:08:55 -0700 | [diff] [blame] | 1302 | |
| 1303 | @VisibleForTesting |
| 1304 | public boolean isUserLocked() { |
| 1305 | return mUserLocked; |
| 1306 | } |
Selim Cinek | 2871bef | 2017-11-22 08:40:00 -0800 | [diff] [blame] | 1307 | |
| 1308 | public void setCurrentBottomRoundness(float currentBottomRoundness) { |
| 1309 | boolean last = true; |
| 1310 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 1311 | ExpandableNotificationRow child = mChildren.get(i); |
| 1312 | if (child.getVisibility() == View.GONE) { |
| 1313 | continue; |
| 1314 | } |
| 1315 | float bottomRoundness = last ? currentBottomRoundness : 0.0f; |
| 1316 | child.setBottomRoundness(bottomRoundness, isShown() /* animate */); |
| 1317 | last = false; |
| 1318 | } |
| 1319 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1320 | |
| 1321 | public void setHeaderVisibleAmount(float headerVisibleAmount) { |
| 1322 | mHeaderVisibleAmount = headerVisibleAmount; |
| 1323 | mCurrentHeaderTranslation = (int) ((1.0f - headerVisibleAmount) * mTranslationForHeader); |
| 1324 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1325 | } |