blob: 602ee6b49b2912f43e22610142c1f4faad9a5321 [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 Cinek2627d722018-01-19 12:16:49 -080019import static com.android.systemui.statusbar.notification.ActivityLaunchAnimator.ExpandAnimationParameters;
Selim Cinek5ba22542017-04-20 15:16:10 -070020import static com.android.systemui.statusbar.notification.NotificationInflater.InflationCallback;
Selim Cinekc478f902017-02-22 20:55:44 -080021
Mady Mellor4b80b102016-01-22 08:03:58 -080022import android.animation.Animator;
23import android.animation.AnimatorListenerAdapter;
Mady Mellor4b80b102016-01-22 08:03:58 -080024import android.animation.ObjectAnimator;
Mady Mellor4b80b102016-01-22 08:03:58 -080025import android.animation.ValueAnimator.AnimatorUpdateListener;
Selim Cinekddf1b392016-05-27 16:33:10 -070026import android.annotation.Nullable;
Rohan Shah63411fc2018-03-28 19:05:52 -070027import android.app.NotificationChannel;
Chris Wren51c75102013-07-16 20:49:17 -040028import android.content.Context;
Rohan Shah63411fc2018-03-28 19:05:52 -070029import android.content.pm.PackageInfo;
30import android.content.pm.PackageManager;
Mady Mellor9d03a522017-04-04 18:45:30 -070031import android.content.res.Configuration;
Julia Reynoldsb5867452018-02-28 16:31:35 -050032import android.content.res.Resources;
Selim Cinek515b2032017-11-15 10:20:19 -080033import android.graphics.Path;
Selim Cinekcab4a602014-09-03 14:47:57 +020034import android.graphics.drawable.AnimatedVectorDrawable;
35import android.graphics.drawable.AnimationDrawable;
Selim Cinekb5605e52015-02-20 18:21:41 +010036import android.graphics.drawable.ColorDrawable;
Selim Cinekcab4a602014-09-03 14:47:57 +020037import android.graphics.drawable.Drawable;
Rohan Shah4ed1b2a2018-03-30 13:26:01 -070038import android.os.AsyncTask;
Selim Cinekda42d652015-12-04 15:51:16 -080039import android.os.Build;
Selim Cineke9bad242016-06-15 11:46:37 -070040import android.os.Bundle;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020041import android.service.notification.StatusBarNotification;
Julia Reynoldsfc640012018-02-21 12:25:27 -050042import android.util.ArraySet;
Chris Wren51c75102013-07-16 20:49:17 -040043import android.util.AttributeSet;
Mady Mellorb0a82462016-04-30 17:31:02 -070044import android.util.FloatProperty;
Rohan Shah63411fc2018-03-28 19:05:52 -070045import android.util.Log;
Selim Cinek2627d722018-01-19 12:16:49 -080046import android.util.MathUtils;
Mady Mellorb0a82462016-04-30 17:31:02 -070047import android.util.Property;
Geoffrey Pitsch409db272017-08-28 14:51:52 +000048import android.view.KeyEvent;
Selim Cinek01af3342016-02-09 19:25:31 -080049import android.view.LayoutInflater;
Selim Cinek6183d122016-01-14 18:48:41 -080050import android.view.MotionEvent;
Selim Cinekeaa29ca2015-11-23 13:51:13 -080051import android.view.NotificationHeaderView;
Dan Sandlera5e0f412014-01-23 15:11:54 -050052import android.view.View;
Selim Cinek875a3a12016-11-18 17:52:16 -080053import android.view.ViewGroup;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020054import android.view.ViewStub;
Jorim Jaggife40f7d2014-04-28 15:20:04 +020055import android.view.accessibility.AccessibilityEvent;
Selim Cineke9bad242016-06-15 11:46:37 -070056import android.view.accessibility.AccessibilityNodeInfo;
Mady Mellorb3a6aed2018-05-11 13:24:07 -070057import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
Selim Cinek98713a42015-09-21 15:47:20 +020058import android.widget.Chronometer;
Mady Mellor95d743c2017-01-10 12:05:27 -080059import android.widget.FrameLayout;
Selim Cinekcab4a602014-09-03 14:47:57 +020060import android.widget.ImageView;
Selim Cinek1a48bab2017-02-17 19:38:40 -080061import android.widget.RemoteViews;
Selim Cinekb5605e52015-02-20 18:21:41 +010062
Selim Cinek5ba22542017-04-20 15:16:10 -070063import com.android.internal.annotations.VisibleForTesting;
Chris Wren698b1702016-05-23 11:16:32 -040064import com.android.internal.logging.MetricsLogger;
Tamas Berghammer383db5eb2016-06-22 15:21:38 +010065import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Selim Cinek4bb59342016-04-08 19:29:35 -070066import com.android.internal.util.NotificationColorUtil;
Selim Cinek875a3a12016-11-18 17:52:16 -080067import com.android.internal.widget.CachingIconView;
Mady Mellor95d743c2017-01-10 12:05:27 -080068import com.android.systemui.Dependency;
Selim Cinek0242fbb2016-10-19 13:38:32 -070069import com.android.systemui.Interpolators;
Dan Sandlera5e0f412014-01-23 15:11:54 -050070import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070071import com.android.systemui.classifier.FalsingManager;
Mady Mellor95d743c2017-01-10 12:05:27 -080072import com.android.systemui.plugins.PluginListener;
73import com.android.systemui.plugins.PluginManager;
74import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
75import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem;
76import com.android.systemui.statusbar.NotificationGuts.GutsContent;
Selim Cinek5cf1d052017-06-01 17:36:46 -070077import com.android.systemui.statusbar.notification.AboveShelfChangedListener;
Selim Cinek2627d722018-01-19 12:16:49 -080078import com.android.systemui.statusbar.notification.ActivityLaunchAnimator;
Selim Cinekc897bd32016-03-18 17:32:31 -070079import com.android.systemui.statusbar.notification.HybridNotificationView;
Rohan Shahda5dcdd2018-04-27 17:21:50 -070080import com.android.systemui.statusbar.notification.NotificationCounters;
Selim Cinek1a48bab2017-02-17 19:38:40 -080081import com.android.systemui.statusbar.notification.NotificationInflater;
Selim Cinek6743c0b2017-01-18 18:24:01 -080082import com.android.systemui.statusbar.notification.NotificationUtils;
Selim Cineke62255c2017-09-28 18:23:23 -070083import com.android.systemui.statusbar.notification.NotificationViewWrapper;
Selim Cineka7d4f822016-12-06 14:34:47 -080084import com.android.systemui.statusbar.notification.VisualStabilityManager;
Selim Cinekb5605e52015-02-20 18:21:41 +010085import com.android.systemui.statusbar.phone.NotificationGroupManager;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050086import com.android.systemui.statusbar.phone.StatusBar;
Selim Cinek31aada42015-12-18 17:51:15 -080087import com.android.systemui.statusbar.policy.HeadsUpManager;
Selim Cinek2627d722018-01-19 12:16:49 -080088import com.android.systemui.statusbar.stack.AmbientState;
Selim Cinek0cfbef42016-11-09 19:06:36 -080089import com.android.systemui.statusbar.stack.AnimationProperties;
90import com.android.systemui.statusbar.stack.ExpandableViewState;
Selim Cinekb5605e52015-02-20 18:21:41 +010091import com.android.systemui.statusbar.stack.NotificationChildrenContainer;
92import com.android.systemui.statusbar.stack.StackScrollState;
Selim Cinekb5605e52015-02-20 18:21:41 +010093
Mady Mellor4b80b102016-01-22 08:03:58 -080094import java.util.ArrayList;
Selim Cinekb5605e52015-02-20 18:21:41 +010095import java.util.List;
Lucas Dupincecc7c22017-09-12 16:02:45 -070096import java.util.function.BooleanSupplier;
Selim Cinek8875de12018-03-22 10:14:32 -070097import java.util.function.Consumer;
Dan Sandlera5e0f412014-01-23 15:11:54 -050098
Rohan Shah63411fc2018-03-28 19:05:52 -070099/**
100 * View representing a notification item - this can be either the individual child notification or
101 * the group summary (which contains 1 or more child notifications).
102 */
Mady Mellor95d743c2017-01-10 12:05:27 -0800103public class ExpandableNotificationRow extends ActivatableNotificationView
104 implements PluginListener<NotificationMenuRowPlugin> {
Selim Cinekb5605e52015-02-20 18:21:41 +0100105
Rohan Shah4ed1b2a2018-03-30 13:26:01 -0700106 private static final boolean DEBUG = false;
Selim Cinekb5605e52015-02-20 18:21:41 +0100107 private static final int DEFAULT_DIVIDER_ALPHA = 0x29;
108 private static final int COLORED_DIVIDER_ALPHA = 0x7B;
Mady Mellor95d743c2017-01-10 12:05:27 -0800109 private static final int MENU_VIEW_INDEX = 0;
Rohan Shah63411fc2018-03-28 19:05:52 -0700110 private static final String TAG = "ExpandableNotifRow";
felkachang3b2ab9b2018-05-24 15:38:04 +0800111 public static final float DEFAULT_HEADER_VISIBLE_AMOUNT = 1.0f;
Mady Mellor95d743c2017-01-10 12:05:27 -0800112
Rohan Shah4ed1b2a2018-03-30 13:26:01 -0700113 /**
114 * Listener for when {@link ExpandableNotificationRow} is laid out.
115 */
Mady Mellor035badd2017-04-04 18:45:30 -0700116 public interface LayoutListener {
Rohan Shah4ed1b2a2018-03-30 13:26:01 -0700117 void onLayout();
Mady Mellor035badd2017-04-04 18:45:30 -0700118 }
119
120 private LayoutListener mLayoutListener;
Lucas Dupincecc7c22017-09-12 16:02:45 -0700121 private boolean mDark;
Selim Cinek55a3e732017-05-25 18:30:10 -0700122 private boolean mLowPriorityStateUpdated;
Selim Cinek1a48bab2017-02-17 19:38:40 -0800123 private final NotificationInflater mNotificationInflater;
Selim Cinek0242fbb2016-10-19 13:38:32 -0700124 private int mIconTransformContentShift;
Selim Cinek875a3a12016-11-18 17:52:16 -0800125 private int mIconTransformContentShiftNoIcon;
Selim Cinek01af3342016-02-09 19:25:31 -0800126 private int mNotificationMinHeightLegacy;
Selim Cinek9b49f6d2017-11-13 18:19:35 -0800127 private int mNotificationMinHeightBeforeP;
Selim Cinek01af3342016-02-09 19:25:31 -0800128 private int mMaxHeadsUpHeightLegacy;
Selim Cinek9b49f6d2017-11-13 18:19:35 -0800129 private int mMaxHeadsUpHeightBeforeP;
Selim Cinek01af3342016-02-09 19:25:31 -0800130 private int mMaxHeadsUpHeight;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800131 private int mMaxHeadsUpHeightIncreased;
Selim Cinek01af3342016-02-09 19:25:31 -0800132 private int mNotificationMinHeight;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800133 private int mNotificationMinHeightLarge;
Selim Cinek01af3342016-02-09 19:25:31 -0800134 private int mNotificationMaxHeight;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800135 private int mNotificationAmbientHeight;
Mady Mellorb0a82462016-04-30 17:31:02 -0700136 private int mIncreasedPaddingBetweenElements;
Selim Cinek2627d722018-01-19 12:16:49 -0800137 private int mNotificationLaunchHeight;
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100138 private boolean mMustStayOnScreen;
Chris Wren51c75102013-07-16 20:49:17 -0400139
Selim Cinek1685e632014-04-08 02:27:49 +0200140 /** Does this row contain layouts that can adapt to row expansion */
Chris Wren51c75102013-07-16 20:49:17 -0400141 private boolean mExpandable;
Selim Cinek1685e632014-04-08 02:27:49 +0200142 /** Has the user actively changed the expansion state of this row */
143 private boolean mHasUserChangedExpansion;
144 /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */
Chris Wren51c75102013-07-16 20:49:17 -0400145 private boolean mUserExpanded;
Rohan Shah524cf7b2018-03-15 14:40:02 -0700146 /** Whether the blocking helper is showing on this notification (even if dismissed) */
147 private boolean mIsBlockingHelperShowing;
Selim Cinek31aada42015-12-18 17:51:15 -0800148
149 /**
150 * Has this notification been expanded while it was pinned
151 */
152 private boolean mExpandedWhenPinned;
Selim Cinek1685e632014-04-08 02:27:49 +0200153 /** Is the user touching this row */
Chris Wren51c75102013-07-16 20:49:17 -0400154 private boolean mUserLocked;
Selim Cinek1685e632014-04-08 02:27:49 +0200155 /** Are we showing the "public" version */
Dan Sandlera5e0f412014-01-23 15:11:54 -0500156 private boolean mShowingPublic;
Jorim Jaggiae441282014-08-01 02:45:18 +0200157 private boolean mSensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -0800158 private boolean mSensitiveHiddenInGeneral;
Jorim Jaggiae441282014-08-01 02:45:18 +0200159 private boolean mShowingPublicInitialized;
Selim Cinek60122be2015-04-15 18:16:50 -0700160 private boolean mHideSensitiveForIntrinsicHeight;
felkachang3b2ab9b2018-05-24 15:38:04 +0800161 private float mHeaderVisibleAmount = DEFAULT_HEADER_VISIBLE_AMOUNT;
Chris Wren51c75102013-07-16 20:49:17 -0400162
Selim Cinek1685e632014-04-08 02:27:49 +0200163 /**
164 * Is this notification expanded by the system. The expansion state can be overridden by the
165 * user expansion.
166 */
167 private boolean mIsSystemExpanded;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200168
169 /**
Selim Cinek83bc7832015-10-22 13:26:54 -0700170 * Whether the notification is on the keyguard and the expansion is disabled.
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200171 */
Selim Cinek83bc7832015-10-22 13:26:54 -0700172 private boolean mOnKeyguard;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200173
Mady Mellorb0a82462016-04-30 17:31:02 -0700174 private Animator mTranslateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -0800175 private ArrayList<View> mTranslateableViews;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200176 private NotificationContentView mPublicLayout;
177 private NotificationContentView mPrivateLayout;
Adrian Rooseb434ff2017-01-11 11:18:48 -0800178 private NotificationContentView[] mLayouts;
Selim Cinek4bb59342016-04-08 19:29:35 -0700179 private int mNotificationColor;
Chris Wren78403d72014-07-28 10:23:24 +0100180 private ExpansionLogger mLogger;
181 private String mLoggingKey;
Selim Cinek8d490d42015-04-10 00:05:50 -0700182 private NotificationGuts mGuts;
Selim Cinekda42d652015-12-04 15:51:16 -0800183 private NotificationData.Entry mEntry;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200184 private StatusBarNotification mStatusBarNotification;
Mady Mellor3fd273e2016-03-15 21:08:14 -0700185 private String mAppName;
Selim Cinek1a521f32014-11-03 17:39:29 +0100186 private boolean mIsHeadsUp;
Selim Cinek98713a42015-09-21 15:47:20 +0200187 private boolean mLastChronometerRunning = true;
Selim Cinekb5605e52015-02-20 18:21:41 +0100188 private ViewStub mChildrenContainerStub;
189 private NotificationGroupManager mGroupManager;
Selim Cinekb5605e52015-02-20 18:21:41 +0100190 private boolean mChildrenExpanded;
Selim Cinek263398f2015-10-21 17:40:23 -0700191 private boolean mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100192 private NotificationChildrenContainer mChildrenContainer;
Mady Mellor95d743c2017-01-10 12:05:27 -0800193 private NotificationMenuRowPlugin mMenuRow;
Selim Cinekab29aeb2015-02-20 18:18:32 +0100194 private ViewStub mGutsStub;
Selim Cinekb5605e52015-02-20 18:21:41 +0100195 private boolean mIsSystemChildExpanded;
Selim Cinek684a4422015-04-15 16:18:39 -0700196 private boolean mIsPinned;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700197 private FalsingManager mFalsingManager;
Selim Cinek2627d722018-01-19 12:16:49 -0800198 private boolean mExpandAnimationRunning;
Selim Cinek5cf1d052017-06-01 17:36:46 -0700199 private AboveShelfChangedListener mAboveShelfChangedListener;
Selim Cinek31aada42015-12-18 17:51:15 -0800200 private HeadsUpManager mHeadsUpManager;
Selim Cinek8875de12018-03-22 10:14:32 -0700201 private Consumer<Boolean> mHeadsUpAnimatingAwayListener;
Selim Cinekc25989e2018-02-16 16:42:14 -0800202 private boolean mChildIsExpanding;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200203
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700204 private boolean mJustClicked;
Selim Cinek5a175d92015-11-23 18:01:33 -0800205 private boolean mIconAnimationRunning;
Selim Cinek34d93b02015-10-22 12:30:38 -0700206 private boolean mShowNoBackground;
Selim Cinek388df6d2015-10-22 13:25:11 -0700207 private ExpandableNotificationRow mNotificationParent;
Selim Cinek570981d2015-12-01 11:37:01 -0800208 private OnExpandClickListener mOnExpandClickListener;
Julia Reynoldsb5867452018-02-28 16:31:35 -0500209 private View.OnClickListener mOnAppOpsClickListener;
Geoffrey Pitsch409db272017-08-28 14:51:52 +0000210
211 // Listener will be called when receiving a long click event.
212 // Use #setLongPressPosition to optionally assign positional data with the long press.
213 private LongPressListener mLongPressListener;
214
Mady Mellorb0a82462016-04-30 17:31:02 -0700215 private boolean mGroupExpansionChanging;
216
Anthony Chen6bf88a02017-04-10 14:41:44 -0700217 /**
Lucas Dupincecc7c22017-09-12 16:02:45 -0700218 * A supplier that returns true if keyguard is secure.
219 */
220 private BooleanSupplier mSecureStateProvider;
221
222 /**
Anthony Chen6bf88a02017-04-10 14:41:44 -0700223 * Whether or not a notification that is not part of a group of notifications can be manually
224 * expanded by the user.
225 */
226 private boolean mEnableNonGroupedNotificationExpand;
227
228 /**
229 * Whether or not to update the background of the header of the notification when its expanded.
230 * If {@code true}, the header background will disappear when expanded.
231 */
232 private boolean mShowGroupBackgroundWhenExpanded;
233
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800234 private OnClickListener mExpandClickListener = new OnClickListener() {
235 @Override
236 public void onClick(View v) {
Selim Cinek0b9cf462017-12-07 16:31:03 -0800237 if (!shouldShowPublic() && (!mIsLowPriority || isExpanded())
Selim Cinek414ad332017-02-24 19:06:12 -0800238 && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) {
Mady Mellor1a5d8ea2016-06-09 10:42:42 -0700239 mGroupExpansionChanging = true;
Chris Wren698b1702016-05-23 11:16:32 -0400240 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
241 boolean nowExpanded = mGroupManager.toggleGroupExpansion(mStatusBarNotification);
242 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400243 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_GROUP_EXPANDER,
244 nowExpanded);
Selim Cinek414ad332017-02-24 19:06:12 -0800245 onExpansionChanged(true /* userAction */, wasExpanded);
Anthony Chen6bf88a02017-04-10 14:41:44 -0700246 } else if (mEnableNonGroupedNotificationExpand) {
Selim Cineke9bad242016-06-15 11:46:37 -0700247 if (v.isAccessibilityFocused()) {
248 mPrivateLayout.setFocusOnVisibilityChange();
249 }
Selim Cinek31aada42015-12-18 17:51:15 -0800250 boolean nowExpanded;
251 if (isPinned()) {
252 nowExpanded = !mExpandedWhenPinned;
253 mExpandedWhenPinned = nowExpanded;
254 } else {
255 nowExpanded = !isExpanded();
256 setUserExpanded(nowExpanded);
257 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800258 notifyHeightChanged(true);
Selim Cinek31aada42015-12-18 17:51:15 -0800259 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400260 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_EXPANDER,
261 nowExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800262 }
263 }
264 };
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700265 private boolean mForceUnlocked;
Selim Cinek3f19f602016-05-02 18:01:56 -0700266 private boolean mDismissed;
267 private boolean mKeepInParent;
268 private boolean mRemoved;
Mady Mellorb0a82462016-04-30 17:31:02 -0700269 private static final Property<ExpandableNotificationRow, Float> TRANSLATE_CONTENT =
270 new FloatProperty<ExpandableNotificationRow>("translate") {
271 @Override
272 public void setValue(ExpandableNotificationRow object, float value) {
273 object.setTranslation(value);
274 }
275
276 @Override
277 public Float get(ExpandableNotificationRow object) {
278 return object.getTranslation();
279 }
Rohan Shah4ed1b2a2018-03-30 13:26:01 -0700280 };
Selim Cinekddf1b392016-05-27 16:33:10 -0700281 private OnClickListener mOnClickListener;
Selim Cinek73cf02a2016-06-17 13:08:00 -0700282 private boolean mHeadsupDisappearRunning;
Selim Cineke9bad242016-06-15 11:46:37 -0700283 private View mChildAfterViewWhenDismissed;
284 private View mGroupParentWhenDismissed;
285 private boolean mRefocusOnDismiss;
Selim Cinek2b549f42016-11-22 16:38:51 -0800286 private float mContentTransformationAmount;
Selim Cinek0242fbb2016-10-19 13:38:32 -0700287 private boolean mIconsVisible = true;
Selim Cinekd127d792016-11-01 19:11:41 -0700288 private boolean mAboveShelf;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800289 private boolean mShowAmbient;
Selim Cinek875a3a12016-11-18 17:52:16 -0800290 private boolean mIsLastChild;
Selim Cineke9079112016-12-14 14:41:01 -0800291 private Runnable mOnDismissRunnable;
Selim Cinek6743c0b2017-01-18 18:24:01 -0800292 private boolean mIsLowPriority;
Selim Cineka7ed2c12017-01-23 20:47:24 -0800293 private boolean mIsColorized;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800294 private boolean mUseIncreasedCollapsedHeight;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800295 private boolean mUseIncreasedHeadsUpHeight;
Selim Cinekef8c2252017-02-10 14:52:18 -0800296 private float mTranslationWhenRemoved;
297 private boolean mWasChildInGroupWhenRemoved;
Adrian Roos6f6e1592017-05-02 16:22:53 -0700298 private int mNotificationColorAmbient;
Selim Cinek2627d722018-01-19 12:16:49 -0800299 private NotificationViewState mNotificationViewState;
Mady Mellorb0a82462016-04-30 17:31:02 -0700300
Rohan Shah4ed1b2a2018-03-30 13:26:01 -0700301 private SystemNotificationAsyncTask mSystemNotificationAsyncTask =
302 new SystemNotificationAsyncTask();
303
304 /**
305 * Returns whether the given {@code statusBarNotification} is a system notification.
306 * <b>Note</b>, this should be run in the background thread if possible as it makes multiple IPC
307 * calls.
308 */
309 private static Boolean isSystemNotification(
310 Context context, StatusBarNotification statusBarNotification) {
311 PackageManager packageManager = StatusBar.getPackageManagerForUser(
312 context, statusBarNotification.getUser().getIdentifier());
313 Boolean isSystemNotification = null;
314
315 try {
316 PackageInfo packageInfo = packageManager.getPackageInfo(
317 statusBarNotification.getPackageName(), PackageManager.GET_SIGNATURES);
318
319 isSystemNotification =
320 com.android.settingslib.Utils.isSystemPackage(
321 context.getResources(), packageManager, packageInfo);
322 } catch (PackageManager.NameNotFoundException e) {
323 Log.e(TAG, "cacheIsSystemNotification: Could not find package info");
324 }
325 return isSystemNotification;
326 }
327
Mady Mellor43c2cd12016-12-12 21:05:13 -0800328 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -0700329 public boolean isGroupExpansionChanging() {
330 if (isChildInGroup()) {
331 return mNotificationParent.isGroupExpansionChanging();
332 }
333 return mGroupExpansionChanging;
334 }
335
336 public void setGroupExpansionChanging(boolean changing) {
337 mGroupExpansionChanging = changing;
338 }
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700339
Adrian Roos599be342016-06-13 14:54:39 -0700340 @Override
341 public void setActualHeightAnimating(boolean animating) {
342 if (mPrivateLayout != null) {
343 mPrivateLayout.setContentHeightAnimating(animating);
344 }
345 }
346
Selim Cinek8d490d42015-04-10 00:05:50 -0700347 public NotificationContentView getPrivateLayout() {
348 return mPrivateLayout;
349 }
350
351 public NotificationContentView getPublicLayout() {
352 return mPublicLayout;
353 }
354
Selim Cinekcab4a602014-09-03 14:47:57 +0200355 public void setIconAnimationRunning(boolean running) {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800356 for (NotificationContentView l : mLayouts) {
357 setIconAnimationRunning(running, l);
358 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800359 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700360 setIconAnimationRunningForChild(running, mChildrenContainer.getHeaderView());
Selim Cinek414ad332017-02-24 19:06:12 -0800361 setIconAnimationRunningForChild(running, mChildrenContainer.getLowPriorityHeaderView());
Selim Cinek5a175d92015-11-23 18:01:33 -0800362 List<ExpandableNotificationRow> notificationChildren =
363 mChildrenContainer.getNotificationChildren();
364 for (int i = 0; i < notificationChildren.size(); i++) {
365 ExpandableNotificationRow child = notificationChildren.get(i);
366 child.setIconAnimationRunning(running);
367 }
368 }
369 mIconAnimationRunning = running;
Selim Cinekcab4a602014-09-03 14:47:57 +0200370 }
371
372 private void setIconAnimationRunning(boolean running, NotificationContentView layout) {
373 if (layout != null) {
374 View contractedChild = layout.getContractedChild();
375 View expandedChild = layout.getExpandedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -0700376 View headsUpChild = layout.getHeadsUpChild();
Selim Cinekcab4a602014-09-03 14:47:57 +0200377 setIconAnimationRunningForChild(running, contractedChild);
378 setIconAnimationRunningForChild(running, expandedChild);
Selim Cinek8d490d42015-04-10 00:05:50 -0700379 setIconAnimationRunningForChild(running, headsUpChild);
Selim Cinekcab4a602014-09-03 14:47:57 +0200380 }
381 }
382
383 private void setIconAnimationRunningForChild(boolean running, View child) {
384 if (child != null) {
385 ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon);
386 setIconRunning(icon, running);
387 ImageView rightIcon = (ImageView) child.findViewById(
388 com.android.internal.R.id.right_icon);
389 setIconRunning(rightIcon, running);
390 }
391 }
392
393 private void setIconRunning(ImageView imageView, boolean running) {
394 if (imageView != null) {
395 Drawable drawable = imageView.getDrawable();
396 if (drawable instanceof AnimationDrawable) {
397 AnimationDrawable animationDrawable = (AnimationDrawable) drawable;
398 if (running) {
399 animationDrawable.start();
400 } else {
401 animationDrawable.stop();
402 }
403 } else if (drawable instanceof AnimatedVectorDrawable) {
404 AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable;
405 if (running) {
406 animationDrawable.start();
407 } else {
408 animationDrawable.stop();
409 }
410 }
411 }
412 }
413
Selim Cinek5ba22542017-04-20 15:16:10 -0700414 public void updateNotification(NotificationData.Entry entry) {
Selim Cinekda42d652015-12-04 15:51:16 -0800415 mEntry = entry;
416 mStatusBarNotification = entry.notification;
Selim Cinek1a48bab2017-02-17 19:38:40 -0800417 mNotificationInflater.inflateNotificationViews();
Rohan Shah63411fc2018-03-28 19:05:52 -0700418
Rohan Shah4ed1b2a2018-03-30 13:26:01 -0700419 cacheIsSystemNotification();
Rohan Shah63411fc2018-03-28 19:05:52 -0700420 }
421
422 /**
Rohan Shah4ed1b2a2018-03-30 13:26:01 -0700423 * Caches whether or not this row contains a system notification. Note, this is only cached
424 * once per notification as the packageInfo can't technically change for a notification row.
Rohan Shah63411fc2018-03-28 19:05:52 -0700425 */
Rohan Shah4ed1b2a2018-03-30 13:26:01 -0700426 private void cacheIsSystemNotification() {
Julia Reynoldsaa96cf32018-04-17 09:09:04 -0400427 if (mEntry != null && mEntry.mIsSystemNotification == null) {
Rohan Shah4ed1b2a2018-03-30 13:26:01 -0700428 if (mSystemNotificationAsyncTask.getStatus() == AsyncTask.Status.PENDING) {
429 // Run async task once, only if it hasn't already been executed. Note this is
430 // executed in serial - no need to parallelize this small task.
431 mSystemNotificationAsyncTask.execute();
Rohan Shah63411fc2018-03-28 19:05:52 -0700432 }
433 }
434 }
435
436 /**
Rohan Shahca0447e2018-03-30 15:18:27 -0700437 * Returns whether this row is considered non-blockable (i.e. it's a non-blockable system notif
438 * or is in a whitelist).
Rohan Shah63411fc2018-03-28 19:05:52 -0700439 */
440 public boolean getIsNonblockable() {
Rohan Shah4ed1b2a2018-03-30 13:26:01 -0700441 boolean isNonblockable = Dependency.get(NotificationBlockingHelperManager.class)
Rohan Shah63411fc2018-03-28 19:05:52 -0700442 .isNonblockablePackage(mStatusBarNotification.getPackageName());
443
Rohan Shah4ed1b2a2018-03-30 13:26:01 -0700444 // If the SystemNotifAsyncTask hasn't finished running or retrieved a value, we'll try once
445 // again, but in-place on the main thread this time. This should rarely ever get called.
Julia Reynoldsaa96cf32018-04-17 09:09:04 -0400446 if (mEntry != null && mEntry.mIsSystemNotification == null) {
Rohan Shah4ed1b2a2018-03-30 13:26:01 -0700447 if (DEBUG) {
448 Log.d(TAG, "Retrieving isSystemNotification on main thread");
449 }
450 mSystemNotificationAsyncTask.cancel(true /* mayInterruptIfRunning */);
Julia Reynoldsaa96cf32018-04-17 09:09:04 -0400451 mEntry.mIsSystemNotification = isSystemNotification(mContext, mStatusBarNotification);
Rohan Shah4ed1b2a2018-03-30 13:26:01 -0700452 }
453
Julia Reynoldsaa96cf32018-04-17 09:09:04 -0400454 if (!isNonblockable && mEntry != null && mEntry.mIsSystemNotification != null) {
455 if (mEntry.mIsSystemNotification) {
Rohan Shah63411fc2018-03-28 19:05:52 -0700456 if (mEntry.channel != null
457 && !mEntry.channel.isBlockableSystem()) {
458 isNonblockable = true;
459 }
460 }
461 }
462 return isNonblockable;
Selim Cinekc478f902017-02-22 20:55:44 -0800463 }
464
Selim Cinek5ba22542017-04-20 15:16:10 -0700465 public void onNotificationUpdated() {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800466 for (NotificationContentView l : mLayouts) {
Selim Cinekc478f902017-02-22 20:55:44 -0800467 l.onNotificationUpdated(mEntry);
Adrian Rooseb434ff2017-01-11 11:18:48 -0800468 }
Selim Cineka7ed2c12017-01-23 20:47:24 -0800469 mIsColorized = mStatusBarNotification.getNotification().isColorized();
Selim Cinek757d8792016-01-28 16:21:08 -0800470 mShowingPublicInitialized = false;
Selim Cinek4bb59342016-04-08 19:29:35 -0700471 updateNotificationColor();
Mady Mellor4c197602017-04-10 17:57:52 -0700472 if (mMenuRow != null) {
Mady Mellor4ab28202017-06-06 11:42:50 -0700473 mMenuRow.onNotificationUpdated(mStatusBarNotification);
Beverly3f56f052018-05-08 14:56:03 -0400474 mMenuRow.setAppName(mAppName);
Mady Mellor4c197602017-04-10 17:57:52 -0700475 }
Selim Cinek8fc93c92015-11-23 17:48:07 -0800476 if (mIsSummaryWithChildren) {
Selim Cinek414ad332017-02-24 19:06:12 -0800477 mChildrenContainer.recreateNotificationHeader(mExpandClickListener);
Selim Cinekc897bd32016-03-18 17:32:31 -0700478 mChildrenContainer.onNotificationUpdated();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800479 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800480 if (mIconAnimationRunning) {
481 setIconAnimationRunning(true);
482 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800483 if (mNotificationParent != null) {
484 mNotificationParent.updateChildrenHeaderAppearance();
485 }
Selim Cinek263398f2015-10-21 17:40:23 -0700486 onChildrenCountChanged();
Selim Cinek624c02db2015-12-14 21:00:02 -0800487 // The public layouts expand button is always visible
488 mPublicLayout.updateExpandButtons(true);
Selim Cinekda42d652015-12-04 15:51:16 -0800489 updateLimits();
Selim Cinek0242fbb2016-10-19 13:38:32 -0700490 updateIconVisibilities();
Selim Cinek6743c0b2017-01-18 18:24:01 -0800491 updateShelfIconColor();
Selim Cinekfe24fb72018-02-13 14:34:55 -0800492 updateRippleAllowed();
Selim Cinek6743c0b2017-01-18 18:24:01 -0800493 }
494
Lucas Dupinb6ed63b2017-05-30 16:17:42 -0700495 @VisibleForTesting
496 void updateShelfIconColor() {
Selim Cinek6743c0b2017-01-18 18:24:01 -0800497 StatusBarIconView expandedIcon = mEntry.expandedIcon;
498 boolean isPreL = Boolean.TRUE.equals(expandedIcon.getTag(R.id.icon_is_pre_L));
499 boolean colorize = !isPreL || NotificationUtils.isGrayscale(expandedIcon,
500 NotificationColorUtil.getInstance(mContext));
Selim Cinek875ba9b2017-02-13 16:20:17 -0800501 int color = StatusBarIconView.NO_COLOR;
Selim Cinek6743c0b2017-01-18 18:24:01 -0800502 if (colorize) {
Lucas Dupinb6ed63b2017-05-30 16:17:42 -0700503 NotificationHeaderView header = getVisibleNotificationHeader();
504 if (header != null) {
505 color = header.getOriginalIconColor();
506 } else {
507 color = mEntry.getContrastedColor(mContext, mIsLowPriority && !isExpanded(),
508 getBackgroundColorWithoutTint());
509 }
Selim Cinek6743c0b2017-01-18 18:24:01 -0800510 }
Selim Cinek875ba9b2017-02-13 16:20:17 -0800511 expandedIcon.setStaticDrawableColor(color);
Selim Cinekda42d652015-12-04 15:51:16 -0800512 }
513
Selim Cinek5cf1d052017-06-01 17:36:46 -0700514 public void setAboveShelfChangedListener(AboveShelfChangedListener aboveShelfChangedListener) {
515 mAboveShelfChangedListener = aboveShelfChangedListener;
516 }
517
Lucas Dupincecc7c22017-09-12 16:02:45 -0700518 /**
519 * Sets a supplier that can determine whether the keyguard is secure or not.
520 * @param secureStateProvider A function that returns true if keyguard is secure.
521 */
522 public void setSecureStateProvider(BooleanSupplier secureStateProvider) {
523 mSecureStateProvider = secureStateProvider;
524 }
525
Selim Cinek4705f292017-04-24 22:18:48 -0700526 @Override
527 public boolean isDimmable() {
528 if (!getShowingLayout().isDimmable()) {
529 return false;
530 }
531 return super.isDimmable();
532 }
533
Selim Cinekda42d652015-12-04 15:51:16 -0800534 private void updateLimits() {
Adrian Rooseb434ff2017-01-11 11:18:48 -0800535 for (NotificationContentView l : mLayouts) {
536 updateLimitsForView(l);
537 }
Selim Cineka1744872016-03-11 15:36:06 -0800538 }
539
540 private void updateLimitsForView(NotificationContentView layout) {
541 boolean customView = layout.getContractedChild().getId()
Selim Cinekda42d652015-12-04 15:51:16 -0800542 != com.android.internal.R.id.status_bar_latest_event_content;
543 boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N;
Selim Cinek9b49f6d2017-11-13 18:19:35 -0800544 boolean beforeP = mEntry.targetSdk < Build.VERSION_CODES.P;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800545 int minHeight;
Selim Cinek9b49f6d2017-11-13 18:19:35 -0800546 if (customView && beforeP && !mIsSummaryWithChildren) {
547 minHeight = beforeN ? mNotificationMinHeightLegacy : mNotificationMinHeightBeforeP;
Selim Cinek7d1009b2017-01-25 15:28:28 -0800548 } else if (mUseIncreasedCollapsedHeight && layout == mPrivateLayout) {
549 minHeight = mNotificationMinHeightLarge;
550 } else {
551 minHeight = mNotificationMinHeight;
552 }
Selim Cineka1744872016-03-11 15:36:06 -0800553 boolean headsUpCustom = layout.getHeadsUpChild() != null &&
554 layout.getHeadsUpChild().getId()
555 != com.android.internal.R.id.status_bar_latest_event_content;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800556 int headsUpheight;
Selim Cinek9b49f6d2017-11-13 18:19:35 -0800557 if (headsUpCustom && beforeP) {
558 headsUpheight = beforeN ? mMaxHeadsUpHeightLegacy : mMaxHeadsUpHeightBeforeP;
Selim Cinek87ed69b2017-02-09 15:59:43 -0800559 } else if (mUseIncreasedHeadsUpHeight && layout == mPrivateLayout) {
560 headsUpheight = mMaxHeadsUpHeightIncreased;
561 } else {
562 headsUpheight = mMaxHeadsUpHeight;
563 }
Selim Cineke62255c2017-09-28 18:23:23 -0700564 NotificationViewWrapper headsUpWrapper = layout.getVisibleWrapper(
565 NotificationContentView.VISIBLE_TYPE_HEADSUP);
566 if (headsUpWrapper != null) {
567 headsUpheight = Math.max(headsUpheight, headsUpWrapper.getMinLayoutHeight());
568 }
Adrian Roos0aac04f2016-12-08 15:59:29 -0800569 layout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight,
570 mNotificationAmbientHeight);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200571 }
572
573 public StatusBarNotification getStatusBarNotification() {
574 return mStatusBarNotification;
575 }
576
Selim Cinek281c2022016-10-13 19:14:43 -0700577 public NotificationData.Entry getEntry() {
578 return mEntry;
579 }
580
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700581 public boolean isHeadsUp() {
582 return mIsHeadsUp;
583 }
584
Selim Cinek1a521f32014-11-03 17:39:29 +0100585 public void setHeadsUp(boolean isHeadsUp) {
Selim Cinek5cf1d052017-06-01 17:36:46 -0700586 boolean wasAboveShelf = isAboveShelf();
Selim Cinekc80fdb12015-04-13 15:09:08 -0700587 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek1a521f32014-11-03 17:39:29 +0100588 mIsHeadsUp = isHeadsUp;
Selim Cinek8d490d42015-04-10 00:05:50 -0700589 mPrivateLayout.setHeadsUp(isHeadsUp);
Selim Cinekb41b2f62016-04-26 14:03:29 -0700590 if (mIsSummaryWithChildren) {
591 // The overflow might change since we allow more lines as HUN.
592 mChildrenContainer.updateGroupOverflow();
593 }
Selim Cinekc80fdb12015-04-13 15:09:08 -0700594 if (intrinsicBefore != getIntrinsicHeight()) {
595 notifyHeightChanged(false /* needsAnimation */);
596 }
Selim Cinekd127d792016-11-01 19:11:41 -0700597 if (isHeadsUp) {
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100598 mMustStayOnScreen = true;
Selim Cinekd127d792016-11-01 19:11:41 -0700599 setAboveShelf(true);
Selim Cinek5cf1d052017-06-01 17:36:46 -0700600 } else if (isAboveShelf() != wasAboveShelf) {
601 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
Selim Cinekd127d792016-11-01 19:11:41 -0700602 }
Selim Cinek1a521f32014-11-03 17:39:29 +0100603 }
604
Selim Cinekb5605e52015-02-20 18:21:41 +0100605 public void setGroupManager(NotificationGroupManager groupManager) {
606 mGroupManager = groupManager;
Selim Cinek83bc7832015-10-22 13:26:54 -0700607 mPrivateLayout.setGroupManager(groupManager);
Selim Cinekb5605e52015-02-20 18:21:41 +0100608 }
609
Adrian Roosb88b1a12015-12-09 18:51:05 -0800610 public void setRemoteInputController(RemoteInputController r) {
611 mPrivateLayout.setRemoteInputController(r);
612 }
613
Mady Mellor3fd273e2016-03-15 21:08:14 -0700614 public void setAppName(String appName) {
615 mAppName = appName;
Mady Mellor95d743c2017-01-10 12:05:27 -0800616 if (mMenuRow != null && mMenuRow.getMenuView() != null) {
Mady Mellor761cde12017-01-10 11:36:39 -0800617 mMenuRow.setAppName(mAppName);
Mady Mellor3fd273e2016-03-15 21:08:14 -0700618 }
619 }
620
Selim Cinekb5605e52015-02-20 18:21:41 +0100621 public void addChildNotification(ExpandableNotificationRow row) {
622 addChildNotification(row, -1);
623 }
624
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800625 /**
626 * Set the how much the header should be visible. A value of 0 will make the header fully gone
627 * and a value of 1 will make the notification look just like normal.
628 * This is being used for heads up notifications, when they are pinned to the top of the screen
629 * and the header content is extracted to the statusbar.
630 *
631 * @param headerVisibleAmount the amount the header should be visible.
632 */
633 public void setHeaderVisibleAmount(float headerVisibleAmount) {
634 if (mHeaderVisibleAmount != headerVisibleAmount) {
635 mHeaderVisibleAmount = headerVisibleAmount;
636 mPrivateLayout.setHeaderVisibleAmount(headerVisibleAmount);
637 if (mChildrenContainer != null) {
638 mChildrenContainer.setHeaderVisibleAmount(headerVisibleAmount);
639 }
640 notifyHeightChanged(false /* needsAnimation */);
641 }
642 }
643
Selim Cinek99e9adf2018-03-15 09:17:47 -0700644 @Override
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800645 public float getHeaderVisibleAmount() {
646 return mHeaderVisibleAmount;
647 }
648
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100649 @Override
650 public void setHeadsUpIsVisible() {
651 super.setHeadsUpIsVisible();
652 mMustStayOnScreen = false;
653 }
654
Selim Cinekb5605e52015-02-20 18:21:41 +0100655 /**
656 * Add a child notification to this view.
657 *
658 * @param row the row to add
659 * @param childIndex the index to add it at, if -1 it will be added at the end
660 */
661 public void addChildNotification(ExpandableNotificationRow row, int childIndex) {
662 if (mChildrenContainer == null) {
663 mChildrenContainerStub.inflate();
664 }
665 mChildrenContainer.addNotification(row, childIndex);
Selim Cinek263398f2015-10-21 17:40:23 -0700666 onChildrenCountChanged();
667 row.setIsChildInGroup(true, this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100668 }
669
670 public void removeChildNotification(ExpandableNotificationRow row) {
671 if (mChildrenContainer != null) {
672 mChildrenContainer.removeNotification(row);
673 }
Selim Cinek263398f2015-10-21 17:40:23 -0700674 onChildrenCountChanged();
675 row.setIsChildInGroup(false, null);
Selim Cinek2871bef2017-11-22 08:40:00 -0800676 row.setBottomRoundness(0.0f, false /* animate */);
Selim Cinek263398f2015-10-21 17:40:23 -0700677 }
678
Mady Mellor43c2cd12016-12-12 21:05:13 -0800679 @Override
Selim Cinek263398f2015-10-21 17:40:23 -0700680 public boolean isChildInGroup() {
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700681 return mNotificationParent != null;
Selim Cinek263398f2015-10-21 17:40:23 -0700682 }
683
Rohan Shah524cf7b2018-03-15 14:40:02 -0700684 /**
685 * @return whether this notification is the only child in the group summary
686 */
687 public boolean isOnlyChildInGroup() {
688 return mGroupManager.isOnlyChildInGroup(getStatusBarNotification());
689 }
690
Selim Cinek388df6d2015-10-22 13:25:11 -0700691 public ExpandableNotificationRow getNotificationParent() {
692 return mNotificationParent;
693 }
694
Selim Cinek263398f2015-10-21 17:40:23 -0700695 /**
696 * @param isChildInGroup Is this notification now in a group
697 * @param parent the new parent notification
698 */
Selim Cinekc25989e2018-02-16 16:42:14 -0800699 public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500700 boolean childInGroup = StatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup;
Selim Cinekc25989e2018-02-16 16:42:14 -0800701 if (mExpandAnimationRunning && !isChildInGroup && mNotificationParent != null) {
702 mNotificationParent.setChildIsExpanding(false);
703 mNotificationParent.setExtraWidthForClipping(0.0f);
704 mNotificationParent.setMinimumHeightForClipping(0);
705 }
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700706 mNotificationParent = childInGroup ? parent : null;
707 mPrivateLayout.setIsChildInGroup(childInGroup);
Selim Cinek5ba22542017-04-20 15:16:10 -0700708 mNotificationInflater.setIsChildInGroup(childInGroup);
Mady Mellorc7d65b42016-05-04 11:44:57 -0400709 resetBackgroundAlpha();
Mady Mellorb0a82462016-04-30 17:31:02 -0700710 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -0700711 updateClickAndFocus();
Mady Mellorb0a82462016-04-30 17:31:02 -0700712 if (mNotificationParent != null) {
Selim Cinek9ce32852017-02-15 16:21:10 -0800713 setOverrideTintColor(NO_COLOR, 0.0f);
Selim Cinekeccf4942018-05-30 09:55:36 -0700714 // Let's reset the distance to top roundness, as this isn't applied to group children
715 setDistanceToTopRoundness(NO_ROUNDNESS);
Mady Mellorb0a82462016-04-30 17:31:02 -0700716 mNotificationParent.updateBackgroundForGroupState();
717 }
Selim Cinekdb167372016-11-17 15:41:17 -0800718 updateIconVisibilities();
Selim Cinek2871bef2017-11-22 08:40:00 -0800719 updateBackgroundClipping();
Selim Cinek34d93b02015-10-22 12:30:38 -0700720 }
721
722 @Override
Selim Cinek72109472016-01-15 16:33:22 -0800723 public boolean onTouchEvent(MotionEvent event) {
724 if (event.getActionMasked() != MotionEvent.ACTION_DOWN
725 || !isChildInGroup() || isGroupExpanded()) {
726 return super.onTouchEvent(event);
727 } else {
728 return false;
729 }
730 }
731
732 @Override
Mady Mellorf0625802016-02-11 18:03:48 -0800733 protected boolean handleSlideBack() {
Mady Mellor95d743c2017-01-10 12:05:27 -0800734 if (mMenuRow != null && mMenuRow.isMenuVisible()) {
Mady Mellorf0625802016-02-11 18:03:48 -0800735 animateTranslateNotification(0 /* targetLeft */);
736 return true;
737 }
738 return false;
739 }
740
741 @Override
Selim Cinek34d93b02015-10-22 12:30:38 -0700742 protected boolean shouldHideBackground() {
743 return super.shouldHideBackground() || mShowNoBackground;
Selim Cinek263398f2015-10-21 17:40:23 -0700744 }
745
746 @Override
747 public boolean isSummaryWithChildren() {
748 return mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100749 }
750
751 @Override
752 public boolean areChildrenExpanded() {
753 return mChildrenExpanded;
754 }
755
756 public List<ExpandableNotificationRow> getNotificationChildren() {
757 return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren();
758 }
759
Selim Cinekeef84282015-10-30 16:28:00 -0700760 public int getNumberOfNotificationChildren() {
761 if (mChildrenContainer == null) {
762 return 0;
763 }
764 return mChildrenContainer.getNotificationChildren().size();
765 }
766
Selim Cinekb5605e52015-02-20 18:21:41 +0100767 /**
768 * Apply the order given in the list to the children.
769 *
770 * @param childOrder the new list order
Selim Cineka7d4f822016-12-06 14:34:47 -0800771 * @param visualStabilityManager
772 * @param callback the callback to invoked in case it is not allowed
Selim Cinekb5605e52015-02-20 18:21:41 +0100773 * @return whether the list order has changed
774 */
Selim Cineka7d4f822016-12-06 14:34:47 -0800775 public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder,
776 VisualStabilityManager visualStabilityManager,
777 VisualStabilityManager.Callback callback) {
778 return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder,
779 visualStabilityManager, callback);
Selim Cinekb5605e52015-02-20 18:21:41 +0100780 }
781
Selim Cinekc25989e2018-02-16 16:42:14 -0800782 public void getChildrenStates(StackScrollState resultState,
783 AmbientState ambientState) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700784 if (mIsSummaryWithChildren) {
Selim Cinekbbcebde2016-11-09 18:28:20 -0800785 ExpandableViewState parentState = resultState.getViewStateForView(this);
Selim Cinekc25989e2018-02-16 16:42:14 -0800786 mChildrenContainer.getState(resultState, parentState, ambientState);
Selim Cinekb5605e52015-02-20 18:21:41 +0100787 }
788 }
789
790 public void applyChildrenState(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700791 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100792 mChildrenContainer.applyState(state);
793 }
794 }
795
796 public void prepareExpansionChanged(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700797 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100798 mChildrenContainer.prepareExpansionChanged(state);
799 }
800 }
801
Selim Cinek0cfbef42016-11-09 19:06:36 -0800802 public void startChildAnimation(StackScrollState finalState, AnimationProperties properties) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700803 if (mIsSummaryWithChildren) {
Selim Cinek0cfbef42016-11-09 19:06:36 -0800804 mChildrenContainer.startAnimationToState(finalState, properties);
Selim Cinekb5605e52015-02-20 18:21:41 +0100805 }
806 }
807
808 public ExpandableNotificationRow getViewAtPosition(float y) {
Selim Cinek43d30f02016-03-04 10:51:32 -0800809 if (!mIsSummaryWithChildren || !mChildrenExpanded) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100810 return this;
811 } else {
812 ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y);
813 return view == null ? this : view;
814 }
815 }
816
Selim Cinekab29aeb2015-02-20 18:18:32 +0100817 public NotificationGuts getGuts() {
818 return mGuts;
819 }
820
Selim Cinek684a4422015-04-15 16:18:39 -0700821 /**
822 * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this
823 * the notification will be rendered on top of the screen.
824 *
825 * @param pinned whether it is pinned
826 */
827 public void setPinned(boolean pinned) {
Selim Cinekdef35a82016-05-03 15:52:51 -0700828 int intrinsicHeight = getIntrinsicHeight();
Selim Cinek5cf1d052017-06-01 17:36:46 -0700829 boolean wasAboveShelf = isAboveShelf();
Selim Cinek684a4422015-04-15 16:18:39 -0700830 mIsPinned = pinned;
Selim Cinekdef35a82016-05-03 15:52:51 -0700831 if (intrinsicHeight != getIntrinsicHeight()) {
Selim Cinekbb42b7d2016-08-10 13:02:38 -0700832 notifyHeightChanged(false /* needsAnimation */);
Selim Cinekdef35a82016-05-03 15:52:51 -0700833 }
Selim Cinek31aada42015-12-18 17:51:15 -0800834 if (pinned) {
835 setIconAnimationRunning(true);
836 mExpandedWhenPinned = false;
837 } else if (mExpandedWhenPinned) {
838 setUserExpanded(true);
839 }
Selim Cinek98713a42015-09-21 15:47:20 +0200840 setChronometerRunning(mLastChronometerRunning);
Selim Cinek5cf1d052017-06-01 17:36:46 -0700841 if (isAboveShelf() != wasAboveShelf) {
842 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
843 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700844 }
845
Selim Cinek29aab962018-02-27 17:05:45 -0800846 @Override
Selim Cinek684a4422015-04-15 16:18:39 -0700847 public boolean isPinned() {
848 return mIsPinned;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700849 }
850
Selim Cinekd127d792016-11-01 19:11:41 -0700851 @Override
852 public int getPinnedHeadsUpHeight() {
853 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
854 }
855
Selim Cinek31aada42015-12-18 17:51:15 -0800856 /**
857 * @param atLeastMinHeight should the value returned be at least the minimum height.
858 * Used to avoid cyclic calls
859 * @return the height of the heads up notification when pinned
860 */
Selim Cinekd127d792016-11-01 19:11:41 -0700861 private int getPinnedHeadsUpHeight(boolean atLeastMinHeight) {
Selim Cinek77019c72015-12-09 10:18:02 -0800862 if (mIsSummaryWithChildren) {
863 return mChildrenContainer.getIntrinsicHeight();
864 }
Selim Cinek31aada42015-12-18 17:51:15 -0800865 if(mExpandedWhenPinned) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800866 return Math.max(getMaxExpandHeight(), getHeadsUpHeight());
Selim Cinek31aada42015-12-18 17:51:15 -0800867 } else if (atLeastMinHeight) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800868 return Math.max(getCollapsedHeight(), getHeadsUpHeight());
Selim Cinek31aada42015-12-18 17:51:15 -0800869 } else {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800870 return getHeadsUpHeight();
Selim Cinek31aada42015-12-18 17:51:15 -0800871 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700872 }
873
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700874 /**
875 * Mark whether this notification was just clicked, i.e. the user has just clicked this
876 * notification in this frame.
877 */
878 public void setJustClicked(boolean justClicked) {
879 mJustClicked = justClicked;
880 }
881
882 /**
883 * @return true if this notification has been clicked in this frame, false otherwise
884 */
885 public boolean wasJustClicked() {
886 return mJustClicked;
887 }
888
Selim Cinek98713a42015-09-21 15:47:20 +0200889 public void setChronometerRunning(boolean running) {
890 mLastChronometerRunning = running;
891 setChronometerRunning(running, mPrivateLayout);
892 setChronometerRunning(running, mPublicLayout);
893 if (mChildrenContainer != null) {
894 List<ExpandableNotificationRow> notificationChildren =
895 mChildrenContainer.getNotificationChildren();
896 for (int i = 0; i < notificationChildren.size(); i++) {
897 ExpandableNotificationRow child = notificationChildren.get(i);
898 child.setChronometerRunning(running);
899 }
900 }
901 }
902
903 private void setChronometerRunning(boolean running, NotificationContentView layout) {
904 if (layout != null) {
905 running = running || isPinned();
906 View contractedChild = layout.getContractedChild();
907 View expandedChild = layout.getExpandedChild();
908 View headsUpChild = layout.getHeadsUpChild();
909 setChronometerRunningForChild(running, contractedChild);
910 setChronometerRunningForChild(running, expandedChild);
911 setChronometerRunningForChild(running, headsUpChild);
912 }
913 }
914
915 private void setChronometerRunningForChild(boolean running, View child) {
916 if (child != null) {
917 View chronometer = child.findViewById(com.android.internal.R.id.chronometer);
918 if (chronometer instanceof Chronometer) {
919 ((Chronometer) chronometer).setStarted(running);
920 }
921 }
922 }
923
Selim Cinekea4bef72015-12-02 15:51:10 -0800924 public NotificationHeaderView getNotificationHeader() {
Mady Mellorb0a82462016-04-30 17:31:02 -0700925 if (mIsSummaryWithChildren) {
926 return mChildrenContainer.getHeaderView();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700927 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800928 return mPrivateLayout.getNotificationHeader();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700929 }
930
Selim Cinek414ad332017-02-24 19:06:12 -0800931 /**
932 * @return the currently visible notification header. This can be different from
933 * {@link #getNotificationHeader()} in case it is a low-priority group.
934 */
935 public NotificationHeaderView getVisibleNotificationHeader() {
Selim Cinek0b9cf462017-12-07 16:31:03 -0800936 if (mIsSummaryWithChildren && !shouldShowPublic()) {
Selim Cinek414ad332017-02-24 19:06:12 -0800937 return mChildrenContainer.getVisibleHeader();
Selim Cinek34eda5e2016-02-18 17:10:43 -0800938 }
939 return getShowingLayout().getVisibleNotificationHeader();
940 }
941
Selim Cinekb26afa32017-06-29 10:28:17 +0200942
943 /**
944 * @return the contracted notification header. This can be different from
945 * {@link #getNotificationHeader()} and also {@link #getVisibleNotificationHeader()} and only
946 * returns the contracted version.
947 */
948 public NotificationHeaderView getContractedNotificationHeader() {
949 if (mIsSummaryWithChildren) {
950 return mChildrenContainer.getHeaderView();
951 }
952 return mPrivateLayout.getContractedNotificationHeader();
953 }
954
Selim Cinek570981d2015-12-01 11:37:01 -0800955 public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) {
956 mOnExpandClickListener = onExpandClickListener;
957 }
958
Geoffrey Pitsch409db272017-08-28 14:51:52 +0000959 public void setLongPressListener(LongPressListener longPressListener) {
960 mLongPressListener = longPressListener;
961 }
962
Selim Cinekddf1b392016-05-27 16:33:10 -0700963 @Override
964 public void setOnClickListener(@Nullable OnClickListener l) {
965 super.setOnClickListener(l);
966 mOnClickListener = l;
967 updateClickAndFocus();
968 }
969
970 private void updateClickAndFocus() {
971 boolean normalChild = !isChildInGroup() || isGroupExpanded();
972 boolean clickable = mOnClickListener != null && normalChild;
973 if (isFocusable() != normalChild) {
974 setFocusable(normalChild);
975 }
976 if (isClickable() != clickable) {
977 setClickable(clickable);
978 }
979 }
980
Selim Cinek31aada42015-12-18 17:51:15 -0800981 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
982 mHeadsUpManager = headsUpManager;
983 }
984
Mady Mellor87d79452017-01-10 11:52:52 -0800985 public void setGutsView(MenuItem item) {
Mady Mellor95d743c2017-01-10 12:05:27 -0800986 if (mGuts != null && item.getGutsView() instanceof GutsContent) {
987 ((GutsContent) item.getGutsView()).setGutsParent(mGuts);
988 mGuts.setGutsContent((GutsContent) item.getGutsView());
Mady Mellor87d79452017-01-10 11:52:52 -0800989 }
990 }
991
Mady Mellor95d743c2017-01-10 12:05:27 -0800992 @Override
993 protected void onAttachedToWindow() {
994 super.onAttachedToWindow();
995 Dependency.get(PluginManager.class).addPluginListener(this,
996 NotificationMenuRowPlugin.class, false /* Allow multiple */);
997 }
998
999 @Override
1000 protected void onDetachedFromWindow() {
1001 super.onDetachedFromWindow();
1002 Dependency.get(PluginManager.class).removePluginListener(this);
1003 }
1004
1005 @Override
1006 public void onPluginConnected(NotificationMenuRowPlugin plugin, Context pluginContext) {
1007 boolean existed = mMenuRow.getMenuView() != null;
1008 if (existed) {
1009 removeView(mMenuRow.getMenuView());
1010 }
1011 mMenuRow = plugin;
1012 if (mMenuRow.useDefaultMenuItems()) {
Mady Mellor4c197602017-04-10 17:57:52 -07001013 ArrayList<MenuItem> items = new ArrayList<>();
1014 items.add(NotificationMenuRow.createInfoItem(mContext));
1015 items.add(NotificationMenuRow.createSnoozeItem(mContext));
Julia Reynoldsb5867452018-02-28 16:31:35 -05001016 items.add(NotificationMenuRow.createAppOpsItem(mContext));
Mady Mellor4c197602017-04-10 17:57:52 -07001017 mMenuRow.setMenuItems(items);
Mady Mellor95d743c2017-01-10 12:05:27 -08001018 }
1019 if (existed) {
1020 createMenu();
1021 }
1022 }
1023
1024 @Override
1025 public void onPluginDisconnected(NotificationMenuRowPlugin plugin) {
1026 boolean existed = mMenuRow.getMenuView() != null;
1027 mMenuRow = new NotificationMenuRow(mContext); // Back to default
1028 if (existed) {
1029 createMenu();
1030 }
1031 }
1032
1033 public NotificationMenuRowPlugin createMenu() {
1034 if (mMenuRow.getMenuView() == null) {
Mady Mellor4ab28202017-06-06 11:42:50 -07001035 mMenuRow.createMenu(this, mStatusBarNotification);
Mady Mellor95d743c2017-01-10 12:05:27 -08001036 mMenuRow.setAppName(mAppName);
1037 FrameLayout.LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
1038 LayoutParams.MATCH_PARENT);
1039 addView(mMenuRow.getMenuView(), MENU_VIEW_INDEX, lp);
1040 }
1041 return mMenuRow;
1042 }
1043
Mady Mellor95d743c2017-01-10 12:05:27 -08001044 public NotificationMenuRowPlugin getProvider() {
1045 return mMenuRow;
1046 }
1047
Anthony Chen9fe1ee72017-04-07 13:53:37 -07001048 @Override
Selim Cinek1a48bab2017-02-17 19:38:40 -08001049 public void onDensityOrFontScaleChanged() {
Anthony Chen9fe1ee72017-04-07 13:53:37 -07001050 super.onDensityOrFontScaleChanged();
Selim Cinek01af3342016-02-09 19:25:31 -08001051 initDimens();
Anthony Chenad4d1582017-04-10 16:07:58 -07001052 initBackground();
Selim Cinek817abe72017-05-24 11:08:55 -07001053 // Let's update our childrencontainer. This is intentionally not guarded with
1054 // mIsSummaryWithChildren since we might have had children but not anymore.
1055 if (mChildrenContainer != null) {
1056 mChildrenContainer.reInflateViews(mExpandClickListener, mEntry.notification);
Selim Cinek01af3342016-02-09 19:25:31 -08001057 }
1058 if (mGuts != null) {
1059 View oldGuts = mGuts;
1060 int index = indexOfChild(oldGuts);
1061 removeView(oldGuts);
1062 mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate(
1063 R.layout.notification_guts, this, false);
1064 mGuts.setVisibility(oldGuts.getVisibility());
1065 addView(mGuts, index);
1066 }
Mady Mellor95d743c2017-01-10 12:05:27 -08001067 View oldMenu = mMenuRow.getMenuView();
1068 if (oldMenu != null) {
Mady Mellor761cde12017-01-10 11:36:39 -08001069 int menuIndex = indexOfChild(oldMenu);
1070 removeView(oldMenu);
Mady Mellor4ab28202017-06-06 11:42:50 -07001071 mMenuRow.createMenu(ExpandableNotificationRow.this, mStatusBarNotification);
Mady Mellor761cde12017-01-10 11:36:39 -08001072 mMenuRow.setAppName(mAppName);
Mady Mellor95d743c2017-01-10 12:05:27 -08001073 addView(mMenuRow.getMenuView(), menuIndex);
Mady Mellor4b80b102016-01-22 08:03:58 -08001074 }
Adrian Rooseb434ff2017-01-11 11:18:48 -08001075 for (NotificationContentView l : mLayouts) {
Selim Cinek9b49f6d2017-11-13 18:19:35 -08001076 l.initView();
Adrian Rooseb434ff2017-01-11 11:18:48 -08001077 l.reInflateViews();
1078 }
Selim Cinek1a48bab2017-02-17 19:38:40 -08001079 mNotificationInflater.onDensityOrFontScaleChanged();
1080 onNotificationUpdated();
Selim Cinek01af3342016-02-09 19:25:31 -08001081 }
1082
Mady Mellor9d03a522017-04-04 18:45:30 -07001083 @Override
1084 public void onConfigurationChanged(Configuration newConfig) {
1085 if (mMenuRow.getMenuView() != null) {
1086 mMenuRow.onConfigurationChanged();
1087 }
1088 }
1089
Selim Cinekc3179332016-03-04 14:44:56 -08001090 public void setContentBackground(int customBackgroundColor, boolean animate,
1091 NotificationContentView notificationContentView) {
1092 if (getShowingLayout() == notificationContentView) {
1093 setTintColor(customBackgroundColor, animate);
1094 }
1095 }
1096
Kenny Guy14d035c2018-05-02 19:10:36 +01001097 @Override
1098 protected void setBackgroundTintColor(int color) {
1099 super.setBackgroundTintColor(color);
1100 NotificationContentView view = getShowingLayout();
1101 if (view != null) {
1102 view.setBackgroundTintColor(color);
1103 }
1104 }
1105
Adrian Roos0bd8a4b2016-03-14 16:21:44 -07001106 public void closeRemoteInput() {
Adrian Rooseb434ff2017-01-11 11:18:48 -08001107 for (NotificationContentView l : mLayouts) {
1108 l.closeRemoteInput();
1109 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -07001110 }
1111
Selim Cinekc897bd32016-03-18 17:32:31 -07001112 /**
1113 * Set by how much the single line view should be indented.
1114 */
1115 public void setSingleLineWidthIndention(int indention) {
1116 mPrivateLayout.setSingleLineWidthIndention(indention);
1117 }
1118
1119 public int getNotificationColor() {
Selim Cinek4bb59342016-04-08 19:29:35 -07001120 return mNotificationColor;
1121 }
1122
1123 private void updateNotificationColor() {
1124 mNotificationColor = NotificationColorUtil.resolveContrastColor(mContext,
Selim Cinekac5f0272017-05-02 16:05:41 -07001125 getStatusBarNotification().getNotification().color,
1126 getBackgroundColorWithoutTint());
Adrian Roos6f6e1592017-05-02 16:22:53 -07001127 mNotificationColorAmbient = NotificationColorUtil.resolveAmbientColor(mContext,
1128 getStatusBarNotification().getNotification().color);
Selim Cinekc897bd32016-03-18 17:32:31 -07001129 }
1130
1131 public HybridNotificationView getSingleLineView() {
1132 return mPrivateLayout.getSingleLineView();
1133 }
1134
Adrian Roos6f6e1592017-05-02 16:22:53 -07001135 public HybridNotificationView getAmbientSingleLineView() {
1136 return getShowingLayout().getAmbientSingleLineChild();
1137 }
1138
Selim Cinekf07d0622016-03-21 19:52:52 -07001139 public boolean isOnKeyguard() {
1140 return mOnKeyguard;
1141 }
1142
Selim Cinekc1e389d2016-04-07 11:02:57 -07001143 public void removeAllChildren() {
1144 List<ExpandableNotificationRow> notificationChildren
1145 = mChildrenContainer.getNotificationChildren();
1146 ArrayList<ExpandableNotificationRow> clonedList = new ArrayList<>(notificationChildren);
1147 for (int i = 0; i < clonedList.size(); i++) {
1148 ExpandableNotificationRow row = clonedList.get(i);
Selim Cinek3f19f602016-05-02 18:01:56 -07001149 if (row.keepInParent()) {
1150 continue;
1151 }
Selim Cinekc1e389d2016-04-07 11:02:57 -07001152 mChildrenContainer.removeNotification(row);
Selim Cinekc1e389d2016-04-07 11:02:57 -07001153 row.setIsChildInGroup(false, null);
1154 }
1155 onChildrenCountChanged();
1156 }
1157
Selim Cinek1b2a05e2016-04-28 14:20:39 -07001158 public void setForceUnlocked(boolean forceUnlocked) {
1159 mForceUnlocked = forceUnlocked;
1160 if (mIsSummaryWithChildren) {
1161 List<ExpandableNotificationRow> notificationChildren = getNotificationChildren();
1162 for (ExpandableNotificationRow child : notificationChildren) {
1163 child.setForceUnlocked(forceUnlocked);
1164 }
1165 }
1166 }
1167
Selim Cinekd03518c2018-03-15 12:13:51 -07001168 public void setDismissed(boolean fromAccessibility) {
Rohan Shahc6990a02018-03-23 17:24:17 -07001169 setLongPressListener(null);
Selim Cinekd03518c2018-03-15 12:13:51 -07001170 mDismissed = true;
Selim Cineke9bad242016-06-15 11:46:37 -07001171 mGroupParentWhenDismissed = mNotificationParent;
1172 mRefocusOnDismiss = fromAccessibility;
1173 mChildAfterViewWhenDismissed = null;
Selim Cinekd03518c2018-03-15 12:13:51 -07001174 mEntry.icon.setDismissed();
Selim Cineke9bad242016-06-15 11:46:37 -07001175 if (isChildInGroup()) {
1176 List<ExpandableNotificationRow> notificationChildren =
1177 mNotificationParent.getNotificationChildren();
1178 int i = notificationChildren.indexOf(this);
1179 if (i != -1 && i < notificationChildren.size() - 1) {
1180 mChildAfterViewWhenDismissed = notificationChildren.get(i + 1);
1181 }
1182 }
Selim Cinek3f19f602016-05-02 18:01:56 -07001183 }
1184
1185 public boolean isDismissed() {
1186 return mDismissed;
1187 }
1188
1189 public boolean keepInParent() {
1190 return mKeepInParent;
1191 }
1192
1193 public void setKeepInParent(boolean keepInParent) {
1194 mKeepInParent = keepInParent;
1195 }
1196
Selim Cinekd9b7dd42017-11-10 17:53:47 -08001197 @Override
Selim Cinek3f19f602016-05-02 18:01:56 -07001198 public boolean isRemoved() {
1199 return mRemoved;
1200 }
1201
Adrian Roosd009ab12016-05-20 17:58:53 -07001202 public void setRemoved() {
1203 mRemoved = true;
Selim Cinekef8c2252017-02-10 14:52:18 -08001204 mTranslationWhenRemoved = getTranslationY();
1205 mWasChildInGroupWhenRemoved = isChildInGroup();
1206 if (isChildInGroup()) {
1207 mTranslationWhenRemoved += getNotificationParent().getTranslationY();
1208 }
Adrian Roosd009ab12016-05-20 17:58:53 -07001209 mPrivateLayout.setRemoved();
Selim Cinek3f19f602016-05-02 18:01:56 -07001210 }
1211
Selim Cinekef8c2252017-02-10 14:52:18 -08001212 public boolean wasChildInGroupWhenRemoved() {
1213 return mWasChildInGroupWhenRemoved;
1214 }
1215
1216 public float getTranslationWhenRemoved() {
1217 return mTranslationWhenRemoved;
1218 }
1219
Selim Cinekd1395642016-04-28 12:22:42 -07001220 public NotificationChildrenContainer getChildrenContainer() {
1221 return mChildrenContainer;
1222 }
1223
Selim Cinekcafa87f2016-10-26 17:00:17 -07001224 public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) {
Selim Cinek5cf1d052017-06-01 17:36:46 -07001225 boolean wasAboveShelf = isAboveShelf();
Selim Cinek8875de12018-03-22 10:14:32 -07001226 boolean changed = headsUpAnimatingAway != mHeadsupDisappearRunning;
Selim Cinekcafa87f2016-10-26 17:00:17 -07001227 mHeadsupDisappearRunning = headsUpAnimatingAway;
1228 mPrivateLayout.setHeadsUpAnimatingAway(headsUpAnimatingAway);
Selim Cinek8875de12018-03-22 10:14:32 -07001229 if (changed && mHeadsUpAnimatingAwayListener != null) {
1230 mHeadsUpAnimatingAwayListener.accept(headsUpAnimatingAway);
1231 }
Selim Cinek5cf1d052017-06-01 17:36:46 -07001232 if (isAboveShelf() != wasAboveShelf) {
1233 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
1234 }
Selim Cinekcafa87f2016-10-26 17:00:17 -07001235 }
1236
Selim Cinek8875de12018-03-22 10:14:32 -07001237 public void setHeadsUpAnimatingAwayListener(Consumer<Boolean> listener) {
1238 mHeadsUpAnimatingAwayListener = listener;
1239 }
1240
Selim Cinekcafa87f2016-10-26 17:00:17 -07001241 /**
1242 * @return if the view was just heads upped and is now animating away. During such a time the
1243 * layout needs to be kept consistent
1244 */
Selim Cinek29aab962018-02-27 17:05:45 -08001245 @Override
Selim Cinekcafa87f2016-10-26 17:00:17 -07001246 public boolean isHeadsUpAnimatingAway() {
1247 return mHeadsupDisappearRunning;
Selim Cinek73cf02a2016-06-17 13:08:00 -07001248 }
1249
Selim Cineke9bad242016-06-15 11:46:37 -07001250 public View getChildAfterViewWhenDismissed() {
1251 return mChildAfterViewWhenDismissed;
1252 }
1253
1254 public View getGroupParentWhenDismissed() {
1255 return mGroupParentWhenDismissed;
1256 }
1257
Rohan Shah524cf7b2018-03-15 14:40:02 -07001258 /**
1259 * Dismisses the notification with the option of showing the blocking helper in-place if we have
1260 * a negative user sentiment.
1261 *
1262 * @param fromAccessibility whether this dismiss is coming from an accessibility action
1263 * @return whether a blocking helper is shown in this row
1264 */
1265 public boolean performDismissWithBlockingHelper(boolean fromAccessibility) {
1266 NotificationBlockingHelperManager manager =
1267 Dependency.get(NotificationBlockingHelperManager.class);
1268 boolean isBlockingHelperShown = manager.perhapsShowBlockingHelper(this, mMenuRow);
1269
Rohan Shahda5dcdd2018-04-27 17:21:50 -07001270 Dependency.get(MetricsLogger.class).count(NotificationCounters.NOTIFICATION_DISMISSED, 1);
1271
Rohan Shah524cf7b2018-03-15 14:40:02 -07001272 // Continue with dismiss since we don't want the blocking helper to be directly associated
1273 // with a certain notification.
1274 performDismiss(fromAccessibility);
1275 return isBlockingHelperShown;
1276 }
1277
yoshiki iguchi85ccbbc2018-01-22 12:33:21 +09001278 public void performDismiss(boolean fromAccessibility) {
Rohan Shah524cf7b2018-03-15 14:40:02 -07001279 if (isOnlyChildInGroup()) {
yoshiki iguchi85ccbbc2018-01-22 12:33:21 +09001280 ExpandableNotificationRow groupSummary =
1281 mGroupManager.getLogicalGroupSummary(getStatusBarNotification());
1282 if (groupSummary.isClearable()) {
Rohan Shah524cf7b2018-03-15 14:40:02 -07001283 // If this is the only child in the group, dismiss the group, but don't try to show
1284 // the blocking helper affordance!
yoshiki iguchi85ccbbc2018-01-22 12:33:21 +09001285 groupSummary.performDismiss(fromAccessibility);
1286 }
1287 }
Selim Cinekd03518c2018-03-15 12:13:51 -07001288 setDismissed(fromAccessibility);
yoshiki iguchi85ccbbc2018-01-22 12:33:21 +09001289 if (isClearable()) {
1290 if (mOnDismissRunnable != null) {
1291 mOnDismissRunnable.run();
1292 }
Selim Cineke9079112016-12-14 14:41:01 -08001293 }
Selim Cinek9e624e72016-07-20 13:46:49 -07001294 }
1295
Rohan Shah524cf7b2018-03-15 14:40:02 -07001296 public void setBlockingHelperShowing(boolean isBlockingHelperShowing) {
1297 mIsBlockingHelperShowing = isBlockingHelperShowing;
1298 }
1299
1300 public boolean isBlockingHelperShowing() {
1301 return mIsBlockingHelperShowing;
1302 }
1303
Selim Cineke9079112016-12-14 14:41:01 -08001304 public void setOnDismissRunnable(Runnable onDismissRunnable) {
1305 mOnDismissRunnable = onDismissRunnable;
Selim Cinek9e624e72016-07-20 13:46:49 -07001306 }
1307
Selim Cinek281c2022016-10-13 19:14:43 -07001308 public View getNotificationIcon() {
Selim Cinek414ad332017-02-24 19:06:12 -08001309 NotificationHeaderView notificationHeader = getVisibleNotificationHeader();
Selim Cinek281c2022016-10-13 19:14:43 -07001310 if (notificationHeader != null) {
1311 return notificationHeader.getIcon();
1312 }
1313 return null;
1314 }
1315
1316 /**
1317 * @return whether the notification is currently showing a view with an icon.
1318 */
1319 public boolean isShowingIcon() {
Mady Mellor434180c2017-02-13 11:29:42 -08001320 if (areGutsExposed()) {
1321 return false;
1322 }
Selim Cinek2ffa02f2017-03-06 15:56:37 -08001323 return getVisibleNotificationHeader() != null;
Selim Cinek281c2022016-10-13 19:14:43 -07001324 }
1325
Selim Cinek0242fbb2016-10-19 13:38:32 -07001326 /**
1327 * Set how much this notification is transformed into an icon.
1328 *
Selim Cinek2b549f42016-11-22 16:38:51 -08001329 * @param contentTransformationAmount A value from 0 to 1 indicating how much we are transformed
1330 * to the content away
Selim Cinek875a3a12016-11-18 17:52:16 -08001331 * @param isLastChild is this the last child in the list. If true, then the transformation is
1332 * different since it's content fades out.
Selim Cinek0242fbb2016-10-19 13:38:32 -07001333 */
Selim Cinek2b549f42016-11-22 16:38:51 -08001334 public void setContentTransformationAmount(float contentTransformationAmount,
1335 boolean isLastChild) {
Selim Cinek875a3a12016-11-18 17:52:16 -08001336 boolean changeTransformation = isLastChild != mIsLastChild;
Selim Cinek2b549f42016-11-22 16:38:51 -08001337 changeTransformation |= mContentTransformationAmount != contentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001338 mIsLastChild = isLastChild;
Selim Cinek2b549f42016-11-22 16:38:51 -08001339 mContentTransformationAmount = contentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001340 if (changeTransformation) {
1341 updateContentTransformation();
Selim Cinek2b549f42016-11-22 16:38:51 -08001342 }
1343 }
1344
1345 /**
1346 * Set the icons to be visible of this notification.
1347 */
1348 public void setIconsVisible(boolean iconsVisible) {
1349 if (iconsVisible != mIconsVisible) {
1350 mIconsVisible = iconsVisible;
1351 updateIconVisibilities();
Selim Cinek0242fbb2016-10-19 13:38:32 -07001352 }
1353 }
1354
Selim Cinekdb167372016-11-17 15:41:17 -08001355 @Override
1356 protected void onBelowSpeedBumpChanged() {
1357 updateIconVisibilities();
1358 }
1359
Selim Cinek875a3a12016-11-18 17:52:16 -08001360 private void updateContentTransformation() {
Selim Cinek2627d722018-01-19 12:16:49 -08001361 if (mExpandAnimationRunning) {
1362 return;
1363 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001364 float contentAlpha;
Selim Cinek2b549f42016-11-22 16:38:51 -08001365 float translationY = -mContentTransformationAmount * mIconTransformContentShift;
Selim Cinek875a3a12016-11-18 17:52:16 -08001366 if (mIsLastChild) {
Selim Cinek2b549f42016-11-22 16:38:51 -08001367 contentAlpha = 1.0f - mContentTransformationAmount;
Selim Cinek875a3a12016-11-18 17:52:16 -08001368 contentAlpha = Math.min(contentAlpha / 0.5f, 1.0f);
Selim Cinek0242fbb2016-10-19 13:38:32 -07001369 contentAlpha = Interpolators.ALPHA_OUT.getInterpolation(contentAlpha);
Selim Cinek875a3a12016-11-18 17:52:16 -08001370 translationY *= 0.4f;
1371 } else {
1372 contentAlpha = 1.0f;
1373 }
Adrian Rooseb434ff2017-01-11 11:18:48 -08001374 for (NotificationContentView l : mLayouts) {
1375 l.setAlpha(contentAlpha);
1376 l.setTranslationY(translationY);
1377 }
Selim Cinek875a3a12016-11-18 17:52:16 -08001378 if (mChildrenContainer != null) {
1379 mChildrenContainer.setAlpha(contentAlpha);
1380 mChildrenContainer.setTranslationY(translationY);
1381 // TODO: handle children fade out better
Selim Cinek0242fbb2016-10-19 13:38:32 -07001382 }
1383 }
1384
1385 private void updateIconVisibilities() {
Selim Cinek17e1b692016-12-02 18:19:11 -08001386 boolean visible = isChildInGroup()
1387 || (isBelowSpeedBump() && !NotificationShelf.SHOW_AMBIENT_ICONS)
1388 || mIconsVisible;
Adrian Rooseb434ff2017-01-11 11:18:48 -08001389 for (NotificationContentView l : mLayouts) {
1390 l.setIconsVisible(visible);
1391 }
Selim Cinekdb167372016-11-17 15:41:17 -08001392 if (mChildrenContainer != null) {
1393 mChildrenContainer.setIconsVisible(visible);
Selim Cinek0242fbb2016-10-19 13:38:32 -07001394 }
1395 }
1396
Selim Cinek875a3a12016-11-18 17:52:16 -08001397 /**
1398 * Get the relative top padding of a view relative to this view. This recursively walks up the
1399 * hierarchy and does the corresponding measuring.
1400 *
1401 * @param view the view to the the padding for. The requested view has to be a child of this
1402 * notification.
1403 * @return the toppadding
1404 */
1405 public int getRelativeTopPadding(View view) {
1406 int topPadding = 0;
1407 while (view.getParent() instanceof ViewGroup) {
1408 topPadding += view.getTop();
1409 view = (View) view.getParent();
1410 if (view instanceof ExpandableNotificationRow) {
1411 return topPadding;
1412 }
1413 }
1414 return topPadding;
1415 }
1416
Selim Cineka1d97902016-12-14 16:31:40 -08001417 public float getContentTranslation() {
1418 return mPrivateLayout.getTranslationY();
1419 }
1420
Selim Cinek6743c0b2017-01-18 18:24:01 -08001421 public void setIsLowPriority(boolean isLowPriority) {
1422 mIsLowPriority = isLowPriority;
1423 mPrivateLayout.setIsLowPriority(isLowPriority);
Selim Cinek1a48bab2017-02-17 19:38:40 -08001424 mNotificationInflater.setIsLowPriority(mIsLowPriority);
Selim Cinek6743c0b2017-01-18 18:24:01 -08001425 if (mChildrenContainer != null) {
1426 mChildrenContainer.setIsLowPriority(isLowPriority);
1427 }
1428 }
1429
Selim Cinek55a3e732017-05-25 18:30:10 -07001430
1431 public void setLowPriorityStateUpdated(boolean lowPriorityStateUpdated) {
1432 mLowPriorityStateUpdated = lowPriorityStateUpdated;
1433 }
1434
1435 public boolean hasLowPriorityStateUpdated() {
1436 return mLowPriorityStateUpdated;
1437 }
1438
Selim Cinek414ad332017-02-24 19:06:12 -08001439 public boolean isLowPriority() {
1440 return mIsLowPriority;
1441 }
1442
Selim Cinek7d1009b2017-01-25 15:28:28 -08001443 public void setUseIncreasedCollapsedHeight(boolean use) {
1444 mUseIncreasedCollapsedHeight = use;
Selim Cinek1a48bab2017-02-17 19:38:40 -08001445 mNotificationInflater.setUsesIncreasedHeight(use);
Selim Cinek7d1009b2017-01-25 15:28:28 -08001446 }
1447
Selim Cinek87ed69b2017-02-09 15:59:43 -08001448 public void setUseIncreasedHeadsUpHeight(boolean use) {
1449 mUseIncreasedHeadsUpHeight = use;
Selim Cinek1a48bab2017-02-17 19:38:40 -08001450 mNotificationInflater.setUsesIncreasedHeadsUpHeight(use);
1451 }
1452
1453 public void setRemoteViewClickHandler(RemoteViews.OnClickHandler remoteViewClickHandler) {
1454 mNotificationInflater.setRemoteViewClickHandler(remoteViewClickHandler);
Selim Cinek87ed69b2017-02-09 15:59:43 -08001455 }
1456
Selim Cinek5ba22542017-04-20 15:16:10 -07001457 public void setInflationCallback(InflationCallback callback) {
1458 mNotificationInflater.setInflationCallback(callback);
Selim Cinekc478f902017-02-22 20:55:44 -08001459 }
1460
Adrian Roos1a1ecfc2017-04-17 11:17:59 -07001461 public void setNeedsRedaction(boolean needsRedaction) {
1462 mNotificationInflater.setRedactAmbient(needsRedaction);
1463 }
1464
Selim Cinek5ba22542017-04-20 15:16:10 -07001465 @VisibleForTesting
1466 public NotificationInflater getNotificationInflater() {
1467 return mNotificationInflater;
1468 }
1469
Adrian Roos6f6e1592017-05-02 16:22:53 -07001470 public int getNotificationColorAmbient() {
1471 return mNotificationColorAmbient;
1472 }
1473
Chris Wren78403d72014-07-28 10:23:24 +01001474 public interface ExpansionLogger {
Anthony Chen6bf88a02017-04-10 14:41:44 -07001475 void logNotificationExpansion(String key, boolean userAction, boolean expanded);
Chris Wren78403d72014-07-28 10:23:24 +01001476 }
Selim Cinek1685e632014-04-08 02:27:49 +02001477
Chris Wren51c75102013-07-16 20:49:17 -04001478 public ExpandableNotificationRow(Context context, AttributeSet attrs) {
1479 super(context, attrs);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001480 mFalsingManager = FalsingManager.getInstance(context);
Selim Cinek1a48bab2017-02-17 19:38:40 -08001481 mNotificationInflater = new NotificationInflater(this);
Mady Mellor95d743c2017-01-10 12:05:27 -08001482 mMenuRow = new NotificationMenuRow(mContext);
Selim Cinek01af3342016-02-09 19:25:31 -08001483 initDimens();
1484 }
1485
1486 private void initDimens() {
Selim Cineke62255c2017-09-28 18:23:23 -07001487 mNotificationMinHeightLegacy = NotificationUtils.getFontScaledHeight(mContext,
1488 R.dimen.notification_min_height_legacy);
Selim Cinek9b49f6d2017-11-13 18:19:35 -08001489 mNotificationMinHeightBeforeP = NotificationUtils.getFontScaledHeight(mContext,
1490 R.dimen.notification_min_height_before_p);
Selim Cineke62255c2017-09-28 18:23:23 -07001491 mNotificationMinHeight = NotificationUtils.getFontScaledHeight(mContext,
1492 R.dimen.notification_min_height);
1493 mNotificationMinHeightLarge = NotificationUtils.getFontScaledHeight(mContext,
Selim Cinek87ed69b2017-02-09 15:59:43 -08001494 R.dimen.notification_min_height_increased);
Selim Cineke62255c2017-09-28 18:23:23 -07001495 mNotificationMaxHeight = NotificationUtils.getFontScaledHeight(mContext,
1496 R.dimen.notification_max_height);
1497 mNotificationAmbientHeight = NotificationUtils.getFontScaledHeight(mContext,
1498 R.dimen.notification_ambient_height);
1499 mMaxHeadsUpHeightLegacy = NotificationUtils.getFontScaledHeight(mContext,
Selim Cinek77019c72015-12-09 10:18:02 -08001500 R.dimen.notification_max_heads_up_height_legacy);
Selim Cinek9b49f6d2017-11-13 18:19:35 -08001501 mMaxHeadsUpHeightBeforeP = NotificationUtils.getFontScaledHeight(mContext,
1502 R.dimen.notification_max_heads_up_height_before_p);
Selim Cineke62255c2017-09-28 18:23:23 -07001503 mMaxHeadsUpHeight = NotificationUtils.getFontScaledHeight(mContext,
1504 R.dimen.notification_max_heads_up_height);
1505 mMaxHeadsUpHeightIncreased = NotificationUtils.getFontScaledHeight(mContext,
Selim Cinek87ed69b2017-02-09 15:59:43 -08001506 R.dimen.notification_max_heads_up_height_increased);
Anthony Chen6bf88a02017-04-10 14:41:44 -07001507
Anthony Chen7acbb772017-04-07 16:45:25 -07001508 Resources res = getResources();
1509 mIncreasedPaddingBetweenElements = res.getDimensionPixelSize(
1510 R.dimen.notification_divider_height_increased);
1511 mIconTransformContentShiftNoIcon = res.getDimensionPixelSize(
Selim Cinek0242fbb2016-10-19 13:38:32 -07001512 R.dimen.notification_icon_transform_content_shift);
Anthony Chen6bf88a02017-04-10 14:41:44 -07001513 mEnableNonGroupedNotificationExpand =
1514 res.getBoolean(R.bool.config_enableNonGroupedNotificationExpand);
1515 mShowGroupBackgroundWhenExpanded =
1516 res.getBoolean(R.bool.config_showGroupNotificationBgWhenExpanded);
Selim Cinekf619ffc2016-02-17 14:53:05 -08001517 }
1518
1519 /**
Christoph Studera7fe6312014-06-27 19:32:44 +02001520 * Resets this view so it can be re-used for an updated notification.
1521 */
1522 public void reset() {
Jorim Jaggiae441282014-08-01 02:45:18 +02001523 mShowingPublicInitialized = false;
Selim Cinek31094df2014-08-14 19:28:15 +02001524 onHeightReset();
Selim Cinek6e28a672014-09-05 14:43:28 +02001525 requestLayout();
Christoph Studera7fe6312014-06-27 19:32:44 +02001526 }
1527
Julia Reynoldsfc640012018-02-21 12:25:27 -05001528 public void showAppOpsIcons(ArraySet<Integer> activeOps) {
1529 if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() != null) {
1530 mChildrenContainer.getHeaderView().showAppOpsIcons(activeOps);
1531 }
1532 mPrivateLayout.showAppOpsIcons(activeOps);
1533 mPublicLayout.showAppOpsIcons(activeOps);
1534 }
1535
Julia Reynoldsb5867452018-02-28 16:31:35 -05001536 public View.OnClickListener getAppOpsOnClickListener() {
1537 return mOnAppOpsClickListener;
1538 }
1539
1540 protected void setAppOpsOnClickListener(ExpandableNotificationRow.OnAppOpsClickListener l) {
1541 mOnAppOpsClickListener = v -> {
1542 createMenu();
1543 MenuItem menuItem = getProvider().getAppOpsMenuItem(mContext);
1544 if (menuItem != null) {
1545 l.onClick(this, v.getWidth() / 2, v.getHeight() / 2, menuItem);
1546 }
1547 };
1548 }
1549
Jorim Jaggi251957d2014-04-09 04:24:09 +02001550 @Override
1551 protected void onFinishInflate() {
1552 super.onFinishInflate();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001553 mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic);
1554 mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded);
Adrian Rooseb434ff2017-01-11 11:18:48 -08001555 mLayouts = new NotificationContentView[] {mPrivateLayout, mPublicLayout};
1556
1557 for (NotificationContentView l : mLayouts) {
1558 l.setExpandClickListener(mExpandClickListener);
1559 l.setContainingNotification(this);
1560 }
Selim Cinekab29aeb2015-02-20 18:18:32 +01001561 mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub);
1562 mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() {
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001563 @Override
1564 public void onInflate(ViewStub stub, View inflated) {
1565 mGuts = (NotificationGuts) inflated;
1566 mGuts.setClipTopAmount(getClipTopAmount());
1567 mGuts.setActualHeight(getActualHeight());
Selim Cinekab29aeb2015-02-20 18:18:32 +01001568 mGutsStub = null;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001569 }
1570 });
Selim Cinekb5605e52015-02-20 18:21:41 +01001571 mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub);
1572 mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() {
1573
1574 @Override
1575 public void onInflate(ViewStub stub, View inflated) {
1576 mChildrenContainer = (NotificationChildrenContainer) inflated;
Selim Cinek6743c0b2017-01-18 18:24:01 -08001577 mChildrenContainer.setIsLowPriority(mIsLowPriority);
Selim Cinek414ad332017-02-24 19:06:12 -08001578 mChildrenContainer.setContainingNotification(ExpandableNotificationRow.this);
Selim Cinekc897bd32016-03-18 17:32:31 -07001579 mChildrenContainer.onNotificationUpdated();
Anthony Chen7acbb772017-04-07 16:45:25 -07001580
1581 if (mShouldTranslateContents) {
1582 mTranslateableViews.add(mChildrenContainer);
1583 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001584 }
1585 });
Mady Mellor4b80b102016-01-22 08:03:58 -08001586
Anthony Chen7acbb772017-04-07 16:45:25 -07001587 if (mShouldTranslateContents) {
1588 // Add the views that we translate to reveal the menu
1589 mTranslateableViews = new ArrayList<>();
1590 for (int i = 0; i < getChildCount(); i++) {
1591 mTranslateableViews.add(getChildAt(i));
1592 }
1593 // Remove views that don't translate
1594 mTranslateableViews.remove(mChildrenContainerStub);
1595 mTranslateableViews.remove(mGutsStub);
Mady Mellor4b80b102016-01-22 08:03:58 -08001596 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001597 }
1598
Geoffrey Pitsch409db272017-08-28 14:51:52 +00001599 private void doLongClickCallback() {
1600 doLongClickCallback(getWidth() / 2, getHeight() / 2);
1601 }
1602
1603 public void doLongClickCallback(int x, int y) {
1604 createMenu();
1605 MenuItem menuItem = getProvider().getLongpressMenuItem(mContext);
Mady Mellorb3a6aed2018-05-11 13:24:07 -07001606 doLongClickCallback(x, y, menuItem);
1607 }
1608
1609 private void doLongClickCallback(int x, int y, MenuItem menuItem) {
Geoffrey Pitsch409db272017-08-28 14:51:52 +00001610 if (mLongPressListener != null && menuItem != null) {
1611 mLongPressListener.onLongPress(this, x, y, menuItem);
1612 }
1613 }
1614
1615 @Override
1616 public boolean onKeyDown(int keyCode, KeyEvent event) {
1617 if (KeyEvent.isConfirmKey(keyCode)) {
1618 event.startTracking();
1619 return true;
1620 }
1621 return super.onKeyDown(keyCode, event);
1622 }
1623
1624 @Override
1625 public boolean onKeyUp(int keyCode, KeyEvent event) {
1626 if (KeyEvent.isConfirmKey(keyCode)) {
1627 if (!event.isCanceled()) {
1628 performClick();
1629 }
1630 return true;
1631 }
1632 return super.onKeyUp(keyCode, event);
1633 }
1634
1635 @Override
1636 public boolean onKeyLongPress(int keyCode, KeyEvent event) {
1637 if (KeyEvent.isConfirmKey(keyCode)) {
1638 doLongClickCallback();
1639 return true;
1640 }
1641 return false;
1642 }
1643
Mady Mellor4b80b102016-01-22 08:03:58 -08001644 public void resetTranslation() {
Mady Mellor32c638a2016-09-14 08:58:25 -07001645 if (mTranslateAnim != null) {
1646 mTranslateAnim.cancel();
1647 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001648
1649 if (!mShouldTranslateContents) {
1650 setTranslationX(0);
1651 } else if (mTranslateableViews != null) {
Mady Mellor4b80b102016-01-22 08:03:58 -08001652 for (int i = 0; i < mTranslateableViews.size(); i++) {
1653 mTranslateableViews.get(i).setTranslationX(0);
1654 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001655 invalidateOutline();
shawnlin4fbeac42018-04-30 20:32:40 +08001656 getEntry().expandedIcon.setScrollX(0);
Mady Mellor4b80b102016-01-22 08:03:58 -08001657 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001658
Mady Mellor95d743c2017-01-10 12:05:27 -08001659 mMenuRow.resetMenu();
Mady Mellor4b80b102016-01-22 08:03:58 -08001660 }
1661
Rohan Shah56eb0912018-05-10 21:49:04 -07001662 void onGutsOpened() {
1663 resetTranslation();
1664 updateContentAccessibilityImportanceForGuts(false /* isEnabled */);
1665 }
1666
1667 void onGutsClosed() {
1668 updateContentAccessibilityImportanceForGuts(true /* isEnabled */);
1669 }
1670
1671 /**
1672 * Updates whether all the non-guts content inside this row is important for accessibility.
1673 *
1674 * @param isEnabled whether the content views should be enabled for accessibility
1675 */
1676 private void updateContentAccessibilityImportanceForGuts(boolean isEnabled) {
1677 if (mChildrenContainer != null) {
1678 updateChildAccessibilityImportance(mChildrenContainer, isEnabled);
1679 }
1680 if (mLayouts != null) {
1681 for (View view : mLayouts) {
1682 updateChildAccessibilityImportance(view, isEnabled);
1683 }
1684 }
1685
1686 if (isEnabled) {
1687 this.requestAccessibilityFocus();
1688 }
1689 }
1690
1691 /**
1692 * Updates whether the given childView is important for accessibility based on
1693 * {@code isEnabled}.
1694 */
1695 private void updateChildAccessibilityImportance(View childView, boolean isEnabled) {
1696 childView.setImportantForAccessibility(isEnabled
1697 ? View.IMPORTANT_FOR_ACCESSIBILITY_AUTO
1698 : View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
1699 }
1700
Selim Cinekde4de0e2018-01-24 16:21:07 -08001701 public CharSequence getActiveRemoteInputText() {
1702 return mPrivateLayout.getActiveRemoteInputText();
1703 }
1704
Mady Mellor4b80b102016-01-22 08:03:58 -08001705 public void animateTranslateNotification(final float leftTarget) {
1706 if (mTranslateAnim != null) {
1707 mTranslateAnim.cancel();
1708 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001709 mTranslateAnim = getTranslateViewAnimator(leftTarget, null /* updateListener */);
Mady Mellor34958fa2016-02-23 09:52:17 -08001710 if (mTranslateAnim != null) {
1711 mTranslateAnim.start();
1712 }
1713 }
1714
1715 @Override
1716 public void setTranslation(float translationX) {
1717 if (areGutsExposed()) {
1718 // Don't translate if guts are showing.
1719 return;
1720 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001721 if (!mShouldTranslateContents) {
1722 setTranslationX(translationX);
1723 } else if (mTranslateableViews != null) {
1724 // Translate the group of views
1725 for (int i = 0; i < mTranslateableViews.size(); i++) {
1726 if (mTranslateableViews.get(i) != null) {
1727 mTranslateableViews.get(i).setTranslationX(translationX);
1728 }
Mady Mellor34958fa2016-02-23 09:52:17 -08001729 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001730 invalidateOutline();
Selim Cinek143672c2018-03-23 20:04:32 -07001731
1732 // In order to keep the shelf in sync with this swiping, we're simply translating
1733 // it's icon by the same amount. The translation is already being used for the normal
1734 // positioning, so we can use the scrollX instead.
1735 getEntry().expandedIcon.setScrollX((int) -translationX);
Mady Mellor34958fa2016-02-23 09:52:17 -08001736 }
Mady Mellor95d743c2017-01-10 12:05:27 -08001737 if (mMenuRow.getMenuView() != null) {
1738 mMenuRow.onTranslationUpdate(translationX);
Mady Mellor34958fa2016-02-23 09:52:17 -08001739 }
1740 }
1741
1742 @Override
1743 public float getTranslation() {
Anthony Chene04afcb2017-04-21 13:51:32 -07001744 if (!mShouldTranslateContents) {
Anthony Chen7acbb772017-04-07 16:45:25 -07001745 return getTranslationX();
1746 }
1747
Mady Mellor34958fa2016-02-23 09:52:17 -08001748 if (mTranslateableViews != null && mTranslateableViews.size() > 0) {
1749 // All of the views in the list should have same translation, just use first one.
1750 return mTranslateableViews.get(0).getTranslationX();
1751 }
Anthony Chen7acbb772017-04-07 16:45:25 -07001752
Mady Mellor34958fa2016-02-23 09:52:17 -08001753 return 0;
1754 }
1755
1756 public Animator getTranslateViewAnimator(final float leftTarget,
1757 AnimatorUpdateListener listener) {
Mady Mellor723f1f92016-03-13 15:54:06 -07001758 if (mTranslateAnim != null) {
1759 mTranslateAnim.cancel();
1760 }
Mady Mellor34958fa2016-02-23 09:52:17 -08001761 if (areGutsExposed()) {
1762 // No translation if guts are exposed.
1763 return null;
1764 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001765 final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(this, TRANSLATE_CONTENT,
1766 leftTarget);
1767 if (listener != null) {
1768 translateAnim.addUpdateListener(listener);
Mady Mellor4b80b102016-01-22 08:03:58 -08001769 }
Mady Mellorb0a82462016-04-30 17:31:02 -07001770 translateAnim.addListener(new AnimatorListenerAdapter() {
1771 boolean cancelled = false;
1772
1773 @Override
1774 public void onAnimationCancel(Animator anim) {
1775 cancelled = true;
1776 }
1777
1778 @Override
1779 public void onAnimationEnd(Animator anim) {
Mady Mellor95d743c2017-01-10 12:05:27 -08001780 if (!cancelled && leftTarget == 0) {
1781 mMenuRow.resetMenu();
Mady Mellorb0a82462016-04-30 17:31:02 -07001782 mTranslateAnim = null;
1783 }
1784 }
1785 });
1786 mTranslateAnim = translateAnim;
1787 return translateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -08001788 }
1789
Selim Cinekab29aeb2015-02-20 18:18:32 +01001790 public void inflateGuts() {
1791 if (mGuts == null) {
1792 mGutsStub.inflate();
1793 }
1794 }
1795
Selim Cinekda42d652015-12-04 15:51:16 -08001796 private void updateChildrenVisibility() {
Selim Cinek7fa385a2018-01-24 08:35:28 -08001797 boolean hideContentWhileLaunching = mExpandAnimationRunning && mGuts != null
1798 && mGuts.isExposed();
1799 mPrivateLayout.setVisibility(!shouldShowPublic() && !mIsSummaryWithChildren
1800 && !hideContentWhileLaunching ? VISIBLE : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -08001801 if (mChildrenContainer != null) {
Selim Cinek7fa385a2018-01-24 08:35:28 -08001802 mChildrenContainer.setVisibility(!shouldShowPublic() && mIsSummaryWithChildren
1803 && !hideContentWhileLaunching ? VISIBLE
Selim Cinekef5127e2015-12-21 16:55:58 -08001804 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -08001805 }
Selim Cinekda42d652015-12-04 15:51:16 -08001806 // The limits might have changed if the view suddenly became a group or vice versa
1807 updateLimits();
Selim Cinekb5605e52015-02-20 18:21:41 +01001808 }
1809
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001810 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08001811 public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
1812 if (super.onRequestSendAccessibilityEventInternal(child, event)) {
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001813 // Add a record for the entire layout since its content is somehow small.
1814 // The event comes from a leaf view that is interacted with.
1815 AccessibilityEvent record = AccessibilityEvent.obtain();
1816 onInitializeAccessibilityEvent(record);
1817 dispatchPopulateAccessibilityEvent(record);
1818 event.appendRecord(record);
1819 return true;
1820 }
1821 return false;
Jorim Jaggic5dc0d02014-04-15 15:42:55 +02001822 }
Chris Wren51c75102013-07-16 20:49:17 -04001823
John Spurlocke15452b2014-08-21 09:44:39 -04001824 @Override
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001825 public void setDark(boolean dark, boolean fade, long delay) {
1826 super.setDark(dark, fade, delay);
Lucas Dupincecc7c22017-09-12 16:02:45 -07001827 mDark = dark;
Adrian Roos28f90c72017-05-08 17:24:26 -07001828 if (!mIsHeadsUp) {
1829 // Only fade the showing view of the pulsing notification.
1830 fade = false;
1831 }
John Spurlocke15452b2014-08-21 09:44:39 -04001832 final NotificationContentView showing = getShowingLayout();
1833 if (showing != null) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001834 showing.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -04001835 }
Selim Cinek9c7712d2015-12-08 19:19:48 -08001836 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001837 mChildrenContainer.setDark(dark, fade, delay);
Selim Cinek9c7712d2015-12-08 19:19:48 -08001838 }
Selim Cineka7c69632017-06-07 15:51:29 -07001839 updateShelfIconColor();
John Spurlocke15452b2014-08-21 09:44:39 -04001840 }
1841
Selim Cinek2627d722018-01-19 12:16:49 -08001842 public void applyExpandAnimationParams(ExpandAnimationParameters params) {
1843 if (params == null) {
1844 return;
1845 }
Selim Cinek2627d722018-01-19 12:16:49 -08001846 float zProgress = Interpolators.FAST_OUT_SLOW_IN.getInterpolation(
1847 params.getProgress(0, 50));
1848 float translationZ = MathUtils.lerp(params.getStartTranslationZ(),
1849 mNotificationLaunchHeight,
1850 zProgress);
1851 setTranslationZ(translationZ);
Selim Cinekc25989e2018-02-16 16:42:14 -08001852 float extraWidthForClipping = params.getWidth() - getWidth()
1853 + MathUtils.lerp(0, mOutlineRadius * 2, params.getProgress());
1854 setExtraWidthForClipping(extraWidthForClipping);
1855 int top = params.getTop();
1856 float interpolation = Interpolators.FAST_OUT_SLOW_IN.getInterpolation(params.getProgress());
1857 int startClipTopAmount = params.getStartClipTopAmount();
1858 if (mNotificationParent != null) {
1859 top -= mNotificationParent.getTranslationY();
1860 mNotificationParent.setTranslationZ(translationZ);
1861 int parentStartClipTopAmount = params.getParentStartClipTopAmount();
1862 if (startClipTopAmount != 0) {
1863 int clipTopAmount = (int) MathUtils.lerp(parentStartClipTopAmount,
1864 parentStartClipTopAmount - startClipTopAmount,
1865 interpolation);
1866 mNotificationParent.setClipTopAmount(clipTopAmount);
1867 }
1868 mNotificationParent.setExtraWidthForClipping(extraWidthForClipping);
1869 mNotificationParent.setMinimumHeightForClipping(params.getHeight()
1870 + mNotificationParent.getActualHeight());
1871 } else if (startClipTopAmount != 0) {
1872 int clipTopAmount = (int) MathUtils.lerp(startClipTopAmount, 0, interpolation);
1873 setClipTopAmount(clipTopAmount);
1874 }
1875 setTranslationY(top);
Selim Cinek2627d722018-01-19 12:16:49 -08001876 setActualHeight(params.getHeight());
Selim Cinekc25989e2018-02-16 16:42:14 -08001877
Selim Cinek2627d722018-01-19 12:16:49 -08001878 mBackgroundNormal.setExpandAnimationParams(params);
1879 }
1880
1881 public void setExpandAnimationRunning(boolean expandAnimationRunning) {
Selim Cinekc25989e2018-02-16 16:42:14 -08001882 View contentView;
1883 if (mIsSummaryWithChildren) {
1884 contentView = mChildrenContainer;
1885 } else {
1886 contentView = getShowingLayout();
1887 }
1888 if (mGuts != null && mGuts.isExposed()) {
1889 contentView = mGuts;
1890 }
Selim Cinek2627d722018-01-19 12:16:49 -08001891 if (expandAnimationRunning) {
Selim Cinek2627d722018-01-19 12:16:49 -08001892 contentView.animate()
1893 .alpha(0f)
1894 .setDuration(ActivityLaunchAnimator.ANIMATION_DURATION_FADE_CONTENT)
1895 .setInterpolator(Interpolators.ALPHA_OUT);
1896 setAboveShelf(true);
1897 mExpandAnimationRunning = true;
1898 mNotificationViewState.cancelAnimations(this);
1899 mNotificationLaunchHeight = AmbientState.getNotificationLaunchHeight(getContext());
1900 } else {
1901 mExpandAnimationRunning = false;
1902 setAboveShelf(isAboveShelf());
Selim Cinek7fa385a2018-01-24 08:35:28 -08001903 if (mGuts != null) {
1904 mGuts.setAlpha(1.0f);
1905 }
Selim Cinekc25989e2018-02-16 16:42:14 -08001906 if (contentView != null) {
1907 contentView.setAlpha(1.0f);
1908 }
1909 setExtraWidthForClipping(0.0f);
1910 if (mNotificationParent != null) {
1911 mNotificationParent.setExtraWidthForClipping(0.0f);
1912 mNotificationParent.setMinimumHeightForClipping(0);
1913 }
1914 }
1915 if (mNotificationParent != null) {
1916 mNotificationParent.setChildIsExpanding(mExpandAnimationRunning);
Selim Cinek2627d722018-01-19 12:16:49 -08001917 }
Selim Cinek7fa385a2018-01-24 08:35:28 -08001918 updateChildrenVisibility();
Selim Cinek2627d722018-01-19 12:16:49 -08001919 updateClipping();
1920 mBackgroundNormal.setExpandAnimationRunning(expandAnimationRunning);
1921 }
1922
Selim Cinekc25989e2018-02-16 16:42:14 -08001923 private void setChildIsExpanding(boolean isExpanding) {
1924 mChildIsExpanding = isExpanding;
1925 }
1926
1927 @Override
1928 public boolean hasExpandingChild() {
1929 return mChildIsExpanding;
1930 }
1931
Selim Cinek2627d722018-01-19 12:16:49 -08001932 @Override
1933 protected boolean shouldClipToActualHeight() {
Selim Cinekc25989e2018-02-16 16:42:14 -08001934 return super.shouldClipToActualHeight() && !mExpandAnimationRunning && !mChildIsExpanding;
Selim Cinek2627d722018-01-19 12:16:49 -08001935 }
1936
1937 @Override
1938 public boolean isExpandAnimationRunning() {
1939 return mExpandAnimationRunning;
1940 }
1941
Lucas Dupincecc7c22017-09-12 16:02:45 -07001942 /**
1943 * Tap sounds should not be played when we're unlocking.
1944 * Doing so would cause audio collision and the system would feel unpolished.
1945 */
1946 @Override
1947 public boolean isSoundEffectsEnabled() {
1948 final boolean mute = mDark && mSecureStateProvider != null &&
1949 !mSecureStateProvider.getAsBoolean();
1950 return !mute && super.isSoundEffectsEnabled();
1951 }
1952
Chris Wren51c75102013-07-16 20:49:17 -04001953 public boolean isExpandable() {
Selim Cinek0b9cf462017-12-07 16:31:03 -08001954 if (mIsSummaryWithChildren && !shouldShowPublic()) {
Selim Cinek388df6d2015-10-22 13:25:11 -07001955 return !mChildrenExpanded;
1956 }
Anthony Chen6bf88a02017-04-10 14:41:44 -07001957 return mEnableNonGroupedNotificationExpand && mExpandable;
Chris Wren51c75102013-07-16 20:49:17 -04001958 }
1959
1960 public void setExpandable(boolean expandable) {
1961 mExpandable = expandable;
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001962 mPrivateLayout.updateExpandButtons(isExpandable());
Chris Wren51c75102013-07-16 20:49:17 -04001963 }
1964
Selim Cinek4ffd6362015-12-29 15:12:23 +01001965 @Override
1966 public void setClipToActualHeight(boolean clipToActualHeight) {
Selim Cinek084c16b2016-01-22 17:48:22 -08001967 super.setClipToActualHeight(clipToActualHeight || isUserLocked());
1968 getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked());
Selim Cinek4ffd6362015-12-29 15:12:23 +01001969 }
1970
Selim Cinek1685e632014-04-08 02:27:49 +02001971 /**
1972 * @return whether the user has changed the expansion state
1973 */
1974 public boolean hasUserChangedExpansion() {
1975 return mHasUserChangedExpansion;
1976 }
1977
Chris Wren51c75102013-07-16 20:49:17 -04001978 public boolean isUserExpanded() {
1979 return mUserExpanded;
1980 }
1981
Selim Cinek1685e632014-04-08 02:27:49 +02001982 /**
1983 * Set this notification to be expanded by the user
1984 *
1985 * @param userExpanded whether the user wants this notification to be expanded
1986 */
Chris Wren51c75102013-07-16 20:49:17 -04001987 public void setUserExpanded(boolean userExpanded) {
Selim Cinek388df6d2015-10-22 13:25:11 -07001988 setUserExpanded(userExpanded, false /* allowChildExpansion */);
1989 }
1990
1991 /**
1992 * Set this notification to be expanded by the user
1993 *
1994 * @param userExpanded whether the user wants this notification to be expanded
1995 * @param allowChildExpansion whether a call to this method allows expanding children
1996 */
1997 public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001998 mFalsingManager.setNotificationExpanded();
Selim Cinek0b9cf462017-12-07 16:31:03 -08001999 if (mIsSummaryWithChildren && !shouldShowPublic() && allowChildExpansion
Selim Cinek414ad332017-02-24 19:06:12 -08002000 && !mChildrenContainer.showingAsLowPriority()) {
Chris Wren698b1702016-05-23 11:16:32 -04002001 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinek388df6d2015-10-22 13:25:11 -07002002 mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded);
Selim Cinek414ad332017-02-24 19:06:12 -08002003 onExpansionChanged(true /* userAction */, wasExpanded);
Selim Cinek388df6d2015-10-22 13:25:11 -07002004 return;
2005 }
Christoph Studera7fe6312014-06-27 19:32:44 +02002006 if (userExpanded && !mExpandable) return;
Chris Wren78403d72014-07-28 10:23:24 +01002007 final boolean wasExpanded = isExpanded();
Selim Cinek1685e632014-04-08 02:27:49 +02002008 mHasUserChangedExpansion = true;
Chris Wren51c75102013-07-16 20:49:17 -04002009 mUserExpanded = userExpanded;
Selim Cinek414ad332017-02-24 19:06:12 -08002010 onExpansionChanged(true /* userAction */, wasExpanded);
Selim Cinek5d6ef8d2017-05-18 22:16:00 -07002011 if (!wasExpanded && isExpanded()
2012 && getActualHeight() != getIntrinsicHeight()) {
2013 notifyHeightChanged(true /* needsAnimation */);
2014 }
Chris Wren51c75102013-07-16 20:49:17 -04002015 }
2016
Selim Cinekccd14fb2014-08-12 18:53:24 +02002017 public void resetUserExpansion() {
Selim Cinek414ad332017-02-24 19:06:12 -08002018 boolean changed = mUserExpanded;
Selim Cinekccd14fb2014-08-12 18:53:24 +02002019 mHasUserChangedExpansion = false;
2020 mUserExpanded = false;
Selim Cinek414ad332017-02-24 19:06:12 -08002021 if (changed && mIsSummaryWithChildren) {
2022 mChildrenContainer.onExpansionChanged();
2023 }
2024 updateShelfIconColor();
Selim Cinekccd14fb2014-08-12 18:53:24 +02002025 }
2026
Chris Wren51c75102013-07-16 20:49:17 -04002027 public boolean isUserLocked() {
Selim Cinek1b2a05e2016-04-28 14:20:39 -07002028 return mUserLocked && !mForceUnlocked;
Chris Wren51c75102013-07-16 20:49:17 -04002029 }
2030
2031 public void setUserLocked(boolean userLocked) {
2032 mUserLocked = userLocked;
Selim Cinek8f2f6a62016-02-23 19:56:31 -08002033 mPrivateLayout.setUserExpanding(userLocked);
Selim Cinek817abe72017-05-24 11:08:55 -07002034 // This is intentionally not guarded with mIsSummaryWithChildren since we might have had
2035 // children but not anymore.
2036 if (mChildrenContainer != null) {
Selim Cinek42357e02016-02-24 18:48:01 -08002037 mChildrenContainer.setUserLocked(userLocked);
Selim Cinek817abe72017-05-24 11:08:55 -07002038 if (mIsSummaryWithChildren && (userLocked || !isGroupExpanded())) {
Mady Mellorb0a82462016-04-30 17:31:02 -07002039 updateBackgroundForGroupState();
2040 }
Selim Cinek42357e02016-02-24 18:48:01 -08002041 }
Chris Wren51c75102013-07-16 20:49:17 -04002042 }
2043
Selim Cinek1685e632014-04-08 02:27:49 +02002044 /**
2045 * @return has the system set this notification to be expanded
2046 */
2047 public boolean isSystemExpanded() {
2048 return mIsSystemExpanded;
2049 }
2050
2051 /**
2052 * Set this notification to be expanded by the system.
2053 *
2054 * @param expand whether the system wants this notification to be expanded.
2055 */
2056 public void setSystemExpanded(boolean expand) {
Selim Cinek31094df2014-08-14 19:28:15 +02002057 if (expand != mIsSystemExpanded) {
2058 final boolean wasExpanded = isExpanded();
2059 mIsSystemExpanded = expand;
Selim Cinekb5605e52015-02-20 18:21:41 +01002060 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek414ad332017-02-24 19:06:12 -08002061 onExpansionChanged(false /* userAction */, wasExpanded);
Selim Cineked6913b2016-06-01 12:01:17 -07002062 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07002063 mChildrenContainer.updateGroupOverflow();
2064 }
Selim Cinek31094df2014-08-14 19:28:15 +02002065 }
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02002066 }
2067
2068 /**
Selim Cinek83bc7832015-10-22 13:26:54 -07002069 * @param onKeyguard whether to prevent notification expansion
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02002070 */
Selim Cinek83bc7832015-10-22 13:26:54 -07002071 public void setOnKeyguard(boolean onKeyguard) {
2072 if (onKeyguard != mOnKeyguard) {
Selim Cinek5cf1d052017-06-01 17:36:46 -07002073 boolean wasAboveShelf = isAboveShelf();
Selim Cinek31094df2014-08-14 19:28:15 +02002074 final boolean wasExpanded = isExpanded();
Selim Cinek83bc7832015-10-22 13:26:54 -07002075 mOnKeyguard = onKeyguard;
Selim Cinek414ad332017-02-24 19:06:12 -08002076 onExpansionChanged(false /* userAction */, wasExpanded);
Selim Cinek31094df2014-08-14 19:28:15 +02002077 if (wasExpanded != isExpanded()) {
Selim Cinekc897bd32016-03-18 17:32:31 -07002078 if (mIsSummaryWithChildren) {
2079 mChildrenContainer.updateGroupOverflow();
2080 }
Mady Mellor4b80b102016-01-22 08:03:58 -08002081 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +02002082 }
Selim Cinek5cf1d052017-06-01 17:36:46 -07002083 if (isAboveShelf() != wasAboveShelf) {
2084 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
2085 }
Selim Cinek31094df2014-08-14 19:28:15 +02002086 }
Selim Cinekfe24fb72018-02-13 14:34:55 -08002087 updateRippleAllowed();
2088 }
2089
2090 private void updateRippleAllowed() {
2091 boolean allowed = isOnKeyguard()
2092 || mEntry.notification.getNotification().contentIntent == null;
2093 setRippleAllowed(allowed);
Selim Cinek1685e632014-04-08 02:27:49 +02002094 }
2095
2096 /**
Selim Cinek9e624e72016-07-20 13:46:49 -07002097 * @return Can the underlying notification be cleared? This can be different from whether the
2098 * notification can be dismissed in case notifications are sensitive on the lockscreen.
2099 * @see #canViewBeDismissed()
Dan Sandler0d3e62f2014-07-14 17:13:50 -04002100 */
2101 public boolean isClearable() {
Selim Cinek506deb62016-07-20 15:43:59 -07002102 if (mStatusBarNotification == null || !mStatusBarNotification.isClearable()) {
2103 return false;
2104 }
2105 if (mIsSummaryWithChildren) {
2106 List<ExpandableNotificationRow> notificationChildren =
2107 mChildrenContainer.getNotificationChildren();
2108 for (int i = 0; i < notificationChildren.size(); i++) {
2109 ExpandableNotificationRow child = notificationChildren.get(i);
2110 if (!child.isClearable()) {
2111 return false;
2112 }
2113 }
2114 }
2115 return true;
Dan Sandler0d3e62f2014-07-14 17:13:50 -04002116 }
2117
Jorim Jaggi9cbadd32014-05-01 20:18:31 +02002118 @Override
2119 public int getIntrinsicHeight() {
Jorim Jaggibe565df2014-04-28 17:51:23 +02002120 if (isUserLocked()) {
2121 return getActualHeight();
2122 }
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05002123 if (mGuts != null && mGuts.isExposed()) {
Mady Mellore09fb702017-03-30 13:23:29 -07002124 return mGuts.getIntrinsicHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -08002125 } else if ((isChildInGroup() && !isGroupExpanded())) {
2126 return mPrivateLayout.getMinHeight();
2127 } else if (mSensitive && mHideSensitiveForIntrinsicHeight) {
2128 return getMinHeight();
Adrian Roos6f6e1592017-05-02 16:22:53 -07002129 } else if (mIsSummaryWithChildren && (!mOnKeyguard || mShowAmbient)) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08002130 return mChildrenContainer.getIntrinsicHeight();
Adrian Roos6f6e1592017-05-02 16:22:53 -07002131 } else if (isHeadsUpAllowed() && (mIsHeadsUp || mHeadsupDisappearRunning)) {
Selim Cinek73cf02a2016-06-17 13:08:00 -07002132 if (isPinned() || mHeadsupDisappearRunning) {
Selim Cinek31aada42015-12-18 17:51:15 -08002133 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
2134 } else if (isExpanded()) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -08002135 return Math.max(getMaxExpandHeight(), getHeadsUpHeight());
Selim Cinek8d490d42015-04-10 00:05:50 -07002136 } else {
Selim Cinekaa9db1f2018-02-27 17:35:47 -08002137 return Math.max(getCollapsedHeight(), getHeadsUpHeight());
Selim Cinek8d490d42015-04-10 00:05:50 -07002138 }
Selim Cinek31aada42015-12-18 17:51:15 -08002139 } else if (isExpanded()) {
Selim Cinek83bc7832015-10-22 13:26:54 -07002140 return getMaxExpandHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -08002141 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07002142 return getCollapsedHeight();
Selim Cinek1685e632014-04-08 02:27:49 +02002143 }
Selim Cinekb5605e52015-02-20 18:21:41 +01002144 }
Selim Cinek1685e632014-04-08 02:27:49 +02002145
Adrian Roos6f6e1592017-05-02 16:22:53 -07002146 private boolean isHeadsUpAllowed() {
2147 return !mOnKeyguard && !mShowAmbient;
2148 }
2149
Mady Mellor43c2cd12016-12-12 21:05:13 -08002150 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -07002151 public boolean isGroupExpanded() {
Selim Cinekeef84282015-10-30 16:28:00 -07002152 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinekb5605e52015-02-20 18:21:41 +01002153 }
2154
Selim Cinek263398f2015-10-21 17:40:23 -07002155 private void onChildrenCountChanged() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -05002156 mIsSummaryWithChildren = StatusBar.ENABLE_CHILD_NOTIFICATIONS
Mady Mellorb0a82462016-04-30 17:31:02 -07002157 && mChildrenContainer != null && mChildrenContainer.getNotificationChildCount() > 0;
2158 if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() == null) {
Selim Cinek414ad332017-02-24 19:06:12 -08002159 mChildrenContainer.recreateNotificationHeader(mExpandClickListener
2160 );
Selim Cinek263398f2015-10-21 17:40:23 -07002161 }
Mady Mellor6baed9e2016-05-25 16:05:09 -07002162 getShowingLayout().updateBackgroundColor(false /* animate */);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08002163 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinekea4bef72015-12-02 15:51:10 -08002164 updateChildrenHeaderAppearance();
Selim Cinekda42d652015-12-04 15:51:16 -08002165 updateChildrenVisibility();
Selim Cinek2871bef2017-11-22 08:40:00 -08002166 applyChildrenRoundness();
Selim Cinek263398f2015-10-21 17:40:23 -07002167 }
Rohan Shah63411fc2018-03-28 19:05:52 -07002168 /**
2169 * Returns the number of channels covered by the notification row (including its children if
2170 * it's a summary notification).
2171 */
2172 public int getNumUniqueChannels() {
2173 ArraySet<NotificationChannel> channels = new ArraySet<>();
2174
2175 channels.add(mEntry.channel);
2176
2177 // If this is a summary, then add in the children notification channels for the
2178 // same user and pkg.
2179 if (mIsSummaryWithChildren) {
2180 final List<ExpandableNotificationRow> childrenRows = getNotificationChildren();
2181 final int numChildren = childrenRows.size();
2182 for (int i = 0; i < numChildren; i++) {
2183 final ExpandableNotificationRow childRow = childrenRows.get(i);
2184 final NotificationChannel childChannel = childRow.getEntry().channel;
2185 final StatusBarNotification childSbn = childRow.getStatusBarNotification();
2186 if (childSbn.getUser().equals(mStatusBarNotification.getUser()) &&
2187 childSbn.getPackageName().equals(mStatusBarNotification.getPackageName())) {
2188 channels.add(childChannel);
2189 }
2190 }
2191 }
2192 return channels.size();
2193 }
Selim Cinek263398f2015-10-21 17:40:23 -07002194
Mady Mellorb0a82462016-04-30 17:31:02 -07002195 public void updateChildrenHeaderAppearance() {
Selim Cineked6913b2016-06-01 12:01:17 -07002196 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -07002197 mChildrenContainer.updateChildrenHeaderAppearance();
2198 }
2199 }
2200
Selim Cinek1685e632014-04-08 02:27:49 +02002201 /**
2202 * Check whether the view state is currently expanded. This is given by the system in {@link
2203 * #setSystemExpanded(boolean)} and can be overridden by user expansion or
2204 * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this
2205 * view can differ from this state, if layout params are modified from outside.
2206 *
2207 * @return whether the view state is currently expanded.
2208 */
Selim Cinek83bc7832015-10-22 13:26:54 -07002209 public boolean isExpanded() {
Selim Cineke81b82b2016-03-04 11:22:28 -08002210 return isExpanded(false /* allowOnKeyguard */);
2211 }
2212
2213 public boolean isExpanded(boolean allowOnKeyguard) {
2214 return (!mOnKeyguard || allowOnKeyguard)
Selim Cinekb5605e52015-02-20 18:21:41 +01002215 && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded())
2216 || isUserExpanded());
2217 }
2218
2219 private boolean isSystemChildExpanded() {
2220 return mIsSystemChildExpanded;
2221 }
2222
2223 public void setSystemChildExpanded(boolean expanded) {
2224 mIsSystemChildExpanded = expanded;
Selim Cinek1685e632014-04-08 02:27:49 +02002225 }
2226
Mady Mellor035badd2017-04-04 18:45:30 -07002227 public void setLayoutListener(LayoutListener listener) {
2228 mLayoutListener = listener;
2229 }
2230
2231 public void removeListener() {
2232 mLayoutListener = null;
2233 }
2234
Selim Cinek1685e632014-04-08 02:27:49 +02002235 @Override
2236 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -08002237 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek1685e632014-04-08 02:27:49 +02002238 super.onLayout(changed, left, top, right, bottom);
Selim Cinekaa9db1f2018-02-27 17:35:47 -08002239 if (intrinsicBefore != getIntrinsicHeight()) {
2240 notifyHeightChanged(true /* needsAnimation */);
2241 }
Mady Mellor95d743c2017-01-10 12:05:27 -08002242 if (mMenuRow.getMenuView() != null) {
2243 mMenuRow.onHeightUpdate();
Mady Mellora6edc872016-04-26 11:01:03 -07002244 }
Selim Cinek875a3a12016-11-18 17:52:16 -08002245 updateContentShiftHeight();
Mady Mellor035badd2017-04-04 18:45:30 -07002246 if (mLayoutListener != null) {
2247 mLayoutListener.onLayout();
2248 }
Selim Cinek875a3a12016-11-18 17:52:16 -08002249 }
2250
2251 /**
2252 * Updates the content shift height such that the header is completely hidden when coming from
2253 * the top.
2254 */
2255 private void updateContentShiftHeight() {
Selim Cinek414ad332017-02-24 19:06:12 -08002256 NotificationHeaderView notificationHeader = getVisibleNotificationHeader();
Selim Cinek875a3a12016-11-18 17:52:16 -08002257 if (notificationHeader != null) {
2258 CachingIconView icon = notificationHeader.getIcon();
2259 mIconTransformContentShift = getRelativeTopPadding(icon) + icon.getHeight();
2260 } else {
2261 mIconTransformContentShift = mIconTransformContentShiftNoIcon;
2262 }
Selim Cinek1685e632014-04-08 02:27:49 +02002263 }
2264
Selim Cinekfa0a2d32016-01-14 13:02:21 -08002265 @Override
2266 public void notifyHeightChanged(boolean needsAnimation) {
2267 super.notifyHeightChanged(needsAnimation);
2268 getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked());
2269 }
2270
Selim Cinek3c76d502016-02-19 15:16:33 -08002271 public void setSensitive(boolean sensitive, boolean hideSensitive) {
Jorim Jaggiae441282014-08-01 02:45:18 +02002272 mSensitive = sensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -08002273 mSensitiveHiddenInGeneral = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02002274 }
2275
Mady Mellor43c2cd12016-12-12 21:05:13 -08002276 @Override
Jorim Jaggiae441282014-08-01 02:45:18 +02002277 public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
Selim Cinek60122be2015-04-15 18:16:50 -07002278 mHideSensitiveForIntrinsicHeight = hideSensitive;
Selim Cineka52f6a12016-02-29 15:35:58 -08002279 if (mIsSummaryWithChildren) {
2280 List<ExpandableNotificationRow> notificationChildren =
2281 mChildrenContainer.getNotificationChildren();
2282 for (int i = 0; i < notificationChildren.size(); i++) {
2283 ExpandableNotificationRow child = notificationChildren.get(i);
2284 child.setHideSensitiveForIntrinsicHeight(hideSensitive);
2285 }
2286 }
Jorim Jaggiae441282014-08-01 02:45:18 +02002287 }
2288
Mady Mellor43c2cd12016-12-12 21:05:13 -08002289 @Override
Jorim Jaggiae441282014-08-01 02:45:18 +02002290 public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
2291 long duration) {
Selim Cinek69594fb2018-05-18 12:06:10 -07002292 if (getVisibility() == GONE) {
2293 // If we are GONE, the hideSensitive parameter will not be calculated and always be
2294 // false, which is incorrect, let's wait until a real call comes in later.
2295 return;
2296 }
Jorim Jaggiae441282014-08-01 02:45:18 +02002297 boolean oldShowingPublic = mShowingPublic;
2298 mShowingPublic = mSensitive && hideSensitive;
2299 if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
2300 return;
2301 }
Dan Sandlera5e0f412014-01-23 15:11:54 -05002302
2303 // bail out if no public version
Selim Cinek1685e632014-04-08 02:27:49 +02002304 if (mPublicLayout.getChildCount() == 0) return;
Dan Sandlera5e0f412014-01-23 15:11:54 -05002305
Jorim Jaggiae441282014-08-01 02:45:18 +02002306 if (!animated) {
2307 mPublicLayout.animate().cancel();
2308 mPrivateLayout.animate().cancel();
Selim Cineka554c702016-06-17 18:02:12 -07002309 if (mChildrenContainer != null) {
2310 mChildrenContainer.animate().cancel();
2311 mChildrenContainer.setAlpha(1f);
2312 }
Jorim Jaggiae441282014-08-01 02:45:18 +02002313 mPublicLayout.setAlpha(1f);
2314 mPrivateLayout.setAlpha(1f);
2315 mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
Selim Cinekd84a5932015-12-15 11:45:36 -08002316 updateChildrenVisibility();
Jorim Jaggiae441282014-08-01 02:45:18 +02002317 } else {
Selim Cinek0b9cf462017-12-07 16:31:03 -08002318 animateShowingPublic(delay, duration, mShowingPublic);
Jorim Jaggiae441282014-08-01 02:45:18 +02002319 }
Selim Cinekc3179332016-03-04 14:44:56 -08002320 NotificationContentView showingLayout = getShowingLayout();
2321 showingLayout.updateBackgroundColor(animated);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08002322 mPrivateLayout.updateExpandButtons(isExpandable());
Lucas Dupinb6ed63b2017-05-30 16:17:42 -07002323 updateShelfIconColor();
Adrian Roose5726a22016-12-19 14:26:51 -08002324 showingLayout.setDark(isDark(), false /* animate */, 0 /* delay */);
Jorim Jaggiae441282014-08-01 02:45:18 +02002325 mShowingPublicInitialized = true;
2326 }
2327
Selim Cinek0b9cf462017-12-07 16:31:03 -08002328 private void animateShowingPublic(long delay, long duration, boolean showingPublic) {
Mady Mellorb0a82462016-04-30 17:31:02 -07002329 View[] privateViews = mIsSummaryWithChildren
2330 ? new View[] {mChildrenContainer}
Selim Cinekd84a5932015-12-15 11:45:36 -08002331 : new View[] {mPrivateLayout};
2332 View[] publicViews = new View[] {mPublicLayout};
Selim Cinek0b9cf462017-12-07 16:31:03 -08002333 View[] hiddenChildren = showingPublic ? privateViews : publicViews;
2334 View[] shownChildren = showingPublic ? publicViews : privateViews;
Selim Cinekd84a5932015-12-15 11:45:36 -08002335 for (final View hiddenView : hiddenChildren) {
2336 hiddenView.setVisibility(View.VISIBLE);
2337 hiddenView.animate().cancel();
2338 hiddenView.animate()
2339 .alpha(0f)
2340 .setStartDelay(delay)
2341 .setDuration(duration)
2342 .withEndAction(new Runnable() {
2343 @Override
2344 public void run() {
2345 hiddenView.setVisibility(View.INVISIBLE);
2346 }
2347 });
2348 }
2349 for (View showView : shownChildren) {
2350 showView.setVisibility(View.VISIBLE);
2351 showView.setAlpha(0f);
2352 showView.animate().cancel();
2353 showView.animate()
2354 .alpha(1f)
2355 .setStartDelay(delay)
2356 .setDuration(duration);
2357 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04002358 }
2359
Mady Mellor43c2cd12016-12-12 21:05:13 -08002360 @Override
Selim Cinek3776fe02016-02-04 13:32:43 -08002361 public boolean mustStayOnScreen() {
Selim Cinek9b9d6e12017-11-30 12:29:47 +01002362 return mIsHeadsUp && mMustStayOnScreen;
Selim Cinek3776fe02016-02-04 13:32:43 -08002363 }
2364
Selim Cinek9e624e72016-07-20 13:46:49 -07002365 /**
2366 * @return Whether this view is allowed to be dismissed. Only valid for visible notifications as
2367 * otherwise some state might not be updated. To request about the general clearability
2368 * see {@link #isClearable()}.
2369 */
2370 public boolean canViewBeDismissed() {
Selim Cinek0b9cf462017-12-07 16:31:03 -08002371 return isClearable() && (!shouldShowPublic() || !mSensitiveHiddenInGeneral);
2372 }
2373
2374 private boolean shouldShowPublic() {
2375 return mSensitive && mHideSensitiveForIntrinsicHeight;
Dan Sandlera5e0f412014-01-23 15:11:54 -05002376 }
Jorim Jaggi251957d2014-04-09 04:24:09 +02002377
Ricky Waicd35def2016-05-03 11:07:07 +01002378 public void makeActionsVisibile() {
2379 setUserExpanded(true, true);
2380 if (isChildInGroup()) {
2381 mGroupManager.setGroupExpanded(mStatusBarNotification, true);
2382 }
Selim Cinekbb42b7d2016-08-10 13:02:38 -07002383 notifyHeightChanged(false /* needsAnimation */);
Ricky Waicd35def2016-05-03 11:07:07 +01002384 }
2385
Selim Cinekb5605e52015-02-20 18:21:41 +01002386 public void setChildrenExpanded(boolean expanded, boolean animate) {
2387 mChildrenExpanded = expanded;
Selim Cinek83bc7832015-10-22 13:26:54 -07002388 if (mChildrenContainer != null) {
2389 mChildrenContainer.setChildrenExpanded(expanded);
2390 }
Mady Mellor1a5d8ea2016-06-09 10:42:42 -07002391 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -07002392 updateClickAndFocus();
Selim Cinekb5605e52015-02-20 18:21:41 +01002393 }
2394
Selim Cinekb5605e52015-02-20 18:21:41 +01002395 public static void applyTint(View v, int color) {
2396 int alpha;
2397 if (color != 0) {
2398 alpha = COLORED_DIVIDER_ALPHA;
2399 } else {
2400 color = 0xff000000;
2401 alpha = DEFAULT_DIVIDER_ALPHA;
2402 }
2403 if (v.getBackground() instanceof ColorDrawable) {
2404 ColorDrawable background = (ColorDrawable) v.getBackground();
2405 background.mutate();
2406 background.setColor(color);
2407 background.setAlpha(alpha);
2408 }
2409 }
2410
Selim Cinek1685e632014-04-08 02:27:49 +02002411 public int getMaxExpandHeight() {
Selim Cinekaa9db1f2018-02-27 17:35:47 -08002412 return mPrivateLayout.getExpandHeight();
2413 }
2414
2415
2416 private int getHeadsUpHeight() {
2417 return mPrivateLayout.getHeadsUpHeight();
Chris Wren51c75102013-07-16 20:49:17 -04002418 }
Jorim Jaggi584a7aa2014-04-10 23:26:13 +02002419
Mady Mellor34958fa2016-02-23 09:52:17 -08002420 public boolean areGutsExposed() {
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05002421 return (mGuts != null && mGuts.isExposed());
Mady Mellor34958fa2016-02-23 09:52:17 -08002422 }
2423
Jorim Jaggibe565df2014-04-28 17:51:23 +02002424 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02002425 public boolean isContentExpandable() {
Selim Cinek0b9cf462017-12-07 16:31:03 -08002426 if (mIsSummaryWithChildren && !shouldShowPublic()) {
Selim Cinekc0ac4af2017-03-03 15:13:48 -08002427 return true;
2428 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02002429 NotificationContentView showingLayout = getShowingLayout();
2430 return showingLayout.isContentExpandable();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02002431 }
2432
2433 @Override
Selim Cinek560e64d2015-06-09 19:58:11 -07002434 protected View getContentView() {
Selim Cinek0b9cf462017-12-07 16:31:03 -08002435 if (mIsSummaryWithChildren && !shouldShowPublic()) {
Selim Cineka5703182016-05-11 21:23:16 -04002436 return mChildrenContainer;
2437 }
Selim Cinek560e64d2015-06-09 19:58:11 -07002438 return getShowingLayout();
2439 }
2440
2441 @Override
Selim Cinekaa3901a2016-08-05 11:04:37 -07002442 protected void onAppearAnimationFinished(boolean wasAppearing) {
2443 super.onAppearAnimationFinished(wasAppearing);
2444 if (wasAppearing) {
2445 // During the animation the visible view might have changed, so let's make sure all
2446 // alphas are reset
2447 if (mChildrenContainer != null) {
2448 mChildrenContainer.setAlpha(1.0f);
2449 mChildrenContainer.setLayerType(LAYER_TYPE_NONE, null);
2450 }
Adrian Rooseb434ff2017-01-11 11:18:48 -08002451 for (NotificationContentView l : mLayouts) {
2452 l.setAlpha(1.0f);
2453 l.setLayerType(LAYER_TYPE_NONE, null);
2454 }
Selim Cinekaa3901a2016-08-05 11:04:37 -07002455 }
2456 }
2457
2458 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -07002459 public int getExtraBottomPadding() {
2460 if (mIsSummaryWithChildren && isGroupExpanded()) {
2461 return mIncreasedPaddingBetweenElements;
2462 }
2463 return 0;
2464 }
2465
2466 @Override
Jorim Jaggid552d9d2014-05-07 19:41:13 +02002467 public void setActualHeight(int height, boolean notifyListeners) {
Selim Cinek4ca6c632017-02-23 18:03:37 -08002468 boolean changed = height != getActualHeight();
Selim Cinekb5605e52015-02-20 18:21:41 +01002469 super.setActualHeight(height, notifyListeners);
Selim Cinek4ca6c632017-02-23 18:03:37 -08002470 if (changed && isRemoved()) {
2471 // TODO: remove this once we found the gfx bug for this.
2472 // This is a hack since a removed view sometimes would just stay blank. it occured
2473 // when sending yourself a message and then clicking on it.
2474 ViewGroup parent = (ViewGroup) getParent();
2475 if (parent != null) {
2476 parent.invalidate();
2477 }
2478 }
Geoffrey Pitsch4dd50062016-12-06 16:41:22 -05002479 if (mGuts != null && mGuts.isExposed()) {
Mady Mellorb53bc272016-02-11 18:28:23 -08002480 mGuts.setActualHeight(height);
2481 return;
2482 }
Selim Cinekeef84282015-10-30 16:28:00 -07002483 int contentHeight = Math.max(getMinHeight(), height);
Adrian Rooseb434ff2017-01-11 11:18:48 -08002484 for (NotificationContentView l : mLayouts) {
2485 l.setContentHeight(contentHeight);
2486 }
Selim Cinek42357e02016-02-24 18:48:01 -08002487 if (mIsSummaryWithChildren) {
2488 mChildrenContainer.setActualHeight(height);
2489 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02002490 if (mGuts != null) {
2491 mGuts.setActualHeight(height);
2492 }
Mady Mellor54540972017-06-07 11:55:36 -07002493 if (mMenuRow.getMenuView() != null) {
2494 mMenuRow.onHeightUpdate();
2495 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02002496 }
2497
2498 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01002499 public int getMaxContentHeight() {
Selim Cinek0b9cf462017-12-07 16:31:03 -08002500 if (mIsSummaryWithChildren && !shouldShowPublic()) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08002501 return mChildrenContainer.getMaxContentHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07002502 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02002503 NotificationContentView showingLayout = getShowingLayout();
2504 return showingLayout.getMaxHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +02002505 }
2506
2507 @Override
Selim Cinekeb3fc3d2017-09-15 13:37:14 -07002508 public int getMinHeight(boolean ignoreTemporaryStates) {
2509 if (!ignoreTemporaryStates && mGuts != null && mGuts.isExposed()) {
Mady Mellore09fb702017-03-30 13:23:29 -07002510 return mGuts.getIntrinsicHeight();
Selim Cinekeb3fc3d2017-09-15 13:37:14 -07002511 } else if (!ignoreTemporaryStates && isHeadsUpAllowed() && mIsHeadsUp
2512 && mHeadsUpManager.isTrackingHeadsUp()) {
Selim Cinek31aada42015-12-18 17:51:15 -08002513 return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
Selim Cinek0b9cf462017-12-07 16:31:03 -08002514 } else if (mIsSummaryWithChildren && !isGroupExpanded() && !shouldShowPublic()) {
Selim Cinekb55386d2015-12-16 17:26:49 -08002515 return mChildrenContainer.getMinHeight();
Selim Cinekeb3fc3d2017-09-15 13:37:14 -07002516 } else if (!ignoreTemporaryStates && isHeadsUpAllowed() && mIsHeadsUp) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -08002517 return getHeadsUpHeight();
Selim Cinekb55386d2015-12-16 17:26:49 -08002518 }
Selim Cinek816c8e42015-11-19 12:00:45 -08002519 NotificationContentView showingLayout = getShowingLayout();
2520 return showingLayout.getMinHeight();
2521 }
2522
2523 @Override
Selim Cinek567e8452016-03-24 10:54:56 -07002524 public int getCollapsedHeight() {
Selim Cinek0b9cf462017-12-07 16:31:03 -08002525 if (mIsSummaryWithChildren && !shouldShowPublic()) {
Selim Cinek567e8452016-03-24 10:54:56 -07002526 return mChildrenContainer.getCollapsedHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07002527 }
Selim Cinek816c8e42015-11-19 12:00:45 -08002528 return getMinHeight();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02002529 }
2530
2531 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02002532 public void setClipTopAmount(int clipTopAmount) {
2533 super.setClipTopAmount(clipTopAmount);
Adrian Rooseb434ff2017-01-11 11:18:48 -08002534 for (NotificationContentView l : mLayouts) {
2535 l.setClipTopAmount(clipTopAmount);
2536 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02002537 if (mGuts != null) {
2538 mGuts.setClipTopAmount(clipTopAmount);
2539 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02002540 }
2541
Selim Cineka686b2c2016-10-26 13:58:27 -07002542 @Override
2543 public void setClipBottomAmount(int clipBottomAmount) {
Selim Cinek2627d722018-01-19 12:16:49 -08002544 if (mExpandAnimationRunning) {
2545 return;
2546 }
Selim Cinek65d418e2016-11-29 15:42:34 -08002547 if (clipBottomAmount != mClipBottomAmount) {
2548 super.setClipBottomAmount(clipBottomAmount);
Adrian Rooseb434ff2017-01-11 11:18:48 -08002549 for (NotificationContentView l : mLayouts) {
2550 l.setClipBottomAmount(clipBottomAmount);
2551 }
Selim Cinek65d418e2016-11-29 15:42:34 -08002552 if (mGuts != null) {
2553 mGuts.setClipBottomAmount(clipBottomAmount);
2554 }
Selim Cineka686b2c2016-10-26 13:58:27 -07002555 }
Selim Cinekc25989e2018-02-16 16:42:14 -08002556 if (mChildrenContainer != null && !mChildIsExpanding) {
Selim Cinek65d418e2016-11-29 15:42:34 -08002557 // We have to update this even if it hasn't changed, since the children locations can
2558 // have changed
Selim Cinekb3dadcc2016-11-21 17:21:13 -08002559 mChildrenContainer.setClipBottomAmount(clipBottomAmount);
2560 }
Selim Cineka686b2c2016-10-26 13:58:27 -07002561 }
2562
Selim Cinek42357e02016-02-24 18:48:01 -08002563 public NotificationContentView getShowingLayout() {
Selim Cinek0b9cf462017-12-07 16:31:03 -08002564 return shouldShowPublic() ? mPublicLayout : mPrivateLayout;
Selim Cinek2f0df8a2014-06-10 17:40:42 +02002565 }
Chris Wren78403d72014-07-28 10:23:24 +01002566
Selim Cinek1a48bab2017-02-17 19:38:40 -08002567 public void setLegacy(boolean legacy) {
Adrian Rooseb434ff2017-01-11 11:18:48 -08002568 for (NotificationContentView l : mLayouts) {
Selim Cinek1a48bab2017-02-17 19:38:40 -08002569 l.setLegacy(legacy);
Adrian Rooseb434ff2017-01-11 11:18:48 -08002570 }
Jorim Jaggi59ec3042015-06-05 15:18:43 -07002571 }
2572
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002573 @Override
2574 protected void updateBackgroundTint() {
2575 super.updateBackgroundTint();
Mady Mellorb0a82462016-04-30 17:31:02 -07002576 updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002577 if (mIsSummaryWithChildren) {
2578 List<ExpandableNotificationRow> notificationChildren =
2579 mChildrenContainer.getNotificationChildren();
2580 for (int i = 0; i < notificationChildren.size(); i++) {
2581 ExpandableNotificationRow child = notificationChildren.get(i);
Mady Mellorb0a82462016-04-30 17:31:02 -07002582 child.updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002583 }
2584 }
2585 }
2586
Mady Mellorb0a82462016-04-30 17:31:02 -07002587 /**
2588 * Called when a group has finished animating from collapsed or expanded state.
2589 */
2590 public void onFinishedExpansionChange() {
2591 mGroupExpansionChanging = false;
2592 updateBackgroundForGroupState();
2593 }
2594
2595 /**
2596 * Updates the parent and children backgrounds in a group based on the expansion state.
2597 */
2598 public void updateBackgroundForGroupState() {
2599 if (mIsSummaryWithChildren) {
2600 // Only when the group has finished expanding do we hide its background.
Anthony Chen6bf88a02017-04-10 14:41:44 -07002601 mShowNoBackground = !mShowGroupBackgroundWhenExpanded && isGroupExpanded()
2602 && !isGroupExpansionChanging() && !isUserLocked();
Mady Mellorb0a82462016-04-30 17:31:02 -07002603 mChildrenContainer.updateHeaderForExpansion(mShowNoBackground);
2604 List<ExpandableNotificationRow> children = mChildrenContainer.getNotificationChildren();
2605 for (int i = 0; i < children.size(); i++) {
2606 children.get(i).updateBackgroundForGroupState();
2607 }
2608 } else if (isChildInGroup()) {
2609 final int childColor = getShowingLayout().getBackgroundColorForExpansionState();
2610 // Only show a background if the group is expanded OR if it is expanding / collapsing
Anthony Chen6bf88a02017-04-10 14:41:44 -07002611 // and has a custom background color.
Mady Mellorb0a82462016-04-30 17:31:02 -07002612 final boolean showBackground = isGroupExpanded()
2613 || ((mNotificationParent.isGroupExpansionChanging()
Anthony Chen6bf88a02017-04-10 14:41:44 -07002614 || mNotificationParent.isUserLocked()) && childColor != 0);
Mady Mellorb0a82462016-04-30 17:31:02 -07002615 mShowNoBackground = !showBackground;
2616 } else {
2617 // Only children or parents ever need no background.
2618 mShowNoBackground = false;
2619 }
2620 updateOutline();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07002621 updateBackground();
2622 }
2623
Adrian Roos4a579672016-05-24 16:54:37 -07002624 public int getPositionOfChild(ExpandableNotificationRow childRow) {
2625 if (mIsSummaryWithChildren) {
2626 return mChildrenContainer.getPositionInLinearLayout(childRow);
2627 }
2628 return 0;
2629 }
2630
Chris Wren78403d72014-07-28 10:23:24 +01002631 public void setExpansionLogger(ExpansionLogger logger, String key) {
2632 mLogger = logger;
2633 mLoggingKey = key;
2634 }
2635
Chris Wren6abeeb92016-05-26 14:44:38 -04002636 public void onExpandedByGesture(boolean userExpanded) {
2637 int event = MetricsEvent.ACTION_NOTIFICATION_GESTURE_EXPANDER;
2638 if (mGroupManager.isSummaryOfGroup(getStatusBarNotification())) {
2639 event = MetricsEvent.ACTION_NOTIFICATION_GROUP_GESTURE_EXPANDER;
2640 }
2641 MetricsLogger.action(mContext, event, userExpanded);
2642 }
2643
Selim Cinek6183d122016-01-14 18:48:41 -08002644 @Override
Selim Cinek42357e02016-02-24 18:48:01 -08002645 public float getIncreasedPaddingAmount() {
2646 if (mIsSummaryWithChildren) {
2647 if (isGroupExpanded()) {
2648 return 1.0f;
2649 } else if (isUserLocked()) {
Selim Cinek414ad332017-02-24 19:06:12 -08002650 return mChildrenContainer.getIncreasedPaddingAmount();
Selim Cinek42357e02016-02-24 18:48:01 -08002651 }
Selim Cinek99104832017-01-25 14:47:33 -08002652 } else if (isColorized() && (!mIsLowPriority || isExpanded())) {
Selim Cineka7ed2c12017-01-23 20:47:24 -08002653 return -1.0f;
Selim Cinek42357e02016-02-24 18:48:01 -08002654 }
2655 return 0.0f;
Selim Cinek61633a82016-01-25 15:54:10 -08002656 }
2657
Selim Cineka7ed2c12017-01-23 20:47:24 -08002658 private boolean isColorized() {
Selim Cinek99104832017-01-25 14:47:33 -08002659 return mIsColorized && mBgTint != NO_COLOR;
Selim Cineka7ed2c12017-01-23 20:47:24 -08002660 }
2661
Selim Cinek61633a82016-01-25 15:54:10 -08002662 @Override
Selim Cinek6183d122016-01-14 18:48:41 -08002663 protected boolean disallowSingleClick(MotionEvent event) {
dongwan0605.kimc4ddef42018-05-06 17:40:23 +09002664 if (areGutsExposed()) {
2665 return false;
2666 }
Selim Cinek6183d122016-01-14 18:48:41 -08002667 float x = event.getX();
2668 float y = event.getY();
Selim Cinek34eda5e2016-02-18 17:10:43 -08002669 NotificationHeaderView header = getVisibleNotificationHeader();
Selim Cinek5d6ef8d2017-05-18 22:16:00 -07002670 if (header != null && header.isInTouchRect(x - getTranslation(), y)) {
2671 return true;
2672 }
Selim Cinek0b9cf462017-12-07 16:31:03 -08002673 if ((!mIsSummaryWithChildren || shouldShowPublic())
Selim Cinek5d6ef8d2017-05-18 22:16:00 -07002674 && getShowingLayout().disallowSingleClick(x, y)) {
2675 return true;
Selim Cinek6183d122016-01-14 18:48:41 -08002676 }
2677 return super.disallowSingleClick(event);
2678 }
2679
Selim Cinek414ad332017-02-24 19:06:12 -08002680 private void onExpansionChanged(boolean userAction, boolean wasExpanded) {
Chris Wren698b1702016-05-23 11:16:32 -04002681 boolean nowExpanded = isExpanded();
Selim Cinek414ad332017-02-24 19:06:12 -08002682 if (mIsSummaryWithChildren && (!mIsLowPriority || wasExpanded)) {
Chris Wren698b1702016-05-23 11:16:32 -04002683 nowExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
2684 }
Selim Cinek414ad332017-02-24 19:06:12 -08002685 if (nowExpanded != wasExpanded) {
2686 updateShelfIconColor();
2687 if (mLogger != null) {
2688 mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded);
2689 }
2690 if (mIsSummaryWithChildren) {
2691 mChildrenContainer.onExpansionChanged();
2692 }
Chris Wren78403d72014-07-28 10:23:24 +01002693 }
2694 }
Selim Cinek570981d2015-12-01 11:37:01 -08002695
Selim Cineke9bad242016-06-15 11:46:37 -07002696 @Override
2697 public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
2698 super.onInitializeAccessibilityNodeInfoInternal(info);
Geoffrey Pitsch409db272017-08-28 14:51:52 +00002699 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK);
Selim Cineke9bad242016-06-15 11:46:37 -07002700 if (canViewBeDismissed()) {
2701 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS);
2702 }
Selim Cinek0b9cf462017-12-07 16:31:03 -08002703 boolean expandable = shouldShowPublic();
Selim Cinekc0ac4af2017-03-03 15:13:48 -08002704 boolean isExpanded = false;
2705 if (!expandable) {
2706 if (mIsSummaryWithChildren) {
2707 expandable = true;
2708 if (!mIsLowPriority || isExpanded()) {
2709 isExpanded = isGroupExpanded();
2710 }
2711 } else {
2712 expandable = mPrivateLayout.isContentExpandable();
2713 isExpanded = isExpanded();
2714 }
2715 }
2716 if (expandable) {
2717 if (isExpanded) {
2718 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE);
2719 } else {
2720 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND);
2721 }
2722 }
Mady Mellorb3a6aed2018-05-11 13:24:07 -07002723 NotificationMenuRowPlugin provider = getProvider();
2724 if (provider != null) {
2725 MenuItem snoozeMenu = provider.getSnoozeMenuItem(getContext());
2726 if (snoozeMenu != null) {
2727 AccessibilityAction action = new AccessibilityAction(R.id.action_snooze,
2728 getContext().getResources()
2729 .getString(R.string.notification_menu_snooze_action));
2730 info.addAction(action);
2731 }
2732 }
Selim Cineke9bad242016-06-15 11:46:37 -07002733 }
2734
2735 @Override
2736 public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
2737 if (super.performAccessibilityActionInternal(action, arguments)) {
2738 return true;
2739 }
2740 switch (action) {
2741 case AccessibilityNodeInfo.ACTION_DISMISS:
Rohan Shah524cf7b2018-03-15 14:40:02 -07002742 performDismissWithBlockingHelper(true /* fromAccessibility */);
Selim Cineke9bad242016-06-15 11:46:37 -07002743 return true;
Selim Cinekc0ac4af2017-03-03 15:13:48 -08002744 case AccessibilityNodeInfo.ACTION_COLLAPSE:
2745 case AccessibilityNodeInfo.ACTION_EXPAND:
2746 mExpandClickListener.onClick(this);
2747 return true;
Geoffrey Pitsch409db272017-08-28 14:51:52 +00002748 case AccessibilityNodeInfo.ACTION_LONG_CLICK:
2749 doLongClickCallback();
2750 return true;
Jason Monk4c9d66e2018-08-09 09:38:21 -04002751 default:
2752 if (action == R.id.action_snooze) {
2753 NotificationMenuRowPlugin provider = getProvider();
2754 if (provider == null) {
2755 provider = createMenu();
2756 }
2757 MenuItem snoozeMenu = provider.getSnoozeMenuItem(getContext());
2758 if (snoozeMenu != null) {
2759 doLongClickCallback(getWidth() / 2, getHeight() / 2, snoozeMenu);
2760 }
2761 return true;
Mady Mellorb3a6aed2018-05-11 13:24:07 -07002762 }
Selim Cineke9bad242016-06-15 11:46:37 -07002763 }
2764 return false;
2765 }
2766
2767 public boolean shouldRefocusOnDismiss() {
2768 return mRefocusOnDismiss || isAccessibilityFocused();
2769 }
2770
Selim Cinek570981d2015-12-01 11:37:01 -08002771 public interface OnExpandClickListener {
Selim Cinek31aada42015-12-18 17:51:15 -08002772 void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
Selim Cinek570981d2015-12-01 11:37:01 -08002773 }
Selim Cinekbbcebde2016-11-09 18:28:20 -08002774
2775 @Override
2776 public ExpandableViewState createNewViewState(StackScrollState stackScrollState) {
Selim Cinek2627d722018-01-19 12:16:49 -08002777 mNotificationViewState = new NotificationViewState(stackScrollState);
2778 return mNotificationViewState;
Selim Cinekbbcebde2016-11-09 18:28:20 -08002779 }
2780
Selim Cinekf93bf3e2018-05-08 14:43:21 -07002781 public NotificationViewState getViewState() {
2782 return mNotificationViewState;
2783 }
2784
Selim Cinekd127d792016-11-01 19:11:41 -07002785 @Override
2786 public boolean isAboveShelf() {
Selim Cinekc8007c52017-02-28 16:09:56 -08002787 return !isOnKeyguard()
Selim Cinek2627d722018-01-19 12:16:49 -08002788 && (mIsPinned || mHeadsupDisappearRunning || (mIsHeadsUp && mAboveShelf)
Selim Cinekc25989e2018-02-16 16:42:14 -08002789 || mExpandAnimationRunning || mChildIsExpanding);
Selim Cinekd127d792016-11-01 19:11:41 -07002790 }
2791
Adrian Roos0aac04f2016-12-08 15:59:29 -08002792 public void setShowAmbient(boolean showAmbient) {
2793 if (showAmbient != mShowAmbient) {
2794 mShowAmbient = showAmbient;
Adrian Roos6f6e1592017-05-02 16:22:53 -07002795 if (mChildrenContainer != null) {
2796 mChildrenContainer.notifyShowAmbientChanged();
2797 }
Adrian Roos0aac04f2016-12-08 15:59:29 -08002798 notifyHeightChanged(false /* needsAnimation */);
2799 }
2800 }
2801
Selim Cinek0fe07392017-11-09 13:26:34 -08002802 @Override
Tony Huangc092c432018-05-18 17:38:54 +08002803 public boolean topAmountNeedsClipping() {
2804 if (isGroupExpanded()) {
2805 return true;
2806 }
2807 if (isGroupExpansionChanging()) {
2808 return true;
2809 }
2810 if (getShowingLayout().shouldClipToRounding(true /* topRounded */,
2811 false /* bottomRounded */)) {
2812 return true;
2813 }
2814 if (mGuts != null && mGuts.getAlpha() != 0.0f) {
2815 return true;
2816 }
2817 return false;
2818 }
2819
2820 @Override
Selim Cinek515b2032017-11-15 10:20:19 -08002821 protected boolean childNeedsClipping(View child) {
2822 if (child instanceof NotificationContentView) {
2823 NotificationContentView contentView = (NotificationContentView) child;
2824 if (isClippingNeeded()) {
2825 return true;
Selim Cinek86bfcee2018-01-17 11:00:47 -08002826 } else if (!hasNoRounding()
2827 && contentView.shouldClipToRounding(getCurrentTopRoundness() != 0.0f,
2828 getCurrentBottomRoundness() != 0.0f)) {
Selim Cinek515b2032017-11-15 10:20:19 -08002829 return true;
2830 }
2831 } else if (child == mChildrenContainer) {
Selim Cinekc25989e2018-02-16 16:42:14 -08002832 if (!mChildIsExpanding && (isClippingNeeded() || !hasNoRounding())) {
Selim Cinek515b2032017-11-15 10:20:19 -08002833 return true;
2834 }
2835 } else if (child instanceof NotificationGuts) {
Selim Cinekb95fd182017-12-21 13:03:32 -08002836 return !hasNoRounding();
Selim Cinek515b2032017-11-15 10:20:19 -08002837 }
2838 return super.childNeedsClipping(child);
2839 }
2840
2841 @Override
Selim Cinek2871bef2017-11-22 08:40:00 -08002842 protected void applyRoundness() {
2843 super.applyRoundness();
2844 applyChildrenRoundness();
2845 }
2846
2847 private void applyChildrenRoundness() {
2848 if (mIsSummaryWithChildren) {
2849 mChildrenContainer.setCurrentBottomRoundness(getCurrentBottomRoundness());
2850 }
2851 }
2852
2853 @Override
Selim Cinek515b2032017-11-15 10:20:19 -08002854 public Path getCustomClipPath(View child) {
2855 if (child instanceof NotificationGuts) {
Selim Cinek2871bef2017-11-22 08:40:00 -08002856 return getClipPath(true, /* ignoreTranslation */
2857 false /* clipRoundedToBottom */);
2858 }
2859 if (child instanceof NotificationChildrenContainer) {
2860 return getClipPath(false, /* ignoreTranslation */
2861 true /* clipRoundedToBottom */);
Selim Cinek515b2032017-11-15 10:20:19 -08002862 }
2863 return super.getCustomClipPath(child);
2864 }
2865
Selim Cinekb95fd182017-12-21 13:03:32 -08002866 private boolean hasNoRounding() {
2867 return getCurrentBottomRoundness() == 0.0f && getCurrentTopRoundness() == 0.0f;
Selim Cinek0fe07392017-11-09 13:26:34 -08002868 }
2869
Adrian Roos6f6e1592017-05-02 16:22:53 -07002870 public boolean isShowingAmbient() {
2871 return mShowAmbient;
2872 }
2873
Selim Cinekd127d792016-11-01 19:11:41 -07002874 public void setAboveShelf(boolean aboveShelf) {
Selim Cinek5cf1d052017-06-01 17:36:46 -07002875 boolean wasAboveShelf = isAboveShelf();
Selim Cinekd127d792016-11-01 19:11:41 -07002876 mAboveShelf = aboveShelf;
Selim Cinek5cf1d052017-06-01 17:36:46 -07002877 if (isAboveShelf() != wasAboveShelf) {
2878 mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
2879 }
Selim Cinekd127d792016-11-01 19:11:41 -07002880 }
2881
Selim Cinekd4776a52017-02-14 18:50:16 -08002882 public static class NotificationViewState extends ExpandableViewState {
Selim Cinekbbcebde2016-11-09 18:28:20 -08002883
2884 private final StackScrollState mOverallState;
Selim Cinek0242fbb2016-10-19 13:38:32 -07002885
Selim Cinekbbcebde2016-11-09 18:28:20 -08002886
2887 private NotificationViewState(StackScrollState stackScrollState) {
2888 mOverallState = stackScrollState;
2889 }
2890
2891 @Override
2892 public void applyToView(View view) {
Selim Cinekbbcebde2016-11-09 18:28:20 -08002893 if (view instanceof ExpandableNotificationRow) {
2894 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
Selim Cinek2627d722018-01-19 12:16:49 -08002895 if (row.isExpandAnimationRunning()) {
2896 return;
2897 }
Selim Cinekc25989e2018-02-16 16:42:14 -08002898 handleFixedTranslationZ(row);
Selim Cinek2627d722018-01-19 12:16:49 -08002899 super.applyToView(view);
Selim Cinekbbcebde2016-11-09 18:28:20 -08002900 row.applyChildrenState(mOverallState);
2901 }
2902 }
Selim Cinek0cfbef42016-11-09 19:06:36 -08002903
Selim Cinekc25989e2018-02-16 16:42:14 -08002904 private void handleFixedTranslationZ(ExpandableNotificationRow row) {
2905 if (row.hasExpandingChild()) {
2906 zTranslation = row.getTranslationZ();
2907 clipTopAmount = row.getClipTopAmount();
2908 }
2909 }
2910
Selim Cinek0cfbef42016-11-09 19:06:36 -08002911 @Override
Selim Cinek2b549f42016-11-22 16:38:51 -08002912 protected void onYTranslationAnimationFinished(View view) {
2913 super.onYTranslationAnimationFinished(view);
Selim Cinekd4776a52017-02-14 18:50:16 -08002914 if (view instanceof ExpandableNotificationRow) {
2915 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
2916 if (row.isHeadsUpAnimatingAway()) {
2917 row.setHeadsUpAnimatingAway(false);
2918 }
Selim Cinek0cfbef42016-11-09 19:06:36 -08002919 }
2920 }
2921
2922 @Override
2923 public void animateTo(View child, AnimationProperties properties) {
Selim Cinek0cfbef42016-11-09 19:06:36 -08002924 if (child instanceof ExpandableNotificationRow) {
2925 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
Selim Cinek2627d722018-01-19 12:16:49 -08002926 if (row.isExpandAnimationRunning()) {
2927 return;
2928 }
Selim Cinekc25989e2018-02-16 16:42:14 -08002929 handleFixedTranslationZ(row);
Selim Cinek2627d722018-01-19 12:16:49 -08002930 super.animateTo(child, properties);
Selim Cinek0cfbef42016-11-09 19:06:36 -08002931 row.startChildAnimation(mOverallState, properties);
2932 }
2933 }
Selim Cinekbbcebde2016-11-09 18:28:20 -08002934 }
Selim Cinek817abe72017-05-24 11:08:55 -07002935
2936 @VisibleForTesting
2937 protected void setChildrenContainer(NotificationChildrenContainer childrenContainer) {
2938 mChildrenContainer = childrenContainer;
2939 }
Geoffrey Pitsch409db272017-08-28 14:51:52 +00002940
Julia Reynoldsfc640012018-02-21 12:25:27 -05002941 @VisibleForTesting
2942 protected void setPrivateLayout(NotificationContentView privateLayout) {
2943 mPrivateLayout = privateLayout;
2944 }
2945
2946 @VisibleForTesting
2947 protected void setPublicLayout(NotificationContentView publicLayout) {
2948 mPublicLayout = publicLayout;
2949 }
2950
Geoffrey Pitsch409db272017-08-28 14:51:52 +00002951 /**
2952 * Equivalent to View.OnLongClickListener with coordinates
2953 */
2954 public interface LongPressListener {
2955 /**
2956 * Equivalent to {@link View.OnLongClickListener#onLongClick(View)} with coordinates
2957 * @return whether the longpress was handled
2958 */
2959 boolean onLongPress(View v, int x, int y, MenuItem item);
2960 }
Julia Reynoldsb5867452018-02-28 16:31:35 -05002961
2962 /**
2963 * Equivalent to View.OnClickListener with coordinates
2964 */
2965 public interface OnAppOpsClickListener {
2966 /**
2967 * Equivalent to {@link View.OnClickListener#onClick(View)} with coordinates
2968 * @return whether the click was handled
2969 */
2970 boolean onClick(View v, int x, int y, MenuItem item);
2971 }
Rohan Shah4ed1b2a2018-03-30 13:26:01 -07002972
2973 /**
2974 * Background task for executing IPCs to check if the notification is a system notification. The
2975 * output is used for both the blocking helper and the notification info.
2976 */
2977 private class SystemNotificationAsyncTask extends AsyncTask<Void, Void, Boolean> {
2978
2979 @Override
2980 protected Boolean doInBackground(Void... voids) {
2981 return isSystemNotification(mContext, mStatusBarNotification);
2982 }
2983
2984 @Override
2985 protected void onPostExecute(Boolean result) {
Julia Reynoldsaa96cf32018-04-17 09:09:04 -04002986 if (mEntry != null) {
2987 mEntry.mIsSystemNotification = result;
2988 }
Rohan Shah4ed1b2a2018-03-30 13:26:01 -07002989 }
2990 }
Chris Wren51c75102013-07-16 20:49:17 -04002991}