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