blob: a1384dcbe66d810dbc95696b008a6be53276c1d0 [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 Cinek0242fbb2016-10-19 13:38:32 -0700196 private float mIconTransformationAmount;
197 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 *
840 * @param iconTransformationAmount A value from 0 to 1 indicating how much we are transformed
841 * to an icon
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 Cinek875a3a12016-11-18 17:52:16 -0800845 public void setIconTransformationAmount(float iconTransformationAmount, boolean isLastChild) {
846 boolean changeTransformation = isLastChild != mIsLastChild;
847 changeTransformation |= mIconTransformationAmount != iconTransformationAmount;
848 mIsLastChild = isLastChild;
849 mIconTransformationAmount = iconTransformationAmount;
850 if (changeTransformation) {
851 updateContentTransformation();
Selim Cinek0242fbb2016-10-19 13:38:32 -0700852 boolean iconsVisible = mIconTransformationAmount == 0.0f;
853 if (iconsVisible != mIconsVisible) {
854 mIconsVisible = iconsVisible;
855 updateIconVisibilities();
856 }
857 }
858 }
859
Selim Cinekdb167372016-11-17 15:41:17 -0800860 @Override
861 protected void onBelowSpeedBumpChanged() {
862 updateIconVisibilities();
863 }
864
Selim Cinek875a3a12016-11-18 17:52:16 -0800865 private void updateContentTransformation() {
866 float contentAlpha;
867 float translationY = - mIconTransformationAmount * mIconTransformContentShift;
868 if (mIsLastChild) {
869 contentAlpha = 1.0f - mIconTransformationAmount;
870 contentAlpha = Math.min(contentAlpha / 0.5f, 1.0f);
Selim Cinek0242fbb2016-10-19 13:38:32 -0700871 contentAlpha = Interpolators.ALPHA_OUT.getInterpolation(contentAlpha);
Selim Cinek875a3a12016-11-18 17:52:16 -0800872 translationY *= 0.4f;
873 } else {
874 contentAlpha = 1.0f;
875 }
876 mPublicLayout.setAlpha(contentAlpha);
877 mPrivateLayout.setAlpha(contentAlpha);
878 mPublicLayout.setTranslationY(translationY);
879 mPrivateLayout.setTranslationY(translationY);
880 if (mChildrenContainer != null) {
881 mChildrenContainer.setAlpha(contentAlpha);
882 mChildrenContainer.setTranslationY(translationY);
883 // TODO: handle children fade out better
Selim Cinek0242fbb2016-10-19 13:38:32 -0700884 }
885 }
886
887 private void updateIconVisibilities() {
Selim Cinekdb167372016-11-17 15:41:17 -0800888 boolean visible = isChildInGroup() || isBelowSpeedBump() || mIconsVisible;
889 mPublicLayout.setIconsVisible(visible);
890 mPrivateLayout.setIconsVisible(visible);
891 if (mChildrenContainer != null) {
892 mChildrenContainer.setIconsVisible(visible);
Selim Cinek0242fbb2016-10-19 13:38:32 -0700893 }
894 }
895
Selim Cinek875a3a12016-11-18 17:52:16 -0800896 /**
897 * Get the relative top padding of a view relative to this view. This recursively walks up the
898 * hierarchy and does the corresponding measuring.
899 *
900 * @param view the view to the the padding for. The requested view has to be a child of this
901 * notification.
902 * @return the toppadding
903 */
904 public int getRelativeTopPadding(View view) {
905 int topPadding = 0;
906 while (view.getParent() instanceof ViewGroup) {
907 topPadding += view.getTop();
908 view = (View) view.getParent();
909 if (view instanceof ExpandableNotificationRow) {
910 return topPadding;
911 }
912 }
913 return topPadding;
914 }
915
Chris Wren78403d72014-07-28 10:23:24 +0100916 public interface ExpansionLogger {
917 public void logNotificationExpansion(String key, boolean userAction, boolean expanded);
918 }
Selim Cinek1685e632014-04-08 02:27:49 +0200919
Chris Wren51c75102013-07-16 20:49:17 -0400920 public ExpandableNotificationRow(Context context, AttributeSet attrs) {
921 super(context, attrs);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700922 mFalsingManager = FalsingManager.getInstance(context);
Selim Cinek01af3342016-02-09 19:25:31 -0800923 initDimens();
924 }
925
926 private void initDimens() {
Selim Cinekf619ffc2016-02-17 14:53:05 -0800927 mNotificationMinHeightLegacy = getFontScaledHeight(R.dimen.notification_min_height_legacy);
928 mNotificationMinHeight = getFontScaledHeight(R.dimen.notification_min_height);
929 mNotificationMaxHeight = getFontScaledHeight(R.dimen.notification_max_height);
930 mMaxHeadsUpHeightLegacy = getFontScaledHeight(
Selim Cinek77019c72015-12-09 10:18:02 -0800931 R.dimen.notification_max_heads_up_height_legacy);
Selim Cinekf619ffc2016-02-17 14:53:05 -0800932 mMaxHeadsUpHeight = getFontScaledHeight(R.dimen.notification_max_heads_up_height);
Mady Mellorb0a82462016-04-30 17:31:02 -0700933 mIncreasedPaddingBetweenElements = getResources()
934 .getDimensionPixelSize(R.dimen.notification_divider_height_increased);
Selim Cinek875a3a12016-11-18 17:52:16 -0800935 mIconTransformContentShiftNoIcon = getResources().getDimensionPixelSize(
Selim Cinek0242fbb2016-10-19 13:38:32 -0700936 R.dimen.notification_icon_transform_content_shift);
Selim Cinekf619ffc2016-02-17 14:53:05 -0800937 }
938
939 /**
940 * @param dimenId the dimen to look up
941 * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
942 */
943 private int getFontScaledHeight(int dimenId) {
944 int dimensionPixelSize = getResources().getDimensionPixelSize(dimenId);
945 float factor = Math.max(1.0f, getResources().getDisplayMetrics().scaledDensity /
946 getResources().getDisplayMetrics().density);
947 return (int) (dimensionPixelSize * factor);
Chris Wren51c75102013-07-16 20:49:17 -0400948 }
949
Christoph Studera7fe6312014-06-27 19:32:44 +0200950 /**
951 * Resets this view so it can be re-used for an updated notification.
952 */
Christoph Studer22f2ee52014-07-29 22:57:21 +0200953 @Override
Christoph Studera7fe6312014-06-27 19:32:44 +0200954 public void reset() {
Christoph Studer22f2ee52014-07-29 22:57:21 +0200955 super.reset();
Chris Wren78403d72014-07-28 10:23:24 +0100956 final boolean wasExpanded = isExpanded();
Christoph Studera7fe6312014-06-27 19:32:44 +0200957 mExpandable = false;
958 mHasUserChangedExpansion = false;
959 mUserLocked = false;
960 mShowingPublic = false;
Jorim Jaggiae441282014-08-01 02:45:18 +0200961 mSensitive = false;
962 mShowingPublicInitialized = false;
Christoph Studera7fe6312014-06-27 19:32:44 +0200963 mIsSystemExpanded = false;
Selim Cinek83bc7832015-10-22 13:26:54 -0700964 mOnKeyguard = false;
Selim Cinek51d94912016-03-02 15:34:28 -0800965 mPublicLayout.reset();
966 mPrivateLayout.reset();
Selim Cinek31094df2014-08-14 19:28:15 +0200967 resetHeight();
Mady Mellor4b80b102016-01-22 08:03:58 -0800968 resetTranslation();
Selim Cinek31094df2014-08-14 19:28:15 +0200969 logExpansionEvent(false, wasExpanded);
970 }
971
972 public void resetHeight() {
Selim Cinek31094df2014-08-14 19:28:15 +0200973 onHeightReset();
Selim Cinek6e28a672014-09-05 14:43:28 +0200974 requestLayout();
Christoph Studera7fe6312014-06-27 19:32:44 +0200975 }
976
Jorim Jaggi251957d2014-04-09 04:24:09 +0200977 @Override
978 protected void onFinishInflate() {
979 super.onFinishInflate();
Jorim Jaggibe565df2014-04-28 17:51:23 +0200980 mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800981 mPublicLayout.setContainingNotification(this);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200982 mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800983 mPrivateLayout.setExpandClickListener(mExpandClickListener);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800984 mPrivateLayout.setContainingNotification(this);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800985 mPublicLayout.setExpandClickListener(mExpandClickListener);
Mady Mellor4b80b102016-01-22 08:03:58 -0800986 mSettingsIconRowStub = (ViewStub) findViewById(R.id.settings_icon_row_stub);
987 mSettingsIconRowStub.setOnInflateListener(new ViewStub.OnInflateListener() {
988 @Override
989 public void onInflate(ViewStub stub, View inflated) {
990 mSettingsIconRow = (NotificationSettingsIconRow) inflated;
991 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
Mady Mellor3fd273e2016-03-15 21:08:14 -0700992 mSettingsIconRow.setAppName(mAppName);
Mady Mellor4b80b102016-01-22 08:03:58 -0800993 }
994 });
Selim Cinekab29aeb2015-02-20 18:18:32 +0100995 mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub);
996 mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() {
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200997 @Override
998 public void onInflate(ViewStub stub, View inflated) {
999 mGuts = (NotificationGuts) inflated;
1000 mGuts.setClipTopAmount(getClipTopAmount());
1001 mGuts.setActualHeight(getActualHeight());
Selim Cinekab29aeb2015-02-20 18:18:32 +01001002 mGutsStub = null;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001003 }
1004 });
Selim Cinekb5605e52015-02-20 18:21:41 +01001005 mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub);
1006 mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() {
1007
1008 @Override
1009 public void onInflate(ViewStub stub, View inflated) {
1010 mChildrenContainer = (NotificationChildrenContainer) inflated;
Selim Cinek388df6d2015-10-22 13:25:11 -07001011 mChildrenContainer.setNotificationParent(ExpandableNotificationRow.this);
Selim Cinekc897bd32016-03-18 17:32:31 -07001012 mChildrenContainer.onNotificationUpdated();
Mady Mellor4b80b102016-01-22 08:03:58 -08001013 mTranslateableViews.add(mChildrenContainer);
Selim Cinekb5605e52015-02-20 18:21:41 +01001014 }
1015 });
Selim Cinek863834b2014-05-20 04:20:25 +02001016 mVetoButton = findViewById(R.id.veto);
Selim Cinek9e624e72016-07-20 13:46:49 -07001017 mVetoButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
1018 mVetoButton.setContentDescription(mContext.getString(
1019 R.string.accessibility_remove_notification));
Mady Mellor4b80b102016-01-22 08:03:58 -08001020
1021 // Add the views that we translate to reveal the gear
1022 mTranslateableViews = new ArrayList<View>();
1023 for (int i = 0; i < getChildCount(); i++) {
1024 mTranslateableViews.add(getChildAt(i));
1025 }
1026 // Remove views that don't translate
1027 mTranslateableViews.remove(mVetoButton);
1028 mTranslateableViews.remove(mSettingsIconRowStub);
1029 mTranslateableViews.remove(mChildrenContainerStub);
1030 mTranslateableViews.remove(mGutsStub);
1031 }
1032
Selim Cinek9e624e72016-07-20 13:46:49 -07001033 public View getVetoButton() {
1034 return mVetoButton;
1035 }
1036
Mady Mellor4b80b102016-01-22 08:03:58 -08001037 public void resetTranslation() {
Mady Mellor32c638a2016-09-14 08:58:25 -07001038 if (mTranslateAnim != null) {
1039 mTranslateAnim.cancel();
1040 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001041 if (mTranslateableViews != null) {
1042 for (int i = 0; i < mTranslateableViews.size(); i++) {
1043 mTranslateableViews.get(i).setTranslationX(0);
1044 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001045 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001046 invalidateOutline();
Mady Mellor4b80b102016-01-22 08:03:58 -08001047 if (mSettingsIconRow != null) {
1048 mSettingsIconRow.resetState();
1049 }
1050 }
1051
1052 public void animateTranslateNotification(final float leftTarget) {
1053 if (mTranslateAnim != null) {
1054 mTranslateAnim.cancel();
1055 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001056 mTranslateAnim = getTranslateViewAnimator(leftTarget, null /* updateListener */);
Mady Mellor34958fa2016-02-23 09:52:17 -08001057 if (mTranslateAnim != null) {
1058 mTranslateAnim.start();
1059 }
1060 }
1061
1062 @Override
1063 public void setTranslation(float translationX) {
1064 if (areGutsExposed()) {
1065 // Don't translate if guts are showing.
1066 return;
1067 }
1068 // Translate the group of views
1069 for (int i = 0; i < mTranslateableViews.size(); i++) {
1070 if (mTranslateableViews.get(i) != null) {
1071 mTranslateableViews.get(i).setTranslationX(translationX);
1072 }
1073 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001074 invalidateOutline();
Mady Mellor34958fa2016-02-23 09:52:17 -08001075 if (mSettingsIconRow != null) {
1076 mSettingsIconRow.updateSettingsIcons(translationX, getMeasuredWidth());
1077 }
1078 }
1079
1080 @Override
1081 public float getTranslation() {
1082 if (mTranslateableViews != null && mTranslateableViews.size() > 0) {
1083 // All of the views in the list should have same translation, just use first one.
1084 return mTranslateableViews.get(0).getTranslationX();
1085 }
1086 return 0;
1087 }
1088
1089 public Animator getTranslateViewAnimator(final float leftTarget,
1090 AnimatorUpdateListener listener) {
Mady Mellor723f1f92016-03-13 15:54:06 -07001091 if (mTranslateAnim != null) {
1092 mTranslateAnim.cancel();
1093 }
Mady Mellor34958fa2016-02-23 09:52:17 -08001094 if (areGutsExposed()) {
1095 // No translation if guts are exposed.
1096 return null;
1097 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001098 final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(this, TRANSLATE_CONTENT,
1099 leftTarget);
1100 if (listener != null) {
1101 translateAnim.addUpdateListener(listener);
Mady Mellor4b80b102016-01-22 08:03:58 -08001102 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001103 translateAnim.addListener(new AnimatorListenerAdapter() {
1104 boolean cancelled = false;
1105
1106 @Override
1107 public void onAnimationCancel(Animator anim) {
1108 cancelled = true;
1109 }
1110
1111 @Override
1112 public void onAnimationEnd(Animator anim) {
1113 if (!cancelled && mSettingsIconRow != null && leftTarget == 0) {
1114 mSettingsIconRow.resetState();
1115 mTranslateAnim = null;
1116 }
1117 }
1118 });
1119 mTranslateAnim = translateAnim;
1120 return translateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -08001121 }
1122
1123 public float getSpaceForGear() {
1124 if (mSettingsIconRow != null) {
1125 return mSettingsIconRow.getSpaceForGear();
1126 }
1127 return 0;
1128 }
1129
1130 public NotificationSettingsIconRow getSettingsRow() {
1131 if (mSettingsIconRow == null) {
1132 mSettingsIconRowStub.inflate();
1133 }
1134 return mSettingsIconRow;
1135 }
1136
Selim Cinekab29aeb2015-02-20 18:18:32 +01001137 public void inflateGuts() {
1138 if (mGuts == null) {
1139 mGutsStub.inflate();
1140 }
1141 }
1142
Selim Cinekda42d652015-12-04 15:51:16 -08001143 private void updateChildrenVisibility() {
Selim Cinekd84a5932015-12-15 11:45:36 -08001144 mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE
1145 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -08001146 if (mChildrenContainer != null) {
1147 mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
1148 : INVISIBLE);
Mady Mellorb0a82462016-04-30 17:31:02 -07001149 mChildrenContainer.updateHeaderVisibility(!mShowingPublic && mIsSummaryWithChildren
1150 ? VISIBLE
Selim Cinekef5127e2015-12-21 16:55:58 -08001151 : INVISIBLE);
1152 }
Selim Cinekda42d652015-12-04 15:51:16 -08001153 // The limits might have changed if the view suddenly became a group or vice versa
1154 updateLimits();
Selim Cinekb5605e52015-02-20 18:21:41 +01001155 }
1156
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001157 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08001158 public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
1159 if (super.onRequestSendAccessibilityEventInternal(child, event)) {
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001160 // Add a record for the entire layout since its content is somehow small.
1161 // The event comes from a leaf view that is interacted with.
1162 AccessibilityEvent record = AccessibilityEvent.obtain();
1163 onInitializeAccessibilityEvent(record);
1164 dispatchPopulateAccessibilityEvent(record);
1165 event.appendRecord(record);
1166 return true;
1167 }
1168 return false;
Jorim Jaggic5dc0d02014-04-15 15:42:55 +02001169 }
Chris Wren51c75102013-07-16 20:49:17 -04001170
John Spurlocke15452b2014-08-21 09:44:39 -04001171 @Override
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001172 public void setDark(boolean dark, boolean fade, long delay) {
1173 super.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -04001174 final NotificationContentView showing = getShowingLayout();
1175 if (showing != null) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001176 showing.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -04001177 }
Selim Cinek9c7712d2015-12-08 19:19:48 -08001178 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001179 mChildrenContainer.setDark(dark, fade, delay);
Selim Cinek9c7712d2015-12-08 19:19:48 -08001180 }
John Spurlocke15452b2014-08-21 09:44:39 -04001181 }
1182
Chris Wren51c75102013-07-16 20:49:17 -04001183 public boolean isExpandable() {
Selim Cinek388df6d2015-10-22 13:25:11 -07001184 if (mIsSummaryWithChildren && !mShowingPublic) {
1185 return !mChildrenExpanded;
1186 }
Chris Wren51c75102013-07-16 20:49:17 -04001187 return mExpandable;
1188 }
1189
1190 public void setExpandable(boolean expandable) {
1191 mExpandable = expandable;
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001192 mPrivateLayout.updateExpandButtons(isExpandable());
Chris Wren51c75102013-07-16 20:49:17 -04001193 }
1194
Selim Cinek4ffd6362015-12-29 15:12:23 +01001195 @Override
1196 public void setClipToActualHeight(boolean clipToActualHeight) {
Selim Cinek084c16b2016-01-22 17:48:22 -08001197 super.setClipToActualHeight(clipToActualHeight || isUserLocked());
1198 getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked());
Selim Cinek4ffd6362015-12-29 15:12:23 +01001199 }
1200
Selim Cinek1685e632014-04-08 02:27:49 +02001201 /**
1202 * @return whether the user has changed the expansion state
1203 */
1204 public boolean hasUserChangedExpansion() {
1205 return mHasUserChangedExpansion;
1206 }
1207
Chris Wren51c75102013-07-16 20:49:17 -04001208 public boolean isUserExpanded() {
1209 return mUserExpanded;
1210 }
1211
Selim Cinek1685e632014-04-08 02:27:49 +02001212 /**
1213 * Set this notification to be expanded by the user
1214 *
1215 * @param userExpanded whether the user wants this notification to be expanded
1216 */
Chris Wren51c75102013-07-16 20:49:17 -04001217 public void setUserExpanded(boolean userExpanded) {
Selim Cinek388df6d2015-10-22 13:25:11 -07001218 setUserExpanded(userExpanded, false /* allowChildExpansion */);
1219 }
1220
1221 /**
1222 * Set this notification to be expanded by the user
1223 *
1224 * @param userExpanded whether the user wants this notification to be expanded
1225 * @param allowChildExpansion whether a call to this method allows expanding children
1226 */
1227 public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001228 mFalsingManager.setNotificationExpanded();
Selim Cinek388df6d2015-10-22 13:25:11 -07001229 if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion) {
Chris Wren698b1702016-05-23 11:16:32 -04001230 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinek388df6d2015-10-22 13:25:11 -07001231 mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded);
Chris Wren698b1702016-05-23 11:16:32 -04001232 logExpansionEvent(true /* userAction */, wasExpanded);
Selim Cinek388df6d2015-10-22 13:25:11 -07001233 return;
1234 }
Christoph Studera7fe6312014-06-27 19:32:44 +02001235 if (userExpanded && !mExpandable) return;
Chris Wren78403d72014-07-28 10:23:24 +01001236 final boolean wasExpanded = isExpanded();
Selim Cinek1685e632014-04-08 02:27:49 +02001237 mHasUserChangedExpansion = true;
Chris Wren51c75102013-07-16 20:49:17 -04001238 mUserExpanded = userExpanded;
Chris Wren78403d72014-07-28 10:23:24 +01001239 logExpansionEvent(true, wasExpanded);
Chris Wren51c75102013-07-16 20:49:17 -04001240 }
1241
Selim Cinekccd14fb2014-08-12 18:53:24 +02001242 public void resetUserExpansion() {
1243 mHasUserChangedExpansion = false;
1244 mUserExpanded = false;
1245 }
1246
Chris Wren51c75102013-07-16 20:49:17 -04001247 public boolean isUserLocked() {
Selim Cinek1b2a05e2016-04-28 14:20:39 -07001248 return mUserLocked && !mForceUnlocked;
Chris Wren51c75102013-07-16 20:49:17 -04001249 }
1250
1251 public void setUserLocked(boolean userLocked) {
1252 mUserLocked = userLocked;
Selim Cinek8f2f6a62016-02-23 19:56:31 -08001253 mPrivateLayout.setUserExpanding(userLocked);
Selim Cinek42357e02016-02-24 18:48:01 -08001254 if (mIsSummaryWithChildren) {
1255 mChildrenContainer.setUserLocked(userLocked);
Selim Cinek7baaa9e2016-07-21 17:21:09 -07001256 if (userLocked || !isGroupExpanded()) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001257 updateBackgroundForGroupState();
1258 }
Selim Cinek42357e02016-02-24 18:48:01 -08001259 }
Chris Wren51c75102013-07-16 20:49:17 -04001260 }
1261
Selim Cinek1685e632014-04-08 02:27:49 +02001262 /**
1263 * @return has the system set this notification to be expanded
1264 */
1265 public boolean isSystemExpanded() {
1266 return mIsSystemExpanded;
1267 }
1268
1269 /**
1270 * Set this notification to be expanded by the system.
1271 *
1272 * @param expand whether the system wants this notification to be expanded.
1273 */
1274 public void setSystemExpanded(boolean expand) {
Selim Cinek31094df2014-08-14 19:28:15 +02001275 if (expand != mIsSystemExpanded) {
1276 final boolean wasExpanded = isExpanded();
1277 mIsSystemExpanded = expand;
Selim Cinekb5605e52015-02-20 18:21:41 +01001278 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +02001279 logExpansionEvent(false, wasExpanded);
Selim Cineked6913b2016-06-01 12:01:17 -07001280 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001281 mChildrenContainer.updateGroupOverflow();
1282 }
Selim Cinek31094df2014-08-14 19:28:15 +02001283 }
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001284 }
1285
1286 /**
Selim Cinek83bc7832015-10-22 13:26:54 -07001287 * @param onKeyguard whether to prevent notification expansion
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001288 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001289 public void setOnKeyguard(boolean onKeyguard) {
1290 if (onKeyguard != mOnKeyguard) {
Selim Cinek31094df2014-08-14 19:28:15 +02001291 final boolean wasExpanded = isExpanded();
Selim Cinek83bc7832015-10-22 13:26:54 -07001292 mOnKeyguard = onKeyguard;
Selim Cinek31094df2014-08-14 19:28:15 +02001293 logExpansionEvent(false, wasExpanded);
1294 if (wasExpanded != isExpanded()) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001295 if (mIsSummaryWithChildren) {
1296 mChildrenContainer.updateGroupOverflow();
1297 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001298 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +02001299 }
1300 }
Selim Cinek1685e632014-04-08 02:27:49 +02001301 }
1302
1303 /**
Selim Cinek9e624e72016-07-20 13:46:49 -07001304 * @return Can the underlying notification be cleared? This can be different from whether the
1305 * notification can be dismissed in case notifications are sensitive on the lockscreen.
1306 * @see #canViewBeDismissed()
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001307 */
1308 public boolean isClearable() {
Selim Cinek506deb62016-07-20 15:43:59 -07001309 if (mStatusBarNotification == null || !mStatusBarNotification.isClearable()) {
1310 return false;
1311 }
1312 if (mIsSummaryWithChildren) {
1313 List<ExpandableNotificationRow> notificationChildren =
1314 mChildrenContainer.getNotificationChildren();
1315 for (int i = 0; i < notificationChildren.size(); i++) {
1316 ExpandableNotificationRow child = notificationChildren.get(i);
1317 if (!child.isClearable()) {
1318 return false;
1319 }
1320 }
1321 }
1322 return true;
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001323 }
1324
Jorim Jaggi9cbadd32014-05-01 20:18:31 +02001325 @Override
1326 public int getIntrinsicHeight() {
Jorim Jaggibe565df2014-04-28 17:51:23 +02001327 if (isUserLocked()) {
1328 return getActualHeight();
1329 }
Selim Cinekd84a5932015-12-15 11:45:36 -08001330 if (mGuts != null && mGuts.areGutsExposed()) {
1331 return mGuts.getHeight();
1332 } else if ((isChildInGroup() && !isGroupExpanded())) {
1333 return mPrivateLayout.getMinHeight();
1334 } else if (mSensitive && mHideSensitiveForIntrinsicHeight) {
1335 return getMinHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001336 } else if (mIsSummaryWithChildren && !mOnKeyguard) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001337 return mChildrenContainer.getIntrinsicHeight();
Selim Cinek73cf02a2016-06-17 13:08:00 -07001338 } else if (mIsHeadsUp || mHeadsupDisappearRunning) {
1339 if (isPinned() || mHeadsupDisappearRunning) {
Selim Cinek31aada42015-12-18 17:51:15 -08001340 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
1341 } else if (isExpanded()) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001342 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001343 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001344 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001345 }
Selim Cinek31aada42015-12-18 17:51:15 -08001346 } else if (isExpanded()) {
Selim Cinek83bc7832015-10-22 13:26:54 -07001347 return getMaxExpandHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -08001348 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001349 return getCollapsedHeight();
Selim Cinek1685e632014-04-08 02:27:49 +02001350 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001351 }
Selim Cinek1685e632014-04-08 02:27:49 +02001352
Mady Mellorb0a82462016-04-30 17:31:02 -07001353 public boolean isGroupExpanded() {
Selim Cinekeef84282015-10-30 16:28:00 -07001354 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinekb5605e52015-02-20 18:21:41 +01001355 }
1356
Selim Cinek263398f2015-10-21 17:40:23 -07001357 private void onChildrenCountChanged() {
Selim Cinek8fc93c92015-11-23 17:48:07 -08001358 mIsSummaryWithChildren = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS
Mady Mellorb0a82462016-04-30 17:31:02 -07001359 && mChildrenContainer != null && mChildrenContainer.getNotificationChildCount() > 0;
1360 if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() == null) {
1361 mChildrenContainer.recreateNotificationHeader(mExpandClickListener,
1362 mEntry.notification);
Selim Cinek263398f2015-10-21 17:40:23 -07001363 }
Mady Mellor6baed9e2016-05-25 16:05:09 -07001364 getShowingLayout().updateBackgroundColor(false /* animate */);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001365 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinekea4bef72015-12-02 15:51:10 -08001366 updateChildrenHeaderAppearance();
Selim Cinekda42d652015-12-04 15:51:16 -08001367 updateChildrenVisibility();
Selim Cinek263398f2015-10-21 17:40:23 -07001368 }
1369
Mady Mellorb0a82462016-04-30 17:31:02 -07001370 public void updateChildrenHeaderAppearance() {
Selim Cineked6913b2016-06-01 12:01:17 -07001371 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001372 mChildrenContainer.updateChildrenHeaderAppearance();
1373 }
1374 }
1375
Selim Cinek1685e632014-04-08 02:27:49 +02001376 /**
1377 * Check whether the view state is currently expanded. This is given by the system in {@link
1378 * #setSystemExpanded(boolean)} and can be overridden by user expansion or
1379 * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this
1380 * view can differ from this state, if layout params are modified from outside.
1381 *
1382 * @return whether the view state is currently expanded.
1383 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001384 public boolean isExpanded() {
Selim Cineke81b82b2016-03-04 11:22:28 -08001385 return isExpanded(false /* allowOnKeyguard */);
1386 }
1387
1388 public boolean isExpanded(boolean allowOnKeyguard) {
1389 return (!mOnKeyguard || allowOnKeyguard)
Selim Cinekb5605e52015-02-20 18:21:41 +01001390 && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded())
1391 || isUserExpanded());
1392 }
1393
1394 private boolean isSystemChildExpanded() {
1395 return mIsSystemChildExpanded;
1396 }
1397
1398 public void setSystemChildExpanded(boolean expanded) {
1399 mIsSystemChildExpanded = expanded;
Selim Cinek1685e632014-04-08 02:27:49 +02001400 }
1401
1402 @Override
1403 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
1404 super.onLayout(changed, left, top, right, bottom);
Selim Cinek8d490d42015-04-10 00:05:50 -07001405 updateMaxHeights();
Mady Mellora6edc872016-04-26 11:01:03 -07001406 if (mSettingsIconRow != null) {
1407 mSettingsIconRow.updateVerticalLocation();
1408 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001409 updateContentShiftHeight();
1410 }
1411
1412 /**
1413 * Updates the content shift height such that the header is completely hidden when coming from
1414 * the top.
1415 */
1416 private void updateContentShiftHeight() {
1417 NotificationHeaderView notificationHeader = getNotificationHeader();
1418 if (notificationHeader != null) {
1419 CachingIconView icon = notificationHeader.getIcon();
1420 mIconTransformContentShift = getRelativeTopPadding(icon) + icon.getHeight();
1421 } else {
1422 mIconTransformContentShift = mIconTransformContentShiftNoIcon;
1423 }
Selim Cinek1685e632014-04-08 02:27:49 +02001424 }
1425
Selim Cinek8d490d42015-04-10 00:05:50 -07001426 private void updateMaxHeights() {
Selim Cinekd2319fb2014-09-01 19:41:54 +02001427 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek8d490d42015-04-10 00:05:50 -07001428 View expandedChild = mPrivateLayout.getExpandedChild();
1429 if (expandedChild == null) {
1430 expandedChild = mPrivateLayout.getContractedChild();
1431 }
1432 mMaxExpandHeight = expandedChild.getHeight();
1433 View headsUpChild = mPrivateLayout.getHeadsUpChild();
Selim Cinek1f3f5442015-04-10 17:54:46 -07001434 if (headsUpChild == null) {
1435 headsUpChild = mPrivateLayout.getContractedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -07001436 }
Selim Cinek1f3f5442015-04-10 17:54:46 -07001437 mHeadsUpHeight = headsUpChild.getHeight();
Selim Cinekd2319fb2014-09-01 19:41:54 +02001438 if (intrinsicBefore != getIntrinsicHeight()) {
Selim Cinekbb42b7d2016-08-10 13:02:38 -07001439 notifyHeightChanged(true /* needsAnimation */);
Selim Cinekd2319fb2014-09-01 19:41:54 +02001440 }
1441 }
1442
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001443 @Override
1444 public void notifyHeightChanged(boolean needsAnimation) {
1445 super.notifyHeightChanged(needsAnimation);
1446 getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked());
1447 }
1448
Selim Cinek3c76d502016-02-19 15:16:33 -08001449 public void setSensitive(boolean sensitive, boolean hideSensitive) {
Jorim Jaggiae441282014-08-01 02:45:18 +02001450 mSensitive = sensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -08001451 mSensitiveHiddenInGeneral = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02001452 }
1453
1454 public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
Selim Cinek60122be2015-04-15 18:16:50 -07001455 mHideSensitiveForIntrinsicHeight = hideSensitive;
Selim Cineka52f6a12016-02-29 15:35:58 -08001456 if (mIsSummaryWithChildren) {
1457 List<ExpandableNotificationRow> notificationChildren =
1458 mChildrenContainer.getNotificationChildren();
1459 for (int i = 0; i < notificationChildren.size(); i++) {
1460 ExpandableNotificationRow child = notificationChildren.get(i);
1461 child.setHideSensitiveForIntrinsicHeight(hideSensitive);
1462 }
1463 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001464 }
1465
1466 public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
1467 long duration) {
1468 boolean oldShowingPublic = mShowingPublic;
1469 mShowingPublic = mSensitive && hideSensitive;
1470 if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
1471 return;
1472 }
Dan Sandlera5e0f412014-01-23 15:11:54 -05001473
1474 // bail out if no public version
Selim Cinek1685e632014-04-08 02:27:49 +02001475 if (mPublicLayout.getChildCount() == 0) return;
Dan Sandlera5e0f412014-01-23 15:11:54 -05001476
Jorim Jaggiae441282014-08-01 02:45:18 +02001477 if (!animated) {
1478 mPublicLayout.animate().cancel();
1479 mPrivateLayout.animate().cancel();
Selim Cineka554c702016-06-17 18:02:12 -07001480 if (mChildrenContainer != null) {
1481 mChildrenContainer.animate().cancel();
1482 mChildrenContainer.setAlpha(1f);
1483 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001484 mPublicLayout.setAlpha(1f);
1485 mPrivateLayout.setAlpha(1f);
1486 mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
Selim Cinekd84a5932015-12-15 11:45:36 -08001487 updateChildrenVisibility();
Jorim Jaggiae441282014-08-01 02:45:18 +02001488 } else {
1489 animateShowingPublic(delay, duration);
1490 }
Selim Cinekc3179332016-03-04 14:44:56 -08001491 NotificationContentView showingLayout = getShowingLayout();
1492 showingLayout.updateBackgroundColor(animated);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001493 mPrivateLayout.updateExpandButtons(isExpandable());
Jorim Jaggiae441282014-08-01 02:45:18 +02001494 mShowingPublicInitialized = true;
1495 }
1496
1497 private void animateShowingPublic(long delay, long duration) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001498 View[] privateViews = mIsSummaryWithChildren
1499 ? new View[] {mChildrenContainer}
Selim Cinekd84a5932015-12-15 11:45:36 -08001500 : new View[] {mPrivateLayout};
1501 View[] publicViews = new View[] {mPublicLayout};
1502 View[] hiddenChildren = mShowingPublic ? privateViews : publicViews;
1503 View[] shownChildren = mShowingPublic ? publicViews : privateViews;
1504 for (final View hiddenView : hiddenChildren) {
1505 hiddenView.setVisibility(View.VISIBLE);
1506 hiddenView.animate().cancel();
1507 hiddenView.animate()
1508 .alpha(0f)
1509 .setStartDelay(delay)
1510 .setDuration(duration)
1511 .withEndAction(new Runnable() {
1512 @Override
1513 public void run() {
1514 hiddenView.setVisibility(View.INVISIBLE);
1515 }
1516 });
1517 }
1518 for (View showView : shownChildren) {
1519 showView.setVisibility(View.VISIBLE);
1520 showView.setAlpha(0f);
1521 showView.animate().cancel();
1522 showView.animate()
1523 .alpha(1f)
1524 .setStartDelay(delay)
1525 .setDuration(duration);
1526 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001527 }
1528
Selim Cinek3776fe02016-02-04 13:32:43 -08001529 public boolean mustStayOnScreen() {
1530 return mIsHeadsUp;
1531 }
1532
Selim Cinek9e624e72016-07-20 13:46:49 -07001533 /**
1534 * @return Whether this view is allowed to be dismissed. Only valid for visible notifications as
1535 * otherwise some state might not be updated. To request about the general clearability
1536 * see {@link #isClearable()}.
1537 */
1538 public boolean canViewBeDismissed() {
Selim Cineke9bad242016-06-15 11:46:37 -07001539 return isClearable() && (!mShowingPublic || !mSensitiveHiddenInGeneral);
Dan Sandlera5e0f412014-01-23 15:11:54 -05001540 }
Jorim Jaggi251957d2014-04-09 04:24:09 +02001541
Ricky Waicd35def2016-05-03 11:07:07 +01001542 public void makeActionsVisibile() {
1543 setUserExpanded(true, true);
1544 if (isChildInGroup()) {
1545 mGroupManager.setGroupExpanded(mStatusBarNotification, true);
1546 }
Selim Cinekbb42b7d2016-08-10 13:02:38 -07001547 notifyHeightChanged(false /* needsAnimation */);
Ricky Waicd35def2016-05-03 11:07:07 +01001548 }
1549
Selim Cinekb5605e52015-02-20 18:21:41 +01001550 public void setChildrenExpanded(boolean expanded, boolean animate) {
1551 mChildrenExpanded = expanded;
Selim Cinek83bc7832015-10-22 13:26:54 -07001552 if (mChildrenContainer != null) {
1553 mChildrenContainer.setChildrenExpanded(expanded);
1554 }
Mady Mellor1a5d8ea2016-06-09 10:42:42 -07001555 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -07001556 updateClickAndFocus();
Selim Cinekb5605e52015-02-20 18:21:41 +01001557 }
1558
Selim Cinekb5605e52015-02-20 18:21:41 +01001559 public static void applyTint(View v, int color) {
1560 int alpha;
1561 if (color != 0) {
1562 alpha = COLORED_DIVIDER_ALPHA;
1563 } else {
1564 color = 0xff000000;
1565 alpha = DEFAULT_DIVIDER_ALPHA;
1566 }
1567 if (v.getBackground() instanceof ColorDrawable) {
1568 ColorDrawable background = (ColorDrawable) v.getBackground();
1569 background.mutate();
1570 background.setColor(color);
1571 background.setAlpha(alpha);
1572 }
1573 }
1574
Selim Cinek1685e632014-04-08 02:27:49 +02001575 public int getMaxExpandHeight() {
Selim Cinekb5605e52015-02-20 18:21:41 +01001576 return mMaxExpandHeight;
Chris Wren51c75102013-07-16 20:49:17 -04001577 }
Jorim Jaggi584a7aa2014-04-10 23:26:13 +02001578
Mady Mellor34958fa2016-02-23 09:52:17 -08001579 public boolean areGutsExposed() {
1580 return (mGuts != null && mGuts.areGutsExposed());
1581 }
1582
Jorim Jaggibe565df2014-04-28 17:51:23 +02001583 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001584 public boolean isContentExpandable() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001585 NotificationContentView showingLayout = getShowingLayout();
1586 return showingLayout.isContentExpandable();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001587 }
1588
1589 @Override
Selim Cinek560e64d2015-06-09 19:58:11 -07001590 protected View getContentView() {
Selim Cinekaa3901a2016-08-05 11:04:37 -07001591 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cineka5703182016-05-11 21:23:16 -04001592 return mChildrenContainer;
1593 }
Selim Cinek560e64d2015-06-09 19:58:11 -07001594 return getShowingLayout();
1595 }
1596
1597 @Override
Selim Cinekaa3901a2016-08-05 11:04:37 -07001598 protected void onAppearAnimationFinished(boolean wasAppearing) {
1599 super.onAppearAnimationFinished(wasAppearing);
1600 if (wasAppearing) {
1601 // During the animation the visible view might have changed, so let's make sure all
1602 // alphas are reset
1603 if (mChildrenContainer != null) {
1604 mChildrenContainer.setAlpha(1.0f);
1605 mChildrenContainer.setLayerType(LAYER_TYPE_NONE, null);
1606 }
1607 mPrivateLayout.setAlpha(1.0f);
1608 mPrivateLayout.setLayerType(LAYER_TYPE_NONE, null);
1609 mPublicLayout.setAlpha(1.0f);
1610 mPublicLayout.setLayerType(LAYER_TYPE_NONE, null);
1611 }
1612 }
1613
1614 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -07001615 public int getExtraBottomPadding() {
1616 if (mIsSummaryWithChildren && isGroupExpanded()) {
1617 return mIncreasedPaddingBetweenElements;
1618 }
1619 return 0;
1620 }
1621
1622 @Override
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001623 public void setActualHeight(int height, boolean notifyListeners) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001624 super.setActualHeight(height, notifyListeners);
Mady Mellorb53bc272016-02-11 18:28:23 -08001625 if (mGuts != null && mGuts.areGutsExposed()) {
1626 mGuts.setActualHeight(height);
1627 return;
1628 }
Selim Cinekeef84282015-10-30 16:28:00 -07001629 int contentHeight = Math.max(getMinHeight(), height);
Selim Cinekb5605e52015-02-20 18:21:41 +01001630 mPrivateLayout.setContentHeight(contentHeight);
1631 mPublicLayout.setContentHeight(contentHeight);
Selim Cinek42357e02016-02-24 18:48:01 -08001632 if (mIsSummaryWithChildren) {
1633 mChildrenContainer.setActualHeight(height);
1634 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001635 if (mGuts != null) {
1636 mGuts.setActualHeight(height);
1637 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001638 }
1639
1640 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01001641 public int getMaxContentHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001642 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001643 return mChildrenContainer.getMaxContentHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001644 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001645 NotificationContentView showingLayout = getShowingLayout();
1646 return showingLayout.getMaxHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001647 }
1648
1649 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001650 public int getMinHeight() {
Selim Cinek31aada42015-12-18 17:51:15 -08001651 if (mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) {
1652 return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
1653 } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001654 return mChildrenContainer.getMinHeight();
Selim Cinek31aada42015-12-18 17:51:15 -08001655 } else if (mIsHeadsUp) {
1656 return mHeadsUpHeight;
Selim Cinekb55386d2015-12-16 17:26:49 -08001657 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001658 NotificationContentView showingLayout = getShowingLayout();
1659 return showingLayout.getMinHeight();
1660 }
1661
1662 @Override
Selim Cinek567e8452016-03-24 10:54:56 -07001663 public int getCollapsedHeight() {
Selim Cinek2c584612016-02-29 16:14:25 -08001664 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinek567e8452016-03-24 10:54:56 -07001665 return mChildrenContainer.getCollapsedHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001666 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001667 return getMinHeight();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001668 }
1669
1670 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02001671 public void setClipTopAmount(int clipTopAmount) {
1672 super.setClipTopAmount(clipTopAmount);
1673 mPrivateLayout.setClipTopAmount(clipTopAmount);
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001674 mPublicLayout.setClipTopAmount(clipTopAmount);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001675 if (mGuts != null) {
1676 mGuts.setClipTopAmount(clipTopAmount);
1677 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001678 }
1679
Selim Cineka686b2c2016-10-26 13:58:27 -07001680 @Override
1681 public void setClipBottomAmount(int clipBottomAmount) {
1682 super.setClipBottomAmount(clipBottomAmount);
1683 mPrivateLayout.setClipBottomAmount(clipBottomAmount);
1684 mPublicLayout.setClipBottomAmount(clipBottomAmount);
1685 if (mGuts != null) {
1686 mGuts.setClipBottomAmount(clipBottomAmount);
1687 }
1688 }
1689
Selim Cinek31094df2014-08-14 19:28:15 +02001690 public boolean isMaxExpandHeightInitialized() {
1691 return mMaxExpandHeight != 0;
Selim Cinek7d447722014-06-10 15:51:59 +02001692 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001693
Selim Cinek42357e02016-02-24 18:48:01 -08001694 public NotificationContentView getShowingLayout() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001695 return mShowingPublic ? mPublicLayout : mPrivateLayout;
1696 }
Chris Wren78403d72014-07-28 10:23:24 +01001697
Jorim Jaggi59ec3042015-06-05 15:18:43 -07001698 @Override
1699 public void setShowingLegacyBackground(boolean showing) {
1700 super.setShowingLegacyBackground(showing);
1701 mPrivateLayout.setShowingLegacyBackground(showing);
1702 mPublicLayout.setShowingLegacyBackground(showing);
1703 }
1704
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001705 @Override
1706 protected void updateBackgroundTint() {
1707 super.updateBackgroundTint();
Mady Mellorb0a82462016-04-30 17:31:02 -07001708 updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001709 if (mIsSummaryWithChildren) {
1710 List<ExpandableNotificationRow> notificationChildren =
1711 mChildrenContainer.getNotificationChildren();
1712 for (int i = 0; i < notificationChildren.size(); i++) {
1713 ExpandableNotificationRow child = notificationChildren.get(i);
Mady Mellorb0a82462016-04-30 17:31:02 -07001714 child.updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001715 }
1716 }
1717 }
1718
Mady Mellorb0a82462016-04-30 17:31:02 -07001719 /**
1720 * Called when a group has finished animating from collapsed or expanded state.
1721 */
1722 public void onFinishedExpansionChange() {
1723 mGroupExpansionChanging = false;
1724 updateBackgroundForGroupState();
1725 }
1726
1727 /**
1728 * Updates the parent and children backgrounds in a group based on the expansion state.
1729 */
1730 public void updateBackgroundForGroupState() {
1731 if (mIsSummaryWithChildren) {
1732 // Only when the group has finished expanding do we hide its background.
1733 mShowNoBackground = isGroupExpanded() && !isGroupExpansionChanging() && !isUserLocked();
1734 mChildrenContainer.updateHeaderForExpansion(mShowNoBackground);
1735 List<ExpandableNotificationRow> children = mChildrenContainer.getNotificationChildren();
1736 for (int i = 0; i < children.size(); i++) {
1737 children.get(i).updateBackgroundForGroupState();
1738 }
1739 } else if (isChildInGroup()) {
1740 final int childColor = getShowingLayout().getBackgroundColorForExpansionState();
1741 // Only show a background if the group is expanded OR if it is expanding / collapsing
1742 // and has a custom background color
1743 final boolean showBackground = isGroupExpanded()
1744 || ((mNotificationParent.isGroupExpansionChanging()
1745 || mNotificationParent.isUserLocked()) && childColor != 0);
1746 mShowNoBackground = !showBackground;
1747 } else {
1748 // Only children or parents ever need no background.
1749 mShowNoBackground = false;
1750 }
1751 updateOutline();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001752 updateBackground();
1753 }
1754
Adrian Roos4a579672016-05-24 16:54:37 -07001755 public int getPositionOfChild(ExpandableNotificationRow childRow) {
1756 if (mIsSummaryWithChildren) {
1757 return mChildrenContainer.getPositionInLinearLayout(childRow);
1758 }
1759 return 0;
1760 }
1761
Chris Wren78403d72014-07-28 10:23:24 +01001762 public void setExpansionLogger(ExpansionLogger logger, String key) {
1763 mLogger = logger;
1764 mLoggingKey = key;
1765 }
1766
Chris Wren6abeeb92016-05-26 14:44:38 -04001767 public void onExpandedByGesture(boolean userExpanded) {
1768 int event = MetricsEvent.ACTION_NOTIFICATION_GESTURE_EXPANDER;
1769 if (mGroupManager.isSummaryOfGroup(getStatusBarNotification())) {
1770 event = MetricsEvent.ACTION_NOTIFICATION_GROUP_GESTURE_EXPANDER;
1771 }
1772 MetricsLogger.action(mContext, event, userExpanded);
1773 }
1774
Selim Cinek6183d122016-01-14 18:48:41 -08001775 @Override
Selim Cinek42357e02016-02-24 18:48:01 -08001776 public float getIncreasedPaddingAmount() {
1777 if (mIsSummaryWithChildren) {
1778 if (isGroupExpanded()) {
1779 return 1.0f;
1780 } else if (isUserLocked()) {
Selim Cinekf07d0622016-03-21 19:52:52 -07001781 return mChildrenContainer.getGroupExpandFraction();
Selim Cinek42357e02016-02-24 18:48:01 -08001782 }
1783 }
1784 return 0.0f;
Selim Cinek61633a82016-01-25 15:54:10 -08001785 }
1786
1787 @Override
Selim Cinek6183d122016-01-14 18:48:41 -08001788 protected boolean disallowSingleClick(MotionEvent event) {
1789 float x = event.getX();
1790 float y = event.getY();
Selim Cinek34eda5e2016-02-18 17:10:43 -08001791 NotificationHeaderView header = getVisibleNotificationHeader();
Selim Cinek6183d122016-01-14 18:48:41 -08001792 if (header != null) {
Mady Mellora8833512016-03-09 09:50:18 -08001793 return header.isInTouchRect(x - getTranslation(), y);
Selim Cinek6183d122016-01-14 18:48:41 -08001794 }
1795 return super.disallowSingleClick(event);
1796 }
1797
Chris Wren78403d72014-07-28 10:23:24 +01001798 private void logExpansionEvent(boolean userAction, boolean wasExpanded) {
Chris Wren698b1702016-05-23 11:16:32 -04001799 boolean nowExpanded = isExpanded();
1800 if (mIsSummaryWithChildren) {
1801 nowExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
1802 }
Chris Wren78403d72014-07-28 10:23:24 +01001803 if (wasExpanded != nowExpanded && mLogger != null) {
1804 mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ;
1805 }
1806 }
Selim Cinek570981d2015-12-01 11:37:01 -08001807
Selim Cineke9bad242016-06-15 11:46:37 -07001808 @Override
1809 public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
1810 super.onInitializeAccessibilityNodeInfoInternal(info);
1811 if (canViewBeDismissed()) {
1812 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS);
1813 }
1814 }
1815
1816 @Override
1817 public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
1818 if (super.performAccessibilityActionInternal(action, arguments)) {
1819 return true;
1820 }
1821 switch (action) {
1822 case AccessibilityNodeInfo.ACTION_DISMISS:
1823 NotificationStackScrollLayout.performDismiss(this, mGroupManager,
1824 true /* fromAccessibility */);
1825 return true;
1826 }
1827 return false;
1828 }
1829
1830 public boolean shouldRefocusOnDismiss() {
1831 return mRefocusOnDismiss || isAccessibilityFocused();
1832 }
1833
Selim Cinek570981d2015-12-01 11:37:01 -08001834 public interface OnExpandClickListener {
Selim Cinek31aada42015-12-18 17:51:15 -08001835 void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
Selim Cinek570981d2015-12-01 11:37:01 -08001836 }
Selim Cinekbbcebde2016-11-09 18:28:20 -08001837
1838 @Override
1839 public ExpandableViewState createNewViewState(StackScrollState stackScrollState) {
1840 return new NotificationViewState(stackScrollState);
1841 }
1842
Selim Cinekd127d792016-11-01 19:11:41 -07001843 @Override
1844 public boolean isAboveShelf() {
1845 return mIsPinned || mHeadsupDisappearRunning || (mIsHeadsUp && mAboveShelf);
1846 }
1847
1848 public void setAboveShelf(boolean aboveShelf) {
1849 mAboveShelf = aboveShelf;
1850 }
1851
Selim Cinek0cfbef42016-11-09 19:06:36 -08001852 public class NotificationViewState extends ExpandableViewState {
Selim Cinekbbcebde2016-11-09 18:28:20 -08001853
1854 private final StackScrollState mOverallState;
Selim Cinek0242fbb2016-10-19 13:38:32 -07001855
Selim Cinekbbcebde2016-11-09 18:28:20 -08001856
1857 private NotificationViewState(StackScrollState stackScrollState) {
1858 mOverallState = stackScrollState;
1859 }
1860
1861 @Override
1862 public void applyToView(View view) {
1863 super.applyToView(view);
1864 if (view instanceof ExpandableNotificationRow) {
1865 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
1866 if (this.isBottomClipped) {
1867 row.setClipToActualHeight(true);
1868 }
1869 row.applyChildrenState(mOverallState);
1870 }
1871 }
Selim Cinek0cfbef42016-11-09 19:06:36 -08001872
1873 @Override
1874 protected void onYTranslationAnimationFinished() {
1875 super.onYTranslationAnimationFinished();
1876 if (mHeadsupDisappearRunning) {
Selim Cinekcafa87f2016-10-26 17:00:17 -07001877 setHeadsUpAnimatingAway(false);
Selim Cinek0cfbef42016-11-09 19:06:36 -08001878 }
1879 }
1880
1881 @Override
1882 public void animateTo(View child, AnimationProperties properties) {
1883 super.animateTo(child, properties);
1884 if (child instanceof ExpandableNotificationRow) {
1885 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
1886 row.startChildAnimation(mOverallState, properties);
1887 }
1888 }
Selim Cinekbbcebde2016-11-09 18:28:20 -08001889 }
Chris Wren51c75102013-07-16 20:49:17 -04001890}