blob: 5173176ffa8f3e6bf36cf7b6e60208d60d3cb545 [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
Mady Mellor4b80b102016-01-22 08:03:58 -080019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
Mady Mellor4b80b102016-01-22 08:03:58 -080021import android.animation.ObjectAnimator;
Mady Mellor4b80b102016-01-22 08:03:58 -080022import android.animation.ValueAnimator.AnimatorUpdateListener;
Selim Cinekddf1b392016-05-27 16:33:10 -070023import android.annotation.Nullable;
Chris Wren51c75102013-07-16 20:49:17 -040024import android.content.Context;
Selim Cinekcab4a602014-09-03 14:47:57 +020025import android.graphics.drawable.AnimatedVectorDrawable;
26import android.graphics.drawable.AnimationDrawable;
Selim Cinekb5605e52015-02-20 18:21:41 +010027import android.graphics.drawable.ColorDrawable;
Selim Cinekcab4a602014-09-03 14:47:57 +020028import android.graphics.drawable.Drawable;
Selim Cinekda42d652015-12-04 15:51:16 -080029import android.os.Build;
Selim Cineke9bad242016-06-15 11:46:37 -070030import android.os.Bundle;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020031import android.service.notification.StatusBarNotification;
Chris Wren51c75102013-07-16 20:49:17 -040032import android.util.AttributeSet;
Mady Mellorb0a82462016-04-30 17:31:02 -070033import android.util.FloatProperty;
34import android.util.Property;
Selim Cinek01af3342016-02-09 19:25:31 -080035import android.view.LayoutInflater;
Selim Cinek6183d122016-01-14 18:48:41 -080036import android.view.MotionEvent;
Selim Cinekeaa29ca2015-11-23 13:51:13 -080037import android.view.NotificationHeaderView;
Dan Sandlera5e0f412014-01-23 15:11:54 -050038import android.view.View;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020039import android.view.ViewStub;
Jorim Jaggife40f7d2014-04-28 15:20:04 +020040import android.view.accessibility.AccessibilityEvent;
Selim Cineke9bad242016-06-15 11:46:37 -070041import android.view.accessibility.AccessibilityNodeInfo;
Selim Cinek98713a42015-09-21 15:47:20 +020042import android.widget.Chronometer;
Selim Cinekcab4a602014-09-03 14:47:57 +020043import android.widget.ImageView;
Selim Cinekb5605e52015-02-20 18:21:41 +010044
Chris Wren698b1702016-05-23 11:16:32 -040045import com.android.internal.logging.MetricsLogger;
Tamas Berghammer383db5eb2016-06-22 15:21:38 +010046import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Selim Cinek4bb59342016-04-08 19:29:35 -070047import com.android.internal.util.NotificationColorUtil;
Dan Sandlera5e0f412014-01-23 15:11:54 -050048import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070049import com.android.systemui.classifier.FalsingManager;
Selim Cinekc897bd32016-03-18 17:32:31 -070050import com.android.systemui.statusbar.notification.HybridNotificationView;
Selim Cinekb5605e52015-02-20 18:21:41 +010051import com.android.systemui.statusbar.phone.NotificationGroupManager;
Selim Cinek31aada42015-12-18 17:51:15 -080052import com.android.systemui.statusbar.policy.HeadsUpManager;
Selim Cinekb5605e52015-02-20 18:21:41 +010053import com.android.systemui.statusbar.stack.NotificationChildrenContainer;
Selim Cineke9bad242016-06-15 11:46:37 -070054import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Selim Cinekb5605e52015-02-20 18:21:41 +010055import com.android.systemui.statusbar.stack.StackScrollState;
56import com.android.systemui.statusbar.stack.StackStateAnimator;
57import com.android.systemui.statusbar.stack.StackViewState;
58
Mady Mellor4b80b102016-01-22 08:03:58 -080059import java.util.ArrayList;
Selim Cinekb5605e52015-02-20 18:21:41 +010060import java.util.List;
Dan Sandlera5e0f412014-01-23 15:11:54 -050061
Jorim Jaggi4222d9a2014-04-23 16:13:15 +020062public class ExpandableNotificationRow extends ActivatableNotificationView {
Selim Cinekb5605e52015-02-20 18:21:41 +010063
64 private static final int DEFAULT_DIVIDER_ALPHA = 0x29;
65 private static final int COLORED_DIVIDER_ALPHA = 0x7B;
Selim Cinek01af3342016-02-09 19:25:31 -080066 private int mNotificationMinHeightLegacy;
67 private int mMaxHeadsUpHeightLegacy;
68 private int mMaxHeadsUpHeight;
69 private int mNotificationMinHeight;
70 private int mNotificationMaxHeight;
Mady Mellorb0a82462016-04-30 17:31:02 -070071 private int mIncreasedPaddingBetweenElements;
Chris Wren51c75102013-07-16 20:49:17 -040072
Selim Cinek1685e632014-04-08 02:27:49 +020073 /** Does this row contain layouts that can adapt to row expansion */
Chris Wren51c75102013-07-16 20:49:17 -040074 private boolean mExpandable;
Selim Cinek1685e632014-04-08 02:27:49 +020075 /** Has the user actively changed the expansion state of this row */
76 private boolean mHasUserChangedExpansion;
77 /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */
Chris Wren51c75102013-07-16 20:49:17 -040078 private boolean mUserExpanded;
Selim Cinek31aada42015-12-18 17:51:15 -080079
80 /**
81 * Has this notification been expanded while it was pinned
82 */
83 private boolean mExpandedWhenPinned;
Selim Cinek1685e632014-04-08 02:27:49 +020084 /** Is the user touching this row */
Chris Wren51c75102013-07-16 20:49:17 -040085 private boolean mUserLocked;
Selim Cinek1685e632014-04-08 02:27:49 +020086 /** Are we showing the "public" version */
Dan Sandlera5e0f412014-01-23 15:11:54 -050087 private boolean mShowingPublic;
Jorim Jaggiae441282014-08-01 02:45:18 +020088 private boolean mSensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -080089 private boolean mSensitiveHiddenInGeneral;
Jorim Jaggiae441282014-08-01 02:45:18 +020090 private boolean mShowingPublicInitialized;
Selim Cinek60122be2015-04-15 18:16:50 -070091 private boolean mHideSensitiveForIntrinsicHeight;
Chris Wren51c75102013-07-16 20:49:17 -040092
Selim Cinek1685e632014-04-08 02:27:49 +020093 /**
94 * Is this notification expanded by the system. The expansion state can be overridden by the
95 * user expansion.
96 */
97 private boolean mIsSystemExpanded;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +020098
99 /**
Selim Cinek83bc7832015-10-22 13:26:54 -0700100 * Whether the notification is on the keyguard and the expansion is disabled.
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200101 */
Selim Cinek83bc7832015-10-22 13:26:54 -0700102 private boolean mOnKeyguard;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200103
Mady Mellorb0a82462016-04-30 17:31:02 -0700104 private Animator mTranslateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -0800105 private ArrayList<View> mTranslateableViews;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200106 private NotificationContentView mPublicLayout;
107 private NotificationContentView mPrivateLayout;
Selim Cinek1685e632014-04-08 02:27:49 +0200108 private int mMaxExpandHeight;
Selim Cinek8d490d42015-04-10 00:05:50 -0700109 private int mHeadsUpHeight;
Selim Cinek863834b2014-05-20 04:20:25 +0200110 private View mVetoButton;
Selim Cinek4bb59342016-04-08 19:29:35 -0700111 private int mNotificationColor;
Chris Wren78403d72014-07-28 10:23:24 +0100112 private ExpansionLogger mLogger;
113 private String mLoggingKey;
Mady Mellor4b80b102016-01-22 08:03:58 -0800114 private NotificationSettingsIconRow mSettingsIconRow;
Selim Cinek8d490d42015-04-10 00:05:50 -0700115 private NotificationGuts mGuts;
Selim Cinekda42d652015-12-04 15:51:16 -0800116 private NotificationData.Entry mEntry;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200117 private StatusBarNotification mStatusBarNotification;
Mady Mellor3fd273e2016-03-15 21:08:14 -0700118 private String mAppName;
Selim Cinek1a521f32014-11-03 17:39:29 +0100119 private boolean mIsHeadsUp;
Selim Cinek98713a42015-09-21 15:47:20 +0200120 private boolean mLastChronometerRunning = true;
Selim Cinekb5605e52015-02-20 18:21:41 +0100121 private ViewStub mChildrenContainerStub;
122 private NotificationGroupManager mGroupManager;
Selim Cinekb5605e52015-02-20 18:21:41 +0100123 private boolean mChildrenExpanded;
Selim Cinek263398f2015-10-21 17:40:23 -0700124 private boolean mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100125 private NotificationChildrenContainer mChildrenContainer;
Mady Mellor4b80b102016-01-22 08:03:58 -0800126 private ViewStub mSettingsIconRowStub;
Selim Cinekab29aeb2015-02-20 18:18:32 +0100127 private ViewStub mGutsStub;
Selim Cinekb5605e52015-02-20 18:21:41 +0100128 private boolean mIsSystemChildExpanded;
Selim Cinek684a4422015-04-15 16:18:39 -0700129 private boolean mIsPinned;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700130 private FalsingManager mFalsingManager;
Selim Cinek31aada42015-12-18 17:51:15 -0800131 private HeadsUpManager mHeadsUpManager;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200132
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700133 private boolean mJustClicked;
Selim Cinek5a175d92015-11-23 18:01:33 -0800134 private boolean mIconAnimationRunning;
Selim Cinek34d93b02015-10-22 12:30:38 -0700135 private boolean mShowNoBackground;
Selim Cinek388df6d2015-10-22 13:25:11 -0700136 private ExpandableNotificationRow mNotificationParent;
Selim Cinek570981d2015-12-01 11:37:01 -0800137 private OnExpandClickListener mOnExpandClickListener;
Mady Mellorb0a82462016-04-30 17:31:02 -0700138 private boolean mGroupExpansionChanging;
139
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800140 private OnClickListener mExpandClickListener = new OnClickListener() {
141 @Override
142 public void onClick(View v) {
Selim Cinek624c02db2015-12-14 21:00:02 -0800143 if (!mShowingPublic && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) {
Mady Mellor1a5d8ea2016-06-09 10:42:42 -0700144 mGroupExpansionChanging = true;
Chris Wren698b1702016-05-23 11:16:32 -0400145 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
146 boolean nowExpanded = mGroupManager.toggleGroupExpansion(mStatusBarNotification);
147 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400148 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_GROUP_EXPANDER,
149 nowExpanded);
150 logExpansionEvent(true /* userAction */, wasExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800151 } else {
Selim Cineke9bad242016-06-15 11:46:37 -0700152 if (v.isAccessibilityFocused()) {
153 mPrivateLayout.setFocusOnVisibilityChange();
154 }
Selim Cinek31aada42015-12-18 17:51:15 -0800155 boolean nowExpanded;
156 if (isPinned()) {
157 nowExpanded = !mExpandedWhenPinned;
158 mExpandedWhenPinned = nowExpanded;
159 } else {
160 nowExpanded = !isExpanded();
161 setUserExpanded(nowExpanded);
162 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800163 notifyHeightChanged(true);
Selim Cinek31aada42015-12-18 17:51:15 -0800164 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400165 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_EXPANDER,
166 nowExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800167 }
168 }
169 };
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700170 private boolean mForceUnlocked;
Selim Cinek3f19f602016-05-02 18:01:56 -0700171 private boolean mDismissed;
172 private boolean mKeepInParent;
173 private boolean mRemoved;
Mady Mellorb0a82462016-04-30 17:31:02 -0700174 private static final Property<ExpandableNotificationRow, Float> TRANSLATE_CONTENT =
175 new FloatProperty<ExpandableNotificationRow>("translate") {
176 @Override
177 public void setValue(ExpandableNotificationRow object, float value) {
178 object.setTranslation(value);
179 }
180
181 @Override
182 public Float get(ExpandableNotificationRow object) {
183 return object.getTranslation();
184 }
185 };
Selim Cinekddf1b392016-05-27 16:33:10 -0700186 private OnClickListener mOnClickListener;
Selim Cinek73cf02a2016-06-17 13:08:00 -0700187 private boolean mHeadsupDisappearRunning;
Selim Cineke9bad242016-06-15 11:46:37 -0700188 private View mChildAfterViewWhenDismissed;
189 private View mGroupParentWhenDismissed;
190 private boolean mRefocusOnDismiss;
Mady Mellorb0a82462016-04-30 17:31:02 -0700191
192 public boolean isGroupExpansionChanging() {
193 if (isChildInGroup()) {
194 return mNotificationParent.isGroupExpansionChanging();
195 }
196 return mGroupExpansionChanging;
197 }
198
199 public void setGroupExpansionChanging(boolean changing) {
200 mGroupExpansionChanging = changing;
201 }
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700202
Adrian Roos599be342016-06-13 14:54:39 -0700203 @Override
204 public void setActualHeightAnimating(boolean animating) {
205 if (mPrivateLayout != null) {
206 mPrivateLayout.setContentHeightAnimating(animating);
207 }
208 }
209
Selim Cinek8d490d42015-04-10 00:05:50 -0700210 public NotificationContentView getPrivateLayout() {
211 return mPrivateLayout;
212 }
213
214 public NotificationContentView getPublicLayout() {
215 return mPublicLayout;
216 }
217
Selim Cinekcab4a602014-09-03 14:47:57 +0200218 public void setIconAnimationRunning(boolean running) {
219 setIconAnimationRunning(running, mPublicLayout);
220 setIconAnimationRunning(running, mPrivateLayout);
Selim Cinek5a175d92015-11-23 18:01:33 -0800221 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700222 setIconAnimationRunningForChild(running, mChildrenContainer.getHeaderView());
Selim Cinek5a175d92015-11-23 18:01:33 -0800223 List<ExpandableNotificationRow> notificationChildren =
224 mChildrenContainer.getNotificationChildren();
225 for (int i = 0; i < notificationChildren.size(); i++) {
226 ExpandableNotificationRow child = notificationChildren.get(i);
227 child.setIconAnimationRunning(running);
228 }
229 }
230 mIconAnimationRunning = running;
Selim Cinekcab4a602014-09-03 14:47:57 +0200231 }
232
233 private void setIconAnimationRunning(boolean running, NotificationContentView layout) {
234 if (layout != null) {
235 View contractedChild = layout.getContractedChild();
236 View expandedChild = layout.getExpandedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -0700237 View headsUpChild = layout.getHeadsUpChild();
Selim Cinekcab4a602014-09-03 14:47:57 +0200238 setIconAnimationRunningForChild(running, contractedChild);
239 setIconAnimationRunningForChild(running, expandedChild);
Selim Cinek8d490d42015-04-10 00:05:50 -0700240 setIconAnimationRunningForChild(running, headsUpChild);
Selim Cinekcab4a602014-09-03 14:47:57 +0200241 }
242 }
243
244 private void setIconAnimationRunningForChild(boolean running, View child) {
245 if (child != null) {
246 ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon);
247 setIconRunning(icon, running);
248 ImageView rightIcon = (ImageView) child.findViewById(
249 com.android.internal.R.id.right_icon);
250 setIconRunning(rightIcon, running);
251 }
252 }
253
254 private void setIconRunning(ImageView imageView, boolean running) {
255 if (imageView != null) {
256 Drawable drawable = imageView.getDrawable();
257 if (drawable instanceof AnimationDrawable) {
258 AnimationDrawable animationDrawable = (AnimationDrawable) drawable;
259 if (running) {
260 animationDrawable.start();
261 } else {
262 animationDrawable.stop();
263 }
264 } else if (drawable instanceof AnimatedVectorDrawable) {
265 AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable;
266 if (running) {
267 animationDrawable.start();
268 } else {
269 animationDrawable.stop();
270 }
271 }
272 }
273 }
274
Selim Cinekda42d652015-12-04 15:51:16 -0800275 public void onNotificationUpdated(NotificationData.Entry entry) {
276 mEntry = entry;
277 mStatusBarNotification = entry.notification;
Adrian Roosb88b1a12015-12-09 18:51:05 -0800278 mPrivateLayout.onNotificationUpdated(entry);
279 mPublicLayout.onNotificationUpdated(entry);
Selim Cinek757d8792016-01-28 16:21:08 -0800280 mShowingPublicInitialized = false;
Selim Cinek4bb59342016-04-08 19:29:35 -0700281 updateNotificationColor();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800282 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700283 mChildrenContainer.recreateNotificationHeader(mExpandClickListener, mEntry.notification);
Selim Cinekc897bd32016-03-18 17:32:31 -0700284 mChildrenContainer.onNotificationUpdated();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800285 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800286 if (mIconAnimationRunning) {
287 setIconAnimationRunning(true);
288 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800289 if (mNotificationParent != null) {
290 mNotificationParent.updateChildrenHeaderAppearance();
291 }
Selim Cinek263398f2015-10-21 17:40:23 -0700292 onChildrenCountChanged();
Selim Cinek624c02db2015-12-14 21:00:02 -0800293 // The public layouts expand button is always visible
294 mPublicLayout.updateExpandButtons(true);
Selim Cinekda42d652015-12-04 15:51:16 -0800295 updateLimits();
296 }
297
298 private void updateLimits() {
Selim Cineka1744872016-03-11 15:36:06 -0800299 updateLimitsForView(mPrivateLayout);
300 updateLimitsForView(mPublicLayout);
301 }
302
303 private void updateLimitsForView(NotificationContentView layout) {
304 boolean customView = layout.getContractedChild().getId()
Selim Cinekda42d652015-12-04 15:51:16 -0800305 != com.android.internal.R.id.status_bar_latest_event_content;
306 boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N;
307 int minHeight = customView && beforeN && !mIsSummaryWithChildren ?
308 mNotificationMinHeightLegacy : mNotificationMinHeight;
Selim Cineka1744872016-03-11 15:36:06 -0800309 boolean headsUpCustom = layout.getHeadsUpChild() != null &&
310 layout.getHeadsUpChild().getId()
311 != com.android.internal.R.id.status_bar_latest_event_content;
Selim Cinek77019c72015-12-09 10:18:02 -0800312 int headsUpheight = headsUpCustom && beforeN ? mMaxHeadsUpHeightLegacy
313 : mMaxHeadsUpHeight;
Selim Cineka1744872016-03-11 15:36:06 -0800314 layout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200315 }
316
317 public StatusBarNotification getStatusBarNotification() {
318 return mStatusBarNotification;
319 }
320
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700321 public boolean isHeadsUp() {
322 return mIsHeadsUp;
323 }
324
Selim Cinek1a521f32014-11-03 17:39:29 +0100325 public void setHeadsUp(boolean isHeadsUp) {
Selim Cinekc80fdb12015-04-13 15:09:08 -0700326 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek1a521f32014-11-03 17:39:29 +0100327 mIsHeadsUp = isHeadsUp;
Selim Cinek8d490d42015-04-10 00:05:50 -0700328 mPrivateLayout.setHeadsUp(isHeadsUp);
Selim Cinekb41b2f62016-04-26 14:03:29 -0700329 if (mIsSummaryWithChildren) {
330 // The overflow might change since we allow more lines as HUN.
331 mChildrenContainer.updateGroupOverflow();
332 }
Selim Cinekc80fdb12015-04-13 15:09:08 -0700333 if (intrinsicBefore != getIntrinsicHeight()) {
334 notifyHeightChanged(false /* needsAnimation */);
335 }
Selim Cinek1a521f32014-11-03 17:39:29 +0100336 }
337
Selim Cinekb5605e52015-02-20 18:21:41 +0100338 public void setGroupManager(NotificationGroupManager groupManager) {
339 mGroupManager = groupManager;
Selim Cinek83bc7832015-10-22 13:26:54 -0700340 mPrivateLayout.setGroupManager(groupManager);
Selim Cinekb5605e52015-02-20 18:21:41 +0100341 }
342
Adrian Roosb88b1a12015-12-09 18:51:05 -0800343 public void setRemoteInputController(RemoteInputController r) {
344 mPrivateLayout.setRemoteInputController(r);
345 }
346
Mady Mellor3fd273e2016-03-15 21:08:14 -0700347 public void setAppName(String appName) {
348 mAppName = appName;
349 if (mSettingsIconRow != null) {
350 mSettingsIconRow.setAppName(mAppName);
351 }
352 }
353
Selim Cinekb5605e52015-02-20 18:21:41 +0100354 public void addChildNotification(ExpandableNotificationRow row) {
355 addChildNotification(row, -1);
356 }
357
358 /**
359 * Add a child notification to this view.
360 *
361 * @param row the row to add
362 * @param childIndex the index to add it at, if -1 it will be added at the end
363 */
364 public void addChildNotification(ExpandableNotificationRow row, int childIndex) {
365 if (mChildrenContainer == null) {
366 mChildrenContainerStub.inflate();
367 }
368 mChildrenContainer.addNotification(row, childIndex);
Selim Cinek263398f2015-10-21 17:40:23 -0700369 onChildrenCountChanged();
370 row.setIsChildInGroup(true, this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100371 }
372
373 public void removeChildNotification(ExpandableNotificationRow row) {
374 if (mChildrenContainer != null) {
375 mChildrenContainer.removeNotification(row);
376 }
Selim Cinek263398f2015-10-21 17:40:23 -0700377 onChildrenCountChanged();
378 row.setIsChildInGroup(false, null);
379 }
380
381 public boolean isChildInGroup() {
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700382 return mNotificationParent != null;
Selim Cinek263398f2015-10-21 17:40:23 -0700383 }
384
Selim Cinek388df6d2015-10-22 13:25:11 -0700385 public ExpandableNotificationRow getNotificationParent() {
386 return mNotificationParent;
387 }
388
Selim Cinek263398f2015-10-21 17:40:23 -0700389 /**
390 * @param isChildInGroup Is this notification now in a group
391 * @param parent the new parent notification
392 */
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700393 public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {;
394 boolean childInGroup = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup;
395 mNotificationParent = childInGroup ? parent : null;
396 mPrivateLayout.setIsChildInGroup(childInGroup);
Mady Mellorc7d65b42016-05-04 11:44:57 -0400397 resetBackgroundAlpha();
Mady Mellorb0a82462016-04-30 17:31:02 -0700398 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -0700399 updateClickAndFocus();
Mady Mellorb0a82462016-04-30 17:31:02 -0700400 if (mNotificationParent != null) {
401 mNotificationParent.updateBackgroundForGroupState();
402 }
Selim Cinek34d93b02015-10-22 12:30:38 -0700403 }
404
405 @Override
Selim Cinek72109472016-01-15 16:33:22 -0800406 public boolean onTouchEvent(MotionEvent event) {
407 if (event.getActionMasked() != MotionEvent.ACTION_DOWN
408 || !isChildInGroup() || isGroupExpanded()) {
409 return super.onTouchEvent(event);
410 } else {
411 return false;
412 }
413 }
414
415 @Override
Mady Mellorf0625802016-02-11 18:03:48 -0800416 protected boolean handleSlideBack() {
417 if (mSettingsIconRow != null && mSettingsIconRow.isVisible()) {
418 animateTranslateNotification(0 /* targetLeft */);
419 return true;
420 }
421 return false;
422 }
423
424 @Override
Selim Cinek34d93b02015-10-22 12:30:38 -0700425 protected boolean shouldHideBackground() {
426 return super.shouldHideBackground() || mShowNoBackground;
Selim Cinek263398f2015-10-21 17:40:23 -0700427 }
428
429 @Override
430 public boolean isSummaryWithChildren() {
431 return mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100432 }
433
434 @Override
435 public boolean areChildrenExpanded() {
436 return mChildrenExpanded;
437 }
438
439 public List<ExpandableNotificationRow> getNotificationChildren() {
440 return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren();
441 }
442
Selim Cinekeef84282015-10-30 16:28:00 -0700443 public int getNumberOfNotificationChildren() {
444 if (mChildrenContainer == null) {
445 return 0;
446 }
447 return mChildrenContainer.getNotificationChildren().size();
448 }
449
Selim Cinekb5605e52015-02-20 18:21:41 +0100450 /**
451 * Apply the order given in the list to the children.
452 *
453 * @param childOrder the new list order
454 * @return whether the list order has changed
455 */
456 public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder) {
457 return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder);
458 }
459
460 public void getChildrenStates(StackScrollState resultState) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700461 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100462 StackViewState parentState = resultState.getViewStateForView(this);
463 mChildrenContainer.getState(resultState, parentState);
464 }
465 }
466
467 public void applyChildrenState(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700468 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100469 mChildrenContainer.applyState(state);
470 }
471 }
472
473 public void prepareExpansionChanged(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700474 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100475 mChildrenContainer.prepareExpansionChanged(state);
476 }
477 }
478
479 public void startChildAnimation(StackScrollState finalState,
Selim Cinek99695592016-01-12 17:51:35 -0800480 StackStateAnimator stateAnimator, long delay, long duration) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700481 if (mIsSummaryWithChildren) {
Selim Cinek99695592016-01-12 17:51:35 -0800482 mChildrenContainer.startAnimationToState(finalState, stateAnimator, delay,
Selim Cinekb5605e52015-02-20 18:21:41 +0100483 duration);
484 }
485 }
486
487 public ExpandableNotificationRow getViewAtPosition(float y) {
Selim Cinek43d30f02016-03-04 10:51:32 -0800488 if (!mIsSummaryWithChildren || !mChildrenExpanded) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100489 return this;
490 } else {
491 ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y);
492 return view == null ? this : view;
493 }
494 }
495
Selim Cinekab29aeb2015-02-20 18:18:32 +0100496 public NotificationGuts getGuts() {
497 return mGuts;
498 }
499
Selim Cinek684a4422015-04-15 16:18:39 -0700500 /**
501 * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this
502 * the notification will be rendered on top of the screen.
503 *
504 * @param pinned whether it is pinned
505 */
506 public void setPinned(boolean pinned) {
Selim Cinekdef35a82016-05-03 15:52:51 -0700507 int intrinsicHeight = getIntrinsicHeight();
Selim Cinek684a4422015-04-15 16:18:39 -0700508 mIsPinned = pinned;
Selim Cinekdef35a82016-05-03 15:52:51 -0700509 if (intrinsicHeight != getIntrinsicHeight()) {
Selim Cinekbb42b7d2016-08-10 13:02:38 -0700510 notifyHeightChanged(false /* needsAnimation */);
Selim Cinekdef35a82016-05-03 15:52:51 -0700511 }
Selim Cinek31aada42015-12-18 17:51:15 -0800512 if (pinned) {
513 setIconAnimationRunning(true);
514 mExpandedWhenPinned = false;
515 } else if (mExpandedWhenPinned) {
516 setUserExpanded(true);
517 }
Selim Cinek98713a42015-09-21 15:47:20 +0200518 setChronometerRunning(mLastChronometerRunning);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700519 }
520
Selim Cinek684a4422015-04-15 16:18:39 -0700521 public boolean isPinned() {
522 return mIsPinned;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700523 }
524
Selim Cinek31aada42015-12-18 17:51:15 -0800525 /**
526 * @param atLeastMinHeight should the value returned be at least the minimum height.
527 * Used to avoid cyclic calls
528 * @return the height of the heads up notification when pinned
529 */
530 public int getPinnedHeadsUpHeight(boolean atLeastMinHeight) {
Selim Cinek77019c72015-12-09 10:18:02 -0800531 if (mIsSummaryWithChildren) {
532 return mChildrenContainer.getIntrinsicHeight();
533 }
Selim Cinek31aada42015-12-18 17:51:15 -0800534 if(mExpandedWhenPinned) {
535 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
536 } else if (atLeastMinHeight) {
Selim Cinek567e8452016-03-24 10:54:56 -0700537 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek31aada42015-12-18 17:51:15 -0800538 } else {
539 return mHeadsUpHeight;
540 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700541 }
542
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700543 /**
544 * Mark whether this notification was just clicked, i.e. the user has just clicked this
545 * notification in this frame.
546 */
547 public void setJustClicked(boolean justClicked) {
548 mJustClicked = justClicked;
549 }
550
551 /**
552 * @return true if this notification has been clicked in this frame, false otherwise
553 */
554 public boolean wasJustClicked() {
555 return mJustClicked;
556 }
557
Selim Cinek98713a42015-09-21 15:47:20 +0200558 public void setChronometerRunning(boolean running) {
559 mLastChronometerRunning = running;
560 setChronometerRunning(running, mPrivateLayout);
561 setChronometerRunning(running, mPublicLayout);
562 if (mChildrenContainer != null) {
563 List<ExpandableNotificationRow> notificationChildren =
564 mChildrenContainer.getNotificationChildren();
565 for (int i = 0; i < notificationChildren.size(); i++) {
566 ExpandableNotificationRow child = notificationChildren.get(i);
567 child.setChronometerRunning(running);
568 }
569 }
570 }
571
572 private void setChronometerRunning(boolean running, NotificationContentView layout) {
573 if (layout != null) {
574 running = running || isPinned();
575 View contractedChild = layout.getContractedChild();
576 View expandedChild = layout.getExpandedChild();
577 View headsUpChild = layout.getHeadsUpChild();
578 setChronometerRunningForChild(running, contractedChild);
579 setChronometerRunningForChild(running, expandedChild);
580 setChronometerRunningForChild(running, headsUpChild);
581 }
582 }
583
584 private void setChronometerRunningForChild(boolean running, View child) {
585 if (child != null) {
586 View chronometer = child.findViewById(com.android.internal.R.id.chronometer);
587 if (chronometer instanceof Chronometer) {
588 ((Chronometer) chronometer).setStarted(running);
589 }
590 }
591 }
592
Selim Cinekea4bef72015-12-02 15:51:10 -0800593 public NotificationHeaderView getNotificationHeader() {
Mady Mellorb0a82462016-04-30 17:31:02 -0700594 if (mIsSummaryWithChildren) {
595 return mChildrenContainer.getHeaderView();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700596 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800597 return mPrivateLayout.getNotificationHeader();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700598 }
599
Selim Cinek34eda5e2016-02-18 17:10:43 -0800600 private NotificationHeaderView getVisibleNotificationHeader() {
Selim Cinekaa3901a2016-08-05 11:04:37 -0700601 if (mIsSummaryWithChildren && !mShowingPublic) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700602 return mChildrenContainer.getHeaderView();
Selim Cinek34eda5e2016-02-18 17:10:43 -0800603 }
604 return getShowingLayout().getVisibleNotificationHeader();
605 }
606
Selim Cinek570981d2015-12-01 11:37:01 -0800607 public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) {
608 mOnExpandClickListener = onExpandClickListener;
609 }
610
Selim Cinekddf1b392016-05-27 16:33:10 -0700611 @Override
612 public void setOnClickListener(@Nullable OnClickListener l) {
613 super.setOnClickListener(l);
614 mOnClickListener = l;
615 updateClickAndFocus();
616 }
617
618 private void updateClickAndFocus() {
619 boolean normalChild = !isChildInGroup() || isGroupExpanded();
620 boolean clickable = mOnClickListener != null && normalChild;
621 if (isFocusable() != normalChild) {
622 setFocusable(normalChild);
623 }
624 if (isClickable() != clickable) {
625 setClickable(clickable);
626 }
627 }
628
Selim Cinek31aada42015-12-18 17:51:15 -0800629 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
630 mHeadsUpManager = headsUpManager;
631 }
632
Selim Cinek01af3342016-02-09 19:25:31 -0800633 public void reInflateViews() {
634 initDimens();
635 if (mIsSummaryWithChildren) {
Selim Cinek01af3342016-02-09 19:25:31 -0800636 if (mChildrenContainer != null) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700637 mChildrenContainer.reInflateViews(mExpandClickListener, mEntry.notification);
Selim Cinek01af3342016-02-09 19:25:31 -0800638 }
639 }
640 if (mGuts != null) {
641 View oldGuts = mGuts;
642 int index = indexOfChild(oldGuts);
643 removeView(oldGuts);
644 mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate(
645 R.layout.notification_guts, this, false);
646 mGuts.setVisibility(oldGuts.getVisibility());
647 addView(mGuts, index);
648 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800649 if (mSettingsIconRow != null) {
650 View oldSettings = mSettingsIconRow;
651 int settingsIndex = indexOfChild(oldSettings);
652 removeView(oldSettings);
653 mSettingsIconRow = (NotificationSettingsIconRow) LayoutInflater.from(mContext).inflate(
654 R.layout.notification_settings_icon_row, this, false);
655 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
Mady Mellor3fd273e2016-03-15 21:08:14 -0700656 mSettingsIconRow.setAppName(mAppName);
Mady Mellor4b80b102016-01-22 08:03:58 -0800657 mSettingsIconRow.setVisibility(oldSettings.getVisibility());
658 addView(mSettingsIconRow, settingsIndex);
659
660 }
Selim Cinekde33a4a2016-02-11 16:43:41 -0800661 mPrivateLayout.reInflateViews();
662 mPublicLayout.reInflateViews();
Selim Cinek01af3342016-02-09 19:25:31 -0800663 }
664
Selim Cinekc3179332016-03-04 14:44:56 -0800665 public void setContentBackground(int customBackgroundColor, boolean animate,
666 NotificationContentView notificationContentView) {
667 if (getShowingLayout() == notificationContentView) {
668 setTintColor(customBackgroundColor, animate);
669 }
670 }
671
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700672 public void closeRemoteInput() {
673 mPrivateLayout.closeRemoteInput();
674 mPublicLayout.closeRemoteInput();
675 }
676
Selim Cinekc897bd32016-03-18 17:32:31 -0700677 /**
678 * Set by how much the single line view should be indented.
679 */
680 public void setSingleLineWidthIndention(int indention) {
681 mPrivateLayout.setSingleLineWidthIndention(indention);
682 }
683
684 public int getNotificationColor() {
Selim Cinek4bb59342016-04-08 19:29:35 -0700685 return mNotificationColor;
686 }
687
688 private void updateNotificationColor() {
689 mNotificationColor = NotificationColorUtil.resolveContrastColor(mContext,
690 getStatusBarNotification().getNotification().color);
Selim Cinekc897bd32016-03-18 17:32:31 -0700691 }
692
693 public HybridNotificationView getSingleLineView() {
694 return mPrivateLayout.getSingleLineView();
695 }
696
Selim Cinekf07d0622016-03-21 19:52:52 -0700697 public boolean isOnKeyguard() {
698 return mOnKeyguard;
699 }
700
Selim Cinekc1e389d2016-04-07 11:02:57 -0700701 public void removeAllChildren() {
702 List<ExpandableNotificationRow> notificationChildren
703 = mChildrenContainer.getNotificationChildren();
704 ArrayList<ExpandableNotificationRow> clonedList = new ArrayList<>(notificationChildren);
705 for (int i = 0; i < clonedList.size(); i++) {
706 ExpandableNotificationRow row = clonedList.get(i);
Selim Cinek3f19f602016-05-02 18:01:56 -0700707 if (row.keepInParent()) {
708 continue;
709 }
Selim Cinekc1e389d2016-04-07 11:02:57 -0700710 mChildrenContainer.removeNotification(row);
Selim Cinekc1e389d2016-04-07 11:02:57 -0700711 row.setIsChildInGroup(false, null);
712 }
713 onChildrenCountChanged();
714 }
715
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700716 public void setForceUnlocked(boolean forceUnlocked) {
717 mForceUnlocked = forceUnlocked;
718 if (mIsSummaryWithChildren) {
719 List<ExpandableNotificationRow> notificationChildren = getNotificationChildren();
720 for (ExpandableNotificationRow child : notificationChildren) {
721 child.setForceUnlocked(forceUnlocked);
722 }
723 }
724 }
725
Selim Cineke9bad242016-06-15 11:46:37 -0700726 public void setDismissed(boolean dismissed, boolean fromAccessibility) {
Selim Cinek3f19f602016-05-02 18:01:56 -0700727 mDismissed = dismissed;
Selim Cineke9bad242016-06-15 11:46:37 -0700728 mGroupParentWhenDismissed = mNotificationParent;
729 mRefocusOnDismiss = fromAccessibility;
730 mChildAfterViewWhenDismissed = null;
731 if (isChildInGroup()) {
732 List<ExpandableNotificationRow> notificationChildren =
733 mNotificationParent.getNotificationChildren();
734 int i = notificationChildren.indexOf(this);
735 if (i != -1 && i < notificationChildren.size() - 1) {
736 mChildAfterViewWhenDismissed = notificationChildren.get(i + 1);
737 }
738 }
Selim Cinek3f19f602016-05-02 18:01:56 -0700739 }
740
741 public boolean isDismissed() {
742 return mDismissed;
743 }
744
745 public boolean keepInParent() {
746 return mKeepInParent;
747 }
748
749 public void setKeepInParent(boolean keepInParent) {
750 mKeepInParent = keepInParent;
751 }
752
753 public boolean isRemoved() {
754 return mRemoved;
755 }
756
Adrian Roosd009ab12016-05-20 17:58:53 -0700757 public void setRemoved() {
758 mRemoved = true;
759
760 mPrivateLayout.setRemoved();
Selim Cinek3f19f602016-05-02 18:01:56 -0700761 }
762
Selim Cinekd1395642016-04-28 12:22:42 -0700763 public NotificationChildrenContainer getChildrenContainer() {
764 return mChildrenContainer;
765 }
766
Selim Cinek73cf02a2016-06-17 13:08:00 -0700767 public void setHeadsupDisappearRunning(boolean running) {
768 mHeadsupDisappearRunning = running;
769 mPrivateLayout.setHeadsupDisappearRunning(running);
770 }
771
Selim Cineke9bad242016-06-15 11:46:37 -0700772 public View getChildAfterViewWhenDismissed() {
773 return mChildAfterViewWhenDismissed;
774 }
775
776 public View getGroupParentWhenDismissed() {
777 return mGroupParentWhenDismissed;
778 }
779
Selim Cinek9e624e72016-07-20 13:46:49 -0700780 public void performDismiss() {
781 mVetoButton.performClick();
782 }
783
784 public void setOnDismissListener(OnClickListener listener) {
785 mVetoButton.setOnClickListener(listener);
786 }
787
Chris Wren78403d72014-07-28 10:23:24 +0100788 public interface ExpansionLogger {
789 public void logNotificationExpansion(String key, boolean userAction, boolean expanded);
790 }
Selim Cinek1685e632014-04-08 02:27:49 +0200791
Chris Wren51c75102013-07-16 20:49:17 -0400792 public ExpandableNotificationRow(Context context, AttributeSet attrs) {
793 super(context, attrs);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700794 mFalsingManager = FalsingManager.getInstance(context);
Selim Cinek01af3342016-02-09 19:25:31 -0800795 initDimens();
796 }
797
798 private void initDimens() {
Selim Cinekf619ffc2016-02-17 14:53:05 -0800799 mNotificationMinHeightLegacy = getFontScaledHeight(R.dimen.notification_min_height_legacy);
800 mNotificationMinHeight = getFontScaledHeight(R.dimen.notification_min_height);
801 mNotificationMaxHeight = getFontScaledHeight(R.dimen.notification_max_height);
802 mMaxHeadsUpHeightLegacy = getFontScaledHeight(
Selim Cinek77019c72015-12-09 10:18:02 -0800803 R.dimen.notification_max_heads_up_height_legacy);
Selim Cinekf619ffc2016-02-17 14:53:05 -0800804 mMaxHeadsUpHeight = getFontScaledHeight(R.dimen.notification_max_heads_up_height);
Mady Mellorb0a82462016-04-30 17:31:02 -0700805 mIncreasedPaddingBetweenElements = getResources()
806 .getDimensionPixelSize(R.dimen.notification_divider_height_increased);
Selim Cinekf619ffc2016-02-17 14:53:05 -0800807 }
808
809 /**
810 * @param dimenId the dimen to look up
811 * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
812 */
813 private int getFontScaledHeight(int dimenId) {
814 int dimensionPixelSize = getResources().getDimensionPixelSize(dimenId);
815 float factor = Math.max(1.0f, getResources().getDisplayMetrics().scaledDensity /
816 getResources().getDisplayMetrics().density);
817 return (int) (dimensionPixelSize * factor);
Chris Wren51c75102013-07-16 20:49:17 -0400818 }
819
Christoph Studera7fe6312014-06-27 19:32:44 +0200820 /**
821 * Resets this view so it can be re-used for an updated notification.
822 */
Christoph Studer22f2ee52014-07-29 22:57:21 +0200823 @Override
Christoph Studera7fe6312014-06-27 19:32:44 +0200824 public void reset() {
Christoph Studer22f2ee52014-07-29 22:57:21 +0200825 super.reset();
Chris Wren78403d72014-07-28 10:23:24 +0100826 final boolean wasExpanded = isExpanded();
Christoph Studera7fe6312014-06-27 19:32:44 +0200827 mExpandable = false;
828 mHasUserChangedExpansion = false;
829 mUserLocked = false;
830 mShowingPublic = false;
Jorim Jaggiae441282014-08-01 02:45:18 +0200831 mSensitive = false;
832 mShowingPublicInitialized = false;
Christoph Studera7fe6312014-06-27 19:32:44 +0200833 mIsSystemExpanded = false;
Selim Cinek83bc7832015-10-22 13:26:54 -0700834 mOnKeyguard = false;
Selim Cinek51d94912016-03-02 15:34:28 -0800835 mPublicLayout.reset();
836 mPrivateLayout.reset();
Selim Cinek31094df2014-08-14 19:28:15 +0200837 resetHeight();
Mady Mellor4b80b102016-01-22 08:03:58 -0800838 resetTranslation();
Selim Cinek31094df2014-08-14 19:28:15 +0200839 logExpansionEvent(false, wasExpanded);
840 }
841
842 public void resetHeight() {
Selim Cinek31094df2014-08-14 19:28:15 +0200843 onHeightReset();
Selim Cinek6e28a672014-09-05 14:43:28 +0200844 requestLayout();
Christoph Studera7fe6312014-06-27 19:32:44 +0200845 }
846
Jorim Jaggi251957d2014-04-09 04:24:09 +0200847 @Override
848 protected void onFinishInflate() {
849 super.onFinishInflate();
Jorim Jaggibe565df2014-04-28 17:51:23 +0200850 mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800851 mPublicLayout.setContainingNotification(this);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200852 mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800853 mPrivateLayout.setExpandClickListener(mExpandClickListener);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800854 mPrivateLayout.setContainingNotification(this);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800855 mPublicLayout.setExpandClickListener(mExpandClickListener);
Mady Mellor4b80b102016-01-22 08:03:58 -0800856 mSettingsIconRowStub = (ViewStub) findViewById(R.id.settings_icon_row_stub);
857 mSettingsIconRowStub.setOnInflateListener(new ViewStub.OnInflateListener() {
858 @Override
859 public void onInflate(ViewStub stub, View inflated) {
860 mSettingsIconRow = (NotificationSettingsIconRow) inflated;
861 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
Mady Mellor3fd273e2016-03-15 21:08:14 -0700862 mSettingsIconRow.setAppName(mAppName);
Mady Mellor4b80b102016-01-22 08:03:58 -0800863 }
864 });
Selim Cinekab29aeb2015-02-20 18:18:32 +0100865 mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub);
866 mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() {
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200867 @Override
868 public void onInflate(ViewStub stub, View inflated) {
869 mGuts = (NotificationGuts) inflated;
870 mGuts.setClipTopAmount(getClipTopAmount());
871 mGuts.setActualHeight(getActualHeight());
Selim Cinekab29aeb2015-02-20 18:18:32 +0100872 mGutsStub = null;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200873 }
874 });
Selim Cinekb5605e52015-02-20 18:21:41 +0100875 mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub);
876 mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() {
877
878 @Override
879 public void onInflate(ViewStub stub, View inflated) {
880 mChildrenContainer = (NotificationChildrenContainer) inflated;
Selim Cinek388df6d2015-10-22 13:25:11 -0700881 mChildrenContainer.setNotificationParent(ExpandableNotificationRow.this);
Selim Cinekc897bd32016-03-18 17:32:31 -0700882 mChildrenContainer.onNotificationUpdated();
Mady Mellor4b80b102016-01-22 08:03:58 -0800883 mTranslateableViews.add(mChildrenContainer);
Selim Cinekb5605e52015-02-20 18:21:41 +0100884 }
885 });
Selim Cinek863834b2014-05-20 04:20:25 +0200886 mVetoButton = findViewById(R.id.veto);
Selim Cinek9e624e72016-07-20 13:46:49 -0700887 mVetoButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
888 mVetoButton.setContentDescription(mContext.getString(
889 R.string.accessibility_remove_notification));
Mady Mellor4b80b102016-01-22 08:03:58 -0800890
891 // Add the views that we translate to reveal the gear
892 mTranslateableViews = new ArrayList<View>();
893 for (int i = 0; i < getChildCount(); i++) {
894 mTranslateableViews.add(getChildAt(i));
895 }
896 // Remove views that don't translate
897 mTranslateableViews.remove(mVetoButton);
898 mTranslateableViews.remove(mSettingsIconRowStub);
899 mTranslateableViews.remove(mChildrenContainerStub);
900 mTranslateableViews.remove(mGutsStub);
901 }
902
Selim Cinek9e624e72016-07-20 13:46:49 -0700903 public View getVetoButton() {
904 return mVetoButton;
905 }
906
Mady Mellor4b80b102016-01-22 08:03:58 -0800907 public void resetTranslation() {
Mady Mellor32c638a2016-09-14 08:58:25 -0700908 if (mTranslateAnim != null) {
909 mTranslateAnim.cancel();
910 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800911 if (mTranslateableViews != null) {
912 for (int i = 0; i < mTranslateableViews.size(); i++) {
913 mTranslateableViews.get(i).setTranslationX(0);
914 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800915 }
Mady Mellorb0a82462016-04-30 17:31:02 -0700916 invalidateOutline();
Mady Mellor4b80b102016-01-22 08:03:58 -0800917 if (mSettingsIconRow != null) {
918 mSettingsIconRow.resetState();
919 }
920 }
921
922 public void animateTranslateNotification(final float leftTarget) {
923 if (mTranslateAnim != null) {
924 mTranslateAnim.cancel();
925 }
Mady Mellorb0a82462016-04-30 17:31:02 -0700926 mTranslateAnim = getTranslateViewAnimator(leftTarget, null /* updateListener */);
Mady Mellor34958fa2016-02-23 09:52:17 -0800927 if (mTranslateAnim != null) {
928 mTranslateAnim.start();
929 }
930 }
931
932 @Override
933 public void setTranslation(float translationX) {
934 if (areGutsExposed()) {
935 // Don't translate if guts are showing.
936 return;
937 }
938 // Translate the group of views
939 for (int i = 0; i < mTranslateableViews.size(); i++) {
940 if (mTranslateableViews.get(i) != null) {
941 mTranslateableViews.get(i).setTranslationX(translationX);
942 }
943 }
Mady Mellorb0a82462016-04-30 17:31:02 -0700944 invalidateOutline();
Mady Mellor34958fa2016-02-23 09:52:17 -0800945 if (mSettingsIconRow != null) {
946 mSettingsIconRow.updateSettingsIcons(translationX, getMeasuredWidth());
947 }
948 }
949
950 @Override
951 public float getTranslation() {
952 if (mTranslateableViews != null && mTranslateableViews.size() > 0) {
953 // All of the views in the list should have same translation, just use first one.
954 return mTranslateableViews.get(0).getTranslationX();
955 }
956 return 0;
957 }
958
959 public Animator getTranslateViewAnimator(final float leftTarget,
960 AnimatorUpdateListener listener) {
Mady Mellor723f1f92016-03-13 15:54:06 -0700961 if (mTranslateAnim != null) {
962 mTranslateAnim.cancel();
963 }
Mady Mellor34958fa2016-02-23 09:52:17 -0800964 if (areGutsExposed()) {
965 // No translation if guts are exposed.
966 return null;
967 }
Mady Mellorb0a82462016-04-30 17:31:02 -0700968 final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(this, TRANSLATE_CONTENT,
969 leftTarget);
970 if (listener != null) {
971 translateAnim.addUpdateListener(listener);
Mady Mellor4b80b102016-01-22 08:03:58 -0800972 }
Mady Mellorb0a82462016-04-30 17:31:02 -0700973 translateAnim.addListener(new AnimatorListenerAdapter() {
974 boolean cancelled = false;
975
976 @Override
977 public void onAnimationCancel(Animator anim) {
978 cancelled = true;
979 }
980
981 @Override
982 public void onAnimationEnd(Animator anim) {
983 if (!cancelled && mSettingsIconRow != null && leftTarget == 0) {
984 mSettingsIconRow.resetState();
985 mTranslateAnim = null;
986 }
987 }
988 });
989 mTranslateAnim = translateAnim;
990 return translateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -0800991 }
992
993 public float getSpaceForGear() {
994 if (mSettingsIconRow != null) {
995 return mSettingsIconRow.getSpaceForGear();
996 }
997 return 0;
998 }
999
1000 public NotificationSettingsIconRow getSettingsRow() {
1001 if (mSettingsIconRow == null) {
1002 mSettingsIconRowStub.inflate();
1003 }
1004 return mSettingsIconRow;
1005 }
1006
Selim Cinekab29aeb2015-02-20 18:18:32 +01001007 public void inflateGuts() {
1008 if (mGuts == null) {
1009 mGutsStub.inflate();
1010 }
1011 }
1012
Selim Cinekda42d652015-12-04 15:51:16 -08001013 private void updateChildrenVisibility() {
Selim Cinekd84a5932015-12-15 11:45:36 -08001014 mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE
1015 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -08001016 if (mChildrenContainer != null) {
1017 mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
1018 : INVISIBLE);
Mady Mellorb0a82462016-04-30 17:31:02 -07001019 mChildrenContainer.updateHeaderVisibility(!mShowingPublic && mIsSummaryWithChildren
1020 ? VISIBLE
Selim Cinekef5127e2015-12-21 16:55:58 -08001021 : INVISIBLE);
1022 }
Selim Cinekda42d652015-12-04 15:51:16 -08001023 // The limits might have changed if the view suddenly became a group or vice versa
1024 updateLimits();
Selim Cinekb5605e52015-02-20 18:21:41 +01001025 }
1026
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001027 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08001028 public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
1029 if (super.onRequestSendAccessibilityEventInternal(child, event)) {
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001030 // Add a record for the entire layout since its content is somehow small.
1031 // The event comes from a leaf view that is interacted with.
1032 AccessibilityEvent record = AccessibilityEvent.obtain();
1033 onInitializeAccessibilityEvent(record);
1034 dispatchPopulateAccessibilityEvent(record);
1035 event.appendRecord(record);
1036 return true;
1037 }
1038 return false;
Jorim Jaggic5dc0d02014-04-15 15:42:55 +02001039 }
Chris Wren51c75102013-07-16 20:49:17 -04001040
John Spurlocke15452b2014-08-21 09:44:39 -04001041 @Override
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001042 public void setDark(boolean dark, boolean fade, long delay) {
1043 super.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -04001044 final NotificationContentView showing = getShowingLayout();
1045 if (showing != null) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001046 showing.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -04001047 }
Selim Cinek9c7712d2015-12-08 19:19:48 -08001048 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001049 mChildrenContainer.setDark(dark, fade, delay);
Selim Cinek9c7712d2015-12-08 19:19:48 -08001050 }
John Spurlocke15452b2014-08-21 09:44:39 -04001051 }
1052
Chris Wren51c75102013-07-16 20:49:17 -04001053 public boolean isExpandable() {
Selim Cinek388df6d2015-10-22 13:25:11 -07001054 if (mIsSummaryWithChildren && !mShowingPublic) {
1055 return !mChildrenExpanded;
1056 }
Chris Wren51c75102013-07-16 20:49:17 -04001057 return mExpandable;
1058 }
1059
1060 public void setExpandable(boolean expandable) {
1061 mExpandable = expandable;
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001062 mPrivateLayout.updateExpandButtons(isExpandable());
Chris Wren51c75102013-07-16 20:49:17 -04001063 }
1064
Selim Cinek4ffd6362015-12-29 15:12:23 +01001065 @Override
1066 public void setClipToActualHeight(boolean clipToActualHeight) {
Selim Cinek084c16b2016-01-22 17:48:22 -08001067 super.setClipToActualHeight(clipToActualHeight || isUserLocked());
1068 getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked());
Selim Cinek4ffd6362015-12-29 15:12:23 +01001069 }
1070
Selim Cinek1685e632014-04-08 02:27:49 +02001071 /**
1072 * @return whether the user has changed the expansion state
1073 */
1074 public boolean hasUserChangedExpansion() {
1075 return mHasUserChangedExpansion;
1076 }
1077
Chris Wren51c75102013-07-16 20:49:17 -04001078 public boolean isUserExpanded() {
1079 return mUserExpanded;
1080 }
1081
Selim Cinek1685e632014-04-08 02:27:49 +02001082 /**
1083 * Set this notification to be expanded by the user
1084 *
1085 * @param userExpanded whether the user wants this notification to be expanded
1086 */
Chris Wren51c75102013-07-16 20:49:17 -04001087 public void setUserExpanded(boolean userExpanded) {
Selim Cinek388df6d2015-10-22 13:25:11 -07001088 setUserExpanded(userExpanded, false /* allowChildExpansion */);
1089 }
1090
1091 /**
1092 * Set this notification to be expanded by the user
1093 *
1094 * @param userExpanded whether the user wants this notification to be expanded
1095 * @param allowChildExpansion whether a call to this method allows expanding children
1096 */
1097 public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001098 mFalsingManager.setNotificationExpanded();
Selim Cinek388df6d2015-10-22 13:25:11 -07001099 if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion) {
Chris Wren698b1702016-05-23 11:16:32 -04001100 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinek388df6d2015-10-22 13:25:11 -07001101 mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded);
Chris Wren698b1702016-05-23 11:16:32 -04001102 logExpansionEvent(true /* userAction */, wasExpanded);
Selim Cinek388df6d2015-10-22 13:25:11 -07001103 return;
1104 }
Christoph Studera7fe6312014-06-27 19:32:44 +02001105 if (userExpanded && !mExpandable) return;
Chris Wren78403d72014-07-28 10:23:24 +01001106 final boolean wasExpanded = isExpanded();
Selim Cinek1685e632014-04-08 02:27:49 +02001107 mHasUserChangedExpansion = true;
Chris Wren51c75102013-07-16 20:49:17 -04001108 mUserExpanded = userExpanded;
Chris Wren78403d72014-07-28 10:23:24 +01001109 logExpansionEvent(true, wasExpanded);
Chris Wren51c75102013-07-16 20:49:17 -04001110 }
1111
Selim Cinekccd14fb2014-08-12 18:53:24 +02001112 public void resetUserExpansion() {
1113 mHasUserChangedExpansion = false;
1114 mUserExpanded = false;
1115 }
1116
Chris Wren51c75102013-07-16 20:49:17 -04001117 public boolean isUserLocked() {
Selim Cinek1b2a05e2016-04-28 14:20:39 -07001118 return mUserLocked && !mForceUnlocked;
Chris Wren51c75102013-07-16 20:49:17 -04001119 }
1120
1121 public void setUserLocked(boolean userLocked) {
1122 mUserLocked = userLocked;
Selim Cinek8f2f6a62016-02-23 19:56:31 -08001123 mPrivateLayout.setUserExpanding(userLocked);
Selim Cinek42357e02016-02-24 18:48:01 -08001124 if (mIsSummaryWithChildren) {
1125 mChildrenContainer.setUserLocked(userLocked);
Selim Cinek7baaa9e2016-07-21 17:21:09 -07001126 if (userLocked || !isGroupExpanded()) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001127 updateBackgroundForGroupState();
1128 }
Selim Cinek42357e02016-02-24 18:48:01 -08001129 }
Chris Wren51c75102013-07-16 20:49:17 -04001130 }
1131
Selim Cinek1685e632014-04-08 02:27:49 +02001132 /**
1133 * @return has the system set this notification to be expanded
1134 */
1135 public boolean isSystemExpanded() {
1136 return mIsSystemExpanded;
1137 }
1138
1139 /**
1140 * Set this notification to be expanded by the system.
1141 *
1142 * @param expand whether the system wants this notification to be expanded.
1143 */
1144 public void setSystemExpanded(boolean expand) {
Selim Cinek31094df2014-08-14 19:28:15 +02001145 if (expand != mIsSystemExpanded) {
1146 final boolean wasExpanded = isExpanded();
1147 mIsSystemExpanded = expand;
Selim Cinekb5605e52015-02-20 18:21:41 +01001148 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +02001149 logExpansionEvent(false, wasExpanded);
Selim Cineked6913b2016-06-01 12:01:17 -07001150 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001151 mChildrenContainer.updateGroupOverflow();
1152 }
Selim Cinek31094df2014-08-14 19:28:15 +02001153 }
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001154 }
1155
1156 /**
Selim Cinek83bc7832015-10-22 13:26:54 -07001157 * @param onKeyguard whether to prevent notification expansion
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001158 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001159 public void setOnKeyguard(boolean onKeyguard) {
1160 if (onKeyguard != mOnKeyguard) {
Selim Cinek31094df2014-08-14 19:28:15 +02001161 final boolean wasExpanded = isExpanded();
Selim Cinek83bc7832015-10-22 13:26:54 -07001162 mOnKeyguard = onKeyguard;
Selim Cinek31094df2014-08-14 19:28:15 +02001163 logExpansionEvent(false, wasExpanded);
1164 if (wasExpanded != isExpanded()) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001165 if (mIsSummaryWithChildren) {
1166 mChildrenContainer.updateGroupOverflow();
1167 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001168 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +02001169 }
1170 }
Selim Cinek1685e632014-04-08 02:27:49 +02001171 }
1172
1173 /**
Selim Cinek9e624e72016-07-20 13:46:49 -07001174 * @return Can the underlying notification be cleared? This can be different from whether the
1175 * notification can be dismissed in case notifications are sensitive on the lockscreen.
1176 * @see #canViewBeDismissed()
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001177 */
1178 public boolean isClearable() {
Selim Cinek506deb62016-07-20 15:43:59 -07001179 if (mStatusBarNotification == null || !mStatusBarNotification.isClearable()) {
1180 return false;
1181 }
1182 if (mIsSummaryWithChildren) {
1183 List<ExpandableNotificationRow> notificationChildren =
1184 mChildrenContainer.getNotificationChildren();
1185 for (int i = 0; i < notificationChildren.size(); i++) {
1186 ExpandableNotificationRow child = notificationChildren.get(i);
1187 if (!child.isClearable()) {
1188 return false;
1189 }
1190 }
1191 }
1192 return true;
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001193 }
1194
Jorim Jaggi9cbadd32014-05-01 20:18:31 +02001195 @Override
1196 public int getIntrinsicHeight() {
Jorim Jaggibe565df2014-04-28 17:51:23 +02001197 if (isUserLocked()) {
1198 return getActualHeight();
1199 }
Selim Cinekd84a5932015-12-15 11:45:36 -08001200 if (mGuts != null && mGuts.areGutsExposed()) {
1201 return mGuts.getHeight();
1202 } else if ((isChildInGroup() && !isGroupExpanded())) {
1203 return mPrivateLayout.getMinHeight();
1204 } else if (mSensitive && mHideSensitiveForIntrinsicHeight) {
1205 return getMinHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001206 } else if (mIsSummaryWithChildren && !mOnKeyguard) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001207 return mChildrenContainer.getIntrinsicHeight();
Selim Cinek73cf02a2016-06-17 13:08:00 -07001208 } else if (mIsHeadsUp || mHeadsupDisappearRunning) {
1209 if (isPinned() || mHeadsupDisappearRunning) {
Selim Cinek31aada42015-12-18 17:51:15 -08001210 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
1211 } else if (isExpanded()) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001212 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001213 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001214 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001215 }
Selim Cinek31aada42015-12-18 17:51:15 -08001216 } else if (isExpanded()) {
Selim Cinek83bc7832015-10-22 13:26:54 -07001217 return getMaxExpandHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -08001218 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001219 return getCollapsedHeight();
Selim Cinek1685e632014-04-08 02:27:49 +02001220 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001221 }
Selim Cinek1685e632014-04-08 02:27:49 +02001222
Mady Mellorb0a82462016-04-30 17:31:02 -07001223 public boolean isGroupExpanded() {
Selim Cinekeef84282015-10-30 16:28:00 -07001224 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinekb5605e52015-02-20 18:21:41 +01001225 }
1226
Selim Cinek263398f2015-10-21 17:40:23 -07001227 private void onChildrenCountChanged() {
Selim Cinek8fc93c92015-11-23 17:48:07 -08001228 mIsSummaryWithChildren = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS
Mady Mellorb0a82462016-04-30 17:31:02 -07001229 && mChildrenContainer != null && mChildrenContainer.getNotificationChildCount() > 0;
1230 if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() == null) {
1231 mChildrenContainer.recreateNotificationHeader(mExpandClickListener,
1232 mEntry.notification);
Selim Cinek263398f2015-10-21 17:40:23 -07001233 }
Mady Mellor6baed9e2016-05-25 16:05:09 -07001234 getShowingLayout().updateBackgroundColor(false /* animate */);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001235 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinekea4bef72015-12-02 15:51:10 -08001236 updateChildrenHeaderAppearance();
Selim Cinekda42d652015-12-04 15:51:16 -08001237 updateChildrenVisibility();
Selim Cinek263398f2015-10-21 17:40:23 -07001238 }
1239
Mady Mellorb0a82462016-04-30 17:31:02 -07001240 public void updateChildrenHeaderAppearance() {
Selim Cineked6913b2016-06-01 12:01:17 -07001241 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001242 mChildrenContainer.updateChildrenHeaderAppearance();
1243 }
1244 }
1245
Selim Cinek1685e632014-04-08 02:27:49 +02001246 /**
1247 * Check whether the view state is currently expanded. This is given by the system in {@link
1248 * #setSystemExpanded(boolean)} and can be overridden by user expansion or
1249 * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this
1250 * view can differ from this state, if layout params are modified from outside.
1251 *
1252 * @return whether the view state is currently expanded.
1253 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001254 public boolean isExpanded() {
Selim Cineke81b82b2016-03-04 11:22:28 -08001255 return isExpanded(false /* allowOnKeyguard */);
1256 }
1257
1258 public boolean isExpanded(boolean allowOnKeyguard) {
1259 return (!mOnKeyguard || allowOnKeyguard)
Selim Cinekb5605e52015-02-20 18:21:41 +01001260 && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded())
1261 || isUserExpanded());
1262 }
1263
1264 private boolean isSystemChildExpanded() {
1265 return mIsSystemChildExpanded;
1266 }
1267
1268 public void setSystemChildExpanded(boolean expanded) {
1269 mIsSystemChildExpanded = expanded;
Selim Cinek1685e632014-04-08 02:27:49 +02001270 }
1271
1272 @Override
1273 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
1274 super.onLayout(changed, left, top, right, bottom);
Selim Cinek8d490d42015-04-10 00:05:50 -07001275 updateMaxHeights();
Mady Mellora6edc872016-04-26 11:01:03 -07001276 if (mSettingsIconRow != null) {
1277 mSettingsIconRow.updateVerticalLocation();
1278 }
Selim Cinek1685e632014-04-08 02:27:49 +02001279 }
1280
Selim Cinek8d490d42015-04-10 00:05:50 -07001281 private void updateMaxHeights() {
Selim Cinekd2319fb2014-09-01 19:41:54 +02001282 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek8d490d42015-04-10 00:05:50 -07001283 View expandedChild = mPrivateLayout.getExpandedChild();
1284 if (expandedChild == null) {
1285 expandedChild = mPrivateLayout.getContractedChild();
1286 }
1287 mMaxExpandHeight = expandedChild.getHeight();
1288 View headsUpChild = mPrivateLayout.getHeadsUpChild();
Selim Cinek1f3f5442015-04-10 17:54:46 -07001289 if (headsUpChild == null) {
1290 headsUpChild = mPrivateLayout.getContractedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -07001291 }
Selim Cinek1f3f5442015-04-10 17:54:46 -07001292 mHeadsUpHeight = headsUpChild.getHeight();
Selim Cinekd2319fb2014-09-01 19:41:54 +02001293 if (intrinsicBefore != getIntrinsicHeight()) {
Selim Cinekbb42b7d2016-08-10 13:02:38 -07001294 notifyHeightChanged(true /* needsAnimation */);
Selim Cinekd2319fb2014-09-01 19:41:54 +02001295 }
1296 }
1297
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001298 @Override
1299 public void notifyHeightChanged(boolean needsAnimation) {
1300 super.notifyHeightChanged(needsAnimation);
1301 getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked());
1302 }
1303
Selim Cinek3c76d502016-02-19 15:16:33 -08001304 public void setSensitive(boolean sensitive, boolean hideSensitive) {
Jorim Jaggiae441282014-08-01 02:45:18 +02001305 mSensitive = sensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -08001306 mSensitiveHiddenInGeneral = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02001307 }
1308
1309 public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
Selim Cinek60122be2015-04-15 18:16:50 -07001310 mHideSensitiveForIntrinsicHeight = hideSensitive;
Selim Cineka52f6a12016-02-29 15:35:58 -08001311 if (mIsSummaryWithChildren) {
1312 List<ExpandableNotificationRow> notificationChildren =
1313 mChildrenContainer.getNotificationChildren();
1314 for (int i = 0; i < notificationChildren.size(); i++) {
1315 ExpandableNotificationRow child = notificationChildren.get(i);
1316 child.setHideSensitiveForIntrinsicHeight(hideSensitive);
1317 }
1318 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001319 }
1320
1321 public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
1322 long duration) {
1323 boolean oldShowingPublic = mShowingPublic;
1324 mShowingPublic = mSensitive && hideSensitive;
1325 if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
1326 return;
1327 }
Dan Sandlera5e0f412014-01-23 15:11:54 -05001328
1329 // bail out if no public version
Selim Cinek1685e632014-04-08 02:27:49 +02001330 if (mPublicLayout.getChildCount() == 0) return;
Dan Sandlera5e0f412014-01-23 15:11:54 -05001331
Jorim Jaggiae441282014-08-01 02:45:18 +02001332 if (!animated) {
1333 mPublicLayout.animate().cancel();
1334 mPrivateLayout.animate().cancel();
Selim Cineka554c702016-06-17 18:02:12 -07001335 if (mChildrenContainer != null) {
1336 mChildrenContainer.animate().cancel();
1337 mChildrenContainer.setAlpha(1f);
1338 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001339 mPublicLayout.setAlpha(1f);
1340 mPrivateLayout.setAlpha(1f);
1341 mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
Selim Cinekd84a5932015-12-15 11:45:36 -08001342 updateChildrenVisibility();
Jorim Jaggiae441282014-08-01 02:45:18 +02001343 } else {
1344 animateShowingPublic(delay, duration);
1345 }
Selim Cinekc3179332016-03-04 14:44:56 -08001346 NotificationContentView showingLayout = getShowingLayout();
1347 showingLayout.updateBackgroundColor(animated);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001348 mPrivateLayout.updateExpandButtons(isExpandable());
Jorim Jaggiae441282014-08-01 02:45:18 +02001349 mShowingPublicInitialized = true;
1350 }
1351
1352 private void animateShowingPublic(long delay, long duration) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001353 View[] privateViews = mIsSummaryWithChildren
1354 ? new View[] {mChildrenContainer}
Selim Cinekd84a5932015-12-15 11:45:36 -08001355 : new View[] {mPrivateLayout};
1356 View[] publicViews = new View[] {mPublicLayout};
1357 View[] hiddenChildren = mShowingPublic ? privateViews : publicViews;
1358 View[] shownChildren = mShowingPublic ? publicViews : privateViews;
1359 for (final View hiddenView : hiddenChildren) {
1360 hiddenView.setVisibility(View.VISIBLE);
1361 hiddenView.animate().cancel();
1362 hiddenView.animate()
1363 .alpha(0f)
1364 .setStartDelay(delay)
1365 .setDuration(duration)
1366 .withEndAction(new Runnable() {
1367 @Override
1368 public void run() {
1369 hiddenView.setVisibility(View.INVISIBLE);
1370 }
1371 });
1372 }
1373 for (View showView : shownChildren) {
1374 showView.setVisibility(View.VISIBLE);
1375 showView.setAlpha(0f);
1376 showView.animate().cancel();
1377 showView.animate()
1378 .alpha(1f)
1379 .setStartDelay(delay)
1380 .setDuration(duration);
1381 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001382 }
1383
Selim Cinek3776fe02016-02-04 13:32:43 -08001384 public boolean mustStayOnScreen() {
1385 return mIsHeadsUp;
1386 }
1387
Selim Cinek9e624e72016-07-20 13:46:49 -07001388 /**
1389 * @return Whether this view is allowed to be dismissed. Only valid for visible notifications as
1390 * otherwise some state might not be updated. To request about the general clearability
1391 * see {@link #isClearable()}.
1392 */
1393 public boolean canViewBeDismissed() {
Selim Cineke9bad242016-06-15 11:46:37 -07001394 return isClearable() && (!mShowingPublic || !mSensitiveHiddenInGeneral);
Dan Sandlera5e0f412014-01-23 15:11:54 -05001395 }
Jorim Jaggi251957d2014-04-09 04:24:09 +02001396
Ricky Waicd35def2016-05-03 11:07:07 +01001397 public void makeActionsVisibile() {
1398 setUserExpanded(true, true);
1399 if (isChildInGroup()) {
1400 mGroupManager.setGroupExpanded(mStatusBarNotification, true);
1401 }
Selim Cinekbb42b7d2016-08-10 13:02:38 -07001402 notifyHeightChanged(false /* needsAnimation */);
Ricky Waicd35def2016-05-03 11:07:07 +01001403 }
1404
Selim Cinekb5605e52015-02-20 18:21:41 +01001405 public void setChildrenExpanded(boolean expanded, boolean animate) {
1406 mChildrenExpanded = expanded;
Selim Cinek83bc7832015-10-22 13:26:54 -07001407 if (mChildrenContainer != null) {
1408 mChildrenContainer.setChildrenExpanded(expanded);
1409 }
Mady Mellor1a5d8ea2016-06-09 10:42:42 -07001410 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -07001411 updateClickAndFocus();
Selim Cinekb5605e52015-02-20 18:21:41 +01001412 }
1413
Selim Cinekb5605e52015-02-20 18:21:41 +01001414 public static void applyTint(View v, int color) {
1415 int alpha;
1416 if (color != 0) {
1417 alpha = COLORED_DIVIDER_ALPHA;
1418 } else {
1419 color = 0xff000000;
1420 alpha = DEFAULT_DIVIDER_ALPHA;
1421 }
1422 if (v.getBackground() instanceof ColorDrawable) {
1423 ColorDrawable background = (ColorDrawable) v.getBackground();
1424 background.mutate();
1425 background.setColor(color);
1426 background.setAlpha(alpha);
1427 }
1428 }
1429
Selim Cinek1685e632014-04-08 02:27:49 +02001430 public int getMaxExpandHeight() {
Selim Cinekb5605e52015-02-20 18:21:41 +01001431 return mMaxExpandHeight;
Chris Wren51c75102013-07-16 20:49:17 -04001432 }
Jorim Jaggi584a7aa2014-04-10 23:26:13 +02001433
Mady Mellor34958fa2016-02-23 09:52:17 -08001434 public boolean areGutsExposed() {
1435 return (mGuts != null && mGuts.areGutsExposed());
1436 }
1437
Jorim Jaggibe565df2014-04-28 17:51:23 +02001438 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001439 public boolean isContentExpandable() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001440 NotificationContentView showingLayout = getShowingLayout();
1441 return showingLayout.isContentExpandable();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001442 }
1443
1444 @Override
Selim Cinek560e64d2015-06-09 19:58:11 -07001445 protected View getContentView() {
Selim Cinekaa3901a2016-08-05 11:04:37 -07001446 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cineka5703182016-05-11 21:23:16 -04001447 return mChildrenContainer;
1448 }
Selim Cinek560e64d2015-06-09 19:58:11 -07001449 return getShowingLayout();
1450 }
1451
1452 @Override
Selim Cinekaa3901a2016-08-05 11:04:37 -07001453 protected void onAppearAnimationFinished(boolean wasAppearing) {
1454 super.onAppearAnimationFinished(wasAppearing);
1455 if (wasAppearing) {
1456 // During the animation the visible view might have changed, so let's make sure all
1457 // alphas are reset
1458 if (mChildrenContainer != null) {
1459 mChildrenContainer.setAlpha(1.0f);
1460 mChildrenContainer.setLayerType(LAYER_TYPE_NONE, null);
1461 }
1462 mPrivateLayout.setAlpha(1.0f);
1463 mPrivateLayout.setLayerType(LAYER_TYPE_NONE, null);
1464 mPublicLayout.setAlpha(1.0f);
1465 mPublicLayout.setLayerType(LAYER_TYPE_NONE, null);
1466 }
1467 }
1468
1469 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -07001470 public int getExtraBottomPadding() {
1471 if (mIsSummaryWithChildren && isGroupExpanded()) {
1472 return mIncreasedPaddingBetweenElements;
1473 }
1474 return 0;
1475 }
1476
1477 @Override
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001478 public void setActualHeight(int height, boolean notifyListeners) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001479 super.setActualHeight(height, notifyListeners);
Mady Mellorb53bc272016-02-11 18:28:23 -08001480 if (mGuts != null && mGuts.areGutsExposed()) {
1481 mGuts.setActualHeight(height);
1482 return;
1483 }
Selim Cinekeef84282015-10-30 16:28:00 -07001484 int contentHeight = Math.max(getMinHeight(), height);
Selim Cinekb5605e52015-02-20 18:21:41 +01001485 mPrivateLayout.setContentHeight(contentHeight);
1486 mPublicLayout.setContentHeight(contentHeight);
Selim Cinek42357e02016-02-24 18:48:01 -08001487 if (mIsSummaryWithChildren) {
1488 mChildrenContainer.setActualHeight(height);
1489 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001490 if (mGuts != null) {
1491 mGuts.setActualHeight(height);
1492 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001493 }
1494
1495 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01001496 public int getMaxContentHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001497 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001498 return mChildrenContainer.getMaxContentHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001499 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001500 NotificationContentView showingLayout = getShowingLayout();
1501 return showingLayout.getMaxHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001502 }
1503
1504 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001505 public int getMinHeight() {
Selim Cinek31aada42015-12-18 17:51:15 -08001506 if (mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) {
1507 return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
1508 } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001509 return mChildrenContainer.getMinHeight();
Selim Cinek31aada42015-12-18 17:51:15 -08001510 } else if (mIsHeadsUp) {
1511 return mHeadsUpHeight;
Selim Cinekb55386d2015-12-16 17:26:49 -08001512 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001513 NotificationContentView showingLayout = getShowingLayout();
1514 return showingLayout.getMinHeight();
1515 }
1516
1517 @Override
Selim Cinek567e8452016-03-24 10:54:56 -07001518 public int getCollapsedHeight() {
Selim Cinek2c584612016-02-29 16:14:25 -08001519 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinek567e8452016-03-24 10:54:56 -07001520 return mChildrenContainer.getCollapsedHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001521 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001522 return getMinHeight();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001523 }
1524
1525 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02001526 public void setClipTopAmount(int clipTopAmount) {
1527 super.setClipTopAmount(clipTopAmount);
1528 mPrivateLayout.setClipTopAmount(clipTopAmount);
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001529 mPublicLayout.setClipTopAmount(clipTopAmount);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001530 if (mGuts != null) {
1531 mGuts.setClipTopAmount(clipTopAmount);
1532 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001533 }
1534
Selim Cinek31094df2014-08-14 19:28:15 +02001535 public boolean isMaxExpandHeightInitialized() {
1536 return mMaxExpandHeight != 0;
Selim Cinek7d447722014-06-10 15:51:59 +02001537 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001538
Selim Cinek42357e02016-02-24 18:48:01 -08001539 public NotificationContentView getShowingLayout() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001540 return mShowingPublic ? mPublicLayout : mPrivateLayout;
1541 }
Chris Wren78403d72014-07-28 10:23:24 +01001542
Jorim Jaggi59ec3042015-06-05 15:18:43 -07001543 @Override
1544 public void setShowingLegacyBackground(boolean showing) {
1545 super.setShowingLegacyBackground(showing);
1546 mPrivateLayout.setShowingLegacyBackground(showing);
1547 mPublicLayout.setShowingLegacyBackground(showing);
1548 }
1549
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001550 @Override
1551 protected void updateBackgroundTint() {
1552 super.updateBackgroundTint();
Mady Mellorb0a82462016-04-30 17:31:02 -07001553 updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001554 if (mIsSummaryWithChildren) {
1555 List<ExpandableNotificationRow> notificationChildren =
1556 mChildrenContainer.getNotificationChildren();
1557 for (int i = 0; i < notificationChildren.size(); i++) {
1558 ExpandableNotificationRow child = notificationChildren.get(i);
Mady Mellorb0a82462016-04-30 17:31:02 -07001559 child.updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001560 }
1561 }
1562 }
1563
Mady Mellorb0a82462016-04-30 17:31:02 -07001564 /**
1565 * Called when a group has finished animating from collapsed or expanded state.
1566 */
1567 public void onFinishedExpansionChange() {
1568 mGroupExpansionChanging = false;
1569 updateBackgroundForGroupState();
1570 }
1571
1572 /**
1573 * Updates the parent and children backgrounds in a group based on the expansion state.
1574 */
1575 public void updateBackgroundForGroupState() {
1576 if (mIsSummaryWithChildren) {
1577 // Only when the group has finished expanding do we hide its background.
1578 mShowNoBackground = isGroupExpanded() && !isGroupExpansionChanging() && !isUserLocked();
1579 mChildrenContainer.updateHeaderForExpansion(mShowNoBackground);
1580 List<ExpandableNotificationRow> children = mChildrenContainer.getNotificationChildren();
1581 for (int i = 0; i < children.size(); i++) {
1582 children.get(i).updateBackgroundForGroupState();
1583 }
1584 } else if (isChildInGroup()) {
1585 final int childColor = getShowingLayout().getBackgroundColorForExpansionState();
1586 // Only show a background if the group is expanded OR if it is expanding / collapsing
1587 // and has a custom background color
1588 final boolean showBackground = isGroupExpanded()
1589 || ((mNotificationParent.isGroupExpansionChanging()
1590 || mNotificationParent.isUserLocked()) && childColor != 0);
1591 mShowNoBackground = !showBackground;
1592 } else {
1593 // Only children or parents ever need no background.
1594 mShowNoBackground = false;
1595 }
1596 updateOutline();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001597 updateBackground();
1598 }
1599
Adrian Roos4a579672016-05-24 16:54:37 -07001600 public int getPositionOfChild(ExpandableNotificationRow childRow) {
1601 if (mIsSummaryWithChildren) {
1602 return mChildrenContainer.getPositionInLinearLayout(childRow);
1603 }
1604 return 0;
1605 }
1606
Chris Wren78403d72014-07-28 10:23:24 +01001607 public void setExpansionLogger(ExpansionLogger logger, String key) {
1608 mLogger = logger;
1609 mLoggingKey = key;
1610 }
1611
Chris Wren6abeeb92016-05-26 14:44:38 -04001612 public void onExpandedByGesture(boolean userExpanded) {
1613 int event = MetricsEvent.ACTION_NOTIFICATION_GESTURE_EXPANDER;
1614 if (mGroupManager.isSummaryOfGroup(getStatusBarNotification())) {
1615 event = MetricsEvent.ACTION_NOTIFICATION_GROUP_GESTURE_EXPANDER;
1616 }
1617 MetricsLogger.action(mContext, event, userExpanded);
1618 }
1619
Selim Cinek6183d122016-01-14 18:48:41 -08001620 @Override
Selim Cinek42357e02016-02-24 18:48:01 -08001621 public float getIncreasedPaddingAmount() {
1622 if (mIsSummaryWithChildren) {
1623 if (isGroupExpanded()) {
1624 return 1.0f;
1625 } else if (isUserLocked()) {
Selim Cinekf07d0622016-03-21 19:52:52 -07001626 return mChildrenContainer.getGroupExpandFraction();
Selim Cinek42357e02016-02-24 18:48:01 -08001627 }
1628 }
1629 return 0.0f;
Selim Cinek61633a82016-01-25 15:54:10 -08001630 }
1631
1632 @Override
Selim Cinek6183d122016-01-14 18:48:41 -08001633 protected boolean disallowSingleClick(MotionEvent event) {
1634 float x = event.getX();
1635 float y = event.getY();
Selim Cinek34eda5e2016-02-18 17:10:43 -08001636 NotificationHeaderView header = getVisibleNotificationHeader();
Selim Cinek6183d122016-01-14 18:48:41 -08001637 if (header != null) {
Mady Mellora8833512016-03-09 09:50:18 -08001638 return header.isInTouchRect(x - getTranslation(), y);
Selim Cinek6183d122016-01-14 18:48:41 -08001639 }
1640 return super.disallowSingleClick(event);
1641 }
1642
Chris Wren78403d72014-07-28 10:23:24 +01001643 private void logExpansionEvent(boolean userAction, boolean wasExpanded) {
Chris Wren698b1702016-05-23 11:16:32 -04001644 boolean nowExpanded = isExpanded();
1645 if (mIsSummaryWithChildren) {
1646 nowExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
1647 }
Chris Wren78403d72014-07-28 10:23:24 +01001648 if (wasExpanded != nowExpanded && mLogger != null) {
1649 mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ;
1650 }
1651 }
Selim Cinek570981d2015-12-01 11:37:01 -08001652
Selim Cineke9bad242016-06-15 11:46:37 -07001653 @Override
1654 public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
1655 super.onInitializeAccessibilityNodeInfoInternal(info);
1656 if (canViewBeDismissed()) {
1657 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS);
1658 }
1659 }
1660
1661 @Override
1662 public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
1663 if (super.performAccessibilityActionInternal(action, arguments)) {
1664 return true;
1665 }
1666 switch (action) {
1667 case AccessibilityNodeInfo.ACTION_DISMISS:
1668 NotificationStackScrollLayout.performDismiss(this, mGroupManager,
1669 true /* fromAccessibility */);
1670 return true;
1671 }
1672 return false;
1673 }
1674
1675 public boolean shouldRefocusOnDismiss() {
1676 return mRefocusOnDismiss || isAccessibilityFocused();
1677 }
1678
Selim Cinek570981d2015-12-01 11:37:01 -08001679 public interface OnExpandClickListener {
Selim Cinek31aada42015-12-18 17:51:15 -08001680 void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
Selim Cinek570981d2015-12-01 11:37:01 -08001681 }
Chris Wren51c75102013-07-16 20:49:17 -04001682}