blob: 8ff950ed1c2475beebb572081260c7c978b1193c [file] [log] [blame]
Chris Wren51c75102013-07-16 20:49:17 -04001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.systemui.statusbar;
18
Selim Cinek5ba22542017-04-20 15:16:10 -070019import static com.android.systemui.statusbar.notification.NotificationInflater.InflationCallback;
Selim Cinekc478f902017-02-22 20:55:44 -080020
Mady Mellor4b80b102016-01-22 08:03:58 -080021import android.animation.Animator;
22import android.animation.AnimatorListenerAdapter;
Mady Mellor4b80b102016-01-22 08:03:58 -080023import android.animation.ObjectAnimator;
Mady Mellor4b80b102016-01-22 08:03:58 -080024import android.animation.ValueAnimator.AnimatorUpdateListener;
Selim Cinekddf1b392016-05-27 16:33:10 -070025import android.annotation.Nullable;
Chris Wren51c75102013-07-16 20:49:17 -040026import android.content.Context;
Anthony Chen7acbb772017-04-07 16:45:25 -070027import android.content.res.Resources;
Mady Mellor9d03a522017-04-04 18:45:30 -070028import android.content.res.Configuration;
Selim Cinekcab4a602014-09-03 14:47:57 +020029import android.graphics.drawable.AnimatedVectorDrawable;
30import android.graphics.drawable.AnimationDrawable;
Selim Cinekb5605e52015-02-20 18:21:41 +010031import android.graphics.drawable.ColorDrawable;
Selim Cinekcab4a602014-09-03 14:47:57 +020032import android.graphics.drawable.Drawable;
Selim Cinekda42d652015-12-04 15:51:16 -080033import android.os.Build;
Selim Cineke9bad242016-06-15 11:46:37 -070034import android.os.Bundle;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020035import android.service.notification.StatusBarNotification;
Chris Wren51c75102013-07-16 20:49:17 -040036import android.util.AttributeSet;
Mady Mellorb0a82462016-04-30 17:31:02 -070037import android.util.FloatProperty;
38import android.util.Property;
Geoffrey Pitsch409db272017-08-28 14:51:52 +000039import android.view.KeyEvent;
Selim Cinek01af3342016-02-09 19:25:31 -080040import android.view.LayoutInflater;
Selim Cinek6183d122016-01-14 18:48:41 -080041import android.view.MotionEvent;
Selim Cinekeaa29ca2015-11-23 13:51:13 -080042import android.view.NotificationHeaderView;
Dan Sandlera5e0f412014-01-23 15:11:54 -050043import android.view.View;
Selim Cinek875a3a12016-11-18 17:52:16 -080044import android.view.ViewGroup;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020045import android.view.ViewStub;
Jorim Jaggife40f7d2014-04-28 15:20:04 +020046import android.view.accessibility.AccessibilityEvent;
Selim Cineke9bad242016-06-15 11:46:37 -070047import android.view.accessibility.AccessibilityNodeInfo;
Selim Cinek98713a42015-09-21 15:47:20 +020048import android.widget.Chronometer;
Mady Mellor95d743c2017-01-10 12:05:27 -080049import android.widget.FrameLayout;
Selim Cinekcab4a602014-09-03 14:47:57 +020050import android.widget.ImageView;
Selim Cinek1a48bab2017-02-17 19:38:40 -080051import android.widget.RemoteViews;
Selim Cinekb5605e52015-02-20 18:21:41 +010052
Selim Cinek5ba22542017-04-20 15:16:10 -070053import com.android.internal.annotations.VisibleForTesting;
Chris Wren698b1702016-05-23 11:16:32 -040054import com.android.internal.logging.MetricsLogger;
Tamas Berghammer383db5eb2016-06-22 15:21:38 +010055import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Selim Cinek4bb59342016-04-08 19:29:35 -070056import com.android.internal.util.NotificationColorUtil;
Selim Cinek875a3a12016-11-18 17:52:16 -080057import com.android.internal.widget.CachingIconView;
Mady Mellor95d743c2017-01-10 12:05:27 -080058import com.android.systemui.Dependency;
Selim Cinek0242fbb2016-10-19 13:38:32 -070059import com.android.systemui.Interpolators;
Dan Sandlera5e0f412014-01-23 15:11:54 -050060import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070061import com.android.systemui.classifier.FalsingManager;
Mady Mellor95d743c2017-01-10 12:05:27 -080062import com.android.systemui.plugins.PluginListener;
63import com.android.systemui.plugins.PluginManager;
64import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
65import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem;
66import com.android.systemui.statusbar.NotificationGuts.GutsContent;
Selim Cinek5cf1d052017-06-01 17:36:46 -070067import com.android.systemui.statusbar.notification.AboveShelfChangedListener;
Selim Cineka6ee4bd2017-09-20 22:52:29 +000068import com.android.systemui.statusbar.notification.AboveShelfObserver;
Selim Cinekc897bd32016-03-18 17:32:31 -070069import com.android.systemui.statusbar.notification.HybridNotificationView;
Selim Cinek1a48bab2017-02-17 19:38:40 -080070import com.android.systemui.statusbar.notification.NotificationInflater;
Selim Cinek6743c0b2017-01-18 18:24:01 -080071import com.android.systemui.statusbar.notification.NotificationUtils;
Selim Cineke62255c2017-09-28 18:23:23 -070072import com.android.systemui.statusbar.notification.NotificationViewWrapper;
Selim Cineka7d4f822016-12-06 14:34:47 -080073import com.android.systemui.statusbar.notification.VisualStabilityManager;
Selim Cinekb5605e52015-02-20 18:21:41 +010074import com.android.systemui.statusbar.phone.NotificationGroupManager;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050075import com.android.systemui.statusbar.phone.StatusBar;
Selim Cinek31aada42015-12-18 17:51:15 -080076import com.android.systemui.statusbar.policy.HeadsUpManager;
Selim Cinek0cfbef42016-11-09 19:06:36 -080077import com.android.systemui.statusbar.stack.AnimationProperties;
78import com.android.systemui.statusbar.stack.ExpandableViewState;
Selim Cinekb5605e52015-02-20 18:21:41 +010079import com.android.systemui.statusbar.stack.NotificationChildrenContainer;
Selim Cineke9bad242016-06-15 11:46:37 -070080import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Selim Cinekb5605e52015-02-20 18:21:41 +010081import com.android.systemui.statusbar.stack.StackScrollState;
Selim Cinekb5605e52015-02-20 18:21:41 +010082
Mady Mellor4b80b102016-01-22 08:03:58 -080083import java.util.ArrayList;
Selim Cinekb5605e52015-02-20 18:21:41 +010084import java.util.List;
Lucas Dupincecc7c22017-09-12 16:02:45 -070085import java.util.function.BooleanSupplier;
Dan Sandlera5e0f412014-01-23 15:11:54 -050086
Mady Mellor95d743c2017-01-10 12:05:27 -080087public class ExpandableNotificationRow extends ActivatableNotificationView
88 implements PluginListener<NotificationMenuRowPlugin> {
Selim Cinekb5605e52015-02-20 18:21:41 +010089
90 private static final int DEFAULT_DIVIDER_ALPHA = 0x29;
91 private static final int COLORED_DIVIDER_ALPHA = 0x7B;
Mady Mellor95d743c2017-01-10 12:05:27 -080092 private static final int MENU_VIEW_INDEX = 0;
93
Mady Mellor035badd2017-04-04 18:45:30 -070094 public interface LayoutListener {
95 public void onLayout();
96 }
97
98 private LayoutListener mLayoutListener;
Lucas Dupincecc7c22017-09-12 16:02:45 -070099 private boolean mDark;
Selim Cinek55a3e732017-05-25 18:30:10 -0700100 private boolean mLowPriorityStateUpdated;
Selim Cinek1a48bab2017-02-17 19:38:40 -0800101 private final NotificationInflater mNotificationInflater;
Selim Cinek0242fbb2016-10-19 13:38:32 -0700102 private int mIconTransformContentShift;
Selim Cinek875a3a12016-11-18 17:52:16 -0800103 private int mIconTransformContentShiftNoIcon;
Selim Cinek01af3342016-02-09 19:25:31 -0800104 private int mNotificationMinHeightLegacy;
105 private int mMaxHeadsUpHeightLegacy;
106 private int mMaxHeadsUpHeight;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800107 private int mMaxHeadsUpHeightIncreased;
Selim Cinek01af3342016-02-09 19:25:31 -0800108 private int mNotificationMinHeight;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800109 private int mNotificationMinHeightLarge;
Selim Cinek01af3342016-02-09 19:25:31 -0800110 private int mNotificationMaxHeight;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800111 private int mNotificationAmbientHeight;
Mady Mellorb0a82462016-04-30 17:31:02 -0700112 private int mIncreasedPaddingBetweenElements;
Chris Wren51c75102013-07-16 20:49:17 -0400113
Selim Cinek1685e632014-04-08 02:27:49 +0200114 /** Does this row contain layouts that can adapt to row expansion */
Chris Wren51c75102013-07-16 20:49:17 -0400115 private boolean mExpandable;
Selim Cinek1685e632014-04-08 02:27:49 +0200116 /** Has the user actively changed the expansion state of this row */
117 private boolean mHasUserChangedExpansion;
118 /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */
Chris Wren51c75102013-07-16 20:49:17 -0400119 private boolean mUserExpanded;
Selim Cinek31aada42015-12-18 17:51:15 -0800120
121 /**
122 * Has this notification been expanded while it was pinned
123 */
124 private boolean mExpandedWhenPinned;
Selim Cinek1685e632014-04-08 02:27:49 +0200125 /** Is the user touching this row */
Chris Wren51c75102013-07-16 20:49:17 -0400126 private boolean mUserLocked;
Selim Cinek1685e632014-04-08 02:27:49 +0200127 /** Are we showing the "public" version */
Dan Sandlera5e0f412014-01-23 15:11:54 -0500128 private boolean mShowingPublic;
Jorim Jaggiae441282014-08-01 02:45:18 +0200129 private boolean mSensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -0800130 private boolean mSensitiveHiddenInGeneral;
Jorim Jaggiae441282014-08-01 02:45:18 +0200131 private boolean mShowingPublicInitialized;
Selim Cinek60122be2015-04-15 18:16:50 -0700132 private boolean mHideSensitiveForIntrinsicHeight;
Chris Wren51c75102013-07-16 20:49:17 -0400133
Selim Cinek1685e632014-04-08 02:27:49 +0200134 /**
135 * Is this notification expanded by the system. The expansion state can be overridden by the
136 * user expansion.
137 */
138 private boolean mIsSystemExpanded;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200139
140 /**
Selim Cinek83bc7832015-10-22 13:26:54 -0700141 * Whether the notification is on the keyguard and the expansion is disabled.
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200142 */
Selim Cinek83bc7832015-10-22 13:26:54 -0700143 private boolean mOnKeyguard;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200144
Mady Mellorb0a82462016-04-30 17:31:02 -0700145 private Animator mTranslateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -0800146 private ArrayList<View> mTranslateableViews;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200147 private NotificationContentView mPublicLayout;
148 private NotificationContentView mPrivateLayout;
Adrian Rooseb434ff2017-01-11 11:18:48 -0800149 private NotificationContentView[] mLayouts;
Selim Cinek1685e632014-04-08 02:27:49 +0200150 private int mMaxExpandHeight;
Selim Cinek8d490d42015-04-10 00:05:50 -0700151 private int mHeadsUpHeight;
Selim Cinek4bb59342016-04-08 19:29:35 -0700152 private int mNotificationColor;
Chris Wren78403d72014-07-28 10:23:24 +0100153 private ExpansionLogger mLogger;
154 private String mLoggingKey;
Selim Cinek8d490d42015-04-10 00:05:50 -0700155 private NotificationGuts mGuts;
Selim Cinekda42d652015-12-04 15:51:16 -0800156 private NotificationData.Entry mEntry;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200157 private StatusBarNotification mStatusBarNotification;
Mady Mellor3fd273e2016-03-15 21:08:14 -0700158 private String mAppName;
Selim Cinek1a521f32014-11-03 17:39:29 +0100159 private boolean mIsHeadsUp;
Selim Cinek98713a42015-09-21 15:47:20 +0200160 private boolean mLastChronometerRunning = true;
Selim Cinekb5605e52015-02-20 18:21:41 +0100161 private ViewStub mChildrenContainerStub;
162 private NotificationGroupManager mGroupManager;
Selim Cinekb5605e52015-02-20 18:21:41 +0100163 private boolean mChildrenExpanded;
Selim Cinek263398f2015-10-21 17:40:23 -0700164 private boolean mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100165 private NotificationChildrenContainer mChildrenContainer;
Mady Mellor95d743c2017-01-10 12:05:27 -0800166 private NotificationMenuRowPlugin mMenuRow;
Selim Cinekab29aeb2015-02-20 18:18:32 +0100167 private ViewStub mGutsStub;
Selim Cinekb5605e52015-02-20 18:21:41 +0100168 private boolean mIsSystemChildExpanded;
Selim Cinek684a4422015-04-15 16:18:39 -0700169 private boolean mIsPinned;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700170 private FalsingManager mFalsingManager;
Selim Cinek5cf1d052017-06-01 17:36:46 -0700171 private AboveShelfChangedListener mAboveShelfChangedListener;
Selim Cinek31aada42015-12-18 17:51:15 -0800172 private HeadsUpManager mHeadsUpManager;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200173
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700174 private boolean mJustClicked;
Selim Cinek5a175d92015-11-23 18:01:33 -0800175 private boolean mIconAnimationRunning;
Selim Cinek34d93b02015-10-22 12:30:38 -0700176 private boolean mShowNoBackground;
Selim Cinek388df6d2015-10-22 13:25:11 -0700177 private ExpandableNotificationRow mNotificationParent;
Selim Cinek570981d2015-12-01 11:37:01 -0800178 private OnExpandClickListener mOnExpandClickListener;
Geoffrey Pitsch409db272017-08-28 14:51:52 +0000179
180 // Listener will be called when receiving a long click event.
181 // Use #setLongPressPosition to optionally assign positional data with the long press.
182 private LongPressListener mLongPressListener;
183
Mady Mellorb0a82462016-04-30 17:31:02 -0700184 private boolean mGroupExpansionChanging;
185
Anthony Chen6bf88a02017-04-10 14:41:44 -0700186 /**
Lucas Dupincecc7c22017-09-12 16:02:45 -0700187 * A supplier that returns true if keyguard is secure.
188 */
189 private BooleanSupplier mSecureStateProvider;
190
191 /**
Anthony Chen6bf88a02017-04-10 14:41:44 -0700192 * Whether or not a notification that is not part of a group of notifications can be manually
193 * expanded by the user.
194 */
195 private boolean mEnableNonGroupedNotificationExpand;
196
197 /**
198 * Whether or not to update the background of the header of the notification when its expanded.
199 * If {@code true}, the header background will disappear when expanded.
200 */
201 private boolean mShowGroupBackgroundWhenExpanded;
202
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800203 private OnClickListener mExpandClickListener = new OnClickListener() {
204 @Override
205 public void onClick(View v) {
Selim Cinek414ad332017-02-24 19:06:12 -0800206 if (!mShowingPublic && (!mIsLowPriority || isExpanded())
207 && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) {
Mady Mellor1a5d8ea2016-06-09 10:42:42 -0700208 mGroupExpansionChanging = true;
Chris Wren698b1702016-05-23 11:16:32 -0400209 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
210 boolean nowExpanded = mGroupManager.toggleGroupExpansion(mStatusBarNotification);
211 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400212 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_GROUP_EXPANDER,
213 nowExpanded);
Selim Cinek414ad332017-02-24 19:06:12 -0800214 onExpansionChanged(true /* userAction */, wasExpanded);
Anthony Chen6bf88a02017-04-10 14:41:44 -0700215 } else if (mEnableNonGroupedNotificationExpand) {
Selim Cineke9bad242016-06-15 11:46:37 -0700216 if (v.isAccessibilityFocused()) {
217 mPrivateLayout.setFocusOnVisibilityChange();
218 }
Selim Cinek31aada42015-12-18 17:51:15 -0800219 boolean nowExpanded;
220 if (isPinned()) {
221 nowExpanded = !mExpandedWhenPinned;
222 mExpandedWhenPinned = nowExpanded;
223 } else {
224 nowExpanded = !isExpanded();
225 setUserExpanded(nowExpanded);
226 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800227 notifyHeightChanged(true);
Selim Cinek31aada42015-12-18 17:51:15 -0800228 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400229 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_EXPANDER,
230 nowExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800231 }
232 }
233 };
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700234 private boolean mForceUnlocked;
Selim Cinek3f19f602016-05-02 18:01:56 -0700235 private boolean mDismissed;
236 private boolean mKeepInParent;
237 private boolean mRemoved;
Mady Mellorb0a82462016-04-30 17:31:02 -0700238 private static final Property<ExpandableNotificationRow, Float> TRANSLATE_CONTENT =
239 new FloatProperty<ExpandableNotificationRow>("translate") {
240 @Override
241 public void setValue(ExpandableNotificationRow object, float value) {
242 object.setTranslation(value);
243 }
244
245 @Override
246 public Float get(ExpandableNotificationRow object) {
247 return object.getTranslation();
248 }
249 };
Selim Cinekddf1b392016-05-27 16:33:10 -0700250 private OnClickListener mOnClickListener;
Selim Cinek73cf02a2016-06-17 13:08:00 -0700251 private boolean mHeadsupDisappearRunning;
Selim Cineke9bad242016-06-15 11:46:37 -0700252 private View mChildAfterViewWhenDismissed;
253 private View mGroupParentWhenDismissed;
254 private boolean mRefocusOnDismiss;
Selim Cinek2b549f42016-11-22 16:38:51 -0800255 private float mContentTransformationAmount;
Selim Cinek0242fbb2016-10-19 13:38:32 -0700256 private boolean mIconsVisible = true;
Selim Cinekd127d792016-11-01 19:11:41 -0700257 private boolean mAboveShelf;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800258 private boolean mShowAmbient;
Selim Cinek875a3a12016-11-18 17:52:16 -0800259 private boolean mIsLastChild;
Selim Cineke9079112016-12-14 14:41:01 -0800260 private Runnable mOnDismissRunnable;
Selim Cinek6743c0b2017-01-18 18:24:01 -0800261 private boolean mIsLowPriority;
Selim Cineka7ed2c12017-01-23 20:47:24 -0800262 private boolean mIsColorized;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800263 private boolean mUseIncreasedCollapsedHeight;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800264 private boolean mUseIncreasedHeadsUpHeight;
Selim Cinekef8c2252017-02-10 14:52:18 -0800265 private float mTranslationWhenRemoved;
266 private boolean mWasChildInGroupWhenRemoved;
Adrian Roos6f6e1592017-05-02 16:22:53 -0700267 private int mNotificationColorAmbient;
Mady Mellorb0a82462016-04-30 17:31:02 -0700268
Mady Mellor43c2cd12016-12-12 21:05:13 -0800269 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -0700270 public boolean isGroupExpansionChanging() {
271 if (isChildInGroup()) {
272 return mNotificationParent.isGroupExpansionChanging();
273 }
274 return mGroupExpansionChanging;
275 }
276
277 public void setGroupExpansionChanging(boolean changing) {
278 mGroupExpansionChanging = changing;
279 }
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700280
Adrian Roos599be342016-06-13 14:54:39 -0700281 @Override
282 public void setActualHeightAnimating(boolean animating) {
283 if (mPrivateLayout != null) {
284 mPrivateLayout.setContentHeightAnimating(animating);
285 }
286 }
287
Selim Cinek8d490d42015-04-10 00:05:50 -0700288 public NotificationContentView getPrivateLayout() {
289 return mPrivateLayout;
290 }
291
292 public NotificationContentView getPublicLayout() {
293 return mPublicLayout;
294 }
295
Selim Cinekcab4a602014-09-03 14:47:57 +0200296 public void setIconAnimationRunning(boolean running) {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800297 for (NotificationContentView l : mLayouts) {
298 setIconAnimationRunning(running, l);
299 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800300 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700301 setIconAnimationRunningForChild(running, mChildrenContainer.getHeaderView());
Selim Cinek414ad332017-02-24 19:06:12 -0800302 setIconAnimationRunningForChild(running, mChildrenContainer.getLowPriorityHeaderView());
Selim Cinek5a175d92015-11-23 18:01:33 -0800303 List<ExpandableNotificationRow> notificationChildren =
304 mChildrenContainer.getNotificationChildren();
305 for (int i = 0; i < notificationChildren.size(); i++) {
306 ExpandableNotificationRow child = notificationChildren.get(i);
307 child.setIconAnimationRunning(running);
308 }
309 }
310 mIconAnimationRunning = running;
Selim Cinekcab4a602014-09-03 14:47:57 +0200311 }
312
313 private void setIconAnimationRunning(boolean running, NotificationContentView layout) {
314 if (layout != null) {
315 View contractedChild = layout.getContractedChild();
316 View expandedChild = layout.getExpandedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -0700317 View headsUpChild = layout.getHeadsUpChild();
Selim Cinekcab4a602014-09-03 14:47:57 +0200318 setIconAnimationRunningForChild(running, contractedChild);
319 setIconAnimationRunningForChild(running, expandedChild);
Selim Cinek8d490d42015-04-10 00:05:50 -0700320 setIconAnimationRunningForChild(running, headsUpChild);
Selim Cinekcab4a602014-09-03 14:47:57 +0200321 }
322 }
323
324 private void setIconAnimationRunningForChild(boolean running, View child) {
325 if (child != null) {
326 ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon);
327 setIconRunning(icon, running);
328 ImageView rightIcon = (ImageView) child.findViewById(
329 com.android.internal.R.id.right_icon);
330 setIconRunning(rightIcon, running);
331 }
332 }
333
334 private void setIconRunning(ImageView imageView, boolean running) {
335 if (imageView != null) {
336 Drawable drawable = imageView.getDrawable();
337 if (drawable instanceof AnimationDrawable) {
338 AnimationDrawable animationDrawable = (AnimationDrawable) drawable;
339 if (running) {
340 animationDrawable.start();
341 } else {
342 animationDrawable.stop();
343 }
344 } else if (drawable instanceof AnimatedVectorDrawable) {
345 AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable;
346 if (running) {
347 animationDrawable.start();
348 } else {
349 animationDrawable.stop();
350 }
351 }
352 }
353 }
354
Selim Cinek5ba22542017-04-20 15:16:10 -0700355 public void updateNotification(NotificationData.Entry entry) {
Selim Cinekda42d652015-12-04 15:51:16 -0800356 mEntry = entry;
357 mStatusBarNotification = entry.notification;
Selim Cinek1a48bab2017-02-17 19:38:40 -0800358 mNotificationInflater.inflateNotificationViews();
Selim Cinekc478f902017-02-22 20:55:44 -0800359 }
360
Selim Cinek5ba22542017-04-20 15:16:10 -0700361 public void onNotificationUpdated() {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800362 for (NotificationContentView l : mLayouts) {
Selim Cinekc478f902017-02-22 20:55:44 -0800363 l.onNotificationUpdated(mEntry);
Adrian Rooseb434ff2017-01-11 11:18:48 -0800364 }
Selim Cineka7ed2c12017-01-23 20:47:24 -0800365 mIsColorized = mStatusBarNotification.getNotification().isColorized();
Selim Cinek757d8792016-01-28 16:21:08 -0800366 mShowingPublicInitialized = false;
Selim Cinek4bb59342016-04-08 19:29:35 -0700367 updateNotificationColor();
Mady Mellor4c197602017-04-10 17:57:52 -0700368 if (mMenuRow != null) {
Mady Mellor4ab28202017-06-06 11:42:50 -0700369 mMenuRow.onNotificationUpdated(mStatusBarNotification);
Mady Mellor4c197602017-04-10 17:57:52 -0700370 }
Selim Cinek8fc93c92015-11-23 17:48:07 -0800371 if (mIsSummaryWithChildren) {
Selim Cinek414ad332017-02-24 19:06:12 -0800372 mChildrenContainer.recreateNotificationHeader(mExpandClickListener);
Selim Cinekc897bd32016-03-18 17:32:31 -0700373 mChildrenContainer.onNotificationUpdated();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800374 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800375 if (mIconAnimationRunning) {
376 setIconAnimationRunning(true);
377 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800378 if (mNotificationParent != null) {
379 mNotificationParent.updateChildrenHeaderAppearance();
380 }
Selim Cinek263398f2015-10-21 17:40:23 -0700381 onChildrenCountChanged();
Selim Cinek624c02db2015-12-14 21:00:02 -0800382 // The public layouts expand button is always visible
383 mPublicLayout.updateExpandButtons(true);
Selim Cinekda42d652015-12-04 15:51:16 -0800384 updateLimits();
Selim Cinek0242fbb2016-10-19 13:38:32 -0700385 updateIconVisibilities();
Selim Cinek6743c0b2017-01-18 18:24:01 -0800386 updateShelfIconColor();
387 }
388
Lucas Dupinb6ed63b2017-05-30 16:17:42 -0700389 @VisibleForTesting
390 void updateShelfIconColor() {
Selim Cinek6743c0b2017-01-18 18:24:01 -0800391 StatusBarIconView expandedIcon = mEntry.expandedIcon;
392 boolean isPreL = Boolean.TRUE.equals(expandedIcon.getTag(R.id.icon_is_pre_L));
393 boolean colorize = !isPreL || NotificationUtils.isGrayscale(expandedIcon,
394 NotificationColorUtil.getInstance(mContext));
Selim Cinek875ba9b2017-02-13 16:20:17 -0800395 int color = StatusBarIconView.NO_COLOR;
Selim Cinek6743c0b2017-01-18 18:24:01 -0800396 if (colorize) {
Lucas Dupinb6ed63b2017-05-30 16:17:42 -0700397 NotificationHeaderView header = getVisibleNotificationHeader();
398 if (header != null) {
399 color = header.getOriginalIconColor();
400 } else {
401 color = mEntry.getContrastedColor(mContext, mIsLowPriority && !isExpanded(),
402 getBackgroundColorWithoutTint());
403 }
Selim Cinek6743c0b2017-01-18 18:24:01 -0800404 }
Selim Cinek875ba9b2017-02-13 16:20:17 -0800405 expandedIcon.setStaticDrawableColor(color);
Selim Cinekda42d652015-12-04 15:51:16 -0800406 }
407
Selim Cinek5cf1d052017-06-01 17:36:46 -0700408 public void setAboveShelfChangedListener(AboveShelfChangedListener aboveShelfChangedListener) {
409 mAboveShelfChangedListener = aboveShelfChangedListener;
410 }
411
Lucas Dupincecc7c22017-09-12 16:02:45 -0700412 /**
413 * Sets a supplier that can determine whether the keyguard is secure or not.
414 * @param secureStateProvider A function that returns true if keyguard is secure.
415 */
416 public void setSecureStateProvider(BooleanSupplier secureStateProvider) {
417 mSecureStateProvider = secureStateProvider;
418 }
419
Selim Cinek4705f292017-04-24 22:18:48 -0700420 @Override
421 public boolean isDimmable() {
422 if (!getShowingLayout().isDimmable()) {
423 return false;
424 }
425 return super.isDimmable();
426 }
427
Selim Cinekda42d652015-12-04 15:51:16 -0800428 private void updateLimits() {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800429 for (NotificationContentView l : mLayouts) {
430 updateLimitsForView(l);
431 }
Selim Cineka1744872016-03-11 15:36:06 -0800432 }
433
434 private void updateLimitsForView(NotificationContentView layout) {
435 boolean customView = layout.getContractedChild().getId()
Selim Cinekda42d652015-12-04 15:51:16 -0800436 != com.android.internal.R.id.status_bar_latest_event_content;
437 boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800438 int minHeight;
439 if (customView && beforeN && !mIsSummaryWithChildren) {
440 minHeight = mNotificationMinHeightLegacy;
441 } else if (mUseIncreasedCollapsedHeight && layout == mPrivateLayout) {
442 minHeight = mNotificationMinHeightLarge;
443 } else {
444 minHeight = mNotificationMinHeight;
445 }
Selim Cineka1744872016-03-11 15:36:06 -0800446 boolean headsUpCustom = layout.getHeadsUpChild() != null &&
447 layout.getHeadsUpChild().getId()
448 != com.android.internal.R.id.status_bar_latest_event_content;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800449 int headsUpheight;
450 if (headsUpCustom && beforeN) {
451 headsUpheight = mMaxHeadsUpHeightLegacy;
452 } else if (mUseIncreasedHeadsUpHeight && layout == mPrivateLayout) {
453 headsUpheight = mMaxHeadsUpHeightIncreased;
454 } else {
455 headsUpheight = mMaxHeadsUpHeight;
456 }
Selim Cineke62255c2017-09-28 18:23:23 -0700457 NotificationViewWrapper headsUpWrapper = layout.getVisibleWrapper(
458 NotificationContentView.VISIBLE_TYPE_HEADSUP);
459 if (headsUpWrapper != null) {
460 headsUpheight = Math.max(headsUpheight, headsUpWrapper.getMinLayoutHeight());
461 }
Adrian Roos0aac04f2016-12-08 15:59:29 -0800462 layout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight,
463 mNotificationAmbientHeight);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200464 }
465
466 public StatusBarNotification getStatusBarNotification() {
467 return mStatusBarNotification;
468 }
469
Selim Cinek281c2022016-10-13 19:14:43 -0700470 public NotificationData.Entry getEntry() {
471 return mEntry;
472 }
473
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700474 public boolean isHeadsUp() {
475 return mIsHeadsUp;
476 }
477
Selim Cinek1a521f32014-11-03 17:39:29 +0100478 public void setHeadsUp(boolean isHeadsUp) {
Selim Cinek5cf1d052017-06-01 17:36:46 -0700479 boolean wasAboveShelf = isAboveShelf();
Selim Cinekc80fdb12015-04-13 15:09:08 -0700480 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek1a521f32014-11-03 17:39:29 +0100481 mIsHeadsUp = isHeadsUp;
Selim Cinek8d490d42015-04-10 00:05:50 -0700482 mPrivateLayout.setHeadsUp(isHeadsUp);
Selim Cinekb41b2f62016-04-26 14:03:29 -0700483 if (mIsSummaryWithChildren) {
484 // The overflow might change since we allow more lines as HUN.
485 mChildrenContainer.updateGroupOverflow();
486 }
Selim Cinekc80fdb12015-04-13 15:09:08 -0700487 if (intrinsicBefore != getIntrinsicHeight()) {
488 notifyHeightChanged(false /* needsAnimation */);
489 }
Selim Cinekd127d792016-11-01 19:11:41 -0700490 if (isHeadsUp) {
491 setAboveShelf(true);
Selim Cinek5cf1d052017-06-01 17:36:46 -0700492 } else if (isAboveShelf() != wasAboveShelf) {
493 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
Selim Cinekd127d792016-11-01 19:11:41 -0700494 }
Selim Cinek1a521f32014-11-03 17:39:29 +0100495 }
496
Selim Cinekb5605e52015-02-20 18:21:41 +0100497 public void setGroupManager(NotificationGroupManager groupManager) {
498 mGroupManager = groupManager;
Selim Cinek83bc7832015-10-22 13:26:54 -0700499 mPrivateLayout.setGroupManager(groupManager);
Selim Cinekb5605e52015-02-20 18:21:41 +0100500 }
501
Adrian Roosb88b1a12015-12-09 18:51:05 -0800502 public void setRemoteInputController(RemoteInputController r) {
503 mPrivateLayout.setRemoteInputController(r);
504 }
505
Mady Mellor3fd273e2016-03-15 21:08:14 -0700506 public void setAppName(String appName) {
507 mAppName = appName;
Mady Mellor95d743c2017-01-10 12:05:27 -0800508 if (mMenuRow != null && mMenuRow.getMenuView() != null) {
Mady Mellor761cde12017-01-10 11:36:39 -0800509 mMenuRow.setAppName(mAppName);
Mady Mellor3fd273e2016-03-15 21:08:14 -0700510 }
511 }
512
Selim Cinekb5605e52015-02-20 18:21:41 +0100513 public void addChildNotification(ExpandableNotificationRow row) {
514 addChildNotification(row, -1);
515 }
516
517 /**
518 * Add a child notification to this view.
519 *
520 * @param row the row to add
521 * @param childIndex the index to add it at, if -1 it will be added at the end
522 */
523 public void addChildNotification(ExpandableNotificationRow row, int childIndex) {
524 if (mChildrenContainer == null) {
525 mChildrenContainerStub.inflate();
526 }
527 mChildrenContainer.addNotification(row, childIndex);
Selim Cinek263398f2015-10-21 17:40:23 -0700528 onChildrenCountChanged();
529 row.setIsChildInGroup(true, this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100530 }
531
532 public void removeChildNotification(ExpandableNotificationRow row) {
533 if (mChildrenContainer != null) {
534 mChildrenContainer.removeNotification(row);
535 }
Selim Cinek263398f2015-10-21 17:40:23 -0700536 onChildrenCountChanged();
537 row.setIsChildInGroup(false, null);
538 }
539
Mady Mellor43c2cd12016-12-12 21:05:13 -0800540 @Override
Selim Cinek263398f2015-10-21 17:40:23 -0700541 public boolean isChildInGroup() {
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700542 return mNotificationParent != null;
Selim Cinek263398f2015-10-21 17:40:23 -0700543 }
544
Selim Cinek388df6d2015-10-22 13:25:11 -0700545 public ExpandableNotificationRow getNotificationParent() {
546 return mNotificationParent;
547 }
548
Selim Cinek263398f2015-10-21 17:40:23 -0700549 /**
550 * @param isChildInGroup Is this notification now in a group
551 * @param parent the new parent notification
552 */
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700553 public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500554 boolean childInGroup = StatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup;
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700555 mNotificationParent = childInGroup ? parent : null;
556 mPrivateLayout.setIsChildInGroup(childInGroup);
Selim Cinek5ba22542017-04-20 15:16:10 -0700557 mNotificationInflater.setIsChildInGroup(childInGroup);
Mady Mellorc7d65b42016-05-04 11:44:57 -0400558 resetBackgroundAlpha();
Mady Mellorb0a82462016-04-30 17:31:02 -0700559 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -0700560 updateClickAndFocus();
Mady Mellorb0a82462016-04-30 17:31:02 -0700561 if (mNotificationParent != null) {
Selim Cinek9ce32852017-02-15 16:21:10 -0800562 setOverrideTintColor(NO_COLOR, 0.0f);
Mady Mellorb0a82462016-04-30 17:31:02 -0700563 mNotificationParent.updateBackgroundForGroupState();
564 }
Selim Cinekdb167372016-11-17 15:41:17 -0800565 updateIconVisibilities();
Selim Cinek34d93b02015-10-22 12:30:38 -0700566 }
567
568 @Override
Selim Cinek72109472016-01-15 16:33:22 -0800569 public boolean onTouchEvent(MotionEvent event) {
570 if (event.getActionMasked() != MotionEvent.ACTION_DOWN
571 || !isChildInGroup() || isGroupExpanded()) {
572 return super.onTouchEvent(event);
573 } else {
574 return false;
575 }
576 }
577
578 @Override
Mady Mellorf0625802016-02-11 18:03:48 -0800579 protected boolean handleSlideBack() {
Mady Mellor95d743c2017-01-10 12:05:27 -0800580 if (mMenuRow != null && mMenuRow.isMenuVisible()) {
Mady Mellorf0625802016-02-11 18:03:48 -0800581 animateTranslateNotification(0 /* targetLeft */);
582 return true;
583 }
584 return false;
585 }
586
587 @Override
Selim Cinek34d93b02015-10-22 12:30:38 -0700588 protected boolean shouldHideBackground() {
589 return super.shouldHideBackground() || mShowNoBackground;
Selim Cinek263398f2015-10-21 17:40:23 -0700590 }
591
592 @Override
593 public boolean isSummaryWithChildren() {
594 return mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100595 }
596
597 @Override
598 public boolean areChildrenExpanded() {
599 return mChildrenExpanded;
600 }
601
602 public List<ExpandableNotificationRow> getNotificationChildren() {
603 return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren();
604 }
605
Selim Cinekeef84282015-10-30 16:28:00 -0700606 public int getNumberOfNotificationChildren() {
607 if (mChildrenContainer == null) {
608 return 0;
609 }
610 return mChildrenContainer.getNotificationChildren().size();
611 }
612
Selim Cinekb5605e52015-02-20 18:21:41 +0100613 /**
614 * Apply the order given in the list to the children.
615 *
616 * @param childOrder the new list order
Selim Cineka7d4f822016-12-06 14:34:47 -0800617 * @param visualStabilityManager
618 * @param callback the callback to invoked in case it is not allowed
Selim Cinekb5605e52015-02-20 18:21:41 +0100619 * @return whether the list order has changed
620 */
Selim Cineka7d4f822016-12-06 14:34:47 -0800621 public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder,
622 VisualStabilityManager visualStabilityManager,
623 VisualStabilityManager.Callback callback) {
624 return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder,
625 visualStabilityManager, callback);
Selim Cinekb5605e52015-02-20 18:21:41 +0100626 }
627
628 public void getChildrenStates(StackScrollState resultState) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700629 if (mIsSummaryWithChildren) {
Selim Cinekbbcebde2016-11-09 18:28:20 -0800630 ExpandableViewState parentState = resultState.getViewStateForView(this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100631 mChildrenContainer.getState(resultState, parentState);
632 }
633 }
634
635 public void applyChildrenState(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700636 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100637 mChildrenContainer.applyState(state);
638 }
639 }
640
641 public void prepareExpansionChanged(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700642 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100643 mChildrenContainer.prepareExpansionChanged(state);
644 }
645 }
646
Selim Cinek0cfbef42016-11-09 19:06:36 -0800647 public void startChildAnimation(StackScrollState finalState, AnimationProperties properties) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700648 if (mIsSummaryWithChildren) {
Selim Cinek0cfbef42016-11-09 19:06:36 -0800649 mChildrenContainer.startAnimationToState(finalState, properties);
Selim Cinekb5605e52015-02-20 18:21:41 +0100650 }
651 }
652
653 public ExpandableNotificationRow getViewAtPosition(float y) {
Selim Cinek43d30f02016-03-04 10:51:32 -0800654 if (!mIsSummaryWithChildren || !mChildrenExpanded) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100655 return this;
656 } else {
657 ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y);
658 return view == null ? this : view;
659 }
660 }
661
Selim Cinekab29aeb2015-02-20 18:18:32 +0100662 public NotificationGuts getGuts() {
663 return mGuts;
664 }
665
Selim Cinek684a4422015-04-15 16:18:39 -0700666 /**
667 * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this
668 * the notification will be rendered on top of the screen.
669 *
670 * @param pinned whether it is pinned
671 */
672 public void setPinned(boolean pinned) {
Selim Cinekdef35a82016-05-03 15:52:51 -0700673 int intrinsicHeight = getIntrinsicHeight();
Selim Cinek5cf1d052017-06-01 17:36:46 -0700674 boolean wasAboveShelf = isAboveShelf();
Selim Cinek684a4422015-04-15 16:18:39 -0700675 mIsPinned = pinned;
Selim Cinekdef35a82016-05-03 15:52:51 -0700676 if (intrinsicHeight != getIntrinsicHeight()) {
Selim Cinekbb42b7d2016-08-10 13:02:38 -0700677 notifyHeightChanged(false /* needsAnimation */);
Selim Cinekdef35a82016-05-03 15:52:51 -0700678 }
Selim Cinek31aada42015-12-18 17:51:15 -0800679 if (pinned) {
680 setIconAnimationRunning(true);
681 mExpandedWhenPinned = false;
682 } else if (mExpandedWhenPinned) {
683 setUserExpanded(true);
684 }
Selim Cinek98713a42015-09-21 15:47:20 +0200685 setChronometerRunning(mLastChronometerRunning);
Selim Cinek5cf1d052017-06-01 17:36:46 -0700686 if (isAboveShelf() != wasAboveShelf) {
687 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
688 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700689 }
690
Selim Cinek684a4422015-04-15 16:18:39 -0700691 public boolean isPinned() {
692 return mIsPinned;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700693 }
694
Selim Cinekd127d792016-11-01 19:11:41 -0700695 @Override
696 public int getPinnedHeadsUpHeight() {
697 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
698 }
699
Selim Cinek31aada42015-12-18 17:51:15 -0800700 /**
701 * @param atLeastMinHeight should the value returned be at least the minimum height.
702 * Used to avoid cyclic calls
703 * @return the height of the heads up notification when pinned
704 */
Selim Cinekd127d792016-11-01 19:11:41 -0700705 private int getPinnedHeadsUpHeight(boolean atLeastMinHeight) {
Selim Cinek77019c72015-12-09 10:18:02 -0800706 if (mIsSummaryWithChildren) {
707 return mChildrenContainer.getIntrinsicHeight();
708 }
Selim Cinek31aada42015-12-18 17:51:15 -0800709 if(mExpandedWhenPinned) {
710 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
711 } else if (atLeastMinHeight) {
Selim Cinek567e8452016-03-24 10:54:56 -0700712 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek31aada42015-12-18 17:51:15 -0800713 } else {
714 return mHeadsUpHeight;
715 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700716 }
717
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700718 /**
719 * Mark whether this notification was just clicked, i.e. the user has just clicked this
720 * notification in this frame.
721 */
722 public void setJustClicked(boolean justClicked) {
723 mJustClicked = justClicked;
724 }
725
726 /**
727 * @return true if this notification has been clicked in this frame, false otherwise
728 */
729 public boolean wasJustClicked() {
730 return mJustClicked;
731 }
732
Selim Cinek98713a42015-09-21 15:47:20 +0200733 public void setChronometerRunning(boolean running) {
734 mLastChronometerRunning = running;
735 setChronometerRunning(running, mPrivateLayout);
736 setChronometerRunning(running, mPublicLayout);
737 if (mChildrenContainer != null) {
738 List<ExpandableNotificationRow> notificationChildren =
739 mChildrenContainer.getNotificationChildren();
740 for (int i = 0; i < notificationChildren.size(); i++) {
741 ExpandableNotificationRow child = notificationChildren.get(i);
742 child.setChronometerRunning(running);
743 }
744 }
745 }
746
747 private void setChronometerRunning(boolean running, NotificationContentView layout) {
748 if (layout != null) {
749 running = running || isPinned();
750 View contractedChild = layout.getContractedChild();
751 View expandedChild = layout.getExpandedChild();
752 View headsUpChild = layout.getHeadsUpChild();
753 setChronometerRunningForChild(running, contractedChild);
754 setChronometerRunningForChild(running, expandedChild);
755 setChronometerRunningForChild(running, headsUpChild);
756 }
757 }
758
759 private void setChronometerRunningForChild(boolean running, View child) {
760 if (child != null) {
761 View chronometer = child.findViewById(com.android.internal.R.id.chronometer);
762 if (chronometer instanceof Chronometer) {
763 ((Chronometer) chronometer).setStarted(running);
764 }
765 }
766 }
767
Selim Cinekea4bef72015-12-02 15:51:10 -0800768 public NotificationHeaderView getNotificationHeader() {
Mady Mellorb0a82462016-04-30 17:31:02 -0700769 if (mIsSummaryWithChildren) {
770 return mChildrenContainer.getHeaderView();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700771 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800772 return mPrivateLayout.getNotificationHeader();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700773 }
774
Selim Cinek414ad332017-02-24 19:06:12 -0800775 /**
776 * @return the currently visible notification header. This can be different from
777 * {@link #getNotificationHeader()} in case it is a low-priority group.
778 */
779 public NotificationHeaderView getVisibleNotificationHeader() {
Selim Cinekaa3901a2016-08-05 11:04:37 -0700780 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinek414ad332017-02-24 19:06:12 -0800781 return mChildrenContainer.getVisibleHeader();
Selim Cinek34eda5e2016-02-18 17:10:43 -0800782 }
783 return getShowingLayout().getVisibleNotificationHeader();
784 }
785
Selim Cinekb26afa32017-06-29 10:28:17 +0200786
787 /**
788 * @return the contracted notification header. This can be different from
789 * {@link #getNotificationHeader()} and also {@link #getVisibleNotificationHeader()} and only
790 * returns the contracted version.
791 */
792 public NotificationHeaderView getContractedNotificationHeader() {
793 if (mIsSummaryWithChildren) {
794 return mChildrenContainer.getHeaderView();
795 }
796 return mPrivateLayout.getContractedNotificationHeader();
797 }
798
Selim Cinek570981d2015-12-01 11:37:01 -0800799 public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) {
800 mOnExpandClickListener = onExpandClickListener;
801 }
802
Geoffrey Pitsch409db272017-08-28 14:51:52 +0000803 public void setLongPressListener(LongPressListener longPressListener) {
804 mLongPressListener = longPressListener;
805 }
806
Selim Cinekddf1b392016-05-27 16:33:10 -0700807 @Override
808 public void setOnClickListener(@Nullable OnClickListener l) {
809 super.setOnClickListener(l);
810 mOnClickListener = l;
811 updateClickAndFocus();
812 }
813
814 private void updateClickAndFocus() {
815 boolean normalChild = !isChildInGroup() || isGroupExpanded();
816 boolean clickable = mOnClickListener != null && normalChild;
817 if (isFocusable() != normalChild) {
818 setFocusable(normalChild);
819 }
820 if (isClickable() != clickable) {
821 setClickable(clickable);
822 }
823 }
824
Selim Cinek31aada42015-12-18 17:51:15 -0800825 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
826 mHeadsUpManager = headsUpManager;
827 }
828
Mady Mellor87d79452017-01-10 11:52:52 -0800829 public void setGutsView(MenuItem item) {
Mady Mellor95d743c2017-01-10 12:05:27 -0800830 if (mGuts != null && item.getGutsView() instanceof GutsContent) {
831 ((GutsContent) item.getGutsView()).setGutsParent(mGuts);
832 mGuts.setGutsContent((GutsContent) item.getGutsView());
Mady Mellor87d79452017-01-10 11:52:52 -0800833 }
834 }
835
Mady Mellor95d743c2017-01-10 12:05:27 -0800836 @Override
837 protected void onAttachedToWindow() {
838 super.onAttachedToWindow();
839 Dependency.get(PluginManager.class).addPluginListener(this,
840 NotificationMenuRowPlugin.class, false /* Allow multiple */);
841 }
842
843 @Override
844 protected void onDetachedFromWindow() {
845 super.onDetachedFromWindow();
846 Dependency.get(PluginManager.class).removePluginListener(this);
847 }
848
849 @Override
850 public void onPluginConnected(NotificationMenuRowPlugin plugin, Context pluginContext) {
851 boolean existed = mMenuRow.getMenuView() != null;
852 if (existed) {
853 removeView(mMenuRow.getMenuView());
854 }
855 mMenuRow = plugin;
856 if (mMenuRow.useDefaultMenuItems()) {
Mady Mellor4c197602017-04-10 17:57:52 -0700857 ArrayList<MenuItem> items = new ArrayList<>();
858 items.add(NotificationMenuRow.createInfoItem(mContext));
859 items.add(NotificationMenuRow.createSnoozeItem(mContext));
860 mMenuRow.setMenuItems(items);
Mady Mellor95d743c2017-01-10 12:05:27 -0800861 }
862 if (existed) {
863 createMenu();
864 }
865 }
866
867 @Override
868 public void onPluginDisconnected(NotificationMenuRowPlugin plugin) {
869 boolean existed = mMenuRow.getMenuView() != null;
870 mMenuRow = new NotificationMenuRow(mContext); // Back to default
871 if (existed) {
872 createMenu();
873 }
874 }
875
876 public NotificationMenuRowPlugin createMenu() {
877 if (mMenuRow.getMenuView() == null) {
Mady Mellor4ab28202017-06-06 11:42:50 -0700878 mMenuRow.createMenu(this, mStatusBarNotification);
Mady Mellor95d743c2017-01-10 12:05:27 -0800879 mMenuRow.setAppName(mAppName);
880 FrameLayout.LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
881 LayoutParams.MATCH_PARENT);
882 addView(mMenuRow.getMenuView(), MENU_VIEW_INDEX, lp);
883 }
884 return mMenuRow;
885 }
886
Mady Mellor95d743c2017-01-10 12:05:27 -0800887 public NotificationMenuRowPlugin getProvider() {
888 return mMenuRow;
889 }
890
Anthony Chen9fe1ee72017-04-07 13:53:37 -0700891 @Override
Selim Cinek1a48bab2017-02-17 19:38:40 -0800892 public void onDensityOrFontScaleChanged() {
Anthony Chen9fe1ee72017-04-07 13:53:37 -0700893 super.onDensityOrFontScaleChanged();
Selim Cinek01af3342016-02-09 19:25:31 -0800894 initDimens();
Anthony Chenad4d1582017-04-10 16:07:58 -0700895 initBackground();
Selim Cinek817abe72017-05-24 11:08:55 -0700896 // Let's update our childrencontainer. This is intentionally not guarded with
897 // mIsSummaryWithChildren since we might have had children but not anymore.
898 if (mChildrenContainer != null) {
899 mChildrenContainer.reInflateViews(mExpandClickListener, mEntry.notification);
Selim Cinek01af3342016-02-09 19:25:31 -0800900 }
901 if (mGuts != null) {
902 View oldGuts = mGuts;
903 int index = indexOfChild(oldGuts);
904 removeView(oldGuts);
905 mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate(
906 R.layout.notification_guts, this, false);
907 mGuts.setVisibility(oldGuts.getVisibility());
908 addView(mGuts, index);
909 }
Mady Mellor95d743c2017-01-10 12:05:27 -0800910 View oldMenu = mMenuRow.getMenuView();
911 if (oldMenu != null) {
Mady Mellor761cde12017-01-10 11:36:39 -0800912 int menuIndex = indexOfChild(oldMenu);
913 removeView(oldMenu);
Mady Mellor4ab28202017-06-06 11:42:50 -0700914 mMenuRow.createMenu(ExpandableNotificationRow.this, mStatusBarNotification);
Mady Mellor761cde12017-01-10 11:36:39 -0800915 mMenuRow.setAppName(mAppName);
Mady Mellor95d743c2017-01-10 12:05:27 -0800916 addView(mMenuRow.getMenuView(), menuIndex);
Mady Mellor4b80b102016-01-22 08:03:58 -0800917 }
Adrian Rooseb434ff2017-01-11 11:18:48 -0800918 for (NotificationContentView l : mLayouts) {
919 l.reInflateViews();
920 }
Selim Cinek1a48bab2017-02-17 19:38:40 -0800921 mNotificationInflater.onDensityOrFontScaleChanged();
922 onNotificationUpdated();
Selim Cinek01af3342016-02-09 19:25:31 -0800923 }
924
Mady Mellor9d03a522017-04-04 18:45:30 -0700925 @Override
926 public void onConfigurationChanged(Configuration newConfig) {
927 if (mMenuRow.getMenuView() != null) {
928 mMenuRow.onConfigurationChanged();
929 }
930 }
931
Selim Cinekc3179332016-03-04 14:44:56 -0800932 public void setContentBackground(int customBackgroundColor, boolean animate,
933 NotificationContentView notificationContentView) {
934 if (getShowingLayout() == notificationContentView) {
935 setTintColor(customBackgroundColor, animate);
936 }
937 }
938
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700939 public void closeRemoteInput() {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800940 for (NotificationContentView l : mLayouts) {
941 l.closeRemoteInput();
942 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700943 }
944
Selim Cinekc897bd32016-03-18 17:32:31 -0700945 /**
946 * Set by how much the single line view should be indented.
947 */
948 public void setSingleLineWidthIndention(int indention) {
949 mPrivateLayout.setSingleLineWidthIndention(indention);
950 }
951
952 public int getNotificationColor() {
Selim Cinek4bb59342016-04-08 19:29:35 -0700953 return mNotificationColor;
954 }
955
956 private void updateNotificationColor() {
957 mNotificationColor = NotificationColorUtil.resolveContrastColor(mContext,
Selim Cinekac5f0272017-05-02 16:05:41 -0700958 getStatusBarNotification().getNotification().color,
959 getBackgroundColorWithoutTint());
Adrian Roos6f6e1592017-05-02 16:22:53 -0700960 mNotificationColorAmbient = NotificationColorUtil.resolveAmbientColor(mContext,
961 getStatusBarNotification().getNotification().color);
Selim Cinekc897bd32016-03-18 17:32:31 -0700962 }
963
964 public HybridNotificationView getSingleLineView() {
965 return mPrivateLayout.getSingleLineView();
966 }
967
Adrian Roos6f6e1592017-05-02 16:22:53 -0700968 public HybridNotificationView getAmbientSingleLineView() {
969 return getShowingLayout().getAmbientSingleLineChild();
970 }
971
Selim Cinekf07d0622016-03-21 19:52:52 -0700972 public boolean isOnKeyguard() {
973 return mOnKeyguard;
974 }
975
Selim Cinekc1e389d2016-04-07 11:02:57 -0700976 public void removeAllChildren() {
977 List<ExpandableNotificationRow> notificationChildren
978 = mChildrenContainer.getNotificationChildren();
979 ArrayList<ExpandableNotificationRow> clonedList = new ArrayList<>(notificationChildren);
980 for (int i = 0; i < clonedList.size(); i++) {
981 ExpandableNotificationRow row = clonedList.get(i);
Selim Cinek3f19f602016-05-02 18:01:56 -0700982 if (row.keepInParent()) {
983 continue;
984 }
Selim Cinekc1e389d2016-04-07 11:02:57 -0700985 mChildrenContainer.removeNotification(row);
Selim Cinekc1e389d2016-04-07 11:02:57 -0700986 row.setIsChildInGroup(false, null);
987 }
988 onChildrenCountChanged();
989 }
990
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700991 public void setForceUnlocked(boolean forceUnlocked) {
992 mForceUnlocked = forceUnlocked;
993 if (mIsSummaryWithChildren) {
994 List<ExpandableNotificationRow> notificationChildren = getNotificationChildren();
995 for (ExpandableNotificationRow child : notificationChildren) {
996 child.setForceUnlocked(forceUnlocked);
997 }
998 }
999 }
1000
Selim Cineke9bad242016-06-15 11:46:37 -07001001 public void setDismissed(boolean dismissed, boolean fromAccessibility) {
Selim Cinek3f19f602016-05-02 18:01:56 -07001002 mDismissed = dismissed;
Selim Cineke9bad242016-06-15 11:46:37 -07001003 mGroupParentWhenDismissed = mNotificationParent;
1004 mRefocusOnDismiss = fromAccessibility;
1005 mChildAfterViewWhenDismissed = null;
1006 if (isChildInGroup()) {
1007 List<ExpandableNotificationRow> notificationChildren =
1008 mNotificationParent.getNotificationChildren();
1009 int i = notificationChildren.indexOf(this);
1010 if (i != -1 && i < notificationChildren.size() - 1) {
1011 mChildAfterViewWhenDismissed = notificationChildren.get(i + 1);
1012 }
1013 }
Selim Cinek3f19f602016-05-02 18:01:56 -07001014 }
1015
1016 public boolean isDismissed() {
1017 return mDismissed;
1018 }
1019
1020 public boolean keepInParent() {
1021 return mKeepInParent;
1022 }
1023
1024 public void setKeepInParent(boolean keepInParent) {
1025 mKeepInParent = keepInParent;
1026 }
1027
1028 public boolean isRemoved() {
1029 return mRemoved;
1030 }
1031
Adrian Roosd009ab12016-05-20 17:58:53 -07001032 public void setRemoved() {
1033 mRemoved = true;
Selim Cinekef8c2252017-02-10 14:52:18 -08001034 mTranslationWhenRemoved = getTranslationY();
1035 mWasChildInGroupWhenRemoved = isChildInGroup();
1036 if (isChildInGroup()) {
1037 mTranslationWhenRemoved += getNotificationParent().getTranslationY();
1038 }
Adrian Roosd009ab12016-05-20 17:58:53 -07001039 mPrivateLayout.setRemoved();
Selim Cinek3f19f602016-05-02 18:01:56 -07001040 }
1041
Selim Cinekef8c2252017-02-10 14:52:18 -08001042 public boolean wasChildInGroupWhenRemoved() {
1043 return mWasChildInGroupWhenRemoved;
1044 }
1045
1046 public float getTranslationWhenRemoved() {
1047 return mTranslationWhenRemoved;
1048 }
1049
Selim Cinekd1395642016-04-28 12:22:42 -07001050 public NotificationChildrenContainer getChildrenContainer() {
1051 return mChildrenContainer;
1052 }
1053
Selim Cinekcafa87f2016-10-26 17:00:17 -07001054 public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) {
Selim Cinek5cf1d052017-06-01 17:36:46 -07001055 boolean wasAboveShelf = isAboveShelf();
Selim Cinekcafa87f2016-10-26 17:00:17 -07001056 mHeadsupDisappearRunning = headsUpAnimatingAway;
1057 mPrivateLayout.setHeadsUpAnimatingAway(headsUpAnimatingAway);
Selim Cinek5cf1d052017-06-01 17:36:46 -07001058 if (isAboveShelf() != wasAboveShelf) {
1059 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
1060 }
Selim Cinekcafa87f2016-10-26 17:00:17 -07001061 }
1062
1063 /**
1064 * @return if the view was just heads upped and is now animating away. During such a time the
1065 * layout needs to be kept consistent
1066 */
1067 public boolean isHeadsUpAnimatingAway() {
1068 return mHeadsupDisappearRunning;
Selim Cinek73cf02a2016-06-17 13:08:00 -07001069 }
1070
Selim Cineke9bad242016-06-15 11:46:37 -07001071 public View getChildAfterViewWhenDismissed() {
1072 return mChildAfterViewWhenDismissed;
1073 }
1074
1075 public View getGroupParentWhenDismissed() {
1076 return mGroupParentWhenDismissed;
1077 }
1078
Selim Cinek9e624e72016-07-20 13:46:49 -07001079 public void performDismiss() {
Selim Cineke9079112016-12-14 14:41:01 -08001080 if (mOnDismissRunnable != null) {
1081 mOnDismissRunnable.run();
1082 }
Selim Cinek9e624e72016-07-20 13:46:49 -07001083 }
1084
Selim Cineke9079112016-12-14 14:41:01 -08001085 public void setOnDismissRunnable(Runnable onDismissRunnable) {
1086 mOnDismissRunnable = onDismissRunnable;
Selim Cinek9e624e72016-07-20 13:46:49 -07001087 }
1088
Selim Cinek281c2022016-10-13 19:14:43 -07001089 public View getNotificationIcon() {
Selim Cinek414ad332017-02-24 19:06:12 -08001090 NotificationHeaderView notificationHeader = getVisibleNotificationHeader();
Selim Cinek281c2022016-10-13 19:14:43 -07001091 if (notificationHeader != null) {
1092 return notificationHeader.getIcon();
1093 }
1094 return null;
1095 }
1096
1097 /**
1098 * @return whether the notification is currently showing a view with an icon.
1099 */
1100 public boolean isShowingIcon() {
Mady Mellor434180c2017-02-13 11:29:42 -08001101 if (areGutsExposed()) {
1102 return false;
1103 }
Selim Cinek2ffa02f2017-03-06 15:56:37 -08001104 return getVisibleNotificationHeader() != null;
Selim Cinek281c2022016-10-13 19:14:43 -07001105 }
1106
Selim Cinek0242fbb2016-10-19 13:38:32 -07001107 /**
1108 * Set how much this notification is transformed into an icon.
1109 *
Selim Cinek2b549f42016-11-22 16:38:51 -08001110 * @param contentTransformationAmount A value from 0 to 1 indicating how much we are transformed
1111 * to the content away
Selim Cinek875a3a12016-11-18 17:52:16 -08001112 * @param isLastChild is this the last child in the list. If true, then the transformation is
1113 * different since it's content fades out.
Selim Cinek0242fbb2016-10-19 13:38:32 -07001114 */
Selim Cinek2b549f42016-11-22 16:38:51 -08001115 public void setContentTransformationAmount(float contentTransformationAmount,
1116 boolean isLastChild) {
Selim Cinek875a3a12016-11-18 17:52:16 -08001117 boolean changeTransformation = isLastChild != mIsLastChild;
Selim Cinek2b549f42016-11-22 16:38:51 -08001118 changeTransformation |= mContentTransformationAmount != contentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001119 mIsLastChild = isLastChild;
Selim Cinek2b549f42016-11-22 16:38:51 -08001120 mContentTransformationAmount = contentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001121 if (changeTransformation) {
1122 updateContentTransformation();
Selim Cinek2b549f42016-11-22 16:38:51 -08001123 }
1124 }
1125
1126 /**
1127 * Set the icons to be visible of this notification.
1128 */
1129 public void setIconsVisible(boolean iconsVisible) {
1130 if (iconsVisible != mIconsVisible) {
1131 mIconsVisible = iconsVisible;
1132 updateIconVisibilities();
Selim Cinek0242fbb2016-10-19 13:38:32 -07001133 }
1134 }
1135
Selim Cinekdb167372016-11-17 15:41:17 -08001136 @Override
1137 protected void onBelowSpeedBumpChanged() {
1138 updateIconVisibilities();
1139 }
1140
Selim Cinek875a3a12016-11-18 17:52:16 -08001141 private void updateContentTransformation() {
1142 float contentAlpha;
Selim Cinek2b549f42016-11-22 16:38:51 -08001143 float translationY = -mContentTransformationAmount * mIconTransformContentShift;
Selim Cinek875a3a12016-11-18 17:52:16 -08001144 if (mIsLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -08001145 contentAlpha = 1.0f - mContentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001146 contentAlpha = Math.min(contentAlpha / 0.5f, 1.0f);
Selim Cinek0242fbb2016-10-19 13:38:32 -07001147 contentAlpha = Interpolators.ALPHA_OUT.getInterpolation(contentAlpha);
Selim Cinek875a3a12016-11-18 17:52:16 -08001148 translationY *= 0.4f;
1149 } else {
1150 contentAlpha = 1.0f;
1151 }
Adrian Rooseb434ff2017-01-11 11:18:48 -08001152 for (NotificationContentView l : mLayouts) {
1153 l.setAlpha(contentAlpha);
1154 l.setTranslationY(translationY);
1155 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001156 if (mChildrenContainer != null) {
1157 mChildrenContainer.setAlpha(contentAlpha);
1158 mChildrenContainer.setTranslationY(translationY);
1159 // TODO: handle children fade out better
Selim Cinek0242fbb2016-10-19 13:38:32 -07001160 }
1161 }
1162
1163 private void updateIconVisibilities() {
Selim Cinek17e1b692016-12-02 18:19:11 -08001164 boolean visible = isChildInGroup()
1165 || (isBelowSpeedBump() && !NotificationShelf.SHOW_AMBIENT_ICONS)
1166 || mIconsVisible;
Adrian Rooseb434ff2017-01-11 11:18:48 -08001167 for (NotificationContentView l : mLayouts) {
1168 l.setIconsVisible(visible);
1169 }
Selim Cinekdb167372016-11-17 15:41:17 -08001170 if (mChildrenContainer != null) {
1171 mChildrenContainer.setIconsVisible(visible);
Selim Cinek0242fbb2016-10-19 13:38:32 -07001172 }
1173 }
1174
Selim Cinek875a3a12016-11-18 17:52:16 -08001175 /**
1176 * Get the relative top padding of a view relative to this view. This recursively walks up the
1177 * hierarchy and does the corresponding measuring.
1178 *
1179 * @param view the view to the the padding for. The requested view has to be a child of this
1180 * notification.
1181 * @return the toppadding
1182 */
1183 public int getRelativeTopPadding(View view) {
1184 int topPadding = 0;
1185 while (view.getParent() instanceof ViewGroup) {
1186 topPadding += view.getTop();
1187 view = (View) view.getParent();
1188 if (view instanceof ExpandableNotificationRow) {
1189 return topPadding;
1190 }
1191 }
1192 return topPadding;
1193 }
1194
Selim Cineka1d97902016-12-14 16:31:40 -08001195 public float getContentTranslation() {
1196 return mPrivateLayout.getTranslationY();
1197 }
1198
Selim Cinek6743c0b2017-01-18 18:24:01 -08001199 public void setIsLowPriority(boolean isLowPriority) {
1200 mIsLowPriority = isLowPriority;
1201 mPrivateLayout.setIsLowPriority(isLowPriority);
Selim Cinek1a48bab2017-02-17 19:38:40 -08001202 mNotificationInflater.setIsLowPriority(mIsLowPriority);
Selim Cinek6743c0b2017-01-18 18:24:01 -08001203 if (mChildrenContainer != null) {
1204 mChildrenContainer.setIsLowPriority(isLowPriority);
1205 }
1206 }
1207
Selim Cinek55a3e732017-05-25 18:30:10 -07001208
1209 public void setLowPriorityStateUpdated(boolean lowPriorityStateUpdated) {
1210 mLowPriorityStateUpdated = lowPriorityStateUpdated;
1211 }
1212
1213 public boolean hasLowPriorityStateUpdated() {
1214 return mLowPriorityStateUpdated;
1215 }
1216
Selim Cinek414ad332017-02-24 19:06:12 -08001217 public boolean isLowPriority() {
1218 return mIsLowPriority;
1219 }
1220
Selim Cinek7d1009b2017-01-25 15:28:28 -08001221 public void setUseIncreasedCollapsedHeight(boolean use) {
1222 mUseIncreasedCollapsedHeight = use;
Selim Cinek1a48bab2017-02-17 19:38:40 -08001223 mNotificationInflater.setUsesIncreasedHeight(use);
Selim Cinek7d1009b2017-01-25 15:28:28 -08001224 }
1225
Selim Cinek87ed69b2017-02-09 15:59:43 -08001226 public void setUseIncreasedHeadsUpHeight(boolean use) {
1227 mUseIncreasedHeadsUpHeight = use;
Selim Cinek1a48bab2017-02-17 19:38:40 -08001228 mNotificationInflater.setUsesIncreasedHeadsUpHeight(use);
1229 }
1230
1231 public void setRemoteViewClickHandler(RemoteViews.OnClickHandler remoteViewClickHandler) {
1232 mNotificationInflater.setRemoteViewClickHandler(remoteViewClickHandler);
Selim Cinek87ed69b2017-02-09 15:59:43 -08001233 }
1234
Selim Cinek5ba22542017-04-20 15:16:10 -07001235 public void setInflationCallback(InflationCallback callback) {
1236 mNotificationInflater.setInflationCallback(callback);
Selim Cinekc478f902017-02-22 20:55:44 -08001237 }
1238
Adrian Roos1a1ecfc2017-04-17 11:17:59 -07001239 public void setNeedsRedaction(boolean needsRedaction) {
1240 mNotificationInflater.setRedactAmbient(needsRedaction);
1241 }
1242
Selim Cinek5ba22542017-04-20 15:16:10 -07001243 @VisibleForTesting
1244 public NotificationInflater getNotificationInflater() {
1245 return mNotificationInflater;
1246 }
1247
Adrian Roos6f6e1592017-05-02 16:22:53 -07001248 public int getNotificationColorAmbient() {
1249 return mNotificationColorAmbient;
1250 }
1251
Chris Wren78403d72014-07-28 10:23:24 +01001252 public interface ExpansionLogger {
Anthony Chen6bf88a02017-04-10 14:41:44 -07001253 void logNotificationExpansion(String key, boolean userAction, boolean expanded);
Chris Wren78403d72014-07-28 10:23:24 +01001254 }
Selim Cinek1685e632014-04-08 02:27:49 +02001255
Chris Wren51c75102013-07-16 20:49:17 -04001256 public ExpandableNotificationRow(Context context, AttributeSet attrs) {
1257 super(context, attrs);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001258 mFalsingManager = FalsingManager.getInstance(context);
Selim Cinek1a48bab2017-02-17 19:38:40 -08001259 mNotificationInflater = new NotificationInflater(this);
Mady Mellor95d743c2017-01-10 12:05:27 -08001260 mMenuRow = new NotificationMenuRow(mContext);
Selim Cinek01af3342016-02-09 19:25:31 -08001261 initDimens();
1262 }
1263
1264 private void initDimens() {
Selim Cineke62255c2017-09-28 18:23:23 -07001265 mNotificationMinHeightLegacy = NotificationUtils.getFontScaledHeight(mContext,
1266 R.dimen.notification_min_height_legacy);
1267 mNotificationMinHeight = NotificationUtils.getFontScaledHeight(mContext,
1268 R.dimen.notification_min_height);
1269 mNotificationMinHeightLarge = NotificationUtils.getFontScaledHeight(mContext,
Selim Cinek87ed69b2017-02-09 15:59:43 -08001270 R.dimen.notification_min_height_increased);
Selim Cineke62255c2017-09-28 18:23:23 -07001271 mNotificationMaxHeight = NotificationUtils.getFontScaledHeight(mContext,
1272 R.dimen.notification_max_height);
1273 mNotificationAmbientHeight = NotificationUtils.getFontScaledHeight(mContext,
1274 R.dimen.notification_ambient_height);
1275 mMaxHeadsUpHeightLegacy = NotificationUtils.getFontScaledHeight(mContext,
Selim Cinek77019c72015-12-09 10:18:02 -08001276 R.dimen.notification_max_heads_up_height_legacy);
Selim Cineke62255c2017-09-28 18:23:23 -07001277 mMaxHeadsUpHeight = NotificationUtils.getFontScaledHeight(mContext,
1278 R.dimen.notification_max_heads_up_height);
1279 mMaxHeadsUpHeightIncreased = NotificationUtils.getFontScaledHeight(mContext,
Selim Cinek87ed69b2017-02-09 15:59:43 -08001280 R.dimen.notification_max_heads_up_height_increased);
Anthony Chen6bf88a02017-04-10 14:41:44 -07001281
Anthony Chen7acbb772017-04-07 16:45:25 -07001282 Resources res = getResources();
1283 mIncreasedPaddingBetweenElements = res.getDimensionPixelSize(
1284 R.dimen.notification_divider_height_increased);
1285 mIconTransformContentShiftNoIcon = res.getDimensionPixelSize(
Selim Cinek0242fbb2016-10-19 13:38:32 -07001286 R.dimen.notification_icon_transform_content_shift);
Anthony Chen6bf88a02017-04-10 14:41:44 -07001287 mEnableNonGroupedNotificationExpand =
1288 res.getBoolean(R.bool.config_enableNonGroupedNotificationExpand);
1289 mShowGroupBackgroundWhenExpanded =
1290 res.getBoolean(R.bool.config_showGroupNotificationBgWhenExpanded);
Selim Cinekf619ffc2016-02-17 14:53:05 -08001291 }
1292
1293 /**
Christoph Studera7fe6312014-06-27 19:32:44 +02001294 * Resets this view so it can be re-used for an updated notification.
1295 */
1296 public void reset() {
Jorim Jaggiae441282014-08-01 02:45:18 +02001297 mShowingPublicInitialized = false;
Selim Cinek31094df2014-08-14 19:28:15 +02001298 onHeightReset();
Selim Cinek6e28a672014-09-05 14:43:28 +02001299 requestLayout();
Christoph Studera7fe6312014-06-27 19:32:44 +02001300 }
1301
Jorim Jaggi251957d2014-04-09 04:24:09 +02001302 @Override
1303 protected void onFinishInflate() {
1304 super.onFinishInflate();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001305 mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic);
1306 mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded);
Adrian Rooseb434ff2017-01-11 11:18:48 -08001307 mLayouts = new NotificationContentView[] {mPrivateLayout, mPublicLayout};
1308
1309 for (NotificationContentView l : mLayouts) {
1310 l.setExpandClickListener(mExpandClickListener);
1311 l.setContainingNotification(this);
1312 }
Selim Cinekab29aeb2015-02-20 18:18:32 +01001313 mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub);
1314 mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() {
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001315 @Override
1316 public void onInflate(ViewStub stub, View inflated) {
1317 mGuts = (NotificationGuts) inflated;
1318 mGuts.setClipTopAmount(getClipTopAmount());
1319 mGuts.setActualHeight(getActualHeight());
Selim Cinekab29aeb2015-02-20 18:18:32 +01001320 mGutsStub = null;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001321 }
1322 });
Selim Cinekb5605e52015-02-20 18:21:41 +01001323 mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub);
1324 mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() {
1325
1326 @Override
1327 public void onInflate(ViewStub stub, View inflated) {
1328 mChildrenContainer = (NotificationChildrenContainer) inflated;
Selim Cinek6743c0b2017-01-18 18:24:01 -08001329 mChildrenContainer.setIsLowPriority(mIsLowPriority);
Selim Cinek414ad332017-02-24 19:06:12 -08001330 mChildrenContainer.setContainingNotification(ExpandableNotificationRow.this);
Selim Cinekc897bd32016-03-18 17:32:31 -07001331 mChildrenContainer.onNotificationUpdated();
Anthony Chen7acbb772017-04-07 16:45:25 -07001332
1333 if (mShouldTranslateContents) {
1334 mTranslateableViews.add(mChildrenContainer);
1335 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001336 }
1337 });
Mady Mellor4b80b102016-01-22 08:03:58 -08001338
Anthony Chen7acbb772017-04-07 16:45:25 -07001339 if (mShouldTranslateContents) {
1340 // Add the views that we translate to reveal the menu
1341 mTranslateableViews = new ArrayList<>();
1342 for (int i = 0; i < getChildCount(); i++) {
1343 mTranslateableViews.add(getChildAt(i));
1344 }
1345 // Remove views that don't translate
1346 mTranslateableViews.remove(mChildrenContainerStub);
1347 mTranslateableViews.remove(mGutsStub);
Mady Mellor4b80b102016-01-22 08:03:58 -08001348 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001349 }
1350
Geoffrey Pitsch409db272017-08-28 14:51:52 +00001351 private void doLongClickCallback() {
1352 doLongClickCallback(getWidth() / 2, getHeight() / 2);
1353 }
1354
1355 public void doLongClickCallback(int x, int y) {
1356 createMenu();
1357 MenuItem menuItem = getProvider().getLongpressMenuItem(mContext);
1358 if (mLongPressListener != null && menuItem != null) {
1359 mLongPressListener.onLongPress(this, x, y, menuItem);
1360 }
1361 }
1362
1363 @Override
1364 public boolean onKeyDown(int keyCode, KeyEvent event) {
1365 if (KeyEvent.isConfirmKey(keyCode)) {
1366 event.startTracking();
1367 return true;
1368 }
1369 return super.onKeyDown(keyCode, event);
1370 }
1371
1372 @Override
1373 public boolean onKeyUp(int keyCode, KeyEvent event) {
1374 if (KeyEvent.isConfirmKey(keyCode)) {
1375 if (!event.isCanceled()) {
1376 performClick();
1377 }
1378 return true;
1379 }
1380 return super.onKeyUp(keyCode, event);
1381 }
1382
1383 @Override
1384 public boolean onKeyLongPress(int keyCode, KeyEvent event) {
1385 if (KeyEvent.isConfirmKey(keyCode)) {
1386 doLongClickCallback();
1387 return true;
1388 }
1389 return false;
1390 }
1391
Mady Mellor4b80b102016-01-22 08:03:58 -08001392 public void resetTranslation() {
Mady Mellor32c638a2016-09-14 08:58:25 -07001393 if (mTranslateAnim != null) {
1394 mTranslateAnim.cancel();
1395 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001396
1397 if (!mShouldTranslateContents) {
1398 setTranslationX(0);
1399 } else if (mTranslateableViews != null) {
Mady Mellor4b80b102016-01-22 08:03:58 -08001400 for (int i = 0; i < mTranslateableViews.size(); i++) {
1401 mTranslateableViews.get(i).setTranslationX(0);
1402 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001403 invalidateOutline();
Mady Mellor4b80b102016-01-22 08:03:58 -08001404 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001405
Mady Mellor95d743c2017-01-10 12:05:27 -08001406 mMenuRow.resetMenu();
Mady Mellor4b80b102016-01-22 08:03:58 -08001407 }
1408
1409 public void animateTranslateNotification(final float leftTarget) {
1410 if (mTranslateAnim != null) {
1411 mTranslateAnim.cancel();
1412 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001413 mTranslateAnim = getTranslateViewAnimator(leftTarget, null /* updateListener */);
Mady Mellor34958fa2016-02-23 09:52:17 -08001414 if (mTranslateAnim != null) {
1415 mTranslateAnim.start();
1416 }
1417 }
1418
1419 @Override
1420 public void setTranslation(float translationX) {
1421 if (areGutsExposed()) {
1422 // Don't translate if guts are showing.
1423 return;
1424 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001425 if (!mShouldTranslateContents) {
1426 setTranslationX(translationX);
1427 } else if (mTranslateableViews != null) {
1428 // Translate the group of views
1429 for (int i = 0; i < mTranslateableViews.size(); i++) {
1430 if (mTranslateableViews.get(i) != null) {
1431 mTranslateableViews.get(i).setTranslationX(translationX);
1432 }
Mady Mellor34958fa2016-02-23 09:52:17 -08001433 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001434 invalidateOutline();
Mady Mellor34958fa2016-02-23 09:52:17 -08001435 }
Mady Mellor95d743c2017-01-10 12:05:27 -08001436 if (mMenuRow.getMenuView() != null) {
1437 mMenuRow.onTranslationUpdate(translationX);
Mady Mellor34958fa2016-02-23 09:52:17 -08001438 }
1439 }
1440
1441 @Override
1442 public float getTranslation() {
Anthony Chene04afcb2017-04-21 13:51:32 -07001443 if (!mShouldTranslateContents) {
Anthony Chen7acbb772017-04-07 16:45:25 -07001444 return getTranslationX();
1445 }
1446
Mady Mellor34958fa2016-02-23 09:52:17 -08001447 if (mTranslateableViews != null && mTranslateableViews.size() > 0) {
1448 // All of the views in the list should have same translation, just use first one.
1449 return mTranslateableViews.get(0).getTranslationX();
1450 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001451
Mady Mellor34958fa2016-02-23 09:52:17 -08001452 return 0;
1453 }
1454
1455 public Animator getTranslateViewAnimator(final float leftTarget,
1456 AnimatorUpdateListener listener) {
Mady Mellor723f1f92016-03-13 15:54:06 -07001457 if (mTranslateAnim != null) {
1458 mTranslateAnim.cancel();
1459 }
Mady Mellor34958fa2016-02-23 09:52:17 -08001460 if (areGutsExposed()) {
1461 // No translation if guts are exposed.
1462 return null;
1463 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001464 final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(this, TRANSLATE_CONTENT,
1465 leftTarget);
1466 if (listener != null) {
1467 translateAnim.addUpdateListener(listener);
Mady Mellor4b80b102016-01-22 08:03:58 -08001468 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001469 translateAnim.addListener(new AnimatorListenerAdapter() {
1470 boolean cancelled = false;
1471
1472 @Override
1473 public void onAnimationCancel(Animator anim) {
1474 cancelled = true;
1475 }
1476
1477 @Override
1478 public void onAnimationEnd(Animator anim) {
Mady Mellor95d743c2017-01-10 12:05:27 -08001479 if (!cancelled && leftTarget == 0) {
1480 mMenuRow.resetMenu();
Mady Mellorb0a82462016-04-30 17:31:02 -07001481 mTranslateAnim = null;
1482 }
1483 }
1484 });
1485 mTranslateAnim = translateAnim;
1486 return translateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -08001487 }
1488
Selim Cinekab29aeb2015-02-20 18:18:32 +01001489 public void inflateGuts() {
1490 if (mGuts == null) {
1491 mGutsStub.inflate();
1492 }
1493 }
1494
Selim Cinekda42d652015-12-04 15:51:16 -08001495 private void updateChildrenVisibility() {
Selim Cinekd84a5932015-12-15 11:45:36 -08001496 mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE
1497 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -08001498 if (mChildrenContainer != null) {
1499 mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
1500 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -08001501 }
Selim Cinekda42d652015-12-04 15:51:16 -08001502 // The limits might have changed if the view suddenly became a group or vice versa
1503 updateLimits();
Selim Cinekb5605e52015-02-20 18:21:41 +01001504 }
1505
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001506 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08001507 public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
1508 if (super.onRequestSendAccessibilityEventInternal(child, event)) {
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001509 // Add a record for the entire layout since its content is somehow small.
1510 // The event comes from a leaf view that is interacted with.
1511 AccessibilityEvent record = AccessibilityEvent.obtain();
1512 onInitializeAccessibilityEvent(record);
1513 dispatchPopulateAccessibilityEvent(record);
1514 event.appendRecord(record);
1515 return true;
1516 }
1517 return false;
Jorim Jaggic5dc0d02014-04-15 15:42:55 +02001518 }
Chris Wren51c75102013-07-16 20:49:17 -04001519
John Spurlocke15452b2014-08-21 09:44:39 -04001520 @Override
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001521 public void setDark(boolean dark, boolean fade, long delay) {
1522 super.setDark(dark, fade, delay);
Lucas Dupincecc7c22017-09-12 16:02:45 -07001523 mDark = dark;
Adrian Roos28f90c72017-05-08 17:24:26 -07001524 if (!mIsHeadsUp) {
1525 // Only fade the showing view of the pulsing notification.
1526 fade = false;
1527 }
John Spurlocke15452b2014-08-21 09:44:39 -04001528 final NotificationContentView showing = getShowingLayout();
1529 if (showing != null) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001530 showing.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -04001531 }
Selim Cinek9c7712d2015-12-08 19:19:48 -08001532 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001533 mChildrenContainer.setDark(dark, fade, delay);
Selim Cinek9c7712d2015-12-08 19:19:48 -08001534 }
Selim Cineka7c69632017-06-07 15:51:29 -07001535 updateShelfIconColor();
John Spurlocke15452b2014-08-21 09:44:39 -04001536 }
1537
Lucas Dupincecc7c22017-09-12 16:02:45 -07001538 /**
1539 * Tap sounds should not be played when we're unlocking.
1540 * Doing so would cause audio collision and the system would feel unpolished.
1541 */
1542 @Override
1543 public boolean isSoundEffectsEnabled() {
1544 final boolean mute = mDark && mSecureStateProvider != null &&
1545 !mSecureStateProvider.getAsBoolean();
1546 return !mute && super.isSoundEffectsEnabled();
1547 }
1548
Chris Wren51c75102013-07-16 20:49:17 -04001549 public boolean isExpandable() {
Selim Cinek388df6d2015-10-22 13:25:11 -07001550 if (mIsSummaryWithChildren && !mShowingPublic) {
1551 return !mChildrenExpanded;
1552 }
Anthony Chen6bf88a02017-04-10 14:41:44 -07001553 return mEnableNonGroupedNotificationExpand && mExpandable;
Chris Wren51c75102013-07-16 20:49:17 -04001554 }
1555
1556 public void setExpandable(boolean expandable) {
1557 mExpandable = expandable;
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001558 mPrivateLayout.updateExpandButtons(isExpandable());
Chris Wren51c75102013-07-16 20:49:17 -04001559 }
1560
Selim Cinek4ffd6362015-12-29 15:12:23 +01001561 @Override
1562 public void setClipToActualHeight(boolean clipToActualHeight) {
Selim Cinek084c16b2016-01-22 17:48:22 -08001563 super.setClipToActualHeight(clipToActualHeight || isUserLocked());
1564 getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked());
Selim Cinek4ffd6362015-12-29 15:12:23 +01001565 }
1566
Selim Cinek1685e632014-04-08 02:27:49 +02001567 /**
1568 * @return whether the user has changed the expansion state
1569 */
1570 public boolean hasUserChangedExpansion() {
1571 return mHasUserChangedExpansion;
1572 }
1573
Chris Wren51c75102013-07-16 20:49:17 -04001574 public boolean isUserExpanded() {
1575 return mUserExpanded;
1576 }
1577
Selim Cinek1685e632014-04-08 02:27:49 +02001578 /**
1579 * Set this notification to be expanded by the user
1580 *
1581 * @param userExpanded whether the user wants this notification to be expanded
1582 */
Chris Wren51c75102013-07-16 20:49:17 -04001583 public void setUserExpanded(boolean userExpanded) {
Selim Cinek388df6d2015-10-22 13:25:11 -07001584 setUserExpanded(userExpanded, false /* allowChildExpansion */);
1585 }
1586
1587 /**
1588 * Set this notification to be expanded by the user
1589 *
1590 * @param userExpanded whether the user wants this notification to be expanded
1591 * @param allowChildExpansion whether a call to this method allows expanding children
1592 */
1593 public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001594 mFalsingManager.setNotificationExpanded();
Selim Cinek414ad332017-02-24 19:06:12 -08001595 if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion
1596 && !mChildrenContainer.showingAsLowPriority()) {
Chris Wren698b1702016-05-23 11:16:32 -04001597 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinek388df6d2015-10-22 13:25:11 -07001598 mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded);
Selim Cinek414ad332017-02-24 19:06:12 -08001599 onExpansionChanged(true /* userAction */, wasExpanded);
Selim Cinek388df6d2015-10-22 13:25:11 -07001600 return;
1601 }
Christoph Studera7fe6312014-06-27 19:32:44 +02001602 if (userExpanded && !mExpandable) return;
Chris Wren78403d72014-07-28 10:23:24 +01001603 final boolean wasExpanded = isExpanded();
Selim Cinek1685e632014-04-08 02:27:49 +02001604 mHasUserChangedExpansion = true;
Chris Wren51c75102013-07-16 20:49:17 -04001605 mUserExpanded = userExpanded;
Selim Cinek414ad332017-02-24 19:06:12 -08001606 onExpansionChanged(true /* userAction */, wasExpanded);
Selim Cinek5d6ef8d2017-05-18 22:16:00 -07001607 if (!wasExpanded && isExpanded()
1608 && getActualHeight() != getIntrinsicHeight()) {
1609 notifyHeightChanged(true /* needsAnimation */);
1610 }
Chris Wren51c75102013-07-16 20:49:17 -04001611 }
1612
Selim Cinekccd14fb2014-08-12 18:53:24 +02001613 public void resetUserExpansion() {
Selim Cinek414ad332017-02-24 19:06:12 -08001614 boolean changed = mUserExpanded;
Selim Cinekccd14fb2014-08-12 18:53:24 +02001615 mHasUserChangedExpansion = false;
1616 mUserExpanded = false;
Selim Cinek414ad332017-02-24 19:06:12 -08001617 if (changed && mIsSummaryWithChildren) {
1618 mChildrenContainer.onExpansionChanged();
1619 }
1620 updateShelfIconColor();
Selim Cinekccd14fb2014-08-12 18:53:24 +02001621 }
1622
Chris Wren51c75102013-07-16 20:49:17 -04001623 public boolean isUserLocked() {
Selim Cinek1b2a05e2016-04-28 14:20:39 -07001624 return mUserLocked && !mForceUnlocked;
Chris Wren51c75102013-07-16 20:49:17 -04001625 }
1626
1627 public void setUserLocked(boolean userLocked) {
1628 mUserLocked = userLocked;
Selim Cinek8f2f6a62016-02-23 19:56:31 -08001629 mPrivateLayout.setUserExpanding(userLocked);
Selim Cinek817abe72017-05-24 11:08:55 -07001630 // This is intentionally not guarded with mIsSummaryWithChildren since we might have had
1631 // children but not anymore.
1632 if (mChildrenContainer != null) {
Selim Cinek42357e02016-02-24 18:48:01 -08001633 mChildrenContainer.setUserLocked(userLocked);
Selim Cinek817abe72017-05-24 11:08:55 -07001634 if (mIsSummaryWithChildren && (userLocked || !isGroupExpanded())) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001635 updateBackgroundForGroupState();
1636 }
Selim Cinek42357e02016-02-24 18:48:01 -08001637 }
Chris Wren51c75102013-07-16 20:49:17 -04001638 }
1639
Selim Cinek1685e632014-04-08 02:27:49 +02001640 /**
1641 * @return has the system set this notification to be expanded
1642 */
1643 public boolean isSystemExpanded() {
1644 return mIsSystemExpanded;
1645 }
1646
1647 /**
1648 * Set this notification to be expanded by the system.
1649 *
1650 * @param expand whether the system wants this notification to be expanded.
1651 */
1652 public void setSystemExpanded(boolean expand) {
Selim Cinek31094df2014-08-14 19:28:15 +02001653 if (expand != mIsSystemExpanded) {
1654 final boolean wasExpanded = isExpanded();
1655 mIsSystemExpanded = expand;
Selim Cinekb5605e52015-02-20 18:21:41 +01001656 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek414ad332017-02-24 19:06:12 -08001657 onExpansionChanged(false /* userAction */, wasExpanded);
Selim Cineked6913b2016-06-01 12:01:17 -07001658 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001659 mChildrenContainer.updateGroupOverflow();
1660 }
Selim Cinek31094df2014-08-14 19:28:15 +02001661 }
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001662 }
1663
1664 /**
Selim Cinek83bc7832015-10-22 13:26:54 -07001665 * @param onKeyguard whether to prevent notification expansion
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001666 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001667 public void setOnKeyguard(boolean onKeyguard) {
1668 if (onKeyguard != mOnKeyguard) {
Selim Cinek5cf1d052017-06-01 17:36:46 -07001669 boolean wasAboveShelf = isAboveShelf();
Selim Cinek31094df2014-08-14 19:28:15 +02001670 final boolean wasExpanded = isExpanded();
Selim Cinek83bc7832015-10-22 13:26:54 -07001671 mOnKeyguard = onKeyguard;
Selim Cinek414ad332017-02-24 19:06:12 -08001672 onExpansionChanged(false /* userAction */, wasExpanded);
Selim Cinek31094df2014-08-14 19:28:15 +02001673 if (wasExpanded != isExpanded()) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001674 if (mIsSummaryWithChildren) {
1675 mChildrenContainer.updateGroupOverflow();
1676 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001677 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +02001678 }
Selim Cinek5cf1d052017-06-01 17:36:46 -07001679 if (isAboveShelf() != wasAboveShelf) {
1680 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
1681 }
Selim Cinek31094df2014-08-14 19:28:15 +02001682 }
Selim Cinek1685e632014-04-08 02:27:49 +02001683 }
1684
1685 /**
Selim Cinek9e624e72016-07-20 13:46:49 -07001686 * @return Can the underlying notification be cleared? This can be different from whether the
1687 * notification can be dismissed in case notifications are sensitive on the lockscreen.
1688 * @see #canViewBeDismissed()
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001689 */
1690 public boolean isClearable() {
Selim Cinek506deb62016-07-20 15:43:59 -07001691 if (mStatusBarNotification == null || !mStatusBarNotification.isClearable()) {
1692 return false;
1693 }
1694 if (mIsSummaryWithChildren) {
1695 List<ExpandableNotificationRow> notificationChildren =
1696 mChildrenContainer.getNotificationChildren();
1697 for (int i = 0; i < notificationChildren.size(); i++) {
1698 ExpandableNotificationRow child = notificationChildren.get(i);
1699 if (!child.isClearable()) {
1700 return false;
1701 }
1702 }
1703 }
1704 return true;
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001705 }
1706
Jorim Jaggi9cbadd32014-05-01 20:18:31 +02001707 @Override
1708 public int getIntrinsicHeight() {
Jorim Jaggibe565df2014-04-28 17:51:23 +02001709 if (isUserLocked()) {
1710 return getActualHeight();
1711 }
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05001712 if (mGuts != null && mGuts.isExposed()) {
Mady Mellore09fb702017-03-30 13:23:29 -07001713 return mGuts.getIntrinsicHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -08001714 } else if ((isChildInGroup() && !isGroupExpanded())) {
1715 return mPrivateLayout.getMinHeight();
1716 } else if (mSensitive && mHideSensitiveForIntrinsicHeight) {
1717 return getMinHeight();
Adrian Roos6f6e1592017-05-02 16:22:53 -07001718 } else if (mIsSummaryWithChildren && (!mOnKeyguard || mShowAmbient)) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001719 return mChildrenContainer.getIntrinsicHeight();
Adrian Roos6f6e1592017-05-02 16:22:53 -07001720 } else if (isHeadsUpAllowed() && (mIsHeadsUp || mHeadsupDisappearRunning)) {
Selim Cinek73cf02a2016-06-17 13:08:00 -07001721 if (isPinned() || mHeadsupDisappearRunning) {
Selim Cinek31aada42015-12-18 17:51:15 -08001722 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
1723 } else if (isExpanded()) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001724 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001725 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001726 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001727 }
Selim Cinek31aada42015-12-18 17:51:15 -08001728 } else if (isExpanded()) {
Selim Cinek83bc7832015-10-22 13:26:54 -07001729 return getMaxExpandHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -08001730 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001731 return getCollapsedHeight();
Selim Cinek1685e632014-04-08 02:27:49 +02001732 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001733 }
Selim Cinek1685e632014-04-08 02:27:49 +02001734
Adrian Roos6f6e1592017-05-02 16:22:53 -07001735 private boolean isHeadsUpAllowed() {
1736 return !mOnKeyguard && !mShowAmbient;
1737 }
1738
Mady Mellor43c2cd12016-12-12 21:05:13 -08001739 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -07001740 public boolean isGroupExpanded() {
Selim Cinekeef84282015-10-30 16:28:00 -07001741 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinekb5605e52015-02-20 18:21:41 +01001742 }
1743
Selim Cinek263398f2015-10-21 17:40:23 -07001744 private void onChildrenCountChanged() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001745 mIsSummaryWithChildren = StatusBar.ENABLE_CHILD_NOTIFICATIONS
Mady Mellorb0a82462016-04-30 17:31:02 -07001746 && mChildrenContainer != null && mChildrenContainer.getNotificationChildCount() > 0;
1747 if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() == null) {
Selim Cinek414ad332017-02-24 19:06:12 -08001748 mChildrenContainer.recreateNotificationHeader(mExpandClickListener
1749 );
Selim Cinek263398f2015-10-21 17:40:23 -07001750 }
Mady Mellor6baed9e2016-05-25 16:05:09 -07001751 getShowingLayout().updateBackgroundColor(false /* animate */);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001752 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinekea4bef72015-12-02 15:51:10 -08001753 updateChildrenHeaderAppearance();
Selim Cinekda42d652015-12-04 15:51:16 -08001754 updateChildrenVisibility();
Selim Cinek263398f2015-10-21 17:40:23 -07001755 }
1756
Mady Mellorb0a82462016-04-30 17:31:02 -07001757 public void updateChildrenHeaderAppearance() {
Selim Cineked6913b2016-06-01 12:01:17 -07001758 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001759 mChildrenContainer.updateChildrenHeaderAppearance();
1760 }
1761 }
1762
Selim Cinek1685e632014-04-08 02:27:49 +02001763 /**
1764 * Check whether the view state is currently expanded. This is given by the system in {@link
1765 * #setSystemExpanded(boolean)} and can be overridden by user expansion or
1766 * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this
1767 * view can differ from this state, if layout params are modified from outside.
1768 *
1769 * @return whether the view state is currently expanded.
1770 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001771 public boolean isExpanded() {
Selim Cineke81b82b2016-03-04 11:22:28 -08001772 return isExpanded(false /* allowOnKeyguard */);
1773 }
1774
1775 public boolean isExpanded(boolean allowOnKeyguard) {
1776 return (!mOnKeyguard || allowOnKeyguard)
Selim Cinekb5605e52015-02-20 18:21:41 +01001777 && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded())
1778 || isUserExpanded());
1779 }
1780
1781 private boolean isSystemChildExpanded() {
1782 return mIsSystemChildExpanded;
1783 }
1784
1785 public void setSystemChildExpanded(boolean expanded) {
1786 mIsSystemChildExpanded = expanded;
Selim Cinek1685e632014-04-08 02:27:49 +02001787 }
1788
Mady Mellor035badd2017-04-04 18:45:30 -07001789 public void setLayoutListener(LayoutListener listener) {
1790 mLayoutListener = listener;
1791 }
1792
1793 public void removeListener() {
1794 mLayoutListener = null;
1795 }
1796
Selim Cinek1685e632014-04-08 02:27:49 +02001797 @Override
1798 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
1799 super.onLayout(changed, left, top, right, bottom);
Selim Cinek8d490d42015-04-10 00:05:50 -07001800 updateMaxHeights();
Mady Mellor95d743c2017-01-10 12:05:27 -08001801 if (mMenuRow.getMenuView() != null) {
1802 mMenuRow.onHeightUpdate();
Mady Mellora6edc872016-04-26 11:01:03 -07001803 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001804 updateContentShiftHeight();
Mady Mellor035badd2017-04-04 18:45:30 -07001805 if (mLayoutListener != null) {
1806 mLayoutListener.onLayout();
1807 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001808 }
1809
1810 /**
1811 * Updates the content shift height such that the header is completely hidden when coming from
1812 * the top.
1813 */
1814 private void updateContentShiftHeight() {
Selim Cinek414ad332017-02-24 19:06:12 -08001815 NotificationHeaderView notificationHeader = getVisibleNotificationHeader();
Selim Cinek875a3a12016-11-18 17:52:16 -08001816 if (notificationHeader != null) {
1817 CachingIconView icon = notificationHeader.getIcon();
1818 mIconTransformContentShift = getRelativeTopPadding(icon) + icon.getHeight();
1819 } else {
1820 mIconTransformContentShift = mIconTransformContentShiftNoIcon;
1821 }
Selim Cinek1685e632014-04-08 02:27:49 +02001822 }
1823
Selim Cinek8d490d42015-04-10 00:05:50 -07001824 private void updateMaxHeights() {
Selim Cinekd2319fb2014-09-01 19:41:54 +02001825 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek8d490d42015-04-10 00:05:50 -07001826 View expandedChild = mPrivateLayout.getExpandedChild();
1827 if (expandedChild == null) {
1828 expandedChild = mPrivateLayout.getContractedChild();
1829 }
1830 mMaxExpandHeight = expandedChild.getHeight();
1831 View headsUpChild = mPrivateLayout.getHeadsUpChild();
Selim Cinek1f3f5442015-04-10 17:54:46 -07001832 if (headsUpChild == null) {
1833 headsUpChild = mPrivateLayout.getContractedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -07001834 }
Selim Cinek1f3f5442015-04-10 17:54:46 -07001835 mHeadsUpHeight = headsUpChild.getHeight();
Selim Cinekd2319fb2014-09-01 19:41:54 +02001836 if (intrinsicBefore != getIntrinsicHeight()) {
Selim Cinekbb42b7d2016-08-10 13:02:38 -07001837 notifyHeightChanged(true /* needsAnimation */);
Selim Cinekd2319fb2014-09-01 19:41:54 +02001838 }
1839 }
1840
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001841 @Override
1842 public void notifyHeightChanged(boolean needsAnimation) {
1843 super.notifyHeightChanged(needsAnimation);
1844 getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked());
1845 }
1846
Selim Cinek3c76d502016-02-19 15:16:33 -08001847 public void setSensitive(boolean sensitive, boolean hideSensitive) {
Jorim Jaggiae441282014-08-01 02:45:18 +02001848 mSensitive = sensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -08001849 mSensitiveHiddenInGeneral = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02001850 }
1851
Mady Mellor43c2cd12016-12-12 21:05:13 -08001852 @Override
Jorim Jaggiae441282014-08-01 02:45:18 +02001853 public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
Selim Cinek60122be2015-04-15 18:16:50 -07001854 mHideSensitiveForIntrinsicHeight = hideSensitive;
Selim Cineka52f6a12016-02-29 15:35:58 -08001855 if (mIsSummaryWithChildren) {
1856 List<ExpandableNotificationRow> notificationChildren =
1857 mChildrenContainer.getNotificationChildren();
1858 for (int i = 0; i < notificationChildren.size(); i++) {
1859 ExpandableNotificationRow child = notificationChildren.get(i);
1860 child.setHideSensitiveForIntrinsicHeight(hideSensitive);
1861 }
1862 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001863 }
1864
Mady Mellor43c2cd12016-12-12 21:05:13 -08001865 @Override
Jorim Jaggiae441282014-08-01 02:45:18 +02001866 public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
1867 long duration) {
1868 boolean oldShowingPublic = mShowingPublic;
1869 mShowingPublic = mSensitive && hideSensitive;
1870 if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
1871 return;
1872 }
Dan Sandlera5e0f412014-01-23 15:11:54 -05001873
1874 // bail out if no public version
Selim Cinek1685e632014-04-08 02:27:49 +02001875 if (mPublicLayout.getChildCount() == 0) return;
Dan Sandlera5e0f412014-01-23 15:11:54 -05001876
Jorim Jaggiae441282014-08-01 02:45:18 +02001877 if (!animated) {
1878 mPublicLayout.animate().cancel();
1879 mPrivateLayout.animate().cancel();
Selim Cineka554c702016-06-17 18:02:12 -07001880 if (mChildrenContainer != null) {
1881 mChildrenContainer.animate().cancel();
1882 mChildrenContainer.setAlpha(1f);
1883 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001884 mPublicLayout.setAlpha(1f);
1885 mPrivateLayout.setAlpha(1f);
1886 mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
Selim Cinekd84a5932015-12-15 11:45:36 -08001887 updateChildrenVisibility();
Jorim Jaggiae441282014-08-01 02:45:18 +02001888 } else {
1889 animateShowingPublic(delay, duration);
1890 }
Selim Cinekc3179332016-03-04 14:44:56 -08001891 NotificationContentView showingLayout = getShowingLayout();
1892 showingLayout.updateBackgroundColor(animated);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001893 mPrivateLayout.updateExpandButtons(isExpandable());
Lucas Dupinb6ed63b2017-05-30 16:17:42 -07001894 updateShelfIconColor();
Adrian Roose5726a22016-12-19 14:26:51 -08001895 showingLayout.setDark(isDark(), false /* animate */, 0 /* delay */);
Jorim Jaggiae441282014-08-01 02:45:18 +02001896 mShowingPublicInitialized = true;
1897 }
1898
1899 private void animateShowingPublic(long delay, long duration) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001900 View[] privateViews = mIsSummaryWithChildren
1901 ? new View[] {mChildrenContainer}
Selim Cinekd84a5932015-12-15 11:45:36 -08001902 : new View[] {mPrivateLayout};
1903 View[] publicViews = new View[] {mPublicLayout};
1904 View[] hiddenChildren = mShowingPublic ? privateViews : publicViews;
1905 View[] shownChildren = mShowingPublic ? publicViews : privateViews;
1906 for (final View hiddenView : hiddenChildren) {
1907 hiddenView.setVisibility(View.VISIBLE);
1908 hiddenView.animate().cancel();
1909 hiddenView.animate()
1910 .alpha(0f)
1911 .setStartDelay(delay)
1912 .setDuration(duration)
1913 .withEndAction(new Runnable() {
1914 @Override
1915 public void run() {
1916 hiddenView.setVisibility(View.INVISIBLE);
1917 }
1918 });
1919 }
1920 for (View showView : shownChildren) {
1921 showView.setVisibility(View.VISIBLE);
1922 showView.setAlpha(0f);
1923 showView.animate().cancel();
1924 showView.animate()
1925 .alpha(1f)
1926 .setStartDelay(delay)
1927 .setDuration(duration);
1928 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001929 }
1930
Mady Mellor43c2cd12016-12-12 21:05:13 -08001931 @Override
Selim Cinek3776fe02016-02-04 13:32:43 -08001932 public boolean mustStayOnScreen() {
1933 return mIsHeadsUp;
1934 }
1935
Selim Cinek9e624e72016-07-20 13:46:49 -07001936 /**
1937 * @return Whether this view is allowed to be dismissed. Only valid for visible notifications as
1938 * otherwise some state might not be updated. To request about the general clearability
1939 * see {@link #isClearable()}.
1940 */
1941 public boolean canViewBeDismissed() {
Selim Cineke9bad242016-06-15 11:46:37 -07001942 return isClearable() && (!mShowingPublic || !mSensitiveHiddenInGeneral);
Dan Sandlera5e0f412014-01-23 15:11:54 -05001943 }
Jorim Jaggi251957d2014-04-09 04:24:09 +02001944
Ricky Waicd35def2016-05-03 11:07:07 +01001945 public void makeActionsVisibile() {
1946 setUserExpanded(true, true);
1947 if (isChildInGroup()) {
1948 mGroupManager.setGroupExpanded(mStatusBarNotification, true);
1949 }
Selim Cinekbb42b7d2016-08-10 13:02:38 -07001950 notifyHeightChanged(false /* needsAnimation */);
Ricky Waicd35def2016-05-03 11:07:07 +01001951 }
1952
Selim Cinekb5605e52015-02-20 18:21:41 +01001953 public void setChildrenExpanded(boolean expanded, boolean animate) {
1954 mChildrenExpanded = expanded;
Selim Cinek83bc7832015-10-22 13:26:54 -07001955 if (mChildrenContainer != null) {
1956 mChildrenContainer.setChildrenExpanded(expanded);
1957 }
Mady Mellor1a5d8ea2016-06-09 10:42:42 -07001958 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -07001959 updateClickAndFocus();
Selim Cinekb5605e52015-02-20 18:21:41 +01001960 }
1961
Selim Cinekb5605e52015-02-20 18:21:41 +01001962 public static void applyTint(View v, int color) {
1963 int alpha;
1964 if (color != 0) {
1965 alpha = COLORED_DIVIDER_ALPHA;
1966 } else {
1967 color = 0xff000000;
1968 alpha = DEFAULT_DIVIDER_ALPHA;
1969 }
1970 if (v.getBackground() instanceof ColorDrawable) {
1971 ColorDrawable background = (ColorDrawable) v.getBackground();
1972 background.mutate();
1973 background.setColor(color);
1974 background.setAlpha(alpha);
1975 }
1976 }
1977
Selim Cinek1685e632014-04-08 02:27:49 +02001978 public int getMaxExpandHeight() {
Selim Cinekb5605e52015-02-20 18:21:41 +01001979 return mMaxExpandHeight;
Chris Wren51c75102013-07-16 20:49:17 -04001980 }
Jorim Jaggi584a7aa2014-04-10 23:26:13 +02001981
Mady Mellor34958fa2016-02-23 09:52:17 -08001982 public boolean areGutsExposed() {
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05001983 return (mGuts != null && mGuts.isExposed());
Mady Mellor34958fa2016-02-23 09:52:17 -08001984 }
1985
Jorim Jaggibe565df2014-04-28 17:51:23 +02001986 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001987 public boolean isContentExpandable() {
Selim Cinekc0ac4af2017-03-03 15:13:48 -08001988 if (mIsSummaryWithChildren && !mShowingPublic) {
1989 return true;
1990 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001991 NotificationContentView showingLayout = getShowingLayout();
1992 return showingLayout.isContentExpandable();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001993 }
1994
1995 @Override
Selim Cinek560e64d2015-06-09 19:58:11 -07001996 protected View getContentView() {
Selim Cinekaa3901a2016-08-05 11:04:37 -07001997 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cineka5703182016-05-11 21:23:16 -04001998 return mChildrenContainer;
1999 }
Selim Cinek560e64d2015-06-09 19:58:11 -07002000 return getShowingLayout();
2001 }
2002
2003 @Override
Selim Cinekaa3901a2016-08-05 11:04:37 -07002004 protected void onAppearAnimationFinished(boolean wasAppearing) {
2005 super.onAppearAnimationFinished(wasAppearing);
2006 if (wasAppearing) {
2007 // During the animation the visible view might have changed, so let's make sure all
2008 // alphas are reset
2009 if (mChildrenContainer != null) {
2010 mChildrenContainer.setAlpha(1.0f);
2011 mChildrenContainer.setLayerType(LAYER_TYPE_NONE, null);
2012 }
Adrian Rooseb434ff2017-01-11 11:18:48 -08002013 for (NotificationContentView l : mLayouts) {
2014 l.setAlpha(1.0f);
2015 l.setLayerType(LAYER_TYPE_NONE, null);
2016 }
Selim Cinekaa3901a2016-08-05 11:04:37 -07002017 }
2018 }
2019
2020 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -07002021 public int getExtraBottomPadding() {
2022 if (mIsSummaryWithChildren && isGroupExpanded()) {
2023 return mIncreasedPaddingBetweenElements;
2024 }
2025 return 0;
2026 }
2027
2028 @Override
Jorim Jaggid552d9d2014-05-07 19:41:13 +02002029 public void setActualHeight(int height, boolean notifyListeners) {
Selim Cinek4ca6c632017-02-23 18:03:37 -08002030 boolean changed = height != getActualHeight();
Selim Cinekb5605e52015-02-20 18:21:41 +01002031 super.setActualHeight(height, notifyListeners);
Selim Cinek4ca6c632017-02-23 18:03:37 -08002032 if (changed && isRemoved()) {
2033 // TODO: remove this once we found the gfx bug for this.
2034 // This is a hack since a removed view sometimes would just stay blank. it occured
2035 // when sending yourself a message and then clicking on it.
2036 ViewGroup parent = (ViewGroup) getParent();
2037 if (parent != null) {
2038 parent.invalidate();
2039 }
2040 }
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05002041 if (mGuts != null && mGuts.isExposed()) {
Mady Mellorb53bc272016-02-11 18:28:23 -08002042 mGuts.setActualHeight(height);
2043 return;
2044 }
Selim Cinekeef84282015-10-30 16:28:00 -07002045 int contentHeight = Math.max(getMinHeight(), height);
Adrian Rooseb434ff2017-01-11 11:18:48 -08002046 for (NotificationContentView l : mLayouts) {
2047 l.setContentHeight(contentHeight);
2048 }
Selim Cinek42357e02016-02-24 18:48:01 -08002049 if (mIsSummaryWithChildren) {
2050 mChildrenContainer.setActualHeight(height);
2051 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02002052 if (mGuts != null) {
2053 mGuts.setActualHeight(height);
2054 }
Mady Mellor54540972017-06-07 11:55:36 -07002055 if (mMenuRow.getMenuView() != null) {
2056 mMenuRow.onHeightUpdate();
2057 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02002058 }
2059
2060 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01002061 public int getMaxContentHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07002062 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08002063 return mChildrenContainer.getMaxContentHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07002064 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02002065 NotificationContentView showingLayout = getShowingLayout();
2066 return showingLayout.getMaxHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +02002067 }
2068
2069 @Override
Selim Cinekeb3fc3d2017-09-15 13:37:14 -07002070 public int getMinHeight(boolean ignoreTemporaryStates) {
2071 if (!ignoreTemporaryStates && mGuts != null && mGuts.isExposed()) {
Mady Mellore09fb702017-03-30 13:23:29 -07002072 return mGuts.getIntrinsicHeight();
Selim Cinekeb3fc3d2017-09-15 13:37:14 -07002073 } else if (!ignoreTemporaryStates && isHeadsUpAllowed() && mIsHeadsUp
2074 && mHeadsUpManager.isTrackingHeadsUp()) {
Selim Cinek31aada42015-12-18 17:51:15 -08002075 return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
2076 } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
Selim Cinekb55386d2015-12-16 17:26:49 -08002077 return mChildrenContainer.getMinHeight();
Selim Cinekeb3fc3d2017-09-15 13:37:14 -07002078 } else if (!ignoreTemporaryStates && isHeadsUpAllowed() && mIsHeadsUp) {
Selim Cinek31aada42015-12-18 17:51:15 -08002079 return mHeadsUpHeight;
Selim Cinekb55386d2015-12-16 17:26:49 -08002080 }
Selim Cinek816c8e42015-11-19 12:00:45 -08002081 NotificationContentView showingLayout = getShowingLayout();
2082 return showingLayout.getMinHeight();
2083 }
2084
2085 @Override
Selim Cinek567e8452016-03-24 10:54:56 -07002086 public int getCollapsedHeight() {
Selim Cinek2c584612016-02-29 16:14:25 -08002087 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinek567e8452016-03-24 10:54:56 -07002088 return mChildrenContainer.getCollapsedHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07002089 }
Selim Cinek816c8e42015-11-19 12:00:45 -08002090 return getMinHeight();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02002091 }
2092
2093 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02002094 public void setClipTopAmount(int clipTopAmount) {
2095 super.setClipTopAmount(clipTopAmount);
Adrian Rooseb434ff2017-01-11 11:18:48 -08002096 for (NotificationContentView l : mLayouts) {
2097 l.setClipTopAmount(clipTopAmount);
2098 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02002099 if (mGuts != null) {
2100 mGuts.setClipTopAmount(clipTopAmount);
2101 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02002102 }
2103
Selim Cineka686b2c2016-10-26 13:58:27 -07002104 @Override
2105 public void setClipBottomAmount(int clipBottomAmount) {
Selim Cinek65d418e2016-11-29 15:42:34 -08002106 if (clipBottomAmount != mClipBottomAmount) {
2107 super.setClipBottomAmount(clipBottomAmount);
Adrian Rooseb434ff2017-01-11 11:18:48 -08002108 for (NotificationContentView l : mLayouts) {
2109 l.setClipBottomAmount(clipBottomAmount);
2110 }
Selim Cinek65d418e2016-11-29 15:42:34 -08002111 if (mGuts != null) {
2112 mGuts.setClipBottomAmount(clipBottomAmount);
2113 }
Selim Cineka686b2c2016-10-26 13:58:27 -07002114 }
Selim Cinekb3dadcc2016-11-21 17:21:13 -08002115 if (mChildrenContainer != null) {
Selim Cinek65d418e2016-11-29 15:42:34 -08002116 // We have to update this even if it hasn't changed, since the children locations can
2117 // have changed
Selim Cinekb3dadcc2016-11-21 17:21:13 -08002118 mChildrenContainer.setClipBottomAmount(clipBottomAmount);
2119 }
Selim Cineka686b2c2016-10-26 13:58:27 -07002120 }
2121
Selim Cinek31094df2014-08-14 19:28:15 +02002122 public boolean isMaxExpandHeightInitialized() {
2123 return mMaxExpandHeight != 0;
Selim Cinek7d447722014-06-10 15:51:59 +02002124 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02002125
Selim Cinek42357e02016-02-24 18:48:01 -08002126 public NotificationContentView getShowingLayout() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02002127 return mShowingPublic ? mPublicLayout : mPrivateLayout;
2128 }
Chris Wren78403d72014-07-28 10:23:24 +01002129
Selim Cinek1a48bab2017-02-17 19:38:40 -08002130 public void setLegacy(boolean legacy) {
Adrian Rooseb434ff2017-01-11 11:18:48 -08002131 for (NotificationContentView l : mLayouts) {
Selim Cinek1a48bab2017-02-17 19:38:40 -08002132 l.setLegacy(legacy);
Adrian Rooseb434ff2017-01-11 11:18:48 -08002133 }
Jorim Jaggi59ec3042015-06-05 15:18:43 -07002134 }
2135
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002136 @Override
2137 protected void updateBackgroundTint() {
2138 super.updateBackgroundTint();
Mady Mellorb0a82462016-04-30 17:31:02 -07002139 updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002140 if (mIsSummaryWithChildren) {
2141 List<ExpandableNotificationRow> notificationChildren =
2142 mChildrenContainer.getNotificationChildren();
2143 for (int i = 0; i < notificationChildren.size(); i++) {
2144 ExpandableNotificationRow child = notificationChildren.get(i);
Mady Mellorb0a82462016-04-30 17:31:02 -07002145 child.updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002146 }
2147 }
2148 }
2149
Mady Mellorb0a82462016-04-30 17:31:02 -07002150 /**
2151 * Called when a group has finished animating from collapsed or expanded state.
2152 */
2153 public void onFinishedExpansionChange() {
2154 mGroupExpansionChanging = false;
2155 updateBackgroundForGroupState();
2156 }
2157
2158 /**
2159 * Updates the parent and children backgrounds in a group based on the expansion state.
2160 */
2161 public void updateBackgroundForGroupState() {
2162 if (mIsSummaryWithChildren) {
2163 // Only when the group has finished expanding do we hide its background.
Anthony Chen6bf88a02017-04-10 14:41:44 -07002164 mShowNoBackground = !mShowGroupBackgroundWhenExpanded && isGroupExpanded()
2165 && !isGroupExpansionChanging() && !isUserLocked();
Mady Mellorb0a82462016-04-30 17:31:02 -07002166 mChildrenContainer.updateHeaderForExpansion(mShowNoBackground);
2167 List<ExpandableNotificationRow> children = mChildrenContainer.getNotificationChildren();
2168 for (int i = 0; i < children.size(); i++) {
2169 children.get(i).updateBackgroundForGroupState();
2170 }
2171 } else if (isChildInGroup()) {
2172 final int childColor = getShowingLayout().getBackgroundColorForExpansionState();
2173 // Only show a background if the group is expanded OR if it is expanding / collapsing
Anthony Chen6bf88a02017-04-10 14:41:44 -07002174 // and has a custom background color.
Mady Mellorb0a82462016-04-30 17:31:02 -07002175 final boolean showBackground = isGroupExpanded()
2176 || ((mNotificationParent.isGroupExpansionChanging()
Anthony Chen6bf88a02017-04-10 14:41:44 -07002177 || mNotificationParent.isUserLocked()) && childColor != 0);
Mady Mellorb0a82462016-04-30 17:31:02 -07002178 mShowNoBackground = !showBackground;
2179 } else {
2180 // Only children or parents ever need no background.
2181 mShowNoBackground = false;
2182 }
2183 updateOutline();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002184 updateBackground();
2185 }
2186
Adrian Roos4a579672016-05-24 16:54:37 -07002187 public int getPositionOfChild(ExpandableNotificationRow childRow) {
2188 if (mIsSummaryWithChildren) {
2189 return mChildrenContainer.getPositionInLinearLayout(childRow);
2190 }
2191 return 0;
2192 }
2193
Chris Wren78403d72014-07-28 10:23:24 +01002194 public void setExpansionLogger(ExpansionLogger logger, String key) {
2195 mLogger = logger;
2196 mLoggingKey = key;
2197 }
2198
Chris Wren6abeeb92016-05-26 14:44:38 -04002199 public void onExpandedByGesture(boolean userExpanded) {
2200 int event = MetricsEvent.ACTION_NOTIFICATION_GESTURE_EXPANDER;
2201 if (mGroupManager.isSummaryOfGroup(getStatusBarNotification())) {
2202 event = MetricsEvent.ACTION_NOTIFICATION_GROUP_GESTURE_EXPANDER;
2203 }
2204 MetricsLogger.action(mContext, event, userExpanded);
2205 }
2206
Selim Cinek6183d122016-01-14 18:48:41 -08002207 @Override
Selim Cinek42357e02016-02-24 18:48:01 -08002208 public float getIncreasedPaddingAmount() {
2209 if (mIsSummaryWithChildren) {
2210 if (isGroupExpanded()) {
2211 return 1.0f;
2212 } else if (isUserLocked()) {
Selim Cinek414ad332017-02-24 19:06:12 -08002213 return mChildrenContainer.getIncreasedPaddingAmount();
Selim Cinek42357e02016-02-24 18:48:01 -08002214 }
Selim Cinek99104832017-01-25 14:47:33 -08002215 } else if (isColorized() && (!mIsLowPriority || isExpanded())) {
Selim Cineka7ed2c12017-01-23 20:47:24 -08002216 return -1.0f;
Selim Cinek42357e02016-02-24 18:48:01 -08002217 }
2218 return 0.0f;
Selim Cinek61633a82016-01-25 15:54:10 -08002219 }
2220
Selim Cineka7ed2c12017-01-23 20:47:24 -08002221 private boolean isColorized() {
Selim Cinek99104832017-01-25 14:47:33 -08002222 return mIsColorized && mBgTint != NO_COLOR;
Selim Cineka7ed2c12017-01-23 20:47:24 -08002223 }
2224
Selim Cinek61633a82016-01-25 15:54:10 -08002225 @Override
Selim Cinek6183d122016-01-14 18:48:41 -08002226 protected boolean disallowSingleClick(MotionEvent event) {
2227 float x = event.getX();
2228 float y = event.getY();
Selim Cinek34eda5e2016-02-18 17:10:43 -08002229 NotificationHeaderView header = getVisibleNotificationHeader();
Selim Cinek5d6ef8d2017-05-18 22:16:00 -07002230 if (header != null && header.isInTouchRect(x - getTranslation(), y)) {
2231 return true;
2232 }
2233 if ((!mIsSummaryWithChildren || mShowingPublic)
2234 && getShowingLayout().disallowSingleClick(x, y)) {
2235 return true;
Selim Cinek6183d122016-01-14 18:48:41 -08002236 }
2237 return super.disallowSingleClick(event);
2238 }
2239
Selim Cinek414ad332017-02-24 19:06:12 -08002240 private void onExpansionChanged(boolean userAction, boolean wasExpanded) {
Chris Wren698b1702016-05-23 11:16:32 -04002241 boolean nowExpanded = isExpanded();
Selim Cinek414ad332017-02-24 19:06:12 -08002242 if (mIsSummaryWithChildren && (!mIsLowPriority || wasExpanded)) {
Chris Wren698b1702016-05-23 11:16:32 -04002243 nowExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
2244 }
Selim Cinek414ad332017-02-24 19:06:12 -08002245 if (nowExpanded != wasExpanded) {
2246 updateShelfIconColor();
2247 if (mLogger != null) {
2248 mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded);
2249 }
2250 if (mIsSummaryWithChildren) {
2251 mChildrenContainer.onExpansionChanged();
2252 }
Chris Wren78403d72014-07-28 10:23:24 +01002253 }
2254 }
Selim Cinek570981d2015-12-01 11:37:01 -08002255
Selim Cineke9bad242016-06-15 11:46:37 -07002256 @Override
2257 public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
2258 super.onInitializeAccessibilityNodeInfoInternal(info);
Geoffrey Pitsch409db272017-08-28 14:51:52 +00002259 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK);
Selim Cineke9bad242016-06-15 11:46:37 -07002260 if (canViewBeDismissed()) {
2261 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS);
2262 }
Selim Cinekc0ac4af2017-03-03 15:13:48 -08002263 boolean expandable = mShowingPublic;
2264 boolean isExpanded = false;
2265 if (!expandable) {
2266 if (mIsSummaryWithChildren) {
2267 expandable = true;
2268 if (!mIsLowPriority || isExpanded()) {
2269 isExpanded = isGroupExpanded();
2270 }
2271 } else {
2272 expandable = mPrivateLayout.isContentExpandable();
2273 isExpanded = isExpanded();
2274 }
2275 }
2276 if (expandable) {
2277 if (isExpanded) {
2278 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE);
2279 } else {
2280 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND);
2281 }
2282 }
Selim Cineke9bad242016-06-15 11:46:37 -07002283 }
2284
2285 @Override
2286 public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
2287 if (super.performAccessibilityActionInternal(action, arguments)) {
2288 return true;
2289 }
2290 switch (action) {
2291 case AccessibilityNodeInfo.ACTION_DISMISS:
2292 NotificationStackScrollLayout.performDismiss(this, mGroupManager,
2293 true /* fromAccessibility */);
2294 return true;
Selim Cinekc0ac4af2017-03-03 15:13:48 -08002295 case AccessibilityNodeInfo.ACTION_COLLAPSE:
2296 case AccessibilityNodeInfo.ACTION_EXPAND:
2297 mExpandClickListener.onClick(this);
2298 return true;
Geoffrey Pitsch409db272017-08-28 14:51:52 +00002299 case AccessibilityNodeInfo.ACTION_LONG_CLICK:
2300 doLongClickCallback();
2301 return true;
Selim Cineke9bad242016-06-15 11:46:37 -07002302 }
2303 return false;
2304 }
2305
2306 public boolean shouldRefocusOnDismiss() {
2307 return mRefocusOnDismiss || isAccessibilityFocused();
2308 }
2309
Selim Cinek570981d2015-12-01 11:37:01 -08002310 public interface OnExpandClickListener {
Selim Cinek31aada42015-12-18 17:51:15 -08002311 void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
Selim Cinek570981d2015-12-01 11:37:01 -08002312 }
Selim Cinekbbcebde2016-11-09 18:28:20 -08002313
2314 @Override
2315 public ExpandableViewState createNewViewState(StackScrollState stackScrollState) {
2316 return new NotificationViewState(stackScrollState);
2317 }
2318
Selim Cinekd127d792016-11-01 19:11:41 -07002319 @Override
2320 public boolean isAboveShelf() {
Selim Cinekc8007c52017-02-28 16:09:56 -08002321 return !isOnKeyguard()
2322 && (mIsPinned || mHeadsupDisappearRunning || (mIsHeadsUp && mAboveShelf));
Selim Cinekd127d792016-11-01 19:11:41 -07002323 }
2324
Adrian Roos0aac04f2016-12-08 15:59:29 -08002325 public void setShowAmbient(boolean showAmbient) {
2326 if (showAmbient != mShowAmbient) {
2327 mShowAmbient = showAmbient;
Adrian Roos6f6e1592017-05-02 16:22:53 -07002328 if (mChildrenContainer != null) {
2329 mChildrenContainer.notifyShowAmbientChanged();
2330 }
Adrian Roos0aac04f2016-12-08 15:59:29 -08002331 notifyHeightChanged(false /* needsAnimation */);
2332 }
2333 }
2334
Adrian Roos6f6e1592017-05-02 16:22:53 -07002335 public boolean isShowingAmbient() {
2336 return mShowAmbient;
2337 }
2338
Selim Cinekd127d792016-11-01 19:11:41 -07002339 public void setAboveShelf(boolean aboveShelf) {
Selim Cinek5cf1d052017-06-01 17:36:46 -07002340 boolean wasAboveShelf = isAboveShelf();
Selim Cinekd127d792016-11-01 19:11:41 -07002341 mAboveShelf = aboveShelf;
Selim Cinek5cf1d052017-06-01 17:36:46 -07002342 if (isAboveShelf() != wasAboveShelf) {
2343 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
2344 }
Selim Cinekd127d792016-11-01 19:11:41 -07002345 }
2346
Selim Cinekd4776a52017-02-14 18:50:16 -08002347 public static class NotificationViewState extends ExpandableViewState {
Selim Cinekbbcebde2016-11-09 18:28:20 -08002348
2349 private final StackScrollState mOverallState;
Selim Cinek0242fbb2016-10-19 13:38:32 -07002350
Selim Cinekbbcebde2016-11-09 18:28:20 -08002351
2352 private NotificationViewState(StackScrollState stackScrollState) {
2353 mOverallState = stackScrollState;
2354 }
2355
2356 @Override
2357 public void applyToView(View view) {
2358 super.applyToView(view);
2359 if (view instanceof ExpandableNotificationRow) {
2360 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
Selim Cinekbbcebde2016-11-09 18:28:20 -08002361 row.applyChildrenState(mOverallState);
2362 }
2363 }
Selim Cinek0cfbef42016-11-09 19:06:36 -08002364
2365 @Override
Selim Cinek2b549f42016-11-22 16:38:51 -08002366 protected void onYTranslationAnimationFinished(View view) {
2367 super.onYTranslationAnimationFinished(view);
Selim Cinekd4776a52017-02-14 18:50:16 -08002368 if (view instanceof ExpandableNotificationRow) {
2369 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
2370 if (row.isHeadsUpAnimatingAway()) {
2371 row.setHeadsUpAnimatingAway(false);
2372 }
Selim Cinek0cfbef42016-11-09 19:06:36 -08002373 }
2374 }
2375
2376 @Override
2377 public void animateTo(View child, AnimationProperties properties) {
2378 super.animateTo(child, properties);
2379 if (child instanceof ExpandableNotificationRow) {
2380 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
2381 row.startChildAnimation(mOverallState, properties);
2382 }
2383 }
Selim Cinekbbcebde2016-11-09 18:28:20 -08002384 }
Selim Cinek817abe72017-05-24 11:08:55 -07002385
2386 @VisibleForTesting
2387 protected void setChildrenContainer(NotificationChildrenContainer childrenContainer) {
2388 mChildrenContainer = childrenContainer;
2389 }
Geoffrey Pitsch409db272017-08-28 14:51:52 +00002390
2391 /**
2392 * Equivalent to View.OnLongClickListener with coordinates
2393 */
2394 public interface LongPressListener {
2395 /**
2396 * Equivalent to {@link View.OnLongClickListener#onLongClick(View)} with coordinates
2397 * @return whether the longpress was handled
2398 */
2399 boolean onLongPress(View v, int x, int y, MenuItem item);
2400 }
Chris Wren51c75102013-07-16 20:49:17 -04002401}