blob: 996e2ef587f05e71d078f2365aaecc53acda2d88 [file] [log] [blame]
Chris Wren51c75102013-07-16 20:49:17 -04001/*
2 * Copyright (C) 2013 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
17package com.android.systemui.statusbar;
18
Mady Mellor4b80b102016-01-22 08:03:58 -080019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
Mady Mellor4b80b102016-01-22 08:03:58 -080021import android.animation.ObjectAnimator;
Mady Mellor4b80b102016-01-22 08:03:58 -080022import android.animation.ValueAnimator.AnimatorUpdateListener;
Selim Cinekddf1b392016-05-27 16:33:10 -070023import android.annotation.Nullable;
Chris Wren51c75102013-07-16 20:49:17 -040024import android.content.Context;
Selim Cinekcab4a602014-09-03 14:47:57 +020025import android.graphics.drawable.AnimatedVectorDrawable;
26import android.graphics.drawable.AnimationDrawable;
Selim Cinekb5605e52015-02-20 18:21:41 +010027import android.graphics.drawable.ColorDrawable;
Selim Cinekcab4a602014-09-03 14:47:57 +020028import android.graphics.drawable.Drawable;
Selim Cinekda42d652015-12-04 15:51:16 -080029import android.os.Build;
Selim Cineke9bad242016-06-15 11:46:37 -070030import android.os.Bundle;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020031import android.service.notification.StatusBarNotification;
Chris Wren51c75102013-07-16 20:49:17 -040032import android.util.AttributeSet;
Mady Mellorb0a82462016-04-30 17:31:02 -070033import android.util.FloatProperty;
34import android.util.Property;
Selim Cinek01af3342016-02-09 19:25:31 -080035import android.view.LayoutInflater;
Selim Cinek6183d122016-01-14 18:48:41 -080036import android.view.MotionEvent;
Selim Cinekeaa29ca2015-11-23 13:51:13 -080037import android.view.NotificationHeaderView;
Dan Sandlera5e0f412014-01-23 15:11:54 -050038import android.view.View;
Selim Cinek875a3a12016-11-18 17:52:16 -080039import android.view.ViewGroup;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020040import android.view.ViewStub;
Jorim Jaggife40f7d2014-04-28 15:20:04 +020041import android.view.accessibility.AccessibilityEvent;
Selim Cineke9bad242016-06-15 11:46:37 -070042import android.view.accessibility.AccessibilityNodeInfo;
Selim Cinek98713a42015-09-21 15:47:20 +020043import android.widget.Chronometer;
Selim Cinekcab4a602014-09-03 14:47:57 +020044import android.widget.ImageView;
Selim Cinekb5605e52015-02-20 18:21:41 +010045
Chris Wren698b1702016-05-23 11:16:32 -040046import com.android.internal.logging.MetricsLogger;
Tamas Berghammer383db5eb2016-06-22 15:21:38 +010047import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Selim Cinek4bb59342016-04-08 19:29:35 -070048import com.android.internal.util.NotificationColorUtil;
Selim Cinek875a3a12016-11-18 17:52:16 -080049import com.android.internal.widget.CachingIconView;
Selim Cinek0242fbb2016-10-19 13:38:32 -070050import com.android.systemui.Interpolators;
Dan Sandlera5e0f412014-01-23 15:11:54 -050051import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070052import com.android.systemui.classifier.FalsingManager;
Selim Cinekc897bd32016-03-18 17:32:31 -070053import com.android.systemui.statusbar.notification.HybridNotificationView;
Selim Cinekb5605e52015-02-20 18:21:41 +010054import com.android.systemui.statusbar.phone.NotificationGroupManager;
Selim Cinek31aada42015-12-18 17:51:15 -080055import com.android.systemui.statusbar.policy.HeadsUpManager;
Selim Cinek0cfbef42016-11-09 19:06:36 -080056import com.android.systemui.statusbar.stack.AnimationProperties;
57import com.android.systemui.statusbar.stack.ExpandableViewState;
Selim Cinekb5605e52015-02-20 18:21:41 +010058import com.android.systemui.statusbar.stack.NotificationChildrenContainer;
Selim Cineke9bad242016-06-15 11:46:37 -070059import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Selim Cinekb5605e52015-02-20 18:21:41 +010060import com.android.systemui.statusbar.stack.StackScrollState;
Selim Cinekb5605e52015-02-20 18:21:41 +010061
Mady Mellor4b80b102016-01-22 08:03:58 -080062import java.util.ArrayList;
Selim Cinekb5605e52015-02-20 18:21:41 +010063import java.util.List;
Dan Sandlera5e0f412014-01-23 15:11:54 -050064
Jorim Jaggi4222d9a2014-04-23 16:13:15 +020065public class ExpandableNotificationRow extends ActivatableNotificationView {
Selim Cinekb5605e52015-02-20 18:21:41 +010066
67 private static final int DEFAULT_DIVIDER_ALPHA = 0x29;
68 private static final int COLORED_DIVIDER_ALPHA = 0x7B;
Selim Cinek0242fbb2016-10-19 13:38:32 -070069 private int mIconTransformContentShift;
Selim Cinek875a3a12016-11-18 17:52:16 -080070 private int mIconTransformContentShiftNoIcon;
Selim Cinek01af3342016-02-09 19:25:31 -080071 private int mNotificationMinHeightLegacy;
72 private int mMaxHeadsUpHeightLegacy;
73 private int mMaxHeadsUpHeight;
74 private int mNotificationMinHeight;
75 private int mNotificationMaxHeight;
Mady Mellorb0a82462016-04-30 17:31:02 -070076 private int mIncreasedPaddingBetweenElements;
Chris Wren51c75102013-07-16 20:49:17 -040077
Selim Cinek1685e632014-04-08 02:27:49 +020078 /** Does this row contain layouts that can adapt to row expansion */
Chris Wren51c75102013-07-16 20:49:17 -040079 private boolean mExpandable;
Selim Cinek1685e632014-04-08 02:27:49 +020080 /** Has the user actively changed the expansion state of this row */
81 private boolean mHasUserChangedExpansion;
82 /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */
Chris Wren51c75102013-07-16 20:49:17 -040083 private boolean mUserExpanded;
Selim Cinek31aada42015-12-18 17:51:15 -080084
85 /**
86 * Has this notification been expanded while it was pinned
87 */
88 private boolean mExpandedWhenPinned;
Selim Cinek1685e632014-04-08 02:27:49 +020089 /** Is the user touching this row */
Chris Wren51c75102013-07-16 20:49:17 -040090 private boolean mUserLocked;
Selim Cinek1685e632014-04-08 02:27:49 +020091 /** Are we showing the "public" version */
Dan Sandlera5e0f412014-01-23 15:11:54 -050092 private boolean mShowingPublic;
Jorim Jaggiae441282014-08-01 02:45:18 +020093 private boolean mSensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -080094 private boolean mSensitiveHiddenInGeneral;
Jorim Jaggiae441282014-08-01 02:45:18 +020095 private boolean mShowingPublicInitialized;
Selim Cinek60122be2015-04-15 18:16:50 -070096 private boolean mHideSensitiveForIntrinsicHeight;
Chris Wren51c75102013-07-16 20:49:17 -040097
Selim Cinek1685e632014-04-08 02:27:49 +020098 /**
99 * Is this notification expanded by the system. The expansion state can be overridden by the
100 * user expansion.
101 */
102 private boolean mIsSystemExpanded;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200103
104 /**
Selim Cinek83bc7832015-10-22 13:26:54 -0700105 * Whether the notification is on the keyguard and the expansion is disabled.
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200106 */
Selim Cinek83bc7832015-10-22 13:26:54 -0700107 private boolean mOnKeyguard;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200108
Mady Mellorb0a82462016-04-30 17:31:02 -0700109 private Animator mTranslateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -0800110 private ArrayList<View> mTranslateableViews;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200111 private NotificationContentView mPublicLayout;
112 private NotificationContentView mPrivateLayout;
Selim Cinek1685e632014-04-08 02:27:49 +0200113 private int mMaxExpandHeight;
Selim Cinek8d490d42015-04-10 00:05:50 -0700114 private int mHeadsUpHeight;
Selim Cinek863834b2014-05-20 04:20:25 +0200115 private View mVetoButton;
Selim Cinek4bb59342016-04-08 19:29:35 -0700116 private int mNotificationColor;
Chris Wren78403d72014-07-28 10:23:24 +0100117 private ExpansionLogger mLogger;
118 private String mLoggingKey;
Mady Mellor4b80b102016-01-22 08:03:58 -0800119 private NotificationSettingsIconRow mSettingsIconRow;
Selim Cinek8d490d42015-04-10 00:05:50 -0700120 private NotificationGuts mGuts;
Selim Cinekda42d652015-12-04 15:51:16 -0800121 private NotificationData.Entry mEntry;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200122 private StatusBarNotification mStatusBarNotification;
Mady Mellor3fd273e2016-03-15 21:08:14 -0700123 private String mAppName;
Selim Cinek1a521f32014-11-03 17:39:29 +0100124 private boolean mIsHeadsUp;
Selim Cinek98713a42015-09-21 15:47:20 +0200125 private boolean mLastChronometerRunning = true;
Selim Cinekb5605e52015-02-20 18:21:41 +0100126 private ViewStub mChildrenContainerStub;
127 private NotificationGroupManager mGroupManager;
Selim Cinekb5605e52015-02-20 18:21:41 +0100128 private boolean mChildrenExpanded;
Selim Cinek263398f2015-10-21 17:40:23 -0700129 private boolean mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100130 private NotificationChildrenContainer mChildrenContainer;
Mady Mellor4b80b102016-01-22 08:03:58 -0800131 private ViewStub mSettingsIconRowStub;
Selim Cinekab29aeb2015-02-20 18:18:32 +0100132 private ViewStub mGutsStub;
Selim Cinekb5605e52015-02-20 18:21:41 +0100133 private boolean mIsSystemChildExpanded;
Selim Cinek684a4422015-04-15 16:18:39 -0700134 private boolean mIsPinned;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700135 private FalsingManager mFalsingManager;
Selim Cinek31aada42015-12-18 17:51:15 -0800136 private HeadsUpManager mHeadsUpManager;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200137
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700138 private boolean mJustClicked;
Selim Cinek5a175d92015-11-23 18:01:33 -0800139 private boolean mIconAnimationRunning;
Selim Cinek34d93b02015-10-22 12:30:38 -0700140 private boolean mShowNoBackground;
Selim Cinek388df6d2015-10-22 13:25:11 -0700141 private ExpandableNotificationRow mNotificationParent;
Selim Cinek570981d2015-12-01 11:37:01 -0800142 private OnExpandClickListener mOnExpandClickListener;
Mady Mellorb0a82462016-04-30 17:31:02 -0700143 private boolean mGroupExpansionChanging;
144
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800145 private OnClickListener mExpandClickListener = new OnClickListener() {
146 @Override
147 public void onClick(View v) {
Selim Cinek624c02db2015-12-14 21:00:02 -0800148 if (!mShowingPublic && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) {
Mady Mellor1a5d8ea2016-06-09 10:42:42 -0700149 mGroupExpansionChanging = true;
Chris Wren698b1702016-05-23 11:16:32 -0400150 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
151 boolean nowExpanded = mGroupManager.toggleGroupExpansion(mStatusBarNotification);
152 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400153 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_GROUP_EXPANDER,
154 nowExpanded);
155 logExpansionEvent(true /* userAction */, wasExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800156 } else {
Selim Cineke9bad242016-06-15 11:46:37 -0700157 if (v.isAccessibilityFocused()) {
158 mPrivateLayout.setFocusOnVisibilityChange();
159 }
Selim Cinek31aada42015-12-18 17:51:15 -0800160 boolean nowExpanded;
161 if (isPinned()) {
162 nowExpanded = !mExpandedWhenPinned;
163 mExpandedWhenPinned = nowExpanded;
164 } else {
165 nowExpanded = !isExpanded();
166 setUserExpanded(nowExpanded);
167 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800168 notifyHeightChanged(true);
Selim Cinek31aada42015-12-18 17:51:15 -0800169 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400170 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_EXPANDER,
171 nowExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800172 }
173 }
174 };
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700175 private boolean mForceUnlocked;
Selim Cinek3f19f602016-05-02 18:01:56 -0700176 private boolean mDismissed;
177 private boolean mKeepInParent;
178 private boolean mRemoved;
Mady Mellorb0a82462016-04-30 17:31:02 -0700179 private static final Property<ExpandableNotificationRow, Float> TRANSLATE_CONTENT =
180 new FloatProperty<ExpandableNotificationRow>("translate") {
181 @Override
182 public void setValue(ExpandableNotificationRow object, float value) {
183 object.setTranslation(value);
184 }
185
186 @Override
187 public Float get(ExpandableNotificationRow object) {
188 return object.getTranslation();
189 }
190 };
Selim Cinekddf1b392016-05-27 16:33:10 -0700191 private OnClickListener mOnClickListener;
Selim Cinek73cf02a2016-06-17 13:08:00 -0700192 private boolean mHeadsupDisappearRunning;
Selim Cineke9bad242016-06-15 11:46:37 -0700193 private View mChildAfterViewWhenDismissed;
194 private View mGroupParentWhenDismissed;
195 private boolean mRefocusOnDismiss;
Selim Cinek2b549f42016-11-22 16:38:51 -0800196 private float mContentTransformationAmount;
Selim Cinek0242fbb2016-10-19 13:38:32 -0700197 private boolean mIconsVisible = true;
Selim Cinekd127d792016-11-01 19:11:41 -0700198 private boolean mAboveShelf;
Selim Cinek875a3a12016-11-18 17:52:16 -0800199 private boolean mIsLastChild;
Mady Mellorb0a82462016-04-30 17:31:02 -0700200
201 public boolean isGroupExpansionChanging() {
202 if (isChildInGroup()) {
203 return mNotificationParent.isGroupExpansionChanging();
204 }
205 return mGroupExpansionChanging;
206 }
207
208 public void setGroupExpansionChanging(boolean changing) {
209 mGroupExpansionChanging = changing;
210 }
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700211
Adrian Roos599be342016-06-13 14:54:39 -0700212 @Override
213 public void setActualHeightAnimating(boolean animating) {
214 if (mPrivateLayout != null) {
215 mPrivateLayout.setContentHeightAnimating(animating);
216 }
217 }
218
Selim Cinek8d490d42015-04-10 00:05:50 -0700219 public NotificationContentView getPrivateLayout() {
220 return mPrivateLayout;
221 }
222
223 public NotificationContentView getPublicLayout() {
224 return mPublicLayout;
225 }
226
Selim Cinekcab4a602014-09-03 14:47:57 +0200227 public void setIconAnimationRunning(boolean running) {
228 setIconAnimationRunning(running, mPublicLayout);
229 setIconAnimationRunning(running, mPrivateLayout);
Selim Cinek5a175d92015-11-23 18:01:33 -0800230 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700231 setIconAnimationRunningForChild(running, mChildrenContainer.getHeaderView());
Selim Cinek5a175d92015-11-23 18:01:33 -0800232 List<ExpandableNotificationRow> notificationChildren =
233 mChildrenContainer.getNotificationChildren();
234 for (int i = 0; i < notificationChildren.size(); i++) {
235 ExpandableNotificationRow child = notificationChildren.get(i);
236 child.setIconAnimationRunning(running);
237 }
238 }
239 mIconAnimationRunning = running;
Selim Cinekcab4a602014-09-03 14:47:57 +0200240 }
241
242 private void setIconAnimationRunning(boolean running, NotificationContentView layout) {
243 if (layout != null) {
244 View contractedChild = layout.getContractedChild();
245 View expandedChild = layout.getExpandedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -0700246 View headsUpChild = layout.getHeadsUpChild();
Selim Cinekcab4a602014-09-03 14:47:57 +0200247 setIconAnimationRunningForChild(running, contractedChild);
248 setIconAnimationRunningForChild(running, expandedChild);
Selim Cinek8d490d42015-04-10 00:05:50 -0700249 setIconAnimationRunningForChild(running, headsUpChild);
Selim Cinekcab4a602014-09-03 14:47:57 +0200250 }
251 }
252
253 private void setIconAnimationRunningForChild(boolean running, View child) {
254 if (child != null) {
255 ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon);
256 setIconRunning(icon, running);
257 ImageView rightIcon = (ImageView) child.findViewById(
258 com.android.internal.R.id.right_icon);
259 setIconRunning(rightIcon, running);
260 }
261 }
262
263 private void setIconRunning(ImageView imageView, boolean running) {
264 if (imageView != null) {
265 Drawable drawable = imageView.getDrawable();
266 if (drawable instanceof AnimationDrawable) {
267 AnimationDrawable animationDrawable = (AnimationDrawable) drawable;
268 if (running) {
269 animationDrawable.start();
270 } else {
271 animationDrawable.stop();
272 }
273 } else if (drawable instanceof AnimatedVectorDrawable) {
274 AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable;
275 if (running) {
276 animationDrawable.start();
277 } else {
278 animationDrawable.stop();
279 }
280 }
281 }
282 }
283
Selim Cinekda42d652015-12-04 15:51:16 -0800284 public void onNotificationUpdated(NotificationData.Entry entry) {
285 mEntry = entry;
286 mStatusBarNotification = entry.notification;
Adrian Roosb88b1a12015-12-09 18:51:05 -0800287 mPrivateLayout.onNotificationUpdated(entry);
288 mPublicLayout.onNotificationUpdated(entry);
Selim Cinek757d8792016-01-28 16:21:08 -0800289 mShowingPublicInitialized = false;
Selim Cinek4bb59342016-04-08 19:29:35 -0700290 updateNotificationColor();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800291 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700292 mChildrenContainer.recreateNotificationHeader(mExpandClickListener, mEntry.notification);
Selim Cinekc897bd32016-03-18 17:32:31 -0700293 mChildrenContainer.onNotificationUpdated();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800294 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800295 if (mIconAnimationRunning) {
296 setIconAnimationRunning(true);
297 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800298 if (mNotificationParent != null) {
299 mNotificationParent.updateChildrenHeaderAppearance();
300 }
Selim Cinek263398f2015-10-21 17:40:23 -0700301 onChildrenCountChanged();
Selim Cinek624c02db2015-12-14 21:00:02 -0800302 // The public layouts expand button is always visible
303 mPublicLayout.updateExpandButtons(true);
Selim Cinekda42d652015-12-04 15:51:16 -0800304 updateLimits();
Selim Cinek0242fbb2016-10-19 13:38:32 -0700305 updateIconVisibilities();
Selim Cinekda42d652015-12-04 15:51:16 -0800306 }
307
308 private void updateLimits() {
Selim Cineka1744872016-03-11 15:36:06 -0800309 updateLimitsForView(mPrivateLayout);
310 updateLimitsForView(mPublicLayout);
311 }
312
313 private void updateLimitsForView(NotificationContentView layout) {
314 boolean customView = layout.getContractedChild().getId()
Selim Cinekda42d652015-12-04 15:51:16 -0800315 != com.android.internal.R.id.status_bar_latest_event_content;
316 boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N;
317 int minHeight = customView && beforeN && !mIsSummaryWithChildren ?
318 mNotificationMinHeightLegacy : mNotificationMinHeight;
Selim Cineka1744872016-03-11 15:36:06 -0800319 boolean headsUpCustom = layout.getHeadsUpChild() != null &&
320 layout.getHeadsUpChild().getId()
321 != com.android.internal.R.id.status_bar_latest_event_content;
Selim Cinek77019c72015-12-09 10:18:02 -0800322 int headsUpheight = headsUpCustom && beforeN ? mMaxHeadsUpHeightLegacy
323 : mMaxHeadsUpHeight;
Selim Cineka1744872016-03-11 15:36:06 -0800324 layout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200325 }
326
327 public StatusBarNotification getStatusBarNotification() {
328 return mStatusBarNotification;
329 }
330
Selim Cinek281c2022016-10-13 19:14:43 -0700331 public NotificationData.Entry getEntry() {
332 return mEntry;
333 }
334
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700335 public boolean isHeadsUp() {
336 return mIsHeadsUp;
337 }
338
Selim Cinek1a521f32014-11-03 17:39:29 +0100339 public void setHeadsUp(boolean isHeadsUp) {
Selim Cinekc80fdb12015-04-13 15:09:08 -0700340 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek1a521f32014-11-03 17:39:29 +0100341 mIsHeadsUp = isHeadsUp;
Selim Cinek8d490d42015-04-10 00:05:50 -0700342 mPrivateLayout.setHeadsUp(isHeadsUp);
Selim Cinekb41b2f62016-04-26 14:03:29 -0700343 if (mIsSummaryWithChildren) {
344 // The overflow might change since we allow more lines as HUN.
345 mChildrenContainer.updateGroupOverflow();
346 }
Selim Cinekc80fdb12015-04-13 15:09:08 -0700347 if (intrinsicBefore != getIntrinsicHeight()) {
348 notifyHeightChanged(false /* needsAnimation */);
349 }
Selim Cinekd127d792016-11-01 19:11:41 -0700350 if (isHeadsUp) {
351 setAboveShelf(true);
352 }
Selim Cinek1a521f32014-11-03 17:39:29 +0100353 }
354
Selim Cinekb5605e52015-02-20 18:21:41 +0100355 public void setGroupManager(NotificationGroupManager groupManager) {
356 mGroupManager = groupManager;
Selim Cinek83bc7832015-10-22 13:26:54 -0700357 mPrivateLayout.setGroupManager(groupManager);
Selim Cinekb5605e52015-02-20 18:21:41 +0100358 }
359
Adrian Roosb88b1a12015-12-09 18:51:05 -0800360 public void setRemoteInputController(RemoteInputController r) {
361 mPrivateLayout.setRemoteInputController(r);
362 }
363
Mady Mellor3fd273e2016-03-15 21:08:14 -0700364 public void setAppName(String appName) {
365 mAppName = appName;
366 if (mSettingsIconRow != null) {
367 mSettingsIconRow.setAppName(mAppName);
368 }
369 }
370
Selim Cinekb5605e52015-02-20 18:21:41 +0100371 public void addChildNotification(ExpandableNotificationRow row) {
372 addChildNotification(row, -1);
373 }
374
375 /**
376 * Add a child notification to this view.
377 *
378 * @param row the row to add
379 * @param childIndex the index to add it at, if -1 it will be added at the end
380 */
381 public void addChildNotification(ExpandableNotificationRow row, int childIndex) {
382 if (mChildrenContainer == null) {
383 mChildrenContainerStub.inflate();
384 }
385 mChildrenContainer.addNotification(row, childIndex);
Selim Cinek263398f2015-10-21 17:40:23 -0700386 onChildrenCountChanged();
387 row.setIsChildInGroup(true, this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100388 }
389
390 public void removeChildNotification(ExpandableNotificationRow row) {
391 if (mChildrenContainer != null) {
392 mChildrenContainer.removeNotification(row);
393 }
Selim Cinek263398f2015-10-21 17:40:23 -0700394 onChildrenCountChanged();
395 row.setIsChildInGroup(false, null);
396 }
397
398 public boolean isChildInGroup() {
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700399 return mNotificationParent != null;
Selim Cinek263398f2015-10-21 17:40:23 -0700400 }
401
Selim Cinek388df6d2015-10-22 13:25:11 -0700402 public ExpandableNotificationRow getNotificationParent() {
403 return mNotificationParent;
404 }
405
Selim Cinek263398f2015-10-21 17:40:23 -0700406 /**
407 * @param isChildInGroup Is this notification now in a group
408 * @param parent the new parent notification
409 */
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700410 public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {;
411 boolean childInGroup = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup;
412 mNotificationParent = childInGroup ? parent : null;
413 mPrivateLayout.setIsChildInGroup(childInGroup);
Mady Mellorc7d65b42016-05-04 11:44:57 -0400414 resetBackgroundAlpha();
Mady Mellorb0a82462016-04-30 17:31:02 -0700415 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -0700416 updateClickAndFocus();
Mady Mellorb0a82462016-04-30 17:31:02 -0700417 if (mNotificationParent != null) {
418 mNotificationParent.updateBackgroundForGroupState();
419 }
Selim Cinekdb167372016-11-17 15:41:17 -0800420 updateIconVisibilities();
Selim Cinek34d93b02015-10-22 12:30:38 -0700421 }
422
423 @Override
Selim Cinek72109472016-01-15 16:33:22 -0800424 public boolean onTouchEvent(MotionEvent event) {
425 if (event.getActionMasked() != MotionEvent.ACTION_DOWN
426 || !isChildInGroup() || isGroupExpanded()) {
427 return super.onTouchEvent(event);
428 } else {
429 return false;
430 }
431 }
432
433 @Override
Mady Mellorf0625802016-02-11 18:03:48 -0800434 protected boolean handleSlideBack() {
435 if (mSettingsIconRow != null && mSettingsIconRow.isVisible()) {
436 animateTranslateNotification(0 /* targetLeft */);
437 return true;
438 }
439 return false;
440 }
441
442 @Override
Selim Cinek34d93b02015-10-22 12:30:38 -0700443 protected boolean shouldHideBackground() {
444 return super.shouldHideBackground() || mShowNoBackground;
Selim Cinek263398f2015-10-21 17:40:23 -0700445 }
446
447 @Override
448 public boolean isSummaryWithChildren() {
449 return mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100450 }
451
452 @Override
453 public boolean areChildrenExpanded() {
454 return mChildrenExpanded;
455 }
456
457 public List<ExpandableNotificationRow> getNotificationChildren() {
458 return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren();
459 }
460
Selim Cinekeef84282015-10-30 16:28:00 -0700461 public int getNumberOfNotificationChildren() {
462 if (mChildrenContainer == null) {
463 return 0;
464 }
465 return mChildrenContainer.getNotificationChildren().size();
466 }
467
Selim Cinekb5605e52015-02-20 18:21:41 +0100468 /**
469 * Apply the order given in the list to the children.
470 *
471 * @param childOrder the new list order
472 * @return whether the list order has changed
473 */
474 public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder) {
475 return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder);
476 }
477
478 public void getChildrenStates(StackScrollState resultState) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700479 if (mIsSummaryWithChildren) {
Selim Cinekbbcebde2016-11-09 18:28:20 -0800480 ExpandableViewState parentState = resultState.getViewStateForView(this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100481 mChildrenContainer.getState(resultState, parentState);
482 }
483 }
484
485 public void applyChildrenState(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700486 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100487 mChildrenContainer.applyState(state);
488 }
489 }
490
491 public void prepareExpansionChanged(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700492 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100493 mChildrenContainer.prepareExpansionChanged(state);
494 }
495 }
496
Selim Cinek0cfbef42016-11-09 19:06:36 -0800497 public void startChildAnimation(StackScrollState finalState, AnimationProperties properties) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700498 if (mIsSummaryWithChildren) {
Selim Cinek0cfbef42016-11-09 19:06:36 -0800499 mChildrenContainer.startAnimationToState(finalState, properties);
Selim Cinekb5605e52015-02-20 18:21:41 +0100500 }
501 }
502
503 public ExpandableNotificationRow getViewAtPosition(float y) {
Selim Cinek43d30f02016-03-04 10:51:32 -0800504 if (!mIsSummaryWithChildren || !mChildrenExpanded) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100505 return this;
506 } else {
507 ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y);
508 return view == null ? this : view;
509 }
510 }
511
Selim Cinekab29aeb2015-02-20 18:18:32 +0100512 public NotificationGuts getGuts() {
513 return mGuts;
514 }
515
Selim Cinek684a4422015-04-15 16:18:39 -0700516 /**
517 * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this
518 * the notification will be rendered on top of the screen.
519 *
520 * @param pinned whether it is pinned
521 */
522 public void setPinned(boolean pinned) {
Selim Cinekdef35a82016-05-03 15:52:51 -0700523 int intrinsicHeight = getIntrinsicHeight();
Selim Cinek684a4422015-04-15 16:18:39 -0700524 mIsPinned = pinned;
Selim Cinekdef35a82016-05-03 15:52:51 -0700525 if (intrinsicHeight != getIntrinsicHeight()) {
Selim Cinekbb42b7d2016-08-10 13:02:38 -0700526 notifyHeightChanged(false /* needsAnimation */);
Selim Cinekdef35a82016-05-03 15:52:51 -0700527 }
Selim Cinek31aada42015-12-18 17:51:15 -0800528 if (pinned) {
529 setIconAnimationRunning(true);
530 mExpandedWhenPinned = false;
531 } else if (mExpandedWhenPinned) {
532 setUserExpanded(true);
533 }
Selim Cinek98713a42015-09-21 15:47:20 +0200534 setChronometerRunning(mLastChronometerRunning);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700535 }
536
Selim Cinek684a4422015-04-15 16:18:39 -0700537 public boolean isPinned() {
538 return mIsPinned;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700539 }
540
Selim Cinekd127d792016-11-01 19:11:41 -0700541 @Override
542 public int getPinnedHeadsUpHeight() {
543 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
544 }
545
Selim Cinek31aada42015-12-18 17:51:15 -0800546 /**
547 * @param atLeastMinHeight should the value returned be at least the minimum height.
548 * Used to avoid cyclic calls
549 * @return the height of the heads up notification when pinned
550 */
Selim Cinekd127d792016-11-01 19:11:41 -0700551 private int getPinnedHeadsUpHeight(boolean atLeastMinHeight) {
Selim Cinek77019c72015-12-09 10:18:02 -0800552 if (mIsSummaryWithChildren) {
553 return mChildrenContainer.getIntrinsicHeight();
554 }
Selim Cinek31aada42015-12-18 17:51:15 -0800555 if(mExpandedWhenPinned) {
556 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
557 } else if (atLeastMinHeight) {
Selim Cinek567e8452016-03-24 10:54:56 -0700558 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek31aada42015-12-18 17:51:15 -0800559 } else {
560 return mHeadsUpHeight;
561 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700562 }
563
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700564 /**
565 * Mark whether this notification was just clicked, i.e. the user has just clicked this
566 * notification in this frame.
567 */
568 public void setJustClicked(boolean justClicked) {
569 mJustClicked = justClicked;
570 }
571
572 /**
573 * @return true if this notification has been clicked in this frame, false otherwise
574 */
575 public boolean wasJustClicked() {
576 return mJustClicked;
577 }
578
Selim Cinek98713a42015-09-21 15:47:20 +0200579 public void setChronometerRunning(boolean running) {
580 mLastChronometerRunning = running;
581 setChronometerRunning(running, mPrivateLayout);
582 setChronometerRunning(running, mPublicLayout);
583 if (mChildrenContainer != null) {
584 List<ExpandableNotificationRow> notificationChildren =
585 mChildrenContainer.getNotificationChildren();
586 for (int i = 0; i < notificationChildren.size(); i++) {
587 ExpandableNotificationRow child = notificationChildren.get(i);
588 child.setChronometerRunning(running);
589 }
590 }
591 }
592
593 private void setChronometerRunning(boolean running, NotificationContentView layout) {
594 if (layout != null) {
595 running = running || isPinned();
596 View contractedChild = layout.getContractedChild();
597 View expandedChild = layout.getExpandedChild();
598 View headsUpChild = layout.getHeadsUpChild();
599 setChronometerRunningForChild(running, contractedChild);
600 setChronometerRunningForChild(running, expandedChild);
601 setChronometerRunningForChild(running, headsUpChild);
602 }
603 }
604
605 private void setChronometerRunningForChild(boolean running, View child) {
606 if (child != null) {
607 View chronometer = child.findViewById(com.android.internal.R.id.chronometer);
608 if (chronometer instanceof Chronometer) {
609 ((Chronometer) chronometer).setStarted(running);
610 }
611 }
612 }
613
Selim Cinekea4bef72015-12-02 15:51:10 -0800614 public NotificationHeaderView getNotificationHeader() {
Mady Mellorb0a82462016-04-30 17:31:02 -0700615 if (mIsSummaryWithChildren) {
616 return mChildrenContainer.getHeaderView();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700617 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800618 return mPrivateLayout.getNotificationHeader();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700619 }
620
Selim Cinek34eda5e2016-02-18 17:10:43 -0800621 private NotificationHeaderView getVisibleNotificationHeader() {
Selim Cinekaa3901a2016-08-05 11:04:37 -0700622 if (mIsSummaryWithChildren && !mShowingPublic) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700623 return mChildrenContainer.getHeaderView();
Selim Cinek34eda5e2016-02-18 17:10:43 -0800624 }
625 return getShowingLayout().getVisibleNotificationHeader();
626 }
627
Selim Cinek570981d2015-12-01 11:37:01 -0800628 public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) {
629 mOnExpandClickListener = onExpandClickListener;
630 }
631
Selim Cinekddf1b392016-05-27 16:33:10 -0700632 @Override
633 public void setOnClickListener(@Nullable OnClickListener l) {
634 super.setOnClickListener(l);
635 mOnClickListener = l;
636 updateClickAndFocus();
637 }
638
639 private void updateClickAndFocus() {
640 boolean normalChild = !isChildInGroup() || isGroupExpanded();
641 boolean clickable = mOnClickListener != null && normalChild;
642 if (isFocusable() != normalChild) {
643 setFocusable(normalChild);
644 }
645 if (isClickable() != clickable) {
646 setClickable(clickable);
647 }
648 }
649
Selim Cinek31aada42015-12-18 17:51:15 -0800650 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
651 mHeadsUpManager = headsUpManager;
652 }
653
Selim Cinek01af3342016-02-09 19:25:31 -0800654 public void reInflateViews() {
655 initDimens();
656 if (mIsSummaryWithChildren) {
Selim Cinek01af3342016-02-09 19:25:31 -0800657 if (mChildrenContainer != null) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700658 mChildrenContainer.reInflateViews(mExpandClickListener, mEntry.notification);
Selim Cinek01af3342016-02-09 19:25:31 -0800659 }
660 }
661 if (mGuts != null) {
662 View oldGuts = mGuts;
663 int index = indexOfChild(oldGuts);
664 removeView(oldGuts);
665 mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate(
666 R.layout.notification_guts, this, false);
667 mGuts.setVisibility(oldGuts.getVisibility());
668 addView(mGuts, index);
669 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800670 if (mSettingsIconRow != null) {
671 View oldSettings = mSettingsIconRow;
672 int settingsIndex = indexOfChild(oldSettings);
673 removeView(oldSettings);
674 mSettingsIconRow = (NotificationSettingsIconRow) LayoutInflater.from(mContext).inflate(
675 R.layout.notification_settings_icon_row, this, false);
676 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
Mady Mellor3fd273e2016-03-15 21:08:14 -0700677 mSettingsIconRow.setAppName(mAppName);
Mady Mellor4b80b102016-01-22 08:03:58 -0800678 mSettingsIconRow.setVisibility(oldSettings.getVisibility());
679 addView(mSettingsIconRow, settingsIndex);
680
681 }
Selim Cinekde33a4a2016-02-11 16:43:41 -0800682 mPrivateLayout.reInflateViews();
683 mPublicLayout.reInflateViews();
Selim Cinek01af3342016-02-09 19:25:31 -0800684 }
685
Selim Cinekc3179332016-03-04 14:44:56 -0800686 public void setContentBackground(int customBackgroundColor, boolean animate,
687 NotificationContentView notificationContentView) {
688 if (getShowingLayout() == notificationContentView) {
689 setTintColor(customBackgroundColor, animate);
690 }
691 }
692
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700693 public void closeRemoteInput() {
694 mPrivateLayout.closeRemoteInput();
695 mPublicLayout.closeRemoteInput();
696 }
697
Selim Cinekc897bd32016-03-18 17:32:31 -0700698 /**
699 * Set by how much the single line view should be indented.
700 */
701 public void setSingleLineWidthIndention(int indention) {
702 mPrivateLayout.setSingleLineWidthIndention(indention);
703 }
704
705 public int getNotificationColor() {
Selim Cinek4bb59342016-04-08 19:29:35 -0700706 return mNotificationColor;
707 }
708
709 private void updateNotificationColor() {
710 mNotificationColor = NotificationColorUtil.resolveContrastColor(mContext,
711 getStatusBarNotification().getNotification().color);
Selim Cinekc897bd32016-03-18 17:32:31 -0700712 }
713
714 public HybridNotificationView getSingleLineView() {
715 return mPrivateLayout.getSingleLineView();
716 }
717
Selim Cinekf07d0622016-03-21 19:52:52 -0700718 public boolean isOnKeyguard() {
719 return mOnKeyguard;
720 }
721
Selim Cinekc1e389d2016-04-07 11:02:57 -0700722 public void removeAllChildren() {
723 List<ExpandableNotificationRow> notificationChildren
724 = mChildrenContainer.getNotificationChildren();
725 ArrayList<ExpandableNotificationRow> clonedList = new ArrayList<>(notificationChildren);
726 for (int i = 0; i < clonedList.size(); i++) {
727 ExpandableNotificationRow row = clonedList.get(i);
Selim Cinek3f19f602016-05-02 18:01:56 -0700728 if (row.keepInParent()) {
729 continue;
730 }
Selim Cinekc1e389d2016-04-07 11:02:57 -0700731 mChildrenContainer.removeNotification(row);
Selim Cinekc1e389d2016-04-07 11:02:57 -0700732 row.setIsChildInGroup(false, null);
733 }
734 onChildrenCountChanged();
735 }
736
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700737 public void setForceUnlocked(boolean forceUnlocked) {
738 mForceUnlocked = forceUnlocked;
739 if (mIsSummaryWithChildren) {
740 List<ExpandableNotificationRow> notificationChildren = getNotificationChildren();
741 for (ExpandableNotificationRow child : notificationChildren) {
742 child.setForceUnlocked(forceUnlocked);
743 }
744 }
745 }
746
Selim Cineke9bad242016-06-15 11:46:37 -0700747 public void setDismissed(boolean dismissed, boolean fromAccessibility) {
Selim Cinek3f19f602016-05-02 18:01:56 -0700748 mDismissed = dismissed;
Selim Cineke9bad242016-06-15 11:46:37 -0700749 mGroupParentWhenDismissed = mNotificationParent;
750 mRefocusOnDismiss = fromAccessibility;
751 mChildAfterViewWhenDismissed = null;
752 if (isChildInGroup()) {
753 List<ExpandableNotificationRow> notificationChildren =
754 mNotificationParent.getNotificationChildren();
755 int i = notificationChildren.indexOf(this);
756 if (i != -1 && i < notificationChildren.size() - 1) {
757 mChildAfterViewWhenDismissed = notificationChildren.get(i + 1);
758 }
759 }
Selim Cinek3f19f602016-05-02 18:01:56 -0700760 }
761
762 public boolean isDismissed() {
763 return mDismissed;
764 }
765
766 public boolean keepInParent() {
767 return mKeepInParent;
768 }
769
770 public void setKeepInParent(boolean keepInParent) {
771 mKeepInParent = keepInParent;
772 }
773
774 public boolean isRemoved() {
775 return mRemoved;
776 }
777
Adrian Roosd009ab12016-05-20 17:58:53 -0700778 public void setRemoved() {
779 mRemoved = true;
780
781 mPrivateLayout.setRemoved();
Selim Cinek3f19f602016-05-02 18:01:56 -0700782 }
783
Selim Cinekd1395642016-04-28 12:22:42 -0700784 public NotificationChildrenContainer getChildrenContainer() {
785 return mChildrenContainer;
786 }
787
Selim Cinekcafa87f2016-10-26 17:00:17 -0700788 public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) {
789 mHeadsupDisappearRunning = headsUpAnimatingAway;
790 mPrivateLayout.setHeadsUpAnimatingAway(headsUpAnimatingAway);
791 }
792
793 /**
794 * @return if the view was just heads upped and is now animating away. During such a time the
795 * layout needs to be kept consistent
796 */
797 public boolean isHeadsUpAnimatingAway() {
798 return mHeadsupDisappearRunning;
Selim Cinek73cf02a2016-06-17 13:08:00 -0700799 }
800
Selim Cineke9bad242016-06-15 11:46:37 -0700801 public View getChildAfterViewWhenDismissed() {
802 return mChildAfterViewWhenDismissed;
803 }
804
805 public View getGroupParentWhenDismissed() {
806 return mGroupParentWhenDismissed;
807 }
808
Selim Cinek9e624e72016-07-20 13:46:49 -0700809 public void performDismiss() {
810 mVetoButton.performClick();
811 }
812
813 public void setOnDismissListener(OnClickListener listener) {
814 mVetoButton.setOnClickListener(listener);
815 }
816
Selim Cinek281c2022016-10-13 19:14:43 -0700817 public View getNotificationIcon() {
818 NotificationHeaderView notificationHeader = getNotificationHeader();
819 if (notificationHeader != null) {
820 return notificationHeader.getIcon();
821 }
822 return null;
823 }
824
825 /**
826 * @return whether the notification is currently showing a view with an icon.
827 */
828 public boolean isShowingIcon() {
829 if (mIsSummaryWithChildren) {
830 return true;
831 }
832 NotificationContentView showingLayout = getShowingLayout();
833 NotificationHeaderView notificationHeader = showingLayout.getVisibleNotificationHeader();
834 return notificationHeader != null;
835 }
836
Selim Cinek0242fbb2016-10-19 13:38:32 -0700837 /**
838 * Set how much this notification is transformed into an icon.
839 *
Selim Cinek2b549f42016-11-22 16:38:51 -0800840 * @param contentTransformationAmount A value from 0 to 1 indicating how much we are transformed
841 * to the content away
Selim Cinek875a3a12016-11-18 17:52:16 -0800842 * @param isLastChild is this the last child in the list. If true, then the transformation is
843 * different since it's content fades out.
Selim Cinek0242fbb2016-10-19 13:38:32 -0700844 */
Selim Cinek2b549f42016-11-22 16:38:51 -0800845 public void setContentTransformationAmount(float contentTransformationAmount,
846 boolean isLastChild) {
Selim Cinek875a3a12016-11-18 17:52:16 -0800847 boolean changeTransformation = isLastChild != mIsLastChild;
Selim Cinek2b549f42016-11-22 16:38:51 -0800848 changeTransformation |= mContentTransformationAmount != contentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -0800849 mIsLastChild = isLastChild;
Selim Cinek2b549f42016-11-22 16:38:51 -0800850 mContentTransformationAmount = contentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -0800851 if (changeTransformation) {
852 updateContentTransformation();
Selim Cinek2b549f42016-11-22 16:38:51 -0800853 }
854 }
855
856 /**
857 * Set the icons to be visible of this notification.
858 */
859 public void setIconsVisible(boolean iconsVisible) {
860 if (iconsVisible != mIconsVisible) {
861 mIconsVisible = iconsVisible;
862 updateIconVisibilities();
Selim Cinek0242fbb2016-10-19 13:38:32 -0700863 }
864 }
865
Selim Cinekdb167372016-11-17 15:41:17 -0800866 @Override
867 protected void onBelowSpeedBumpChanged() {
868 updateIconVisibilities();
869 }
870
Selim Cinek875a3a12016-11-18 17:52:16 -0800871 private void updateContentTransformation() {
872 float contentAlpha;
Selim Cinek2b549f42016-11-22 16:38:51 -0800873 float translationY = -mContentTransformationAmount * mIconTransformContentShift;
Selim Cinek875a3a12016-11-18 17:52:16 -0800874 if (mIsLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -0800875 contentAlpha = 1.0f - mContentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -0800876 contentAlpha = Math.min(contentAlpha / 0.5f, 1.0f);
Selim Cinek0242fbb2016-10-19 13:38:32 -0700877 contentAlpha = Interpolators.ALPHA_OUT.getInterpolation(contentAlpha);
Selim Cinek875a3a12016-11-18 17:52:16 -0800878 translationY *= 0.4f;
879 } else {
880 contentAlpha = 1.0f;
881 }
882 mPublicLayout.setAlpha(contentAlpha);
883 mPrivateLayout.setAlpha(contentAlpha);
884 mPublicLayout.setTranslationY(translationY);
885 mPrivateLayout.setTranslationY(translationY);
886 if (mChildrenContainer != null) {
887 mChildrenContainer.setAlpha(contentAlpha);
888 mChildrenContainer.setTranslationY(translationY);
889 // TODO: handle children fade out better
Selim Cinek0242fbb2016-10-19 13:38:32 -0700890 }
891 }
892
893 private void updateIconVisibilities() {
Selim Cinekdb167372016-11-17 15:41:17 -0800894 boolean visible = isChildInGroup() || isBelowSpeedBump() || mIconsVisible;
895 mPublicLayout.setIconsVisible(visible);
896 mPrivateLayout.setIconsVisible(visible);
897 if (mChildrenContainer != null) {
898 mChildrenContainer.setIconsVisible(visible);
Selim Cinek0242fbb2016-10-19 13:38:32 -0700899 }
900 }
901
Selim Cinek875a3a12016-11-18 17:52:16 -0800902 /**
903 * Get the relative top padding of a view relative to this view. This recursively walks up the
904 * hierarchy and does the corresponding measuring.
905 *
906 * @param view the view to the the padding for. The requested view has to be a child of this
907 * notification.
908 * @return the toppadding
909 */
910 public int getRelativeTopPadding(View view) {
911 int topPadding = 0;
912 while (view.getParent() instanceof ViewGroup) {
913 topPadding += view.getTop();
914 view = (View) view.getParent();
915 if (view instanceof ExpandableNotificationRow) {
916 return topPadding;
917 }
918 }
919 return topPadding;
920 }
921
Chris Wren78403d72014-07-28 10:23:24 +0100922 public interface ExpansionLogger {
923 public void logNotificationExpansion(String key, boolean userAction, boolean expanded);
924 }
Selim Cinek1685e632014-04-08 02:27:49 +0200925
Chris Wren51c75102013-07-16 20:49:17 -0400926 public ExpandableNotificationRow(Context context, AttributeSet attrs) {
927 super(context, attrs);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700928 mFalsingManager = FalsingManager.getInstance(context);
Selim Cinek01af3342016-02-09 19:25:31 -0800929 initDimens();
930 }
931
932 private void initDimens() {
Selim Cinekf619ffc2016-02-17 14:53:05 -0800933 mNotificationMinHeightLegacy = getFontScaledHeight(R.dimen.notification_min_height_legacy);
934 mNotificationMinHeight = getFontScaledHeight(R.dimen.notification_min_height);
935 mNotificationMaxHeight = getFontScaledHeight(R.dimen.notification_max_height);
936 mMaxHeadsUpHeightLegacy = getFontScaledHeight(
Selim Cinek77019c72015-12-09 10:18:02 -0800937 R.dimen.notification_max_heads_up_height_legacy);
Selim Cinekf619ffc2016-02-17 14:53:05 -0800938 mMaxHeadsUpHeight = getFontScaledHeight(R.dimen.notification_max_heads_up_height);
Mady Mellorb0a82462016-04-30 17:31:02 -0700939 mIncreasedPaddingBetweenElements = getResources()
940 .getDimensionPixelSize(R.dimen.notification_divider_height_increased);
Selim Cinek875a3a12016-11-18 17:52:16 -0800941 mIconTransformContentShiftNoIcon = getResources().getDimensionPixelSize(
Selim Cinek0242fbb2016-10-19 13:38:32 -0700942 R.dimen.notification_icon_transform_content_shift);
Selim Cinekf619ffc2016-02-17 14:53:05 -0800943 }
944
945 /**
946 * @param dimenId the dimen to look up
947 * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
948 */
949 private int getFontScaledHeight(int dimenId) {
950 int dimensionPixelSize = getResources().getDimensionPixelSize(dimenId);
951 float factor = Math.max(1.0f, getResources().getDisplayMetrics().scaledDensity /
952 getResources().getDisplayMetrics().density);
953 return (int) (dimensionPixelSize * factor);
Chris Wren51c75102013-07-16 20:49:17 -0400954 }
955
Christoph Studera7fe6312014-06-27 19:32:44 +0200956 /**
957 * Resets this view so it can be re-used for an updated notification.
958 */
Christoph Studer22f2ee52014-07-29 22:57:21 +0200959 @Override
Christoph Studera7fe6312014-06-27 19:32:44 +0200960 public void reset() {
Christoph Studer22f2ee52014-07-29 22:57:21 +0200961 super.reset();
Chris Wren78403d72014-07-28 10:23:24 +0100962 final boolean wasExpanded = isExpanded();
Christoph Studera7fe6312014-06-27 19:32:44 +0200963 mExpandable = false;
964 mHasUserChangedExpansion = false;
965 mUserLocked = false;
966 mShowingPublic = false;
Jorim Jaggiae441282014-08-01 02:45:18 +0200967 mSensitive = false;
968 mShowingPublicInitialized = false;
Christoph Studera7fe6312014-06-27 19:32:44 +0200969 mIsSystemExpanded = false;
Selim Cinek83bc7832015-10-22 13:26:54 -0700970 mOnKeyguard = false;
Selim Cinek51d94912016-03-02 15:34:28 -0800971 mPublicLayout.reset();
972 mPrivateLayout.reset();
Selim Cinek31094df2014-08-14 19:28:15 +0200973 resetHeight();
Mady Mellor4b80b102016-01-22 08:03:58 -0800974 resetTranslation();
Selim Cinek31094df2014-08-14 19:28:15 +0200975 logExpansionEvent(false, wasExpanded);
976 }
977
978 public void resetHeight() {
Selim Cinek31094df2014-08-14 19:28:15 +0200979 onHeightReset();
Selim Cinek6e28a672014-09-05 14:43:28 +0200980 requestLayout();
Christoph Studera7fe6312014-06-27 19:32:44 +0200981 }
982
Jorim Jaggi251957d2014-04-09 04:24:09 +0200983 @Override
984 protected void onFinishInflate() {
985 super.onFinishInflate();
Jorim Jaggibe565df2014-04-28 17:51:23 +0200986 mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800987 mPublicLayout.setContainingNotification(this);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200988 mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800989 mPrivateLayout.setExpandClickListener(mExpandClickListener);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800990 mPrivateLayout.setContainingNotification(this);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800991 mPublicLayout.setExpandClickListener(mExpandClickListener);
Mady Mellor4b80b102016-01-22 08:03:58 -0800992 mSettingsIconRowStub = (ViewStub) findViewById(R.id.settings_icon_row_stub);
993 mSettingsIconRowStub.setOnInflateListener(new ViewStub.OnInflateListener() {
994 @Override
995 public void onInflate(ViewStub stub, View inflated) {
996 mSettingsIconRow = (NotificationSettingsIconRow) inflated;
997 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
Mady Mellor3fd273e2016-03-15 21:08:14 -0700998 mSettingsIconRow.setAppName(mAppName);
Mady Mellor4b80b102016-01-22 08:03:58 -0800999 }
1000 });
Selim Cinekab29aeb2015-02-20 18:18:32 +01001001 mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub);
1002 mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() {
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001003 @Override
1004 public void onInflate(ViewStub stub, View inflated) {
1005 mGuts = (NotificationGuts) inflated;
1006 mGuts.setClipTopAmount(getClipTopAmount());
1007 mGuts.setActualHeight(getActualHeight());
Selim Cinekab29aeb2015-02-20 18:18:32 +01001008 mGutsStub = null;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001009 }
1010 });
Selim Cinekb5605e52015-02-20 18:21:41 +01001011 mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub);
1012 mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() {
1013
1014 @Override
1015 public void onInflate(ViewStub stub, View inflated) {
1016 mChildrenContainer = (NotificationChildrenContainer) inflated;
Selim Cinek388df6d2015-10-22 13:25:11 -07001017 mChildrenContainer.setNotificationParent(ExpandableNotificationRow.this);
Selim Cinekc897bd32016-03-18 17:32:31 -07001018 mChildrenContainer.onNotificationUpdated();
Mady Mellor4b80b102016-01-22 08:03:58 -08001019 mTranslateableViews.add(mChildrenContainer);
Selim Cinekb5605e52015-02-20 18:21:41 +01001020 }
1021 });
Selim Cinek863834b2014-05-20 04:20:25 +02001022 mVetoButton = findViewById(R.id.veto);
Selim Cinek9e624e72016-07-20 13:46:49 -07001023 mVetoButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
1024 mVetoButton.setContentDescription(mContext.getString(
1025 R.string.accessibility_remove_notification));
Mady Mellor4b80b102016-01-22 08:03:58 -08001026
1027 // Add the views that we translate to reveal the gear
1028 mTranslateableViews = new ArrayList<View>();
1029 for (int i = 0; i < getChildCount(); i++) {
1030 mTranslateableViews.add(getChildAt(i));
1031 }
1032 // Remove views that don't translate
1033 mTranslateableViews.remove(mVetoButton);
1034 mTranslateableViews.remove(mSettingsIconRowStub);
1035 mTranslateableViews.remove(mChildrenContainerStub);
1036 mTranslateableViews.remove(mGutsStub);
1037 }
1038
Selim Cinek9e624e72016-07-20 13:46:49 -07001039 public View getVetoButton() {
1040 return mVetoButton;
1041 }
1042
Mady Mellor4b80b102016-01-22 08:03:58 -08001043 public void resetTranslation() {
Mady Mellor32c638a2016-09-14 08:58:25 -07001044 if (mTranslateAnim != null) {
1045 mTranslateAnim.cancel();
1046 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001047 if (mTranslateableViews != null) {
1048 for (int i = 0; i < mTranslateableViews.size(); i++) {
1049 mTranslateableViews.get(i).setTranslationX(0);
1050 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001051 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001052 invalidateOutline();
Mady Mellor4b80b102016-01-22 08:03:58 -08001053 if (mSettingsIconRow != null) {
1054 mSettingsIconRow.resetState();
1055 }
1056 }
1057
1058 public void animateTranslateNotification(final float leftTarget) {
1059 if (mTranslateAnim != null) {
1060 mTranslateAnim.cancel();
1061 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001062 mTranslateAnim = getTranslateViewAnimator(leftTarget, null /* updateListener */);
Mady Mellor34958fa2016-02-23 09:52:17 -08001063 if (mTranslateAnim != null) {
1064 mTranslateAnim.start();
1065 }
1066 }
1067
1068 @Override
1069 public void setTranslation(float translationX) {
1070 if (areGutsExposed()) {
1071 // Don't translate if guts are showing.
1072 return;
1073 }
1074 // Translate the group of views
1075 for (int i = 0; i < mTranslateableViews.size(); i++) {
1076 if (mTranslateableViews.get(i) != null) {
1077 mTranslateableViews.get(i).setTranslationX(translationX);
1078 }
1079 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001080 invalidateOutline();
Mady Mellor34958fa2016-02-23 09:52:17 -08001081 if (mSettingsIconRow != null) {
1082 mSettingsIconRow.updateSettingsIcons(translationX, getMeasuredWidth());
1083 }
1084 }
1085
1086 @Override
1087 public float getTranslation() {
1088 if (mTranslateableViews != null && mTranslateableViews.size() > 0) {
1089 // All of the views in the list should have same translation, just use first one.
1090 return mTranslateableViews.get(0).getTranslationX();
1091 }
1092 return 0;
1093 }
1094
1095 public Animator getTranslateViewAnimator(final float leftTarget,
1096 AnimatorUpdateListener listener) {
Mady Mellor723f1f92016-03-13 15:54:06 -07001097 if (mTranslateAnim != null) {
1098 mTranslateAnim.cancel();
1099 }
Mady Mellor34958fa2016-02-23 09:52:17 -08001100 if (areGutsExposed()) {
1101 // No translation if guts are exposed.
1102 return null;
1103 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001104 final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(this, TRANSLATE_CONTENT,
1105 leftTarget);
1106 if (listener != null) {
1107 translateAnim.addUpdateListener(listener);
Mady Mellor4b80b102016-01-22 08:03:58 -08001108 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001109 translateAnim.addListener(new AnimatorListenerAdapter() {
1110 boolean cancelled = false;
1111
1112 @Override
1113 public void onAnimationCancel(Animator anim) {
1114 cancelled = true;
1115 }
1116
1117 @Override
1118 public void onAnimationEnd(Animator anim) {
1119 if (!cancelled && mSettingsIconRow != null && leftTarget == 0) {
1120 mSettingsIconRow.resetState();
1121 mTranslateAnim = null;
1122 }
1123 }
1124 });
1125 mTranslateAnim = translateAnim;
1126 return translateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -08001127 }
1128
1129 public float getSpaceForGear() {
1130 if (mSettingsIconRow != null) {
1131 return mSettingsIconRow.getSpaceForGear();
1132 }
1133 return 0;
1134 }
1135
1136 public NotificationSettingsIconRow getSettingsRow() {
1137 if (mSettingsIconRow == null) {
1138 mSettingsIconRowStub.inflate();
1139 }
1140 return mSettingsIconRow;
1141 }
1142
Selim Cinekab29aeb2015-02-20 18:18:32 +01001143 public void inflateGuts() {
1144 if (mGuts == null) {
1145 mGutsStub.inflate();
1146 }
1147 }
1148
Selim Cinekda42d652015-12-04 15:51:16 -08001149 private void updateChildrenVisibility() {
Selim Cinekd84a5932015-12-15 11:45:36 -08001150 mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE
1151 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -08001152 if (mChildrenContainer != null) {
1153 mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
1154 : INVISIBLE);
Mady Mellorb0a82462016-04-30 17:31:02 -07001155 mChildrenContainer.updateHeaderVisibility(!mShowingPublic && mIsSummaryWithChildren
1156 ? VISIBLE
Selim Cinekef5127e2015-12-21 16:55:58 -08001157 : INVISIBLE);
1158 }
Selim Cinekda42d652015-12-04 15:51:16 -08001159 // The limits might have changed if the view suddenly became a group or vice versa
1160 updateLimits();
Selim Cinekb5605e52015-02-20 18:21:41 +01001161 }
1162
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001163 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08001164 public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
1165 if (super.onRequestSendAccessibilityEventInternal(child, event)) {
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001166 // Add a record for the entire layout since its content is somehow small.
1167 // The event comes from a leaf view that is interacted with.
1168 AccessibilityEvent record = AccessibilityEvent.obtain();
1169 onInitializeAccessibilityEvent(record);
1170 dispatchPopulateAccessibilityEvent(record);
1171 event.appendRecord(record);
1172 return true;
1173 }
1174 return false;
Jorim Jaggic5dc0d02014-04-15 15:42:55 +02001175 }
Chris Wren51c75102013-07-16 20:49:17 -04001176
John Spurlocke15452b2014-08-21 09:44:39 -04001177 @Override
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001178 public void setDark(boolean dark, boolean fade, long delay) {
1179 super.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -04001180 final NotificationContentView showing = getShowingLayout();
1181 if (showing != null) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001182 showing.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -04001183 }
Selim Cinek9c7712d2015-12-08 19:19:48 -08001184 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001185 mChildrenContainer.setDark(dark, fade, delay);
Selim Cinek9c7712d2015-12-08 19:19:48 -08001186 }
John Spurlocke15452b2014-08-21 09:44:39 -04001187 }
1188
Chris Wren51c75102013-07-16 20:49:17 -04001189 public boolean isExpandable() {
Selim Cinek388df6d2015-10-22 13:25:11 -07001190 if (mIsSummaryWithChildren && !mShowingPublic) {
1191 return !mChildrenExpanded;
1192 }
Chris Wren51c75102013-07-16 20:49:17 -04001193 return mExpandable;
1194 }
1195
1196 public void setExpandable(boolean expandable) {
1197 mExpandable = expandable;
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001198 mPrivateLayout.updateExpandButtons(isExpandable());
Chris Wren51c75102013-07-16 20:49:17 -04001199 }
1200
Selim Cinek4ffd6362015-12-29 15:12:23 +01001201 @Override
1202 public void setClipToActualHeight(boolean clipToActualHeight) {
Selim Cinek084c16b2016-01-22 17:48:22 -08001203 super.setClipToActualHeight(clipToActualHeight || isUserLocked());
1204 getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked());
Selim Cinek4ffd6362015-12-29 15:12:23 +01001205 }
1206
Selim Cinek1685e632014-04-08 02:27:49 +02001207 /**
1208 * @return whether the user has changed the expansion state
1209 */
1210 public boolean hasUserChangedExpansion() {
1211 return mHasUserChangedExpansion;
1212 }
1213
Chris Wren51c75102013-07-16 20:49:17 -04001214 public boolean isUserExpanded() {
1215 return mUserExpanded;
1216 }
1217
Selim Cinek1685e632014-04-08 02:27:49 +02001218 /**
1219 * Set this notification to be expanded by the user
1220 *
1221 * @param userExpanded whether the user wants this notification to be expanded
1222 */
Chris Wren51c75102013-07-16 20:49:17 -04001223 public void setUserExpanded(boolean userExpanded) {
Selim Cinek388df6d2015-10-22 13:25:11 -07001224 setUserExpanded(userExpanded, false /* allowChildExpansion */);
1225 }
1226
1227 /**
1228 * Set this notification to be expanded by the user
1229 *
1230 * @param userExpanded whether the user wants this notification to be expanded
1231 * @param allowChildExpansion whether a call to this method allows expanding children
1232 */
1233 public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001234 mFalsingManager.setNotificationExpanded();
Selim Cinek388df6d2015-10-22 13:25:11 -07001235 if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion) {
Chris Wren698b1702016-05-23 11:16:32 -04001236 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinek388df6d2015-10-22 13:25:11 -07001237 mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded);
Chris Wren698b1702016-05-23 11:16:32 -04001238 logExpansionEvent(true /* userAction */, wasExpanded);
Selim Cinek388df6d2015-10-22 13:25:11 -07001239 return;
1240 }
Christoph Studera7fe6312014-06-27 19:32:44 +02001241 if (userExpanded && !mExpandable) return;
Chris Wren78403d72014-07-28 10:23:24 +01001242 final boolean wasExpanded = isExpanded();
Selim Cinek1685e632014-04-08 02:27:49 +02001243 mHasUserChangedExpansion = true;
Chris Wren51c75102013-07-16 20:49:17 -04001244 mUserExpanded = userExpanded;
Chris Wren78403d72014-07-28 10:23:24 +01001245 logExpansionEvent(true, wasExpanded);
Chris Wren51c75102013-07-16 20:49:17 -04001246 }
1247
Selim Cinekccd14fb2014-08-12 18:53:24 +02001248 public void resetUserExpansion() {
1249 mHasUserChangedExpansion = false;
1250 mUserExpanded = false;
1251 }
1252
Chris Wren51c75102013-07-16 20:49:17 -04001253 public boolean isUserLocked() {
Selim Cinek1b2a05e2016-04-28 14:20:39 -07001254 return mUserLocked && !mForceUnlocked;
Chris Wren51c75102013-07-16 20:49:17 -04001255 }
1256
1257 public void setUserLocked(boolean userLocked) {
1258 mUserLocked = userLocked;
Selim Cinek8f2f6a62016-02-23 19:56:31 -08001259 mPrivateLayout.setUserExpanding(userLocked);
Selim Cinek42357e02016-02-24 18:48:01 -08001260 if (mIsSummaryWithChildren) {
1261 mChildrenContainer.setUserLocked(userLocked);
Selim Cinek7baaa9e2016-07-21 17:21:09 -07001262 if (userLocked || !isGroupExpanded()) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001263 updateBackgroundForGroupState();
1264 }
Selim Cinek42357e02016-02-24 18:48:01 -08001265 }
Chris Wren51c75102013-07-16 20:49:17 -04001266 }
1267
Selim Cinek1685e632014-04-08 02:27:49 +02001268 /**
1269 * @return has the system set this notification to be expanded
1270 */
1271 public boolean isSystemExpanded() {
1272 return mIsSystemExpanded;
1273 }
1274
1275 /**
1276 * Set this notification to be expanded by the system.
1277 *
1278 * @param expand whether the system wants this notification to be expanded.
1279 */
1280 public void setSystemExpanded(boolean expand) {
Selim Cinek31094df2014-08-14 19:28:15 +02001281 if (expand != mIsSystemExpanded) {
1282 final boolean wasExpanded = isExpanded();
1283 mIsSystemExpanded = expand;
Selim Cinekb5605e52015-02-20 18:21:41 +01001284 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +02001285 logExpansionEvent(false, wasExpanded);
Selim Cineked6913b2016-06-01 12:01:17 -07001286 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001287 mChildrenContainer.updateGroupOverflow();
1288 }
Selim Cinek31094df2014-08-14 19:28:15 +02001289 }
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001290 }
1291
1292 /**
Selim Cinek83bc7832015-10-22 13:26:54 -07001293 * @param onKeyguard whether to prevent notification expansion
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001294 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001295 public void setOnKeyguard(boolean onKeyguard) {
1296 if (onKeyguard != mOnKeyguard) {
Selim Cinek31094df2014-08-14 19:28:15 +02001297 final boolean wasExpanded = isExpanded();
Selim Cinek83bc7832015-10-22 13:26:54 -07001298 mOnKeyguard = onKeyguard;
Selim Cinek31094df2014-08-14 19:28:15 +02001299 logExpansionEvent(false, wasExpanded);
1300 if (wasExpanded != isExpanded()) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001301 if (mIsSummaryWithChildren) {
1302 mChildrenContainer.updateGroupOverflow();
1303 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001304 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +02001305 }
1306 }
Selim Cinek1685e632014-04-08 02:27:49 +02001307 }
1308
1309 /**
Selim Cinek9e624e72016-07-20 13:46:49 -07001310 * @return Can the underlying notification be cleared? This can be different from whether the
1311 * notification can be dismissed in case notifications are sensitive on the lockscreen.
1312 * @see #canViewBeDismissed()
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001313 */
1314 public boolean isClearable() {
Selim Cinek506deb62016-07-20 15:43:59 -07001315 if (mStatusBarNotification == null || !mStatusBarNotification.isClearable()) {
1316 return false;
1317 }
1318 if (mIsSummaryWithChildren) {
1319 List<ExpandableNotificationRow> notificationChildren =
1320 mChildrenContainer.getNotificationChildren();
1321 for (int i = 0; i < notificationChildren.size(); i++) {
1322 ExpandableNotificationRow child = notificationChildren.get(i);
1323 if (!child.isClearable()) {
1324 return false;
1325 }
1326 }
1327 }
1328 return true;
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001329 }
1330
Jorim Jaggi9cbadd32014-05-01 20:18:31 +02001331 @Override
1332 public int getIntrinsicHeight() {
Jorim Jaggibe565df2014-04-28 17:51:23 +02001333 if (isUserLocked()) {
1334 return getActualHeight();
1335 }
Selim Cinekd84a5932015-12-15 11:45:36 -08001336 if (mGuts != null && mGuts.areGutsExposed()) {
1337 return mGuts.getHeight();
1338 } else if ((isChildInGroup() && !isGroupExpanded())) {
1339 return mPrivateLayout.getMinHeight();
1340 } else if (mSensitive && mHideSensitiveForIntrinsicHeight) {
1341 return getMinHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001342 } else if (mIsSummaryWithChildren && !mOnKeyguard) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001343 return mChildrenContainer.getIntrinsicHeight();
Selim Cinek73cf02a2016-06-17 13:08:00 -07001344 } else if (mIsHeadsUp || mHeadsupDisappearRunning) {
1345 if (isPinned() || mHeadsupDisappearRunning) {
Selim Cinek31aada42015-12-18 17:51:15 -08001346 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
1347 } else if (isExpanded()) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001348 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001349 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001350 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001351 }
Selim Cinek31aada42015-12-18 17:51:15 -08001352 } else if (isExpanded()) {
Selim Cinek83bc7832015-10-22 13:26:54 -07001353 return getMaxExpandHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -08001354 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001355 return getCollapsedHeight();
Selim Cinek1685e632014-04-08 02:27:49 +02001356 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001357 }
Selim Cinek1685e632014-04-08 02:27:49 +02001358
Mady Mellorb0a82462016-04-30 17:31:02 -07001359 public boolean isGroupExpanded() {
Selim Cinekeef84282015-10-30 16:28:00 -07001360 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinekb5605e52015-02-20 18:21:41 +01001361 }
1362
Selim Cinek263398f2015-10-21 17:40:23 -07001363 private void onChildrenCountChanged() {
Selim Cinek8fc93c92015-11-23 17:48:07 -08001364 mIsSummaryWithChildren = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS
Mady Mellorb0a82462016-04-30 17:31:02 -07001365 && mChildrenContainer != null && mChildrenContainer.getNotificationChildCount() > 0;
1366 if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() == null) {
1367 mChildrenContainer.recreateNotificationHeader(mExpandClickListener,
1368 mEntry.notification);
Selim Cinek263398f2015-10-21 17:40:23 -07001369 }
Mady Mellor6baed9e2016-05-25 16:05:09 -07001370 getShowingLayout().updateBackgroundColor(false /* animate */);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001371 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinekea4bef72015-12-02 15:51:10 -08001372 updateChildrenHeaderAppearance();
Selim Cinekda42d652015-12-04 15:51:16 -08001373 updateChildrenVisibility();
Selim Cinek263398f2015-10-21 17:40:23 -07001374 }
1375
Mady Mellorb0a82462016-04-30 17:31:02 -07001376 public void updateChildrenHeaderAppearance() {
Selim Cineked6913b2016-06-01 12:01:17 -07001377 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001378 mChildrenContainer.updateChildrenHeaderAppearance();
1379 }
1380 }
1381
Selim Cinek1685e632014-04-08 02:27:49 +02001382 /**
1383 * Check whether the view state is currently expanded. This is given by the system in {@link
1384 * #setSystemExpanded(boolean)} and can be overridden by user expansion or
1385 * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this
1386 * view can differ from this state, if layout params are modified from outside.
1387 *
1388 * @return whether the view state is currently expanded.
1389 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001390 public boolean isExpanded() {
Selim Cineke81b82b2016-03-04 11:22:28 -08001391 return isExpanded(false /* allowOnKeyguard */);
1392 }
1393
1394 public boolean isExpanded(boolean allowOnKeyguard) {
1395 return (!mOnKeyguard || allowOnKeyguard)
Selim Cinekb5605e52015-02-20 18:21:41 +01001396 && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded())
1397 || isUserExpanded());
1398 }
1399
1400 private boolean isSystemChildExpanded() {
1401 return mIsSystemChildExpanded;
1402 }
1403
1404 public void setSystemChildExpanded(boolean expanded) {
1405 mIsSystemChildExpanded = expanded;
Selim Cinek1685e632014-04-08 02:27:49 +02001406 }
1407
1408 @Override
1409 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
1410 super.onLayout(changed, left, top, right, bottom);
Selim Cinek8d490d42015-04-10 00:05:50 -07001411 updateMaxHeights();
Mady Mellora6edc872016-04-26 11:01:03 -07001412 if (mSettingsIconRow != null) {
1413 mSettingsIconRow.updateVerticalLocation();
1414 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001415 updateContentShiftHeight();
1416 }
1417
1418 /**
1419 * Updates the content shift height such that the header is completely hidden when coming from
1420 * the top.
1421 */
1422 private void updateContentShiftHeight() {
1423 NotificationHeaderView notificationHeader = getNotificationHeader();
1424 if (notificationHeader != null) {
1425 CachingIconView icon = notificationHeader.getIcon();
1426 mIconTransformContentShift = getRelativeTopPadding(icon) + icon.getHeight();
1427 } else {
1428 mIconTransformContentShift = mIconTransformContentShiftNoIcon;
1429 }
Selim Cinek1685e632014-04-08 02:27:49 +02001430 }
1431
Selim Cinek8d490d42015-04-10 00:05:50 -07001432 private void updateMaxHeights() {
Selim Cinekd2319fb2014-09-01 19:41:54 +02001433 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek8d490d42015-04-10 00:05:50 -07001434 View expandedChild = mPrivateLayout.getExpandedChild();
1435 if (expandedChild == null) {
1436 expandedChild = mPrivateLayout.getContractedChild();
1437 }
1438 mMaxExpandHeight = expandedChild.getHeight();
1439 View headsUpChild = mPrivateLayout.getHeadsUpChild();
Selim Cinek1f3f5442015-04-10 17:54:46 -07001440 if (headsUpChild == null) {
1441 headsUpChild = mPrivateLayout.getContractedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -07001442 }
Selim Cinek1f3f5442015-04-10 17:54:46 -07001443 mHeadsUpHeight = headsUpChild.getHeight();
Selim Cinekd2319fb2014-09-01 19:41:54 +02001444 if (intrinsicBefore != getIntrinsicHeight()) {
Selim Cinekbb42b7d2016-08-10 13:02:38 -07001445 notifyHeightChanged(true /* needsAnimation */);
Selim Cinekd2319fb2014-09-01 19:41:54 +02001446 }
1447 }
1448
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001449 @Override
1450 public void notifyHeightChanged(boolean needsAnimation) {
1451 super.notifyHeightChanged(needsAnimation);
1452 getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked());
1453 }
1454
Selim Cinek3c76d502016-02-19 15:16:33 -08001455 public void setSensitive(boolean sensitive, boolean hideSensitive) {
Jorim Jaggiae441282014-08-01 02:45:18 +02001456 mSensitive = sensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -08001457 mSensitiveHiddenInGeneral = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02001458 }
1459
1460 public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
Selim Cinek60122be2015-04-15 18:16:50 -07001461 mHideSensitiveForIntrinsicHeight = hideSensitive;
Selim Cineka52f6a12016-02-29 15:35:58 -08001462 if (mIsSummaryWithChildren) {
1463 List<ExpandableNotificationRow> notificationChildren =
1464 mChildrenContainer.getNotificationChildren();
1465 for (int i = 0; i < notificationChildren.size(); i++) {
1466 ExpandableNotificationRow child = notificationChildren.get(i);
1467 child.setHideSensitiveForIntrinsicHeight(hideSensitive);
1468 }
1469 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001470 }
1471
1472 public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
1473 long duration) {
1474 boolean oldShowingPublic = mShowingPublic;
1475 mShowingPublic = mSensitive && hideSensitive;
1476 if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
1477 return;
1478 }
Dan Sandlera5e0f412014-01-23 15:11:54 -05001479
1480 // bail out if no public version
Selim Cinek1685e632014-04-08 02:27:49 +02001481 if (mPublicLayout.getChildCount() == 0) return;
Dan Sandlera5e0f412014-01-23 15:11:54 -05001482
Jorim Jaggiae441282014-08-01 02:45:18 +02001483 if (!animated) {
1484 mPublicLayout.animate().cancel();
1485 mPrivateLayout.animate().cancel();
Selim Cineka554c702016-06-17 18:02:12 -07001486 if (mChildrenContainer != null) {
1487 mChildrenContainer.animate().cancel();
1488 mChildrenContainer.setAlpha(1f);
1489 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001490 mPublicLayout.setAlpha(1f);
1491 mPrivateLayout.setAlpha(1f);
1492 mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
Selim Cinekd84a5932015-12-15 11:45:36 -08001493 updateChildrenVisibility();
Jorim Jaggiae441282014-08-01 02:45:18 +02001494 } else {
1495 animateShowingPublic(delay, duration);
1496 }
Selim Cinekc3179332016-03-04 14:44:56 -08001497 NotificationContentView showingLayout = getShowingLayout();
1498 showingLayout.updateBackgroundColor(animated);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001499 mPrivateLayout.updateExpandButtons(isExpandable());
Jorim Jaggiae441282014-08-01 02:45:18 +02001500 mShowingPublicInitialized = true;
1501 }
1502
1503 private void animateShowingPublic(long delay, long duration) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001504 View[] privateViews = mIsSummaryWithChildren
1505 ? new View[] {mChildrenContainer}
Selim Cinekd84a5932015-12-15 11:45:36 -08001506 : new View[] {mPrivateLayout};
1507 View[] publicViews = new View[] {mPublicLayout};
1508 View[] hiddenChildren = mShowingPublic ? privateViews : publicViews;
1509 View[] shownChildren = mShowingPublic ? publicViews : privateViews;
1510 for (final View hiddenView : hiddenChildren) {
1511 hiddenView.setVisibility(View.VISIBLE);
1512 hiddenView.animate().cancel();
1513 hiddenView.animate()
1514 .alpha(0f)
1515 .setStartDelay(delay)
1516 .setDuration(duration)
1517 .withEndAction(new Runnable() {
1518 @Override
1519 public void run() {
1520 hiddenView.setVisibility(View.INVISIBLE);
1521 }
1522 });
1523 }
1524 for (View showView : shownChildren) {
1525 showView.setVisibility(View.VISIBLE);
1526 showView.setAlpha(0f);
1527 showView.animate().cancel();
1528 showView.animate()
1529 .alpha(1f)
1530 .setStartDelay(delay)
1531 .setDuration(duration);
1532 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001533 }
1534
Selim Cinek3776fe02016-02-04 13:32:43 -08001535 public boolean mustStayOnScreen() {
1536 return mIsHeadsUp;
1537 }
1538
Selim Cinek9e624e72016-07-20 13:46:49 -07001539 /**
1540 * @return Whether this view is allowed to be dismissed. Only valid for visible notifications as
1541 * otherwise some state might not be updated. To request about the general clearability
1542 * see {@link #isClearable()}.
1543 */
1544 public boolean canViewBeDismissed() {
Selim Cineke9bad242016-06-15 11:46:37 -07001545 return isClearable() && (!mShowingPublic || !mSensitiveHiddenInGeneral);
Dan Sandlera5e0f412014-01-23 15:11:54 -05001546 }
Jorim Jaggi251957d2014-04-09 04:24:09 +02001547
Ricky Waicd35def2016-05-03 11:07:07 +01001548 public void makeActionsVisibile() {
1549 setUserExpanded(true, true);
1550 if (isChildInGroup()) {
1551 mGroupManager.setGroupExpanded(mStatusBarNotification, true);
1552 }
Selim Cinekbb42b7d2016-08-10 13:02:38 -07001553 notifyHeightChanged(false /* needsAnimation */);
Ricky Waicd35def2016-05-03 11:07:07 +01001554 }
1555
Selim Cinekb5605e52015-02-20 18:21:41 +01001556 public void setChildrenExpanded(boolean expanded, boolean animate) {
1557 mChildrenExpanded = expanded;
Selim Cinek83bc7832015-10-22 13:26:54 -07001558 if (mChildrenContainer != null) {
1559 mChildrenContainer.setChildrenExpanded(expanded);
1560 }
Mady Mellor1a5d8ea2016-06-09 10:42:42 -07001561 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -07001562 updateClickAndFocus();
Selim Cinekb5605e52015-02-20 18:21:41 +01001563 }
1564
Selim Cinekb5605e52015-02-20 18:21:41 +01001565 public static void applyTint(View v, int color) {
1566 int alpha;
1567 if (color != 0) {
1568 alpha = COLORED_DIVIDER_ALPHA;
1569 } else {
1570 color = 0xff000000;
1571 alpha = DEFAULT_DIVIDER_ALPHA;
1572 }
1573 if (v.getBackground() instanceof ColorDrawable) {
1574 ColorDrawable background = (ColorDrawable) v.getBackground();
1575 background.mutate();
1576 background.setColor(color);
1577 background.setAlpha(alpha);
1578 }
1579 }
1580
Selim Cinek1685e632014-04-08 02:27:49 +02001581 public int getMaxExpandHeight() {
Selim Cinekb5605e52015-02-20 18:21:41 +01001582 return mMaxExpandHeight;
Chris Wren51c75102013-07-16 20:49:17 -04001583 }
Jorim Jaggi584a7aa2014-04-10 23:26:13 +02001584
Mady Mellor34958fa2016-02-23 09:52:17 -08001585 public boolean areGutsExposed() {
1586 return (mGuts != null && mGuts.areGutsExposed());
1587 }
1588
Jorim Jaggibe565df2014-04-28 17:51:23 +02001589 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001590 public boolean isContentExpandable() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001591 NotificationContentView showingLayout = getShowingLayout();
1592 return showingLayout.isContentExpandable();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001593 }
1594
1595 @Override
Selim Cinek560e64d2015-06-09 19:58:11 -07001596 protected View getContentView() {
Selim Cinekaa3901a2016-08-05 11:04:37 -07001597 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cineka5703182016-05-11 21:23:16 -04001598 return mChildrenContainer;
1599 }
Selim Cinek560e64d2015-06-09 19:58:11 -07001600 return getShowingLayout();
1601 }
1602
1603 @Override
Selim Cinekaa3901a2016-08-05 11:04:37 -07001604 protected void onAppearAnimationFinished(boolean wasAppearing) {
1605 super.onAppearAnimationFinished(wasAppearing);
1606 if (wasAppearing) {
1607 // During the animation the visible view might have changed, so let's make sure all
1608 // alphas are reset
1609 if (mChildrenContainer != null) {
1610 mChildrenContainer.setAlpha(1.0f);
1611 mChildrenContainer.setLayerType(LAYER_TYPE_NONE, null);
1612 }
1613 mPrivateLayout.setAlpha(1.0f);
1614 mPrivateLayout.setLayerType(LAYER_TYPE_NONE, null);
1615 mPublicLayout.setAlpha(1.0f);
1616 mPublicLayout.setLayerType(LAYER_TYPE_NONE, null);
1617 }
1618 }
1619
1620 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -07001621 public int getExtraBottomPadding() {
1622 if (mIsSummaryWithChildren && isGroupExpanded()) {
1623 return mIncreasedPaddingBetweenElements;
1624 }
1625 return 0;
1626 }
1627
1628 @Override
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001629 public void setActualHeight(int height, boolean notifyListeners) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001630 super.setActualHeight(height, notifyListeners);
Mady Mellorb53bc272016-02-11 18:28:23 -08001631 if (mGuts != null && mGuts.areGutsExposed()) {
1632 mGuts.setActualHeight(height);
1633 return;
1634 }
Selim Cinekeef84282015-10-30 16:28:00 -07001635 int contentHeight = Math.max(getMinHeight(), height);
Selim Cinekb5605e52015-02-20 18:21:41 +01001636 mPrivateLayout.setContentHeight(contentHeight);
1637 mPublicLayout.setContentHeight(contentHeight);
Selim Cinek42357e02016-02-24 18:48:01 -08001638 if (mIsSummaryWithChildren) {
1639 mChildrenContainer.setActualHeight(height);
1640 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001641 if (mGuts != null) {
1642 mGuts.setActualHeight(height);
1643 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001644 }
1645
1646 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01001647 public int getMaxContentHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001648 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001649 return mChildrenContainer.getMaxContentHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001650 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001651 NotificationContentView showingLayout = getShowingLayout();
1652 return showingLayout.getMaxHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001653 }
1654
1655 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001656 public int getMinHeight() {
Selim Cinek31aada42015-12-18 17:51:15 -08001657 if (mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) {
1658 return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
1659 } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001660 return mChildrenContainer.getMinHeight();
Selim Cinek31aada42015-12-18 17:51:15 -08001661 } else if (mIsHeadsUp) {
1662 return mHeadsUpHeight;
Selim Cinekb55386d2015-12-16 17:26:49 -08001663 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001664 NotificationContentView showingLayout = getShowingLayout();
1665 return showingLayout.getMinHeight();
1666 }
1667
1668 @Override
Selim Cinek567e8452016-03-24 10:54:56 -07001669 public int getCollapsedHeight() {
Selim Cinek2c584612016-02-29 16:14:25 -08001670 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinek567e8452016-03-24 10:54:56 -07001671 return mChildrenContainer.getCollapsedHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001672 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001673 return getMinHeight();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001674 }
1675
1676 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02001677 public void setClipTopAmount(int clipTopAmount) {
1678 super.setClipTopAmount(clipTopAmount);
1679 mPrivateLayout.setClipTopAmount(clipTopAmount);
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001680 mPublicLayout.setClipTopAmount(clipTopAmount);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001681 if (mGuts != null) {
1682 mGuts.setClipTopAmount(clipTopAmount);
1683 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001684 }
1685
Selim Cineka686b2c2016-10-26 13:58:27 -07001686 @Override
1687 public void setClipBottomAmount(int clipBottomAmount) {
Selim Cinek65d418e2016-11-29 15:42:34 -08001688 if (clipBottomAmount != mClipBottomAmount) {
1689 super.setClipBottomAmount(clipBottomAmount);
1690 mPrivateLayout.setClipBottomAmount(clipBottomAmount);
1691 mPublicLayout.setClipBottomAmount(clipBottomAmount);
1692 if (mGuts != null) {
1693 mGuts.setClipBottomAmount(clipBottomAmount);
1694 }
Selim Cineka686b2c2016-10-26 13:58:27 -07001695 }
Selim Cinekb3dadcc2016-11-21 17:21:13 -08001696 if (mChildrenContainer != null) {
Selim Cinek65d418e2016-11-29 15:42:34 -08001697 // We have to update this even if it hasn't changed, since the children locations can
1698 // have changed
Selim Cinekb3dadcc2016-11-21 17:21:13 -08001699 mChildrenContainer.setClipBottomAmount(clipBottomAmount);
1700 }
Selim Cineka686b2c2016-10-26 13:58:27 -07001701 }
1702
Selim Cinek31094df2014-08-14 19:28:15 +02001703 public boolean isMaxExpandHeightInitialized() {
1704 return mMaxExpandHeight != 0;
Selim Cinek7d447722014-06-10 15:51:59 +02001705 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001706
Selim Cinek42357e02016-02-24 18:48:01 -08001707 public NotificationContentView getShowingLayout() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001708 return mShowingPublic ? mPublicLayout : mPrivateLayout;
1709 }
Chris Wren78403d72014-07-28 10:23:24 +01001710
Jorim Jaggi59ec3042015-06-05 15:18:43 -07001711 @Override
1712 public void setShowingLegacyBackground(boolean showing) {
1713 super.setShowingLegacyBackground(showing);
1714 mPrivateLayout.setShowingLegacyBackground(showing);
1715 mPublicLayout.setShowingLegacyBackground(showing);
1716 }
1717
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001718 @Override
1719 protected void updateBackgroundTint() {
1720 super.updateBackgroundTint();
Mady Mellorb0a82462016-04-30 17:31:02 -07001721 updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001722 if (mIsSummaryWithChildren) {
1723 List<ExpandableNotificationRow> notificationChildren =
1724 mChildrenContainer.getNotificationChildren();
1725 for (int i = 0; i < notificationChildren.size(); i++) {
1726 ExpandableNotificationRow child = notificationChildren.get(i);
Mady Mellorb0a82462016-04-30 17:31:02 -07001727 child.updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001728 }
1729 }
1730 }
1731
Mady Mellorb0a82462016-04-30 17:31:02 -07001732 /**
1733 * Called when a group has finished animating from collapsed or expanded state.
1734 */
1735 public void onFinishedExpansionChange() {
1736 mGroupExpansionChanging = false;
1737 updateBackgroundForGroupState();
1738 }
1739
1740 /**
1741 * Updates the parent and children backgrounds in a group based on the expansion state.
1742 */
1743 public void updateBackgroundForGroupState() {
1744 if (mIsSummaryWithChildren) {
1745 // Only when the group has finished expanding do we hide its background.
1746 mShowNoBackground = isGroupExpanded() && !isGroupExpansionChanging() && !isUserLocked();
1747 mChildrenContainer.updateHeaderForExpansion(mShowNoBackground);
1748 List<ExpandableNotificationRow> children = mChildrenContainer.getNotificationChildren();
1749 for (int i = 0; i < children.size(); i++) {
1750 children.get(i).updateBackgroundForGroupState();
1751 }
1752 } else if (isChildInGroup()) {
1753 final int childColor = getShowingLayout().getBackgroundColorForExpansionState();
1754 // Only show a background if the group is expanded OR if it is expanding / collapsing
1755 // and has a custom background color
1756 final boolean showBackground = isGroupExpanded()
1757 || ((mNotificationParent.isGroupExpansionChanging()
1758 || mNotificationParent.isUserLocked()) && childColor != 0);
1759 mShowNoBackground = !showBackground;
1760 } else {
1761 // Only children or parents ever need no background.
1762 mShowNoBackground = false;
1763 }
1764 updateOutline();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001765 updateBackground();
1766 }
1767
Adrian Roos4a579672016-05-24 16:54:37 -07001768 public int getPositionOfChild(ExpandableNotificationRow childRow) {
1769 if (mIsSummaryWithChildren) {
1770 return mChildrenContainer.getPositionInLinearLayout(childRow);
1771 }
1772 return 0;
1773 }
1774
Chris Wren78403d72014-07-28 10:23:24 +01001775 public void setExpansionLogger(ExpansionLogger logger, String key) {
1776 mLogger = logger;
1777 mLoggingKey = key;
1778 }
1779
Chris Wren6abeeb92016-05-26 14:44:38 -04001780 public void onExpandedByGesture(boolean userExpanded) {
1781 int event = MetricsEvent.ACTION_NOTIFICATION_GESTURE_EXPANDER;
1782 if (mGroupManager.isSummaryOfGroup(getStatusBarNotification())) {
1783 event = MetricsEvent.ACTION_NOTIFICATION_GROUP_GESTURE_EXPANDER;
1784 }
1785 MetricsLogger.action(mContext, event, userExpanded);
1786 }
1787
Selim Cinek6183d122016-01-14 18:48:41 -08001788 @Override
Selim Cinek42357e02016-02-24 18:48:01 -08001789 public float getIncreasedPaddingAmount() {
1790 if (mIsSummaryWithChildren) {
1791 if (isGroupExpanded()) {
1792 return 1.0f;
1793 } else if (isUserLocked()) {
Selim Cinekf07d0622016-03-21 19:52:52 -07001794 return mChildrenContainer.getGroupExpandFraction();
Selim Cinek42357e02016-02-24 18:48:01 -08001795 }
1796 }
1797 return 0.0f;
Selim Cinek61633a82016-01-25 15:54:10 -08001798 }
1799
1800 @Override
Selim Cinek6183d122016-01-14 18:48:41 -08001801 protected boolean disallowSingleClick(MotionEvent event) {
1802 float x = event.getX();
1803 float y = event.getY();
Selim Cinek34eda5e2016-02-18 17:10:43 -08001804 NotificationHeaderView header = getVisibleNotificationHeader();
Selim Cinek6183d122016-01-14 18:48:41 -08001805 if (header != null) {
Mady Mellora8833512016-03-09 09:50:18 -08001806 return header.isInTouchRect(x - getTranslation(), y);
Selim Cinek6183d122016-01-14 18:48:41 -08001807 }
1808 return super.disallowSingleClick(event);
1809 }
1810
Chris Wren78403d72014-07-28 10:23:24 +01001811 private void logExpansionEvent(boolean userAction, boolean wasExpanded) {
Chris Wren698b1702016-05-23 11:16:32 -04001812 boolean nowExpanded = isExpanded();
1813 if (mIsSummaryWithChildren) {
1814 nowExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
1815 }
Chris Wren78403d72014-07-28 10:23:24 +01001816 if (wasExpanded != nowExpanded && mLogger != null) {
1817 mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ;
1818 }
1819 }
Selim Cinek570981d2015-12-01 11:37:01 -08001820
Selim Cineke9bad242016-06-15 11:46:37 -07001821 @Override
1822 public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
1823 super.onInitializeAccessibilityNodeInfoInternal(info);
1824 if (canViewBeDismissed()) {
1825 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS);
1826 }
1827 }
1828
1829 @Override
1830 public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
1831 if (super.performAccessibilityActionInternal(action, arguments)) {
1832 return true;
1833 }
1834 switch (action) {
1835 case AccessibilityNodeInfo.ACTION_DISMISS:
1836 NotificationStackScrollLayout.performDismiss(this, mGroupManager,
1837 true /* fromAccessibility */);
1838 return true;
1839 }
1840 return false;
1841 }
1842
1843 public boolean shouldRefocusOnDismiss() {
1844 return mRefocusOnDismiss || isAccessibilityFocused();
1845 }
1846
Selim Cinek570981d2015-12-01 11:37:01 -08001847 public interface OnExpandClickListener {
Selim Cinek31aada42015-12-18 17:51:15 -08001848 void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
Selim Cinek570981d2015-12-01 11:37:01 -08001849 }
Selim Cinekbbcebde2016-11-09 18:28:20 -08001850
1851 @Override
1852 public ExpandableViewState createNewViewState(StackScrollState stackScrollState) {
1853 return new NotificationViewState(stackScrollState);
1854 }
1855
Selim Cinekd127d792016-11-01 19:11:41 -07001856 @Override
1857 public boolean isAboveShelf() {
1858 return mIsPinned || mHeadsupDisappearRunning || (mIsHeadsUp && mAboveShelf);
1859 }
1860
1861 public void setAboveShelf(boolean aboveShelf) {
1862 mAboveShelf = aboveShelf;
1863 }
1864
Selim Cinek0cfbef42016-11-09 19:06:36 -08001865 public class NotificationViewState extends ExpandableViewState {
Selim Cinekbbcebde2016-11-09 18:28:20 -08001866
1867 private final StackScrollState mOverallState;
Selim Cinek0242fbb2016-10-19 13:38:32 -07001868
Selim Cinekbbcebde2016-11-09 18:28:20 -08001869
1870 private NotificationViewState(StackScrollState stackScrollState) {
1871 mOverallState = stackScrollState;
1872 }
1873
1874 @Override
1875 public void applyToView(View view) {
1876 super.applyToView(view);
1877 if (view instanceof ExpandableNotificationRow) {
1878 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
Selim Cinekbbcebde2016-11-09 18:28:20 -08001879 row.applyChildrenState(mOverallState);
1880 }
1881 }
Selim Cinek0cfbef42016-11-09 19:06:36 -08001882
1883 @Override
Selim Cinek2b549f42016-11-22 16:38:51 -08001884 protected void onYTranslationAnimationFinished(View view) {
1885 super.onYTranslationAnimationFinished(view);
Selim Cinek0cfbef42016-11-09 19:06:36 -08001886 if (mHeadsupDisappearRunning) {
Selim Cinekcafa87f2016-10-26 17:00:17 -07001887 setHeadsUpAnimatingAway(false);
Selim Cinek0cfbef42016-11-09 19:06:36 -08001888 }
1889 }
1890
1891 @Override
1892 public void animateTo(View child, AnimationProperties properties) {
1893 super.animateTo(child, properties);
1894 if (child instanceof ExpandableNotificationRow) {
1895 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
1896 row.startChildAnimation(mOverallState, properties);
1897 }
1898 }
Selim Cinekbbcebde2016-11-09 18:28:20 -08001899 }
Chris Wren51c75102013-07-16 20:49:17 -04001900}