blob: 7f2f5f62add6e3133a9f56f890db4c531edbd291 [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 Cinekc897bd32016-03-18 17:32:31 -070066import com.android.systemui.statusbar.notification.HybridNotificationView;
Selim Cinek1a48bab2017-02-17 19:38:40 -080067import com.android.systemui.statusbar.notification.NotificationInflater;
Selim Cinek6743c0b2017-01-18 18:24:01 -080068import com.android.systemui.statusbar.notification.NotificationUtils;
Selim Cineka7d4f822016-12-06 14:34:47 -080069import com.android.systemui.statusbar.notification.VisualStabilityManager;
Selim Cinekb5605e52015-02-20 18:21:41 +010070import com.android.systemui.statusbar.phone.NotificationGroupManager;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050071import com.android.systemui.statusbar.phone.StatusBar;
Selim Cinek31aada42015-12-18 17:51:15 -080072import com.android.systemui.statusbar.policy.HeadsUpManager;
Selim Cinek0cfbef42016-11-09 19:06:36 -080073import com.android.systemui.statusbar.stack.AnimationProperties;
74import com.android.systemui.statusbar.stack.ExpandableViewState;
Selim Cinekb5605e52015-02-20 18:21:41 +010075import com.android.systemui.statusbar.stack.NotificationChildrenContainer;
Selim Cineke9bad242016-06-15 11:46:37 -070076import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Selim Cinekb5605e52015-02-20 18:21:41 +010077import com.android.systemui.statusbar.stack.StackScrollState;
Selim Cinekb5605e52015-02-20 18:21:41 +010078
Mady Mellor4b80b102016-01-22 08:03:58 -080079import java.util.ArrayList;
Selim Cinekb5605e52015-02-20 18:21:41 +010080import java.util.List;
Dan Sandlera5e0f412014-01-23 15:11:54 -050081
Mady Mellor95d743c2017-01-10 12:05:27 -080082public class ExpandableNotificationRow extends ActivatableNotificationView
83 implements PluginListener<NotificationMenuRowPlugin> {
Selim Cinekb5605e52015-02-20 18:21:41 +010084
85 private static final int DEFAULT_DIVIDER_ALPHA = 0x29;
86 private static final int COLORED_DIVIDER_ALPHA = 0x7B;
Mady Mellor95d743c2017-01-10 12:05:27 -080087 private static final int MENU_VIEW_INDEX = 0;
88
Mady Mellor035badd2017-04-04 18:45:30 -070089 public interface LayoutListener {
90 public void onLayout();
91 }
92
93 private LayoutListener mLayoutListener;
Selim Cinek55a3e732017-05-25 18:30:10 -070094 private boolean mLowPriorityStateUpdated;
Selim Cinek1a48bab2017-02-17 19:38:40 -080095 private final NotificationInflater mNotificationInflater;
Selim Cinek0242fbb2016-10-19 13:38:32 -070096 private int mIconTransformContentShift;
Selim Cinek875a3a12016-11-18 17:52:16 -080097 private int mIconTransformContentShiftNoIcon;
Selim Cinek01af3342016-02-09 19:25:31 -080098 private int mNotificationMinHeightLegacy;
99 private int mMaxHeadsUpHeightLegacy;
100 private int mMaxHeadsUpHeight;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800101 private int mMaxHeadsUpHeightIncreased;
Selim Cinek01af3342016-02-09 19:25:31 -0800102 private int mNotificationMinHeight;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800103 private int mNotificationMinHeightLarge;
Selim Cinek01af3342016-02-09 19:25:31 -0800104 private int mNotificationMaxHeight;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800105 private int mNotificationAmbientHeight;
Mady Mellorb0a82462016-04-30 17:31:02 -0700106 private int mIncreasedPaddingBetweenElements;
Chris Wren51c75102013-07-16 20:49:17 -0400107
Selim Cinek1685e632014-04-08 02:27:49 +0200108 /** Does this row contain layouts that can adapt to row expansion */
Chris Wren51c75102013-07-16 20:49:17 -0400109 private boolean mExpandable;
Selim Cinek1685e632014-04-08 02:27:49 +0200110 /** Has the user actively changed the expansion state of this row */
111 private boolean mHasUserChangedExpansion;
112 /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */
Chris Wren51c75102013-07-16 20:49:17 -0400113 private boolean mUserExpanded;
Selim Cinek31aada42015-12-18 17:51:15 -0800114
115 /**
116 * Has this notification been expanded while it was pinned
117 */
118 private boolean mExpandedWhenPinned;
Selim Cinek1685e632014-04-08 02:27:49 +0200119 /** Is the user touching this row */
Chris Wren51c75102013-07-16 20:49:17 -0400120 private boolean mUserLocked;
Selim Cinek1685e632014-04-08 02:27:49 +0200121 /** Are we showing the "public" version */
Dan Sandlera5e0f412014-01-23 15:11:54 -0500122 private boolean mShowingPublic;
Jorim Jaggiae441282014-08-01 02:45:18 +0200123 private boolean mSensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -0800124 private boolean mSensitiveHiddenInGeneral;
Jorim Jaggiae441282014-08-01 02:45:18 +0200125 private boolean mShowingPublicInitialized;
Selim Cinek60122be2015-04-15 18:16:50 -0700126 private boolean mHideSensitiveForIntrinsicHeight;
Chris Wren51c75102013-07-16 20:49:17 -0400127
Selim Cinek1685e632014-04-08 02:27:49 +0200128 /**
129 * Is this notification expanded by the system. The expansion state can be overridden by the
130 * user expansion.
131 */
132 private boolean mIsSystemExpanded;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200133
134 /**
Selim Cinek83bc7832015-10-22 13:26:54 -0700135 * Whether the notification is on the keyguard and the expansion is disabled.
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200136 */
Selim Cinek83bc7832015-10-22 13:26:54 -0700137 private boolean mOnKeyguard;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200138
Mady Mellorb0a82462016-04-30 17:31:02 -0700139 private Animator mTranslateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -0800140 private ArrayList<View> mTranslateableViews;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200141 private NotificationContentView mPublicLayout;
142 private NotificationContentView mPrivateLayout;
Adrian Rooseb434ff2017-01-11 11:18:48 -0800143 private NotificationContentView[] mLayouts;
Selim Cinek1685e632014-04-08 02:27:49 +0200144 private int mMaxExpandHeight;
Selim Cinek8d490d42015-04-10 00:05:50 -0700145 private int mHeadsUpHeight;
Selim Cinek4bb59342016-04-08 19:29:35 -0700146 private int mNotificationColor;
Chris Wren78403d72014-07-28 10:23:24 +0100147 private ExpansionLogger mLogger;
148 private String mLoggingKey;
Selim Cinek8d490d42015-04-10 00:05:50 -0700149 private NotificationGuts mGuts;
Selim Cinekda42d652015-12-04 15:51:16 -0800150 private NotificationData.Entry mEntry;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200151 private StatusBarNotification mStatusBarNotification;
Mady Mellor3fd273e2016-03-15 21:08:14 -0700152 private String mAppName;
Selim Cinek1a521f32014-11-03 17:39:29 +0100153 private boolean mIsHeadsUp;
Selim Cinek98713a42015-09-21 15:47:20 +0200154 private boolean mLastChronometerRunning = true;
Selim Cinekb5605e52015-02-20 18:21:41 +0100155 private ViewStub mChildrenContainerStub;
156 private NotificationGroupManager mGroupManager;
Selim Cinekb5605e52015-02-20 18:21:41 +0100157 private boolean mChildrenExpanded;
Selim Cinek263398f2015-10-21 17:40:23 -0700158 private boolean mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100159 private NotificationChildrenContainer mChildrenContainer;
Mady Mellor95d743c2017-01-10 12:05:27 -0800160 private NotificationMenuRowPlugin mMenuRow;
Selim Cinekab29aeb2015-02-20 18:18:32 +0100161 private ViewStub mGutsStub;
Selim Cinekb5605e52015-02-20 18:21:41 +0100162 private boolean mIsSystemChildExpanded;
Selim Cinek684a4422015-04-15 16:18:39 -0700163 private boolean mIsPinned;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700164 private FalsingManager mFalsingManager;
Selim Cinek31aada42015-12-18 17:51:15 -0800165 private HeadsUpManager mHeadsUpManager;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200166
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700167 private boolean mJustClicked;
Selim Cinek5a175d92015-11-23 18:01:33 -0800168 private boolean mIconAnimationRunning;
Selim Cinek34d93b02015-10-22 12:30:38 -0700169 private boolean mShowNoBackground;
Selim Cinek388df6d2015-10-22 13:25:11 -0700170 private ExpandableNotificationRow mNotificationParent;
Selim Cinek570981d2015-12-01 11:37:01 -0800171 private OnExpandClickListener mOnExpandClickListener;
Mady Mellorb0a82462016-04-30 17:31:02 -0700172 private boolean mGroupExpansionChanging;
173
Anthony Chen6bf88a02017-04-10 14:41:44 -0700174 /**
175 * Whether or not a notification that is not part of a group of notifications can be manually
176 * expanded by the user.
177 */
178 private boolean mEnableNonGroupedNotificationExpand;
179
180 /**
181 * Whether or not to update the background of the header of the notification when its expanded.
182 * If {@code true}, the header background will disappear when expanded.
183 */
184 private boolean mShowGroupBackgroundWhenExpanded;
185
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800186 private OnClickListener mExpandClickListener = new OnClickListener() {
187 @Override
188 public void onClick(View v) {
Selim Cinek414ad332017-02-24 19:06:12 -0800189 if (!mShowingPublic && (!mIsLowPriority || isExpanded())
190 && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) {
Mady Mellor1a5d8ea2016-06-09 10:42:42 -0700191 mGroupExpansionChanging = true;
Chris Wren698b1702016-05-23 11:16:32 -0400192 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
193 boolean nowExpanded = mGroupManager.toggleGroupExpansion(mStatusBarNotification);
194 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400195 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_GROUP_EXPANDER,
196 nowExpanded);
Selim Cinek414ad332017-02-24 19:06:12 -0800197 onExpansionChanged(true /* userAction */, wasExpanded);
Anthony Chen6bf88a02017-04-10 14:41:44 -0700198 } else if (mEnableNonGroupedNotificationExpand) {
Selim Cineke9bad242016-06-15 11:46:37 -0700199 if (v.isAccessibilityFocused()) {
200 mPrivateLayout.setFocusOnVisibilityChange();
201 }
Selim Cinek31aada42015-12-18 17:51:15 -0800202 boolean nowExpanded;
203 if (isPinned()) {
204 nowExpanded = !mExpandedWhenPinned;
205 mExpandedWhenPinned = nowExpanded;
206 } else {
207 nowExpanded = !isExpanded();
208 setUserExpanded(nowExpanded);
209 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800210 notifyHeightChanged(true);
Selim Cinek31aada42015-12-18 17:51:15 -0800211 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400212 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_EXPANDER,
213 nowExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800214 }
215 }
216 };
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700217 private boolean mForceUnlocked;
Selim Cinek3f19f602016-05-02 18:01:56 -0700218 private boolean mDismissed;
219 private boolean mKeepInParent;
220 private boolean mRemoved;
Mady Mellorb0a82462016-04-30 17:31:02 -0700221 private static final Property<ExpandableNotificationRow, Float> TRANSLATE_CONTENT =
222 new FloatProperty<ExpandableNotificationRow>("translate") {
223 @Override
224 public void setValue(ExpandableNotificationRow object, float value) {
225 object.setTranslation(value);
226 }
227
228 @Override
229 public Float get(ExpandableNotificationRow object) {
230 return object.getTranslation();
231 }
232 };
Selim Cinekddf1b392016-05-27 16:33:10 -0700233 private OnClickListener mOnClickListener;
Selim Cinek73cf02a2016-06-17 13:08:00 -0700234 private boolean mHeadsupDisappearRunning;
Selim Cineke9bad242016-06-15 11:46:37 -0700235 private View mChildAfterViewWhenDismissed;
236 private View mGroupParentWhenDismissed;
237 private boolean mRefocusOnDismiss;
Selim Cinek2b549f42016-11-22 16:38:51 -0800238 private float mContentTransformationAmount;
Selim Cinek0242fbb2016-10-19 13:38:32 -0700239 private boolean mIconsVisible = true;
Selim Cinekd127d792016-11-01 19:11:41 -0700240 private boolean mAboveShelf;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800241 private boolean mShowAmbient;
Selim Cinek875a3a12016-11-18 17:52:16 -0800242 private boolean mIsLastChild;
Selim Cineke9079112016-12-14 14:41:01 -0800243 private Runnable mOnDismissRunnable;
Selim Cinek6743c0b2017-01-18 18:24:01 -0800244 private boolean mIsLowPriority;
Selim Cineka7ed2c12017-01-23 20:47:24 -0800245 private boolean mIsColorized;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800246 private boolean mUseIncreasedCollapsedHeight;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800247 private boolean mUseIncreasedHeadsUpHeight;
Selim Cinekef8c2252017-02-10 14:52:18 -0800248 private float mTranslationWhenRemoved;
249 private boolean mWasChildInGroupWhenRemoved;
Adrian Roos6f6e1592017-05-02 16:22:53 -0700250 private int mNotificationColorAmbient;
Mady Mellorb0a82462016-04-30 17:31:02 -0700251
Mady Mellor43c2cd12016-12-12 21:05:13 -0800252 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -0700253 public boolean isGroupExpansionChanging() {
254 if (isChildInGroup()) {
255 return mNotificationParent.isGroupExpansionChanging();
256 }
257 return mGroupExpansionChanging;
258 }
259
260 public void setGroupExpansionChanging(boolean changing) {
261 mGroupExpansionChanging = changing;
262 }
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700263
Adrian Roos599be342016-06-13 14:54:39 -0700264 @Override
265 public void setActualHeightAnimating(boolean animating) {
266 if (mPrivateLayout != null) {
267 mPrivateLayout.setContentHeightAnimating(animating);
268 }
269 }
270
Selim Cinek8d490d42015-04-10 00:05:50 -0700271 public NotificationContentView getPrivateLayout() {
272 return mPrivateLayout;
273 }
274
275 public NotificationContentView getPublicLayout() {
276 return mPublicLayout;
277 }
278
Selim Cinekcab4a602014-09-03 14:47:57 +0200279 public void setIconAnimationRunning(boolean running) {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800280 for (NotificationContentView l : mLayouts) {
281 setIconAnimationRunning(running, l);
282 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800283 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700284 setIconAnimationRunningForChild(running, mChildrenContainer.getHeaderView());
Selim Cinek414ad332017-02-24 19:06:12 -0800285 setIconAnimationRunningForChild(running, mChildrenContainer.getLowPriorityHeaderView());
Selim Cinek5a175d92015-11-23 18:01:33 -0800286 List<ExpandableNotificationRow> notificationChildren =
287 mChildrenContainer.getNotificationChildren();
288 for (int i = 0; i < notificationChildren.size(); i++) {
289 ExpandableNotificationRow child = notificationChildren.get(i);
290 child.setIconAnimationRunning(running);
291 }
292 }
293 mIconAnimationRunning = running;
Selim Cinekcab4a602014-09-03 14:47:57 +0200294 }
295
296 private void setIconAnimationRunning(boolean running, NotificationContentView layout) {
297 if (layout != null) {
298 View contractedChild = layout.getContractedChild();
299 View expandedChild = layout.getExpandedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -0700300 View headsUpChild = layout.getHeadsUpChild();
Selim Cinekcab4a602014-09-03 14:47:57 +0200301 setIconAnimationRunningForChild(running, contractedChild);
302 setIconAnimationRunningForChild(running, expandedChild);
Selim Cinek8d490d42015-04-10 00:05:50 -0700303 setIconAnimationRunningForChild(running, headsUpChild);
Selim Cinekcab4a602014-09-03 14:47:57 +0200304 }
305 }
306
307 private void setIconAnimationRunningForChild(boolean running, View child) {
308 if (child != null) {
309 ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon);
310 setIconRunning(icon, running);
311 ImageView rightIcon = (ImageView) child.findViewById(
312 com.android.internal.R.id.right_icon);
313 setIconRunning(rightIcon, running);
314 }
315 }
316
317 private void setIconRunning(ImageView imageView, boolean running) {
318 if (imageView != null) {
319 Drawable drawable = imageView.getDrawable();
320 if (drawable instanceof AnimationDrawable) {
321 AnimationDrawable animationDrawable = (AnimationDrawable) drawable;
322 if (running) {
323 animationDrawable.start();
324 } else {
325 animationDrawable.stop();
326 }
327 } else if (drawable instanceof AnimatedVectorDrawable) {
328 AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable;
329 if (running) {
330 animationDrawable.start();
331 } else {
332 animationDrawable.stop();
333 }
334 }
335 }
336 }
337
Selim Cinek5ba22542017-04-20 15:16:10 -0700338 public void updateNotification(NotificationData.Entry entry) {
Selim Cinekda42d652015-12-04 15:51:16 -0800339 mEntry = entry;
340 mStatusBarNotification = entry.notification;
Selim Cinek1a48bab2017-02-17 19:38:40 -0800341 mNotificationInflater.inflateNotificationViews();
Selim Cinekc478f902017-02-22 20:55:44 -0800342 }
343
Selim Cinek5ba22542017-04-20 15:16:10 -0700344 public void onNotificationUpdated() {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800345 for (NotificationContentView l : mLayouts) {
Selim Cinekc478f902017-02-22 20:55:44 -0800346 l.onNotificationUpdated(mEntry);
Adrian Rooseb434ff2017-01-11 11:18:48 -0800347 }
Selim Cineka7ed2c12017-01-23 20:47:24 -0800348 mIsColorized = mStatusBarNotification.getNotification().isColorized();
Selim Cinek757d8792016-01-28 16:21:08 -0800349 mShowingPublicInitialized = false;
Selim Cinek4bb59342016-04-08 19:29:35 -0700350 updateNotificationColor();
Mady Mellor4c197602017-04-10 17:57:52 -0700351 if (mMenuRow != null) {
352 mMenuRow.onNotificationUpdated();
353 }
Selim Cinek8fc93c92015-11-23 17:48:07 -0800354 if (mIsSummaryWithChildren) {
Selim Cinek414ad332017-02-24 19:06:12 -0800355 mChildrenContainer.recreateNotificationHeader(mExpandClickListener);
Selim Cinekc897bd32016-03-18 17:32:31 -0700356 mChildrenContainer.onNotificationUpdated();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800357 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800358 if (mIconAnimationRunning) {
359 setIconAnimationRunning(true);
360 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800361 if (mNotificationParent != null) {
362 mNotificationParent.updateChildrenHeaderAppearance();
363 }
Selim Cinek263398f2015-10-21 17:40:23 -0700364 onChildrenCountChanged();
Selim Cinek624c02db2015-12-14 21:00:02 -0800365 // The public layouts expand button is always visible
366 mPublicLayout.updateExpandButtons(true);
Selim Cinekda42d652015-12-04 15:51:16 -0800367 updateLimits();
Selim Cinek0242fbb2016-10-19 13:38:32 -0700368 updateIconVisibilities();
Selim Cinek6743c0b2017-01-18 18:24:01 -0800369 updateShelfIconColor();
370 }
371
372 private void updateShelfIconColor() {
373 StatusBarIconView expandedIcon = mEntry.expandedIcon;
374 boolean isPreL = Boolean.TRUE.equals(expandedIcon.getTag(R.id.icon_is_pre_L));
375 boolean colorize = !isPreL || NotificationUtils.isGrayscale(expandedIcon,
376 NotificationColorUtil.getInstance(mContext));
Selim Cinek875ba9b2017-02-13 16:20:17 -0800377 int color = StatusBarIconView.NO_COLOR;
Selim Cinek6743c0b2017-01-18 18:24:01 -0800378 if (colorize) {
Selim Cinekac5f0272017-05-02 16:05:41 -0700379 color = mEntry.getContrastedColor(mContext, mIsLowPriority && !isExpanded(),
380 getBackgroundColorWithoutTint());
Selim Cinek6743c0b2017-01-18 18:24:01 -0800381 }
Selim Cinek875ba9b2017-02-13 16:20:17 -0800382 expandedIcon.setStaticDrawableColor(color);
Selim Cinekda42d652015-12-04 15:51:16 -0800383 }
384
Selim Cinek4705f292017-04-24 22:18:48 -0700385 @Override
386 public boolean isDimmable() {
387 if (!getShowingLayout().isDimmable()) {
388 return false;
389 }
390 return super.isDimmable();
391 }
392
Selim Cinekda42d652015-12-04 15:51:16 -0800393 private void updateLimits() {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800394 for (NotificationContentView l : mLayouts) {
395 updateLimitsForView(l);
396 }
Selim Cineka1744872016-03-11 15:36:06 -0800397 }
398
399 private void updateLimitsForView(NotificationContentView layout) {
400 boolean customView = layout.getContractedChild().getId()
Selim Cinekda42d652015-12-04 15:51:16 -0800401 != com.android.internal.R.id.status_bar_latest_event_content;
402 boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800403 int minHeight;
404 if (customView && beforeN && !mIsSummaryWithChildren) {
405 minHeight = mNotificationMinHeightLegacy;
406 } else if (mUseIncreasedCollapsedHeight && layout == mPrivateLayout) {
407 minHeight = mNotificationMinHeightLarge;
408 } else {
409 minHeight = mNotificationMinHeight;
410 }
Selim Cineka1744872016-03-11 15:36:06 -0800411 boolean headsUpCustom = layout.getHeadsUpChild() != null &&
412 layout.getHeadsUpChild().getId()
413 != com.android.internal.R.id.status_bar_latest_event_content;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800414 int headsUpheight;
415 if (headsUpCustom && beforeN) {
416 headsUpheight = mMaxHeadsUpHeightLegacy;
417 } else if (mUseIncreasedHeadsUpHeight && layout == mPrivateLayout) {
418 headsUpheight = mMaxHeadsUpHeightIncreased;
419 } else {
420 headsUpheight = mMaxHeadsUpHeight;
421 }
Adrian Roos0aac04f2016-12-08 15:59:29 -0800422 layout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight,
423 mNotificationAmbientHeight);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200424 }
425
426 public StatusBarNotification getStatusBarNotification() {
427 return mStatusBarNotification;
428 }
429
Selim Cinek281c2022016-10-13 19:14:43 -0700430 public NotificationData.Entry getEntry() {
431 return mEntry;
432 }
433
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700434 public boolean isHeadsUp() {
435 return mIsHeadsUp;
436 }
437
Selim Cinek1a521f32014-11-03 17:39:29 +0100438 public void setHeadsUp(boolean isHeadsUp) {
Selim Cinekc80fdb12015-04-13 15:09:08 -0700439 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek1a521f32014-11-03 17:39:29 +0100440 mIsHeadsUp = isHeadsUp;
Selim Cinek8d490d42015-04-10 00:05:50 -0700441 mPrivateLayout.setHeadsUp(isHeadsUp);
Selim Cinekb41b2f62016-04-26 14:03:29 -0700442 if (mIsSummaryWithChildren) {
443 // The overflow might change since we allow more lines as HUN.
444 mChildrenContainer.updateGroupOverflow();
445 }
Selim Cinekc80fdb12015-04-13 15:09:08 -0700446 if (intrinsicBefore != getIntrinsicHeight()) {
447 notifyHeightChanged(false /* needsAnimation */);
448 }
Selim Cinekd127d792016-11-01 19:11:41 -0700449 if (isHeadsUp) {
450 setAboveShelf(true);
451 }
Selim Cinek1a521f32014-11-03 17:39:29 +0100452 }
453
Selim Cinekb5605e52015-02-20 18:21:41 +0100454 public void setGroupManager(NotificationGroupManager groupManager) {
455 mGroupManager = groupManager;
Selim Cinek83bc7832015-10-22 13:26:54 -0700456 mPrivateLayout.setGroupManager(groupManager);
Selim Cinekb5605e52015-02-20 18:21:41 +0100457 }
458
Adrian Roosb88b1a12015-12-09 18:51:05 -0800459 public void setRemoteInputController(RemoteInputController r) {
460 mPrivateLayout.setRemoteInputController(r);
461 }
462
Mady Mellor3fd273e2016-03-15 21:08:14 -0700463 public void setAppName(String appName) {
464 mAppName = appName;
Mady Mellor95d743c2017-01-10 12:05:27 -0800465 if (mMenuRow != null && mMenuRow.getMenuView() != null) {
Mady Mellor761cde12017-01-10 11:36:39 -0800466 mMenuRow.setAppName(mAppName);
Mady Mellor3fd273e2016-03-15 21:08:14 -0700467 }
468 }
469
Selim Cinekb5605e52015-02-20 18:21:41 +0100470 public void addChildNotification(ExpandableNotificationRow row) {
471 addChildNotification(row, -1);
472 }
473
474 /**
475 * Add a child notification to this view.
476 *
477 * @param row the row to add
478 * @param childIndex the index to add it at, if -1 it will be added at the end
479 */
480 public void addChildNotification(ExpandableNotificationRow row, int childIndex) {
481 if (mChildrenContainer == null) {
482 mChildrenContainerStub.inflate();
483 }
484 mChildrenContainer.addNotification(row, childIndex);
Selim Cinek263398f2015-10-21 17:40:23 -0700485 onChildrenCountChanged();
486 row.setIsChildInGroup(true, this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100487 }
488
489 public void removeChildNotification(ExpandableNotificationRow row) {
490 if (mChildrenContainer != null) {
491 mChildrenContainer.removeNotification(row);
492 }
Selim Cinek263398f2015-10-21 17:40:23 -0700493 onChildrenCountChanged();
494 row.setIsChildInGroup(false, null);
495 }
496
Mady Mellor43c2cd12016-12-12 21:05:13 -0800497 @Override
Selim Cinek263398f2015-10-21 17:40:23 -0700498 public boolean isChildInGroup() {
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700499 return mNotificationParent != null;
Selim Cinek263398f2015-10-21 17:40:23 -0700500 }
501
Selim Cinek388df6d2015-10-22 13:25:11 -0700502 public ExpandableNotificationRow getNotificationParent() {
503 return mNotificationParent;
504 }
505
Selim Cinek263398f2015-10-21 17:40:23 -0700506 /**
507 * @param isChildInGroup Is this notification now in a group
508 * @param parent the new parent notification
509 */
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700510 public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500511 boolean childInGroup = StatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup;
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700512 mNotificationParent = childInGroup ? parent : null;
513 mPrivateLayout.setIsChildInGroup(childInGroup);
Selim Cinek5ba22542017-04-20 15:16:10 -0700514 mNotificationInflater.setIsChildInGroup(childInGroup);
Mady Mellorc7d65b42016-05-04 11:44:57 -0400515 resetBackgroundAlpha();
Mady Mellorb0a82462016-04-30 17:31:02 -0700516 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -0700517 updateClickAndFocus();
Mady Mellorb0a82462016-04-30 17:31:02 -0700518 if (mNotificationParent != null) {
Selim Cinek9ce32852017-02-15 16:21:10 -0800519 setOverrideTintColor(NO_COLOR, 0.0f);
Mady Mellorb0a82462016-04-30 17:31:02 -0700520 mNotificationParent.updateBackgroundForGroupState();
521 }
Selim Cinekdb167372016-11-17 15:41:17 -0800522 updateIconVisibilities();
Selim Cinek34d93b02015-10-22 12:30:38 -0700523 }
524
525 @Override
Selim Cinek72109472016-01-15 16:33:22 -0800526 public boolean onTouchEvent(MotionEvent event) {
527 if (event.getActionMasked() != MotionEvent.ACTION_DOWN
528 || !isChildInGroup() || isGroupExpanded()) {
529 return super.onTouchEvent(event);
530 } else {
531 return false;
532 }
533 }
534
535 @Override
Mady Mellorf0625802016-02-11 18:03:48 -0800536 protected boolean handleSlideBack() {
Mady Mellor95d743c2017-01-10 12:05:27 -0800537 if (mMenuRow != null && mMenuRow.isMenuVisible()) {
Mady Mellorf0625802016-02-11 18:03:48 -0800538 animateTranslateNotification(0 /* targetLeft */);
539 return true;
540 }
541 return false;
542 }
543
544 @Override
Selim Cinek34d93b02015-10-22 12:30:38 -0700545 protected boolean shouldHideBackground() {
546 return super.shouldHideBackground() || mShowNoBackground;
Selim Cinek263398f2015-10-21 17:40:23 -0700547 }
548
549 @Override
550 public boolean isSummaryWithChildren() {
551 return mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100552 }
553
554 @Override
555 public boolean areChildrenExpanded() {
556 return mChildrenExpanded;
557 }
558
559 public List<ExpandableNotificationRow> getNotificationChildren() {
560 return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren();
561 }
562
Selim Cinekeef84282015-10-30 16:28:00 -0700563 public int getNumberOfNotificationChildren() {
564 if (mChildrenContainer == null) {
565 return 0;
566 }
567 return mChildrenContainer.getNotificationChildren().size();
568 }
569
Selim Cinekb5605e52015-02-20 18:21:41 +0100570 /**
571 * Apply the order given in the list to the children.
572 *
573 * @param childOrder the new list order
Selim Cineka7d4f822016-12-06 14:34:47 -0800574 * @param visualStabilityManager
575 * @param callback the callback to invoked in case it is not allowed
Selim Cinekb5605e52015-02-20 18:21:41 +0100576 * @return whether the list order has changed
577 */
Selim Cineka7d4f822016-12-06 14:34:47 -0800578 public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder,
579 VisualStabilityManager visualStabilityManager,
580 VisualStabilityManager.Callback callback) {
581 return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder,
582 visualStabilityManager, callback);
Selim Cinekb5605e52015-02-20 18:21:41 +0100583 }
584
585 public void getChildrenStates(StackScrollState resultState) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700586 if (mIsSummaryWithChildren) {
Selim Cinekbbcebde2016-11-09 18:28:20 -0800587 ExpandableViewState parentState = resultState.getViewStateForView(this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100588 mChildrenContainer.getState(resultState, parentState);
589 }
590 }
591
592 public void applyChildrenState(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700593 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100594 mChildrenContainer.applyState(state);
595 }
596 }
597
598 public void prepareExpansionChanged(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700599 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100600 mChildrenContainer.prepareExpansionChanged(state);
601 }
602 }
603
Selim Cinek0cfbef42016-11-09 19:06:36 -0800604 public void startChildAnimation(StackScrollState finalState, AnimationProperties properties) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700605 if (mIsSummaryWithChildren) {
Selim Cinek0cfbef42016-11-09 19:06:36 -0800606 mChildrenContainer.startAnimationToState(finalState, properties);
Selim Cinekb5605e52015-02-20 18:21:41 +0100607 }
608 }
609
610 public ExpandableNotificationRow getViewAtPosition(float y) {
Selim Cinek43d30f02016-03-04 10:51:32 -0800611 if (!mIsSummaryWithChildren || !mChildrenExpanded) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100612 return this;
613 } else {
614 ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y);
615 return view == null ? this : view;
616 }
617 }
618
Selim Cinekab29aeb2015-02-20 18:18:32 +0100619 public NotificationGuts getGuts() {
620 return mGuts;
621 }
622
Selim Cinek684a4422015-04-15 16:18:39 -0700623 /**
624 * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this
625 * the notification will be rendered on top of the screen.
626 *
627 * @param pinned whether it is pinned
628 */
629 public void setPinned(boolean pinned) {
Selim Cinekdef35a82016-05-03 15:52:51 -0700630 int intrinsicHeight = getIntrinsicHeight();
Selim Cinek684a4422015-04-15 16:18:39 -0700631 mIsPinned = pinned;
Selim Cinekdef35a82016-05-03 15:52:51 -0700632 if (intrinsicHeight != getIntrinsicHeight()) {
Selim Cinekbb42b7d2016-08-10 13:02:38 -0700633 notifyHeightChanged(false /* needsAnimation */);
Selim Cinekdef35a82016-05-03 15:52:51 -0700634 }
Selim Cinek31aada42015-12-18 17:51:15 -0800635 if (pinned) {
636 setIconAnimationRunning(true);
637 mExpandedWhenPinned = false;
638 } else if (mExpandedWhenPinned) {
639 setUserExpanded(true);
640 }
Selim Cinek98713a42015-09-21 15:47:20 +0200641 setChronometerRunning(mLastChronometerRunning);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700642 }
643
Selim Cinek684a4422015-04-15 16:18:39 -0700644 public boolean isPinned() {
645 return mIsPinned;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700646 }
647
Selim Cinekd127d792016-11-01 19:11:41 -0700648 @Override
649 public int getPinnedHeadsUpHeight() {
650 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
651 }
652
Selim Cinek31aada42015-12-18 17:51:15 -0800653 /**
654 * @param atLeastMinHeight should the value returned be at least the minimum height.
655 * Used to avoid cyclic calls
656 * @return the height of the heads up notification when pinned
657 */
Selim Cinekd127d792016-11-01 19:11:41 -0700658 private int getPinnedHeadsUpHeight(boolean atLeastMinHeight) {
Selim Cinek77019c72015-12-09 10:18:02 -0800659 if (mIsSummaryWithChildren) {
660 return mChildrenContainer.getIntrinsicHeight();
661 }
Selim Cinek31aada42015-12-18 17:51:15 -0800662 if(mExpandedWhenPinned) {
663 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
664 } else if (atLeastMinHeight) {
Selim Cinek567e8452016-03-24 10:54:56 -0700665 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek31aada42015-12-18 17:51:15 -0800666 } else {
667 return mHeadsUpHeight;
668 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700669 }
670
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700671 /**
672 * Mark whether this notification was just clicked, i.e. the user has just clicked this
673 * notification in this frame.
674 */
675 public void setJustClicked(boolean justClicked) {
676 mJustClicked = justClicked;
677 }
678
679 /**
680 * @return true if this notification has been clicked in this frame, false otherwise
681 */
682 public boolean wasJustClicked() {
683 return mJustClicked;
684 }
685
Selim Cinek98713a42015-09-21 15:47:20 +0200686 public void setChronometerRunning(boolean running) {
687 mLastChronometerRunning = running;
688 setChronometerRunning(running, mPrivateLayout);
689 setChronometerRunning(running, mPublicLayout);
690 if (mChildrenContainer != null) {
691 List<ExpandableNotificationRow> notificationChildren =
692 mChildrenContainer.getNotificationChildren();
693 for (int i = 0; i < notificationChildren.size(); i++) {
694 ExpandableNotificationRow child = notificationChildren.get(i);
695 child.setChronometerRunning(running);
696 }
697 }
698 }
699
700 private void setChronometerRunning(boolean running, NotificationContentView layout) {
701 if (layout != null) {
702 running = running || isPinned();
703 View contractedChild = layout.getContractedChild();
704 View expandedChild = layout.getExpandedChild();
705 View headsUpChild = layout.getHeadsUpChild();
706 setChronometerRunningForChild(running, contractedChild);
707 setChronometerRunningForChild(running, expandedChild);
708 setChronometerRunningForChild(running, headsUpChild);
709 }
710 }
711
712 private void setChronometerRunningForChild(boolean running, View child) {
713 if (child != null) {
714 View chronometer = child.findViewById(com.android.internal.R.id.chronometer);
715 if (chronometer instanceof Chronometer) {
716 ((Chronometer) chronometer).setStarted(running);
717 }
718 }
719 }
720
Selim Cinekea4bef72015-12-02 15:51:10 -0800721 public NotificationHeaderView getNotificationHeader() {
Mady Mellorb0a82462016-04-30 17:31:02 -0700722 if (mIsSummaryWithChildren) {
723 return mChildrenContainer.getHeaderView();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700724 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800725 return mPrivateLayout.getNotificationHeader();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700726 }
727
Selim Cinek414ad332017-02-24 19:06:12 -0800728 /**
729 * @return the currently visible notification header. This can be different from
730 * {@link #getNotificationHeader()} in case it is a low-priority group.
731 */
732 public NotificationHeaderView getVisibleNotificationHeader() {
Selim Cinekaa3901a2016-08-05 11:04:37 -0700733 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinek414ad332017-02-24 19:06:12 -0800734 return mChildrenContainer.getVisibleHeader();
Selim Cinek34eda5e2016-02-18 17:10:43 -0800735 }
736 return getShowingLayout().getVisibleNotificationHeader();
737 }
738
Selim Cinek570981d2015-12-01 11:37:01 -0800739 public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) {
740 mOnExpandClickListener = onExpandClickListener;
741 }
742
Selim Cinekddf1b392016-05-27 16:33:10 -0700743 @Override
744 public void setOnClickListener(@Nullable OnClickListener l) {
745 super.setOnClickListener(l);
746 mOnClickListener = l;
747 updateClickAndFocus();
748 }
749
750 private void updateClickAndFocus() {
751 boolean normalChild = !isChildInGroup() || isGroupExpanded();
752 boolean clickable = mOnClickListener != null && normalChild;
753 if (isFocusable() != normalChild) {
754 setFocusable(normalChild);
755 }
756 if (isClickable() != clickable) {
757 setClickable(clickable);
758 }
759 }
760
Selim Cinek31aada42015-12-18 17:51:15 -0800761 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
762 mHeadsUpManager = headsUpManager;
763 }
764
Mady Mellor87d79452017-01-10 11:52:52 -0800765 public void setGutsView(MenuItem item) {
Mady Mellor95d743c2017-01-10 12:05:27 -0800766 if (mGuts != null && item.getGutsView() instanceof GutsContent) {
767 ((GutsContent) item.getGutsView()).setGutsParent(mGuts);
768 mGuts.setGutsContent((GutsContent) item.getGutsView());
Mady Mellor87d79452017-01-10 11:52:52 -0800769 }
770 }
771
Mady Mellor95d743c2017-01-10 12:05:27 -0800772 @Override
773 protected void onAttachedToWindow() {
774 super.onAttachedToWindow();
775 Dependency.get(PluginManager.class).addPluginListener(this,
776 NotificationMenuRowPlugin.class, false /* Allow multiple */);
777 }
778
779 @Override
780 protected void onDetachedFromWindow() {
781 super.onDetachedFromWindow();
782 Dependency.get(PluginManager.class).removePluginListener(this);
783 }
784
785 @Override
786 public void onPluginConnected(NotificationMenuRowPlugin plugin, Context pluginContext) {
787 boolean existed = mMenuRow.getMenuView() != null;
788 if (existed) {
789 removeView(mMenuRow.getMenuView());
790 }
791 mMenuRow = plugin;
792 if (mMenuRow.useDefaultMenuItems()) {
Mady Mellor4c197602017-04-10 17:57:52 -0700793 ArrayList<MenuItem> items = new ArrayList<>();
794 items.add(NotificationMenuRow.createInfoItem(mContext));
795 items.add(NotificationMenuRow.createSnoozeItem(mContext));
796 mMenuRow.setMenuItems(items);
Mady Mellor95d743c2017-01-10 12:05:27 -0800797 }
798 if (existed) {
799 createMenu();
800 }
801 }
802
803 @Override
804 public void onPluginDisconnected(NotificationMenuRowPlugin plugin) {
805 boolean existed = mMenuRow.getMenuView() != null;
806 mMenuRow = new NotificationMenuRow(mContext); // Back to default
807 if (existed) {
808 createMenu();
809 }
810 }
811
812 public NotificationMenuRowPlugin createMenu() {
813 if (mMenuRow.getMenuView() == null) {
814 mMenuRow.createMenu(this);
815 mMenuRow.setAppName(mAppName);
816 FrameLayout.LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
817 LayoutParams.MATCH_PARENT);
818 addView(mMenuRow.getMenuView(), MENU_VIEW_INDEX, lp);
819 }
820 return mMenuRow;
821 }
822
Mady Mellor95d743c2017-01-10 12:05:27 -0800823 public NotificationMenuRowPlugin getProvider() {
824 return mMenuRow;
825 }
826
Anthony Chen9fe1ee72017-04-07 13:53:37 -0700827 @Override
Selim Cinek1a48bab2017-02-17 19:38:40 -0800828 public void onDensityOrFontScaleChanged() {
Anthony Chen9fe1ee72017-04-07 13:53:37 -0700829 super.onDensityOrFontScaleChanged();
Selim Cinek01af3342016-02-09 19:25:31 -0800830 initDimens();
Selim Cinek817abe72017-05-24 11:08:55 -0700831 // Let's update our childrencontainer. This is intentionally not guarded with
832 // mIsSummaryWithChildren since we might have had children but not anymore.
833 if (mChildrenContainer != null) {
834 mChildrenContainer.reInflateViews(mExpandClickListener, mEntry.notification);
Selim Cinek01af3342016-02-09 19:25:31 -0800835 }
836 if (mGuts != null) {
837 View oldGuts = mGuts;
838 int index = indexOfChild(oldGuts);
839 removeView(oldGuts);
840 mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate(
841 R.layout.notification_guts, this, false);
842 mGuts.setVisibility(oldGuts.getVisibility());
843 addView(mGuts, index);
844 }
Mady Mellor95d743c2017-01-10 12:05:27 -0800845 View oldMenu = mMenuRow.getMenuView();
846 if (oldMenu != null) {
Mady Mellor761cde12017-01-10 11:36:39 -0800847 int menuIndex = indexOfChild(oldMenu);
848 removeView(oldMenu);
Mady Mellor95d743c2017-01-10 12:05:27 -0800849 mMenuRow.createMenu(ExpandableNotificationRow.this);
Mady Mellor761cde12017-01-10 11:36:39 -0800850 mMenuRow.setAppName(mAppName);
Mady Mellor95d743c2017-01-10 12:05:27 -0800851 addView(mMenuRow.getMenuView(), menuIndex);
Mady Mellor4b80b102016-01-22 08:03:58 -0800852 }
Adrian Rooseb434ff2017-01-11 11:18:48 -0800853 for (NotificationContentView l : mLayouts) {
854 l.reInflateViews();
855 }
Selim Cinek1a48bab2017-02-17 19:38:40 -0800856 mNotificationInflater.onDensityOrFontScaleChanged();
857 onNotificationUpdated();
Selim Cinek01af3342016-02-09 19:25:31 -0800858 }
859
Mady Mellor9d03a522017-04-04 18:45:30 -0700860 @Override
861 public void onConfigurationChanged(Configuration newConfig) {
862 if (mMenuRow.getMenuView() != null) {
863 mMenuRow.onConfigurationChanged();
864 }
865 }
866
Selim Cinekc3179332016-03-04 14:44:56 -0800867 public void setContentBackground(int customBackgroundColor, boolean animate,
868 NotificationContentView notificationContentView) {
869 if (getShowingLayout() == notificationContentView) {
870 setTintColor(customBackgroundColor, animate);
871 }
872 }
873
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700874 public void closeRemoteInput() {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800875 for (NotificationContentView l : mLayouts) {
876 l.closeRemoteInput();
877 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700878 }
879
Selim Cinekc897bd32016-03-18 17:32:31 -0700880 /**
881 * Set by how much the single line view should be indented.
882 */
883 public void setSingleLineWidthIndention(int indention) {
884 mPrivateLayout.setSingleLineWidthIndention(indention);
885 }
886
887 public int getNotificationColor() {
Selim Cinek4bb59342016-04-08 19:29:35 -0700888 return mNotificationColor;
889 }
890
891 private void updateNotificationColor() {
892 mNotificationColor = NotificationColorUtil.resolveContrastColor(mContext,
Selim Cinekac5f0272017-05-02 16:05:41 -0700893 getStatusBarNotification().getNotification().color,
894 getBackgroundColorWithoutTint());
Adrian Roos6f6e1592017-05-02 16:22:53 -0700895 mNotificationColorAmbient = NotificationColorUtil.resolveAmbientColor(mContext,
896 getStatusBarNotification().getNotification().color);
Selim Cinekc897bd32016-03-18 17:32:31 -0700897 }
898
899 public HybridNotificationView getSingleLineView() {
900 return mPrivateLayout.getSingleLineView();
901 }
902
Adrian Roos6f6e1592017-05-02 16:22:53 -0700903 public HybridNotificationView getAmbientSingleLineView() {
904 return getShowingLayout().getAmbientSingleLineChild();
905 }
906
Selim Cinekf07d0622016-03-21 19:52:52 -0700907 public boolean isOnKeyguard() {
908 return mOnKeyguard;
909 }
910
Selim Cinekc1e389d2016-04-07 11:02:57 -0700911 public void removeAllChildren() {
912 List<ExpandableNotificationRow> notificationChildren
913 = mChildrenContainer.getNotificationChildren();
914 ArrayList<ExpandableNotificationRow> clonedList = new ArrayList<>(notificationChildren);
915 for (int i = 0; i < clonedList.size(); i++) {
916 ExpandableNotificationRow row = clonedList.get(i);
Selim Cinek3f19f602016-05-02 18:01:56 -0700917 if (row.keepInParent()) {
918 continue;
919 }
Selim Cinekc1e389d2016-04-07 11:02:57 -0700920 mChildrenContainer.removeNotification(row);
Selim Cinekc1e389d2016-04-07 11:02:57 -0700921 row.setIsChildInGroup(false, null);
922 }
923 onChildrenCountChanged();
924 }
925
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700926 public void setForceUnlocked(boolean forceUnlocked) {
927 mForceUnlocked = forceUnlocked;
928 if (mIsSummaryWithChildren) {
929 List<ExpandableNotificationRow> notificationChildren = getNotificationChildren();
930 for (ExpandableNotificationRow child : notificationChildren) {
931 child.setForceUnlocked(forceUnlocked);
932 }
933 }
934 }
935
Selim Cineke9bad242016-06-15 11:46:37 -0700936 public void setDismissed(boolean dismissed, boolean fromAccessibility) {
Selim Cinek3f19f602016-05-02 18:01:56 -0700937 mDismissed = dismissed;
Selim Cineke9bad242016-06-15 11:46:37 -0700938 mGroupParentWhenDismissed = mNotificationParent;
939 mRefocusOnDismiss = fromAccessibility;
940 mChildAfterViewWhenDismissed = null;
941 if (isChildInGroup()) {
942 List<ExpandableNotificationRow> notificationChildren =
943 mNotificationParent.getNotificationChildren();
944 int i = notificationChildren.indexOf(this);
945 if (i != -1 && i < notificationChildren.size() - 1) {
946 mChildAfterViewWhenDismissed = notificationChildren.get(i + 1);
947 }
948 }
Selim Cinek3f19f602016-05-02 18:01:56 -0700949 }
950
951 public boolean isDismissed() {
952 return mDismissed;
953 }
954
955 public boolean keepInParent() {
956 return mKeepInParent;
957 }
958
959 public void setKeepInParent(boolean keepInParent) {
960 mKeepInParent = keepInParent;
961 }
962
963 public boolean isRemoved() {
964 return mRemoved;
965 }
966
Adrian Roosd009ab12016-05-20 17:58:53 -0700967 public void setRemoved() {
968 mRemoved = true;
Selim Cinekef8c2252017-02-10 14:52:18 -0800969 mTranslationWhenRemoved = getTranslationY();
970 mWasChildInGroupWhenRemoved = isChildInGroup();
971 if (isChildInGroup()) {
972 mTranslationWhenRemoved += getNotificationParent().getTranslationY();
973 }
Adrian Roosd009ab12016-05-20 17:58:53 -0700974 mPrivateLayout.setRemoved();
Selim Cinek3f19f602016-05-02 18:01:56 -0700975 }
976
Selim Cinekef8c2252017-02-10 14:52:18 -0800977 public boolean wasChildInGroupWhenRemoved() {
978 return mWasChildInGroupWhenRemoved;
979 }
980
981 public float getTranslationWhenRemoved() {
982 return mTranslationWhenRemoved;
983 }
984
Selim Cinekd1395642016-04-28 12:22:42 -0700985 public NotificationChildrenContainer getChildrenContainer() {
986 return mChildrenContainer;
987 }
988
Selim Cinekcafa87f2016-10-26 17:00:17 -0700989 public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) {
990 mHeadsupDisappearRunning = headsUpAnimatingAway;
991 mPrivateLayout.setHeadsUpAnimatingAway(headsUpAnimatingAway);
992 }
993
994 /**
995 * @return if the view was just heads upped and is now animating away. During such a time the
996 * layout needs to be kept consistent
997 */
998 public boolean isHeadsUpAnimatingAway() {
999 return mHeadsupDisappearRunning;
Selim Cinek73cf02a2016-06-17 13:08:00 -07001000 }
1001
Selim Cineke9bad242016-06-15 11:46:37 -07001002 public View getChildAfterViewWhenDismissed() {
1003 return mChildAfterViewWhenDismissed;
1004 }
1005
1006 public View getGroupParentWhenDismissed() {
1007 return mGroupParentWhenDismissed;
1008 }
1009
Selim Cinek9e624e72016-07-20 13:46:49 -07001010 public void performDismiss() {
Selim Cineke9079112016-12-14 14:41:01 -08001011 if (mOnDismissRunnable != null) {
1012 mOnDismissRunnable.run();
1013 }
Selim Cinek9e624e72016-07-20 13:46:49 -07001014 }
1015
Selim Cineke9079112016-12-14 14:41:01 -08001016 public void setOnDismissRunnable(Runnable onDismissRunnable) {
1017 mOnDismissRunnable = onDismissRunnable;
Selim Cinek9e624e72016-07-20 13:46:49 -07001018 }
1019
Selim Cinek281c2022016-10-13 19:14:43 -07001020 public View getNotificationIcon() {
Selim Cinek414ad332017-02-24 19:06:12 -08001021 NotificationHeaderView notificationHeader = getVisibleNotificationHeader();
Selim Cinek281c2022016-10-13 19:14:43 -07001022 if (notificationHeader != null) {
1023 return notificationHeader.getIcon();
1024 }
1025 return null;
1026 }
1027
1028 /**
1029 * @return whether the notification is currently showing a view with an icon.
1030 */
1031 public boolean isShowingIcon() {
Mady Mellor434180c2017-02-13 11:29:42 -08001032 if (areGutsExposed()) {
1033 return false;
1034 }
Selim Cinek2ffa02f2017-03-06 15:56:37 -08001035 return getVisibleNotificationHeader() != null;
Selim Cinek281c2022016-10-13 19:14:43 -07001036 }
1037
Selim Cinek0242fbb2016-10-19 13:38:32 -07001038 /**
1039 * Set how much this notification is transformed into an icon.
1040 *
Selim Cinek2b549f42016-11-22 16:38:51 -08001041 * @param contentTransformationAmount A value from 0 to 1 indicating how much we are transformed
1042 * to the content away
Selim Cinek875a3a12016-11-18 17:52:16 -08001043 * @param isLastChild is this the last child in the list. If true, then the transformation is
1044 * different since it's content fades out.
Selim Cinek0242fbb2016-10-19 13:38:32 -07001045 */
Selim Cinek2b549f42016-11-22 16:38:51 -08001046 public void setContentTransformationAmount(float contentTransformationAmount,
1047 boolean isLastChild) {
Selim Cinek875a3a12016-11-18 17:52:16 -08001048 boolean changeTransformation = isLastChild != mIsLastChild;
Selim Cinek2b549f42016-11-22 16:38:51 -08001049 changeTransformation |= mContentTransformationAmount != contentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001050 mIsLastChild = isLastChild;
Selim Cinek2b549f42016-11-22 16:38:51 -08001051 mContentTransformationAmount = contentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001052 if (changeTransformation) {
1053 updateContentTransformation();
Selim Cinek2b549f42016-11-22 16:38:51 -08001054 }
1055 }
1056
1057 /**
1058 * Set the icons to be visible of this notification.
1059 */
1060 public void setIconsVisible(boolean iconsVisible) {
1061 if (iconsVisible != mIconsVisible) {
1062 mIconsVisible = iconsVisible;
1063 updateIconVisibilities();
Selim Cinek0242fbb2016-10-19 13:38:32 -07001064 }
1065 }
1066
Selim Cinekdb167372016-11-17 15:41:17 -08001067 @Override
1068 protected void onBelowSpeedBumpChanged() {
1069 updateIconVisibilities();
1070 }
1071
Selim Cinek875a3a12016-11-18 17:52:16 -08001072 private void updateContentTransformation() {
1073 float contentAlpha;
Selim Cinek2b549f42016-11-22 16:38:51 -08001074 float translationY = -mContentTransformationAmount * mIconTransformContentShift;
Selim Cinek875a3a12016-11-18 17:52:16 -08001075 if (mIsLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -08001076 contentAlpha = 1.0f - mContentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001077 contentAlpha = Math.min(contentAlpha / 0.5f, 1.0f);
Selim Cinek0242fbb2016-10-19 13:38:32 -07001078 contentAlpha = Interpolators.ALPHA_OUT.getInterpolation(contentAlpha);
Selim Cinek875a3a12016-11-18 17:52:16 -08001079 translationY *= 0.4f;
1080 } else {
1081 contentAlpha = 1.0f;
1082 }
Adrian Rooseb434ff2017-01-11 11:18:48 -08001083 for (NotificationContentView l : mLayouts) {
1084 l.setAlpha(contentAlpha);
1085 l.setTranslationY(translationY);
1086 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001087 if (mChildrenContainer != null) {
1088 mChildrenContainer.setAlpha(contentAlpha);
1089 mChildrenContainer.setTranslationY(translationY);
1090 // TODO: handle children fade out better
Selim Cinek0242fbb2016-10-19 13:38:32 -07001091 }
1092 }
1093
1094 private void updateIconVisibilities() {
Selim Cinek17e1b692016-12-02 18:19:11 -08001095 boolean visible = isChildInGroup()
1096 || (isBelowSpeedBump() && !NotificationShelf.SHOW_AMBIENT_ICONS)
1097 || mIconsVisible;
Adrian Rooseb434ff2017-01-11 11:18:48 -08001098 for (NotificationContentView l : mLayouts) {
1099 l.setIconsVisible(visible);
1100 }
Selim Cinekdb167372016-11-17 15:41:17 -08001101 if (mChildrenContainer != null) {
1102 mChildrenContainer.setIconsVisible(visible);
Selim Cinek0242fbb2016-10-19 13:38:32 -07001103 }
1104 }
1105
Selim Cinek875a3a12016-11-18 17:52:16 -08001106 /**
1107 * Get the relative top padding of a view relative to this view. This recursively walks up the
1108 * hierarchy and does the corresponding measuring.
1109 *
1110 * @param view the view to the the padding for. The requested view has to be a child of this
1111 * notification.
1112 * @return the toppadding
1113 */
1114 public int getRelativeTopPadding(View view) {
1115 int topPadding = 0;
1116 while (view.getParent() instanceof ViewGroup) {
1117 topPadding += view.getTop();
1118 view = (View) view.getParent();
1119 if (view instanceof ExpandableNotificationRow) {
1120 return topPadding;
1121 }
1122 }
1123 return topPadding;
1124 }
1125
Selim Cineka1d97902016-12-14 16:31:40 -08001126 public float getContentTranslation() {
1127 return mPrivateLayout.getTranslationY();
1128 }
1129
Selim Cinek6743c0b2017-01-18 18:24:01 -08001130 public void setIsLowPriority(boolean isLowPriority) {
1131 mIsLowPriority = isLowPriority;
1132 mPrivateLayout.setIsLowPriority(isLowPriority);
Selim Cinek1a48bab2017-02-17 19:38:40 -08001133 mNotificationInflater.setIsLowPriority(mIsLowPriority);
Selim Cinek6743c0b2017-01-18 18:24:01 -08001134 if (mChildrenContainer != null) {
1135 mChildrenContainer.setIsLowPriority(isLowPriority);
1136 }
1137 }
1138
Selim Cinek55a3e732017-05-25 18:30:10 -07001139
1140 public void setLowPriorityStateUpdated(boolean lowPriorityStateUpdated) {
1141 mLowPriorityStateUpdated = lowPriorityStateUpdated;
1142 }
1143
1144 public boolean hasLowPriorityStateUpdated() {
1145 return mLowPriorityStateUpdated;
1146 }
1147
Selim Cinek414ad332017-02-24 19:06:12 -08001148 public boolean isLowPriority() {
1149 return mIsLowPriority;
1150 }
1151
Selim Cinek7d1009b2017-01-25 15:28:28 -08001152 public void setUseIncreasedCollapsedHeight(boolean use) {
1153 mUseIncreasedCollapsedHeight = use;
Selim Cinek1a48bab2017-02-17 19:38:40 -08001154 mNotificationInflater.setUsesIncreasedHeight(use);
Selim Cinek7d1009b2017-01-25 15:28:28 -08001155 }
1156
Selim Cinek87ed69b2017-02-09 15:59:43 -08001157 public void setUseIncreasedHeadsUpHeight(boolean use) {
1158 mUseIncreasedHeadsUpHeight = use;
Selim Cinek1a48bab2017-02-17 19:38:40 -08001159 mNotificationInflater.setUsesIncreasedHeadsUpHeight(use);
1160 }
1161
1162 public void setRemoteViewClickHandler(RemoteViews.OnClickHandler remoteViewClickHandler) {
1163 mNotificationInflater.setRemoteViewClickHandler(remoteViewClickHandler);
Selim Cinek87ed69b2017-02-09 15:59:43 -08001164 }
1165
Selim Cinek5ba22542017-04-20 15:16:10 -07001166 public void setInflationCallback(InflationCallback callback) {
1167 mNotificationInflater.setInflationCallback(callback);
Selim Cinekc478f902017-02-22 20:55:44 -08001168 }
1169
Adrian Roos1a1ecfc2017-04-17 11:17:59 -07001170 public void setNeedsRedaction(boolean needsRedaction) {
1171 mNotificationInflater.setRedactAmbient(needsRedaction);
1172 }
1173
Selim Cinek5ba22542017-04-20 15:16:10 -07001174 @VisibleForTesting
1175 public NotificationInflater getNotificationInflater() {
1176 return mNotificationInflater;
1177 }
1178
Adrian Roos6f6e1592017-05-02 16:22:53 -07001179 public int getNotificationColorAmbient() {
1180 return mNotificationColorAmbient;
1181 }
1182
Chris Wren78403d72014-07-28 10:23:24 +01001183 public interface ExpansionLogger {
Anthony Chen6bf88a02017-04-10 14:41:44 -07001184 void logNotificationExpansion(String key, boolean userAction, boolean expanded);
Chris Wren78403d72014-07-28 10:23:24 +01001185 }
Selim Cinek1685e632014-04-08 02:27:49 +02001186
Chris Wren51c75102013-07-16 20:49:17 -04001187 public ExpandableNotificationRow(Context context, AttributeSet attrs) {
1188 super(context, attrs);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001189 mFalsingManager = FalsingManager.getInstance(context);
Selim Cinek1a48bab2017-02-17 19:38:40 -08001190 mNotificationInflater = new NotificationInflater(this);
Mady Mellor95d743c2017-01-10 12:05:27 -08001191 mMenuRow = new NotificationMenuRow(mContext);
Selim Cinek01af3342016-02-09 19:25:31 -08001192 initDimens();
1193 }
1194
1195 private void initDimens() {
Selim Cinekf619ffc2016-02-17 14:53:05 -08001196 mNotificationMinHeightLegacy = getFontScaledHeight(R.dimen.notification_min_height_legacy);
1197 mNotificationMinHeight = getFontScaledHeight(R.dimen.notification_min_height);
Selim Cinek7d1009b2017-01-25 15:28:28 -08001198 mNotificationMinHeightLarge = getFontScaledHeight(
Selim Cinek87ed69b2017-02-09 15:59:43 -08001199 R.dimen.notification_min_height_increased);
Selim Cinekf619ffc2016-02-17 14:53:05 -08001200 mNotificationMaxHeight = getFontScaledHeight(R.dimen.notification_max_height);
Adrian Roos0aac04f2016-12-08 15:59:29 -08001201 mNotificationAmbientHeight = getFontScaledHeight(R.dimen.notification_ambient_height);
Selim Cinekf619ffc2016-02-17 14:53:05 -08001202 mMaxHeadsUpHeightLegacy = getFontScaledHeight(
Selim Cinek77019c72015-12-09 10:18:02 -08001203 R.dimen.notification_max_heads_up_height_legacy);
Selim Cinekf619ffc2016-02-17 14:53:05 -08001204 mMaxHeadsUpHeight = getFontScaledHeight(R.dimen.notification_max_heads_up_height);
Selim Cinek87ed69b2017-02-09 15:59:43 -08001205 mMaxHeadsUpHeightIncreased = getFontScaledHeight(
1206 R.dimen.notification_max_heads_up_height_increased);
Anthony Chen6bf88a02017-04-10 14:41:44 -07001207
Anthony Chen7acbb772017-04-07 16:45:25 -07001208 Resources res = getResources();
1209 mIncreasedPaddingBetweenElements = res.getDimensionPixelSize(
1210 R.dimen.notification_divider_height_increased);
1211 mIconTransformContentShiftNoIcon = res.getDimensionPixelSize(
Selim Cinek0242fbb2016-10-19 13:38:32 -07001212 R.dimen.notification_icon_transform_content_shift);
Anthony Chen6bf88a02017-04-10 14:41:44 -07001213 mEnableNonGroupedNotificationExpand =
1214 res.getBoolean(R.bool.config_enableNonGroupedNotificationExpand);
1215 mShowGroupBackgroundWhenExpanded =
1216 res.getBoolean(R.bool.config_showGroupNotificationBgWhenExpanded);
Selim Cinekf619ffc2016-02-17 14:53:05 -08001217 }
1218
1219 /**
1220 * @param dimenId the dimen to look up
1221 * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
1222 */
1223 private int getFontScaledHeight(int dimenId) {
1224 int dimensionPixelSize = getResources().getDimensionPixelSize(dimenId);
1225 float factor = Math.max(1.0f, getResources().getDisplayMetrics().scaledDensity /
1226 getResources().getDisplayMetrics().density);
1227 return (int) (dimensionPixelSize * factor);
Chris Wren51c75102013-07-16 20:49:17 -04001228 }
1229
Christoph Studera7fe6312014-06-27 19:32:44 +02001230 /**
1231 * Resets this view so it can be re-used for an updated notification.
1232 */
1233 public void reset() {
Jorim Jaggiae441282014-08-01 02:45:18 +02001234 mShowingPublicInitialized = false;
Selim Cinek31094df2014-08-14 19:28:15 +02001235 onHeightReset();
Selim Cinek6e28a672014-09-05 14:43:28 +02001236 requestLayout();
Christoph Studera7fe6312014-06-27 19:32:44 +02001237 }
1238
Jorim Jaggi251957d2014-04-09 04:24:09 +02001239 @Override
1240 protected void onFinishInflate() {
1241 super.onFinishInflate();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001242 mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic);
1243 mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded);
Adrian Rooseb434ff2017-01-11 11:18:48 -08001244 mLayouts = new NotificationContentView[] {mPrivateLayout, mPublicLayout};
1245
1246 for (NotificationContentView l : mLayouts) {
1247 l.setExpandClickListener(mExpandClickListener);
1248 l.setContainingNotification(this);
1249 }
Selim Cinekab29aeb2015-02-20 18:18:32 +01001250 mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub);
1251 mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() {
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001252 @Override
1253 public void onInflate(ViewStub stub, View inflated) {
1254 mGuts = (NotificationGuts) inflated;
1255 mGuts.setClipTopAmount(getClipTopAmount());
1256 mGuts.setActualHeight(getActualHeight());
Selim Cinekab29aeb2015-02-20 18:18:32 +01001257 mGutsStub = null;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001258 }
1259 });
Selim Cinekb5605e52015-02-20 18:21:41 +01001260 mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub);
1261 mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() {
1262
1263 @Override
1264 public void onInflate(ViewStub stub, View inflated) {
1265 mChildrenContainer = (NotificationChildrenContainer) inflated;
Selim Cinek6743c0b2017-01-18 18:24:01 -08001266 mChildrenContainer.setIsLowPriority(mIsLowPriority);
Selim Cinek414ad332017-02-24 19:06:12 -08001267 mChildrenContainer.setContainingNotification(ExpandableNotificationRow.this);
Selim Cinekc897bd32016-03-18 17:32:31 -07001268 mChildrenContainer.onNotificationUpdated();
Anthony Chen7acbb772017-04-07 16:45:25 -07001269
1270 if (mShouldTranslateContents) {
1271 mTranslateableViews.add(mChildrenContainer);
1272 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001273 }
1274 });
Mady Mellor4b80b102016-01-22 08:03:58 -08001275
Anthony Chen7acbb772017-04-07 16:45:25 -07001276 if (mShouldTranslateContents) {
1277 // Add the views that we translate to reveal the menu
1278 mTranslateableViews = new ArrayList<>();
1279 for (int i = 0; i < getChildCount(); i++) {
1280 mTranslateableViews.add(getChildAt(i));
1281 }
1282 // Remove views that don't translate
1283 mTranslateableViews.remove(mChildrenContainerStub);
1284 mTranslateableViews.remove(mGutsStub);
Mady Mellor4b80b102016-01-22 08:03:58 -08001285 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001286 }
1287
Mady Mellor4b80b102016-01-22 08:03:58 -08001288 public void resetTranslation() {
Mady Mellor32c638a2016-09-14 08:58:25 -07001289 if (mTranslateAnim != null) {
1290 mTranslateAnim.cancel();
1291 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001292
1293 if (!mShouldTranslateContents) {
1294 setTranslationX(0);
1295 } else if (mTranslateableViews != null) {
Mady Mellor4b80b102016-01-22 08:03:58 -08001296 for (int i = 0; i < mTranslateableViews.size(); i++) {
1297 mTranslateableViews.get(i).setTranslationX(0);
1298 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001299 invalidateOutline();
Mady Mellor4b80b102016-01-22 08:03:58 -08001300 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001301
Mady Mellor95d743c2017-01-10 12:05:27 -08001302 mMenuRow.resetMenu();
Mady Mellor4b80b102016-01-22 08:03:58 -08001303 }
1304
1305 public void animateTranslateNotification(final float leftTarget) {
1306 if (mTranslateAnim != null) {
1307 mTranslateAnim.cancel();
1308 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001309 mTranslateAnim = getTranslateViewAnimator(leftTarget, null /* updateListener */);
Mady Mellor34958fa2016-02-23 09:52:17 -08001310 if (mTranslateAnim != null) {
1311 mTranslateAnim.start();
1312 }
1313 }
1314
1315 @Override
1316 public void setTranslation(float translationX) {
1317 if (areGutsExposed()) {
1318 // Don't translate if guts are showing.
1319 return;
1320 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001321 if (!mShouldTranslateContents) {
1322 setTranslationX(translationX);
1323 } else if (mTranslateableViews != null) {
1324 // Translate the group of views
1325 for (int i = 0; i < mTranslateableViews.size(); i++) {
1326 if (mTranslateableViews.get(i) != null) {
1327 mTranslateableViews.get(i).setTranslationX(translationX);
1328 }
Mady Mellor34958fa2016-02-23 09:52:17 -08001329 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001330 invalidateOutline();
Mady Mellor34958fa2016-02-23 09:52:17 -08001331 }
Mady Mellor95d743c2017-01-10 12:05:27 -08001332 if (mMenuRow.getMenuView() != null) {
1333 mMenuRow.onTranslationUpdate(translationX);
Mady Mellor34958fa2016-02-23 09:52:17 -08001334 }
1335 }
1336
1337 @Override
1338 public float getTranslation() {
Anthony Chene04afcb2017-04-21 13:51:32 -07001339 if (!mShouldTranslateContents) {
Anthony Chen7acbb772017-04-07 16:45:25 -07001340 return getTranslationX();
1341 }
1342
Mady Mellor34958fa2016-02-23 09:52:17 -08001343 if (mTranslateableViews != null && mTranslateableViews.size() > 0) {
1344 // All of the views in the list should have same translation, just use first one.
1345 return mTranslateableViews.get(0).getTranslationX();
1346 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001347
Mady Mellor34958fa2016-02-23 09:52:17 -08001348 return 0;
1349 }
1350
1351 public Animator getTranslateViewAnimator(final float leftTarget,
1352 AnimatorUpdateListener listener) {
Mady Mellor723f1f92016-03-13 15:54:06 -07001353 if (mTranslateAnim != null) {
1354 mTranslateAnim.cancel();
1355 }
Mady Mellor34958fa2016-02-23 09:52:17 -08001356 if (areGutsExposed()) {
1357 // No translation if guts are exposed.
1358 return null;
1359 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001360 final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(this, TRANSLATE_CONTENT,
1361 leftTarget);
1362 if (listener != null) {
1363 translateAnim.addUpdateListener(listener);
Mady Mellor4b80b102016-01-22 08:03:58 -08001364 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001365 translateAnim.addListener(new AnimatorListenerAdapter() {
1366 boolean cancelled = false;
1367
1368 @Override
1369 public void onAnimationCancel(Animator anim) {
1370 cancelled = true;
1371 }
1372
1373 @Override
1374 public void onAnimationEnd(Animator anim) {
Mady Mellor95d743c2017-01-10 12:05:27 -08001375 if (!cancelled && leftTarget == 0) {
1376 mMenuRow.resetMenu();
Mady Mellorb0a82462016-04-30 17:31:02 -07001377 mTranslateAnim = null;
1378 }
1379 }
1380 });
1381 mTranslateAnim = translateAnim;
1382 return translateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -08001383 }
1384
Selim Cinekab29aeb2015-02-20 18:18:32 +01001385 public void inflateGuts() {
1386 if (mGuts == null) {
1387 mGutsStub.inflate();
1388 }
1389 }
1390
Selim Cinekda42d652015-12-04 15:51:16 -08001391 private void updateChildrenVisibility() {
Selim Cinekd84a5932015-12-15 11:45:36 -08001392 mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE
1393 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -08001394 if (mChildrenContainer != null) {
1395 mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
1396 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -08001397 }
Selim Cinekda42d652015-12-04 15:51:16 -08001398 // The limits might have changed if the view suddenly became a group or vice versa
1399 updateLimits();
Selim Cinekb5605e52015-02-20 18:21:41 +01001400 }
1401
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001402 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08001403 public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
1404 if (super.onRequestSendAccessibilityEventInternal(child, event)) {
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001405 // Add a record for the entire layout since its content is somehow small.
1406 // The event comes from a leaf view that is interacted with.
1407 AccessibilityEvent record = AccessibilityEvent.obtain();
1408 onInitializeAccessibilityEvent(record);
1409 dispatchPopulateAccessibilityEvent(record);
1410 event.appendRecord(record);
1411 return true;
1412 }
1413 return false;
Jorim Jaggic5dc0d02014-04-15 15:42:55 +02001414 }
Chris Wren51c75102013-07-16 20:49:17 -04001415
John Spurlocke15452b2014-08-21 09:44:39 -04001416 @Override
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001417 public void setDark(boolean dark, boolean fade, long delay) {
1418 super.setDark(dark, fade, delay);
Adrian Roos28f90c72017-05-08 17:24:26 -07001419 if (!mIsHeadsUp) {
1420 // Only fade the showing view of the pulsing notification.
1421 fade = false;
1422 }
John Spurlocke15452b2014-08-21 09:44:39 -04001423 final NotificationContentView showing = getShowingLayout();
1424 if (showing != null) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001425 showing.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -04001426 }
Selim Cinek9c7712d2015-12-08 19:19:48 -08001427 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001428 mChildrenContainer.setDark(dark, fade, delay);
Selim Cinek9c7712d2015-12-08 19:19:48 -08001429 }
John Spurlocke15452b2014-08-21 09:44:39 -04001430 }
1431
Chris Wren51c75102013-07-16 20:49:17 -04001432 public boolean isExpandable() {
Selim Cinek388df6d2015-10-22 13:25:11 -07001433 if (mIsSummaryWithChildren && !mShowingPublic) {
1434 return !mChildrenExpanded;
1435 }
Anthony Chen6bf88a02017-04-10 14:41:44 -07001436 return mEnableNonGroupedNotificationExpand && mExpandable;
Chris Wren51c75102013-07-16 20:49:17 -04001437 }
1438
1439 public void setExpandable(boolean expandable) {
1440 mExpandable = expandable;
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001441 mPrivateLayout.updateExpandButtons(isExpandable());
Chris Wren51c75102013-07-16 20:49:17 -04001442 }
1443
Selim Cinek4ffd6362015-12-29 15:12:23 +01001444 @Override
1445 public void setClipToActualHeight(boolean clipToActualHeight) {
Selim Cinek084c16b2016-01-22 17:48:22 -08001446 super.setClipToActualHeight(clipToActualHeight || isUserLocked());
1447 getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked());
Selim Cinek4ffd6362015-12-29 15:12:23 +01001448 }
1449
Selim Cinek1685e632014-04-08 02:27:49 +02001450 /**
1451 * @return whether the user has changed the expansion state
1452 */
1453 public boolean hasUserChangedExpansion() {
1454 return mHasUserChangedExpansion;
1455 }
1456
Chris Wren51c75102013-07-16 20:49:17 -04001457 public boolean isUserExpanded() {
1458 return mUserExpanded;
1459 }
1460
Selim Cinek1685e632014-04-08 02:27:49 +02001461 /**
1462 * Set this notification to be expanded by the user
1463 *
1464 * @param userExpanded whether the user wants this notification to be expanded
1465 */
Chris Wren51c75102013-07-16 20:49:17 -04001466 public void setUserExpanded(boolean userExpanded) {
Selim Cinek388df6d2015-10-22 13:25:11 -07001467 setUserExpanded(userExpanded, false /* allowChildExpansion */);
1468 }
1469
1470 /**
1471 * Set this notification to be expanded by the user
1472 *
1473 * @param userExpanded whether the user wants this notification to be expanded
1474 * @param allowChildExpansion whether a call to this method allows expanding children
1475 */
1476 public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001477 mFalsingManager.setNotificationExpanded();
Selim Cinek414ad332017-02-24 19:06:12 -08001478 if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion
1479 && !mChildrenContainer.showingAsLowPriority()) {
Chris Wren698b1702016-05-23 11:16:32 -04001480 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinek388df6d2015-10-22 13:25:11 -07001481 mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded);
Selim Cinek414ad332017-02-24 19:06:12 -08001482 onExpansionChanged(true /* userAction */, wasExpanded);
Selim Cinek388df6d2015-10-22 13:25:11 -07001483 return;
1484 }
Christoph Studera7fe6312014-06-27 19:32:44 +02001485 if (userExpanded && !mExpandable) return;
Chris Wren78403d72014-07-28 10:23:24 +01001486 final boolean wasExpanded = isExpanded();
Selim Cinek1685e632014-04-08 02:27:49 +02001487 mHasUserChangedExpansion = true;
Chris Wren51c75102013-07-16 20:49:17 -04001488 mUserExpanded = userExpanded;
Selim Cinek414ad332017-02-24 19:06:12 -08001489 onExpansionChanged(true /* userAction */, wasExpanded);
Selim Cinek5d6ef8d2017-05-18 22:16:00 -07001490 if (!wasExpanded && isExpanded()
1491 && getActualHeight() != getIntrinsicHeight()) {
1492 notifyHeightChanged(true /* needsAnimation */);
1493 }
Chris Wren51c75102013-07-16 20:49:17 -04001494 }
1495
Selim Cinekccd14fb2014-08-12 18:53:24 +02001496 public void resetUserExpansion() {
Selim Cinek414ad332017-02-24 19:06:12 -08001497 boolean changed = mUserExpanded;
Selim Cinekccd14fb2014-08-12 18:53:24 +02001498 mHasUserChangedExpansion = false;
1499 mUserExpanded = false;
Selim Cinek414ad332017-02-24 19:06:12 -08001500 if (changed && mIsSummaryWithChildren) {
1501 mChildrenContainer.onExpansionChanged();
1502 }
1503 updateShelfIconColor();
Selim Cinekccd14fb2014-08-12 18:53:24 +02001504 }
1505
Chris Wren51c75102013-07-16 20:49:17 -04001506 public boolean isUserLocked() {
Selim Cinek1b2a05e2016-04-28 14:20:39 -07001507 return mUserLocked && !mForceUnlocked;
Chris Wren51c75102013-07-16 20:49:17 -04001508 }
1509
1510 public void setUserLocked(boolean userLocked) {
1511 mUserLocked = userLocked;
Selim Cinek8f2f6a62016-02-23 19:56:31 -08001512 mPrivateLayout.setUserExpanding(userLocked);
Selim Cinek817abe72017-05-24 11:08:55 -07001513 // This is intentionally not guarded with mIsSummaryWithChildren since we might have had
1514 // children but not anymore.
1515 if (mChildrenContainer != null) {
Selim Cinek42357e02016-02-24 18:48:01 -08001516 mChildrenContainer.setUserLocked(userLocked);
Selim Cinek817abe72017-05-24 11:08:55 -07001517 if (mIsSummaryWithChildren && (userLocked || !isGroupExpanded())) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001518 updateBackgroundForGroupState();
1519 }
Selim Cinek42357e02016-02-24 18:48:01 -08001520 }
Chris Wren51c75102013-07-16 20:49:17 -04001521 }
1522
Selim Cinek1685e632014-04-08 02:27:49 +02001523 /**
1524 * @return has the system set this notification to be expanded
1525 */
1526 public boolean isSystemExpanded() {
1527 return mIsSystemExpanded;
1528 }
1529
1530 /**
1531 * Set this notification to be expanded by the system.
1532 *
1533 * @param expand whether the system wants this notification to be expanded.
1534 */
1535 public void setSystemExpanded(boolean expand) {
Selim Cinek31094df2014-08-14 19:28:15 +02001536 if (expand != mIsSystemExpanded) {
1537 final boolean wasExpanded = isExpanded();
1538 mIsSystemExpanded = expand;
Selim Cinekb5605e52015-02-20 18:21:41 +01001539 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek414ad332017-02-24 19:06:12 -08001540 onExpansionChanged(false /* userAction */, wasExpanded);
Selim Cineked6913b2016-06-01 12:01:17 -07001541 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001542 mChildrenContainer.updateGroupOverflow();
1543 }
Selim Cinek31094df2014-08-14 19:28:15 +02001544 }
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001545 }
1546
1547 /**
Selim Cinek83bc7832015-10-22 13:26:54 -07001548 * @param onKeyguard whether to prevent notification expansion
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001549 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001550 public void setOnKeyguard(boolean onKeyguard) {
1551 if (onKeyguard != mOnKeyguard) {
Selim Cinek31094df2014-08-14 19:28:15 +02001552 final boolean wasExpanded = isExpanded();
Selim Cinek83bc7832015-10-22 13:26:54 -07001553 mOnKeyguard = onKeyguard;
Selim Cinek414ad332017-02-24 19:06:12 -08001554 onExpansionChanged(false /* userAction */, wasExpanded);
Selim Cinek31094df2014-08-14 19:28:15 +02001555 if (wasExpanded != isExpanded()) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001556 if (mIsSummaryWithChildren) {
1557 mChildrenContainer.updateGroupOverflow();
1558 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001559 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +02001560 }
1561 }
Selim Cinek1685e632014-04-08 02:27:49 +02001562 }
1563
1564 /**
Selim Cinek9e624e72016-07-20 13:46:49 -07001565 * @return Can the underlying notification be cleared? This can be different from whether the
1566 * notification can be dismissed in case notifications are sensitive on the lockscreen.
1567 * @see #canViewBeDismissed()
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001568 */
1569 public boolean isClearable() {
Selim Cinek506deb62016-07-20 15:43:59 -07001570 if (mStatusBarNotification == null || !mStatusBarNotification.isClearable()) {
1571 return false;
1572 }
1573 if (mIsSummaryWithChildren) {
1574 List<ExpandableNotificationRow> notificationChildren =
1575 mChildrenContainer.getNotificationChildren();
1576 for (int i = 0; i < notificationChildren.size(); i++) {
1577 ExpandableNotificationRow child = notificationChildren.get(i);
1578 if (!child.isClearable()) {
1579 return false;
1580 }
1581 }
1582 }
1583 return true;
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001584 }
1585
Jorim Jaggi9cbadd32014-05-01 20:18:31 +02001586 @Override
1587 public int getIntrinsicHeight() {
Jorim Jaggibe565df2014-04-28 17:51:23 +02001588 if (isUserLocked()) {
1589 return getActualHeight();
1590 }
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05001591 if (mGuts != null && mGuts.isExposed()) {
Mady Mellore09fb702017-03-30 13:23:29 -07001592 return mGuts.getIntrinsicHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -08001593 } else if ((isChildInGroup() && !isGroupExpanded())) {
1594 return mPrivateLayout.getMinHeight();
1595 } else if (mSensitive && mHideSensitiveForIntrinsicHeight) {
1596 return getMinHeight();
Adrian Roos6f6e1592017-05-02 16:22:53 -07001597 } else if (mIsSummaryWithChildren && (!mOnKeyguard || mShowAmbient)) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001598 return mChildrenContainer.getIntrinsicHeight();
Adrian Roos6f6e1592017-05-02 16:22:53 -07001599 } else if (isHeadsUpAllowed() && (mIsHeadsUp || mHeadsupDisappearRunning)) {
Selim Cinek73cf02a2016-06-17 13:08:00 -07001600 if (isPinned() || mHeadsupDisappearRunning) {
Selim Cinek31aada42015-12-18 17:51:15 -08001601 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
1602 } else if (isExpanded()) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001603 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001604 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001605 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001606 }
Selim Cinek31aada42015-12-18 17:51:15 -08001607 } else if (isExpanded()) {
Selim Cinek83bc7832015-10-22 13:26:54 -07001608 return getMaxExpandHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -08001609 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001610 return getCollapsedHeight();
Selim Cinek1685e632014-04-08 02:27:49 +02001611 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001612 }
Selim Cinek1685e632014-04-08 02:27:49 +02001613
Adrian Roos6f6e1592017-05-02 16:22:53 -07001614 private boolean isHeadsUpAllowed() {
1615 return !mOnKeyguard && !mShowAmbient;
1616 }
1617
Mady Mellor43c2cd12016-12-12 21:05:13 -08001618 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -07001619 public boolean isGroupExpanded() {
Selim Cinekeef84282015-10-30 16:28:00 -07001620 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinekb5605e52015-02-20 18:21:41 +01001621 }
1622
Selim Cinek263398f2015-10-21 17:40:23 -07001623 private void onChildrenCountChanged() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001624 mIsSummaryWithChildren = StatusBar.ENABLE_CHILD_NOTIFICATIONS
Mady Mellorb0a82462016-04-30 17:31:02 -07001625 && mChildrenContainer != null && mChildrenContainer.getNotificationChildCount() > 0;
1626 if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() == null) {
Selim Cinek414ad332017-02-24 19:06:12 -08001627 mChildrenContainer.recreateNotificationHeader(mExpandClickListener
1628 );
Selim Cinek263398f2015-10-21 17:40:23 -07001629 }
Mady Mellor6baed9e2016-05-25 16:05:09 -07001630 getShowingLayout().updateBackgroundColor(false /* animate */);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001631 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinekea4bef72015-12-02 15:51:10 -08001632 updateChildrenHeaderAppearance();
Selim Cinekda42d652015-12-04 15:51:16 -08001633 updateChildrenVisibility();
Selim Cinek263398f2015-10-21 17:40:23 -07001634 }
1635
Mady Mellorb0a82462016-04-30 17:31:02 -07001636 public void updateChildrenHeaderAppearance() {
Selim Cineked6913b2016-06-01 12:01:17 -07001637 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001638 mChildrenContainer.updateChildrenHeaderAppearance();
1639 }
1640 }
1641
Selim Cinek1685e632014-04-08 02:27:49 +02001642 /**
1643 * Check whether the view state is currently expanded. This is given by the system in {@link
1644 * #setSystemExpanded(boolean)} and can be overridden by user expansion or
1645 * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this
1646 * view can differ from this state, if layout params are modified from outside.
1647 *
1648 * @return whether the view state is currently expanded.
1649 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001650 public boolean isExpanded() {
Selim Cineke81b82b2016-03-04 11:22:28 -08001651 return isExpanded(false /* allowOnKeyguard */);
1652 }
1653
1654 public boolean isExpanded(boolean allowOnKeyguard) {
1655 return (!mOnKeyguard || allowOnKeyguard)
Selim Cinekb5605e52015-02-20 18:21:41 +01001656 && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded())
1657 || isUserExpanded());
1658 }
1659
1660 private boolean isSystemChildExpanded() {
1661 return mIsSystemChildExpanded;
1662 }
1663
1664 public void setSystemChildExpanded(boolean expanded) {
1665 mIsSystemChildExpanded = expanded;
Selim Cinek1685e632014-04-08 02:27:49 +02001666 }
1667
Mady Mellor035badd2017-04-04 18:45:30 -07001668 public void setLayoutListener(LayoutListener listener) {
1669 mLayoutListener = listener;
1670 }
1671
1672 public void removeListener() {
1673 mLayoutListener = null;
1674 }
1675
Selim Cinek1685e632014-04-08 02:27:49 +02001676 @Override
1677 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
1678 super.onLayout(changed, left, top, right, bottom);
Selim Cinek8d490d42015-04-10 00:05:50 -07001679 updateMaxHeights();
Mady Mellor95d743c2017-01-10 12:05:27 -08001680 if (mMenuRow.getMenuView() != null) {
1681 mMenuRow.onHeightUpdate();
Mady Mellora6edc872016-04-26 11:01:03 -07001682 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001683 updateContentShiftHeight();
Mady Mellor035badd2017-04-04 18:45:30 -07001684 if (mLayoutListener != null) {
1685 mLayoutListener.onLayout();
1686 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001687 }
1688
1689 /**
1690 * Updates the content shift height such that the header is completely hidden when coming from
1691 * the top.
1692 */
1693 private void updateContentShiftHeight() {
Selim Cinek414ad332017-02-24 19:06:12 -08001694 NotificationHeaderView notificationHeader = getVisibleNotificationHeader();
Selim Cinek875a3a12016-11-18 17:52:16 -08001695 if (notificationHeader != null) {
1696 CachingIconView icon = notificationHeader.getIcon();
1697 mIconTransformContentShift = getRelativeTopPadding(icon) + icon.getHeight();
1698 } else {
1699 mIconTransformContentShift = mIconTransformContentShiftNoIcon;
1700 }
Selim Cinek1685e632014-04-08 02:27:49 +02001701 }
1702
Selim Cinek8d490d42015-04-10 00:05:50 -07001703 private void updateMaxHeights() {
Selim Cinekd2319fb2014-09-01 19:41:54 +02001704 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek8d490d42015-04-10 00:05:50 -07001705 View expandedChild = mPrivateLayout.getExpandedChild();
1706 if (expandedChild == null) {
1707 expandedChild = mPrivateLayout.getContractedChild();
1708 }
1709 mMaxExpandHeight = expandedChild.getHeight();
1710 View headsUpChild = mPrivateLayout.getHeadsUpChild();
Selim Cinek1f3f5442015-04-10 17:54:46 -07001711 if (headsUpChild == null) {
1712 headsUpChild = mPrivateLayout.getContractedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -07001713 }
Selim Cinek1f3f5442015-04-10 17:54:46 -07001714 mHeadsUpHeight = headsUpChild.getHeight();
Selim Cinekd2319fb2014-09-01 19:41:54 +02001715 if (intrinsicBefore != getIntrinsicHeight()) {
Selim Cinekbb42b7d2016-08-10 13:02:38 -07001716 notifyHeightChanged(true /* needsAnimation */);
Selim Cinekd2319fb2014-09-01 19:41:54 +02001717 }
1718 }
1719
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001720 @Override
1721 public void notifyHeightChanged(boolean needsAnimation) {
1722 super.notifyHeightChanged(needsAnimation);
1723 getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked());
1724 }
1725
Selim Cinek3c76d502016-02-19 15:16:33 -08001726 public void setSensitive(boolean sensitive, boolean hideSensitive) {
Jorim Jaggiae441282014-08-01 02:45:18 +02001727 mSensitive = sensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -08001728 mSensitiveHiddenInGeneral = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02001729 }
1730
Mady Mellor43c2cd12016-12-12 21:05:13 -08001731 @Override
Jorim Jaggiae441282014-08-01 02:45:18 +02001732 public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
Selim Cinek60122be2015-04-15 18:16:50 -07001733 mHideSensitiveForIntrinsicHeight = hideSensitive;
Selim Cineka52f6a12016-02-29 15:35:58 -08001734 if (mIsSummaryWithChildren) {
1735 List<ExpandableNotificationRow> notificationChildren =
1736 mChildrenContainer.getNotificationChildren();
1737 for (int i = 0; i < notificationChildren.size(); i++) {
1738 ExpandableNotificationRow child = notificationChildren.get(i);
1739 child.setHideSensitiveForIntrinsicHeight(hideSensitive);
1740 }
1741 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001742 }
1743
Mady Mellor43c2cd12016-12-12 21:05:13 -08001744 @Override
Jorim Jaggiae441282014-08-01 02:45:18 +02001745 public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
1746 long duration) {
1747 boolean oldShowingPublic = mShowingPublic;
1748 mShowingPublic = mSensitive && hideSensitive;
1749 if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
1750 return;
1751 }
Dan Sandlera5e0f412014-01-23 15:11:54 -05001752
1753 // bail out if no public version
Selim Cinek1685e632014-04-08 02:27:49 +02001754 if (mPublicLayout.getChildCount() == 0) return;
Dan Sandlera5e0f412014-01-23 15:11:54 -05001755
Jorim Jaggiae441282014-08-01 02:45:18 +02001756 if (!animated) {
1757 mPublicLayout.animate().cancel();
1758 mPrivateLayout.animate().cancel();
Selim Cineka554c702016-06-17 18:02:12 -07001759 if (mChildrenContainer != null) {
1760 mChildrenContainer.animate().cancel();
1761 mChildrenContainer.setAlpha(1f);
1762 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001763 mPublicLayout.setAlpha(1f);
1764 mPrivateLayout.setAlpha(1f);
1765 mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
Selim Cinekd84a5932015-12-15 11:45:36 -08001766 updateChildrenVisibility();
Jorim Jaggiae441282014-08-01 02:45:18 +02001767 } else {
1768 animateShowingPublic(delay, duration);
1769 }
Selim Cinekc3179332016-03-04 14:44:56 -08001770 NotificationContentView showingLayout = getShowingLayout();
1771 showingLayout.updateBackgroundColor(animated);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001772 mPrivateLayout.updateExpandButtons(isExpandable());
Adrian Roose5726a22016-12-19 14:26:51 -08001773 showingLayout.setDark(isDark(), false /* animate */, 0 /* delay */);
Jorim Jaggiae441282014-08-01 02:45:18 +02001774 mShowingPublicInitialized = true;
1775 }
1776
1777 private void animateShowingPublic(long delay, long duration) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001778 View[] privateViews = mIsSummaryWithChildren
1779 ? new View[] {mChildrenContainer}
Selim Cinekd84a5932015-12-15 11:45:36 -08001780 : new View[] {mPrivateLayout};
1781 View[] publicViews = new View[] {mPublicLayout};
1782 View[] hiddenChildren = mShowingPublic ? privateViews : publicViews;
1783 View[] shownChildren = mShowingPublic ? publicViews : privateViews;
1784 for (final View hiddenView : hiddenChildren) {
1785 hiddenView.setVisibility(View.VISIBLE);
1786 hiddenView.animate().cancel();
1787 hiddenView.animate()
1788 .alpha(0f)
1789 .setStartDelay(delay)
1790 .setDuration(duration)
1791 .withEndAction(new Runnable() {
1792 @Override
1793 public void run() {
1794 hiddenView.setVisibility(View.INVISIBLE);
1795 }
1796 });
1797 }
1798 for (View showView : shownChildren) {
1799 showView.setVisibility(View.VISIBLE);
1800 showView.setAlpha(0f);
1801 showView.animate().cancel();
1802 showView.animate()
1803 .alpha(1f)
1804 .setStartDelay(delay)
1805 .setDuration(duration);
1806 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001807 }
1808
Mady Mellor43c2cd12016-12-12 21:05:13 -08001809 @Override
Selim Cinek3776fe02016-02-04 13:32:43 -08001810 public boolean mustStayOnScreen() {
1811 return mIsHeadsUp;
1812 }
1813
Selim Cinek9e624e72016-07-20 13:46:49 -07001814 /**
1815 * @return Whether this view is allowed to be dismissed. Only valid for visible notifications as
1816 * otherwise some state might not be updated. To request about the general clearability
1817 * see {@link #isClearable()}.
1818 */
1819 public boolean canViewBeDismissed() {
Selim Cineke9bad242016-06-15 11:46:37 -07001820 return isClearable() && (!mShowingPublic || !mSensitiveHiddenInGeneral);
Dan Sandlera5e0f412014-01-23 15:11:54 -05001821 }
Jorim Jaggi251957d2014-04-09 04:24:09 +02001822
Ricky Waicd35def2016-05-03 11:07:07 +01001823 public void makeActionsVisibile() {
1824 setUserExpanded(true, true);
1825 if (isChildInGroup()) {
1826 mGroupManager.setGroupExpanded(mStatusBarNotification, true);
1827 }
Selim Cinekbb42b7d2016-08-10 13:02:38 -07001828 notifyHeightChanged(false /* needsAnimation */);
Ricky Waicd35def2016-05-03 11:07:07 +01001829 }
1830
Selim Cinekb5605e52015-02-20 18:21:41 +01001831 public void setChildrenExpanded(boolean expanded, boolean animate) {
1832 mChildrenExpanded = expanded;
Selim Cinek83bc7832015-10-22 13:26:54 -07001833 if (mChildrenContainer != null) {
1834 mChildrenContainer.setChildrenExpanded(expanded);
1835 }
Mady Mellor1a5d8ea2016-06-09 10:42:42 -07001836 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -07001837 updateClickAndFocus();
Selim Cinekb5605e52015-02-20 18:21:41 +01001838 }
1839
Selim Cinekb5605e52015-02-20 18:21:41 +01001840 public static void applyTint(View v, int color) {
1841 int alpha;
1842 if (color != 0) {
1843 alpha = COLORED_DIVIDER_ALPHA;
1844 } else {
1845 color = 0xff000000;
1846 alpha = DEFAULT_DIVIDER_ALPHA;
1847 }
1848 if (v.getBackground() instanceof ColorDrawable) {
1849 ColorDrawable background = (ColorDrawable) v.getBackground();
1850 background.mutate();
1851 background.setColor(color);
1852 background.setAlpha(alpha);
1853 }
1854 }
1855
Selim Cinek1685e632014-04-08 02:27:49 +02001856 public int getMaxExpandHeight() {
Selim Cinekb5605e52015-02-20 18:21:41 +01001857 return mMaxExpandHeight;
Chris Wren51c75102013-07-16 20:49:17 -04001858 }
Jorim Jaggi584a7aa2014-04-10 23:26:13 +02001859
Mady Mellor34958fa2016-02-23 09:52:17 -08001860 public boolean areGutsExposed() {
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05001861 return (mGuts != null && mGuts.isExposed());
Mady Mellor34958fa2016-02-23 09:52:17 -08001862 }
1863
Jorim Jaggibe565df2014-04-28 17:51:23 +02001864 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001865 public boolean isContentExpandable() {
Selim Cinekc0ac4af2017-03-03 15:13:48 -08001866 if (mIsSummaryWithChildren && !mShowingPublic) {
1867 return true;
1868 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001869 NotificationContentView showingLayout = getShowingLayout();
1870 return showingLayout.isContentExpandable();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001871 }
1872
1873 @Override
Selim Cinek560e64d2015-06-09 19:58:11 -07001874 protected View getContentView() {
Selim Cinekaa3901a2016-08-05 11:04:37 -07001875 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cineka5703182016-05-11 21:23:16 -04001876 return mChildrenContainer;
1877 }
Selim Cinek560e64d2015-06-09 19:58:11 -07001878 return getShowingLayout();
1879 }
1880
1881 @Override
Selim Cinekaa3901a2016-08-05 11:04:37 -07001882 protected void onAppearAnimationFinished(boolean wasAppearing) {
1883 super.onAppearAnimationFinished(wasAppearing);
1884 if (wasAppearing) {
1885 // During the animation the visible view might have changed, so let's make sure all
1886 // alphas are reset
1887 if (mChildrenContainer != null) {
1888 mChildrenContainer.setAlpha(1.0f);
1889 mChildrenContainer.setLayerType(LAYER_TYPE_NONE, null);
1890 }
Adrian Rooseb434ff2017-01-11 11:18:48 -08001891 for (NotificationContentView l : mLayouts) {
1892 l.setAlpha(1.0f);
1893 l.setLayerType(LAYER_TYPE_NONE, null);
1894 }
Selim Cinekaa3901a2016-08-05 11:04:37 -07001895 }
1896 }
1897
1898 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -07001899 public int getExtraBottomPadding() {
1900 if (mIsSummaryWithChildren && isGroupExpanded()) {
1901 return mIncreasedPaddingBetweenElements;
1902 }
1903 return 0;
1904 }
1905
1906 @Override
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001907 public void setActualHeight(int height, boolean notifyListeners) {
Selim Cinek4ca6c632017-02-23 18:03:37 -08001908 boolean changed = height != getActualHeight();
Selim Cinekb5605e52015-02-20 18:21:41 +01001909 super.setActualHeight(height, notifyListeners);
Selim Cinek4ca6c632017-02-23 18:03:37 -08001910 if (changed && isRemoved()) {
1911 // TODO: remove this once we found the gfx bug for this.
1912 // This is a hack since a removed view sometimes would just stay blank. it occured
1913 // when sending yourself a message and then clicking on it.
1914 ViewGroup parent = (ViewGroup) getParent();
1915 if (parent != null) {
1916 parent.invalidate();
1917 }
1918 }
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05001919 if (mGuts != null && mGuts.isExposed()) {
Mady Mellorb53bc272016-02-11 18:28:23 -08001920 mGuts.setActualHeight(height);
1921 return;
1922 }
Selim Cinekeef84282015-10-30 16:28:00 -07001923 int contentHeight = Math.max(getMinHeight(), height);
Adrian Rooseb434ff2017-01-11 11:18:48 -08001924 for (NotificationContentView l : mLayouts) {
1925 l.setContentHeight(contentHeight);
1926 }
Selim Cinek42357e02016-02-24 18:48:01 -08001927 if (mIsSummaryWithChildren) {
1928 mChildrenContainer.setActualHeight(height);
1929 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001930 if (mGuts != null) {
1931 mGuts.setActualHeight(height);
1932 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001933 }
1934
1935 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01001936 public int getMaxContentHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001937 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001938 return mChildrenContainer.getMaxContentHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001939 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001940 NotificationContentView showingLayout = getShowingLayout();
1941 return showingLayout.getMaxHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001942 }
1943
1944 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001945 public int getMinHeight() {
Mady Mellore09fb702017-03-30 13:23:29 -07001946 if (mGuts != null && mGuts.isExposed()) {
1947 return mGuts.getIntrinsicHeight();
Adrian Roos6f6e1592017-05-02 16:22:53 -07001948 } else if (isHeadsUpAllowed() && mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) {
Selim Cinek31aada42015-12-18 17:51:15 -08001949 return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
1950 } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001951 return mChildrenContainer.getMinHeight();
Adrian Roos6f6e1592017-05-02 16:22:53 -07001952 } else if (isHeadsUpAllowed() && mIsHeadsUp) {
Selim Cinek31aada42015-12-18 17:51:15 -08001953 return mHeadsUpHeight;
Selim Cinekb55386d2015-12-16 17:26:49 -08001954 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001955 NotificationContentView showingLayout = getShowingLayout();
1956 return showingLayout.getMinHeight();
1957 }
1958
1959 @Override
Selim Cinek567e8452016-03-24 10:54:56 -07001960 public int getCollapsedHeight() {
Selim Cinek2c584612016-02-29 16:14:25 -08001961 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinek567e8452016-03-24 10:54:56 -07001962 return mChildrenContainer.getCollapsedHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001963 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001964 return getMinHeight();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001965 }
1966
1967 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02001968 public void setClipTopAmount(int clipTopAmount) {
1969 super.setClipTopAmount(clipTopAmount);
Adrian Rooseb434ff2017-01-11 11:18:48 -08001970 for (NotificationContentView l : mLayouts) {
1971 l.setClipTopAmount(clipTopAmount);
1972 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001973 if (mGuts != null) {
1974 mGuts.setClipTopAmount(clipTopAmount);
1975 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001976 }
1977
Selim Cineka686b2c2016-10-26 13:58:27 -07001978 @Override
1979 public void setClipBottomAmount(int clipBottomAmount) {
Selim Cinek65d418e2016-11-29 15:42:34 -08001980 if (clipBottomAmount != mClipBottomAmount) {
1981 super.setClipBottomAmount(clipBottomAmount);
Adrian Rooseb434ff2017-01-11 11:18:48 -08001982 for (NotificationContentView l : mLayouts) {
1983 l.setClipBottomAmount(clipBottomAmount);
1984 }
Selim Cinek65d418e2016-11-29 15:42:34 -08001985 if (mGuts != null) {
1986 mGuts.setClipBottomAmount(clipBottomAmount);
1987 }
Selim Cineka686b2c2016-10-26 13:58:27 -07001988 }
Selim Cinekb3dadcc2016-11-21 17:21:13 -08001989 if (mChildrenContainer != null) {
Selim Cinek65d418e2016-11-29 15:42:34 -08001990 // We have to update this even if it hasn't changed, since the children locations can
1991 // have changed
Selim Cinekb3dadcc2016-11-21 17:21:13 -08001992 mChildrenContainer.setClipBottomAmount(clipBottomAmount);
1993 }
Selim Cineka686b2c2016-10-26 13:58:27 -07001994 }
1995
Selim Cinek31094df2014-08-14 19:28:15 +02001996 public boolean isMaxExpandHeightInitialized() {
1997 return mMaxExpandHeight != 0;
Selim Cinek7d447722014-06-10 15:51:59 +02001998 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001999
Selim Cinek42357e02016-02-24 18:48:01 -08002000 public NotificationContentView getShowingLayout() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02002001 return mShowingPublic ? mPublicLayout : mPrivateLayout;
2002 }
Chris Wren78403d72014-07-28 10:23:24 +01002003
Selim Cinek1a48bab2017-02-17 19:38:40 -08002004 public void setLegacy(boolean legacy) {
Adrian Rooseb434ff2017-01-11 11:18:48 -08002005 for (NotificationContentView l : mLayouts) {
Selim Cinek1a48bab2017-02-17 19:38:40 -08002006 l.setLegacy(legacy);
Adrian Rooseb434ff2017-01-11 11:18:48 -08002007 }
Jorim Jaggi59ec3042015-06-05 15:18:43 -07002008 }
2009
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002010 @Override
2011 protected void updateBackgroundTint() {
2012 super.updateBackgroundTint();
Mady Mellorb0a82462016-04-30 17:31:02 -07002013 updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002014 if (mIsSummaryWithChildren) {
2015 List<ExpandableNotificationRow> notificationChildren =
2016 mChildrenContainer.getNotificationChildren();
2017 for (int i = 0; i < notificationChildren.size(); i++) {
2018 ExpandableNotificationRow child = notificationChildren.get(i);
Mady Mellorb0a82462016-04-30 17:31:02 -07002019 child.updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002020 }
2021 }
2022 }
2023
Mady Mellorb0a82462016-04-30 17:31:02 -07002024 /**
2025 * Called when a group has finished animating from collapsed or expanded state.
2026 */
2027 public void onFinishedExpansionChange() {
2028 mGroupExpansionChanging = false;
2029 updateBackgroundForGroupState();
2030 }
2031
2032 /**
2033 * Updates the parent and children backgrounds in a group based on the expansion state.
2034 */
2035 public void updateBackgroundForGroupState() {
2036 if (mIsSummaryWithChildren) {
2037 // Only when the group has finished expanding do we hide its background.
Anthony Chen6bf88a02017-04-10 14:41:44 -07002038 mShowNoBackground = !mShowGroupBackgroundWhenExpanded && isGroupExpanded()
2039 && !isGroupExpansionChanging() && !isUserLocked();
Mady Mellorb0a82462016-04-30 17:31:02 -07002040 mChildrenContainer.updateHeaderForExpansion(mShowNoBackground);
2041 List<ExpandableNotificationRow> children = mChildrenContainer.getNotificationChildren();
2042 for (int i = 0; i < children.size(); i++) {
2043 children.get(i).updateBackgroundForGroupState();
2044 }
2045 } else if (isChildInGroup()) {
2046 final int childColor = getShowingLayout().getBackgroundColorForExpansionState();
2047 // Only show a background if the group is expanded OR if it is expanding / collapsing
Anthony Chen6bf88a02017-04-10 14:41:44 -07002048 // and has a custom background color.
Mady Mellorb0a82462016-04-30 17:31:02 -07002049 final boolean showBackground = isGroupExpanded()
2050 || ((mNotificationParent.isGroupExpansionChanging()
Anthony Chen6bf88a02017-04-10 14:41:44 -07002051 || mNotificationParent.isUserLocked()) && childColor != 0);
Mady Mellorb0a82462016-04-30 17:31:02 -07002052 mShowNoBackground = !showBackground;
2053 } else {
2054 // Only children or parents ever need no background.
2055 mShowNoBackground = false;
2056 }
2057 updateOutline();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002058 updateBackground();
2059 }
2060
Adrian Roos4a579672016-05-24 16:54:37 -07002061 public int getPositionOfChild(ExpandableNotificationRow childRow) {
2062 if (mIsSummaryWithChildren) {
2063 return mChildrenContainer.getPositionInLinearLayout(childRow);
2064 }
2065 return 0;
2066 }
2067
Chris Wren78403d72014-07-28 10:23:24 +01002068 public void setExpansionLogger(ExpansionLogger logger, String key) {
2069 mLogger = logger;
2070 mLoggingKey = key;
2071 }
2072
Chris Wren6abeeb92016-05-26 14:44:38 -04002073 public void onExpandedByGesture(boolean userExpanded) {
2074 int event = MetricsEvent.ACTION_NOTIFICATION_GESTURE_EXPANDER;
2075 if (mGroupManager.isSummaryOfGroup(getStatusBarNotification())) {
2076 event = MetricsEvent.ACTION_NOTIFICATION_GROUP_GESTURE_EXPANDER;
2077 }
2078 MetricsLogger.action(mContext, event, userExpanded);
2079 }
2080
Selim Cinek6183d122016-01-14 18:48:41 -08002081 @Override
Selim Cinek42357e02016-02-24 18:48:01 -08002082 public float getIncreasedPaddingAmount() {
2083 if (mIsSummaryWithChildren) {
2084 if (isGroupExpanded()) {
2085 return 1.0f;
2086 } else if (isUserLocked()) {
Selim Cinek414ad332017-02-24 19:06:12 -08002087 return mChildrenContainer.getIncreasedPaddingAmount();
Selim Cinek42357e02016-02-24 18:48:01 -08002088 }
Selim Cinek99104832017-01-25 14:47:33 -08002089 } else if (isColorized() && (!mIsLowPriority || isExpanded())) {
Selim Cineka7ed2c12017-01-23 20:47:24 -08002090 return -1.0f;
Selim Cinek42357e02016-02-24 18:48:01 -08002091 }
2092 return 0.0f;
Selim Cinek61633a82016-01-25 15:54:10 -08002093 }
2094
Selim Cineka7ed2c12017-01-23 20:47:24 -08002095 private boolean isColorized() {
Selim Cinek99104832017-01-25 14:47:33 -08002096 return mIsColorized && mBgTint != NO_COLOR;
Selim Cineka7ed2c12017-01-23 20:47:24 -08002097 }
2098
Selim Cinek61633a82016-01-25 15:54:10 -08002099 @Override
Selim Cinek6183d122016-01-14 18:48:41 -08002100 protected boolean disallowSingleClick(MotionEvent event) {
2101 float x = event.getX();
2102 float y = event.getY();
Selim Cinek34eda5e2016-02-18 17:10:43 -08002103 NotificationHeaderView header = getVisibleNotificationHeader();
Selim Cinek5d6ef8d2017-05-18 22:16:00 -07002104 if (header != null && header.isInTouchRect(x - getTranslation(), y)) {
2105 return true;
2106 }
2107 if ((!mIsSummaryWithChildren || mShowingPublic)
2108 && getShowingLayout().disallowSingleClick(x, y)) {
2109 return true;
Selim Cinek6183d122016-01-14 18:48:41 -08002110 }
2111 return super.disallowSingleClick(event);
2112 }
2113
Selim Cinek414ad332017-02-24 19:06:12 -08002114 private void onExpansionChanged(boolean userAction, boolean wasExpanded) {
Chris Wren698b1702016-05-23 11:16:32 -04002115 boolean nowExpanded = isExpanded();
Selim Cinek414ad332017-02-24 19:06:12 -08002116 if (mIsSummaryWithChildren && (!mIsLowPriority || wasExpanded)) {
Chris Wren698b1702016-05-23 11:16:32 -04002117 nowExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
2118 }
Selim Cinek414ad332017-02-24 19:06:12 -08002119 if (nowExpanded != wasExpanded) {
2120 updateShelfIconColor();
2121 if (mLogger != null) {
2122 mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded);
2123 }
2124 if (mIsSummaryWithChildren) {
2125 mChildrenContainer.onExpansionChanged();
2126 }
Chris Wren78403d72014-07-28 10:23:24 +01002127 }
2128 }
Selim Cinek570981d2015-12-01 11:37:01 -08002129
Selim Cineke9bad242016-06-15 11:46:37 -07002130 @Override
2131 public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
2132 super.onInitializeAccessibilityNodeInfoInternal(info);
2133 if (canViewBeDismissed()) {
2134 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS);
2135 }
Selim Cinekc0ac4af2017-03-03 15:13:48 -08002136 boolean expandable = mShowingPublic;
2137 boolean isExpanded = false;
2138 if (!expandable) {
2139 if (mIsSummaryWithChildren) {
2140 expandable = true;
2141 if (!mIsLowPriority || isExpanded()) {
2142 isExpanded = isGroupExpanded();
2143 }
2144 } else {
2145 expandable = mPrivateLayout.isContentExpandable();
2146 isExpanded = isExpanded();
2147 }
2148 }
2149 if (expandable) {
2150 if (isExpanded) {
2151 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE);
2152 } else {
2153 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND);
2154 }
2155 }
Selim Cineke9bad242016-06-15 11:46:37 -07002156 }
2157
2158 @Override
2159 public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
2160 if (super.performAccessibilityActionInternal(action, arguments)) {
2161 return true;
2162 }
2163 switch (action) {
2164 case AccessibilityNodeInfo.ACTION_DISMISS:
2165 NotificationStackScrollLayout.performDismiss(this, mGroupManager,
2166 true /* fromAccessibility */);
2167 return true;
Selim Cinekc0ac4af2017-03-03 15:13:48 -08002168 case AccessibilityNodeInfo.ACTION_COLLAPSE:
2169 case AccessibilityNodeInfo.ACTION_EXPAND:
2170 mExpandClickListener.onClick(this);
2171 return true;
Selim Cineke9bad242016-06-15 11:46:37 -07002172 }
2173 return false;
2174 }
2175
2176 public boolean shouldRefocusOnDismiss() {
2177 return mRefocusOnDismiss || isAccessibilityFocused();
2178 }
2179
Selim Cinek570981d2015-12-01 11:37:01 -08002180 public interface OnExpandClickListener {
Selim Cinek31aada42015-12-18 17:51:15 -08002181 void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
Selim Cinek570981d2015-12-01 11:37:01 -08002182 }
Selim Cinekbbcebde2016-11-09 18:28:20 -08002183
2184 @Override
2185 public ExpandableViewState createNewViewState(StackScrollState stackScrollState) {
2186 return new NotificationViewState(stackScrollState);
2187 }
2188
Selim Cinekd127d792016-11-01 19:11:41 -07002189 @Override
2190 public boolean isAboveShelf() {
Selim Cinekc8007c52017-02-28 16:09:56 -08002191 return !isOnKeyguard()
2192 && (mIsPinned || mHeadsupDisappearRunning || (mIsHeadsUp && mAboveShelf));
Selim Cinekd127d792016-11-01 19:11:41 -07002193 }
2194
Adrian Roos0aac04f2016-12-08 15:59:29 -08002195 public void setShowAmbient(boolean showAmbient) {
2196 if (showAmbient != mShowAmbient) {
2197 mShowAmbient = showAmbient;
Adrian Roos6f6e1592017-05-02 16:22:53 -07002198 if (mChildrenContainer != null) {
2199 mChildrenContainer.notifyShowAmbientChanged();
2200 }
Adrian Roos0aac04f2016-12-08 15:59:29 -08002201 notifyHeightChanged(false /* needsAnimation */);
2202 }
2203 }
2204
Adrian Roos6f6e1592017-05-02 16:22:53 -07002205 public boolean isShowingAmbient() {
2206 return mShowAmbient;
2207 }
2208
Selim Cinekd127d792016-11-01 19:11:41 -07002209 public void setAboveShelf(boolean aboveShelf) {
2210 mAboveShelf = aboveShelf;
2211 }
2212
Selim Cinekd4776a52017-02-14 18:50:16 -08002213 public static class NotificationViewState extends ExpandableViewState {
Selim Cinekbbcebde2016-11-09 18:28:20 -08002214
2215 private final StackScrollState mOverallState;
Selim Cinek0242fbb2016-10-19 13:38:32 -07002216
Selim Cinekbbcebde2016-11-09 18:28:20 -08002217
2218 private NotificationViewState(StackScrollState stackScrollState) {
2219 mOverallState = stackScrollState;
2220 }
2221
2222 @Override
2223 public void applyToView(View view) {
2224 super.applyToView(view);
2225 if (view instanceof ExpandableNotificationRow) {
2226 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
Selim Cinekbbcebde2016-11-09 18:28:20 -08002227 row.applyChildrenState(mOverallState);
2228 }
2229 }
Selim Cinek0cfbef42016-11-09 19:06:36 -08002230
2231 @Override
Selim Cinek2b549f42016-11-22 16:38:51 -08002232 protected void onYTranslationAnimationFinished(View view) {
2233 super.onYTranslationAnimationFinished(view);
Selim Cinekd4776a52017-02-14 18:50:16 -08002234 if (view instanceof ExpandableNotificationRow) {
2235 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
2236 if (row.isHeadsUpAnimatingAway()) {
2237 row.setHeadsUpAnimatingAway(false);
2238 }
Selim Cinek0cfbef42016-11-09 19:06:36 -08002239 }
2240 }
2241
2242 @Override
2243 public void animateTo(View child, AnimationProperties properties) {
2244 super.animateTo(child, properties);
2245 if (child instanceof ExpandableNotificationRow) {
2246 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
2247 row.startChildAnimation(mOverallState, properties);
2248 }
2249 }
Selim Cinekbbcebde2016-11-09 18:28:20 -08002250 }
Selim Cinek817abe72017-05-24 11:08:55 -07002251
2252 @VisibleForTesting
2253 protected void setChildrenContainer(NotificationChildrenContainer childrenContainer) {
2254 mChildrenContainer = childrenContainer;
2255 }
Chris Wren51c75102013-07-16 20:49:17 -04002256}