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