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