blob: 9176f57c35ccc471e3b9b06a6351b449fed86e68 [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 Cinekc478f902017-02-22 20:55:44 -080019import static com.android.systemui.statusbar.notification.NotificationInflater.InflationExceptionHandler;
20
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;
Selim Cinekcab4a602014-09-03 14:47:57 +020027import android.graphics.drawable.AnimatedVectorDrawable;
28import android.graphics.drawable.AnimationDrawable;
Selim Cinekb5605e52015-02-20 18:21:41 +010029import android.graphics.drawable.ColorDrawable;
Selim Cinekcab4a602014-09-03 14:47:57 +020030import android.graphics.drawable.Drawable;
Selim Cinekda42d652015-12-04 15:51:16 -080031import android.os.Build;
Selim Cineke9bad242016-06-15 11:46:37 -070032import android.os.Bundle;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020033import android.service.notification.StatusBarNotification;
Chris Wren51c75102013-07-16 20:49:17 -040034import android.util.AttributeSet;
Mady Mellorb0a82462016-04-30 17:31:02 -070035import android.util.FloatProperty;
36import android.util.Property;
Selim Cinek01af3342016-02-09 19:25:31 -080037import android.view.LayoutInflater;
Selim Cinek6183d122016-01-14 18:48:41 -080038import android.view.MotionEvent;
Selim Cinekeaa29ca2015-11-23 13:51:13 -080039import android.view.NotificationHeaderView;
Dan Sandlera5e0f412014-01-23 15:11:54 -050040import android.view.View;
Selim Cinek875a3a12016-11-18 17:52:16 -080041import android.view.ViewGroup;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020042import android.view.ViewStub;
Jorim Jaggife40f7d2014-04-28 15:20:04 +020043import android.view.accessibility.AccessibilityEvent;
Selim Cineke9bad242016-06-15 11:46:37 -070044import android.view.accessibility.AccessibilityNodeInfo;
Selim Cinek98713a42015-09-21 15:47:20 +020045import android.widget.Chronometer;
Mady Mellor95d743c2017-01-10 12:05:27 -080046import android.widget.FrameLayout;
Selim Cinekcab4a602014-09-03 14:47:57 +020047import android.widget.ImageView;
Selim Cinek1a48bab2017-02-17 19:38:40 -080048import android.widget.RemoteViews;
Selim Cinekb5605e52015-02-20 18:21:41 +010049
Chris Wren698b1702016-05-23 11:16:32 -040050import com.android.internal.logging.MetricsLogger;
Tamas Berghammer383db5eb2016-06-22 15:21:38 +010051import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Selim Cinek4bb59342016-04-08 19:29:35 -070052import com.android.internal.util.NotificationColorUtil;
Selim Cinek875a3a12016-11-18 17:52:16 -080053import com.android.internal.widget.CachingIconView;
Mady Mellor95d743c2017-01-10 12:05:27 -080054import com.android.systemui.Dependency;
Selim Cinek0242fbb2016-10-19 13:38:32 -070055import com.android.systemui.Interpolators;
Dan Sandlera5e0f412014-01-23 15:11:54 -050056import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070057import com.android.systemui.classifier.FalsingManager;
Mady Mellor95d743c2017-01-10 12:05:27 -080058import com.android.systemui.plugins.PluginListener;
59import com.android.systemui.plugins.PluginManager;
60import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
61import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem;
62import com.android.systemui.statusbar.NotificationGuts.GutsContent;
Selim Cinekc897bd32016-03-18 17:32:31 -070063import com.android.systemui.statusbar.notification.HybridNotificationView;
Selim Cinek1a48bab2017-02-17 19:38:40 -080064import com.android.systemui.statusbar.notification.InflationException;
65import com.android.systemui.statusbar.notification.NotificationInflater;
Selim Cinek6743c0b2017-01-18 18:24:01 -080066import com.android.systemui.statusbar.notification.NotificationUtils;
Selim Cineka7d4f822016-12-06 14:34:47 -080067import com.android.systemui.statusbar.notification.VisualStabilityManager;
Selim Cinekb5605e52015-02-20 18:21:41 +010068import com.android.systemui.statusbar.phone.NotificationGroupManager;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050069import com.android.systemui.statusbar.phone.StatusBar;
Selim Cinek31aada42015-12-18 17:51:15 -080070import com.android.systemui.statusbar.policy.HeadsUpManager;
Selim Cinek0cfbef42016-11-09 19:06:36 -080071import com.android.systemui.statusbar.stack.AnimationProperties;
72import com.android.systemui.statusbar.stack.ExpandableViewState;
Selim Cinekb5605e52015-02-20 18:21:41 +010073import com.android.systemui.statusbar.stack.NotificationChildrenContainer;
Selim Cineke9bad242016-06-15 11:46:37 -070074import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Selim Cinekb5605e52015-02-20 18:21:41 +010075import com.android.systemui.statusbar.stack.StackScrollState;
Selim Cinekb5605e52015-02-20 18:21:41 +010076
Mady Mellor4b80b102016-01-22 08:03:58 -080077import java.util.ArrayList;
Selim Cinekb5605e52015-02-20 18:21:41 +010078import java.util.List;
Dan Sandlera5e0f412014-01-23 15:11:54 -050079
Mady Mellor95d743c2017-01-10 12:05:27 -080080public class ExpandableNotificationRow extends ActivatableNotificationView
81 implements PluginListener<NotificationMenuRowPlugin> {
Selim Cinekb5605e52015-02-20 18:21:41 +010082
83 private static final int DEFAULT_DIVIDER_ALPHA = 0x29;
84 private static final int COLORED_DIVIDER_ALPHA = 0x7B;
Mady Mellor95d743c2017-01-10 12:05:27 -080085 private static final int MENU_VIEW_INDEX = 0;
86
Selim Cinek1a48bab2017-02-17 19:38:40 -080087 private final NotificationInflater mNotificationInflater;
Selim Cinek0242fbb2016-10-19 13:38:32 -070088 private int mIconTransformContentShift;
Selim Cinek875a3a12016-11-18 17:52:16 -080089 private int mIconTransformContentShiftNoIcon;
Selim Cinek01af3342016-02-09 19:25:31 -080090 private int mNotificationMinHeightLegacy;
91 private int mMaxHeadsUpHeightLegacy;
92 private int mMaxHeadsUpHeight;
Selim Cinek87ed69b2017-02-09 15:59:43 -080093 private int mMaxHeadsUpHeightIncreased;
Selim Cinek01af3342016-02-09 19:25:31 -080094 private int mNotificationMinHeight;
Selim Cinek7d1009b2017-01-25 15:28:28 -080095 private int mNotificationMinHeightLarge;
Selim Cinek01af3342016-02-09 19:25:31 -080096 private int mNotificationMaxHeight;
Adrian Roos0aac04f2016-12-08 15:59:29 -080097 private int mNotificationAmbientHeight;
Mady Mellorb0a82462016-04-30 17:31:02 -070098 private int mIncreasedPaddingBetweenElements;
Chris Wren51c75102013-07-16 20:49:17 -040099
Selim Cinek1685e632014-04-08 02:27:49 +0200100 /** Does this row contain layouts that can adapt to row expansion */
Chris Wren51c75102013-07-16 20:49:17 -0400101 private boolean mExpandable;
Selim Cinek1685e632014-04-08 02:27:49 +0200102 /** Has the user actively changed the expansion state of this row */
103 private boolean mHasUserChangedExpansion;
104 /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */
Chris Wren51c75102013-07-16 20:49:17 -0400105 private boolean mUserExpanded;
Selim Cinek31aada42015-12-18 17:51:15 -0800106
107 /**
108 * Has this notification been expanded while it was pinned
109 */
110 private boolean mExpandedWhenPinned;
Selim Cinek1685e632014-04-08 02:27:49 +0200111 /** Is the user touching this row */
Chris Wren51c75102013-07-16 20:49:17 -0400112 private boolean mUserLocked;
Selim Cinek1685e632014-04-08 02:27:49 +0200113 /** Are we showing the "public" version */
Dan Sandlera5e0f412014-01-23 15:11:54 -0500114 private boolean mShowingPublic;
Jorim Jaggiae441282014-08-01 02:45:18 +0200115 private boolean mSensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -0800116 private boolean mSensitiveHiddenInGeneral;
Jorim Jaggiae441282014-08-01 02:45:18 +0200117 private boolean mShowingPublicInitialized;
Selim Cinek60122be2015-04-15 18:16:50 -0700118 private boolean mHideSensitiveForIntrinsicHeight;
Chris Wren51c75102013-07-16 20:49:17 -0400119
Selim Cinek1685e632014-04-08 02:27:49 +0200120 /**
121 * Is this notification expanded by the system. The expansion state can be overridden by the
122 * user expansion.
123 */
124 private boolean mIsSystemExpanded;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200125
126 /**
Selim Cinek83bc7832015-10-22 13:26:54 -0700127 * Whether the notification is on the keyguard and the expansion is disabled.
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200128 */
Selim Cinek83bc7832015-10-22 13:26:54 -0700129 private boolean mOnKeyguard;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200130
Mady Mellorb0a82462016-04-30 17:31:02 -0700131 private Animator mTranslateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -0800132 private ArrayList<View> mTranslateableViews;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200133 private NotificationContentView mPublicLayout;
134 private NotificationContentView mPrivateLayout;
Adrian Rooseb434ff2017-01-11 11:18:48 -0800135 private NotificationContentView[] mLayouts;
Selim Cinek1685e632014-04-08 02:27:49 +0200136 private int mMaxExpandHeight;
Selim Cinek8d490d42015-04-10 00:05:50 -0700137 private int mHeadsUpHeight;
Selim Cinek4bb59342016-04-08 19:29:35 -0700138 private int mNotificationColor;
Chris Wren78403d72014-07-28 10:23:24 +0100139 private ExpansionLogger mLogger;
140 private String mLoggingKey;
Selim Cinek8d490d42015-04-10 00:05:50 -0700141 private NotificationGuts mGuts;
Selim Cinekda42d652015-12-04 15:51:16 -0800142 private NotificationData.Entry mEntry;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200143 private StatusBarNotification mStatusBarNotification;
Mady Mellor3fd273e2016-03-15 21:08:14 -0700144 private String mAppName;
Selim Cinek1a521f32014-11-03 17:39:29 +0100145 private boolean mIsHeadsUp;
Selim Cinek98713a42015-09-21 15:47:20 +0200146 private boolean mLastChronometerRunning = true;
Selim Cinekb5605e52015-02-20 18:21:41 +0100147 private ViewStub mChildrenContainerStub;
148 private NotificationGroupManager mGroupManager;
Selim Cinekb5605e52015-02-20 18:21:41 +0100149 private boolean mChildrenExpanded;
Selim Cinek263398f2015-10-21 17:40:23 -0700150 private boolean mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100151 private NotificationChildrenContainer mChildrenContainer;
Mady Mellor95d743c2017-01-10 12:05:27 -0800152 private NotificationMenuRowPlugin mMenuRow;
Selim Cinekab29aeb2015-02-20 18:18:32 +0100153 private ViewStub mGutsStub;
Selim Cinekb5605e52015-02-20 18:21:41 +0100154 private boolean mIsSystemChildExpanded;
Selim Cinek684a4422015-04-15 16:18:39 -0700155 private boolean mIsPinned;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700156 private FalsingManager mFalsingManager;
Selim Cinek31aada42015-12-18 17:51:15 -0800157 private HeadsUpManager mHeadsUpManager;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200158
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700159 private boolean mJustClicked;
Selim Cinek5a175d92015-11-23 18:01:33 -0800160 private boolean mIconAnimationRunning;
Selim Cinek34d93b02015-10-22 12:30:38 -0700161 private boolean mShowNoBackground;
Selim Cinek388df6d2015-10-22 13:25:11 -0700162 private ExpandableNotificationRow mNotificationParent;
Selim Cinek570981d2015-12-01 11:37:01 -0800163 private OnExpandClickListener mOnExpandClickListener;
Mady Mellorb0a82462016-04-30 17:31:02 -0700164 private boolean mGroupExpansionChanging;
165
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800166 private OnClickListener mExpandClickListener = new OnClickListener() {
167 @Override
168 public void onClick(View v) {
Selim Cinek414ad332017-02-24 19:06:12 -0800169 if (!mShowingPublic && (!mIsLowPriority || isExpanded())
170 && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) {
Mady Mellor1a5d8ea2016-06-09 10:42:42 -0700171 mGroupExpansionChanging = true;
Chris Wren698b1702016-05-23 11:16:32 -0400172 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
173 boolean nowExpanded = mGroupManager.toggleGroupExpansion(mStatusBarNotification);
174 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400175 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_GROUP_EXPANDER,
176 nowExpanded);
Selim Cinek414ad332017-02-24 19:06:12 -0800177 onExpansionChanged(true /* userAction */, wasExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800178 } else {
Selim Cineke9bad242016-06-15 11:46:37 -0700179 if (v.isAccessibilityFocused()) {
180 mPrivateLayout.setFocusOnVisibilityChange();
181 }
Selim Cinek31aada42015-12-18 17:51:15 -0800182 boolean nowExpanded;
183 if (isPinned()) {
184 nowExpanded = !mExpandedWhenPinned;
185 mExpandedWhenPinned = nowExpanded;
186 } else {
187 nowExpanded = !isExpanded();
188 setUserExpanded(nowExpanded);
189 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800190 notifyHeightChanged(true);
Selim Cinek31aada42015-12-18 17:51:15 -0800191 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400192 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_EXPANDER,
193 nowExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800194 }
195 }
196 };
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700197 private boolean mForceUnlocked;
Selim Cinek3f19f602016-05-02 18:01:56 -0700198 private boolean mDismissed;
199 private boolean mKeepInParent;
200 private boolean mRemoved;
Mady Mellorb0a82462016-04-30 17:31:02 -0700201 private static final Property<ExpandableNotificationRow, Float> TRANSLATE_CONTENT =
202 new FloatProperty<ExpandableNotificationRow>("translate") {
203 @Override
204 public void setValue(ExpandableNotificationRow object, float value) {
205 object.setTranslation(value);
206 }
207
208 @Override
209 public Float get(ExpandableNotificationRow object) {
210 return object.getTranslation();
211 }
212 };
Selim Cinekddf1b392016-05-27 16:33:10 -0700213 private OnClickListener mOnClickListener;
Selim Cinek73cf02a2016-06-17 13:08:00 -0700214 private boolean mHeadsupDisappearRunning;
Selim Cineke9bad242016-06-15 11:46:37 -0700215 private View mChildAfterViewWhenDismissed;
216 private View mGroupParentWhenDismissed;
217 private boolean mRefocusOnDismiss;
Selim Cinek2b549f42016-11-22 16:38:51 -0800218 private float mContentTransformationAmount;
Selim Cinek0242fbb2016-10-19 13:38:32 -0700219 private boolean mIconsVisible = true;
Selim Cinekd127d792016-11-01 19:11:41 -0700220 private boolean mAboveShelf;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800221 private boolean mShowAmbient;
Selim Cinek875a3a12016-11-18 17:52:16 -0800222 private boolean mIsLastChild;
Selim Cineke9079112016-12-14 14:41:01 -0800223 private Runnable mOnDismissRunnable;
Selim Cinek6743c0b2017-01-18 18:24:01 -0800224 private boolean mIsLowPriority;
Selim Cineka7ed2c12017-01-23 20:47:24 -0800225 private boolean mIsColorized;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800226 private boolean mUseIncreasedCollapsedHeight;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800227 private boolean mUseIncreasedHeadsUpHeight;
Selim Cinekef8c2252017-02-10 14:52:18 -0800228 private float mTranslationWhenRemoved;
229 private boolean mWasChildInGroupWhenRemoved;
Mady Mellorb0a82462016-04-30 17:31:02 -0700230
Mady Mellor43c2cd12016-12-12 21:05:13 -0800231 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -0700232 public boolean isGroupExpansionChanging() {
233 if (isChildInGroup()) {
234 return mNotificationParent.isGroupExpansionChanging();
235 }
236 return mGroupExpansionChanging;
237 }
238
239 public void setGroupExpansionChanging(boolean changing) {
240 mGroupExpansionChanging = changing;
241 }
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700242
Adrian Roos599be342016-06-13 14:54:39 -0700243 @Override
244 public void setActualHeightAnimating(boolean animating) {
245 if (mPrivateLayout != null) {
246 mPrivateLayout.setContentHeightAnimating(animating);
247 }
248 }
249
Selim Cinek8d490d42015-04-10 00:05:50 -0700250 public NotificationContentView getPrivateLayout() {
251 return mPrivateLayout;
252 }
253
254 public NotificationContentView getPublicLayout() {
255 return mPublicLayout;
256 }
257
Selim Cinekcab4a602014-09-03 14:47:57 +0200258 public void setIconAnimationRunning(boolean running) {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800259 for (NotificationContentView l : mLayouts) {
260 setIconAnimationRunning(running, l);
261 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800262 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700263 setIconAnimationRunningForChild(running, mChildrenContainer.getHeaderView());
Selim Cinek414ad332017-02-24 19:06:12 -0800264 setIconAnimationRunningForChild(running, mChildrenContainer.getLowPriorityHeaderView());
Selim Cinek5a175d92015-11-23 18:01:33 -0800265 List<ExpandableNotificationRow> notificationChildren =
266 mChildrenContainer.getNotificationChildren();
267 for (int i = 0; i < notificationChildren.size(); i++) {
268 ExpandableNotificationRow child = notificationChildren.get(i);
269 child.setIconAnimationRunning(running);
270 }
271 }
272 mIconAnimationRunning = running;
Selim Cinekcab4a602014-09-03 14:47:57 +0200273 }
274
275 private void setIconAnimationRunning(boolean running, NotificationContentView layout) {
276 if (layout != null) {
277 View contractedChild = layout.getContractedChild();
278 View expandedChild = layout.getExpandedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -0700279 View headsUpChild = layout.getHeadsUpChild();
Selim Cinekcab4a602014-09-03 14:47:57 +0200280 setIconAnimationRunningForChild(running, contractedChild);
281 setIconAnimationRunningForChild(running, expandedChild);
Selim Cinek8d490d42015-04-10 00:05:50 -0700282 setIconAnimationRunningForChild(running, headsUpChild);
Selim Cinekcab4a602014-09-03 14:47:57 +0200283 }
284 }
285
286 private void setIconAnimationRunningForChild(boolean running, View child) {
287 if (child != null) {
288 ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon);
289 setIconRunning(icon, running);
290 ImageView rightIcon = (ImageView) child.findViewById(
291 com.android.internal.R.id.right_icon);
292 setIconRunning(rightIcon, running);
293 }
294 }
295
296 private void setIconRunning(ImageView imageView, boolean running) {
297 if (imageView != null) {
298 Drawable drawable = imageView.getDrawable();
299 if (drawable instanceof AnimationDrawable) {
300 AnimationDrawable animationDrawable = (AnimationDrawable) drawable;
301 if (running) {
302 animationDrawable.start();
303 } else {
304 animationDrawable.stop();
305 }
306 } else if (drawable instanceof AnimatedVectorDrawable) {
307 AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable;
308 if (running) {
309 animationDrawable.start();
310 } else {
311 animationDrawable.stop();
312 }
313 }
314 }
315 }
316
Selim Cinek1a48bab2017-02-17 19:38:40 -0800317 public void updateNotification(NotificationData.Entry entry) throws InflationException {
Selim Cinekda42d652015-12-04 15:51:16 -0800318 mEntry = entry;
319 mStatusBarNotification = entry.notification;
Selim Cinek1a48bab2017-02-17 19:38:40 -0800320 mNotificationInflater.inflateNotificationViews();
Selim Cinekc478f902017-02-22 20:55:44 -0800321 onNotificationUpdated();
322 }
323
324 private void onNotificationUpdated() {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800325 for (NotificationContentView l : mLayouts) {
Selim Cinekc478f902017-02-22 20:55:44 -0800326 l.onNotificationUpdated(mEntry);
Adrian Rooseb434ff2017-01-11 11:18:48 -0800327 }
Selim Cineka7ed2c12017-01-23 20:47:24 -0800328 mIsColorized = mStatusBarNotification.getNotification().isColorized();
Selim Cinek757d8792016-01-28 16:21:08 -0800329 mShowingPublicInitialized = false;
Selim Cinek4bb59342016-04-08 19:29:35 -0700330 updateNotificationColor();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800331 if (mIsSummaryWithChildren) {
Selim Cinek414ad332017-02-24 19:06:12 -0800332 mChildrenContainer.recreateNotificationHeader(mExpandClickListener);
Selim Cinekc897bd32016-03-18 17:32:31 -0700333 mChildrenContainer.onNotificationUpdated();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800334 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800335 if (mIconAnimationRunning) {
336 setIconAnimationRunning(true);
337 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800338 if (mNotificationParent != null) {
339 mNotificationParent.updateChildrenHeaderAppearance();
340 }
Selim Cinek263398f2015-10-21 17:40:23 -0700341 onChildrenCountChanged();
Selim Cinek624c02db2015-12-14 21:00:02 -0800342 // The public layouts expand button is always visible
343 mPublicLayout.updateExpandButtons(true);
Selim Cinekda42d652015-12-04 15:51:16 -0800344 updateLimits();
Selim Cinek0242fbb2016-10-19 13:38:32 -0700345 updateIconVisibilities();
Selim Cinek6743c0b2017-01-18 18:24:01 -0800346 updateShelfIconColor();
347 }
348
349 private void updateShelfIconColor() {
350 StatusBarIconView expandedIcon = mEntry.expandedIcon;
351 boolean isPreL = Boolean.TRUE.equals(expandedIcon.getTag(R.id.icon_is_pre_L));
352 boolean colorize = !isPreL || NotificationUtils.isGrayscale(expandedIcon,
353 NotificationColorUtil.getInstance(mContext));
Selim Cinek875ba9b2017-02-13 16:20:17 -0800354 int color = StatusBarIconView.NO_COLOR;
Selim Cinek6743c0b2017-01-18 18:24:01 -0800355 if (colorize) {
Selim Cinek875ba9b2017-02-13 16:20:17 -0800356 color = mEntry.getContrastedColor(mContext, mIsLowPriority && !isExpanded());
Selim Cinek6743c0b2017-01-18 18:24:01 -0800357 }
Selim Cinek875ba9b2017-02-13 16:20:17 -0800358 expandedIcon.setStaticDrawableColor(color);
Selim Cinekda42d652015-12-04 15:51:16 -0800359 }
360
361 private void updateLimits() {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800362 for (NotificationContentView l : mLayouts) {
363 updateLimitsForView(l);
364 }
Selim Cineka1744872016-03-11 15:36:06 -0800365 }
366
367 private void updateLimitsForView(NotificationContentView layout) {
368 boolean customView = layout.getContractedChild().getId()
Selim Cinekda42d652015-12-04 15:51:16 -0800369 != com.android.internal.R.id.status_bar_latest_event_content;
370 boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800371 int minHeight;
372 if (customView && beforeN && !mIsSummaryWithChildren) {
373 minHeight = mNotificationMinHeightLegacy;
374 } else if (mUseIncreasedCollapsedHeight && layout == mPrivateLayout) {
375 minHeight = mNotificationMinHeightLarge;
376 } else {
377 minHeight = mNotificationMinHeight;
378 }
Selim Cineka1744872016-03-11 15:36:06 -0800379 boolean headsUpCustom = layout.getHeadsUpChild() != null &&
380 layout.getHeadsUpChild().getId()
381 != com.android.internal.R.id.status_bar_latest_event_content;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800382 int headsUpheight;
383 if (headsUpCustom && beforeN) {
384 headsUpheight = mMaxHeadsUpHeightLegacy;
385 } else if (mUseIncreasedHeadsUpHeight && layout == mPrivateLayout) {
386 headsUpheight = mMaxHeadsUpHeightIncreased;
387 } else {
388 headsUpheight = mMaxHeadsUpHeight;
389 }
Adrian Roos0aac04f2016-12-08 15:59:29 -0800390 layout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight,
391 mNotificationAmbientHeight);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200392 }
393
394 public StatusBarNotification getStatusBarNotification() {
395 return mStatusBarNotification;
396 }
397
Selim Cinek281c2022016-10-13 19:14:43 -0700398 public NotificationData.Entry getEntry() {
399 return mEntry;
400 }
401
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700402 public boolean isHeadsUp() {
403 return mIsHeadsUp;
404 }
405
Selim Cinek1a521f32014-11-03 17:39:29 +0100406 public void setHeadsUp(boolean isHeadsUp) {
Selim Cinekc80fdb12015-04-13 15:09:08 -0700407 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek1a521f32014-11-03 17:39:29 +0100408 mIsHeadsUp = isHeadsUp;
Selim Cinek8d490d42015-04-10 00:05:50 -0700409 mPrivateLayout.setHeadsUp(isHeadsUp);
Selim Cinekb41b2f62016-04-26 14:03:29 -0700410 if (mIsSummaryWithChildren) {
411 // The overflow might change since we allow more lines as HUN.
412 mChildrenContainer.updateGroupOverflow();
413 }
Selim Cinekc80fdb12015-04-13 15:09:08 -0700414 if (intrinsicBefore != getIntrinsicHeight()) {
415 notifyHeightChanged(false /* needsAnimation */);
416 }
Selim Cinekd127d792016-11-01 19:11:41 -0700417 if (isHeadsUp) {
418 setAboveShelf(true);
419 }
Selim Cinek1a521f32014-11-03 17:39:29 +0100420 }
421
Selim Cinekb5605e52015-02-20 18:21:41 +0100422 public void setGroupManager(NotificationGroupManager groupManager) {
423 mGroupManager = groupManager;
Selim Cinek83bc7832015-10-22 13:26:54 -0700424 mPrivateLayout.setGroupManager(groupManager);
Selim Cinekb5605e52015-02-20 18:21:41 +0100425 }
426
Adrian Roosb88b1a12015-12-09 18:51:05 -0800427 public void setRemoteInputController(RemoteInputController r) {
428 mPrivateLayout.setRemoteInputController(r);
429 }
430
Mady Mellor3fd273e2016-03-15 21:08:14 -0700431 public void setAppName(String appName) {
432 mAppName = appName;
Mady Mellor95d743c2017-01-10 12:05:27 -0800433 if (mMenuRow != null && mMenuRow.getMenuView() != null) {
Mady Mellor761cde12017-01-10 11:36:39 -0800434 mMenuRow.setAppName(mAppName);
Mady Mellor3fd273e2016-03-15 21:08:14 -0700435 }
436 }
437
Selim Cinekb5605e52015-02-20 18:21:41 +0100438 public void addChildNotification(ExpandableNotificationRow row) {
439 addChildNotification(row, -1);
440 }
441
442 /**
443 * Add a child notification to this view.
444 *
445 * @param row the row to add
446 * @param childIndex the index to add it at, if -1 it will be added at the end
447 */
448 public void addChildNotification(ExpandableNotificationRow row, int childIndex) {
449 if (mChildrenContainer == null) {
450 mChildrenContainerStub.inflate();
451 }
452 mChildrenContainer.addNotification(row, childIndex);
Selim Cinek263398f2015-10-21 17:40:23 -0700453 onChildrenCountChanged();
454 row.setIsChildInGroup(true, this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100455 }
456
457 public void removeChildNotification(ExpandableNotificationRow row) {
458 if (mChildrenContainer != null) {
459 mChildrenContainer.removeNotification(row);
460 }
Selim Cinek263398f2015-10-21 17:40:23 -0700461 onChildrenCountChanged();
462 row.setIsChildInGroup(false, null);
463 }
464
Mady Mellor43c2cd12016-12-12 21:05:13 -0800465 @Override
Selim Cinek263398f2015-10-21 17:40:23 -0700466 public boolean isChildInGroup() {
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700467 return mNotificationParent != null;
Selim Cinek263398f2015-10-21 17:40:23 -0700468 }
469
Selim Cinek388df6d2015-10-22 13:25:11 -0700470 public ExpandableNotificationRow getNotificationParent() {
471 return mNotificationParent;
472 }
473
Selim Cinek263398f2015-10-21 17:40:23 -0700474 /**
475 * @param isChildInGroup Is this notification now in a group
476 * @param parent the new parent notification
477 */
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700478 public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500479 boolean childInGroup = StatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup;
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700480 mNotificationParent = childInGroup ? parent : null;
481 mPrivateLayout.setIsChildInGroup(childInGroup);
Selim Cinekc478f902017-02-22 20:55:44 -0800482 if (mNotificationInflater.setIsChildInGroup(childInGroup)) {
483 onNotificationUpdated();
484 }
Mady Mellorc7d65b42016-05-04 11:44:57 -0400485 resetBackgroundAlpha();
Mady Mellorb0a82462016-04-30 17:31:02 -0700486 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -0700487 updateClickAndFocus();
Mady Mellorb0a82462016-04-30 17:31:02 -0700488 if (mNotificationParent != null) {
Selim Cinek9ce32852017-02-15 16:21:10 -0800489 setOverrideTintColor(NO_COLOR, 0.0f);
Mady Mellorb0a82462016-04-30 17:31:02 -0700490 mNotificationParent.updateBackgroundForGroupState();
491 }
Selim Cinekdb167372016-11-17 15:41:17 -0800492 updateIconVisibilities();
Selim Cinek34d93b02015-10-22 12:30:38 -0700493 }
494
495 @Override
Selim Cinek72109472016-01-15 16:33:22 -0800496 public boolean onTouchEvent(MotionEvent event) {
497 if (event.getActionMasked() != MotionEvent.ACTION_DOWN
498 || !isChildInGroup() || isGroupExpanded()) {
499 return super.onTouchEvent(event);
500 } else {
501 return false;
502 }
503 }
504
505 @Override
Mady Mellorf0625802016-02-11 18:03:48 -0800506 protected boolean handleSlideBack() {
Mady Mellor95d743c2017-01-10 12:05:27 -0800507 if (mMenuRow != null && mMenuRow.isMenuVisible()) {
Mady Mellorf0625802016-02-11 18:03:48 -0800508 animateTranslateNotification(0 /* targetLeft */);
509 return true;
510 }
511 return false;
512 }
513
514 @Override
Selim Cinek34d93b02015-10-22 12:30:38 -0700515 protected boolean shouldHideBackground() {
516 return super.shouldHideBackground() || mShowNoBackground;
Selim Cinek263398f2015-10-21 17:40:23 -0700517 }
518
519 @Override
520 public boolean isSummaryWithChildren() {
521 return mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100522 }
523
524 @Override
525 public boolean areChildrenExpanded() {
526 return mChildrenExpanded;
527 }
528
529 public List<ExpandableNotificationRow> getNotificationChildren() {
530 return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren();
531 }
532
Selim Cinekeef84282015-10-30 16:28:00 -0700533 public int getNumberOfNotificationChildren() {
534 if (mChildrenContainer == null) {
535 return 0;
536 }
537 return mChildrenContainer.getNotificationChildren().size();
538 }
539
Selim Cinekb5605e52015-02-20 18:21:41 +0100540 /**
541 * Apply the order given in the list to the children.
542 *
543 * @param childOrder the new list order
Selim Cineka7d4f822016-12-06 14:34:47 -0800544 * @param visualStabilityManager
545 * @param callback the callback to invoked in case it is not allowed
Selim Cinekb5605e52015-02-20 18:21:41 +0100546 * @return whether the list order has changed
547 */
Selim Cineka7d4f822016-12-06 14:34:47 -0800548 public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder,
549 VisualStabilityManager visualStabilityManager,
550 VisualStabilityManager.Callback callback) {
551 return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder,
552 visualStabilityManager, callback);
Selim Cinekb5605e52015-02-20 18:21:41 +0100553 }
554
555 public void getChildrenStates(StackScrollState resultState) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700556 if (mIsSummaryWithChildren) {
Selim Cinekbbcebde2016-11-09 18:28:20 -0800557 ExpandableViewState parentState = resultState.getViewStateForView(this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100558 mChildrenContainer.getState(resultState, parentState);
559 }
560 }
561
562 public void applyChildrenState(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700563 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100564 mChildrenContainer.applyState(state);
565 }
566 }
567
568 public void prepareExpansionChanged(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700569 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100570 mChildrenContainer.prepareExpansionChanged(state);
571 }
572 }
573
Selim Cinek0cfbef42016-11-09 19:06:36 -0800574 public void startChildAnimation(StackScrollState finalState, AnimationProperties properties) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700575 if (mIsSummaryWithChildren) {
Selim Cinek0cfbef42016-11-09 19:06:36 -0800576 mChildrenContainer.startAnimationToState(finalState, properties);
Selim Cinekb5605e52015-02-20 18:21:41 +0100577 }
578 }
579
580 public ExpandableNotificationRow getViewAtPosition(float y) {
Selim Cinek43d30f02016-03-04 10:51:32 -0800581 if (!mIsSummaryWithChildren || !mChildrenExpanded) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100582 return this;
583 } else {
584 ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y);
585 return view == null ? this : view;
586 }
587 }
588
Selim Cinekab29aeb2015-02-20 18:18:32 +0100589 public NotificationGuts getGuts() {
590 return mGuts;
591 }
592
Selim Cinek684a4422015-04-15 16:18:39 -0700593 /**
594 * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this
595 * the notification will be rendered on top of the screen.
596 *
597 * @param pinned whether it is pinned
598 */
599 public void setPinned(boolean pinned) {
Selim Cinekdef35a82016-05-03 15:52:51 -0700600 int intrinsicHeight = getIntrinsicHeight();
Selim Cinek684a4422015-04-15 16:18:39 -0700601 mIsPinned = pinned;
Selim Cinekdef35a82016-05-03 15:52:51 -0700602 if (intrinsicHeight != getIntrinsicHeight()) {
Selim Cinekbb42b7d2016-08-10 13:02:38 -0700603 notifyHeightChanged(false /* needsAnimation */);
Selim Cinekdef35a82016-05-03 15:52:51 -0700604 }
Selim Cinek31aada42015-12-18 17:51:15 -0800605 if (pinned) {
606 setIconAnimationRunning(true);
607 mExpandedWhenPinned = false;
608 } else if (mExpandedWhenPinned) {
609 setUserExpanded(true);
610 }
Selim Cinek98713a42015-09-21 15:47:20 +0200611 setChronometerRunning(mLastChronometerRunning);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700612 }
613
Selim Cinek684a4422015-04-15 16:18:39 -0700614 public boolean isPinned() {
615 return mIsPinned;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700616 }
617
Selim Cinekd127d792016-11-01 19:11:41 -0700618 @Override
619 public int getPinnedHeadsUpHeight() {
620 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
621 }
622
Selim Cinek31aada42015-12-18 17:51:15 -0800623 /**
624 * @param atLeastMinHeight should the value returned be at least the minimum height.
625 * Used to avoid cyclic calls
626 * @return the height of the heads up notification when pinned
627 */
Selim Cinekd127d792016-11-01 19:11:41 -0700628 private int getPinnedHeadsUpHeight(boolean atLeastMinHeight) {
Selim Cinek77019c72015-12-09 10:18:02 -0800629 if (mIsSummaryWithChildren) {
630 return mChildrenContainer.getIntrinsicHeight();
631 }
Selim Cinek31aada42015-12-18 17:51:15 -0800632 if(mExpandedWhenPinned) {
633 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
634 } else if (atLeastMinHeight) {
Selim Cinek567e8452016-03-24 10:54:56 -0700635 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek31aada42015-12-18 17:51:15 -0800636 } else {
637 return mHeadsUpHeight;
638 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700639 }
640
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700641 /**
642 * Mark whether this notification was just clicked, i.e. the user has just clicked this
643 * notification in this frame.
644 */
645 public void setJustClicked(boolean justClicked) {
646 mJustClicked = justClicked;
647 }
648
649 /**
650 * @return true if this notification has been clicked in this frame, false otherwise
651 */
652 public boolean wasJustClicked() {
653 return mJustClicked;
654 }
655
Selim Cinek98713a42015-09-21 15:47:20 +0200656 public void setChronometerRunning(boolean running) {
657 mLastChronometerRunning = running;
658 setChronometerRunning(running, mPrivateLayout);
659 setChronometerRunning(running, mPublicLayout);
660 if (mChildrenContainer != null) {
661 List<ExpandableNotificationRow> notificationChildren =
662 mChildrenContainer.getNotificationChildren();
663 for (int i = 0; i < notificationChildren.size(); i++) {
664 ExpandableNotificationRow child = notificationChildren.get(i);
665 child.setChronometerRunning(running);
666 }
667 }
668 }
669
670 private void setChronometerRunning(boolean running, NotificationContentView layout) {
671 if (layout != null) {
672 running = running || isPinned();
673 View contractedChild = layout.getContractedChild();
674 View expandedChild = layout.getExpandedChild();
675 View headsUpChild = layout.getHeadsUpChild();
676 setChronometerRunningForChild(running, contractedChild);
677 setChronometerRunningForChild(running, expandedChild);
678 setChronometerRunningForChild(running, headsUpChild);
679 }
680 }
681
682 private void setChronometerRunningForChild(boolean running, View child) {
683 if (child != null) {
684 View chronometer = child.findViewById(com.android.internal.R.id.chronometer);
685 if (chronometer instanceof Chronometer) {
686 ((Chronometer) chronometer).setStarted(running);
687 }
688 }
689 }
690
Selim Cinekea4bef72015-12-02 15:51:10 -0800691 public NotificationHeaderView getNotificationHeader() {
Mady Mellorb0a82462016-04-30 17:31:02 -0700692 if (mIsSummaryWithChildren) {
693 return mChildrenContainer.getHeaderView();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700694 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800695 return mPrivateLayout.getNotificationHeader();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700696 }
697
Selim Cinek414ad332017-02-24 19:06:12 -0800698 /**
699 * @return the currently visible notification header. This can be different from
700 * {@link #getNotificationHeader()} in case it is a low-priority group.
701 */
702 public NotificationHeaderView getVisibleNotificationHeader() {
Selim Cinekaa3901a2016-08-05 11:04:37 -0700703 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinek414ad332017-02-24 19:06:12 -0800704 return mChildrenContainer.getVisibleHeader();
Selim Cinek34eda5e2016-02-18 17:10:43 -0800705 }
706 return getShowingLayout().getVisibleNotificationHeader();
707 }
708
Selim Cinek570981d2015-12-01 11:37:01 -0800709 public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) {
710 mOnExpandClickListener = onExpandClickListener;
711 }
712
Selim Cinekddf1b392016-05-27 16:33:10 -0700713 @Override
714 public void setOnClickListener(@Nullable OnClickListener l) {
715 super.setOnClickListener(l);
716 mOnClickListener = l;
717 updateClickAndFocus();
718 }
719
720 private void updateClickAndFocus() {
721 boolean normalChild = !isChildInGroup() || isGroupExpanded();
722 boolean clickable = mOnClickListener != null && normalChild;
723 if (isFocusable() != normalChild) {
724 setFocusable(normalChild);
725 }
726 if (isClickable() != clickable) {
727 setClickable(clickable);
728 }
729 }
730
Selim Cinek31aada42015-12-18 17:51:15 -0800731 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
732 mHeadsUpManager = headsUpManager;
733 }
734
Mady Mellor87d79452017-01-10 11:52:52 -0800735 public void setGutsView(MenuItem item) {
Mady Mellor95d743c2017-01-10 12:05:27 -0800736 if (mGuts != null && item.getGutsView() instanceof GutsContent) {
737 ((GutsContent) item.getGutsView()).setGutsParent(mGuts);
738 mGuts.setGutsContent((GutsContent) item.getGutsView());
Mady Mellor87d79452017-01-10 11:52:52 -0800739 }
740 }
741
Mady Mellor95d743c2017-01-10 12:05:27 -0800742 @Override
743 protected void onAttachedToWindow() {
744 super.onAttachedToWindow();
745 Dependency.get(PluginManager.class).addPluginListener(this,
746 NotificationMenuRowPlugin.class, false /* Allow multiple */);
747 }
748
749 @Override
750 protected void onDetachedFromWindow() {
751 super.onDetachedFromWindow();
752 Dependency.get(PluginManager.class).removePluginListener(this);
753 }
754
755 @Override
756 public void onPluginConnected(NotificationMenuRowPlugin plugin, Context pluginContext) {
757 boolean existed = mMenuRow.getMenuView() != null;
758 if (existed) {
759 removeView(mMenuRow.getMenuView());
760 }
761 mMenuRow = plugin;
762 if (mMenuRow.useDefaultMenuItems()) {
763 mMenuRow.setMenuItems(NotificationMenuRow.getDefaultMenuItems(mContext));
764 }
765 if (existed) {
766 createMenu();
767 }
768 }
769
770 @Override
771 public void onPluginDisconnected(NotificationMenuRowPlugin plugin) {
772 boolean existed = mMenuRow.getMenuView() != null;
773 mMenuRow = new NotificationMenuRow(mContext); // Back to default
774 if (existed) {
775 createMenu();
776 }
777 }
778
779 public NotificationMenuRowPlugin createMenu() {
780 if (mMenuRow.getMenuView() == null) {
781 mMenuRow.createMenu(this);
782 mMenuRow.setAppName(mAppName);
783 FrameLayout.LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
784 LayoutParams.MATCH_PARENT);
785 addView(mMenuRow.getMenuView(), MENU_VIEW_INDEX, lp);
786 }
787 return mMenuRow;
788 }
789
790
791 public NotificationMenuRowPlugin getProvider() {
792 return mMenuRow;
793 }
794
Selim Cinek1a48bab2017-02-17 19:38:40 -0800795 public void onDensityOrFontScaleChanged() {
Selim Cinek01af3342016-02-09 19:25:31 -0800796 initDimens();
797 if (mIsSummaryWithChildren) {
Selim Cinek01af3342016-02-09 19:25:31 -0800798 if (mChildrenContainer != null) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700799 mChildrenContainer.reInflateViews(mExpandClickListener, mEntry.notification);
Selim Cinek01af3342016-02-09 19:25:31 -0800800 }
801 }
802 if (mGuts != null) {
803 View oldGuts = mGuts;
804 int index = indexOfChild(oldGuts);
805 removeView(oldGuts);
806 mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate(
807 R.layout.notification_guts, this, false);
808 mGuts.setVisibility(oldGuts.getVisibility());
809 addView(mGuts, index);
810 }
Mady Mellor95d743c2017-01-10 12:05:27 -0800811 View oldMenu = mMenuRow.getMenuView();
812 if (oldMenu != null) {
Mady Mellor761cde12017-01-10 11:36:39 -0800813 int menuIndex = indexOfChild(oldMenu);
814 removeView(oldMenu);
Mady Mellor95d743c2017-01-10 12:05:27 -0800815 mMenuRow.createMenu(ExpandableNotificationRow.this);
Mady Mellor761cde12017-01-10 11:36:39 -0800816 mMenuRow.setAppName(mAppName);
Mady Mellor95d743c2017-01-10 12:05:27 -0800817 addView(mMenuRow.getMenuView(), menuIndex);
Mady Mellor4b80b102016-01-22 08:03:58 -0800818 }
Adrian Rooseb434ff2017-01-11 11:18:48 -0800819 for (NotificationContentView l : mLayouts) {
820 l.reInflateViews();
821 }
Selim Cinek1a48bab2017-02-17 19:38:40 -0800822 mNotificationInflater.onDensityOrFontScaleChanged();
823 onNotificationUpdated();
Selim Cinek01af3342016-02-09 19:25:31 -0800824 }
825
Selim Cinekc3179332016-03-04 14:44:56 -0800826 public void setContentBackground(int customBackgroundColor, boolean animate,
827 NotificationContentView notificationContentView) {
828 if (getShowingLayout() == notificationContentView) {
829 setTintColor(customBackgroundColor, animate);
830 }
831 }
832
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700833 public void closeRemoteInput() {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800834 for (NotificationContentView l : mLayouts) {
835 l.closeRemoteInput();
836 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700837 }
838
Selim Cinekc897bd32016-03-18 17:32:31 -0700839 /**
840 * Set by how much the single line view should be indented.
841 */
842 public void setSingleLineWidthIndention(int indention) {
843 mPrivateLayout.setSingleLineWidthIndention(indention);
844 }
845
846 public int getNotificationColor() {
Selim Cinek4bb59342016-04-08 19:29:35 -0700847 return mNotificationColor;
848 }
849
850 private void updateNotificationColor() {
851 mNotificationColor = NotificationColorUtil.resolveContrastColor(mContext,
852 getStatusBarNotification().getNotification().color);
Selim Cinekc897bd32016-03-18 17:32:31 -0700853 }
854
855 public HybridNotificationView getSingleLineView() {
856 return mPrivateLayout.getSingleLineView();
857 }
858
Selim Cinekf07d0622016-03-21 19:52:52 -0700859 public boolean isOnKeyguard() {
860 return mOnKeyguard;
861 }
862
Selim Cinekc1e389d2016-04-07 11:02:57 -0700863 public void removeAllChildren() {
864 List<ExpandableNotificationRow> notificationChildren
865 = mChildrenContainer.getNotificationChildren();
866 ArrayList<ExpandableNotificationRow> clonedList = new ArrayList<>(notificationChildren);
867 for (int i = 0; i < clonedList.size(); i++) {
868 ExpandableNotificationRow row = clonedList.get(i);
Selim Cinek3f19f602016-05-02 18:01:56 -0700869 if (row.keepInParent()) {
870 continue;
871 }
Selim Cinekc1e389d2016-04-07 11:02:57 -0700872 mChildrenContainer.removeNotification(row);
Selim Cinekc1e389d2016-04-07 11:02:57 -0700873 row.setIsChildInGroup(false, null);
874 }
875 onChildrenCountChanged();
876 }
877
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700878 public void setForceUnlocked(boolean forceUnlocked) {
879 mForceUnlocked = forceUnlocked;
880 if (mIsSummaryWithChildren) {
881 List<ExpandableNotificationRow> notificationChildren = getNotificationChildren();
882 for (ExpandableNotificationRow child : notificationChildren) {
883 child.setForceUnlocked(forceUnlocked);
884 }
885 }
886 }
887
Selim Cineke9bad242016-06-15 11:46:37 -0700888 public void setDismissed(boolean dismissed, boolean fromAccessibility) {
Selim Cinek3f19f602016-05-02 18:01:56 -0700889 mDismissed = dismissed;
Selim Cineke9bad242016-06-15 11:46:37 -0700890 mGroupParentWhenDismissed = mNotificationParent;
891 mRefocusOnDismiss = fromAccessibility;
892 mChildAfterViewWhenDismissed = null;
893 if (isChildInGroup()) {
894 List<ExpandableNotificationRow> notificationChildren =
895 mNotificationParent.getNotificationChildren();
896 int i = notificationChildren.indexOf(this);
897 if (i != -1 && i < notificationChildren.size() - 1) {
898 mChildAfterViewWhenDismissed = notificationChildren.get(i + 1);
899 }
900 }
Selim Cinek3f19f602016-05-02 18:01:56 -0700901 }
902
903 public boolean isDismissed() {
904 return mDismissed;
905 }
906
907 public boolean keepInParent() {
908 return mKeepInParent;
909 }
910
911 public void setKeepInParent(boolean keepInParent) {
912 mKeepInParent = keepInParent;
913 }
914
915 public boolean isRemoved() {
916 return mRemoved;
917 }
918
Adrian Roosd009ab12016-05-20 17:58:53 -0700919 public void setRemoved() {
920 mRemoved = true;
Selim Cinekef8c2252017-02-10 14:52:18 -0800921 mTranslationWhenRemoved = getTranslationY();
922 mWasChildInGroupWhenRemoved = isChildInGroup();
923 if (isChildInGroup()) {
924 mTranslationWhenRemoved += getNotificationParent().getTranslationY();
925 }
Adrian Roosd009ab12016-05-20 17:58:53 -0700926 mPrivateLayout.setRemoved();
Selim Cinek3f19f602016-05-02 18:01:56 -0700927 }
928
Selim Cinekef8c2252017-02-10 14:52:18 -0800929 public boolean wasChildInGroupWhenRemoved() {
930 return mWasChildInGroupWhenRemoved;
931 }
932
933 public float getTranslationWhenRemoved() {
934 return mTranslationWhenRemoved;
935 }
936
Selim Cinekd1395642016-04-28 12:22:42 -0700937 public NotificationChildrenContainer getChildrenContainer() {
938 return mChildrenContainer;
939 }
940
Selim Cinekcafa87f2016-10-26 17:00:17 -0700941 public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) {
942 mHeadsupDisappearRunning = headsUpAnimatingAway;
943 mPrivateLayout.setHeadsUpAnimatingAway(headsUpAnimatingAway);
944 }
945
946 /**
947 * @return if the view was just heads upped and is now animating away. During such a time the
948 * layout needs to be kept consistent
949 */
950 public boolean isHeadsUpAnimatingAway() {
951 return mHeadsupDisappearRunning;
Selim Cinek73cf02a2016-06-17 13:08:00 -0700952 }
953
Selim Cineke9bad242016-06-15 11:46:37 -0700954 public View getChildAfterViewWhenDismissed() {
955 return mChildAfterViewWhenDismissed;
956 }
957
958 public View getGroupParentWhenDismissed() {
959 return mGroupParentWhenDismissed;
960 }
961
Selim Cinek9e624e72016-07-20 13:46:49 -0700962 public void performDismiss() {
Selim Cineke9079112016-12-14 14:41:01 -0800963 if (mOnDismissRunnable != null) {
964 mOnDismissRunnable.run();
965 }
Selim Cinek9e624e72016-07-20 13:46:49 -0700966 }
967
Selim Cineke9079112016-12-14 14:41:01 -0800968 public void setOnDismissRunnable(Runnable onDismissRunnable) {
969 mOnDismissRunnable = onDismissRunnable;
Selim Cinek9e624e72016-07-20 13:46:49 -0700970 }
971
Selim Cinek281c2022016-10-13 19:14:43 -0700972 public View getNotificationIcon() {
Selim Cinek414ad332017-02-24 19:06:12 -0800973 NotificationHeaderView notificationHeader = getVisibleNotificationHeader();
Selim Cinek281c2022016-10-13 19:14:43 -0700974 if (notificationHeader != null) {
975 return notificationHeader.getIcon();
976 }
977 return null;
978 }
979
980 /**
981 * @return whether the notification is currently showing a view with an icon.
982 */
983 public boolean isShowingIcon() {
Mady Mellor434180c2017-02-13 11:29:42 -0800984 if (areGutsExposed()) {
985 return false;
986 }
Selim Cinek2ffa02f2017-03-06 15:56:37 -0800987 return getVisibleNotificationHeader() != null;
Selim Cinek281c2022016-10-13 19:14:43 -0700988 }
989
Selim Cinek0242fbb2016-10-19 13:38:32 -0700990 /**
991 * Set how much this notification is transformed into an icon.
992 *
Selim Cinek2b549f42016-11-22 16:38:51 -0800993 * @param contentTransformationAmount A value from 0 to 1 indicating how much we are transformed
994 * to the content away
Selim Cinek875a3a12016-11-18 17:52:16 -0800995 * @param isLastChild is this the last child in the list. If true, then the transformation is
996 * different since it's content fades out.
Selim Cinek0242fbb2016-10-19 13:38:32 -0700997 */
Selim Cinek2b549f42016-11-22 16:38:51 -0800998 public void setContentTransformationAmount(float contentTransformationAmount,
999 boolean isLastChild) {
Selim Cinek875a3a12016-11-18 17:52:16 -08001000 boolean changeTransformation = isLastChild != mIsLastChild;
Selim Cinek2b549f42016-11-22 16:38:51 -08001001 changeTransformation |= mContentTransformationAmount != contentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001002 mIsLastChild = isLastChild;
Selim Cinek2b549f42016-11-22 16:38:51 -08001003 mContentTransformationAmount = contentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001004 if (changeTransformation) {
1005 updateContentTransformation();
Selim Cinek2b549f42016-11-22 16:38:51 -08001006 }
1007 }
1008
1009 /**
1010 * Set the icons to be visible of this notification.
1011 */
1012 public void setIconsVisible(boolean iconsVisible) {
1013 if (iconsVisible != mIconsVisible) {
1014 mIconsVisible = iconsVisible;
1015 updateIconVisibilities();
Selim Cinek0242fbb2016-10-19 13:38:32 -07001016 }
1017 }
1018
Selim Cinekdb167372016-11-17 15:41:17 -08001019 @Override
1020 protected void onBelowSpeedBumpChanged() {
1021 updateIconVisibilities();
1022 }
1023
Selim Cinek875a3a12016-11-18 17:52:16 -08001024 private void updateContentTransformation() {
1025 float contentAlpha;
Selim Cinek2b549f42016-11-22 16:38:51 -08001026 float translationY = -mContentTransformationAmount * mIconTransformContentShift;
Selim Cinek875a3a12016-11-18 17:52:16 -08001027 if (mIsLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -08001028 contentAlpha = 1.0f - mContentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001029 contentAlpha = Math.min(contentAlpha / 0.5f, 1.0f);
Selim Cinek0242fbb2016-10-19 13:38:32 -07001030 contentAlpha = Interpolators.ALPHA_OUT.getInterpolation(contentAlpha);
Selim Cinek875a3a12016-11-18 17:52:16 -08001031 translationY *= 0.4f;
1032 } else {
1033 contentAlpha = 1.0f;
1034 }
Adrian Rooseb434ff2017-01-11 11:18:48 -08001035 for (NotificationContentView l : mLayouts) {
1036 l.setAlpha(contentAlpha);
1037 l.setTranslationY(translationY);
1038 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001039 if (mChildrenContainer != null) {
1040 mChildrenContainer.setAlpha(contentAlpha);
1041 mChildrenContainer.setTranslationY(translationY);
1042 // TODO: handle children fade out better
Selim Cinek0242fbb2016-10-19 13:38:32 -07001043 }
1044 }
1045
1046 private void updateIconVisibilities() {
Selim Cinek17e1b692016-12-02 18:19:11 -08001047 boolean visible = isChildInGroup()
1048 || (isBelowSpeedBump() && !NotificationShelf.SHOW_AMBIENT_ICONS)
1049 || mIconsVisible;
Adrian Rooseb434ff2017-01-11 11:18:48 -08001050 for (NotificationContentView l : mLayouts) {
1051 l.setIconsVisible(visible);
1052 }
Selim Cinekdb167372016-11-17 15:41:17 -08001053 if (mChildrenContainer != null) {
1054 mChildrenContainer.setIconsVisible(visible);
Selim Cinek0242fbb2016-10-19 13:38:32 -07001055 }
1056 }
1057
Selim Cinek875a3a12016-11-18 17:52:16 -08001058 /**
1059 * Get the relative top padding of a view relative to this view. This recursively walks up the
1060 * hierarchy and does the corresponding measuring.
1061 *
1062 * @param view the view to the the padding for. The requested view has to be a child of this
1063 * notification.
1064 * @return the toppadding
1065 */
1066 public int getRelativeTopPadding(View view) {
1067 int topPadding = 0;
1068 while (view.getParent() instanceof ViewGroup) {
1069 topPadding += view.getTop();
1070 view = (View) view.getParent();
1071 if (view instanceof ExpandableNotificationRow) {
1072 return topPadding;
1073 }
1074 }
1075 return topPadding;
1076 }
1077
Selim Cineka1d97902016-12-14 16:31:40 -08001078 public float getContentTranslation() {
1079 return mPrivateLayout.getTranslationY();
1080 }
1081
Selim Cinek6743c0b2017-01-18 18:24:01 -08001082 public void setIsLowPriority(boolean isLowPriority) {
1083 mIsLowPriority = isLowPriority;
1084 mPrivateLayout.setIsLowPriority(isLowPriority);
Selim Cinek1a48bab2017-02-17 19:38:40 -08001085 mNotificationInflater.setIsLowPriority(mIsLowPriority);
Selim Cinek6743c0b2017-01-18 18:24:01 -08001086 if (mChildrenContainer != null) {
1087 mChildrenContainer.setIsLowPriority(isLowPriority);
1088 }
1089 }
1090
Selim Cinek414ad332017-02-24 19:06:12 -08001091 public boolean isLowPriority() {
1092 return mIsLowPriority;
1093 }
1094
Selim Cinek7d1009b2017-01-25 15:28:28 -08001095 public void setUseIncreasedCollapsedHeight(boolean use) {
1096 mUseIncreasedCollapsedHeight = use;
Selim Cinek1a48bab2017-02-17 19:38:40 -08001097 mNotificationInflater.setUsesIncreasedHeight(use);
Selim Cinek7d1009b2017-01-25 15:28:28 -08001098 }
1099
Selim Cinek87ed69b2017-02-09 15:59:43 -08001100 public void setUseIncreasedHeadsUpHeight(boolean use) {
1101 mUseIncreasedHeadsUpHeight = use;
Selim Cinek1a48bab2017-02-17 19:38:40 -08001102 mNotificationInflater.setUsesIncreasedHeadsUpHeight(use);
1103 }
1104
1105 public void setRemoteViewClickHandler(RemoteViews.OnClickHandler remoteViewClickHandler) {
1106 mNotificationInflater.setRemoteViewClickHandler(remoteViewClickHandler);
Selim Cinek87ed69b2017-02-09 15:59:43 -08001107 }
1108
Selim Cinekc478f902017-02-22 20:55:44 -08001109 public void setInflateExceptionHandler(InflationExceptionHandler inflateExceptionHandler) {
1110 mNotificationInflater.setInflateExceptionHandler(inflateExceptionHandler);
1111 }
1112
Chris Wren78403d72014-07-28 10:23:24 +01001113 public interface ExpansionLogger {
1114 public void logNotificationExpansion(String key, boolean userAction, boolean expanded);
1115 }
Selim Cinek1685e632014-04-08 02:27:49 +02001116
Chris Wren51c75102013-07-16 20:49:17 -04001117 public ExpandableNotificationRow(Context context, AttributeSet attrs) {
1118 super(context, attrs);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001119 mFalsingManager = FalsingManager.getInstance(context);
Selim Cinek1a48bab2017-02-17 19:38:40 -08001120 mNotificationInflater = new NotificationInflater(this);
Mady Mellor95d743c2017-01-10 12:05:27 -08001121 mMenuRow = new NotificationMenuRow(mContext);
Selim Cinek01af3342016-02-09 19:25:31 -08001122 initDimens();
1123 }
1124
1125 private void initDimens() {
Selim Cinekf619ffc2016-02-17 14:53:05 -08001126 mNotificationMinHeightLegacy = getFontScaledHeight(R.dimen.notification_min_height_legacy);
1127 mNotificationMinHeight = getFontScaledHeight(R.dimen.notification_min_height);
Selim Cinek7d1009b2017-01-25 15:28:28 -08001128 mNotificationMinHeightLarge = getFontScaledHeight(
Selim Cinek87ed69b2017-02-09 15:59:43 -08001129 R.dimen.notification_min_height_increased);
Selim Cinekf619ffc2016-02-17 14:53:05 -08001130 mNotificationMaxHeight = getFontScaledHeight(R.dimen.notification_max_height);
Adrian Roos0aac04f2016-12-08 15:59:29 -08001131 mNotificationAmbientHeight = getFontScaledHeight(R.dimen.notification_ambient_height);
Selim Cinekf619ffc2016-02-17 14:53:05 -08001132 mMaxHeadsUpHeightLegacy = getFontScaledHeight(
Selim Cinek77019c72015-12-09 10:18:02 -08001133 R.dimen.notification_max_heads_up_height_legacy);
Selim Cinekf619ffc2016-02-17 14:53:05 -08001134 mMaxHeadsUpHeight = getFontScaledHeight(R.dimen.notification_max_heads_up_height);
Selim Cinek87ed69b2017-02-09 15:59:43 -08001135 mMaxHeadsUpHeightIncreased = getFontScaledHeight(
1136 R.dimen.notification_max_heads_up_height_increased);
Mady Mellorb0a82462016-04-30 17:31:02 -07001137 mIncreasedPaddingBetweenElements = getResources()
1138 .getDimensionPixelSize(R.dimen.notification_divider_height_increased);
Selim Cinek875a3a12016-11-18 17:52:16 -08001139 mIconTransformContentShiftNoIcon = getResources().getDimensionPixelSize(
Selim Cinek0242fbb2016-10-19 13:38:32 -07001140 R.dimen.notification_icon_transform_content_shift);
Selim Cinekf619ffc2016-02-17 14:53:05 -08001141 }
1142
1143 /**
1144 * @param dimenId the dimen to look up
1145 * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
1146 */
1147 private int getFontScaledHeight(int dimenId) {
1148 int dimensionPixelSize = getResources().getDimensionPixelSize(dimenId);
1149 float factor = Math.max(1.0f, getResources().getDisplayMetrics().scaledDensity /
1150 getResources().getDisplayMetrics().density);
1151 return (int) (dimensionPixelSize * factor);
Chris Wren51c75102013-07-16 20:49:17 -04001152 }
1153
Christoph Studera7fe6312014-06-27 19:32:44 +02001154 /**
1155 * Resets this view so it can be re-used for an updated notification.
1156 */
1157 public void reset() {
Jorim Jaggiae441282014-08-01 02:45:18 +02001158 mShowingPublicInitialized = false;
Selim Cinek31094df2014-08-14 19:28:15 +02001159 onHeightReset();
Selim Cinek6e28a672014-09-05 14:43:28 +02001160 requestLayout();
Christoph Studera7fe6312014-06-27 19:32:44 +02001161 }
1162
Jorim Jaggi251957d2014-04-09 04:24:09 +02001163 @Override
1164 protected void onFinishInflate() {
1165 super.onFinishInflate();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001166 mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic);
1167 mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded);
Adrian Rooseb434ff2017-01-11 11:18:48 -08001168 mLayouts = new NotificationContentView[] {mPrivateLayout, mPublicLayout};
1169
1170 for (NotificationContentView l : mLayouts) {
1171 l.setExpandClickListener(mExpandClickListener);
1172 l.setContainingNotification(this);
1173 }
Selim Cinekab29aeb2015-02-20 18:18:32 +01001174 mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub);
1175 mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() {
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001176 @Override
1177 public void onInflate(ViewStub stub, View inflated) {
1178 mGuts = (NotificationGuts) inflated;
1179 mGuts.setClipTopAmount(getClipTopAmount());
1180 mGuts.setActualHeight(getActualHeight());
Selim Cinekab29aeb2015-02-20 18:18:32 +01001181 mGutsStub = null;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001182 }
1183 });
Selim Cinekb5605e52015-02-20 18:21:41 +01001184 mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub);
1185 mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() {
1186
1187 @Override
1188 public void onInflate(ViewStub stub, View inflated) {
1189 mChildrenContainer = (NotificationChildrenContainer) inflated;
Selim Cinek6743c0b2017-01-18 18:24:01 -08001190 mChildrenContainer.setIsLowPriority(mIsLowPriority);
Selim Cinek414ad332017-02-24 19:06:12 -08001191 mChildrenContainer.setContainingNotification(ExpandableNotificationRow.this);
Selim Cinekc897bd32016-03-18 17:32:31 -07001192 mChildrenContainer.onNotificationUpdated();
Mady Mellor4b80b102016-01-22 08:03:58 -08001193 mTranslateableViews.add(mChildrenContainer);
Selim Cinekb5605e52015-02-20 18:21:41 +01001194 }
1195 });
Mady Mellor4b80b102016-01-22 08:03:58 -08001196
Mady Mellor95d743c2017-01-10 12:05:27 -08001197 // Add the views that we translate to reveal the menu
Mady Mellor4b80b102016-01-22 08:03:58 -08001198 mTranslateableViews = new ArrayList<View>();
1199 for (int i = 0; i < getChildCount(); i++) {
1200 mTranslateableViews.add(getChildAt(i));
1201 }
1202 // Remove views that don't translate
Mady Mellor4b80b102016-01-22 08:03:58 -08001203 mTranslateableViews.remove(mChildrenContainerStub);
1204 mTranslateableViews.remove(mGutsStub);
1205 }
1206
Mady Mellor4b80b102016-01-22 08:03:58 -08001207 public void resetTranslation() {
Mady Mellor32c638a2016-09-14 08:58:25 -07001208 if (mTranslateAnim != null) {
1209 mTranslateAnim.cancel();
1210 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001211 if (mTranslateableViews != null) {
1212 for (int i = 0; i < mTranslateableViews.size(); i++) {
1213 mTranslateableViews.get(i).setTranslationX(0);
1214 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001215 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001216 invalidateOutline();
Mady Mellor95d743c2017-01-10 12:05:27 -08001217 mMenuRow.resetMenu();
Mady Mellor4b80b102016-01-22 08:03:58 -08001218 }
1219
1220 public void animateTranslateNotification(final float leftTarget) {
1221 if (mTranslateAnim != null) {
1222 mTranslateAnim.cancel();
1223 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001224 mTranslateAnim = getTranslateViewAnimator(leftTarget, null /* updateListener */);
Mady Mellor34958fa2016-02-23 09:52:17 -08001225 if (mTranslateAnim != null) {
1226 mTranslateAnim.start();
1227 }
1228 }
1229
1230 @Override
1231 public void setTranslation(float translationX) {
1232 if (areGutsExposed()) {
1233 // Don't translate if guts are showing.
1234 return;
1235 }
1236 // Translate the group of views
1237 for (int i = 0; i < mTranslateableViews.size(); i++) {
1238 if (mTranslateableViews.get(i) != null) {
1239 mTranslateableViews.get(i).setTranslationX(translationX);
1240 }
1241 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001242 invalidateOutline();
Mady Mellor95d743c2017-01-10 12:05:27 -08001243 if (mMenuRow.getMenuView() != null) {
1244 mMenuRow.onTranslationUpdate(translationX);
Mady Mellor34958fa2016-02-23 09:52:17 -08001245 }
1246 }
1247
1248 @Override
1249 public float getTranslation() {
1250 if (mTranslateableViews != null && mTranslateableViews.size() > 0) {
1251 // All of the views in the list should have same translation, just use first one.
1252 return mTranslateableViews.get(0).getTranslationX();
1253 }
1254 return 0;
1255 }
1256
1257 public Animator getTranslateViewAnimator(final float leftTarget,
1258 AnimatorUpdateListener listener) {
Mady Mellor723f1f92016-03-13 15:54:06 -07001259 if (mTranslateAnim != null) {
1260 mTranslateAnim.cancel();
1261 }
Mady Mellor34958fa2016-02-23 09:52:17 -08001262 if (areGutsExposed()) {
1263 // No translation if guts are exposed.
1264 return null;
1265 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001266 final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(this, TRANSLATE_CONTENT,
1267 leftTarget);
1268 if (listener != null) {
1269 translateAnim.addUpdateListener(listener);
Mady Mellor4b80b102016-01-22 08:03:58 -08001270 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001271 translateAnim.addListener(new AnimatorListenerAdapter() {
1272 boolean cancelled = false;
1273
1274 @Override
1275 public void onAnimationCancel(Animator anim) {
1276 cancelled = true;
1277 }
1278
1279 @Override
1280 public void onAnimationEnd(Animator anim) {
Mady Mellor95d743c2017-01-10 12:05:27 -08001281 if (!cancelled && leftTarget == 0) {
1282 mMenuRow.resetMenu();
Mady Mellorb0a82462016-04-30 17:31:02 -07001283 mTranslateAnim = null;
1284 }
1285 }
1286 });
1287 mTranslateAnim = translateAnim;
1288 return translateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -08001289 }
1290
Selim Cinekab29aeb2015-02-20 18:18:32 +01001291 public void inflateGuts() {
1292 if (mGuts == null) {
1293 mGutsStub.inflate();
1294 }
1295 }
1296
Selim Cinekda42d652015-12-04 15:51:16 -08001297 private void updateChildrenVisibility() {
Selim Cinekd84a5932015-12-15 11:45:36 -08001298 mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE
1299 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -08001300 if (mChildrenContainer != null) {
1301 mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
1302 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -08001303 }
Selim Cinekda42d652015-12-04 15:51:16 -08001304 // The limits might have changed if the view suddenly became a group or vice versa
1305 updateLimits();
Selim Cinekb5605e52015-02-20 18:21:41 +01001306 }
1307
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001308 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08001309 public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
1310 if (super.onRequestSendAccessibilityEventInternal(child, event)) {
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001311 // Add a record for the entire layout since its content is somehow small.
1312 // The event comes from a leaf view that is interacted with.
1313 AccessibilityEvent record = AccessibilityEvent.obtain();
1314 onInitializeAccessibilityEvent(record);
1315 dispatchPopulateAccessibilityEvent(record);
1316 event.appendRecord(record);
1317 return true;
1318 }
1319 return false;
Jorim Jaggic5dc0d02014-04-15 15:42:55 +02001320 }
Chris Wren51c75102013-07-16 20:49:17 -04001321
John Spurlocke15452b2014-08-21 09:44:39 -04001322 @Override
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001323 public void setDark(boolean dark, boolean fade, long delay) {
1324 super.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -04001325 final NotificationContentView showing = getShowingLayout();
1326 if (showing != null) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001327 showing.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -04001328 }
Selim Cinek9c7712d2015-12-08 19:19:48 -08001329 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001330 mChildrenContainer.setDark(dark, fade, delay);
Selim Cinek9c7712d2015-12-08 19:19:48 -08001331 }
John Spurlocke15452b2014-08-21 09:44:39 -04001332 }
1333
Chris Wren51c75102013-07-16 20:49:17 -04001334 public boolean isExpandable() {
Selim Cinek388df6d2015-10-22 13:25:11 -07001335 if (mIsSummaryWithChildren && !mShowingPublic) {
1336 return !mChildrenExpanded;
1337 }
Chris Wren51c75102013-07-16 20:49:17 -04001338 return mExpandable;
1339 }
1340
1341 public void setExpandable(boolean expandable) {
1342 mExpandable = expandable;
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001343 mPrivateLayout.updateExpandButtons(isExpandable());
Chris Wren51c75102013-07-16 20:49:17 -04001344 }
1345
Selim Cinek4ffd6362015-12-29 15:12:23 +01001346 @Override
1347 public void setClipToActualHeight(boolean clipToActualHeight) {
Selim Cinek084c16b2016-01-22 17:48:22 -08001348 super.setClipToActualHeight(clipToActualHeight || isUserLocked());
1349 getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked());
Selim Cinek4ffd6362015-12-29 15:12:23 +01001350 }
1351
Selim Cinek1685e632014-04-08 02:27:49 +02001352 /**
1353 * @return whether the user has changed the expansion state
1354 */
1355 public boolean hasUserChangedExpansion() {
1356 return mHasUserChangedExpansion;
1357 }
1358
Chris Wren51c75102013-07-16 20:49:17 -04001359 public boolean isUserExpanded() {
1360 return mUserExpanded;
1361 }
1362
Selim Cinek1685e632014-04-08 02:27:49 +02001363 /**
1364 * Set this notification to be expanded by the user
1365 *
1366 * @param userExpanded whether the user wants this notification to be expanded
1367 */
Chris Wren51c75102013-07-16 20:49:17 -04001368 public void setUserExpanded(boolean userExpanded) {
Selim Cinek388df6d2015-10-22 13:25:11 -07001369 setUserExpanded(userExpanded, false /* allowChildExpansion */);
1370 }
1371
1372 /**
1373 * Set this notification to be expanded by the user
1374 *
1375 * @param userExpanded whether the user wants this notification to be expanded
1376 * @param allowChildExpansion whether a call to this method allows expanding children
1377 */
1378 public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001379 mFalsingManager.setNotificationExpanded();
Selim Cinek414ad332017-02-24 19:06:12 -08001380 if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion
1381 && !mChildrenContainer.showingAsLowPriority()) {
Chris Wren698b1702016-05-23 11:16:32 -04001382 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinek388df6d2015-10-22 13:25:11 -07001383 mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded);
Selim Cinek414ad332017-02-24 19:06:12 -08001384 onExpansionChanged(true /* userAction */, wasExpanded);
Selim Cinek388df6d2015-10-22 13:25:11 -07001385 return;
1386 }
Christoph Studera7fe6312014-06-27 19:32:44 +02001387 if (userExpanded && !mExpandable) return;
Chris Wren78403d72014-07-28 10:23:24 +01001388 final boolean wasExpanded = isExpanded();
Selim Cinek1685e632014-04-08 02:27:49 +02001389 mHasUserChangedExpansion = true;
Chris Wren51c75102013-07-16 20:49:17 -04001390 mUserExpanded = userExpanded;
Selim Cinek414ad332017-02-24 19:06:12 -08001391 onExpansionChanged(true /* userAction */, wasExpanded);
Chris Wren51c75102013-07-16 20:49:17 -04001392 }
1393
Selim Cinekccd14fb2014-08-12 18:53:24 +02001394 public void resetUserExpansion() {
Selim Cinek414ad332017-02-24 19:06:12 -08001395 boolean changed = mUserExpanded;
Selim Cinekccd14fb2014-08-12 18:53:24 +02001396 mHasUserChangedExpansion = false;
1397 mUserExpanded = false;
Selim Cinek414ad332017-02-24 19:06:12 -08001398 if (changed && mIsSummaryWithChildren) {
1399 mChildrenContainer.onExpansionChanged();
1400 }
1401 updateShelfIconColor();
Selim Cinekccd14fb2014-08-12 18:53:24 +02001402 }
1403
Chris Wren51c75102013-07-16 20:49:17 -04001404 public boolean isUserLocked() {
Selim Cinek1b2a05e2016-04-28 14:20:39 -07001405 return mUserLocked && !mForceUnlocked;
Chris Wren51c75102013-07-16 20:49:17 -04001406 }
1407
1408 public void setUserLocked(boolean userLocked) {
1409 mUserLocked = userLocked;
Selim Cinek8f2f6a62016-02-23 19:56:31 -08001410 mPrivateLayout.setUserExpanding(userLocked);
Selim Cinek42357e02016-02-24 18:48:01 -08001411 if (mIsSummaryWithChildren) {
1412 mChildrenContainer.setUserLocked(userLocked);
Selim Cinek7baaa9e2016-07-21 17:21:09 -07001413 if (userLocked || !isGroupExpanded()) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001414 updateBackgroundForGroupState();
1415 }
Selim Cinek42357e02016-02-24 18:48:01 -08001416 }
Chris Wren51c75102013-07-16 20:49:17 -04001417 }
1418
Selim Cinek1685e632014-04-08 02:27:49 +02001419 /**
1420 * @return has the system set this notification to be expanded
1421 */
1422 public boolean isSystemExpanded() {
1423 return mIsSystemExpanded;
1424 }
1425
1426 /**
1427 * Set this notification to be expanded by the system.
1428 *
1429 * @param expand whether the system wants this notification to be expanded.
1430 */
1431 public void setSystemExpanded(boolean expand) {
Selim Cinek31094df2014-08-14 19:28:15 +02001432 if (expand != mIsSystemExpanded) {
1433 final boolean wasExpanded = isExpanded();
1434 mIsSystemExpanded = expand;
Selim Cinekb5605e52015-02-20 18:21:41 +01001435 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek414ad332017-02-24 19:06:12 -08001436 onExpansionChanged(false /* userAction */, wasExpanded);
Selim Cineked6913b2016-06-01 12:01:17 -07001437 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001438 mChildrenContainer.updateGroupOverflow();
1439 }
Selim Cinek31094df2014-08-14 19:28:15 +02001440 }
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001441 }
1442
1443 /**
Selim Cinek83bc7832015-10-22 13:26:54 -07001444 * @param onKeyguard whether to prevent notification expansion
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001445 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001446 public void setOnKeyguard(boolean onKeyguard) {
1447 if (onKeyguard != mOnKeyguard) {
Selim Cinek31094df2014-08-14 19:28:15 +02001448 final boolean wasExpanded = isExpanded();
Selim Cinek83bc7832015-10-22 13:26:54 -07001449 mOnKeyguard = onKeyguard;
Selim Cinek414ad332017-02-24 19:06:12 -08001450 onExpansionChanged(false /* userAction */, wasExpanded);
Selim Cinek31094df2014-08-14 19:28:15 +02001451 if (wasExpanded != isExpanded()) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001452 if (mIsSummaryWithChildren) {
1453 mChildrenContainer.updateGroupOverflow();
1454 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001455 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +02001456 }
1457 }
Selim Cinek1685e632014-04-08 02:27:49 +02001458 }
1459
1460 /**
Selim Cinek9e624e72016-07-20 13:46:49 -07001461 * @return Can the underlying notification be cleared? This can be different from whether the
1462 * notification can be dismissed in case notifications are sensitive on the lockscreen.
1463 * @see #canViewBeDismissed()
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001464 */
1465 public boolean isClearable() {
Selim Cinek506deb62016-07-20 15:43:59 -07001466 if (mStatusBarNotification == null || !mStatusBarNotification.isClearable()) {
1467 return false;
1468 }
1469 if (mIsSummaryWithChildren) {
1470 List<ExpandableNotificationRow> notificationChildren =
1471 mChildrenContainer.getNotificationChildren();
1472 for (int i = 0; i < notificationChildren.size(); i++) {
1473 ExpandableNotificationRow child = notificationChildren.get(i);
1474 if (!child.isClearable()) {
1475 return false;
1476 }
1477 }
1478 }
1479 return true;
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001480 }
1481
Jorim Jaggi9cbadd32014-05-01 20:18:31 +02001482 @Override
1483 public int getIntrinsicHeight() {
Jorim Jaggibe565df2014-04-28 17:51:23 +02001484 if (isUserLocked()) {
1485 return getActualHeight();
1486 }
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05001487 if (mGuts != null && mGuts.isExposed()) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001488 return mGuts.getHeight();
1489 } else if ((isChildInGroup() && !isGroupExpanded())) {
1490 return mPrivateLayout.getMinHeight();
Adrian Roos0aac04f2016-12-08 15:59:29 -08001491 } else if (mShowAmbient) {
1492 return getAmbientHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -08001493 } else if (mSensitive && mHideSensitiveForIntrinsicHeight) {
1494 return getMinHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001495 } else if (mIsSummaryWithChildren && !mOnKeyguard) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001496 return mChildrenContainer.getIntrinsicHeight();
Selim Cinek01ee2cd52016-12-21 18:23:11 +01001497 } else if (!mOnKeyguard && (mIsHeadsUp || mHeadsupDisappearRunning)) {
Selim Cinek73cf02a2016-06-17 13:08:00 -07001498 if (isPinned() || mHeadsupDisappearRunning) {
Selim Cinek31aada42015-12-18 17:51:15 -08001499 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
1500 } else if (isExpanded()) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001501 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001502 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001503 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001504 }
Selim Cinek31aada42015-12-18 17:51:15 -08001505 } else if (isExpanded()) {
Selim Cinek83bc7832015-10-22 13:26:54 -07001506 return getMaxExpandHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -08001507 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001508 return getCollapsedHeight();
Selim Cinek1685e632014-04-08 02:27:49 +02001509 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001510 }
Selim Cinek1685e632014-04-08 02:27:49 +02001511
Mady Mellor43c2cd12016-12-12 21:05:13 -08001512 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -07001513 public boolean isGroupExpanded() {
Selim Cinekeef84282015-10-30 16:28:00 -07001514 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinekb5605e52015-02-20 18:21:41 +01001515 }
1516
Selim Cinek263398f2015-10-21 17:40:23 -07001517 private void onChildrenCountChanged() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001518 mIsSummaryWithChildren = StatusBar.ENABLE_CHILD_NOTIFICATIONS
Mady Mellorb0a82462016-04-30 17:31:02 -07001519 && mChildrenContainer != null && mChildrenContainer.getNotificationChildCount() > 0;
1520 if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() == null) {
Selim Cinek414ad332017-02-24 19:06:12 -08001521 mChildrenContainer.recreateNotificationHeader(mExpandClickListener
1522 );
Selim Cinek263398f2015-10-21 17:40:23 -07001523 }
Mady Mellor6baed9e2016-05-25 16:05:09 -07001524 getShowingLayout().updateBackgroundColor(false /* animate */);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001525 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinekea4bef72015-12-02 15:51:10 -08001526 updateChildrenHeaderAppearance();
Selim Cinekda42d652015-12-04 15:51:16 -08001527 updateChildrenVisibility();
Selim Cinek263398f2015-10-21 17:40:23 -07001528 }
1529
Mady Mellorb0a82462016-04-30 17:31:02 -07001530 public void updateChildrenHeaderAppearance() {
Selim Cineked6913b2016-06-01 12:01:17 -07001531 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001532 mChildrenContainer.updateChildrenHeaderAppearance();
1533 }
1534 }
1535
Selim Cinek1685e632014-04-08 02:27:49 +02001536 /**
1537 * Check whether the view state is currently expanded. This is given by the system in {@link
1538 * #setSystemExpanded(boolean)} and can be overridden by user expansion or
1539 * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this
1540 * view can differ from this state, if layout params are modified from outside.
1541 *
1542 * @return whether the view state is currently expanded.
1543 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001544 public boolean isExpanded() {
Selim Cineke81b82b2016-03-04 11:22:28 -08001545 return isExpanded(false /* allowOnKeyguard */);
1546 }
1547
1548 public boolean isExpanded(boolean allowOnKeyguard) {
1549 return (!mOnKeyguard || allowOnKeyguard)
Selim Cinekb5605e52015-02-20 18:21:41 +01001550 && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded())
1551 || isUserExpanded());
1552 }
1553
1554 private boolean isSystemChildExpanded() {
1555 return mIsSystemChildExpanded;
1556 }
1557
1558 public void setSystemChildExpanded(boolean expanded) {
1559 mIsSystemChildExpanded = expanded;
Selim Cinek1685e632014-04-08 02:27:49 +02001560 }
1561
1562 @Override
1563 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
1564 super.onLayout(changed, left, top, right, bottom);
Selim Cinek8d490d42015-04-10 00:05:50 -07001565 updateMaxHeights();
Mady Mellor95d743c2017-01-10 12:05:27 -08001566 if (mMenuRow.getMenuView() != null) {
1567 mMenuRow.onHeightUpdate();
Mady Mellora6edc872016-04-26 11:01:03 -07001568 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001569 updateContentShiftHeight();
1570 }
1571
1572 /**
1573 * Updates the content shift height such that the header is completely hidden when coming from
1574 * the top.
1575 */
1576 private void updateContentShiftHeight() {
Selim Cinek414ad332017-02-24 19:06:12 -08001577 NotificationHeaderView notificationHeader = getVisibleNotificationHeader();
Selim Cinek875a3a12016-11-18 17:52:16 -08001578 if (notificationHeader != null) {
1579 CachingIconView icon = notificationHeader.getIcon();
1580 mIconTransformContentShift = getRelativeTopPadding(icon) + icon.getHeight();
1581 } else {
1582 mIconTransformContentShift = mIconTransformContentShiftNoIcon;
1583 }
Selim Cinek1685e632014-04-08 02:27:49 +02001584 }
1585
Selim Cinek8d490d42015-04-10 00:05:50 -07001586 private void updateMaxHeights() {
Selim Cinekd2319fb2014-09-01 19:41:54 +02001587 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek8d490d42015-04-10 00:05:50 -07001588 View expandedChild = mPrivateLayout.getExpandedChild();
1589 if (expandedChild == null) {
1590 expandedChild = mPrivateLayout.getContractedChild();
1591 }
1592 mMaxExpandHeight = expandedChild.getHeight();
1593 View headsUpChild = mPrivateLayout.getHeadsUpChild();
Selim Cinek1f3f5442015-04-10 17:54:46 -07001594 if (headsUpChild == null) {
1595 headsUpChild = mPrivateLayout.getContractedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -07001596 }
Selim Cinek1f3f5442015-04-10 17:54:46 -07001597 mHeadsUpHeight = headsUpChild.getHeight();
Selim Cinekd2319fb2014-09-01 19:41:54 +02001598 if (intrinsicBefore != getIntrinsicHeight()) {
Selim Cinekbb42b7d2016-08-10 13:02:38 -07001599 notifyHeightChanged(true /* needsAnimation */);
Selim Cinekd2319fb2014-09-01 19:41:54 +02001600 }
1601 }
1602
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001603 @Override
1604 public void notifyHeightChanged(boolean needsAnimation) {
1605 super.notifyHeightChanged(needsAnimation);
1606 getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked());
1607 }
1608
Selim Cinek3c76d502016-02-19 15:16:33 -08001609 public void setSensitive(boolean sensitive, boolean hideSensitive) {
Jorim Jaggiae441282014-08-01 02:45:18 +02001610 mSensitive = sensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -08001611 mSensitiveHiddenInGeneral = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02001612 }
1613
Mady Mellor43c2cd12016-12-12 21:05:13 -08001614 @Override
Jorim Jaggiae441282014-08-01 02:45:18 +02001615 public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
Selim Cinek60122be2015-04-15 18:16:50 -07001616 mHideSensitiveForIntrinsicHeight = hideSensitive;
Selim Cineka52f6a12016-02-29 15:35:58 -08001617 if (mIsSummaryWithChildren) {
1618 List<ExpandableNotificationRow> notificationChildren =
1619 mChildrenContainer.getNotificationChildren();
1620 for (int i = 0; i < notificationChildren.size(); i++) {
1621 ExpandableNotificationRow child = notificationChildren.get(i);
1622 child.setHideSensitiveForIntrinsicHeight(hideSensitive);
1623 }
1624 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001625 }
1626
Mady Mellor43c2cd12016-12-12 21:05:13 -08001627 @Override
Jorim Jaggiae441282014-08-01 02:45:18 +02001628 public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
1629 long duration) {
1630 boolean oldShowingPublic = mShowingPublic;
1631 mShowingPublic = mSensitive && hideSensitive;
1632 if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
1633 return;
1634 }
Dan Sandlera5e0f412014-01-23 15:11:54 -05001635
1636 // bail out if no public version
Selim Cinek1685e632014-04-08 02:27:49 +02001637 if (mPublicLayout.getChildCount() == 0) return;
Dan Sandlera5e0f412014-01-23 15:11:54 -05001638
Jorim Jaggiae441282014-08-01 02:45:18 +02001639 if (!animated) {
1640 mPublicLayout.animate().cancel();
1641 mPrivateLayout.animate().cancel();
Selim Cineka554c702016-06-17 18:02:12 -07001642 if (mChildrenContainer != null) {
1643 mChildrenContainer.animate().cancel();
1644 mChildrenContainer.setAlpha(1f);
1645 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001646 mPublicLayout.setAlpha(1f);
1647 mPrivateLayout.setAlpha(1f);
1648 mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
Selim Cinekd84a5932015-12-15 11:45:36 -08001649 updateChildrenVisibility();
Jorim Jaggiae441282014-08-01 02:45:18 +02001650 } else {
1651 animateShowingPublic(delay, duration);
1652 }
Selim Cinekc3179332016-03-04 14:44:56 -08001653 NotificationContentView showingLayout = getShowingLayout();
1654 showingLayout.updateBackgroundColor(animated);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001655 mPrivateLayout.updateExpandButtons(isExpandable());
Adrian Roose5726a22016-12-19 14:26:51 -08001656 showingLayout.setDark(isDark(), false /* animate */, 0 /* delay */);
Jorim Jaggiae441282014-08-01 02:45:18 +02001657 mShowingPublicInitialized = true;
1658 }
1659
1660 private void animateShowingPublic(long delay, long duration) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001661 View[] privateViews = mIsSummaryWithChildren
1662 ? new View[] {mChildrenContainer}
Selim Cinekd84a5932015-12-15 11:45:36 -08001663 : new View[] {mPrivateLayout};
1664 View[] publicViews = new View[] {mPublicLayout};
1665 View[] hiddenChildren = mShowingPublic ? privateViews : publicViews;
1666 View[] shownChildren = mShowingPublic ? publicViews : privateViews;
1667 for (final View hiddenView : hiddenChildren) {
1668 hiddenView.setVisibility(View.VISIBLE);
1669 hiddenView.animate().cancel();
1670 hiddenView.animate()
1671 .alpha(0f)
1672 .setStartDelay(delay)
1673 .setDuration(duration)
1674 .withEndAction(new Runnable() {
1675 @Override
1676 public void run() {
1677 hiddenView.setVisibility(View.INVISIBLE);
1678 }
1679 });
1680 }
1681 for (View showView : shownChildren) {
1682 showView.setVisibility(View.VISIBLE);
1683 showView.setAlpha(0f);
1684 showView.animate().cancel();
1685 showView.animate()
1686 .alpha(1f)
1687 .setStartDelay(delay)
1688 .setDuration(duration);
1689 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001690 }
1691
Mady Mellor43c2cd12016-12-12 21:05:13 -08001692 @Override
Selim Cinek3776fe02016-02-04 13:32:43 -08001693 public boolean mustStayOnScreen() {
1694 return mIsHeadsUp;
1695 }
1696
Selim Cinek9e624e72016-07-20 13:46:49 -07001697 /**
1698 * @return Whether this view is allowed to be dismissed. Only valid for visible notifications as
1699 * otherwise some state might not be updated. To request about the general clearability
1700 * see {@link #isClearable()}.
1701 */
1702 public boolean canViewBeDismissed() {
Selim Cineke9bad242016-06-15 11:46:37 -07001703 return isClearable() && (!mShowingPublic || !mSensitiveHiddenInGeneral);
Dan Sandlera5e0f412014-01-23 15:11:54 -05001704 }
Jorim Jaggi251957d2014-04-09 04:24:09 +02001705
Ricky Waicd35def2016-05-03 11:07:07 +01001706 public void makeActionsVisibile() {
1707 setUserExpanded(true, true);
1708 if (isChildInGroup()) {
1709 mGroupManager.setGroupExpanded(mStatusBarNotification, true);
1710 }
Selim Cinekbb42b7d2016-08-10 13:02:38 -07001711 notifyHeightChanged(false /* needsAnimation */);
Ricky Waicd35def2016-05-03 11:07:07 +01001712 }
1713
Selim Cinekb5605e52015-02-20 18:21:41 +01001714 public void setChildrenExpanded(boolean expanded, boolean animate) {
1715 mChildrenExpanded = expanded;
Selim Cinek83bc7832015-10-22 13:26:54 -07001716 if (mChildrenContainer != null) {
1717 mChildrenContainer.setChildrenExpanded(expanded);
1718 }
Mady Mellor1a5d8ea2016-06-09 10:42:42 -07001719 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -07001720 updateClickAndFocus();
Selim Cinekb5605e52015-02-20 18:21:41 +01001721 }
1722
Selim Cinekb5605e52015-02-20 18:21:41 +01001723 public static void applyTint(View v, int color) {
1724 int alpha;
1725 if (color != 0) {
1726 alpha = COLORED_DIVIDER_ALPHA;
1727 } else {
1728 color = 0xff000000;
1729 alpha = DEFAULT_DIVIDER_ALPHA;
1730 }
1731 if (v.getBackground() instanceof ColorDrawable) {
1732 ColorDrawable background = (ColorDrawable) v.getBackground();
1733 background.mutate();
1734 background.setColor(color);
1735 background.setAlpha(alpha);
1736 }
1737 }
1738
Selim Cinek1685e632014-04-08 02:27:49 +02001739 public int getMaxExpandHeight() {
Selim Cinekb5605e52015-02-20 18:21:41 +01001740 return mMaxExpandHeight;
Chris Wren51c75102013-07-16 20:49:17 -04001741 }
Jorim Jaggi584a7aa2014-04-10 23:26:13 +02001742
Mady Mellor34958fa2016-02-23 09:52:17 -08001743 public boolean areGutsExposed() {
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05001744 return (mGuts != null && mGuts.isExposed());
Mady Mellor34958fa2016-02-23 09:52:17 -08001745 }
1746
Jorim Jaggibe565df2014-04-28 17:51:23 +02001747 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001748 public boolean isContentExpandable() {
Selim Cinekc0ac4af2017-03-03 15:13:48 -08001749 if (mIsSummaryWithChildren && !mShowingPublic) {
1750 return true;
1751 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001752 NotificationContentView showingLayout = getShowingLayout();
1753 return showingLayout.isContentExpandable();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001754 }
1755
1756 @Override
Selim Cinek560e64d2015-06-09 19:58:11 -07001757 protected View getContentView() {
Selim Cinekaa3901a2016-08-05 11:04:37 -07001758 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cineka5703182016-05-11 21:23:16 -04001759 return mChildrenContainer;
1760 }
Selim Cinek560e64d2015-06-09 19:58:11 -07001761 return getShowingLayout();
1762 }
1763
1764 @Override
Selim Cinekaa3901a2016-08-05 11:04:37 -07001765 protected void onAppearAnimationFinished(boolean wasAppearing) {
1766 super.onAppearAnimationFinished(wasAppearing);
1767 if (wasAppearing) {
1768 // During the animation the visible view might have changed, so let's make sure all
1769 // alphas are reset
1770 if (mChildrenContainer != null) {
1771 mChildrenContainer.setAlpha(1.0f);
1772 mChildrenContainer.setLayerType(LAYER_TYPE_NONE, null);
1773 }
Adrian Rooseb434ff2017-01-11 11:18:48 -08001774 for (NotificationContentView l : mLayouts) {
1775 l.setAlpha(1.0f);
1776 l.setLayerType(LAYER_TYPE_NONE, null);
1777 }
Selim Cinekaa3901a2016-08-05 11:04:37 -07001778 }
1779 }
1780
1781 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -07001782 public int getExtraBottomPadding() {
1783 if (mIsSummaryWithChildren && isGroupExpanded()) {
1784 return mIncreasedPaddingBetweenElements;
1785 }
1786 return 0;
1787 }
1788
1789 @Override
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001790 public void setActualHeight(int height, boolean notifyListeners) {
Selim Cinek4ca6c632017-02-23 18:03:37 -08001791 boolean changed = height != getActualHeight();
Selim Cinekb5605e52015-02-20 18:21:41 +01001792 super.setActualHeight(height, notifyListeners);
Selim Cinek4ca6c632017-02-23 18:03:37 -08001793 if (changed && isRemoved()) {
1794 // TODO: remove this once we found the gfx bug for this.
1795 // This is a hack since a removed view sometimes would just stay blank. it occured
1796 // when sending yourself a message and then clicking on it.
1797 ViewGroup parent = (ViewGroup) getParent();
1798 if (parent != null) {
1799 parent.invalidate();
1800 }
1801 }
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05001802 if (mGuts != null && mGuts.isExposed()) {
Mady Mellorb53bc272016-02-11 18:28:23 -08001803 mGuts.setActualHeight(height);
1804 return;
1805 }
Selim Cinekeef84282015-10-30 16:28:00 -07001806 int contentHeight = Math.max(getMinHeight(), height);
Adrian Rooseb434ff2017-01-11 11:18:48 -08001807 for (NotificationContentView l : mLayouts) {
1808 l.setContentHeight(contentHeight);
1809 }
Selim Cinek42357e02016-02-24 18:48:01 -08001810 if (mIsSummaryWithChildren) {
1811 mChildrenContainer.setActualHeight(height);
1812 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001813 if (mGuts != null) {
1814 mGuts.setActualHeight(height);
1815 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001816 }
1817
1818 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01001819 public int getMaxContentHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001820 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001821 return mChildrenContainer.getMaxContentHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001822 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001823 NotificationContentView showingLayout = getShowingLayout();
1824 return showingLayout.getMaxHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001825 }
1826
1827 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001828 public int getMinHeight() {
Selim Cinek01ee2cd52016-12-21 18:23:11 +01001829 if (!mOnKeyguard && mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) {
Selim Cinek31aada42015-12-18 17:51:15 -08001830 return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
1831 } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001832 return mChildrenContainer.getMinHeight();
Selim Cinek01ee2cd52016-12-21 18:23:11 +01001833 } else if (!mOnKeyguard && mIsHeadsUp) {
Selim Cinek31aada42015-12-18 17:51:15 -08001834 return mHeadsUpHeight;
Selim Cinekb55386d2015-12-16 17:26:49 -08001835 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001836 NotificationContentView showingLayout = getShowingLayout();
1837 return showingLayout.getMinHeight();
1838 }
1839
Adrian Roos0aac04f2016-12-08 15:59:29 -08001840 private int getAmbientHeight() {
1841 NotificationContentView showingLayout = getShowingLayout();
1842 return showingLayout.getAmbientChild() != null
1843 ? showingLayout.getAmbientChild().getHeight()
1844 : getCollapsedHeight();
1845 }
1846
Selim Cinek816c8e42015-11-19 12:00:45 -08001847 @Override
Selim Cinek567e8452016-03-24 10:54:56 -07001848 public int getCollapsedHeight() {
Selim Cinek2c584612016-02-29 16:14:25 -08001849 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinek567e8452016-03-24 10:54:56 -07001850 return mChildrenContainer.getCollapsedHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001851 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001852 return getMinHeight();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001853 }
1854
1855 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02001856 public void setClipTopAmount(int clipTopAmount) {
1857 super.setClipTopAmount(clipTopAmount);
Adrian Rooseb434ff2017-01-11 11:18:48 -08001858 for (NotificationContentView l : mLayouts) {
1859 l.setClipTopAmount(clipTopAmount);
1860 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001861 if (mGuts != null) {
1862 mGuts.setClipTopAmount(clipTopAmount);
1863 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001864 }
1865
Selim Cineka686b2c2016-10-26 13:58:27 -07001866 @Override
1867 public void setClipBottomAmount(int clipBottomAmount) {
Selim Cinek65d418e2016-11-29 15:42:34 -08001868 if (clipBottomAmount != mClipBottomAmount) {
1869 super.setClipBottomAmount(clipBottomAmount);
Adrian Rooseb434ff2017-01-11 11:18:48 -08001870 for (NotificationContentView l : mLayouts) {
1871 l.setClipBottomAmount(clipBottomAmount);
1872 }
Selim Cinek65d418e2016-11-29 15:42:34 -08001873 if (mGuts != null) {
1874 mGuts.setClipBottomAmount(clipBottomAmount);
1875 }
Selim Cineka686b2c2016-10-26 13:58:27 -07001876 }
Selim Cinekb3dadcc2016-11-21 17:21:13 -08001877 if (mChildrenContainer != null) {
Selim Cinek65d418e2016-11-29 15:42:34 -08001878 // We have to update this even if it hasn't changed, since the children locations can
1879 // have changed
Selim Cinekb3dadcc2016-11-21 17:21:13 -08001880 mChildrenContainer.setClipBottomAmount(clipBottomAmount);
1881 }
Selim Cineka686b2c2016-10-26 13:58:27 -07001882 }
1883
Selim Cinek31094df2014-08-14 19:28:15 +02001884 public boolean isMaxExpandHeightInitialized() {
1885 return mMaxExpandHeight != 0;
Selim Cinek7d447722014-06-10 15:51:59 +02001886 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001887
Selim Cinek42357e02016-02-24 18:48:01 -08001888 public NotificationContentView getShowingLayout() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001889 return mShowingPublic ? mPublicLayout : mPrivateLayout;
1890 }
Chris Wren78403d72014-07-28 10:23:24 +01001891
Selim Cinek1a48bab2017-02-17 19:38:40 -08001892 public void setLegacy(boolean legacy) {
Adrian Rooseb434ff2017-01-11 11:18:48 -08001893 for (NotificationContentView l : mLayouts) {
Selim Cinek1a48bab2017-02-17 19:38:40 -08001894 l.setLegacy(legacy);
Adrian Rooseb434ff2017-01-11 11:18:48 -08001895 }
Jorim Jaggi59ec3042015-06-05 15:18:43 -07001896 }
1897
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001898 @Override
1899 protected void updateBackgroundTint() {
1900 super.updateBackgroundTint();
Mady Mellorb0a82462016-04-30 17:31:02 -07001901 updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001902 if (mIsSummaryWithChildren) {
1903 List<ExpandableNotificationRow> notificationChildren =
1904 mChildrenContainer.getNotificationChildren();
1905 for (int i = 0; i < notificationChildren.size(); i++) {
1906 ExpandableNotificationRow child = notificationChildren.get(i);
Mady Mellorb0a82462016-04-30 17:31:02 -07001907 child.updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001908 }
1909 }
1910 }
1911
Mady Mellorb0a82462016-04-30 17:31:02 -07001912 /**
1913 * Called when a group has finished animating from collapsed or expanded state.
1914 */
1915 public void onFinishedExpansionChange() {
1916 mGroupExpansionChanging = false;
1917 updateBackgroundForGroupState();
1918 }
1919
1920 /**
1921 * Updates the parent and children backgrounds in a group based on the expansion state.
1922 */
1923 public void updateBackgroundForGroupState() {
1924 if (mIsSummaryWithChildren) {
1925 // Only when the group has finished expanding do we hide its background.
1926 mShowNoBackground = isGroupExpanded() && !isGroupExpansionChanging() && !isUserLocked();
1927 mChildrenContainer.updateHeaderForExpansion(mShowNoBackground);
1928 List<ExpandableNotificationRow> children = mChildrenContainer.getNotificationChildren();
1929 for (int i = 0; i < children.size(); i++) {
1930 children.get(i).updateBackgroundForGroupState();
1931 }
1932 } else if (isChildInGroup()) {
1933 final int childColor = getShowingLayout().getBackgroundColorForExpansionState();
1934 // Only show a background if the group is expanded OR if it is expanding / collapsing
1935 // and has a custom background color
1936 final boolean showBackground = isGroupExpanded()
1937 || ((mNotificationParent.isGroupExpansionChanging()
1938 || mNotificationParent.isUserLocked()) && childColor != 0);
1939 mShowNoBackground = !showBackground;
1940 } else {
1941 // Only children or parents ever need no background.
1942 mShowNoBackground = false;
1943 }
1944 updateOutline();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001945 updateBackground();
1946 }
1947
Adrian Roos4a579672016-05-24 16:54:37 -07001948 public int getPositionOfChild(ExpandableNotificationRow childRow) {
1949 if (mIsSummaryWithChildren) {
1950 return mChildrenContainer.getPositionInLinearLayout(childRow);
1951 }
1952 return 0;
1953 }
1954
Chris Wren78403d72014-07-28 10:23:24 +01001955 public void setExpansionLogger(ExpansionLogger logger, String key) {
1956 mLogger = logger;
1957 mLoggingKey = key;
1958 }
1959
Chris Wren6abeeb92016-05-26 14:44:38 -04001960 public void onExpandedByGesture(boolean userExpanded) {
1961 int event = MetricsEvent.ACTION_NOTIFICATION_GESTURE_EXPANDER;
1962 if (mGroupManager.isSummaryOfGroup(getStatusBarNotification())) {
1963 event = MetricsEvent.ACTION_NOTIFICATION_GROUP_GESTURE_EXPANDER;
1964 }
1965 MetricsLogger.action(mContext, event, userExpanded);
1966 }
1967
Selim Cinek6183d122016-01-14 18:48:41 -08001968 @Override
Selim Cinek42357e02016-02-24 18:48:01 -08001969 public float getIncreasedPaddingAmount() {
1970 if (mIsSummaryWithChildren) {
1971 if (isGroupExpanded()) {
1972 return 1.0f;
1973 } else if (isUserLocked()) {
Selim Cinek414ad332017-02-24 19:06:12 -08001974 return mChildrenContainer.getIncreasedPaddingAmount();
Selim Cinek42357e02016-02-24 18:48:01 -08001975 }
Selim Cinek99104832017-01-25 14:47:33 -08001976 } else if (isColorized() && (!mIsLowPriority || isExpanded())) {
Selim Cineka7ed2c12017-01-23 20:47:24 -08001977 return -1.0f;
Selim Cinek42357e02016-02-24 18:48:01 -08001978 }
1979 return 0.0f;
Selim Cinek61633a82016-01-25 15:54:10 -08001980 }
1981
Selim Cineka7ed2c12017-01-23 20:47:24 -08001982 private boolean isColorized() {
Selim Cinek99104832017-01-25 14:47:33 -08001983 return mIsColorized && mBgTint != NO_COLOR;
Selim Cineka7ed2c12017-01-23 20:47:24 -08001984 }
1985
Selim Cinek61633a82016-01-25 15:54:10 -08001986 @Override
Selim Cinek6183d122016-01-14 18:48:41 -08001987 protected boolean disallowSingleClick(MotionEvent event) {
1988 float x = event.getX();
1989 float y = event.getY();
Selim Cinek34eda5e2016-02-18 17:10:43 -08001990 NotificationHeaderView header = getVisibleNotificationHeader();
Selim Cinek6183d122016-01-14 18:48:41 -08001991 if (header != null) {
Mady Mellora8833512016-03-09 09:50:18 -08001992 return header.isInTouchRect(x - getTranslation(), y);
Selim Cinek6183d122016-01-14 18:48:41 -08001993 }
1994 return super.disallowSingleClick(event);
1995 }
1996
Selim Cinek414ad332017-02-24 19:06:12 -08001997 private void onExpansionChanged(boolean userAction, boolean wasExpanded) {
Chris Wren698b1702016-05-23 11:16:32 -04001998 boolean nowExpanded = isExpanded();
Selim Cinek414ad332017-02-24 19:06:12 -08001999 if (mIsSummaryWithChildren && (!mIsLowPriority || wasExpanded)) {
Chris Wren698b1702016-05-23 11:16:32 -04002000 nowExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
2001 }
Selim Cinek414ad332017-02-24 19:06:12 -08002002 if (nowExpanded != wasExpanded) {
2003 updateShelfIconColor();
2004 if (mLogger != null) {
2005 mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded);
2006 }
2007 if (mIsSummaryWithChildren) {
2008 mChildrenContainer.onExpansionChanged();
2009 }
Chris Wren78403d72014-07-28 10:23:24 +01002010 }
2011 }
Selim Cinek570981d2015-12-01 11:37:01 -08002012
Selim Cineke9bad242016-06-15 11:46:37 -07002013 @Override
2014 public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
2015 super.onInitializeAccessibilityNodeInfoInternal(info);
2016 if (canViewBeDismissed()) {
2017 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS);
2018 }
Selim Cinekc0ac4af2017-03-03 15:13:48 -08002019 boolean expandable = mShowingPublic;
2020 boolean isExpanded = false;
2021 if (!expandable) {
2022 if (mIsSummaryWithChildren) {
2023 expandable = true;
2024 if (!mIsLowPriority || isExpanded()) {
2025 isExpanded = isGroupExpanded();
2026 }
2027 } else {
2028 expandable = mPrivateLayout.isContentExpandable();
2029 isExpanded = isExpanded();
2030 }
2031 }
2032 if (expandable) {
2033 if (isExpanded) {
2034 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE);
2035 } else {
2036 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND);
2037 }
2038 }
Selim Cineke9bad242016-06-15 11:46:37 -07002039 }
2040
2041 @Override
2042 public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
2043 if (super.performAccessibilityActionInternal(action, arguments)) {
2044 return true;
2045 }
2046 switch (action) {
2047 case AccessibilityNodeInfo.ACTION_DISMISS:
2048 NotificationStackScrollLayout.performDismiss(this, mGroupManager,
2049 true /* fromAccessibility */);
2050 return true;
Selim Cinekc0ac4af2017-03-03 15:13:48 -08002051 case AccessibilityNodeInfo.ACTION_COLLAPSE:
2052 case AccessibilityNodeInfo.ACTION_EXPAND:
2053 mExpandClickListener.onClick(this);
2054 return true;
Selim Cineke9bad242016-06-15 11:46:37 -07002055 }
2056 return false;
2057 }
2058
2059 public boolean shouldRefocusOnDismiss() {
2060 return mRefocusOnDismiss || isAccessibilityFocused();
2061 }
2062
Selim Cinek570981d2015-12-01 11:37:01 -08002063 public interface OnExpandClickListener {
Selim Cinek31aada42015-12-18 17:51:15 -08002064 void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
Selim Cinek570981d2015-12-01 11:37:01 -08002065 }
Selim Cinekbbcebde2016-11-09 18:28:20 -08002066
2067 @Override
2068 public ExpandableViewState createNewViewState(StackScrollState stackScrollState) {
2069 return new NotificationViewState(stackScrollState);
2070 }
2071
Selim Cinekd127d792016-11-01 19:11:41 -07002072 @Override
2073 public boolean isAboveShelf() {
Selim Cinekc8007c52017-02-28 16:09:56 -08002074 return !isOnKeyguard()
2075 && (mIsPinned || mHeadsupDisappearRunning || (mIsHeadsUp && mAboveShelf));
Selim Cinekd127d792016-11-01 19:11:41 -07002076 }
2077
Adrian Roos0aac04f2016-12-08 15:59:29 -08002078 public void setShowAmbient(boolean showAmbient) {
2079 if (showAmbient != mShowAmbient) {
2080 mShowAmbient = showAmbient;
2081 notifyHeightChanged(false /* needsAnimation */);
2082 }
2083 }
2084
Selim Cinekd127d792016-11-01 19:11:41 -07002085 public void setAboveShelf(boolean aboveShelf) {
2086 mAboveShelf = aboveShelf;
2087 }
2088
Selim Cinekd4776a52017-02-14 18:50:16 -08002089 public static class NotificationViewState extends ExpandableViewState {
Selim Cinekbbcebde2016-11-09 18:28:20 -08002090
2091 private final StackScrollState mOverallState;
Selim Cinek0242fbb2016-10-19 13:38:32 -07002092
Selim Cinekbbcebde2016-11-09 18:28:20 -08002093
2094 private NotificationViewState(StackScrollState stackScrollState) {
2095 mOverallState = stackScrollState;
2096 }
2097
2098 @Override
2099 public void applyToView(View view) {
2100 super.applyToView(view);
2101 if (view instanceof ExpandableNotificationRow) {
2102 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
Selim Cinekbbcebde2016-11-09 18:28:20 -08002103 row.applyChildrenState(mOverallState);
2104 }
2105 }
Selim Cinek0cfbef42016-11-09 19:06:36 -08002106
2107 @Override
Selim Cinek2b549f42016-11-22 16:38:51 -08002108 protected void onYTranslationAnimationFinished(View view) {
2109 super.onYTranslationAnimationFinished(view);
Selim Cinekd4776a52017-02-14 18:50:16 -08002110 if (view instanceof ExpandableNotificationRow) {
2111 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
2112 if (row.isHeadsUpAnimatingAway()) {
2113 row.setHeadsUpAnimatingAway(false);
2114 }
Selim Cinek0cfbef42016-11-09 19:06:36 -08002115 }
2116 }
2117
2118 @Override
2119 public void animateTo(View child, AnimationProperties properties) {
2120 super.animateTo(child, properties);
2121 if (child instanceof ExpandableNotificationRow) {
2122 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
2123 row.startChildAnimation(mOverallState, properties);
2124 }
2125 }
Selim Cinekbbcebde2016-11-09 18:28:20 -08002126 }
Chris Wren51c75102013-07-16 20:49:17 -04002127}