blob: bf6db23d8366172d1d396e624c927fcd95a8cb5d [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
Selim Cinek5ba22542017-04-20 15:16:10 -070019import static com.android.systemui.statusbar.notification.NotificationInflater.InflationCallback;
Selim Cinekc478f902017-02-22 20:55:44 -080020
Mady Mellor4b80b102016-01-22 08:03:58 -080021import android.animation.Animator;
22import android.animation.AnimatorListenerAdapter;
Mady Mellor4b80b102016-01-22 08:03:58 -080023import android.animation.ObjectAnimator;
Mady Mellor4b80b102016-01-22 08:03:58 -080024import android.animation.ValueAnimator.AnimatorUpdateListener;
Selim Cinekddf1b392016-05-27 16:33:10 -070025import android.annotation.Nullable;
Chris Wren51c75102013-07-16 20:49:17 -040026import android.content.Context;
Anthony Chen7acbb772017-04-07 16:45:25 -070027import android.content.res.Resources;
Mady Mellor9d03a522017-04-04 18:45:30 -070028import android.content.res.Configuration;
Selim Cinekcab4a602014-09-03 14:47:57 +020029import android.graphics.drawable.AnimatedVectorDrawable;
30import android.graphics.drawable.AnimationDrawable;
Selim Cinekb5605e52015-02-20 18:21:41 +010031import android.graphics.drawable.ColorDrawable;
Selim Cinekcab4a602014-09-03 14:47:57 +020032import android.graphics.drawable.Drawable;
Selim Cinekda42d652015-12-04 15:51:16 -080033import android.os.Build;
Selim Cineke9bad242016-06-15 11:46:37 -070034import android.os.Bundle;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020035import android.service.notification.StatusBarNotification;
Chris Wren51c75102013-07-16 20:49:17 -040036import android.util.AttributeSet;
Mady Mellorb0a82462016-04-30 17:31:02 -070037import android.util.FloatProperty;
38import android.util.Property;
Selim Cinek01af3342016-02-09 19:25:31 -080039import android.view.LayoutInflater;
Selim Cinek6183d122016-01-14 18:48:41 -080040import android.view.MotionEvent;
Selim Cinekeaa29ca2015-11-23 13:51:13 -080041import android.view.NotificationHeaderView;
Dan Sandlera5e0f412014-01-23 15:11:54 -050042import android.view.View;
Selim Cinek875a3a12016-11-18 17:52:16 -080043import android.view.ViewGroup;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020044import android.view.ViewStub;
Jorim Jaggife40f7d2014-04-28 15:20:04 +020045import android.view.accessibility.AccessibilityEvent;
Selim Cineke9bad242016-06-15 11:46:37 -070046import android.view.accessibility.AccessibilityNodeInfo;
Selim Cinek98713a42015-09-21 15:47:20 +020047import android.widget.Chronometer;
Mady Mellor95d743c2017-01-10 12:05:27 -080048import android.widget.FrameLayout;
Selim Cinekcab4a602014-09-03 14:47:57 +020049import android.widget.ImageView;
Selim Cinek1a48bab2017-02-17 19:38:40 -080050import android.widget.RemoteViews;
Selim Cinekb5605e52015-02-20 18:21:41 +010051
Selim Cinek5ba22542017-04-20 15:16:10 -070052import com.android.internal.annotations.VisibleForTesting;
Chris Wren698b1702016-05-23 11:16:32 -040053import com.android.internal.logging.MetricsLogger;
Tamas Berghammer383db5eb2016-06-22 15:21:38 +010054import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Selim Cinek4bb59342016-04-08 19:29:35 -070055import com.android.internal.util.NotificationColorUtil;
Selim Cinek875a3a12016-11-18 17:52:16 -080056import com.android.internal.widget.CachingIconView;
Mady Mellor95d743c2017-01-10 12:05:27 -080057import com.android.systemui.Dependency;
Selim Cinek0242fbb2016-10-19 13:38:32 -070058import com.android.systemui.Interpolators;
Dan Sandlera5e0f412014-01-23 15:11:54 -050059import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070060import com.android.systemui.classifier.FalsingManager;
Mady Mellor95d743c2017-01-10 12:05:27 -080061import com.android.systemui.plugins.PluginListener;
62import com.android.systemui.plugins.PluginManager;
63import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
64import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem;
65import com.android.systemui.statusbar.NotificationGuts.GutsContent;
Selim Cinek5cf1d052017-06-01 17:36:46 -070066import com.android.systemui.statusbar.notification.AboveShelfChangedListener;
67import com.android.systemui.statusbar.notification.AboveShelfObserver;
Selim Cinekc897bd32016-03-18 17:32:31 -070068import com.android.systemui.statusbar.notification.HybridNotificationView;
Selim Cinek1a48bab2017-02-17 19:38:40 -080069import com.android.systemui.statusbar.notification.NotificationInflater;
Selim Cinek6743c0b2017-01-18 18:24:01 -080070import com.android.systemui.statusbar.notification.NotificationUtils;
Selim Cineka7d4f822016-12-06 14:34:47 -080071import com.android.systemui.statusbar.notification.VisualStabilityManager;
Selim Cinekb5605e52015-02-20 18:21:41 +010072import com.android.systemui.statusbar.phone.NotificationGroupManager;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050073import com.android.systemui.statusbar.phone.StatusBar;
Selim Cinek31aada42015-12-18 17:51:15 -080074import com.android.systemui.statusbar.policy.HeadsUpManager;
Selim Cinek0cfbef42016-11-09 19:06:36 -080075import com.android.systemui.statusbar.stack.AnimationProperties;
76import com.android.systemui.statusbar.stack.ExpandableViewState;
Selim Cinekb5605e52015-02-20 18:21:41 +010077import com.android.systemui.statusbar.stack.NotificationChildrenContainer;
Selim Cineke9bad242016-06-15 11:46:37 -070078import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Selim Cinekb5605e52015-02-20 18:21:41 +010079import com.android.systemui.statusbar.stack.StackScrollState;
Selim Cinekb5605e52015-02-20 18:21:41 +010080
Mady Mellor4b80b102016-01-22 08:03:58 -080081import java.util.ArrayList;
Selim Cinekb5605e52015-02-20 18:21:41 +010082import java.util.List;
Dan Sandlera5e0f412014-01-23 15:11:54 -050083
Mady Mellor95d743c2017-01-10 12:05:27 -080084public class ExpandableNotificationRow extends ActivatableNotificationView
85 implements PluginListener<NotificationMenuRowPlugin> {
Selim Cinekb5605e52015-02-20 18:21:41 +010086
87 private static final int DEFAULT_DIVIDER_ALPHA = 0x29;
88 private static final int COLORED_DIVIDER_ALPHA = 0x7B;
Mady Mellor95d743c2017-01-10 12:05:27 -080089 private static final int MENU_VIEW_INDEX = 0;
90
Mady Mellor035badd2017-04-04 18:45:30 -070091 public interface LayoutListener {
92 public void onLayout();
93 }
94
95 private LayoutListener mLayoutListener;
Selim Cinek55a3e732017-05-25 18:30:10 -070096 private boolean mLowPriorityStateUpdated;
Selim Cinek1a48bab2017-02-17 19:38:40 -080097 private final NotificationInflater mNotificationInflater;
Selim Cinek0242fbb2016-10-19 13:38:32 -070098 private int mIconTransformContentShift;
Selim Cinek875a3a12016-11-18 17:52:16 -080099 private int mIconTransformContentShiftNoIcon;
Selim Cinek01af3342016-02-09 19:25:31 -0800100 private int mNotificationMinHeightLegacy;
101 private int mMaxHeadsUpHeightLegacy;
102 private int mMaxHeadsUpHeight;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800103 private int mMaxHeadsUpHeightIncreased;
Selim Cinek01af3342016-02-09 19:25:31 -0800104 private int mNotificationMinHeight;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800105 private int mNotificationMinHeightLarge;
Selim Cinek01af3342016-02-09 19:25:31 -0800106 private int mNotificationMaxHeight;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800107 private int mNotificationAmbientHeight;
Mady Mellorb0a82462016-04-30 17:31:02 -0700108 private int mIncreasedPaddingBetweenElements;
Chris Wren51c75102013-07-16 20:49:17 -0400109
Selim Cinek1685e632014-04-08 02:27:49 +0200110 /** Does this row contain layouts that can adapt to row expansion */
Chris Wren51c75102013-07-16 20:49:17 -0400111 private boolean mExpandable;
Selim Cinek1685e632014-04-08 02:27:49 +0200112 /** Has the user actively changed the expansion state of this row */
113 private boolean mHasUserChangedExpansion;
114 /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */
Chris Wren51c75102013-07-16 20:49:17 -0400115 private boolean mUserExpanded;
Selim Cinek31aada42015-12-18 17:51:15 -0800116
117 /**
118 * Has this notification been expanded while it was pinned
119 */
120 private boolean mExpandedWhenPinned;
Selim Cinek1685e632014-04-08 02:27:49 +0200121 /** Is the user touching this row */
Chris Wren51c75102013-07-16 20:49:17 -0400122 private boolean mUserLocked;
Selim Cinek1685e632014-04-08 02:27:49 +0200123 /** Are we showing the "public" version */
Dan Sandlera5e0f412014-01-23 15:11:54 -0500124 private boolean mShowingPublic;
Jorim Jaggiae441282014-08-01 02:45:18 +0200125 private boolean mSensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -0800126 private boolean mSensitiveHiddenInGeneral;
Jorim Jaggiae441282014-08-01 02:45:18 +0200127 private boolean mShowingPublicInitialized;
Selim Cinek60122be2015-04-15 18:16:50 -0700128 private boolean mHideSensitiveForIntrinsicHeight;
Chris Wren51c75102013-07-16 20:49:17 -0400129
Selim Cinek1685e632014-04-08 02:27:49 +0200130 /**
131 * Is this notification expanded by the system. The expansion state can be overridden by the
132 * user expansion.
133 */
134 private boolean mIsSystemExpanded;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200135
136 /**
Selim Cinek83bc7832015-10-22 13:26:54 -0700137 * Whether the notification is on the keyguard and the expansion is disabled.
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200138 */
Selim Cinek83bc7832015-10-22 13:26:54 -0700139 private boolean mOnKeyguard;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200140
Mady Mellorb0a82462016-04-30 17:31:02 -0700141 private Animator mTranslateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -0800142 private ArrayList<View> mTranslateableViews;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200143 private NotificationContentView mPublicLayout;
144 private NotificationContentView mPrivateLayout;
Adrian Rooseb434ff2017-01-11 11:18:48 -0800145 private NotificationContentView[] mLayouts;
Selim Cinek1685e632014-04-08 02:27:49 +0200146 private int mMaxExpandHeight;
Selim Cinek8d490d42015-04-10 00:05:50 -0700147 private int mHeadsUpHeight;
Selim Cinek4bb59342016-04-08 19:29:35 -0700148 private int mNotificationColor;
Chris Wren78403d72014-07-28 10:23:24 +0100149 private ExpansionLogger mLogger;
150 private String mLoggingKey;
Selim Cinek8d490d42015-04-10 00:05:50 -0700151 private NotificationGuts mGuts;
Selim Cinekda42d652015-12-04 15:51:16 -0800152 private NotificationData.Entry mEntry;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200153 private StatusBarNotification mStatusBarNotification;
Mady Mellor3fd273e2016-03-15 21:08:14 -0700154 private String mAppName;
Selim Cinek1a521f32014-11-03 17:39:29 +0100155 private boolean mIsHeadsUp;
Selim Cinek98713a42015-09-21 15:47:20 +0200156 private boolean mLastChronometerRunning = true;
Selim Cinekb5605e52015-02-20 18:21:41 +0100157 private ViewStub mChildrenContainerStub;
158 private NotificationGroupManager mGroupManager;
Selim Cinekb5605e52015-02-20 18:21:41 +0100159 private boolean mChildrenExpanded;
Selim Cinek263398f2015-10-21 17:40:23 -0700160 private boolean mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100161 private NotificationChildrenContainer mChildrenContainer;
Mady Mellor95d743c2017-01-10 12:05:27 -0800162 private NotificationMenuRowPlugin mMenuRow;
Selim Cinekab29aeb2015-02-20 18:18:32 +0100163 private ViewStub mGutsStub;
Selim Cinekb5605e52015-02-20 18:21:41 +0100164 private boolean mIsSystemChildExpanded;
Selim Cinek684a4422015-04-15 16:18:39 -0700165 private boolean mIsPinned;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700166 private FalsingManager mFalsingManager;
Selim Cinek5cf1d052017-06-01 17:36:46 -0700167 private AboveShelfChangedListener mAboveShelfChangedListener;
Selim Cinek31aada42015-12-18 17:51:15 -0800168 private HeadsUpManager mHeadsUpManager;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200169
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700170 private boolean mJustClicked;
Selim Cinek5a175d92015-11-23 18:01:33 -0800171 private boolean mIconAnimationRunning;
Selim Cinek34d93b02015-10-22 12:30:38 -0700172 private boolean mShowNoBackground;
Selim Cinek388df6d2015-10-22 13:25:11 -0700173 private ExpandableNotificationRow mNotificationParent;
Selim Cinek570981d2015-12-01 11:37:01 -0800174 private OnExpandClickListener mOnExpandClickListener;
Mady Mellorb0a82462016-04-30 17:31:02 -0700175 private boolean mGroupExpansionChanging;
176
Anthony Chen6bf88a02017-04-10 14:41:44 -0700177 /**
178 * Whether or not a notification that is not part of a group of notifications can be manually
179 * expanded by the user.
180 */
181 private boolean mEnableNonGroupedNotificationExpand;
182
183 /**
184 * Whether or not to update the background of the header of the notification when its expanded.
185 * If {@code true}, the header background will disappear when expanded.
186 */
187 private boolean mShowGroupBackgroundWhenExpanded;
188
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800189 private OnClickListener mExpandClickListener = new OnClickListener() {
190 @Override
191 public void onClick(View v) {
Selim Cinek414ad332017-02-24 19:06:12 -0800192 if (!mShowingPublic && (!mIsLowPriority || isExpanded())
193 && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) {
Mady Mellor1a5d8ea2016-06-09 10:42:42 -0700194 mGroupExpansionChanging = true;
Chris Wren698b1702016-05-23 11:16:32 -0400195 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
196 boolean nowExpanded = mGroupManager.toggleGroupExpansion(mStatusBarNotification);
197 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400198 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_GROUP_EXPANDER,
199 nowExpanded);
Selim Cinek414ad332017-02-24 19:06:12 -0800200 onExpansionChanged(true /* userAction */, wasExpanded);
Anthony Chen6bf88a02017-04-10 14:41:44 -0700201 } else if (mEnableNonGroupedNotificationExpand) {
Selim Cineke9bad242016-06-15 11:46:37 -0700202 if (v.isAccessibilityFocused()) {
203 mPrivateLayout.setFocusOnVisibilityChange();
204 }
Selim Cinek31aada42015-12-18 17:51:15 -0800205 boolean nowExpanded;
206 if (isPinned()) {
207 nowExpanded = !mExpandedWhenPinned;
208 mExpandedWhenPinned = nowExpanded;
209 } else {
210 nowExpanded = !isExpanded();
211 setUserExpanded(nowExpanded);
212 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800213 notifyHeightChanged(true);
Selim Cinek31aada42015-12-18 17:51:15 -0800214 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400215 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_EXPANDER,
216 nowExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800217 }
218 }
219 };
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700220 private boolean mForceUnlocked;
Selim Cinek3f19f602016-05-02 18:01:56 -0700221 private boolean mDismissed;
222 private boolean mKeepInParent;
223 private boolean mRemoved;
Mady Mellorb0a82462016-04-30 17:31:02 -0700224 private static final Property<ExpandableNotificationRow, Float> TRANSLATE_CONTENT =
225 new FloatProperty<ExpandableNotificationRow>("translate") {
226 @Override
227 public void setValue(ExpandableNotificationRow object, float value) {
228 object.setTranslation(value);
229 }
230
231 @Override
232 public Float get(ExpandableNotificationRow object) {
233 return object.getTranslation();
234 }
235 };
Selim Cinekddf1b392016-05-27 16:33:10 -0700236 private OnClickListener mOnClickListener;
Selim Cinek73cf02a2016-06-17 13:08:00 -0700237 private boolean mHeadsupDisappearRunning;
Selim Cineke9bad242016-06-15 11:46:37 -0700238 private View mChildAfterViewWhenDismissed;
239 private View mGroupParentWhenDismissed;
240 private boolean mRefocusOnDismiss;
Selim Cinek2b549f42016-11-22 16:38:51 -0800241 private float mContentTransformationAmount;
Selim Cinek0242fbb2016-10-19 13:38:32 -0700242 private boolean mIconsVisible = true;
Selim Cinekd127d792016-11-01 19:11:41 -0700243 private boolean mAboveShelf;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800244 private boolean mShowAmbient;
Selim Cinek875a3a12016-11-18 17:52:16 -0800245 private boolean mIsLastChild;
Selim Cineke9079112016-12-14 14:41:01 -0800246 private Runnable mOnDismissRunnable;
Selim Cinek6743c0b2017-01-18 18:24:01 -0800247 private boolean mIsLowPriority;
Selim Cineka7ed2c12017-01-23 20:47:24 -0800248 private boolean mIsColorized;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800249 private boolean mUseIncreasedCollapsedHeight;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800250 private boolean mUseIncreasedHeadsUpHeight;
Selim Cinekef8c2252017-02-10 14:52:18 -0800251 private float mTranslationWhenRemoved;
252 private boolean mWasChildInGroupWhenRemoved;
Adrian Roos6f6e1592017-05-02 16:22:53 -0700253 private int mNotificationColorAmbient;
Mady Mellorb0a82462016-04-30 17:31:02 -0700254
Mady Mellor43c2cd12016-12-12 21:05:13 -0800255 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -0700256 public boolean isGroupExpansionChanging() {
257 if (isChildInGroup()) {
258 return mNotificationParent.isGroupExpansionChanging();
259 }
260 return mGroupExpansionChanging;
261 }
262
263 public void setGroupExpansionChanging(boolean changing) {
264 mGroupExpansionChanging = changing;
265 }
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700266
Adrian Roos599be342016-06-13 14:54:39 -0700267 @Override
268 public void setActualHeightAnimating(boolean animating) {
269 if (mPrivateLayout != null) {
270 mPrivateLayout.setContentHeightAnimating(animating);
271 }
272 }
273
Selim Cinek8d490d42015-04-10 00:05:50 -0700274 public NotificationContentView getPrivateLayout() {
275 return mPrivateLayout;
276 }
277
278 public NotificationContentView getPublicLayout() {
279 return mPublicLayout;
280 }
281
Selim Cinekcab4a602014-09-03 14:47:57 +0200282 public void setIconAnimationRunning(boolean running) {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800283 for (NotificationContentView l : mLayouts) {
284 setIconAnimationRunning(running, l);
285 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800286 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700287 setIconAnimationRunningForChild(running, mChildrenContainer.getHeaderView());
Selim Cinek414ad332017-02-24 19:06:12 -0800288 setIconAnimationRunningForChild(running, mChildrenContainer.getLowPriorityHeaderView());
Selim Cinek5a175d92015-11-23 18:01:33 -0800289 List<ExpandableNotificationRow> notificationChildren =
290 mChildrenContainer.getNotificationChildren();
291 for (int i = 0; i < notificationChildren.size(); i++) {
292 ExpandableNotificationRow child = notificationChildren.get(i);
293 child.setIconAnimationRunning(running);
294 }
295 }
296 mIconAnimationRunning = running;
Selim Cinekcab4a602014-09-03 14:47:57 +0200297 }
298
299 private void setIconAnimationRunning(boolean running, NotificationContentView layout) {
300 if (layout != null) {
301 View contractedChild = layout.getContractedChild();
302 View expandedChild = layout.getExpandedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -0700303 View headsUpChild = layout.getHeadsUpChild();
Selim Cinekcab4a602014-09-03 14:47:57 +0200304 setIconAnimationRunningForChild(running, contractedChild);
305 setIconAnimationRunningForChild(running, expandedChild);
Selim Cinek8d490d42015-04-10 00:05:50 -0700306 setIconAnimationRunningForChild(running, headsUpChild);
Selim Cinekcab4a602014-09-03 14:47:57 +0200307 }
308 }
309
310 private void setIconAnimationRunningForChild(boolean running, View child) {
311 if (child != null) {
312 ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon);
313 setIconRunning(icon, running);
314 ImageView rightIcon = (ImageView) child.findViewById(
315 com.android.internal.R.id.right_icon);
316 setIconRunning(rightIcon, running);
317 }
318 }
319
320 private void setIconRunning(ImageView imageView, boolean running) {
321 if (imageView != null) {
322 Drawable drawable = imageView.getDrawable();
323 if (drawable instanceof AnimationDrawable) {
324 AnimationDrawable animationDrawable = (AnimationDrawable) drawable;
325 if (running) {
326 animationDrawable.start();
327 } else {
328 animationDrawable.stop();
329 }
330 } else if (drawable instanceof AnimatedVectorDrawable) {
331 AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable;
332 if (running) {
333 animationDrawable.start();
334 } else {
335 animationDrawable.stop();
336 }
337 }
338 }
339 }
340
Selim Cinek5ba22542017-04-20 15:16:10 -0700341 public void updateNotification(NotificationData.Entry entry) {
Selim Cinekda42d652015-12-04 15:51:16 -0800342 mEntry = entry;
343 mStatusBarNotification = entry.notification;
Selim Cinek1a48bab2017-02-17 19:38:40 -0800344 mNotificationInflater.inflateNotificationViews();
Selim Cinekc478f902017-02-22 20:55:44 -0800345 }
346
Selim Cinek5ba22542017-04-20 15:16:10 -0700347 public void onNotificationUpdated() {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800348 for (NotificationContentView l : mLayouts) {
Selim Cinekc478f902017-02-22 20:55:44 -0800349 l.onNotificationUpdated(mEntry);
Adrian Rooseb434ff2017-01-11 11:18:48 -0800350 }
Selim Cineka7ed2c12017-01-23 20:47:24 -0800351 mIsColorized = mStatusBarNotification.getNotification().isColorized();
Selim Cinek757d8792016-01-28 16:21:08 -0800352 mShowingPublicInitialized = false;
Selim Cinek4bb59342016-04-08 19:29:35 -0700353 updateNotificationColor();
Mady Mellor4c197602017-04-10 17:57:52 -0700354 if (mMenuRow != null) {
355 mMenuRow.onNotificationUpdated();
356 }
Selim Cinek8fc93c92015-11-23 17:48:07 -0800357 if (mIsSummaryWithChildren) {
Selim Cinek414ad332017-02-24 19:06:12 -0800358 mChildrenContainer.recreateNotificationHeader(mExpandClickListener);
Selim Cinekc897bd32016-03-18 17:32:31 -0700359 mChildrenContainer.onNotificationUpdated();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800360 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800361 if (mIconAnimationRunning) {
362 setIconAnimationRunning(true);
363 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800364 if (mNotificationParent != null) {
365 mNotificationParent.updateChildrenHeaderAppearance();
366 }
Selim Cinek263398f2015-10-21 17:40:23 -0700367 onChildrenCountChanged();
Selim Cinek624c02db2015-12-14 21:00:02 -0800368 // The public layouts expand button is always visible
369 mPublicLayout.updateExpandButtons(true);
Selim Cinekda42d652015-12-04 15:51:16 -0800370 updateLimits();
Selim Cinek0242fbb2016-10-19 13:38:32 -0700371 updateIconVisibilities();
Selim Cinek6743c0b2017-01-18 18:24:01 -0800372 updateShelfIconColor();
373 }
374
Lucas Dupinb6ed63b2017-05-30 16:17:42 -0700375 @VisibleForTesting
376 void updateShelfIconColor() {
Selim Cinek6743c0b2017-01-18 18:24:01 -0800377 StatusBarIconView expandedIcon = mEntry.expandedIcon;
378 boolean isPreL = Boolean.TRUE.equals(expandedIcon.getTag(R.id.icon_is_pre_L));
379 boolean colorize = !isPreL || NotificationUtils.isGrayscale(expandedIcon,
380 NotificationColorUtil.getInstance(mContext));
Selim Cinek875ba9b2017-02-13 16:20:17 -0800381 int color = StatusBarIconView.NO_COLOR;
Selim Cinek6743c0b2017-01-18 18:24:01 -0800382 if (colorize) {
Lucas Dupinb6ed63b2017-05-30 16:17:42 -0700383 NotificationHeaderView header = getVisibleNotificationHeader();
384 if (header != null) {
385 color = header.getOriginalIconColor();
386 } else {
387 color = mEntry.getContrastedColor(mContext, mIsLowPriority && !isExpanded(),
388 getBackgroundColorWithoutTint());
389 }
Selim Cinek6743c0b2017-01-18 18:24:01 -0800390 }
Selim Cinek875ba9b2017-02-13 16:20:17 -0800391 expandedIcon.setStaticDrawableColor(color);
Selim Cinekda42d652015-12-04 15:51:16 -0800392 }
393
Selim Cinek5cf1d052017-06-01 17:36:46 -0700394 public void setAboveShelfChangedListener(AboveShelfChangedListener aboveShelfChangedListener) {
395 mAboveShelfChangedListener = aboveShelfChangedListener;
396 }
397
Selim Cinek4705f292017-04-24 22:18:48 -0700398 @Override
399 public boolean isDimmable() {
400 if (!getShowingLayout().isDimmable()) {
401 return false;
402 }
403 return super.isDimmable();
404 }
405
Selim Cinekda42d652015-12-04 15:51:16 -0800406 private void updateLimits() {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800407 for (NotificationContentView l : mLayouts) {
408 updateLimitsForView(l);
409 }
Selim Cineka1744872016-03-11 15:36:06 -0800410 }
411
412 private void updateLimitsForView(NotificationContentView layout) {
413 boolean customView = layout.getContractedChild().getId()
Selim Cinekda42d652015-12-04 15:51:16 -0800414 != com.android.internal.R.id.status_bar_latest_event_content;
415 boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800416 int minHeight;
417 if (customView && beforeN && !mIsSummaryWithChildren) {
418 minHeight = mNotificationMinHeightLegacy;
419 } else if (mUseIncreasedCollapsedHeight && layout == mPrivateLayout) {
420 minHeight = mNotificationMinHeightLarge;
421 } else {
422 minHeight = mNotificationMinHeight;
423 }
Selim Cineka1744872016-03-11 15:36:06 -0800424 boolean headsUpCustom = layout.getHeadsUpChild() != null &&
425 layout.getHeadsUpChild().getId()
426 != com.android.internal.R.id.status_bar_latest_event_content;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800427 int headsUpheight;
428 if (headsUpCustom && beforeN) {
429 headsUpheight = mMaxHeadsUpHeightLegacy;
430 } else if (mUseIncreasedHeadsUpHeight && layout == mPrivateLayout) {
431 headsUpheight = mMaxHeadsUpHeightIncreased;
432 } else {
433 headsUpheight = mMaxHeadsUpHeight;
434 }
Adrian Roos0aac04f2016-12-08 15:59:29 -0800435 layout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight,
436 mNotificationAmbientHeight);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200437 }
438
439 public StatusBarNotification getStatusBarNotification() {
440 return mStatusBarNotification;
441 }
442
Selim Cinek281c2022016-10-13 19:14:43 -0700443 public NotificationData.Entry getEntry() {
444 return mEntry;
445 }
446
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700447 public boolean isHeadsUp() {
448 return mIsHeadsUp;
449 }
450
Selim Cinek1a521f32014-11-03 17:39:29 +0100451 public void setHeadsUp(boolean isHeadsUp) {
Selim Cinek5cf1d052017-06-01 17:36:46 -0700452 boolean wasAboveShelf = isAboveShelf();
Selim Cinekc80fdb12015-04-13 15:09:08 -0700453 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek1a521f32014-11-03 17:39:29 +0100454 mIsHeadsUp = isHeadsUp;
Selim Cinek8d490d42015-04-10 00:05:50 -0700455 mPrivateLayout.setHeadsUp(isHeadsUp);
Selim Cinekb41b2f62016-04-26 14:03:29 -0700456 if (mIsSummaryWithChildren) {
457 // The overflow might change since we allow more lines as HUN.
458 mChildrenContainer.updateGroupOverflow();
459 }
Selim Cinekc80fdb12015-04-13 15:09:08 -0700460 if (intrinsicBefore != getIntrinsicHeight()) {
461 notifyHeightChanged(false /* needsAnimation */);
462 }
Selim Cinekd127d792016-11-01 19:11:41 -0700463 if (isHeadsUp) {
464 setAboveShelf(true);
Selim Cinek5cf1d052017-06-01 17:36:46 -0700465 } else if (isAboveShelf() != wasAboveShelf) {
466 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
Selim Cinekd127d792016-11-01 19:11:41 -0700467 }
Selim Cinek1a521f32014-11-03 17:39:29 +0100468 }
469
Selim Cinekb5605e52015-02-20 18:21:41 +0100470 public void setGroupManager(NotificationGroupManager groupManager) {
471 mGroupManager = groupManager;
Selim Cinek83bc7832015-10-22 13:26:54 -0700472 mPrivateLayout.setGroupManager(groupManager);
Selim Cinekb5605e52015-02-20 18:21:41 +0100473 }
474
Adrian Roosb88b1a12015-12-09 18:51:05 -0800475 public void setRemoteInputController(RemoteInputController r) {
476 mPrivateLayout.setRemoteInputController(r);
477 }
478
Mady Mellor3fd273e2016-03-15 21:08:14 -0700479 public void setAppName(String appName) {
480 mAppName = appName;
Mady Mellor95d743c2017-01-10 12:05:27 -0800481 if (mMenuRow != null && mMenuRow.getMenuView() != null) {
Mady Mellor761cde12017-01-10 11:36:39 -0800482 mMenuRow.setAppName(mAppName);
Mady Mellor3fd273e2016-03-15 21:08:14 -0700483 }
484 }
485
Selim Cinekb5605e52015-02-20 18:21:41 +0100486 public void addChildNotification(ExpandableNotificationRow row) {
487 addChildNotification(row, -1);
488 }
489
490 /**
491 * Add a child notification to this view.
492 *
493 * @param row the row to add
494 * @param childIndex the index to add it at, if -1 it will be added at the end
495 */
496 public void addChildNotification(ExpandableNotificationRow row, int childIndex) {
497 if (mChildrenContainer == null) {
498 mChildrenContainerStub.inflate();
499 }
500 mChildrenContainer.addNotification(row, childIndex);
Selim Cinek263398f2015-10-21 17:40:23 -0700501 onChildrenCountChanged();
502 row.setIsChildInGroup(true, this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100503 }
504
505 public void removeChildNotification(ExpandableNotificationRow row) {
506 if (mChildrenContainer != null) {
507 mChildrenContainer.removeNotification(row);
508 }
Selim Cinek263398f2015-10-21 17:40:23 -0700509 onChildrenCountChanged();
510 row.setIsChildInGroup(false, null);
511 }
512
Mady Mellor43c2cd12016-12-12 21:05:13 -0800513 @Override
Selim Cinek263398f2015-10-21 17:40:23 -0700514 public boolean isChildInGroup() {
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700515 return mNotificationParent != null;
Selim Cinek263398f2015-10-21 17:40:23 -0700516 }
517
Selim Cinek388df6d2015-10-22 13:25:11 -0700518 public ExpandableNotificationRow getNotificationParent() {
519 return mNotificationParent;
520 }
521
Selim Cinek263398f2015-10-21 17:40:23 -0700522 /**
523 * @param isChildInGroup Is this notification now in a group
524 * @param parent the new parent notification
525 */
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700526 public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500527 boolean childInGroup = StatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup;
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700528 mNotificationParent = childInGroup ? parent : null;
529 mPrivateLayout.setIsChildInGroup(childInGroup);
Selim Cinek5ba22542017-04-20 15:16:10 -0700530 mNotificationInflater.setIsChildInGroup(childInGroup);
Mady Mellorc7d65b42016-05-04 11:44:57 -0400531 resetBackgroundAlpha();
Mady Mellorb0a82462016-04-30 17:31:02 -0700532 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -0700533 updateClickAndFocus();
Mady Mellorb0a82462016-04-30 17:31:02 -0700534 if (mNotificationParent != null) {
Selim Cinek9ce32852017-02-15 16:21:10 -0800535 setOverrideTintColor(NO_COLOR, 0.0f);
Mady Mellorb0a82462016-04-30 17:31:02 -0700536 mNotificationParent.updateBackgroundForGroupState();
537 }
Selim Cinekdb167372016-11-17 15:41:17 -0800538 updateIconVisibilities();
Selim Cinek34d93b02015-10-22 12:30:38 -0700539 }
540
541 @Override
Selim Cinek72109472016-01-15 16:33:22 -0800542 public boolean onTouchEvent(MotionEvent event) {
543 if (event.getActionMasked() != MotionEvent.ACTION_DOWN
544 || !isChildInGroup() || isGroupExpanded()) {
545 return super.onTouchEvent(event);
546 } else {
547 return false;
548 }
549 }
550
551 @Override
Mady Mellorf0625802016-02-11 18:03:48 -0800552 protected boolean handleSlideBack() {
Mady Mellor95d743c2017-01-10 12:05:27 -0800553 if (mMenuRow != null && mMenuRow.isMenuVisible()) {
Mady Mellorf0625802016-02-11 18:03:48 -0800554 animateTranslateNotification(0 /* targetLeft */);
555 return true;
556 }
557 return false;
558 }
559
560 @Override
Selim Cinek34d93b02015-10-22 12:30:38 -0700561 protected boolean shouldHideBackground() {
562 return super.shouldHideBackground() || mShowNoBackground;
Selim Cinek263398f2015-10-21 17:40:23 -0700563 }
564
565 @Override
566 public boolean isSummaryWithChildren() {
567 return mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100568 }
569
570 @Override
571 public boolean areChildrenExpanded() {
572 return mChildrenExpanded;
573 }
574
575 public List<ExpandableNotificationRow> getNotificationChildren() {
576 return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren();
577 }
578
Selim Cinekeef84282015-10-30 16:28:00 -0700579 public int getNumberOfNotificationChildren() {
580 if (mChildrenContainer == null) {
581 return 0;
582 }
583 return mChildrenContainer.getNotificationChildren().size();
584 }
585
Selim Cinekb5605e52015-02-20 18:21:41 +0100586 /**
587 * Apply the order given in the list to the children.
588 *
589 * @param childOrder the new list order
Selim Cineka7d4f822016-12-06 14:34:47 -0800590 * @param visualStabilityManager
591 * @param callback the callback to invoked in case it is not allowed
Selim Cinekb5605e52015-02-20 18:21:41 +0100592 * @return whether the list order has changed
593 */
Selim Cineka7d4f822016-12-06 14:34:47 -0800594 public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder,
595 VisualStabilityManager visualStabilityManager,
596 VisualStabilityManager.Callback callback) {
597 return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder,
598 visualStabilityManager, callback);
Selim Cinekb5605e52015-02-20 18:21:41 +0100599 }
600
601 public void getChildrenStates(StackScrollState resultState) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700602 if (mIsSummaryWithChildren) {
Selim Cinekbbcebde2016-11-09 18:28:20 -0800603 ExpandableViewState parentState = resultState.getViewStateForView(this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100604 mChildrenContainer.getState(resultState, parentState);
605 }
606 }
607
608 public void applyChildrenState(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700609 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100610 mChildrenContainer.applyState(state);
611 }
612 }
613
614 public void prepareExpansionChanged(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700615 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100616 mChildrenContainer.prepareExpansionChanged(state);
617 }
618 }
619
Selim Cinek0cfbef42016-11-09 19:06:36 -0800620 public void startChildAnimation(StackScrollState finalState, AnimationProperties properties) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700621 if (mIsSummaryWithChildren) {
Selim Cinek0cfbef42016-11-09 19:06:36 -0800622 mChildrenContainer.startAnimationToState(finalState, properties);
Selim Cinekb5605e52015-02-20 18:21:41 +0100623 }
624 }
625
626 public ExpandableNotificationRow getViewAtPosition(float y) {
Selim Cinek43d30f02016-03-04 10:51:32 -0800627 if (!mIsSummaryWithChildren || !mChildrenExpanded) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100628 return this;
629 } else {
630 ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y);
631 return view == null ? this : view;
632 }
633 }
634
Selim Cinekab29aeb2015-02-20 18:18:32 +0100635 public NotificationGuts getGuts() {
636 return mGuts;
637 }
638
Selim Cinek684a4422015-04-15 16:18:39 -0700639 /**
640 * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this
641 * the notification will be rendered on top of the screen.
642 *
643 * @param pinned whether it is pinned
644 */
645 public void setPinned(boolean pinned) {
Selim Cinekdef35a82016-05-03 15:52:51 -0700646 int intrinsicHeight = getIntrinsicHeight();
Selim Cinek5cf1d052017-06-01 17:36:46 -0700647 boolean wasAboveShelf = isAboveShelf();
Selim Cinek684a4422015-04-15 16:18:39 -0700648 mIsPinned = pinned;
Selim Cinekdef35a82016-05-03 15:52:51 -0700649 if (intrinsicHeight != getIntrinsicHeight()) {
Selim Cinekbb42b7d2016-08-10 13:02:38 -0700650 notifyHeightChanged(false /* needsAnimation */);
Selim Cinekdef35a82016-05-03 15:52:51 -0700651 }
Selim Cinek31aada42015-12-18 17:51:15 -0800652 if (pinned) {
653 setIconAnimationRunning(true);
654 mExpandedWhenPinned = false;
655 } else if (mExpandedWhenPinned) {
656 setUserExpanded(true);
657 }
Selim Cinek98713a42015-09-21 15:47:20 +0200658 setChronometerRunning(mLastChronometerRunning);
Selim Cinek5cf1d052017-06-01 17:36:46 -0700659 if (isAboveShelf() != wasAboveShelf) {
660 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
661 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700662 }
663
Selim Cinek684a4422015-04-15 16:18:39 -0700664 public boolean isPinned() {
665 return mIsPinned;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700666 }
667
Selim Cinekd127d792016-11-01 19:11:41 -0700668 @Override
669 public int getPinnedHeadsUpHeight() {
670 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
671 }
672
Selim Cinek31aada42015-12-18 17:51:15 -0800673 /**
674 * @param atLeastMinHeight should the value returned be at least the minimum height.
675 * Used to avoid cyclic calls
676 * @return the height of the heads up notification when pinned
677 */
Selim Cinekd127d792016-11-01 19:11:41 -0700678 private int getPinnedHeadsUpHeight(boolean atLeastMinHeight) {
Selim Cinek77019c72015-12-09 10:18:02 -0800679 if (mIsSummaryWithChildren) {
680 return mChildrenContainer.getIntrinsicHeight();
681 }
Selim Cinek31aada42015-12-18 17:51:15 -0800682 if(mExpandedWhenPinned) {
683 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
684 } else if (atLeastMinHeight) {
Selim Cinek567e8452016-03-24 10:54:56 -0700685 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek31aada42015-12-18 17:51:15 -0800686 } else {
687 return mHeadsUpHeight;
688 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700689 }
690
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700691 /**
692 * Mark whether this notification was just clicked, i.e. the user has just clicked this
693 * notification in this frame.
694 */
695 public void setJustClicked(boolean justClicked) {
696 mJustClicked = justClicked;
697 }
698
699 /**
700 * @return true if this notification has been clicked in this frame, false otherwise
701 */
702 public boolean wasJustClicked() {
703 return mJustClicked;
704 }
705
Selim Cinek98713a42015-09-21 15:47:20 +0200706 public void setChronometerRunning(boolean running) {
707 mLastChronometerRunning = running;
708 setChronometerRunning(running, mPrivateLayout);
709 setChronometerRunning(running, mPublicLayout);
710 if (mChildrenContainer != null) {
711 List<ExpandableNotificationRow> notificationChildren =
712 mChildrenContainer.getNotificationChildren();
713 for (int i = 0; i < notificationChildren.size(); i++) {
714 ExpandableNotificationRow child = notificationChildren.get(i);
715 child.setChronometerRunning(running);
716 }
717 }
718 }
719
720 private void setChronometerRunning(boolean running, NotificationContentView layout) {
721 if (layout != null) {
722 running = running || isPinned();
723 View contractedChild = layout.getContractedChild();
724 View expandedChild = layout.getExpandedChild();
725 View headsUpChild = layout.getHeadsUpChild();
726 setChronometerRunningForChild(running, contractedChild);
727 setChronometerRunningForChild(running, expandedChild);
728 setChronometerRunningForChild(running, headsUpChild);
729 }
730 }
731
732 private void setChronometerRunningForChild(boolean running, View child) {
733 if (child != null) {
734 View chronometer = child.findViewById(com.android.internal.R.id.chronometer);
735 if (chronometer instanceof Chronometer) {
736 ((Chronometer) chronometer).setStarted(running);
737 }
738 }
739 }
740
Selim Cinekea4bef72015-12-02 15:51:10 -0800741 public NotificationHeaderView getNotificationHeader() {
Mady Mellorb0a82462016-04-30 17:31:02 -0700742 if (mIsSummaryWithChildren) {
743 return mChildrenContainer.getHeaderView();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700744 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800745 return mPrivateLayout.getNotificationHeader();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700746 }
747
Selim Cinek414ad332017-02-24 19:06:12 -0800748 /**
749 * @return the currently visible notification header. This can be different from
750 * {@link #getNotificationHeader()} in case it is a low-priority group.
751 */
752 public NotificationHeaderView getVisibleNotificationHeader() {
Selim Cinekaa3901a2016-08-05 11:04:37 -0700753 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinek414ad332017-02-24 19:06:12 -0800754 return mChildrenContainer.getVisibleHeader();
Selim Cinek34eda5e2016-02-18 17:10:43 -0800755 }
756 return getShowingLayout().getVisibleNotificationHeader();
757 }
758
Selim Cinek570981d2015-12-01 11:37:01 -0800759 public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) {
760 mOnExpandClickListener = onExpandClickListener;
761 }
762
Selim Cinekddf1b392016-05-27 16:33:10 -0700763 @Override
764 public void setOnClickListener(@Nullable OnClickListener l) {
765 super.setOnClickListener(l);
766 mOnClickListener = l;
767 updateClickAndFocus();
768 }
769
770 private void updateClickAndFocus() {
771 boolean normalChild = !isChildInGroup() || isGroupExpanded();
772 boolean clickable = mOnClickListener != null && normalChild;
773 if (isFocusable() != normalChild) {
774 setFocusable(normalChild);
775 }
776 if (isClickable() != clickable) {
777 setClickable(clickable);
778 }
779 }
780
Selim Cinek31aada42015-12-18 17:51:15 -0800781 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
782 mHeadsUpManager = headsUpManager;
783 }
784
Mady Mellor87d79452017-01-10 11:52:52 -0800785 public void setGutsView(MenuItem item) {
Mady Mellor95d743c2017-01-10 12:05:27 -0800786 if (mGuts != null && item.getGutsView() instanceof GutsContent) {
787 ((GutsContent) item.getGutsView()).setGutsParent(mGuts);
788 mGuts.setGutsContent((GutsContent) item.getGutsView());
Mady Mellor87d79452017-01-10 11:52:52 -0800789 }
790 }
791
Mady Mellor95d743c2017-01-10 12:05:27 -0800792 @Override
793 protected void onAttachedToWindow() {
794 super.onAttachedToWindow();
795 Dependency.get(PluginManager.class).addPluginListener(this,
796 NotificationMenuRowPlugin.class, false /* Allow multiple */);
797 }
798
799 @Override
800 protected void onDetachedFromWindow() {
801 super.onDetachedFromWindow();
802 Dependency.get(PluginManager.class).removePluginListener(this);
803 }
804
805 @Override
806 public void onPluginConnected(NotificationMenuRowPlugin plugin, Context pluginContext) {
807 boolean existed = mMenuRow.getMenuView() != null;
808 if (existed) {
809 removeView(mMenuRow.getMenuView());
810 }
811 mMenuRow = plugin;
812 if (mMenuRow.useDefaultMenuItems()) {
Mady Mellor4c197602017-04-10 17:57:52 -0700813 ArrayList<MenuItem> items = new ArrayList<>();
814 items.add(NotificationMenuRow.createInfoItem(mContext));
815 items.add(NotificationMenuRow.createSnoozeItem(mContext));
816 mMenuRow.setMenuItems(items);
Mady Mellor95d743c2017-01-10 12:05:27 -0800817 }
818 if (existed) {
819 createMenu();
820 }
821 }
822
823 @Override
824 public void onPluginDisconnected(NotificationMenuRowPlugin plugin) {
825 boolean existed = mMenuRow.getMenuView() != null;
826 mMenuRow = new NotificationMenuRow(mContext); // Back to default
827 if (existed) {
828 createMenu();
829 }
830 }
831
832 public NotificationMenuRowPlugin createMenu() {
833 if (mMenuRow.getMenuView() == null) {
834 mMenuRow.createMenu(this);
835 mMenuRow.setAppName(mAppName);
836 FrameLayout.LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
837 LayoutParams.MATCH_PARENT);
838 addView(mMenuRow.getMenuView(), MENU_VIEW_INDEX, lp);
839 }
840 return mMenuRow;
841 }
842
Mady Mellor95d743c2017-01-10 12:05:27 -0800843 public NotificationMenuRowPlugin getProvider() {
844 return mMenuRow;
845 }
846
Anthony Chen9fe1ee72017-04-07 13:53:37 -0700847 @Override
Selim Cinek1a48bab2017-02-17 19:38:40 -0800848 public void onDensityOrFontScaleChanged() {
Anthony Chen9fe1ee72017-04-07 13:53:37 -0700849 super.onDensityOrFontScaleChanged();
Selim Cinek01af3342016-02-09 19:25:31 -0800850 initDimens();
Selim Cinek817abe72017-05-24 11:08:55 -0700851 // Let's update our childrencontainer. This is intentionally not guarded with
852 // mIsSummaryWithChildren since we might have had children but not anymore.
853 if (mChildrenContainer != null) {
854 mChildrenContainer.reInflateViews(mExpandClickListener, mEntry.notification);
Selim Cinek01af3342016-02-09 19:25:31 -0800855 }
856 if (mGuts != null) {
857 View oldGuts = mGuts;
858 int index = indexOfChild(oldGuts);
859 removeView(oldGuts);
860 mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate(
861 R.layout.notification_guts, this, false);
862 mGuts.setVisibility(oldGuts.getVisibility());
863 addView(mGuts, index);
864 }
Mady Mellor95d743c2017-01-10 12:05:27 -0800865 View oldMenu = mMenuRow.getMenuView();
866 if (oldMenu != null) {
Mady Mellor761cde12017-01-10 11:36:39 -0800867 int menuIndex = indexOfChild(oldMenu);
868 removeView(oldMenu);
Mady Mellor95d743c2017-01-10 12:05:27 -0800869 mMenuRow.createMenu(ExpandableNotificationRow.this);
Mady Mellor761cde12017-01-10 11:36:39 -0800870 mMenuRow.setAppName(mAppName);
Mady Mellor95d743c2017-01-10 12:05:27 -0800871 addView(mMenuRow.getMenuView(), menuIndex);
Mady Mellor4b80b102016-01-22 08:03:58 -0800872 }
Adrian Rooseb434ff2017-01-11 11:18:48 -0800873 for (NotificationContentView l : mLayouts) {
874 l.reInflateViews();
875 }
Selim Cinek1a48bab2017-02-17 19:38:40 -0800876 mNotificationInflater.onDensityOrFontScaleChanged();
877 onNotificationUpdated();
Selim Cinek01af3342016-02-09 19:25:31 -0800878 }
879
Mady Mellor9d03a522017-04-04 18:45:30 -0700880 @Override
881 public void onConfigurationChanged(Configuration newConfig) {
882 if (mMenuRow.getMenuView() != null) {
883 mMenuRow.onConfigurationChanged();
884 }
885 }
886
Selim Cinekc3179332016-03-04 14:44:56 -0800887 public void setContentBackground(int customBackgroundColor, boolean animate,
888 NotificationContentView notificationContentView) {
889 if (getShowingLayout() == notificationContentView) {
890 setTintColor(customBackgroundColor, animate);
891 }
892 }
893
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700894 public void closeRemoteInput() {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800895 for (NotificationContentView l : mLayouts) {
896 l.closeRemoteInput();
897 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700898 }
899
Selim Cinekc897bd32016-03-18 17:32:31 -0700900 /**
901 * Set by how much the single line view should be indented.
902 */
903 public void setSingleLineWidthIndention(int indention) {
904 mPrivateLayout.setSingleLineWidthIndention(indention);
905 }
906
907 public int getNotificationColor() {
Selim Cinek4bb59342016-04-08 19:29:35 -0700908 return mNotificationColor;
909 }
910
911 private void updateNotificationColor() {
912 mNotificationColor = NotificationColorUtil.resolveContrastColor(mContext,
Selim Cinekac5f0272017-05-02 16:05:41 -0700913 getStatusBarNotification().getNotification().color,
914 getBackgroundColorWithoutTint());
Adrian Roos6f6e1592017-05-02 16:22:53 -0700915 mNotificationColorAmbient = NotificationColorUtil.resolveAmbientColor(mContext,
916 getStatusBarNotification().getNotification().color);
Selim Cinekc897bd32016-03-18 17:32:31 -0700917 }
918
919 public HybridNotificationView getSingleLineView() {
920 return mPrivateLayout.getSingleLineView();
921 }
922
Adrian Roos6f6e1592017-05-02 16:22:53 -0700923 public HybridNotificationView getAmbientSingleLineView() {
924 return getShowingLayout().getAmbientSingleLineChild();
925 }
926
Selim Cinekf07d0622016-03-21 19:52:52 -0700927 public boolean isOnKeyguard() {
928 return mOnKeyguard;
929 }
930
Selim Cinekc1e389d2016-04-07 11:02:57 -0700931 public void removeAllChildren() {
932 List<ExpandableNotificationRow> notificationChildren
933 = mChildrenContainer.getNotificationChildren();
934 ArrayList<ExpandableNotificationRow> clonedList = new ArrayList<>(notificationChildren);
935 for (int i = 0; i < clonedList.size(); i++) {
936 ExpandableNotificationRow row = clonedList.get(i);
Selim Cinek3f19f602016-05-02 18:01:56 -0700937 if (row.keepInParent()) {
938 continue;
939 }
Selim Cinekc1e389d2016-04-07 11:02:57 -0700940 mChildrenContainer.removeNotification(row);
Selim Cinekc1e389d2016-04-07 11:02:57 -0700941 row.setIsChildInGroup(false, null);
942 }
943 onChildrenCountChanged();
944 }
945
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700946 public void setForceUnlocked(boolean forceUnlocked) {
947 mForceUnlocked = forceUnlocked;
948 if (mIsSummaryWithChildren) {
949 List<ExpandableNotificationRow> notificationChildren = getNotificationChildren();
950 for (ExpandableNotificationRow child : notificationChildren) {
951 child.setForceUnlocked(forceUnlocked);
952 }
953 }
954 }
955
Selim Cineke9bad242016-06-15 11:46:37 -0700956 public void setDismissed(boolean dismissed, boolean fromAccessibility) {
Selim Cinek3f19f602016-05-02 18:01:56 -0700957 mDismissed = dismissed;
Selim Cineke9bad242016-06-15 11:46:37 -0700958 mGroupParentWhenDismissed = mNotificationParent;
959 mRefocusOnDismiss = fromAccessibility;
960 mChildAfterViewWhenDismissed = null;
961 if (isChildInGroup()) {
962 List<ExpandableNotificationRow> notificationChildren =
963 mNotificationParent.getNotificationChildren();
964 int i = notificationChildren.indexOf(this);
965 if (i != -1 && i < notificationChildren.size() - 1) {
966 mChildAfterViewWhenDismissed = notificationChildren.get(i + 1);
967 }
968 }
Selim Cinek3f19f602016-05-02 18:01:56 -0700969 }
970
971 public boolean isDismissed() {
972 return mDismissed;
973 }
974
975 public boolean keepInParent() {
976 return mKeepInParent;
977 }
978
979 public void setKeepInParent(boolean keepInParent) {
980 mKeepInParent = keepInParent;
981 }
982
983 public boolean isRemoved() {
984 return mRemoved;
985 }
986
Adrian Roosd009ab12016-05-20 17:58:53 -0700987 public void setRemoved() {
988 mRemoved = true;
Selim Cinekef8c2252017-02-10 14:52:18 -0800989 mTranslationWhenRemoved = getTranslationY();
990 mWasChildInGroupWhenRemoved = isChildInGroup();
991 if (isChildInGroup()) {
992 mTranslationWhenRemoved += getNotificationParent().getTranslationY();
993 }
Adrian Roosd009ab12016-05-20 17:58:53 -0700994 mPrivateLayout.setRemoved();
Selim Cinek3f19f602016-05-02 18:01:56 -0700995 }
996
Selim Cinekef8c2252017-02-10 14:52:18 -0800997 public boolean wasChildInGroupWhenRemoved() {
998 return mWasChildInGroupWhenRemoved;
999 }
1000
1001 public float getTranslationWhenRemoved() {
1002 return mTranslationWhenRemoved;
1003 }
1004
Selim Cinekd1395642016-04-28 12:22:42 -07001005 public NotificationChildrenContainer getChildrenContainer() {
1006 return mChildrenContainer;
1007 }
1008
Selim Cinekcafa87f2016-10-26 17:00:17 -07001009 public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) {
Selim Cinek5cf1d052017-06-01 17:36:46 -07001010 boolean wasAboveShelf = isAboveShelf();
Selim Cinekcafa87f2016-10-26 17:00:17 -07001011 mHeadsupDisappearRunning = headsUpAnimatingAway;
1012 mPrivateLayout.setHeadsUpAnimatingAway(headsUpAnimatingAway);
Selim Cinek5cf1d052017-06-01 17:36:46 -07001013 if (isAboveShelf() != wasAboveShelf) {
1014 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
1015 }
Selim Cinekcafa87f2016-10-26 17:00:17 -07001016 }
1017
1018 /**
1019 * @return if the view was just heads upped and is now animating away. During such a time the
1020 * layout needs to be kept consistent
1021 */
1022 public boolean isHeadsUpAnimatingAway() {
1023 return mHeadsupDisappearRunning;
Selim Cinek73cf02a2016-06-17 13:08:00 -07001024 }
1025
Selim Cineke9bad242016-06-15 11:46:37 -07001026 public View getChildAfterViewWhenDismissed() {
1027 return mChildAfterViewWhenDismissed;
1028 }
1029
1030 public View getGroupParentWhenDismissed() {
1031 return mGroupParentWhenDismissed;
1032 }
1033
Selim Cinek9e624e72016-07-20 13:46:49 -07001034 public void performDismiss() {
Selim Cineke9079112016-12-14 14:41:01 -08001035 if (mOnDismissRunnable != null) {
1036 mOnDismissRunnable.run();
1037 }
Selim Cinek9e624e72016-07-20 13:46:49 -07001038 }
1039
Selim Cineke9079112016-12-14 14:41:01 -08001040 public void setOnDismissRunnable(Runnable onDismissRunnable) {
1041 mOnDismissRunnable = onDismissRunnable;
Selim Cinek9e624e72016-07-20 13:46:49 -07001042 }
1043
Selim Cinek281c2022016-10-13 19:14:43 -07001044 public View getNotificationIcon() {
Selim Cinek414ad332017-02-24 19:06:12 -08001045 NotificationHeaderView notificationHeader = getVisibleNotificationHeader();
Selim Cinek281c2022016-10-13 19:14:43 -07001046 if (notificationHeader != null) {
1047 return notificationHeader.getIcon();
1048 }
1049 return null;
1050 }
1051
1052 /**
1053 * @return whether the notification is currently showing a view with an icon.
1054 */
1055 public boolean isShowingIcon() {
Mady Mellor434180c2017-02-13 11:29:42 -08001056 if (areGutsExposed()) {
1057 return false;
1058 }
Selim Cinek2ffa02f2017-03-06 15:56:37 -08001059 return getVisibleNotificationHeader() != null;
Selim Cinek281c2022016-10-13 19:14:43 -07001060 }
1061
Selim Cinek0242fbb2016-10-19 13:38:32 -07001062 /**
1063 * Set how much this notification is transformed into an icon.
1064 *
Selim Cinek2b549f42016-11-22 16:38:51 -08001065 * @param contentTransformationAmount A value from 0 to 1 indicating how much we are transformed
1066 * to the content away
Selim Cinek875a3a12016-11-18 17:52:16 -08001067 * @param isLastChild is this the last child in the list. If true, then the transformation is
1068 * different since it's content fades out.
Selim Cinek0242fbb2016-10-19 13:38:32 -07001069 */
Selim Cinek2b549f42016-11-22 16:38:51 -08001070 public void setContentTransformationAmount(float contentTransformationAmount,
1071 boolean isLastChild) {
Selim Cinek875a3a12016-11-18 17:52:16 -08001072 boolean changeTransformation = isLastChild != mIsLastChild;
Selim Cinek2b549f42016-11-22 16:38:51 -08001073 changeTransformation |= mContentTransformationAmount != contentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001074 mIsLastChild = isLastChild;
Selim Cinek2b549f42016-11-22 16:38:51 -08001075 mContentTransformationAmount = contentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001076 if (changeTransformation) {
1077 updateContentTransformation();
Selim Cinek2b549f42016-11-22 16:38:51 -08001078 }
1079 }
1080
1081 /**
1082 * Set the icons to be visible of this notification.
1083 */
1084 public void setIconsVisible(boolean iconsVisible) {
1085 if (iconsVisible != mIconsVisible) {
1086 mIconsVisible = iconsVisible;
1087 updateIconVisibilities();
Selim Cinek0242fbb2016-10-19 13:38:32 -07001088 }
1089 }
1090
Selim Cinekdb167372016-11-17 15:41:17 -08001091 @Override
1092 protected void onBelowSpeedBumpChanged() {
1093 updateIconVisibilities();
1094 }
1095
Selim Cinek875a3a12016-11-18 17:52:16 -08001096 private void updateContentTransformation() {
1097 float contentAlpha;
Selim Cinek2b549f42016-11-22 16:38:51 -08001098 float translationY = -mContentTransformationAmount * mIconTransformContentShift;
Selim Cinek875a3a12016-11-18 17:52:16 -08001099 if (mIsLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -08001100 contentAlpha = 1.0f - mContentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001101 contentAlpha = Math.min(contentAlpha / 0.5f, 1.0f);
Selim Cinek0242fbb2016-10-19 13:38:32 -07001102 contentAlpha = Interpolators.ALPHA_OUT.getInterpolation(contentAlpha);
Selim Cinek875a3a12016-11-18 17:52:16 -08001103 translationY *= 0.4f;
1104 } else {
1105 contentAlpha = 1.0f;
1106 }
Adrian Rooseb434ff2017-01-11 11:18:48 -08001107 for (NotificationContentView l : mLayouts) {
1108 l.setAlpha(contentAlpha);
1109 l.setTranslationY(translationY);
1110 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001111 if (mChildrenContainer != null) {
1112 mChildrenContainer.setAlpha(contentAlpha);
1113 mChildrenContainer.setTranslationY(translationY);
1114 // TODO: handle children fade out better
Selim Cinek0242fbb2016-10-19 13:38:32 -07001115 }
1116 }
1117
1118 private void updateIconVisibilities() {
Selim Cinek17e1b692016-12-02 18:19:11 -08001119 boolean visible = isChildInGroup()
1120 || (isBelowSpeedBump() && !NotificationShelf.SHOW_AMBIENT_ICONS)
1121 || mIconsVisible;
Adrian Rooseb434ff2017-01-11 11:18:48 -08001122 for (NotificationContentView l : mLayouts) {
1123 l.setIconsVisible(visible);
1124 }
Selim Cinekdb167372016-11-17 15:41:17 -08001125 if (mChildrenContainer != null) {
1126 mChildrenContainer.setIconsVisible(visible);
Selim Cinek0242fbb2016-10-19 13:38:32 -07001127 }
1128 }
1129
Selim Cinek875a3a12016-11-18 17:52:16 -08001130 /**
1131 * Get the relative top padding of a view relative to this view. This recursively walks up the
1132 * hierarchy and does the corresponding measuring.
1133 *
1134 * @param view the view to the the padding for. The requested view has to be a child of this
1135 * notification.
1136 * @return the toppadding
1137 */
1138 public int getRelativeTopPadding(View view) {
1139 int topPadding = 0;
1140 while (view.getParent() instanceof ViewGroup) {
1141 topPadding += view.getTop();
1142 view = (View) view.getParent();
1143 if (view instanceof ExpandableNotificationRow) {
1144 return topPadding;
1145 }
1146 }
1147 return topPadding;
1148 }
1149
Selim Cineka1d97902016-12-14 16:31:40 -08001150 public float getContentTranslation() {
1151 return mPrivateLayout.getTranslationY();
1152 }
1153
Selim Cinek6743c0b2017-01-18 18:24:01 -08001154 public void setIsLowPriority(boolean isLowPriority) {
1155 mIsLowPriority = isLowPriority;
1156 mPrivateLayout.setIsLowPriority(isLowPriority);
Selim Cinek1a48bab2017-02-17 19:38:40 -08001157 mNotificationInflater.setIsLowPriority(mIsLowPriority);
Selim Cinek6743c0b2017-01-18 18:24:01 -08001158 if (mChildrenContainer != null) {
1159 mChildrenContainer.setIsLowPriority(isLowPriority);
1160 }
1161 }
1162
Selim Cinek55a3e732017-05-25 18:30:10 -07001163
1164 public void setLowPriorityStateUpdated(boolean lowPriorityStateUpdated) {
1165 mLowPriorityStateUpdated = lowPriorityStateUpdated;
1166 }
1167
1168 public boolean hasLowPriorityStateUpdated() {
1169 return mLowPriorityStateUpdated;
1170 }
1171
Selim Cinek414ad332017-02-24 19:06:12 -08001172 public boolean isLowPriority() {
1173 return mIsLowPriority;
1174 }
1175
Selim Cinek7d1009b2017-01-25 15:28:28 -08001176 public void setUseIncreasedCollapsedHeight(boolean use) {
1177 mUseIncreasedCollapsedHeight = use;
Selim Cinek1a48bab2017-02-17 19:38:40 -08001178 mNotificationInflater.setUsesIncreasedHeight(use);
Selim Cinek7d1009b2017-01-25 15:28:28 -08001179 }
1180
Selim Cinek87ed69b2017-02-09 15:59:43 -08001181 public void setUseIncreasedHeadsUpHeight(boolean use) {
1182 mUseIncreasedHeadsUpHeight = use;
Selim Cinek1a48bab2017-02-17 19:38:40 -08001183 mNotificationInflater.setUsesIncreasedHeadsUpHeight(use);
1184 }
1185
1186 public void setRemoteViewClickHandler(RemoteViews.OnClickHandler remoteViewClickHandler) {
1187 mNotificationInflater.setRemoteViewClickHandler(remoteViewClickHandler);
Selim Cinek87ed69b2017-02-09 15:59:43 -08001188 }
1189
Selim Cinek5ba22542017-04-20 15:16:10 -07001190 public void setInflationCallback(InflationCallback callback) {
1191 mNotificationInflater.setInflationCallback(callback);
Selim Cinekc478f902017-02-22 20:55:44 -08001192 }
1193
Adrian Roos1a1ecfc2017-04-17 11:17:59 -07001194 public void setNeedsRedaction(boolean needsRedaction) {
1195 mNotificationInflater.setRedactAmbient(needsRedaction);
1196 }
1197
Selim Cinek5ba22542017-04-20 15:16:10 -07001198 @VisibleForTesting
1199 public NotificationInflater getNotificationInflater() {
1200 return mNotificationInflater;
1201 }
1202
Adrian Roos6f6e1592017-05-02 16:22:53 -07001203 public int getNotificationColorAmbient() {
1204 return mNotificationColorAmbient;
1205 }
1206
Chris Wren78403d72014-07-28 10:23:24 +01001207 public interface ExpansionLogger {
Anthony Chen6bf88a02017-04-10 14:41:44 -07001208 void logNotificationExpansion(String key, boolean userAction, boolean expanded);
Chris Wren78403d72014-07-28 10:23:24 +01001209 }
Selim Cinek1685e632014-04-08 02:27:49 +02001210
Chris Wren51c75102013-07-16 20:49:17 -04001211 public ExpandableNotificationRow(Context context, AttributeSet attrs) {
1212 super(context, attrs);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001213 mFalsingManager = FalsingManager.getInstance(context);
Selim Cinek1a48bab2017-02-17 19:38:40 -08001214 mNotificationInflater = new NotificationInflater(this);
Mady Mellor95d743c2017-01-10 12:05:27 -08001215 mMenuRow = new NotificationMenuRow(mContext);
Selim Cinek01af3342016-02-09 19:25:31 -08001216 initDimens();
1217 }
1218
1219 private void initDimens() {
Selim Cinekf619ffc2016-02-17 14:53:05 -08001220 mNotificationMinHeightLegacy = getFontScaledHeight(R.dimen.notification_min_height_legacy);
1221 mNotificationMinHeight = getFontScaledHeight(R.dimen.notification_min_height);
Selim Cinek7d1009b2017-01-25 15:28:28 -08001222 mNotificationMinHeightLarge = getFontScaledHeight(
Selim Cinek87ed69b2017-02-09 15:59:43 -08001223 R.dimen.notification_min_height_increased);
Selim Cinekf619ffc2016-02-17 14:53:05 -08001224 mNotificationMaxHeight = getFontScaledHeight(R.dimen.notification_max_height);
Adrian Roos0aac04f2016-12-08 15:59:29 -08001225 mNotificationAmbientHeight = getFontScaledHeight(R.dimen.notification_ambient_height);
Selim Cinekf619ffc2016-02-17 14:53:05 -08001226 mMaxHeadsUpHeightLegacy = getFontScaledHeight(
Selim Cinek77019c72015-12-09 10:18:02 -08001227 R.dimen.notification_max_heads_up_height_legacy);
Selim Cinekf619ffc2016-02-17 14:53:05 -08001228 mMaxHeadsUpHeight = getFontScaledHeight(R.dimen.notification_max_heads_up_height);
Selim Cinek87ed69b2017-02-09 15:59:43 -08001229 mMaxHeadsUpHeightIncreased = getFontScaledHeight(
1230 R.dimen.notification_max_heads_up_height_increased);
Anthony Chen6bf88a02017-04-10 14:41:44 -07001231
Anthony Chen7acbb772017-04-07 16:45:25 -07001232 Resources res = getResources();
1233 mIncreasedPaddingBetweenElements = res.getDimensionPixelSize(
1234 R.dimen.notification_divider_height_increased);
1235 mIconTransformContentShiftNoIcon = res.getDimensionPixelSize(
Selim Cinek0242fbb2016-10-19 13:38:32 -07001236 R.dimen.notification_icon_transform_content_shift);
Anthony Chen6bf88a02017-04-10 14:41:44 -07001237 mEnableNonGroupedNotificationExpand =
1238 res.getBoolean(R.bool.config_enableNonGroupedNotificationExpand);
1239 mShowGroupBackgroundWhenExpanded =
1240 res.getBoolean(R.bool.config_showGroupNotificationBgWhenExpanded);
Selim Cinekf619ffc2016-02-17 14:53:05 -08001241 }
1242
1243 /**
1244 * @param dimenId the dimen to look up
1245 * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
1246 */
1247 private int getFontScaledHeight(int dimenId) {
1248 int dimensionPixelSize = getResources().getDimensionPixelSize(dimenId);
1249 float factor = Math.max(1.0f, getResources().getDisplayMetrics().scaledDensity /
1250 getResources().getDisplayMetrics().density);
1251 return (int) (dimensionPixelSize * factor);
Chris Wren51c75102013-07-16 20:49:17 -04001252 }
1253
Christoph Studera7fe6312014-06-27 19:32:44 +02001254 /**
1255 * Resets this view so it can be re-used for an updated notification.
1256 */
1257 public void reset() {
Jorim Jaggiae441282014-08-01 02:45:18 +02001258 mShowingPublicInitialized = false;
Selim Cinek31094df2014-08-14 19:28:15 +02001259 onHeightReset();
Selim Cinek6e28a672014-09-05 14:43:28 +02001260 requestLayout();
Christoph Studera7fe6312014-06-27 19:32:44 +02001261 }
1262
Jorim Jaggi251957d2014-04-09 04:24:09 +02001263 @Override
1264 protected void onFinishInflate() {
1265 super.onFinishInflate();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001266 mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic);
1267 mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded);
Adrian Rooseb434ff2017-01-11 11:18:48 -08001268 mLayouts = new NotificationContentView[] {mPrivateLayout, mPublicLayout};
1269
1270 for (NotificationContentView l : mLayouts) {
1271 l.setExpandClickListener(mExpandClickListener);
1272 l.setContainingNotification(this);
1273 }
Selim Cinekab29aeb2015-02-20 18:18:32 +01001274 mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub);
1275 mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() {
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001276 @Override
1277 public void onInflate(ViewStub stub, View inflated) {
1278 mGuts = (NotificationGuts) inflated;
1279 mGuts.setClipTopAmount(getClipTopAmount());
1280 mGuts.setActualHeight(getActualHeight());
Selim Cinekab29aeb2015-02-20 18:18:32 +01001281 mGutsStub = null;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001282 }
1283 });
Selim Cinekb5605e52015-02-20 18:21:41 +01001284 mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub);
1285 mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() {
1286
1287 @Override
1288 public void onInflate(ViewStub stub, View inflated) {
1289 mChildrenContainer = (NotificationChildrenContainer) inflated;
Selim Cinek6743c0b2017-01-18 18:24:01 -08001290 mChildrenContainer.setIsLowPriority(mIsLowPriority);
Selim Cinek414ad332017-02-24 19:06:12 -08001291 mChildrenContainer.setContainingNotification(ExpandableNotificationRow.this);
Selim Cinekc897bd32016-03-18 17:32:31 -07001292 mChildrenContainer.onNotificationUpdated();
Anthony Chen7acbb772017-04-07 16:45:25 -07001293
1294 if (mShouldTranslateContents) {
1295 mTranslateableViews.add(mChildrenContainer);
1296 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001297 }
1298 });
Mady Mellor4b80b102016-01-22 08:03:58 -08001299
Anthony Chen7acbb772017-04-07 16:45:25 -07001300 if (mShouldTranslateContents) {
1301 // Add the views that we translate to reveal the menu
1302 mTranslateableViews = new ArrayList<>();
1303 for (int i = 0; i < getChildCount(); i++) {
1304 mTranslateableViews.add(getChildAt(i));
1305 }
1306 // Remove views that don't translate
1307 mTranslateableViews.remove(mChildrenContainerStub);
1308 mTranslateableViews.remove(mGutsStub);
Mady Mellor4b80b102016-01-22 08:03:58 -08001309 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001310 }
1311
Mady Mellor4b80b102016-01-22 08:03:58 -08001312 public void resetTranslation() {
Mady Mellor32c638a2016-09-14 08:58:25 -07001313 if (mTranslateAnim != null) {
1314 mTranslateAnim.cancel();
1315 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001316
1317 if (!mShouldTranslateContents) {
1318 setTranslationX(0);
1319 } else if (mTranslateableViews != null) {
Mady Mellor4b80b102016-01-22 08:03:58 -08001320 for (int i = 0; i < mTranslateableViews.size(); i++) {
1321 mTranslateableViews.get(i).setTranslationX(0);
1322 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001323 invalidateOutline();
Mady Mellor4b80b102016-01-22 08:03:58 -08001324 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001325
Mady Mellor95d743c2017-01-10 12:05:27 -08001326 mMenuRow.resetMenu();
Mady Mellor4b80b102016-01-22 08:03:58 -08001327 }
1328
1329 public void animateTranslateNotification(final float leftTarget) {
1330 if (mTranslateAnim != null) {
1331 mTranslateAnim.cancel();
1332 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001333 mTranslateAnim = getTranslateViewAnimator(leftTarget, null /* updateListener */);
Mady Mellor34958fa2016-02-23 09:52:17 -08001334 if (mTranslateAnim != null) {
1335 mTranslateAnim.start();
1336 }
1337 }
1338
1339 @Override
1340 public void setTranslation(float translationX) {
1341 if (areGutsExposed()) {
1342 // Don't translate if guts are showing.
1343 return;
1344 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001345 if (!mShouldTranslateContents) {
1346 setTranslationX(translationX);
1347 } else if (mTranslateableViews != null) {
1348 // Translate the group of views
1349 for (int i = 0; i < mTranslateableViews.size(); i++) {
1350 if (mTranslateableViews.get(i) != null) {
1351 mTranslateableViews.get(i).setTranslationX(translationX);
1352 }
Mady Mellor34958fa2016-02-23 09:52:17 -08001353 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001354 invalidateOutline();
Mady Mellor34958fa2016-02-23 09:52:17 -08001355 }
Mady Mellor95d743c2017-01-10 12:05:27 -08001356 if (mMenuRow.getMenuView() != null) {
1357 mMenuRow.onTranslationUpdate(translationX);
Mady Mellor34958fa2016-02-23 09:52:17 -08001358 }
1359 }
1360
1361 @Override
1362 public float getTranslation() {
Anthony Chene04afcb2017-04-21 13:51:32 -07001363 if (!mShouldTranslateContents) {
Anthony Chen7acbb772017-04-07 16:45:25 -07001364 return getTranslationX();
1365 }
1366
Mady Mellor34958fa2016-02-23 09:52:17 -08001367 if (mTranslateableViews != null && mTranslateableViews.size() > 0) {
1368 // All of the views in the list should have same translation, just use first one.
1369 return mTranslateableViews.get(0).getTranslationX();
1370 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001371
Mady Mellor34958fa2016-02-23 09:52:17 -08001372 return 0;
1373 }
1374
1375 public Animator getTranslateViewAnimator(final float leftTarget,
1376 AnimatorUpdateListener listener) {
Mady Mellor723f1f92016-03-13 15:54:06 -07001377 if (mTranslateAnim != null) {
1378 mTranslateAnim.cancel();
1379 }
Mady Mellor34958fa2016-02-23 09:52:17 -08001380 if (areGutsExposed()) {
1381 // No translation if guts are exposed.
1382 return null;
1383 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001384 final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(this, TRANSLATE_CONTENT,
1385 leftTarget);
1386 if (listener != null) {
1387 translateAnim.addUpdateListener(listener);
Mady Mellor4b80b102016-01-22 08:03:58 -08001388 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001389 translateAnim.addListener(new AnimatorListenerAdapter() {
1390 boolean cancelled = false;
1391
1392 @Override
1393 public void onAnimationCancel(Animator anim) {
1394 cancelled = true;
1395 }
1396
1397 @Override
1398 public void onAnimationEnd(Animator anim) {
Mady Mellor95d743c2017-01-10 12:05:27 -08001399 if (!cancelled && leftTarget == 0) {
1400 mMenuRow.resetMenu();
Mady Mellorb0a82462016-04-30 17:31:02 -07001401 mTranslateAnim = null;
1402 }
1403 }
1404 });
1405 mTranslateAnim = translateAnim;
1406 return translateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -08001407 }
1408
Selim Cinekab29aeb2015-02-20 18:18:32 +01001409 public void inflateGuts() {
1410 if (mGuts == null) {
1411 mGutsStub.inflate();
1412 }
1413 }
1414
Selim Cinekda42d652015-12-04 15:51:16 -08001415 private void updateChildrenVisibility() {
Selim Cinekd84a5932015-12-15 11:45:36 -08001416 mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE
1417 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -08001418 if (mChildrenContainer != null) {
1419 mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
1420 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -08001421 }
Selim Cinekda42d652015-12-04 15:51:16 -08001422 // The limits might have changed if the view suddenly became a group or vice versa
1423 updateLimits();
Selim Cinekb5605e52015-02-20 18:21:41 +01001424 }
1425
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001426 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08001427 public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
1428 if (super.onRequestSendAccessibilityEventInternal(child, event)) {
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001429 // Add a record for the entire layout since its content is somehow small.
1430 // The event comes from a leaf view that is interacted with.
1431 AccessibilityEvent record = AccessibilityEvent.obtain();
1432 onInitializeAccessibilityEvent(record);
1433 dispatchPopulateAccessibilityEvent(record);
1434 event.appendRecord(record);
1435 return true;
1436 }
1437 return false;
Jorim Jaggic5dc0d02014-04-15 15:42:55 +02001438 }
Chris Wren51c75102013-07-16 20:49:17 -04001439
John Spurlocke15452b2014-08-21 09:44:39 -04001440 @Override
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001441 public void setDark(boolean dark, boolean fade, long delay) {
1442 super.setDark(dark, fade, delay);
Adrian Roos28f90c72017-05-08 17:24:26 -07001443 if (!mIsHeadsUp) {
1444 // Only fade the showing view of the pulsing notification.
1445 fade = false;
1446 }
John Spurlocke15452b2014-08-21 09:44:39 -04001447 final NotificationContentView showing = getShowingLayout();
1448 if (showing != null) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001449 showing.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -04001450 }
Selim Cinek9c7712d2015-12-08 19:19:48 -08001451 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001452 mChildrenContainer.setDark(dark, fade, delay);
Selim Cinek9c7712d2015-12-08 19:19:48 -08001453 }
John Spurlocke15452b2014-08-21 09:44:39 -04001454 }
1455
Chris Wren51c75102013-07-16 20:49:17 -04001456 public boolean isExpandable() {
Selim Cinek388df6d2015-10-22 13:25:11 -07001457 if (mIsSummaryWithChildren && !mShowingPublic) {
1458 return !mChildrenExpanded;
1459 }
Anthony Chen6bf88a02017-04-10 14:41:44 -07001460 return mEnableNonGroupedNotificationExpand && mExpandable;
Chris Wren51c75102013-07-16 20:49:17 -04001461 }
1462
1463 public void setExpandable(boolean expandable) {
1464 mExpandable = expandable;
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001465 mPrivateLayout.updateExpandButtons(isExpandable());
Chris Wren51c75102013-07-16 20:49:17 -04001466 }
1467
Selim Cinek4ffd6362015-12-29 15:12:23 +01001468 @Override
1469 public void setClipToActualHeight(boolean clipToActualHeight) {
Selim Cinek084c16b2016-01-22 17:48:22 -08001470 super.setClipToActualHeight(clipToActualHeight || isUserLocked());
1471 getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked());
Selim Cinek4ffd6362015-12-29 15:12:23 +01001472 }
1473
Selim Cinek1685e632014-04-08 02:27:49 +02001474 /**
1475 * @return whether the user has changed the expansion state
1476 */
1477 public boolean hasUserChangedExpansion() {
1478 return mHasUserChangedExpansion;
1479 }
1480
Chris Wren51c75102013-07-16 20:49:17 -04001481 public boolean isUserExpanded() {
1482 return mUserExpanded;
1483 }
1484
Selim Cinek1685e632014-04-08 02:27:49 +02001485 /**
1486 * Set this notification to be expanded by the user
1487 *
1488 * @param userExpanded whether the user wants this notification to be expanded
1489 */
Chris Wren51c75102013-07-16 20:49:17 -04001490 public void setUserExpanded(boolean userExpanded) {
Selim Cinek388df6d2015-10-22 13:25:11 -07001491 setUserExpanded(userExpanded, false /* allowChildExpansion */);
1492 }
1493
1494 /**
1495 * Set this notification to be expanded by the user
1496 *
1497 * @param userExpanded whether the user wants this notification to be expanded
1498 * @param allowChildExpansion whether a call to this method allows expanding children
1499 */
1500 public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001501 mFalsingManager.setNotificationExpanded();
Selim Cinek414ad332017-02-24 19:06:12 -08001502 if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion
1503 && !mChildrenContainer.showingAsLowPriority()) {
Chris Wren698b1702016-05-23 11:16:32 -04001504 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinek388df6d2015-10-22 13:25:11 -07001505 mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded);
Selim Cinek414ad332017-02-24 19:06:12 -08001506 onExpansionChanged(true /* userAction */, wasExpanded);
Selim Cinek388df6d2015-10-22 13:25:11 -07001507 return;
1508 }
Christoph Studera7fe6312014-06-27 19:32:44 +02001509 if (userExpanded && !mExpandable) return;
Chris Wren78403d72014-07-28 10:23:24 +01001510 final boolean wasExpanded = isExpanded();
Selim Cinek1685e632014-04-08 02:27:49 +02001511 mHasUserChangedExpansion = true;
Chris Wren51c75102013-07-16 20:49:17 -04001512 mUserExpanded = userExpanded;
Selim Cinek414ad332017-02-24 19:06:12 -08001513 onExpansionChanged(true /* userAction */, wasExpanded);
Selim Cinek5d6ef8d2017-05-18 22:16:00 -07001514 if (!wasExpanded && isExpanded()
1515 && getActualHeight() != getIntrinsicHeight()) {
1516 notifyHeightChanged(true /* needsAnimation */);
1517 }
Chris Wren51c75102013-07-16 20:49:17 -04001518 }
1519
Selim Cinekccd14fb2014-08-12 18:53:24 +02001520 public void resetUserExpansion() {
Selim Cinek414ad332017-02-24 19:06:12 -08001521 boolean changed = mUserExpanded;
Selim Cinekccd14fb2014-08-12 18:53:24 +02001522 mHasUserChangedExpansion = false;
1523 mUserExpanded = false;
Selim Cinek414ad332017-02-24 19:06:12 -08001524 if (changed && mIsSummaryWithChildren) {
1525 mChildrenContainer.onExpansionChanged();
1526 }
1527 updateShelfIconColor();
Selim Cinekccd14fb2014-08-12 18:53:24 +02001528 }
1529
Chris Wren51c75102013-07-16 20:49:17 -04001530 public boolean isUserLocked() {
Selim Cinek1b2a05e2016-04-28 14:20:39 -07001531 return mUserLocked && !mForceUnlocked;
Chris Wren51c75102013-07-16 20:49:17 -04001532 }
1533
1534 public void setUserLocked(boolean userLocked) {
1535 mUserLocked = userLocked;
Selim Cinek8f2f6a62016-02-23 19:56:31 -08001536 mPrivateLayout.setUserExpanding(userLocked);
Selim Cinek817abe72017-05-24 11:08:55 -07001537 // This is intentionally not guarded with mIsSummaryWithChildren since we might have had
1538 // children but not anymore.
1539 if (mChildrenContainer != null) {
Selim Cinek42357e02016-02-24 18:48:01 -08001540 mChildrenContainer.setUserLocked(userLocked);
Selim Cinek817abe72017-05-24 11:08:55 -07001541 if (mIsSummaryWithChildren && (userLocked || !isGroupExpanded())) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001542 updateBackgroundForGroupState();
1543 }
Selim Cinek42357e02016-02-24 18:48:01 -08001544 }
Chris Wren51c75102013-07-16 20:49:17 -04001545 }
1546
Selim Cinek1685e632014-04-08 02:27:49 +02001547 /**
1548 * @return has the system set this notification to be expanded
1549 */
1550 public boolean isSystemExpanded() {
1551 return mIsSystemExpanded;
1552 }
1553
1554 /**
1555 * Set this notification to be expanded by the system.
1556 *
1557 * @param expand whether the system wants this notification to be expanded.
1558 */
1559 public void setSystemExpanded(boolean expand) {
Selim Cinek31094df2014-08-14 19:28:15 +02001560 if (expand != mIsSystemExpanded) {
1561 final boolean wasExpanded = isExpanded();
1562 mIsSystemExpanded = expand;
Selim Cinekb5605e52015-02-20 18:21:41 +01001563 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek414ad332017-02-24 19:06:12 -08001564 onExpansionChanged(false /* userAction */, wasExpanded);
Selim Cineked6913b2016-06-01 12:01:17 -07001565 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001566 mChildrenContainer.updateGroupOverflow();
1567 }
Selim Cinek31094df2014-08-14 19:28:15 +02001568 }
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001569 }
1570
1571 /**
Selim Cinek83bc7832015-10-22 13:26:54 -07001572 * @param onKeyguard whether to prevent notification expansion
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001573 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001574 public void setOnKeyguard(boolean onKeyguard) {
1575 if (onKeyguard != mOnKeyguard) {
Selim Cinek5cf1d052017-06-01 17:36:46 -07001576 boolean wasAboveShelf = isAboveShelf();
Selim Cinek31094df2014-08-14 19:28:15 +02001577 final boolean wasExpanded = isExpanded();
Selim Cinek83bc7832015-10-22 13:26:54 -07001578 mOnKeyguard = onKeyguard;
Selim Cinek414ad332017-02-24 19:06:12 -08001579 onExpansionChanged(false /* userAction */, wasExpanded);
Selim Cinek31094df2014-08-14 19:28:15 +02001580 if (wasExpanded != isExpanded()) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001581 if (mIsSummaryWithChildren) {
1582 mChildrenContainer.updateGroupOverflow();
1583 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001584 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +02001585 }
Selim Cinek5cf1d052017-06-01 17:36:46 -07001586 if (isAboveShelf() != wasAboveShelf) {
1587 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
1588 }
Selim Cinek31094df2014-08-14 19:28:15 +02001589 }
Selim Cinek1685e632014-04-08 02:27:49 +02001590 }
1591
1592 /**
Selim Cinek9e624e72016-07-20 13:46:49 -07001593 * @return Can the underlying notification be cleared? This can be different from whether the
1594 * notification can be dismissed in case notifications are sensitive on the lockscreen.
1595 * @see #canViewBeDismissed()
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001596 */
1597 public boolean isClearable() {
Selim Cinek506deb62016-07-20 15:43:59 -07001598 if (mStatusBarNotification == null || !mStatusBarNotification.isClearable()) {
1599 return false;
1600 }
1601 if (mIsSummaryWithChildren) {
1602 List<ExpandableNotificationRow> notificationChildren =
1603 mChildrenContainer.getNotificationChildren();
1604 for (int i = 0; i < notificationChildren.size(); i++) {
1605 ExpandableNotificationRow child = notificationChildren.get(i);
1606 if (!child.isClearable()) {
1607 return false;
1608 }
1609 }
1610 }
1611 return true;
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001612 }
1613
Jorim Jaggi9cbadd32014-05-01 20:18:31 +02001614 @Override
1615 public int getIntrinsicHeight() {
Jorim Jaggibe565df2014-04-28 17:51:23 +02001616 if (isUserLocked()) {
1617 return getActualHeight();
1618 }
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05001619 if (mGuts != null && mGuts.isExposed()) {
Mady Mellore09fb702017-03-30 13:23:29 -07001620 return mGuts.getIntrinsicHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -08001621 } else if ((isChildInGroup() && !isGroupExpanded())) {
1622 return mPrivateLayout.getMinHeight();
1623 } else if (mSensitive && mHideSensitiveForIntrinsicHeight) {
1624 return getMinHeight();
Adrian Roos6f6e1592017-05-02 16:22:53 -07001625 } else if (mIsSummaryWithChildren && (!mOnKeyguard || mShowAmbient)) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001626 return mChildrenContainer.getIntrinsicHeight();
Adrian Roos6f6e1592017-05-02 16:22:53 -07001627 } else if (isHeadsUpAllowed() && (mIsHeadsUp || mHeadsupDisappearRunning)) {
Selim Cinek73cf02a2016-06-17 13:08:00 -07001628 if (isPinned() || mHeadsupDisappearRunning) {
Selim Cinek31aada42015-12-18 17:51:15 -08001629 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
1630 } else if (isExpanded()) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001631 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001632 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001633 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001634 }
Selim Cinek31aada42015-12-18 17:51:15 -08001635 } else if (isExpanded()) {
Selim Cinek83bc7832015-10-22 13:26:54 -07001636 return getMaxExpandHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -08001637 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001638 return getCollapsedHeight();
Selim Cinek1685e632014-04-08 02:27:49 +02001639 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001640 }
Selim Cinek1685e632014-04-08 02:27:49 +02001641
Adrian Roos6f6e1592017-05-02 16:22:53 -07001642 private boolean isHeadsUpAllowed() {
1643 return !mOnKeyguard && !mShowAmbient;
1644 }
1645
Mady Mellor43c2cd12016-12-12 21:05:13 -08001646 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -07001647 public boolean isGroupExpanded() {
Selim Cinekeef84282015-10-30 16:28:00 -07001648 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinekb5605e52015-02-20 18:21:41 +01001649 }
1650
Selim Cinek263398f2015-10-21 17:40:23 -07001651 private void onChildrenCountChanged() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001652 mIsSummaryWithChildren = StatusBar.ENABLE_CHILD_NOTIFICATIONS
Mady Mellorb0a82462016-04-30 17:31:02 -07001653 && mChildrenContainer != null && mChildrenContainer.getNotificationChildCount() > 0;
1654 if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() == null) {
Selim Cinek414ad332017-02-24 19:06:12 -08001655 mChildrenContainer.recreateNotificationHeader(mExpandClickListener
1656 );
Selim Cinek263398f2015-10-21 17:40:23 -07001657 }
Mady Mellor6baed9e2016-05-25 16:05:09 -07001658 getShowingLayout().updateBackgroundColor(false /* animate */);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001659 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinekea4bef72015-12-02 15:51:10 -08001660 updateChildrenHeaderAppearance();
Selim Cinekda42d652015-12-04 15:51:16 -08001661 updateChildrenVisibility();
Selim Cinek263398f2015-10-21 17:40:23 -07001662 }
1663
Mady Mellorb0a82462016-04-30 17:31:02 -07001664 public void updateChildrenHeaderAppearance() {
Selim Cineked6913b2016-06-01 12:01:17 -07001665 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001666 mChildrenContainer.updateChildrenHeaderAppearance();
1667 }
1668 }
1669
Selim Cinek1685e632014-04-08 02:27:49 +02001670 /**
1671 * Check whether the view state is currently expanded. This is given by the system in {@link
1672 * #setSystemExpanded(boolean)} and can be overridden by user expansion or
1673 * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this
1674 * view can differ from this state, if layout params are modified from outside.
1675 *
1676 * @return whether the view state is currently expanded.
1677 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001678 public boolean isExpanded() {
Selim Cineke81b82b2016-03-04 11:22:28 -08001679 return isExpanded(false /* allowOnKeyguard */);
1680 }
1681
1682 public boolean isExpanded(boolean allowOnKeyguard) {
1683 return (!mOnKeyguard || allowOnKeyguard)
Selim Cinekb5605e52015-02-20 18:21:41 +01001684 && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded())
1685 || isUserExpanded());
1686 }
1687
1688 private boolean isSystemChildExpanded() {
1689 return mIsSystemChildExpanded;
1690 }
1691
1692 public void setSystemChildExpanded(boolean expanded) {
1693 mIsSystemChildExpanded = expanded;
Selim Cinek1685e632014-04-08 02:27:49 +02001694 }
1695
Mady Mellor035badd2017-04-04 18:45:30 -07001696 public void setLayoutListener(LayoutListener listener) {
1697 mLayoutListener = listener;
1698 }
1699
1700 public void removeListener() {
1701 mLayoutListener = null;
1702 }
1703
Selim Cinek1685e632014-04-08 02:27:49 +02001704 @Override
1705 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
1706 super.onLayout(changed, left, top, right, bottom);
Selim Cinek8d490d42015-04-10 00:05:50 -07001707 updateMaxHeights();
Mady Mellor95d743c2017-01-10 12:05:27 -08001708 if (mMenuRow.getMenuView() != null) {
1709 mMenuRow.onHeightUpdate();
Mady Mellora6edc872016-04-26 11:01:03 -07001710 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001711 updateContentShiftHeight();
Mady Mellor035badd2017-04-04 18:45:30 -07001712 if (mLayoutListener != null) {
1713 mLayoutListener.onLayout();
1714 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001715 }
1716
1717 /**
1718 * Updates the content shift height such that the header is completely hidden when coming from
1719 * the top.
1720 */
1721 private void updateContentShiftHeight() {
Selim Cinek414ad332017-02-24 19:06:12 -08001722 NotificationHeaderView notificationHeader = getVisibleNotificationHeader();
Selim Cinek875a3a12016-11-18 17:52:16 -08001723 if (notificationHeader != null) {
1724 CachingIconView icon = notificationHeader.getIcon();
1725 mIconTransformContentShift = getRelativeTopPadding(icon) + icon.getHeight();
1726 } else {
1727 mIconTransformContentShift = mIconTransformContentShiftNoIcon;
1728 }
Selim Cinek1685e632014-04-08 02:27:49 +02001729 }
1730
Selim Cinek8d490d42015-04-10 00:05:50 -07001731 private void updateMaxHeights() {
Selim Cinekd2319fb2014-09-01 19:41:54 +02001732 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek8d490d42015-04-10 00:05:50 -07001733 View expandedChild = mPrivateLayout.getExpandedChild();
1734 if (expandedChild == null) {
1735 expandedChild = mPrivateLayout.getContractedChild();
1736 }
1737 mMaxExpandHeight = expandedChild.getHeight();
1738 View headsUpChild = mPrivateLayout.getHeadsUpChild();
Selim Cinek1f3f5442015-04-10 17:54:46 -07001739 if (headsUpChild == null) {
1740 headsUpChild = mPrivateLayout.getContractedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -07001741 }
Selim Cinek1f3f5442015-04-10 17:54:46 -07001742 mHeadsUpHeight = headsUpChild.getHeight();
Selim Cinekd2319fb2014-09-01 19:41:54 +02001743 if (intrinsicBefore != getIntrinsicHeight()) {
Selim Cinekbb42b7d2016-08-10 13:02:38 -07001744 notifyHeightChanged(true /* needsAnimation */);
Selim Cinekd2319fb2014-09-01 19:41:54 +02001745 }
1746 }
1747
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001748 @Override
1749 public void notifyHeightChanged(boolean needsAnimation) {
1750 super.notifyHeightChanged(needsAnimation);
1751 getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked());
1752 }
1753
Selim Cinek3c76d502016-02-19 15:16:33 -08001754 public void setSensitive(boolean sensitive, boolean hideSensitive) {
Jorim Jaggiae441282014-08-01 02:45:18 +02001755 mSensitive = sensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -08001756 mSensitiveHiddenInGeneral = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02001757 }
1758
Mady Mellor43c2cd12016-12-12 21:05:13 -08001759 @Override
Jorim Jaggiae441282014-08-01 02:45:18 +02001760 public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
Selim Cinek60122be2015-04-15 18:16:50 -07001761 mHideSensitiveForIntrinsicHeight = hideSensitive;
Selim Cineka52f6a12016-02-29 15:35:58 -08001762 if (mIsSummaryWithChildren) {
1763 List<ExpandableNotificationRow> notificationChildren =
1764 mChildrenContainer.getNotificationChildren();
1765 for (int i = 0; i < notificationChildren.size(); i++) {
1766 ExpandableNotificationRow child = notificationChildren.get(i);
1767 child.setHideSensitiveForIntrinsicHeight(hideSensitive);
1768 }
1769 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001770 }
1771
Mady Mellor43c2cd12016-12-12 21:05:13 -08001772 @Override
Jorim Jaggiae441282014-08-01 02:45:18 +02001773 public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
1774 long duration) {
1775 boolean oldShowingPublic = mShowingPublic;
1776 mShowingPublic = mSensitive && hideSensitive;
1777 if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
1778 return;
1779 }
Dan Sandlera5e0f412014-01-23 15:11:54 -05001780
1781 // bail out if no public version
Selim Cinek1685e632014-04-08 02:27:49 +02001782 if (mPublicLayout.getChildCount() == 0) return;
Dan Sandlera5e0f412014-01-23 15:11:54 -05001783
Jorim Jaggiae441282014-08-01 02:45:18 +02001784 if (!animated) {
1785 mPublicLayout.animate().cancel();
1786 mPrivateLayout.animate().cancel();
Selim Cineka554c702016-06-17 18:02:12 -07001787 if (mChildrenContainer != null) {
1788 mChildrenContainer.animate().cancel();
1789 mChildrenContainer.setAlpha(1f);
1790 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001791 mPublicLayout.setAlpha(1f);
1792 mPrivateLayout.setAlpha(1f);
1793 mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
Selim Cinekd84a5932015-12-15 11:45:36 -08001794 updateChildrenVisibility();
Jorim Jaggiae441282014-08-01 02:45:18 +02001795 } else {
1796 animateShowingPublic(delay, duration);
1797 }
Selim Cinekc3179332016-03-04 14:44:56 -08001798 NotificationContentView showingLayout = getShowingLayout();
1799 showingLayout.updateBackgroundColor(animated);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001800 mPrivateLayout.updateExpandButtons(isExpandable());
Lucas Dupinb6ed63b2017-05-30 16:17:42 -07001801 updateShelfIconColor();
Adrian Roose5726a22016-12-19 14:26:51 -08001802 showingLayout.setDark(isDark(), false /* animate */, 0 /* delay */);
Jorim Jaggiae441282014-08-01 02:45:18 +02001803 mShowingPublicInitialized = true;
1804 }
1805
1806 private void animateShowingPublic(long delay, long duration) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001807 View[] privateViews = mIsSummaryWithChildren
1808 ? new View[] {mChildrenContainer}
Selim Cinekd84a5932015-12-15 11:45:36 -08001809 : new View[] {mPrivateLayout};
1810 View[] publicViews = new View[] {mPublicLayout};
1811 View[] hiddenChildren = mShowingPublic ? privateViews : publicViews;
1812 View[] shownChildren = mShowingPublic ? publicViews : privateViews;
1813 for (final View hiddenView : hiddenChildren) {
1814 hiddenView.setVisibility(View.VISIBLE);
1815 hiddenView.animate().cancel();
1816 hiddenView.animate()
1817 .alpha(0f)
1818 .setStartDelay(delay)
1819 .setDuration(duration)
1820 .withEndAction(new Runnable() {
1821 @Override
1822 public void run() {
1823 hiddenView.setVisibility(View.INVISIBLE);
1824 }
1825 });
1826 }
1827 for (View showView : shownChildren) {
1828 showView.setVisibility(View.VISIBLE);
1829 showView.setAlpha(0f);
1830 showView.animate().cancel();
1831 showView.animate()
1832 .alpha(1f)
1833 .setStartDelay(delay)
1834 .setDuration(duration);
1835 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001836 }
1837
Mady Mellor43c2cd12016-12-12 21:05:13 -08001838 @Override
Selim Cinek3776fe02016-02-04 13:32:43 -08001839 public boolean mustStayOnScreen() {
1840 return mIsHeadsUp;
1841 }
1842
Selim Cinek9e624e72016-07-20 13:46:49 -07001843 /**
1844 * @return Whether this view is allowed to be dismissed. Only valid for visible notifications as
1845 * otherwise some state might not be updated. To request about the general clearability
1846 * see {@link #isClearable()}.
1847 */
1848 public boolean canViewBeDismissed() {
Selim Cineke9bad242016-06-15 11:46:37 -07001849 return isClearable() && (!mShowingPublic || !mSensitiveHiddenInGeneral);
Dan Sandlera5e0f412014-01-23 15:11:54 -05001850 }
Jorim Jaggi251957d2014-04-09 04:24:09 +02001851
Ricky Waicd35def2016-05-03 11:07:07 +01001852 public void makeActionsVisibile() {
1853 setUserExpanded(true, true);
1854 if (isChildInGroup()) {
1855 mGroupManager.setGroupExpanded(mStatusBarNotification, true);
1856 }
Selim Cinekbb42b7d2016-08-10 13:02:38 -07001857 notifyHeightChanged(false /* needsAnimation */);
Ricky Waicd35def2016-05-03 11:07:07 +01001858 }
1859
Selim Cinekb5605e52015-02-20 18:21:41 +01001860 public void setChildrenExpanded(boolean expanded, boolean animate) {
1861 mChildrenExpanded = expanded;
Selim Cinek83bc7832015-10-22 13:26:54 -07001862 if (mChildrenContainer != null) {
1863 mChildrenContainer.setChildrenExpanded(expanded);
1864 }
Mady Mellor1a5d8ea2016-06-09 10:42:42 -07001865 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -07001866 updateClickAndFocus();
Selim Cinekb5605e52015-02-20 18:21:41 +01001867 }
1868
Selim Cinekb5605e52015-02-20 18:21:41 +01001869 public static void applyTint(View v, int color) {
1870 int alpha;
1871 if (color != 0) {
1872 alpha = COLORED_DIVIDER_ALPHA;
1873 } else {
1874 color = 0xff000000;
1875 alpha = DEFAULT_DIVIDER_ALPHA;
1876 }
1877 if (v.getBackground() instanceof ColorDrawable) {
1878 ColorDrawable background = (ColorDrawable) v.getBackground();
1879 background.mutate();
1880 background.setColor(color);
1881 background.setAlpha(alpha);
1882 }
1883 }
1884
Selim Cinek1685e632014-04-08 02:27:49 +02001885 public int getMaxExpandHeight() {
Selim Cinekb5605e52015-02-20 18:21:41 +01001886 return mMaxExpandHeight;
Chris Wren51c75102013-07-16 20:49:17 -04001887 }
Jorim Jaggi584a7aa2014-04-10 23:26:13 +02001888
Mady Mellor34958fa2016-02-23 09:52:17 -08001889 public boolean areGutsExposed() {
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05001890 return (mGuts != null && mGuts.isExposed());
Mady Mellor34958fa2016-02-23 09:52:17 -08001891 }
1892
Jorim Jaggibe565df2014-04-28 17:51:23 +02001893 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001894 public boolean isContentExpandable() {
Selim Cinekc0ac4af2017-03-03 15:13:48 -08001895 if (mIsSummaryWithChildren && !mShowingPublic) {
1896 return true;
1897 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001898 NotificationContentView showingLayout = getShowingLayout();
1899 return showingLayout.isContentExpandable();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001900 }
1901
1902 @Override
Selim Cinek560e64d2015-06-09 19:58:11 -07001903 protected View getContentView() {
Selim Cinekaa3901a2016-08-05 11:04:37 -07001904 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cineka5703182016-05-11 21:23:16 -04001905 return mChildrenContainer;
1906 }
Selim Cinek560e64d2015-06-09 19:58:11 -07001907 return getShowingLayout();
1908 }
1909
1910 @Override
Selim Cinekaa3901a2016-08-05 11:04:37 -07001911 protected void onAppearAnimationFinished(boolean wasAppearing) {
1912 super.onAppearAnimationFinished(wasAppearing);
1913 if (wasAppearing) {
1914 // During the animation the visible view might have changed, so let's make sure all
1915 // alphas are reset
1916 if (mChildrenContainer != null) {
1917 mChildrenContainer.setAlpha(1.0f);
1918 mChildrenContainer.setLayerType(LAYER_TYPE_NONE, null);
1919 }
Adrian Rooseb434ff2017-01-11 11:18:48 -08001920 for (NotificationContentView l : mLayouts) {
1921 l.setAlpha(1.0f);
1922 l.setLayerType(LAYER_TYPE_NONE, null);
1923 }
Selim Cinekaa3901a2016-08-05 11:04:37 -07001924 }
1925 }
1926
1927 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -07001928 public int getExtraBottomPadding() {
1929 if (mIsSummaryWithChildren && isGroupExpanded()) {
1930 return mIncreasedPaddingBetweenElements;
1931 }
1932 return 0;
1933 }
1934
1935 @Override
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001936 public void setActualHeight(int height, boolean notifyListeners) {
Selim Cinek4ca6c632017-02-23 18:03:37 -08001937 boolean changed = height != getActualHeight();
Selim Cinekb5605e52015-02-20 18:21:41 +01001938 super.setActualHeight(height, notifyListeners);
Selim Cinek4ca6c632017-02-23 18:03:37 -08001939 if (changed && isRemoved()) {
1940 // TODO: remove this once we found the gfx bug for this.
1941 // This is a hack since a removed view sometimes would just stay blank. it occured
1942 // when sending yourself a message and then clicking on it.
1943 ViewGroup parent = (ViewGroup) getParent();
1944 if (parent != null) {
1945 parent.invalidate();
1946 }
1947 }
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05001948 if (mGuts != null && mGuts.isExposed()) {
Mady Mellorb53bc272016-02-11 18:28:23 -08001949 mGuts.setActualHeight(height);
1950 return;
1951 }
Selim Cinekeef84282015-10-30 16:28:00 -07001952 int contentHeight = Math.max(getMinHeight(), height);
Adrian Rooseb434ff2017-01-11 11:18:48 -08001953 for (NotificationContentView l : mLayouts) {
1954 l.setContentHeight(contentHeight);
1955 }
Selim Cinek42357e02016-02-24 18:48:01 -08001956 if (mIsSummaryWithChildren) {
1957 mChildrenContainer.setActualHeight(height);
1958 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001959 if (mGuts != null) {
1960 mGuts.setActualHeight(height);
1961 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001962 }
1963
1964 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01001965 public int getMaxContentHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001966 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001967 return mChildrenContainer.getMaxContentHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001968 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001969 NotificationContentView showingLayout = getShowingLayout();
1970 return showingLayout.getMaxHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001971 }
1972
1973 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001974 public int getMinHeight() {
Mady Mellore09fb702017-03-30 13:23:29 -07001975 if (mGuts != null && mGuts.isExposed()) {
1976 return mGuts.getIntrinsicHeight();
Adrian Roos6f6e1592017-05-02 16:22:53 -07001977 } else if (isHeadsUpAllowed() && mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) {
Selim Cinek31aada42015-12-18 17:51:15 -08001978 return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
1979 } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001980 return mChildrenContainer.getMinHeight();
Adrian Roos6f6e1592017-05-02 16:22:53 -07001981 } else if (isHeadsUpAllowed() && mIsHeadsUp) {
Selim Cinek31aada42015-12-18 17:51:15 -08001982 return mHeadsUpHeight;
Selim Cinekb55386d2015-12-16 17:26:49 -08001983 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001984 NotificationContentView showingLayout = getShowingLayout();
1985 return showingLayout.getMinHeight();
1986 }
1987
1988 @Override
Selim Cinek567e8452016-03-24 10:54:56 -07001989 public int getCollapsedHeight() {
Selim Cinek2c584612016-02-29 16:14:25 -08001990 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinek567e8452016-03-24 10:54:56 -07001991 return mChildrenContainer.getCollapsedHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001992 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001993 return getMinHeight();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001994 }
1995
1996 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02001997 public void setClipTopAmount(int clipTopAmount) {
1998 super.setClipTopAmount(clipTopAmount);
Adrian Rooseb434ff2017-01-11 11:18:48 -08001999 for (NotificationContentView l : mLayouts) {
2000 l.setClipTopAmount(clipTopAmount);
2001 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02002002 if (mGuts != null) {
2003 mGuts.setClipTopAmount(clipTopAmount);
2004 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02002005 }
2006
Selim Cineka686b2c2016-10-26 13:58:27 -07002007 @Override
2008 public void setClipBottomAmount(int clipBottomAmount) {
Selim Cinek65d418e2016-11-29 15:42:34 -08002009 if (clipBottomAmount != mClipBottomAmount) {
2010 super.setClipBottomAmount(clipBottomAmount);
Adrian Rooseb434ff2017-01-11 11:18:48 -08002011 for (NotificationContentView l : mLayouts) {
2012 l.setClipBottomAmount(clipBottomAmount);
2013 }
Selim Cinek65d418e2016-11-29 15:42:34 -08002014 if (mGuts != null) {
2015 mGuts.setClipBottomAmount(clipBottomAmount);
2016 }
Selim Cineka686b2c2016-10-26 13:58:27 -07002017 }
Selim Cinekb3dadcc2016-11-21 17:21:13 -08002018 if (mChildrenContainer != null) {
Selim Cinek65d418e2016-11-29 15:42:34 -08002019 // We have to update this even if it hasn't changed, since the children locations can
2020 // have changed
Selim Cinekb3dadcc2016-11-21 17:21:13 -08002021 mChildrenContainer.setClipBottomAmount(clipBottomAmount);
2022 }
Selim Cineka686b2c2016-10-26 13:58:27 -07002023 }
2024
Selim Cinek31094df2014-08-14 19:28:15 +02002025 public boolean isMaxExpandHeightInitialized() {
2026 return mMaxExpandHeight != 0;
Selim Cinek7d447722014-06-10 15:51:59 +02002027 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02002028
Selim Cinek42357e02016-02-24 18:48:01 -08002029 public NotificationContentView getShowingLayout() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02002030 return mShowingPublic ? mPublicLayout : mPrivateLayout;
2031 }
Chris Wren78403d72014-07-28 10:23:24 +01002032
Selim Cinek1a48bab2017-02-17 19:38:40 -08002033 public void setLegacy(boolean legacy) {
Adrian Rooseb434ff2017-01-11 11:18:48 -08002034 for (NotificationContentView l : mLayouts) {
Selim Cinek1a48bab2017-02-17 19:38:40 -08002035 l.setLegacy(legacy);
Adrian Rooseb434ff2017-01-11 11:18:48 -08002036 }
Jorim Jaggi59ec3042015-06-05 15:18:43 -07002037 }
2038
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002039 @Override
2040 protected void updateBackgroundTint() {
2041 super.updateBackgroundTint();
Mady Mellorb0a82462016-04-30 17:31:02 -07002042 updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002043 if (mIsSummaryWithChildren) {
2044 List<ExpandableNotificationRow> notificationChildren =
2045 mChildrenContainer.getNotificationChildren();
2046 for (int i = 0; i < notificationChildren.size(); i++) {
2047 ExpandableNotificationRow child = notificationChildren.get(i);
Mady Mellorb0a82462016-04-30 17:31:02 -07002048 child.updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002049 }
2050 }
2051 }
2052
Mady Mellorb0a82462016-04-30 17:31:02 -07002053 /**
2054 * Called when a group has finished animating from collapsed or expanded state.
2055 */
2056 public void onFinishedExpansionChange() {
2057 mGroupExpansionChanging = false;
2058 updateBackgroundForGroupState();
2059 }
2060
2061 /**
2062 * Updates the parent and children backgrounds in a group based on the expansion state.
2063 */
2064 public void updateBackgroundForGroupState() {
2065 if (mIsSummaryWithChildren) {
2066 // Only when the group has finished expanding do we hide its background.
Anthony Chen6bf88a02017-04-10 14:41:44 -07002067 mShowNoBackground = !mShowGroupBackgroundWhenExpanded && isGroupExpanded()
2068 && !isGroupExpansionChanging() && !isUserLocked();
Mady Mellorb0a82462016-04-30 17:31:02 -07002069 mChildrenContainer.updateHeaderForExpansion(mShowNoBackground);
2070 List<ExpandableNotificationRow> children = mChildrenContainer.getNotificationChildren();
2071 for (int i = 0; i < children.size(); i++) {
2072 children.get(i).updateBackgroundForGroupState();
2073 }
2074 } else if (isChildInGroup()) {
2075 final int childColor = getShowingLayout().getBackgroundColorForExpansionState();
2076 // Only show a background if the group is expanded OR if it is expanding / collapsing
Anthony Chen6bf88a02017-04-10 14:41:44 -07002077 // and has a custom background color.
Mady Mellorb0a82462016-04-30 17:31:02 -07002078 final boolean showBackground = isGroupExpanded()
2079 || ((mNotificationParent.isGroupExpansionChanging()
Anthony Chen6bf88a02017-04-10 14:41:44 -07002080 || mNotificationParent.isUserLocked()) && childColor != 0);
Mady Mellorb0a82462016-04-30 17:31:02 -07002081 mShowNoBackground = !showBackground;
2082 } else {
2083 // Only children or parents ever need no background.
2084 mShowNoBackground = false;
2085 }
2086 updateOutline();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002087 updateBackground();
2088 }
2089
Adrian Roos4a579672016-05-24 16:54:37 -07002090 public int getPositionOfChild(ExpandableNotificationRow childRow) {
2091 if (mIsSummaryWithChildren) {
2092 return mChildrenContainer.getPositionInLinearLayout(childRow);
2093 }
2094 return 0;
2095 }
2096
Chris Wren78403d72014-07-28 10:23:24 +01002097 public void setExpansionLogger(ExpansionLogger logger, String key) {
2098 mLogger = logger;
2099 mLoggingKey = key;
2100 }
2101
Chris Wren6abeeb92016-05-26 14:44:38 -04002102 public void onExpandedByGesture(boolean userExpanded) {
2103 int event = MetricsEvent.ACTION_NOTIFICATION_GESTURE_EXPANDER;
2104 if (mGroupManager.isSummaryOfGroup(getStatusBarNotification())) {
2105 event = MetricsEvent.ACTION_NOTIFICATION_GROUP_GESTURE_EXPANDER;
2106 }
2107 MetricsLogger.action(mContext, event, userExpanded);
2108 }
2109
Selim Cinek6183d122016-01-14 18:48:41 -08002110 @Override
Selim Cinek42357e02016-02-24 18:48:01 -08002111 public float getIncreasedPaddingAmount() {
2112 if (mIsSummaryWithChildren) {
2113 if (isGroupExpanded()) {
2114 return 1.0f;
2115 } else if (isUserLocked()) {
Selim Cinek414ad332017-02-24 19:06:12 -08002116 return mChildrenContainer.getIncreasedPaddingAmount();
Selim Cinek42357e02016-02-24 18:48:01 -08002117 }
Selim Cinek99104832017-01-25 14:47:33 -08002118 } else if (isColorized() && (!mIsLowPriority || isExpanded())) {
Selim Cineka7ed2c12017-01-23 20:47:24 -08002119 return -1.0f;
Selim Cinek42357e02016-02-24 18:48:01 -08002120 }
2121 return 0.0f;
Selim Cinek61633a82016-01-25 15:54:10 -08002122 }
2123
Selim Cineka7ed2c12017-01-23 20:47:24 -08002124 private boolean isColorized() {
Selim Cinek99104832017-01-25 14:47:33 -08002125 return mIsColorized && mBgTint != NO_COLOR;
Selim Cineka7ed2c12017-01-23 20:47:24 -08002126 }
2127
Selim Cinek61633a82016-01-25 15:54:10 -08002128 @Override
Selim Cinek6183d122016-01-14 18:48:41 -08002129 protected boolean disallowSingleClick(MotionEvent event) {
2130 float x = event.getX();
2131 float y = event.getY();
Selim Cinek34eda5e2016-02-18 17:10:43 -08002132 NotificationHeaderView header = getVisibleNotificationHeader();
Selim Cinek5d6ef8d2017-05-18 22:16:00 -07002133 if (header != null && header.isInTouchRect(x - getTranslation(), y)) {
2134 return true;
2135 }
2136 if ((!mIsSummaryWithChildren || mShowingPublic)
2137 && getShowingLayout().disallowSingleClick(x, y)) {
2138 return true;
Selim Cinek6183d122016-01-14 18:48:41 -08002139 }
2140 return super.disallowSingleClick(event);
2141 }
2142
Selim Cinek414ad332017-02-24 19:06:12 -08002143 private void onExpansionChanged(boolean userAction, boolean wasExpanded) {
Chris Wren698b1702016-05-23 11:16:32 -04002144 boolean nowExpanded = isExpanded();
Selim Cinek414ad332017-02-24 19:06:12 -08002145 if (mIsSummaryWithChildren && (!mIsLowPriority || wasExpanded)) {
Chris Wren698b1702016-05-23 11:16:32 -04002146 nowExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
2147 }
Selim Cinek414ad332017-02-24 19:06:12 -08002148 if (nowExpanded != wasExpanded) {
2149 updateShelfIconColor();
2150 if (mLogger != null) {
2151 mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded);
2152 }
2153 if (mIsSummaryWithChildren) {
2154 mChildrenContainer.onExpansionChanged();
2155 }
Chris Wren78403d72014-07-28 10:23:24 +01002156 }
2157 }
Selim Cinek570981d2015-12-01 11:37:01 -08002158
Selim Cineke9bad242016-06-15 11:46:37 -07002159 @Override
2160 public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
2161 super.onInitializeAccessibilityNodeInfoInternal(info);
2162 if (canViewBeDismissed()) {
2163 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS);
2164 }
Selim Cinekc0ac4af2017-03-03 15:13:48 -08002165 boolean expandable = mShowingPublic;
2166 boolean isExpanded = false;
2167 if (!expandable) {
2168 if (mIsSummaryWithChildren) {
2169 expandable = true;
2170 if (!mIsLowPriority || isExpanded()) {
2171 isExpanded = isGroupExpanded();
2172 }
2173 } else {
2174 expandable = mPrivateLayout.isContentExpandable();
2175 isExpanded = isExpanded();
2176 }
2177 }
2178 if (expandable) {
2179 if (isExpanded) {
2180 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE);
2181 } else {
2182 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND);
2183 }
2184 }
Selim Cineke9bad242016-06-15 11:46:37 -07002185 }
2186
2187 @Override
2188 public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
2189 if (super.performAccessibilityActionInternal(action, arguments)) {
2190 return true;
2191 }
2192 switch (action) {
2193 case AccessibilityNodeInfo.ACTION_DISMISS:
2194 NotificationStackScrollLayout.performDismiss(this, mGroupManager,
2195 true /* fromAccessibility */);
2196 return true;
Selim Cinekc0ac4af2017-03-03 15:13:48 -08002197 case AccessibilityNodeInfo.ACTION_COLLAPSE:
2198 case AccessibilityNodeInfo.ACTION_EXPAND:
2199 mExpandClickListener.onClick(this);
2200 return true;
Selim Cineke9bad242016-06-15 11:46:37 -07002201 }
2202 return false;
2203 }
2204
2205 public boolean shouldRefocusOnDismiss() {
2206 return mRefocusOnDismiss || isAccessibilityFocused();
2207 }
2208
Selim Cinek570981d2015-12-01 11:37:01 -08002209 public interface OnExpandClickListener {
Selim Cinek31aada42015-12-18 17:51:15 -08002210 void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
Selim Cinek570981d2015-12-01 11:37:01 -08002211 }
Selim Cinekbbcebde2016-11-09 18:28:20 -08002212
2213 @Override
2214 public ExpandableViewState createNewViewState(StackScrollState stackScrollState) {
2215 return new NotificationViewState(stackScrollState);
2216 }
2217
Selim Cinekd127d792016-11-01 19:11:41 -07002218 @Override
2219 public boolean isAboveShelf() {
Selim Cinekc8007c52017-02-28 16:09:56 -08002220 return !isOnKeyguard()
2221 && (mIsPinned || mHeadsupDisappearRunning || (mIsHeadsUp && mAboveShelf));
Selim Cinekd127d792016-11-01 19:11:41 -07002222 }
2223
Adrian Roos0aac04f2016-12-08 15:59:29 -08002224 public void setShowAmbient(boolean showAmbient) {
2225 if (showAmbient != mShowAmbient) {
2226 mShowAmbient = showAmbient;
Adrian Roos6f6e1592017-05-02 16:22:53 -07002227 if (mChildrenContainer != null) {
2228 mChildrenContainer.notifyShowAmbientChanged();
2229 }
Adrian Roos0aac04f2016-12-08 15:59:29 -08002230 notifyHeightChanged(false /* needsAnimation */);
2231 }
2232 }
2233
Adrian Roos6f6e1592017-05-02 16:22:53 -07002234 public boolean isShowingAmbient() {
2235 return mShowAmbient;
2236 }
2237
Selim Cinekd127d792016-11-01 19:11:41 -07002238 public void setAboveShelf(boolean aboveShelf) {
Selim Cinek5cf1d052017-06-01 17:36:46 -07002239 boolean wasAboveShelf = isAboveShelf();
Selim Cinekd127d792016-11-01 19:11:41 -07002240 mAboveShelf = aboveShelf;
Selim Cinek5cf1d052017-06-01 17:36:46 -07002241 if (isAboveShelf() != wasAboveShelf) {
2242 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
2243 }
Selim Cinekd127d792016-11-01 19:11:41 -07002244 }
2245
Selim Cinekd4776a52017-02-14 18:50:16 -08002246 public static class NotificationViewState extends ExpandableViewState {
Selim Cinekbbcebde2016-11-09 18:28:20 -08002247
2248 private final StackScrollState mOverallState;
Selim Cinek0242fbb2016-10-19 13:38:32 -07002249
Selim Cinekbbcebde2016-11-09 18:28:20 -08002250
2251 private NotificationViewState(StackScrollState stackScrollState) {
2252 mOverallState = stackScrollState;
2253 }
2254
2255 @Override
2256 public void applyToView(View view) {
2257 super.applyToView(view);
2258 if (view instanceof ExpandableNotificationRow) {
2259 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
Selim Cinekbbcebde2016-11-09 18:28:20 -08002260 row.applyChildrenState(mOverallState);
2261 }
2262 }
Selim Cinek0cfbef42016-11-09 19:06:36 -08002263
2264 @Override
Selim Cinek2b549f42016-11-22 16:38:51 -08002265 protected void onYTranslationAnimationFinished(View view) {
2266 super.onYTranslationAnimationFinished(view);
Selim Cinekd4776a52017-02-14 18:50:16 -08002267 if (view instanceof ExpandableNotificationRow) {
2268 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
2269 if (row.isHeadsUpAnimatingAway()) {
2270 row.setHeadsUpAnimatingAway(false);
2271 }
Selim Cinek0cfbef42016-11-09 19:06:36 -08002272 }
2273 }
2274
2275 @Override
2276 public void animateTo(View child, AnimationProperties properties) {
2277 super.animateTo(child, properties);
2278 if (child instanceof ExpandableNotificationRow) {
2279 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
2280 row.startChildAnimation(mOverallState, properties);
2281 }
2282 }
Selim Cinekbbcebde2016-11-09 18:28:20 -08002283 }
Selim Cinek817abe72017-05-24 11:08:55 -07002284
2285 @VisibleForTesting
2286 protected void setChildrenContainer(NotificationChildrenContainer childrenContainer) {
2287 mChildrenContainer = childrenContainer;
2288 }
Chris Wren51c75102013-07-16 20:49:17 -04002289}