blob: bb518d51a5de4073ad962bcbff2a656487ea1bf5 [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;
21import android.animation.AnimatorSet;
22import android.animation.ObjectAnimator;
23import android.animation.ValueAnimator;
24import android.animation.ValueAnimator.AnimatorUpdateListener;
Selim Cineka6c6bfb2015-10-29 16:27:08 -070025import android.app.Notification;
Chris Wren51c75102013-07-16 20:49:17 -040026import android.content.Context;
Selim Cinekcab4a602014-09-03 14:47:57 +020027import android.graphics.drawable.AnimatedVectorDrawable;
28import android.graphics.drawable.AnimationDrawable;
Selim Cinekb5605e52015-02-20 18:21:41 +010029import android.graphics.drawable.ColorDrawable;
Selim Cinekcab4a602014-09-03 14:47:57 +020030import android.graphics.drawable.Drawable;
Selim Cinekda42d652015-12-04 15:51:16 -080031import android.os.Build;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020032import android.service.notification.StatusBarNotification;
Chris Wren51c75102013-07-16 20:49:17 -040033import android.util.AttributeSet;
Selim Cinek01af3342016-02-09 19:25:31 -080034import android.view.LayoutInflater;
Selim Cinek6183d122016-01-14 18:48:41 -080035import android.view.MotionEvent;
Selim Cinekeaa29ca2015-11-23 13:51:13 -080036import android.view.NotificationHeaderView;
Dan Sandlera5e0f412014-01-23 15:11:54 -050037import android.view.View;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020038import android.view.ViewStub;
Jorim Jaggife40f7d2014-04-28 15:20:04 +020039import android.view.accessibility.AccessibilityEvent;
Selim Cinek98713a42015-09-21 15:47:20 +020040import android.widget.Chronometer;
Selim Cinekcab4a602014-09-03 14:47:57 +020041import android.widget.ImageView;
Selim Cinekeaa29ca2015-11-23 13:51:13 -080042import android.widget.RemoteViews;
Selim Cinekb5605e52015-02-20 18:21:41 +010043
Dan Sandlera5e0f412014-01-23 15:11:54 -050044import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070045import com.android.systemui.classifier.FalsingManager;
Selim Cinek0ffbda62016-01-01 20:29:12 +010046import com.android.systemui.statusbar.notification.NotificationViewWrapper;
Selim Cinekb5605e52015-02-20 18:21:41 +010047import com.android.systemui.statusbar.phone.NotificationGroupManager;
Selim Cinek31aada42015-12-18 17:51:15 -080048import com.android.systemui.statusbar.policy.HeadsUpManager;
Selim Cinekb5605e52015-02-20 18:21:41 +010049import com.android.systemui.statusbar.stack.NotificationChildrenContainer;
50import com.android.systemui.statusbar.stack.StackScrollState;
51import com.android.systemui.statusbar.stack.StackStateAnimator;
52import com.android.systemui.statusbar.stack.StackViewState;
53
Mady Mellor4b80b102016-01-22 08:03:58 -080054import java.util.ArrayList;
Selim Cinekb5605e52015-02-20 18:21:41 +010055import java.util.List;
Dan Sandlera5e0f412014-01-23 15:11:54 -050056
Jorim Jaggi4222d9a2014-04-23 16:13:15 +020057public class ExpandableNotificationRow extends ActivatableNotificationView {
Selim Cinekb5605e52015-02-20 18:21:41 +010058
59 private static final int DEFAULT_DIVIDER_ALPHA = 0x29;
60 private static final int COLORED_DIVIDER_ALPHA = 0x7B;
Selim Cinek01af3342016-02-09 19:25:31 -080061 private int mNotificationMinHeightLegacy;
62 private int mMaxHeadsUpHeightLegacy;
63 private int mMaxHeadsUpHeight;
64 private int mNotificationMinHeight;
65 private int mNotificationMaxHeight;
Chris Wren51c75102013-07-16 20:49:17 -040066
Selim Cinek1685e632014-04-08 02:27:49 +020067 /** Does this row contain layouts that can adapt to row expansion */
Chris Wren51c75102013-07-16 20:49:17 -040068 private boolean mExpandable;
Selim Cinek1685e632014-04-08 02:27:49 +020069 /** Has the user actively changed the expansion state of this row */
70 private boolean mHasUserChangedExpansion;
71 /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */
Chris Wren51c75102013-07-16 20:49:17 -040072 private boolean mUserExpanded;
Selim Cinek31aada42015-12-18 17:51:15 -080073
74 /**
75 * Has this notification been expanded while it was pinned
76 */
77 private boolean mExpandedWhenPinned;
Selim Cinek1685e632014-04-08 02:27:49 +020078 /** Is the user touching this row */
Chris Wren51c75102013-07-16 20:49:17 -040079 private boolean mUserLocked;
Selim Cinek1685e632014-04-08 02:27:49 +020080 /** Are we showing the "public" version */
Dan Sandlera5e0f412014-01-23 15:11:54 -050081 private boolean mShowingPublic;
Jorim Jaggiae441282014-08-01 02:45:18 +020082 private boolean mSensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -080083 private boolean mSensitiveHiddenInGeneral;
Jorim Jaggiae441282014-08-01 02:45:18 +020084 private boolean mShowingPublicInitialized;
Selim Cinek60122be2015-04-15 18:16:50 -070085 private boolean mHideSensitiveForIntrinsicHeight;
Chris Wren51c75102013-07-16 20:49:17 -040086
Selim Cinek1685e632014-04-08 02:27:49 +020087 /**
88 * Is this notification expanded by the system. The expansion state can be overridden by the
89 * user expansion.
90 */
91 private boolean mIsSystemExpanded;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +020092
93 /**
Selim Cinek83bc7832015-10-22 13:26:54 -070094 * Whether the notification is on the keyguard and the expansion is disabled.
Jorim Jaggidce3c4c2014-04-29 23:12:24 +020095 */
Selim Cinek83bc7832015-10-22 13:26:54 -070096 private boolean mOnKeyguard;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +020097
Mady Mellor4b80b102016-01-22 08:03:58 -080098 private AnimatorSet mTranslateAnim;
99 private ArrayList<View> mTranslateableViews;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200100 private NotificationContentView mPublicLayout;
101 private NotificationContentView mPrivateLayout;
Selim Cinek1685e632014-04-08 02:27:49 +0200102 private int mMaxExpandHeight;
Selim Cinek8d490d42015-04-10 00:05:50 -0700103 private int mHeadsUpHeight;
Selim Cinek863834b2014-05-20 04:20:25 +0200104 private View mVetoButton;
Dan Sandler0d3e62f2014-07-14 17:13:50 -0400105 private boolean mClearable;
Chris Wren78403d72014-07-28 10:23:24 +0100106 private ExpansionLogger mLogger;
107 private String mLoggingKey;
Mady Mellor4b80b102016-01-22 08:03:58 -0800108 private NotificationSettingsIconRow mSettingsIconRow;
Selim Cinek8d490d42015-04-10 00:05:50 -0700109 private NotificationGuts mGuts;
Selim Cinekda42d652015-12-04 15:51:16 -0800110 private NotificationData.Entry mEntry;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200111 private StatusBarNotification mStatusBarNotification;
Selim Cinek1a521f32014-11-03 17:39:29 +0100112 private boolean mIsHeadsUp;
Selim Cinek98713a42015-09-21 15:47:20 +0200113 private boolean mLastChronometerRunning = true;
Selim Cinekeef84282015-10-30 16:28:00 -0700114 private NotificationHeaderView mNotificationHeader;
Selim Cinek9c7712d2015-12-08 19:19:48 -0800115 private NotificationViewWrapper mNotificationHeaderWrapper;
Selim Cinekb5605e52015-02-20 18:21:41 +0100116 private ViewStub mChildrenContainerStub;
117 private NotificationGroupManager mGroupManager;
Selim Cinekb5605e52015-02-20 18:21:41 +0100118 private boolean mChildrenExpanded;
Selim Cinek263398f2015-10-21 17:40:23 -0700119 private boolean mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100120 private NotificationChildrenContainer mChildrenContainer;
Mady Mellor4b80b102016-01-22 08:03:58 -0800121 private ViewStub mSettingsIconRowStub;
Selim Cinekab29aeb2015-02-20 18:18:32 +0100122 private ViewStub mGutsStub;
Selim Cinekb5605e52015-02-20 18:21:41 +0100123 private boolean mIsSystemChildExpanded;
Selim Cinek684a4422015-04-15 16:18:39 -0700124 private boolean mIsPinned;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700125 private FalsingManager mFalsingManager;
Selim Cinek31aada42015-12-18 17:51:15 -0800126 private HeadsUpManager mHeadsUpManager;
Selim Cinekea4bef72015-12-02 15:51:10 -0800127 private NotificationHeaderUtil mHeaderUtil = new NotificationHeaderUtil(this);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200128
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700129 private boolean mJustClicked;
Selim Cinek5a175d92015-11-23 18:01:33 -0800130 private boolean mIconAnimationRunning;
Selim Cinek34d93b02015-10-22 12:30:38 -0700131 private boolean mShowNoBackground;
Selim Cinek388df6d2015-10-22 13:25:11 -0700132 private ExpandableNotificationRow mNotificationParent;
Selim Cinek570981d2015-12-01 11:37:01 -0800133 private OnExpandClickListener mOnExpandClickListener;
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800134 private OnClickListener mExpandClickListener = new OnClickListener() {
135 @Override
136 public void onClick(View v) {
Selim Cinek624c02db2015-12-14 21:00:02 -0800137 if (!mShowingPublic && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800138 mGroupManager.toggleGroupExpansion(mStatusBarNotification);
Selim Cinek31aada42015-12-18 17:51:15 -0800139 mOnExpandClickListener.onExpandClicked(mEntry,
Selim Cinek570981d2015-12-01 11:37:01 -0800140 mGroupManager.isGroupExpanded(mStatusBarNotification));
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800141 } else {
Selim Cinek31aada42015-12-18 17:51:15 -0800142 boolean nowExpanded;
143 if (isPinned()) {
144 nowExpanded = !mExpandedWhenPinned;
145 mExpandedWhenPinned = nowExpanded;
146 } else {
147 nowExpanded = !isExpanded();
148 setUserExpanded(nowExpanded);
149 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800150 notifyHeightChanged(true);
Selim Cinek31aada42015-12-18 17:51:15 -0800151 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800152 }
153 }
154 };
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700155
Selim Cinek8d490d42015-04-10 00:05:50 -0700156 public NotificationContentView getPrivateLayout() {
157 return mPrivateLayout;
158 }
159
160 public NotificationContentView getPublicLayout() {
161 return mPublicLayout;
162 }
163
Selim Cinekcab4a602014-09-03 14:47:57 +0200164 public void setIconAnimationRunning(boolean running) {
165 setIconAnimationRunning(running, mPublicLayout);
166 setIconAnimationRunning(running, mPrivateLayout);
Selim Cinek5a175d92015-11-23 18:01:33 -0800167 setIconAnimationRunningForChild(running, mNotificationHeader);
168 if (mIsSummaryWithChildren) {
169 List<ExpandableNotificationRow> notificationChildren =
170 mChildrenContainer.getNotificationChildren();
171 for (int i = 0; i < notificationChildren.size(); i++) {
172 ExpandableNotificationRow child = notificationChildren.get(i);
173 child.setIconAnimationRunning(running);
174 }
175 }
176 mIconAnimationRunning = running;
Selim Cinekcab4a602014-09-03 14:47:57 +0200177 }
178
179 private void setIconAnimationRunning(boolean running, NotificationContentView layout) {
180 if (layout != null) {
181 View contractedChild = layout.getContractedChild();
182 View expandedChild = layout.getExpandedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -0700183 View headsUpChild = layout.getHeadsUpChild();
Selim Cinekcab4a602014-09-03 14:47:57 +0200184 setIconAnimationRunningForChild(running, contractedChild);
185 setIconAnimationRunningForChild(running, expandedChild);
Selim Cinek8d490d42015-04-10 00:05:50 -0700186 setIconAnimationRunningForChild(running, headsUpChild);
Selim Cinekcab4a602014-09-03 14:47:57 +0200187 }
188 }
189
190 private void setIconAnimationRunningForChild(boolean running, View child) {
191 if (child != null) {
192 ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon);
193 setIconRunning(icon, running);
194 ImageView rightIcon = (ImageView) child.findViewById(
195 com.android.internal.R.id.right_icon);
196 setIconRunning(rightIcon, running);
197 }
198 }
199
200 private void setIconRunning(ImageView imageView, boolean running) {
201 if (imageView != null) {
202 Drawable drawable = imageView.getDrawable();
203 if (drawable instanceof AnimationDrawable) {
204 AnimationDrawable animationDrawable = (AnimationDrawable) drawable;
205 if (running) {
206 animationDrawable.start();
207 } else {
208 animationDrawable.stop();
209 }
210 } else if (drawable instanceof AnimatedVectorDrawable) {
211 AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable;
212 if (running) {
213 animationDrawable.start();
214 } else {
215 animationDrawable.stop();
216 }
217 }
218 }
219 }
220
Selim Cinekda42d652015-12-04 15:51:16 -0800221 public void onNotificationUpdated(NotificationData.Entry entry) {
222 mEntry = entry;
223 mStatusBarNotification = entry.notification;
Adrian Roosb88b1a12015-12-09 18:51:05 -0800224 mPrivateLayout.onNotificationUpdated(entry);
225 mPublicLayout.onNotificationUpdated(entry);
Selim Cinek757d8792016-01-28 16:21:08 -0800226 mShowingPublicInitialized = false;
227 updateClearability();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800228 if (mIsSummaryWithChildren) {
229 recreateNotificationHeader();
230 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800231 if (mIconAnimationRunning) {
232 setIconAnimationRunning(true);
233 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800234 if (mNotificationParent != null) {
235 mNotificationParent.updateChildrenHeaderAppearance();
236 }
Selim Cinek263398f2015-10-21 17:40:23 -0700237 onChildrenCountChanged();
Selim Cinek624c02db2015-12-14 21:00:02 -0800238 // The public layouts expand button is always visible
239 mPublicLayout.updateExpandButtons(true);
Selim Cinekda42d652015-12-04 15:51:16 -0800240 updateLimits();
241 }
242
243 private void updateLimits() {
Selim Cineka1744872016-03-11 15:36:06 -0800244 updateLimitsForView(mPrivateLayout);
245 updateLimitsForView(mPublicLayout);
246 }
247
248 private void updateLimitsForView(NotificationContentView layout) {
249 boolean customView = layout.getContractedChild().getId()
Selim Cinekda42d652015-12-04 15:51:16 -0800250 != com.android.internal.R.id.status_bar_latest_event_content;
251 boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N;
252 int minHeight = customView && beforeN && !mIsSummaryWithChildren ?
253 mNotificationMinHeightLegacy : mNotificationMinHeight;
Selim Cineka1744872016-03-11 15:36:06 -0800254 boolean headsUpCustom = layout.getHeadsUpChild() != null &&
255 layout.getHeadsUpChild().getId()
256 != com.android.internal.R.id.status_bar_latest_event_content;
Selim Cinek77019c72015-12-09 10:18:02 -0800257 int headsUpheight = headsUpCustom && beforeN ? mMaxHeadsUpHeightLegacy
258 : mMaxHeadsUpHeight;
Selim Cineka1744872016-03-11 15:36:06 -0800259 layout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200260 }
261
262 public StatusBarNotification getStatusBarNotification() {
263 return mStatusBarNotification;
264 }
265
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700266 public boolean isHeadsUp() {
267 return mIsHeadsUp;
268 }
269
Selim Cinek1a521f32014-11-03 17:39:29 +0100270 public void setHeadsUp(boolean isHeadsUp) {
Selim Cinekc80fdb12015-04-13 15:09:08 -0700271 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek1a521f32014-11-03 17:39:29 +0100272 mIsHeadsUp = isHeadsUp;
Selim Cinek8d490d42015-04-10 00:05:50 -0700273 mPrivateLayout.setHeadsUp(isHeadsUp);
Selim Cinekc80fdb12015-04-13 15:09:08 -0700274 if (intrinsicBefore != getIntrinsicHeight()) {
275 notifyHeightChanged(false /* needsAnimation */);
276 }
Selim Cinek1a521f32014-11-03 17:39:29 +0100277 }
278
Selim Cinekb5605e52015-02-20 18:21:41 +0100279 public void setGroupManager(NotificationGroupManager groupManager) {
280 mGroupManager = groupManager;
Selim Cinek83bc7832015-10-22 13:26:54 -0700281 mPrivateLayout.setGroupManager(groupManager);
Selim Cinekb5605e52015-02-20 18:21:41 +0100282 }
283
Adrian Roosb88b1a12015-12-09 18:51:05 -0800284 public void setRemoteInputController(RemoteInputController r) {
285 mPrivateLayout.setRemoteInputController(r);
286 }
287
Selim Cinekb5605e52015-02-20 18:21:41 +0100288 public void addChildNotification(ExpandableNotificationRow row) {
289 addChildNotification(row, -1);
290 }
291
292 /**
293 * Add a child notification to this view.
294 *
295 * @param row the row to add
296 * @param childIndex the index to add it at, if -1 it will be added at the end
297 */
298 public void addChildNotification(ExpandableNotificationRow row, int childIndex) {
299 if (mChildrenContainer == null) {
300 mChildrenContainerStub.inflate();
301 }
302 mChildrenContainer.addNotification(row, childIndex);
Selim Cinek263398f2015-10-21 17:40:23 -0700303 onChildrenCountChanged();
304 row.setIsChildInGroup(true, this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100305 }
306
307 public void removeChildNotification(ExpandableNotificationRow row) {
308 if (mChildrenContainer != null) {
309 mChildrenContainer.removeNotification(row);
310 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800311 mHeaderUtil.restoreNotificationHeader(row);
Selim Cinek263398f2015-10-21 17:40:23 -0700312 onChildrenCountChanged();
313 row.setIsChildInGroup(false, null);
314 }
315
316 public boolean isChildInGroup() {
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700317 return mNotificationParent != null;
Selim Cinek263398f2015-10-21 17:40:23 -0700318 }
319
Selim Cinek388df6d2015-10-22 13:25:11 -0700320 public ExpandableNotificationRow getNotificationParent() {
321 return mNotificationParent;
322 }
323
Selim Cinek263398f2015-10-21 17:40:23 -0700324 /**
325 * @param isChildInGroup Is this notification now in a group
326 * @param parent the new parent notification
327 */
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700328 public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {;
329 boolean childInGroup = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup;
330 mNotificationParent = childInGroup ? parent : null;
331 mPrivateLayout.setIsChildInGroup(childInGroup);
332 updateNoBackgroundState();
Selim Cinek34d93b02015-10-22 12:30:38 -0700333 }
334
335 @Override
Selim Cinek72109472016-01-15 16:33:22 -0800336 public boolean onTouchEvent(MotionEvent event) {
337 if (event.getActionMasked() != MotionEvent.ACTION_DOWN
338 || !isChildInGroup() || isGroupExpanded()) {
339 return super.onTouchEvent(event);
340 } else {
341 return false;
342 }
343 }
344
345 @Override
Mady Mellorf0625802016-02-11 18:03:48 -0800346 protected boolean handleSlideBack() {
347 if (mSettingsIconRow != null && mSettingsIconRow.isVisible()) {
348 animateTranslateNotification(0 /* targetLeft */);
349 return true;
350 }
351 return false;
352 }
353
354 @Override
Selim Cinek34d93b02015-10-22 12:30:38 -0700355 protected boolean shouldHideBackground() {
356 return super.shouldHideBackground() || mShowNoBackground;
Selim Cinek263398f2015-10-21 17:40:23 -0700357 }
358
359 @Override
360 public boolean isSummaryWithChildren() {
361 return mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100362 }
363
364 @Override
365 public boolean areChildrenExpanded() {
366 return mChildrenExpanded;
367 }
368
369 public List<ExpandableNotificationRow> getNotificationChildren() {
370 return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren();
371 }
372
Selim Cinekeef84282015-10-30 16:28:00 -0700373 public int getNumberOfNotificationChildren() {
374 if (mChildrenContainer == null) {
375 return 0;
376 }
377 return mChildrenContainer.getNotificationChildren().size();
378 }
379
Selim Cinekb5605e52015-02-20 18:21:41 +0100380 /**
381 * Apply the order given in the list to the children.
382 *
383 * @param childOrder the new list order
384 * @return whether the list order has changed
385 */
386 public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder) {
387 return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder);
388 }
389
390 public void getChildrenStates(StackScrollState resultState) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700391 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100392 StackViewState parentState = resultState.getViewStateForView(this);
393 mChildrenContainer.getState(resultState, parentState);
394 }
395 }
396
397 public void applyChildrenState(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700398 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100399 mChildrenContainer.applyState(state);
400 }
401 }
402
403 public void prepareExpansionChanged(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700404 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100405 mChildrenContainer.prepareExpansionChanged(state);
406 }
407 }
408
409 public void startChildAnimation(StackScrollState finalState,
Selim Cinek99695592016-01-12 17:51:35 -0800410 StackStateAnimator stateAnimator, long delay, long duration) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700411 if (mIsSummaryWithChildren) {
Selim Cinek99695592016-01-12 17:51:35 -0800412 mChildrenContainer.startAnimationToState(finalState, stateAnimator, delay,
Selim Cinekb5605e52015-02-20 18:21:41 +0100413 duration);
414 }
415 }
416
417 public ExpandableNotificationRow getViewAtPosition(float y) {
Selim Cinek43d30f02016-03-04 10:51:32 -0800418 if (!mIsSummaryWithChildren || !mChildrenExpanded) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100419 return this;
420 } else {
421 ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y);
422 return view == null ? this : view;
423 }
424 }
425
Selim Cinekab29aeb2015-02-20 18:18:32 +0100426 public NotificationGuts getGuts() {
427 return mGuts;
428 }
429
Selim Cinek684a4422015-04-15 16:18:39 -0700430 /**
431 * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this
432 * the notification will be rendered on top of the screen.
433 *
434 * @param pinned whether it is pinned
435 */
436 public void setPinned(boolean pinned) {
437 mIsPinned = pinned;
Selim Cinek31aada42015-12-18 17:51:15 -0800438 if (pinned) {
439 setIconAnimationRunning(true);
440 mExpandedWhenPinned = false;
441 } else if (mExpandedWhenPinned) {
442 setUserExpanded(true);
443 }
Selim Cinek98713a42015-09-21 15:47:20 +0200444 setChronometerRunning(mLastChronometerRunning);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700445 }
446
Selim Cinek684a4422015-04-15 16:18:39 -0700447 public boolean isPinned() {
448 return mIsPinned;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700449 }
450
Selim Cinek31aada42015-12-18 17:51:15 -0800451 /**
452 * @param atLeastMinHeight should the value returned be at least the minimum height.
453 * Used to avoid cyclic calls
454 * @return the height of the heads up notification when pinned
455 */
456 public int getPinnedHeadsUpHeight(boolean atLeastMinHeight) {
Selim Cinek77019c72015-12-09 10:18:02 -0800457 if (mIsSummaryWithChildren) {
458 return mChildrenContainer.getIntrinsicHeight();
459 }
Selim Cinek31aada42015-12-18 17:51:15 -0800460 if(mExpandedWhenPinned) {
461 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
462 } else if (atLeastMinHeight) {
463 return Math.max(getMinHeight(), mHeadsUpHeight);
464 } else {
465 return mHeadsUpHeight;
466 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700467 }
468
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700469 /**
470 * Mark whether this notification was just clicked, i.e. the user has just clicked this
471 * notification in this frame.
472 */
473 public void setJustClicked(boolean justClicked) {
474 mJustClicked = justClicked;
475 }
476
477 /**
478 * @return true if this notification has been clicked in this frame, false otherwise
479 */
480 public boolean wasJustClicked() {
481 return mJustClicked;
482 }
483
Selim Cinek98713a42015-09-21 15:47:20 +0200484 public void setChronometerRunning(boolean running) {
485 mLastChronometerRunning = running;
486 setChronometerRunning(running, mPrivateLayout);
487 setChronometerRunning(running, mPublicLayout);
488 if (mChildrenContainer != null) {
489 List<ExpandableNotificationRow> notificationChildren =
490 mChildrenContainer.getNotificationChildren();
491 for (int i = 0; i < notificationChildren.size(); i++) {
492 ExpandableNotificationRow child = notificationChildren.get(i);
493 child.setChronometerRunning(running);
494 }
495 }
496 }
497
498 private void setChronometerRunning(boolean running, NotificationContentView layout) {
499 if (layout != null) {
500 running = running || isPinned();
501 View contractedChild = layout.getContractedChild();
502 View expandedChild = layout.getExpandedChild();
503 View headsUpChild = layout.getHeadsUpChild();
504 setChronometerRunningForChild(running, contractedChild);
505 setChronometerRunningForChild(running, expandedChild);
506 setChronometerRunningForChild(running, headsUpChild);
507 }
508 }
509
510 private void setChronometerRunningForChild(boolean running, View child) {
511 if (child != null) {
512 View chronometer = child.findViewById(com.android.internal.R.id.chronometer);
513 if (chronometer instanceof Chronometer) {
514 ((Chronometer) chronometer).setStarted(running);
515 }
516 }
517 }
518
Selim Cinekea4bef72015-12-02 15:51:10 -0800519 public NotificationHeaderView getNotificationHeader() {
520 if (mNotificationHeader != null) {
521 return mNotificationHeader;
Selim Cinek8d6440d2015-10-22 13:00:05 -0700522 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800523 return mPrivateLayout.getNotificationHeader();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700524 }
525
Selim Cinek34eda5e2016-02-18 17:10:43 -0800526 private NotificationHeaderView getVisibleNotificationHeader() {
527 if (mNotificationHeader != null) {
528 return mNotificationHeader;
529 }
530 return getShowingLayout().getVisibleNotificationHeader();
531 }
532
Selim Cinek570981d2015-12-01 11:37:01 -0800533 public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) {
534 mOnExpandClickListener = onExpandClickListener;
535 }
536
Selim Cinek31aada42015-12-18 17:51:15 -0800537 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
538 mHeadsUpManager = headsUpManager;
539 }
540
Selim Cinek01af3342016-02-09 19:25:31 -0800541 public void reInflateViews() {
542 initDimens();
543 if (mIsSummaryWithChildren) {
544 removeView(mNotificationHeader);
545 mNotificationHeader = null;
546 recreateNotificationHeader();
547 if (mChildrenContainer != null) {
548 mChildrenContainer.reInflateViews();
549 }
550 }
551 if (mGuts != null) {
552 View oldGuts = mGuts;
553 int index = indexOfChild(oldGuts);
554 removeView(oldGuts);
555 mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate(
556 R.layout.notification_guts, this, false);
557 mGuts.setVisibility(oldGuts.getVisibility());
558 addView(mGuts, index);
559 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800560 if (mSettingsIconRow != null) {
561 View oldSettings = mSettingsIconRow;
562 int settingsIndex = indexOfChild(oldSettings);
563 removeView(oldSettings);
564 mSettingsIconRow = (NotificationSettingsIconRow) LayoutInflater.from(mContext).inflate(
565 R.layout.notification_settings_icon_row, this, false);
566 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
567 mSettingsIconRow.setVisibility(oldSettings.getVisibility());
568 addView(mSettingsIconRow, settingsIndex);
569
570 }
Selim Cinekde33a4a2016-02-11 16:43:41 -0800571 mPrivateLayout.reInflateViews();
572 mPublicLayout.reInflateViews();
Selim Cinek01af3342016-02-09 19:25:31 -0800573 }
574
Selim Cinekc3179332016-03-04 14:44:56 -0800575 public void setContentBackground(int customBackgroundColor, boolean animate,
576 NotificationContentView notificationContentView) {
577 if (getShowingLayout() == notificationContentView) {
578 setTintColor(customBackgroundColor, animate);
579 }
580 }
581
Chris Wren78403d72014-07-28 10:23:24 +0100582 public interface ExpansionLogger {
583 public void logNotificationExpansion(String key, boolean userAction, boolean expanded);
584 }
Selim Cinek1685e632014-04-08 02:27:49 +0200585
Chris Wren51c75102013-07-16 20:49:17 -0400586 public ExpandableNotificationRow(Context context, AttributeSet attrs) {
587 super(context, attrs);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700588 mFalsingManager = FalsingManager.getInstance(context);
Selim Cinek01af3342016-02-09 19:25:31 -0800589 initDimens();
590 }
591
592 private void initDimens() {
Selim Cinekf619ffc2016-02-17 14:53:05 -0800593 mNotificationMinHeightLegacy = getFontScaledHeight(R.dimen.notification_min_height_legacy);
594 mNotificationMinHeight = getFontScaledHeight(R.dimen.notification_min_height);
595 mNotificationMaxHeight = getFontScaledHeight(R.dimen.notification_max_height);
596 mMaxHeadsUpHeightLegacy = getFontScaledHeight(
Selim Cinek77019c72015-12-09 10:18:02 -0800597 R.dimen.notification_max_heads_up_height_legacy);
Selim Cinekf619ffc2016-02-17 14:53:05 -0800598 mMaxHeadsUpHeight = getFontScaledHeight(R.dimen.notification_max_heads_up_height);
599 }
600
601 /**
602 * @param dimenId the dimen to look up
603 * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
604 */
605 private int getFontScaledHeight(int dimenId) {
606 int dimensionPixelSize = getResources().getDimensionPixelSize(dimenId);
607 float factor = Math.max(1.0f, getResources().getDisplayMetrics().scaledDensity /
608 getResources().getDisplayMetrics().density);
609 return (int) (dimensionPixelSize * factor);
Chris Wren51c75102013-07-16 20:49:17 -0400610 }
611
Christoph Studera7fe6312014-06-27 19:32:44 +0200612 /**
613 * Resets this view so it can be re-used for an updated notification.
614 */
Christoph Studer22f2ee52014-07-29 22:57:21 +0200615 @Override
Christoph Studera7fe6312014-06-27 19:32:44 +0200616 public void reset() {
Christoph Studer22f2ee52014-07-29 22:57:21 +0200617 super.reset();
Chris Wren78403d72014-07-28 10:23:24 +0100618 final boolean wasExpanded = isExpanded();
Christoph Studera7fe6312014-06-27 19:32:44 +0200619 mExpandable = false;
620 mHasUserChangedExpansion = false;
621 mUserLocked = false;
622 mShowingPublic = false;
Jorim Jaggiae441282014-08-01 02:45:18 +0200623 mSensitive = false;
624 mShowingPublicInitialized = false;
Christoph Studera7fe6312014-06-27 19:32:44 +0200625 mIsSystemExpanded = false;
Selim Cinek83bc7832015-10-22 13:26:54 -0700626 mOnKeyguard = false;
Selim Cinek51d94912016-03-02 15:34:28 -0800627 mPublicLayout.reset();
628 mPrivateLayout.reset();
Selim Cinek31094df2014-08-14 19:28:15 +0200629 resetHeight();
Mady Mellor4b80b102016-01-22 08:03:58 -0800630 resetTranslation();
Selim Cinek31094df2014-08-14 19:28:15 +0200631 logExpansionEvent(false, wasExpanded);
632 }
633
634 public void resetHeight() {
Christoph Studera7fe6312014-06-27 19:32:44 +0200635 mMaxExpandHeight = 0;
Selim Cinek8d490d42015-04-10 00:05:50 -0700636 mHeadsUpHeight = 0;
Selim Cinek31094df2014-08-14 19:28:15 +0200637 onHeightReset();
Selim Cinek6e28a672014-09-05 14:43:28 +0200638 requestLayout();
Christoph Studera7fe6312014-06-27 19:32:44 +0200639 }
640
Jorim Jaggi251957d2014-04-09 04:24:09 +0200641 @Override
642 protected void onFinishInflate() {
643 super.onFinishInflate();
Jorim Jaggibe565df2014-04-28 17:51:23 +0200644 mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800645 mPublicLayout.setContainingNotification(this);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200646 mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800647 mPrivateLayout.setExpandClickListener(mExpandClickListener);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800648 mPrivateLayout.setContainingNotification(this);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800649 mPublicLayout.setExpandClickListener(mExpandClickListener);
Mady Mellor4b80b102016-01-22 08:03:58 -0800650 mSettingsIconRowStub = (ViewStub) findViewById(R.id.settings_icon_row_stub);
651 mSettingsIconRowStub.setOnInflateListener(new ViewStub.OnInflateListener() {
652 @Override
653 public void onInflate(ViewStub stub, View inflated) {
654 mSettingsIconRow = (NotificationSettingsIconRow) inflated;
655 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
656 }
657 });
Selim Cinekab29aeb2015-02-20 18:18:32 +0100658 mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub);
659 mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() {
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200660 @Override
661 public void onInflate(ViewStub stub, View inflated) {
662 mGuts = (NotificationGuts) inflated;
663 mGuts.setClipTopAmount(getClipTopAmount());
664 mGuts.setActualHeight(getActualHeight());
Selim Cinekab29aeb2015-02-20 18:18:32 +0100665 mGutsStub = null;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200666 }
667 });
Selim Cinekb5605e52015-02-20 18:21:41 +0100668 mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub);
669 mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() {
670
671 @Override
672 public void onInflate(ViewStub stub, View inflated) {
673 mChildrenContainer = (NotificationChildrenContainer) inflated;
Selim Cinek388df6d2015-10-22 13:25:11 -0700674 mChildrenContainer.setNotificationParent(ExpandableNotificationRow.this);
Mady Mellor4b80b102016-01-22 08:03:58 -0800675 mTranslateableViews.add(mChildrenContainer);
Selim Cinekb5605e52015-02-20 18:21:41 +0100676 }
677 });
Selim Cinek863834b2014-05-20 04:20:25 +0200678 mVetoButton = findViewById(R.id.veto);
Mady Mellor4b80b102016-01-22 08:03:58 -0800679
680 // Add the views that we translate to reveal the gear
681 mTranslateableViews = new ArrayList<View>();
682 for (int i = 0; i < getChildCount(); i++) {
683 mTranslateableViews.add(getChildAt(i));
684 }
685 // Remove views that don't translate
686 mTranslateableViews.remove(mVetoButton);
687 mTranslateableViews.remove(mSettingsIconRowStub);
688 mTranslateableViews.remove(mChildrenContainerStub);
689 mTranslateableViews.remove(mGutsStub);
690 }
691
Mady Mellor34958fa2016-02-23 09:52:17 -0800692 private void setTranslationForOutline(float translationX) {
Mady Mellor4b80b102016-01-22 08:03:58 -0800693 setOutlineRect(false, translationX, getTop(), getRight() + translationX, getBottom());
694 }
695
696 public void resetTranslation() {
697 if (mTranslateableViews != null) {
698 for (int i = 0; i < mTranslateableViews.size(); i++) {
699 mTranslateableViews.get(i).setTranslationX(0);
700 }
701 setTranslationForOutline(0);
702 }
703 if (mSettingsIconRow != null) {
704 mSettingsIconRow.resetState();
705 }
706 }
707
708 public void animateTranslateNotification(final float leftTarget) {
709 if (mTranslateAnim != null) {
710 mTranslateAnim.cancel();
711 }
Mady Mellor34958fa2016-02-23 09:52:17 -0800712 mTranslateAnim = (AnimatorSet) getTranslateViewAnimator(leftTarget,
713 null /* updateListener */);
714 if (mTranslateAnim != null) {
715 mTranslateAnim.start();
716 }
717 }
718
719 @Override
720 public void setTranslation(float translationX) {
721 if (areGutsExposed()) {
722 // Don't translate if guts are showing.
723 return;
724 }
725 // Translate the group of views
726 for (int i = 0; i < mTranslateableViews.size(); i++) {
727 if (mTranslateableViews.get(i) != null) {
728 mTranslateableViews.get(i).setTranslationX(translationX);
729 }
730 }
731 setTranslationForOutline(translationX);
732 if (mSettingsIconRow != null) {
733 mSettingsIconRow.updateSettingsIcons(translationX, getMeasuredWidth());
734 }
735 }
736
737 @Override
738 public float getTranslation() {
739 if (mTranslateableViews != null && mTranslateableViews.size() > 0) {
740 // All of the views in the list should have same translation, just use first one.
741 return mTranslateableViews.get(0).getTranslationX();
742 }
743 return 0;
744 }
745
746 public Animator getTranslateViewAnimator(final float leftTarget,
747 AnimatorUpdateListener listener) {
748 if (areGutsExposed()) {
749 // No translation if guts are exposed.
750 return null;
751 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800752 AnimatorSet set = new AnimatorSet();
753 if (mTranslateableViews != null) {
754 for (int i = 0; i < mTranslateableViews.size(); i++) {
755 final View animView = mTranslateableViews.get(i);
756 final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(
757 animView, "translationX", leftTarget);
758 if (i == 0) {
759 translateAnim.addUpdateListener(new AnimatorUpdateListener() {
760 @Override
761 public void onAnimationUpdate(ValueAnimator animation) {
762 setTranslationForOutline((float) animation.getAnimatedValue());
Mady Mellor34958fa2016-02-23 09:52:17 -0800763 if (mSettingsIconRow != null) {
764 mSettingsIconRow.updateSettingsIcons(
765 (float) animation.getAnimatedValue(), getMeasuredWidth());
766 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800767 }
768 });
Mady Mellor34958fa2016-02-23 09:52:17 -0800769 if (listener != null) {
770 translateAnim.addUpdateListener(listener);
771 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800772 }
773 translateAnim.addListener(new AnimatorListenerAdapter() {
774 @Override
775 public void onAnimationEnd(Animator anim) {
776 if (mSettingsIconRow != null && leftTarget == 0) {
777 mSettingsIconRow.resetState();
778 }
779 mTranslateAnim = null;
780 }
781 });
782 set.play(translateAnim);
783 }
784 }
Mady Mellor34958fa2016-02-23 09:52:17 -0800785 return set;
Mady Mellor4b80b102016-01-22 08:03:58 -0800786 }
787
788 public float getSpaceForGear() {
789 if (mSettingsIconRow != null) {
790 return mSettingsIconRow.getSpaceForGear();
791 }
792 return 0;
793 }
794
795 public NotificationSettingsIconRow getSettingsRow() {
796 if (mSettingsIconRow == null) {
797 mSettingsIconRowStub.inflate();
798 }
799 return mSettingsIconRow;
800 }
801
Selim Cinekab29aeb2015-02-20 18:18:32 +0100802 public void inflateGuts() {
803 if (mGuts == null) {
804 mGutsStub.inflate();
805 }
806 }
807
Selim Cinekda42d652015-12-04 15:51:16 -0800808 private void updateChildrenVisibility() {
Selim Cinekd84a5932015-12-15 11:45:36 -0800809 mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE
810 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -0800811 if (mChildrenContainer != null) {
812 mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
813 : INVISIBLE);
Selim Cinekb5605e52015-02-20 18:21:41 +0100814 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800815 if (mNotificationHeader != null) {
816 mNotificationHeader.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
817 : INVISIBLE);
818 }
Selim Cinekda42d652015-12-04 15:51:16 -0800819 // The limits might have changed if the view suddenly became a group or vice versa
820 updateLimits();
Selim Cinekb5605e52015-02-20 18:21:41 +0100821 }
822
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200823 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -0800824 public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
825 if (super.onRequestSendAccessibilityEventInternal(child, event)) {
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200826 // Add a record for the entire layout since its content is somehow small.
827 // The event comes from a leaf view that is interacted with.
828 AccessibilityEvent record = AccessibilityEvent.obtain();
829 onInitializeAccessibilityEvent(record);
830 dispatchPopulateAccessibilityEvent(record);
831 event.appendRecord(record);
832 return true;
833 }
834 return false;
Jorim Jaggic5dc0d02014-04-15 15:42:55 +0200835 }
Chris Wren51c75102013-07-16 20:49:17 -0400836
John Spurlocke15452b2014-08-21 09:44:39 -0400837 @Override
Jorim Jaggi4e857f42014-11-17 19:14:04 +0100838 public void setDark(boolean dark, boolean fade, long delay) {
839 super.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -0400840 final NotificationContentView showing = getShowingLayout();
841 if (showing != null) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +0100842 showing.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -0400843 }
Selim Cinek9c7712d2015-12-08 19:19:48 -0800844 if (mIsSummaryWithChildren) {
845 mChildrenContainer.setDark(dark, fade, delay);
846 mNotificationHeaderWrapper.setDark(dark, fade, delay);
847 }
John Spurlocke15452b2014-08-21 09:44:39 -0400848 }
849
Chris Wren51c75102013-07-16 20:49:17 -0400850 public boolean isExpandable() {
Selim Cinek388df6d2015-10-22 13:25:11 -0700851 if (mIsSummaryWithChildren && !mShowingPublic) {
852 return !mChildrenExpanded;
853 }
Chris Wren51c75102013-07-16 20:49:17 -0400854 return mExpandable;
855 }
856
857 public void setExpandable(boolean expandable) {
858 mExpandable = expandable;
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800859 mPrivateLayout.updateExpandButtons(isExpandable());
Chris Wren51c75102013-07-16 20:49:17 -0400860 }
861
Selim Cinek4ffd6362015-12-29 15:12:23 +0100862 @Override
863 public void setClipToActualHeight(boolean clipToActualHeight) {
Selim Cinek084c16b2016-01-22 17:48:22 -0800864 super.setClipToActualHeight(clipToActualHeight || isUserLocked());
865 getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked());
Selim Cinek4ffd6362015-12-29 15:12:23 +0100866 }
867
Selim Cinek1685e632014-04-08 02:27:49 +0200868 /**
869 * @return whether the user has changed the expansion state
870 */
871 public boolean hasUserChangedExpansion() {
872 return mHasUserChangedExpansion;
873 }
874
Chris Wren51c75102013-07-16 20:49:17 -0400875 public boolean isUserExpanded() {
876 return mUserExpanded;
877 }
878
Selim Cinek1685e632014-04-08 02:27:49 +0200879 /**
880 * Set this notification to be expanded by the user
881 *
882 * @param userExpanded whether the user wants this notification to be expanded
883 */
Chris Wren51c75102013-07-16 20:49:17 -0400884 public void setUserExpanded(boolean userExpanded) {
Selim Cinek388df6d2015-10-22 13:25:11 -0700885 setUserExpanded(userExpanded, false /* allowChildExpansion */);
886 }
887
888 /**
889 * Set this notification to be expanded by the user
890 *
891 * @param userExpanded whether the user wants this notification to be expanded
892 * @param allowChildExpansion whether a call to this method allows expanding children
893 */
894 public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700895 mFalsingManager.setNotificationExpanded();
Selim Cinek388df6d2015-10-22 13:25:11 -0700896 if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion) {
897 mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded);
898 return;
899 }
Christoph Studera7fe6312014-06-27 19:32:44 +0200900 if (userExpanded && !mExpandable) return;
Chris Wren78403d72014-07-28 10:23:24 +0100901 final boolean wasExpanded = isExpanded();
Selim Cinek1685e632014-04-08 02:27:49 +0200902 mHasUserChangedExpansion = true;
Chris Wren51c75102013-07-16 20:49:17 -0400903 mUserExpanded = userExpanded;
Chris Wren78403d72014-07-28 10:23:24 +0100904 logExpansionEvent(true, wasExpanded);
Chris Wren51c75102013-07-16 20:49:17 -0400905 }
906
Selim Cinekccd14fb2014-08-12 18:53:24 +0200907 public void resetUserExpansion() {
908 mHasUserChangedExpansion = false;
909 mUserExpanded = false;
910 }
911
Chris Wren51c75102013-07-16 20:49:17 -0400912 public boolean isUserLocked() {
913 return mUserLocked;
914 }
915
916 public void setUserLocked(boolean userLocked) {
917 mUserLocked = userLocked;
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800918 mPrivateLayout.setUserExpanding(userLocked);
Selim Cinek42357e02016-02-24 18:48:01 -0800919 if (mIsSummaryWithChildren) {
920 mChildrenContainer.setUserLocked(userLocked);
921 }
Chris Wren51c75102013-07-16 20:49:17 -0400922 }
923
Selim Cinek1685e632014-04-08 02:27:49 +0200924 /**
925 * @return has the system set this notification to be expanded
926 */
927 public boolean isSystemExpanded() {
928 return mIsSystemExpanded;
929 }
930
931 /**
932 * Set this notification to be expanded by the system.
933 *
934 * @param expand whether the system wants this notification to be expanded.
935 */
936 public void setSystemExpanded(boolean expand) {
Selim Cinek31094df2014-08-14 19:28:15 +0200937 if (expand != mIsSystemExpanded) {
938 final boolean wasExpanded = isExpanded();
939 mIsSystemExpanded = expand;
Selim Cinekb5605e52015-02-20 18:21:41 +0100940 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +0200941 logExpansionEvent(false, wasExpanded);
Selim Cinek83bc7832015-10-22 13:26:54 -0700942 if (mChildrenContainer != null) {
943 mChildrenContainer.updateGroupOverflow();
944 }
Selim Cinek31094df2014-08-14 19:28:15 +0200945 }
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200946 }
947
948 /**
Selim Cinek83bc7832015-10-22 13:26:54 -0700949 * @param onKeyguard whether to prevent notification expansion
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200950 */
Selim Cinek83bc7832015-10-22 13:26:54 -0700951 public void setOnKeyguard(boolean onKeyguard) {
952 if (onKeyguard != mOnKeyguard) {
Selim Cinek31094df2014-08-14 19:28:15 +0200953 final boolean wasExpanded = isExpanded();
Selim Cinek83bc7832015-10-22 13:26:54 -0700954 mOnKeyguard = onKeyguard;
Selim Cinek31094df2014-08-14 19:28:15 +0200955 logExpansionEvent(false, wasExpanded);
956 if (wasExpanded != isExpanded()) {
Selim Cinek2108fe02015-12-10 12:56:13 -0800957 if (mIsSummaryWithChildren) {
958 mChildrenContainer.updateGroupOverflow();
959 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800960 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +0200961 }
962 }
Selim Cinek1685e632014-04-08 02:27:49 +0200963 }
964
965 /**
Dan Sandler0d3e62f2014-07-14 17:13:50 -0400966 * @return Can the underlying notification be cleared?
967 */
968 public boolean isClearable() {
Selim Cineka37774f2014-11-11 19:16:18 +0100969 return mStatusBarNotification != null && mStatusBarNotification.isClearable();
Dan Sandler0d3e62f2014-07-14 17:13:50 -0400970 }
971
Jorim Jaggi9cbadd32014-05-01 20:18:31 +0200972 @Override
973 public int getIntrinsicHeight() {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200974 if (isUserLocked()) {
975 return getActualHeight();
976 }
Selim Cinekd84a5932015-12-15 11:45:36 -0800977 if (mGuts != null && mGuts.areGutsExposed()) {
978 return mGuts.getHeight();
979 } else if ((isChildInGroup() && !isGroupExpanded())) {
980 return mPrivateLayout.getMinHeight();
981 } else if (mSensitive && mHideSensitiveForIntrinsicHeight) {
982 return getMinHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -0700983 } else if (mIsSummaryWithChildren && !mOnKeyguard) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800984 return mChildrenContainer.getIntrinsicHeight();
Selim Cinek60122be2015-04-15 18:16:50 -0700985 } else if (mIsHeadsUp) {
Selim Cinek31aada42015-12-18 17:51:15 -0800986 if (isPinned()) {
987 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
988 } else if (isExpanded()) {
Selim Cinekd84a5932015-12-15 11:45:36 -0800989 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -0700990 } else {
Selim Cinekd84a5932015-12-15 11:45:36 -0800991 return Math.max(getMinHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -0700992 }
Selim Cinek31aada42015-12-18 17:51:15 -0800993 } else if (isExpanded()) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700994 return getMaxExpandHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -0800995 } else {
996 return getMinHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200997 }
Selim Cinekb5605e52015-02-20 18:21:41 +0100998 }
Selim Cinek1685e632014-04-08 02:27:49 +0200999
Selim Cinekeef84282015-10-30 16:28:00 -07001000 private boolean isGroupExpanded() {
1001 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinekb5605e52015-02-20 18:21:41 +01001002 }
1003
Selim Cinekeef84282015-10-30 16:28:00 -07001004 /**
1005 * @return whether this view has a header on the top of the content
1006 */
1007 private boolean hasNotificationHeader() {
1008 return mIsSummaryWithChildren;
Selim Cinek1685e632014-04-08 02:27:49 +02001009 }
1010
Selim Cinek263398f2015-10-21 17:40:23 -07001011 private void onChildrenCountChanged() {
Selim Cinek8fc93c92015-11-23 17:48:07 -08001012 mIsSummaryWithChildren = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS
Selim Cinek263398f2015-10-21 17:40:23 -07001013 && mGroupManager.hasGroupChildren(mStatusBarNotification);
Selim Cinek8fc93c92015-11-23 17:48:07 -08001014 if (mIsSummaryWithChildren) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001015 if (mChildrenContainer == null) {
1016 mChildrenContainerStub.inflate();
1017 }
Selim Cinek8fc93c92015-11-23 17:48:07 -08001018 if (mNotificationHeader == null) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001019 recreateNotificationHeader();
1020 }
Selim Cinek263398f2015-10-21 17:40:23 -07001021 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001022 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinekea4bef72015-12-02 15:51:10 -08001023 updateChildrenHeaderAppearance();
Selim Cinekda42d652015-12-04 15:51:16 -08001024 updateChildrenVisibility();
Selim Cinek263398f2015-10-21 17:40:23 -07001025 }
1026
Selim Cinek1685e632014-04-08 02:27:49 +02001027 /**
1028 * Check whether the view state is currently expanded. This is given by the system in {@link
1029 * #setSystemExpanded(boolean)} and can be overridden by user expansion or
1030 * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this
1031 * view can differ from this state, if layout params are modified from outside.
1032 *
1033 * @return whether the view state is currently expanded.
1034 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001035 public boolean isExpanded() {
Selim Cineke81b82b2016-03-04 11:22:28 -08001036 return isExpanded(false /* allowOnKeyguard */);
1037 }
1038
1039 public boolean isExpanded(boolean allowOnKeyguard) {
1040 return (!mOnKeyguard || allowOnKeyguard)
Selim Cinekb5605e52015-02-20 18:21:41 +01001041 && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded())
1042 || isUserExpanded());
1043 }
1044
1045 private boolean isSystemChildExpanded() {
1046 return mIsSystemChildExpanded;
1047 }
1048
1049 public void setSystemChildExpanded(boolean expanded) {
1050 mIsSystemChildExpanded = expanded;
Selim Cinek1685e632014-04-08 02:27:49 +02001051 }
1052
1053 @Override
1054 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
1055 super.onLayout(changed, left, top, right, bottom);
Selim Cinek8d490d42015-04-10 00:05:50 -07001056 updateMaxHeights();
Selim Cinek1685e632014-04-08 02:27:49 +02001057 }
1058
Selim Cinek8d490d42015-04-10 00:05:50 -07001059 private void updateMaxHeights() {
Selim Cinekd2319fb2014-09-01 19:41:54 +02001060 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek8d490d42015-04-10 00:05:50 -07001061 View expandedChild = mPrivateLayout.getExpandedChild();
1062 if (expandedChild == null) {
1063 expandedChild = mPrivateLayout.getContractedChild();
1064 }
1065 mMaxExpandHeight = expandedChild.getHeight();
1066 View headsUpChild = mPrivateLayout.getHeadsUpChild();
Selim Cinek1f3f5442015-04-10 17:54:46 -07001067 if (headsUpChild == null) {
1068 headsUpChild = mPrivateLayout.getContractedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -07001069 }
Selim Cinek1f3f5442015-04-10 17:54:46 -07001070 mHeadsUpHeight = headsUpChild.getHeight();
Selim Cinekd2319fb2014-09-01 19:41:54 +02001071 if (intrinsicBefore != getIntrinsicHeight()) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001072 notifyHeightChanged(false /* needsAnimation */);
Selim Cinekd2319fb2014-09-01 19:41:54 +02001073 }
1074 }
1075
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001076 @Override
1077 public void notifyHeightChanged(boolean needsAnimation) {
1078 super.notifyHeightChanged(needsAnimation);
1079 getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked());
1080 }
1081
Selim Cinek3c76d502016-02-19 15:16:33 -08001082 public void setSensitive(boolean sensitive, boolean hideSensitive) {
Jorim Jaggiae441282014-08-01 02:45:18 +02001083 mSensitive = sensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -08001084 mSensitiveHiddenInGeneral = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02001085 }
1086
1087 public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
Selim Cinek60122be2015-04-15 18:16:50 -07001088 mHideSensitiveForIntrinsicHeight = hideSensitive;
Selim Cineka52f6a12016-02-29 15:35:58 -08001089 if (mIsSummaryWithChildren) {
1090 List<ExpandableNotificationRow> notificationChildren =
1091 mChildrenContainer.getNotificationChildren();
1092 for (int i = 0; i < notificationChildren.size(); i++) {
1093 ExpandableNotificationRow child = notificationChildren.get(i);
1094 child.setHideSensitiveForIntrinsicHeight(hideSensitive);
1095 }
1096 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001097 }
1098
1099 public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
1100 long duration) {
1101 boolean oldShowingPublic = mShowingPublic;
1102 mShowingPublic = mSensitive && hideSensitive;
1103 if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
1104 return;
1105 }
Dan Sandlera5e0f412014-01-23 15:11:54 -05001106
1107 // bail out if no public version
Selim Cinek1685e632014-04-08 02:27:49 +02001108 if (mPublicLayout.getChildCount() == 0) return;
Dan Sandlera5e0f412014-01-23 15:11:54 -05001109
Jorim Jaggiae441282014-08-01 02:45:18 +02001110 if (!animated) {
1111 mPublicLayout.animate().cancel();
1112 mPrivateLayout.animate().cancel();
1113 mPublicLayout.setAlpha(1f);
1114 mPrivateLayout.setAlpha(1f);
1115 mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
Selim Cinekd84a5932015-12-15 11:45:36 -08001116 updateChildrenVisibility();
Jorim Jaggiae441282014-08-01 02:45:18 +02001117 } else {
1118 animateShowingPublic(delay, duration);
1119 }
Selim Cinekc3179332016-03-04 14:44:56 -08001120 NotificationContentView showingLayout = getShowingLayout();
1121 showingLayout.updateBackgroundColor(animated);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001122 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinek757d8792016-01-28 16:21:08 -08001123 updateClearability();
Jorim Jaggiae441282014-08-01 02:45:18 +02001124 mShowingPublicInitialized = true;
1125 }
1126
1127 private void animateShowingPublic(long delay, long duration) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001128 View[] privateViews = mIsSummaryWithChildren ?
1129 new View[] {mChildrenContainer, mNotificationHeader}
1130 : new View[] {mPrivateLayout};
1131 View[] publicViews = new View[] {mPublicLayout};
1132 View[] hiddenChildren = mShowingPublic ? privateViews : publicViews;
1133 View[] shownChildren = mShowingPublic ? publicViews : privateViews;
1134 for (final View hiddenView : hiddenChildren) {
1135 hiddenView.setVisibility(View.VISIBLE);
1136 hiddenView.animate().cancel();
1137 hiddenView.animate()
1138 .alpha(0f)
1139 .setStartDelay(delay)
1140 .setDuration(duration)
1141 .withEndAction(new Runnable() {
1142 @Override
1143 public void run() {
1144 hiddenView.setVisibility(View.INVISIBLE);
1145 }
1146 });
1147 }
1148 for (View showView : shownChildren) {
1149 showView.setVisibility(View.VISIBLE);
1150 showView.setAlpha(0f);
1151 showView.animate().cancel();
1152 showView.animate()
1153 .alpha(1f)
1154 .setStartDelay(delay)
1155 .setDuration(duration);
1156 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001157 }
1158
Selim Cinek3776fe02016-02-04 13:32:43 -08001159 public boolean mustStayOnScreen() {
1160 return mIsHeadsUp;
1161 }
1162
Selim Cinek757d8792016-01-28 16:21:08 -08001163 private void updateClearability() {
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001164 // public versions cannot be dismissed
Selim Cinek3c76d502016-02-19 15:16:33 -08001165 mVetoButton.setVisibility(isClearable() && (!mShowingPublic
1166 || !mSensitiveHiddenInGeneral) ? View.VISIBLE : View.GONE);
Dan Sandlera5e0f412014-01-23 15:11:54 -05001167 }
Jorim Jaggi251957d2014-04-09 04:24:09 +02001168
Selim Cinekb5605e52015-02-20 18:21:41 +01001169 public void setChildrenExpanded(boolean expanded, boolean animate) {
1170 mChildrenExpanded = expanded;
Selim Cinek7b836392015-12-04 20:02:59 -08001171 if (mNotificationHeader != null) {
1172 mNotificationHeader.setExpanded(expanded);
1173 }
Selim Cinek83bc7832015-10-22 13:26:54 -07001174 if (mChildrenContainer != null) {
1175 mChildrenContainer.setChildrenExpanded(expanded);
1176 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001177 }
1178
Selim Cinekb5605e52015-02-20 18:21:41 +01001179 public static void applyTint(View v, int color) {
1180 int alpha;
1181 if (color != 0) {
1182 alpha = COLORED_DIVIDER_ALPHA;
1183 } else {
1184 color = 0xff000000;
1185 alpha = DEFAULT_DIVIDER_ALPHA;
1186 }
1187 if (v.getBackground() instanceof ColorDrawable) {
1188 ColorDrawable background = (ColorDrawable) v.getBackground();
1189 background.mutate();
1190 background.setColor(color);
1191 background.setAlpha(alpha);
1192 }
1193 }
1194
Selim Cinek1685e632014-04-08 02:27:49 +02001195 public int getMaxExpandHeight() {
Selim Cinekb5605e52015-02-20 18:21:41 +01001196 return mMaxExpandHeight;
Chris Wren51c75102013-07-16 20:49:17 -04001197 }
Jorim Jaggi584a7aa2014-04-10 23:26:13 +02001198
Mady Mellor34958fa2016-02-23 09:52:17 -08001199 public boolean areGutsExposed() {
1200 return (mGuts != null && mGuts.areGutsExposed());
1201 }
1202
Jorim Jaggibe565df2014-04-28 17:51:23 +02001203 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001204 public boolean isContentExpandable() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001205 NotificationContentView showingLayout = getShowingLayout();
1206 return showingLayout.isContentExpandable();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001207 }
1208
1209 @Override
Selim Cinek560e64d2015-06-09 19:58:11 -07001210 protected View getContentView() {
1211 return getShowingLayout();
1212 }
1213
1214 @Override
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001215 public void setActualHeight(int height, boolean notifyListeners) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001216 super.setActualHeight(height, notifyListeners);
Mady Mellorb53bc272016-02-11 18:28:23 -08001217 if (mGuts != null && mGuts.areGutsExposed()) {
1218 mGuts.setActualHeight(height);
1219 return;
1220 }
Selim Cinekeef84282015-10-30 16:28:00 -07001221 int contentHeight = Math.max(getMinHeight(), height);
Selim Cinekb5605e52015-02-20 18:21:41 +01001222 mPrivateLayout.setContentHeight(contentHeight);
1223 mPublicLayout.setContentHeight(contentHeight);
Selim Cinek42357e02016-02-24 18:48:01 -08001224 if (mIsSummaryWithChildren) {
1225 mChildrenContainer.setActualHeight(height);
1226 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001227 if (mGuts != null) {
1228 mGuts.setActualHeight(height);
1229 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001230 }
1231
1232 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01001233 public int getMaxContentHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001234 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001235 return mChildrenContainer.getMaxContentHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001236 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001237 NotificationContentView showingLayout = getShowingLayout();
1238 return showingLayout.getMaxHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001239 }
1240
1241 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001242 public int getMinHeight() {
Selim Cinek31aada42015-12-18 17:51:15 -08001243 if (mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) {
1244 return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
1245 } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001246 return mChildrenContainer.getMinHeight();
Selim Cinek31aada42015-12-18 17:51:15 -08001247 } else if (mIsHeadsUp) {
1248 return mHeadsUpHeight;
Selim Cinekb55386d2015-12-16 17:26:49 -08001249 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001250 NotificationContentView showingLayout = getShowingLayout();
1251 return showingLayout.getMinHeight();
1252 }
1253
1254 @Override
1255 public int getMinExpandHeight() {
Selim Cinek2c584612016-02-29 16:14:25 -08001256 if (mIsSummaryWithChildren && !mShowingPublic) {
1257 return mChildrenContainer.getMinExpandHeight(mOnKeyguard);
Selim Cinek83bc7832015-10-22 13:26:54 -07001258 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001259 return getMinHeight();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001260 }
1261
1262 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02001263 public void setClipTopAmount(int clipTopAmount) {
1264 super.setClipTopAmount(clipTopAmount);
1265 mPrivateLayout.setClipTopAmount(clipTopAmount);
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001266 mPublicLayout.setClipTopAmount(clipTopAmount);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001267 if (mGuts != null) {
1268 mGuts.setClipTopAmount(clipTopAmount);
1269 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001270 }
1271
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001272 private void recreateNotificationHeader() {
1273 final Notification.Builder builder = Notification.Builder.recoverBuilder(getContext(),
1274 getStatusBarNotification().getNotification());
1275 final RemoteViews header = builder.makeNotificationHeader();
1276 if (mNotificationHeader == null) {
1277 mNotificationHeader = (NotificationHeaderView) header.apply(getContext(), this);
1278 final View expandButton = mNotificationHeader.findViewById(
1279 com.android.internal.R.id.expand_button);
1280 expandButton.setVisibility(VISIBLE);
1281 mNotificationHeader.setOnClickListener(mExpandClickListener);
Selim Cinek9c7712d2015-12-08 19:19:48 -08001282 mNotificationHeaderWrapper = NotificationViewWrapper.wrap(getContext(),
1283 mNotificationHeader);
Selim Cinekb5a83612015-12-11 14:14:39 -08001284 addView(mNotificationHeader, indexOfChild(mChildrenContainer) + 1);
Mady Mellor4b80b102016-01-22 08:03:58 -08001285 mTranslateableViews.add(mNotificationHeader);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001286 } else {
1287 header.reapply(getContext(), mNotificationHeader);
Selim Cinek4ffd6362015-12-29 15:12:23 +01001288 mNotificationHeaderWrapper.notifyContentUpdated(mEntry.notification);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001289 }
Selim Cinekea4bef72015-12-02 15:51:10 -08001290 updateChildrenHeaderAppearance();
Selim Cinek343e6e22014-04-11 21:23:30 +02001291 }
Selim Cinek7d447722014-06-10 15:51:59 +02001292
Selim Cinekea4bef72015-12-02 15:51:10 -08001293 public void updateChildrenHeaderAppearance() {
1294 if (mIsSummaryWithChildren) {
1295 mHeaderUtil.updateChildrenHeaderAppearance();
1296 }
1297 }
1298
Selim Cinek31094df2014-08-14 19:28:15 +02001299 public boolean isMaxExpandHeightInitialized() {
1300 return mMaxExpandHeight != 0;
Selim Cinek7d447722014-06-10 15:51:59 +02001301 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001302
Selim Cinek42357e02016-02-24 18:48:01 -08001303 public NotificationContentView getShowingLayout() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001304 return mShowingPublic ? mPublicLayout : mPrivateLayout;
1305 }
Chris Wren78403d72014-07-28 10:23:24 +01001306
Jorim Jaggi59ec3042015-06-05 15:18:43 -07001307 @Override
1308 public void setShowingLegacyBackground(boolean showing) {
1309 super.setShowingLegacyBackground(showing);
1310 mPrivateLayout.setShowingLegacyBackground(showing);
1311 mPublicLayout.setShowingLegacyBackground(showing);
1312 }
1313
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001314 @Override
1315 protected void updateBackgroundTint() {
1316 super.updateBackgroundTint();
1317 updateNoBackgroundState();
1318 if (mIsSummaryWithChildren) {
1319 List<ExpandableNotificationRow> notificationChildren =
1320 mChildrenContainer.getNotificationChildren();
1321 for (int i = 0; i < notificationChildren.size(); i++) {
1322 ExpandableNotificationRow child = notificationChildren.get(i);
1323 child.updateNoBackgroundState();
1324 }
1325 }
1326 }
1327
1328 private void updateNoBackgroundState() {
1329 mShowNoBackground = isChildInGroup() && hasSameBgColor(mNotificationParent);
1330 updateBackground();
1331 }
1332
Chris Wren78403d72014-07-28 10:23:24 +01001333 public void setExpansionLogger(ExpansionLogger logger, String key) {
1334 mLogger = logger;
1335 mLoggingKey = key;
1336 }
1337
Selim Cinek6183d122016-01-14 18:48:41 -08001338 @Override
Selim Cinek42357e02016-02-24 18:48:01 -08001339 public float getIncreasedPaddingAmount() {
1340 if (mIsSummaryWithChildren) {
1341 if (isGroupExpanded()) {
1342 return 1.0f;
1343 } else if (isUserLocked()) {
1344 return mChildrenContainer.getChildExpandFraction();
1345 }
1346 }
1347 return 0.0f;
Selim Cinek61633a82016-01-25 15:54:10 -08001348 }
1349
1350 @Override
Selim Cinek6183d122016-01-14 18:48:41 -08001351 protected boolean disallowSingleClick(MotionEvent event) {
1352 float x = event.getX();
1353 float y = event.getY();
Selim Cinek34eda5e2016-02-18 17:10:43 -08001354 NotificationHeaderView header = getVisibleNotificationHeader();
Selim Cinek6183d122016-01-14 18:48:41 -08001355 if (header != null) {
1356 return header.isInTouchRect(x, y);
1357 }
1358 return super.disallowSingleClick(event);
1359 }
1360
Chris Wren78403d72014-07-28 10:23:24 +01001361 private void logExpansionEvent(boolean userAction, boolean wasExpanded) {
1362 final boolean nowExpanded = isExpanded();
1363 if (wasExpanded != nowExpanded && mLogger != null) {
1364 mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ;
1365 }
1366 }
Selim Cinek570981d2015-12-01 11:37:01 -08001367
1368 public interface OnExpandClickListener {
Selim Cinek31aada42015-12-18 17:51:15 -08001369 void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
Selim Cinek570981d2015-12-01 11:37:01 -08001370 }
Chris Wren51c75102013-07-16 20:49:17 -04001371}