blob: 397afb3a018ac2eb52782e2695749f481d83cc40 [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;
83 private boolean mShowingPublicInitialized;
Selim Cinek60122be2015-04-15 18:16:50 -070084 private boolean mHideSensitiveForIntrinsicHeight;
Chris Wren51c75102013-07-16 20:49:17 -040085
Selim Cinek1685e632014-04-08 02:27:49 +020086 /**
87 * Is this notification expanded by the system. The expansion state can be overridden by the
88 * user expansion.
89 */
90 private boolean mIsSystemExpanded;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +020091
92 /**
Selim Cinek83bc7832015-10-22 13:26:54 -070093 * Whether the notification is on the keyguard and the expansion is disabled.
Jorim Jaggidce3c4c2014-04-29 23:12:24 +020094 */
Selim Cinek83bc7832015-10-22 13:26:54 -070095 private boolean mOnKeyguard;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +020096
Mady Mellor4b80b102016-01-22 08:03:58 -080097 private AnimatorSet mTranslateAnim;
98 private ArrayList<View> mTranslateableViews;
Jorim Jaggibe565df2014-04-28 17:51:23 +020099 private NotificationContentView mPublicLayout;
100 private NotificationContentView mPrivateLayout;
Selim Cinek1685e632014-04-08 02:27:49 +0200101 private int mMaxExpandHeight;
Selim Cinek8d490d42015-04-10 00:05:50 -0700102 private int mHeadsUpHeight;
Selim Cinek863834b2014-05-20 04:20:25 +0200103 private View mVetoButton;
Dan Sandler0d3e62f2014-07-14 17:13:50 -0400104 private boolean mClearable;
Chris Wren78403d72014-07-28 10:23:24 +0100105 private ExpansionLogger mLogger;
106 private String mLoggingKey;
Selim Cineka5e211b2014-08-11 17:35:48 +0200107 private boolean mWasReset;
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() {
244 boolean customView = getPrivateLayout().getContractedChild().getId()
245 != com.android.internal.R.id.status_bar_latest_event_content;
246 boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N;
247 int minHeight = customView && beforeN && !mIsSummaryWithChildren ?
248 mNotificationMinHeightLegacy : mNotificationMinHeight;
Selim Cinek77019c72015-12-09 10:18:02 -0800249 boolean headsUpCustom = getPrivateLayout().getHeadsUpChild() != null &&
250 getPrivateLayout().getHeadsUpChild().getId()
251 != com.android.internal.R.id.status_bar_latest_event_content;
252 int headsUpheight = headsUpCustom && beforeN ? mMaxHeadsUpHeightLegacy
253 : mMaxHeadsUpHeight;
Selim Cinekda42d652015-12-04 15:51:16 -0800254 mMaxViewHeight = mNotificationMaxHeight;
Selim Cinek860b6da2015-12-16 19:02:19 -0800255 mPrivateLayout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight);
256 mPublicLayout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200257 }
258
259 public StatusBarNotification getStatusBarNotification() {
260 return mStatusBarNotification;
261 }
262
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700263 public boolean isHeadsUp() {
264 return mIsHeadsUp;
265 }
266
Selim Cinek1a521f32014-11-03 17:39:29 +0100267 public void setHeadsUp(boolean isHeadsUp) {
Selim Cinekc80fdb12015-04-13 15:09:08 -0700268 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek1a521f32014-11-03 17:39:29 +0100269 mIsHeadsUp = isHeadsUp;
Selim Cinek8d490d42015-04-10 00:05:50 -0700270 mPrivateLayout.setHeadsUp(isHeadsUp);
Selim Cinekc80fdb12015-04-13 15:09:08 -0700271 if (intrinsicBefore != getIntrinsicHeight()) {
272 notifyHeightChanged(false /* needsAnimation */);
273 }
Selim Cinek1a521f32014-11-03 17:39:29 +0100274 }
275
Selim Cinekb5605e52015-02-20 18:21:41 +0100276 public void setGroupManager(NotificationGroupManager groupManager) {
277 mGroupManager = groupManager;
Selim Cinek83bc7832015-10-22 13:26:54 -0700278 mPrivateLayout.setGroupManager(groupManager);
Selim Cinekb5605e52015-02-20 18:21:41 +0100279 }
280
Adrian Roosb88b1a12015-12-09 18:51:05 -0800281 public void setRemoteInputController(RemoteInputController r) {
282 mPrivateLayout.setRemoteInputController(r);
283 }
284
Selim Cinekb5605e52015-02-20 18:21:41 +0100285 public void addChildNotification(ExpandableNotificationRow row) {
286 addChildNotification(row, -1);
287 }
288
289 /**
290 * Add a child notification to this view.
291 *
292 * @param row the row to add
293 * @param childIndex the index to add it at, if -1 it will be added at the end
294 */
295 public void addChildNotification(ExpandableNotificationRow row, int childIndex) {
296 if (mChildrenContainer == null) {
297 mChildrenContainerStub.inflate();
298 }
299 mChildrenContainer.addNotification(row, childIndex);
Selim Cinek263398f2015-10-21 17:40:23 -0700300 onChildrenCountChanged();
301 row.setIsChildInGroup(true, this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100302 }
303
304 public void removeChildNotification(ExpandableNotificationRow row) {
305 if (mChildrenContainer != null) {
306 mChildrenContainer.removeNotification(row);
307 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800308 mHeaderUtil.restoreNotificationHeader(row);
Selim Cinek263398f2015-10-21 17:40:23 -0700309 onChildrenCountChanged();
310 row.setIsChildInGroup(false, null);
311 }
312
313 public boolean isChildInGroup() {
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700314 return mNotificationParent != null;
Selim Cinek263398f2015-10-21 17:40:23 -0700315 }
316
Selim Cinek388df6d2015-10-22 13:25:11 -0700317 public ExpandableNotificationRow getNotificationParent() {
318 return mNotificationParent;
319 }
320
Selim Cinek263398f2015-10-21 17:40:23 -0700321 /**
322 * @param isChildInGroup Is this notification now in a group
323 * @param parent the new parent notification
324 */
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700325 public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {;
326 boolean childInGroup = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup;
327 mNotificationParent = childInGroup ? parent : null;
328 mPrivateLayout.setIsChildInGroup(childInGroup);
329 updateNoBackgroundState();
Selim Cinek34d93b02015-10-22 12:30:38 -0700330 }
331
332 @Override
Selim Cinek72109472016-01-15 16:33:22 -0800333 public boolean onTouchEvent(MotionEvent event) {
334 if (event.getActionMasked() != MotionEvent.ACTION_DOWN
335 || !isChildInGroup() || isGroupExpanded()) {
336 return super.onTouchEvent(event);
337 } else {
338 return false;
339 }
340 }
341
342 @Override
Mady Mellorf0625802016-02-11 18:03:48 -0800343 protected boolean handleSlideBack() {
344 if (mSettingsIconRow != null && mSettingsIconRow.isVisible()) {
345 animateTranslateNotification(0 /* targetLeft */);
346 return true;
347 }
348 return false;
349 }
350
351 @Override
Selim Cinek34d93b02015-10-22 12:30:38 -0700352 protected boolean shouldHideBackground() {
353 return super.shouldHideBackground() || mShowNoBackground;
Selim Cinek263398f2015-10-21 17:40:23 -0700354 }
355
356 @Override
357 public boolean isSummaryWithChildren() {
358 return mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100359 }
360
361 @Override
362 public boolean areChildrenExpanded() {
363 return mChildrenExpanded;
364 }
365
366 public List<ExpandableNotificationRow> getNotificationChildren() {
367 return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren();
368 }
369
Selim Cinekeef84282015-10-30 16:28:00 -0700370 public int getNumberOfNotificationChildren() {
371 if (mChildrenContainer == null) {
372 return 0;
373 }
374 return mChildrenContainer.getNotificationChildren().size();
375 }
376
Selim Cinekb5605e52015-02-20 18:21:41 +0100377 /**
378 * Apply the order given in the list to the children.
379 *
380 * @param childOrder the new list order
381 * @return whether the list order has changed
382 */
383 public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder) {
384 return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder);
385 }
386
387 public void getChildrenStates(StackScrollState resultState) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700388 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100389 StackViewState parentState = resultState.getViewStateForView(this);
390 mChildrenContainer.getState(resultState, parentState);
391 }
392 }
393
394 public void applyChildrenState(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700395 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100396 mChildrenContainer.applyState(state);
397 }
398 }
399
400 public void prepareExpansionChanged(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700401 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100402 mChildrenContainer.prepareExpansionChanged(state);
403 }
404 }
405
406 public void startChildAnimation(StackScrollState finalState,
Selim Cinek99695592016-01-12 17:51:35 -0800407 StackStateAnimator stateAnimator, long delay, long duration) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700408 if (mIsSummaryWithChildren) {
Selim Cinek99695592016-01-12 17:51:35 -0800409 mChildrenContainer.startAnimationToState(finalState, stateAnimator, delay,
Selim Cinekb5605e52015-02-20 18:21:41 +0100410 duration);
411 }
412 }
413
414 public ExpandableNotificationRow getViewAtPosition(float y) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700415 if (!mIsSummaryWithChildren || !mChildrenExpanded) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100416 return this;
417 } else {
418 ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y);
419 return view == null ? this : view;
420 }
421 }
422
Selim Cinekab29aeb2015-02-20 18:18:32 +0100423 public NotificationGuts getGuts() {
424 return mGuts;
425 }
426
Selim Cinek684a4422015-04-15 16:18:39 -0700427 /**
428 * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this
429 * the notification will be rendered on top of the screen.
430 *
431 * @param pinned whether it is pinned
432 */
433 public void setPinned(boolean pinned) {
434 mIsPinned = pinned;
Selim Cinek31aada42015-12-18 17:51:15 -0800435 if (pinned) {
436 setIconAnimationRunning(true);
437 mExpandedWhenPinned = false;
438 } else if (mExpandedWhenPinned) {
439 setUserExpanded(true);
440 }
Selim Cinek98713a42015-09-21 15:47:20 +0200441 setChronometerRunning(mLastChronometerRunning);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700442 }
443
Selim Cinek684a4422015-04-15 16:18:39 -0700444 public boolean isPinned() {
445 return mIsPinned;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700446 }
447
Selim Cinek31aada42015-12-18 17:51:15 -0800448 /**
449 * @param atLeastMinHeight should the value returned be at least the minimum height.
450 * Used to avoid cyclic calls
451 * @return the height of the heads up notification when pinned
452 */
453 public int getPinnedHeadsUpHeight(boolean atLeastMinHeight) {
Selim Cinek77019c72015-12-09 10:18:02 -0800454 if (mIsSummaryWithChildren) {
455 return mChildrenContainer.getIntrinsicHeight();
456 }
Selim Cinek31aada42015-12-18 17:51:15 -0800457 if(mExpandedWhenPinned) {
458 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
459 } else if (atLeastMinHeight) {
460 return Math.max(getMinHeight(), mHeadsUpHeight);
461 } else {
462 return mHeadsUpHeight;
463 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700464 }
465
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700466 /**
467 * Mark whether this notification was just clicked, i.e. the user has just clicked this
468 * notification in this frame.
469 */
470 public void setJustClicked(boolean justClicked) {
471 mJustClicked = justClicked;
472 }
473
474 /**
475 * @return true if this notification has been clicked in this frame, false otherwise
476 */
477 public boolean wasJustClicked() {
478 return mJustClicked;
479 }
480
Selim Cinek98713a42015-09-21 15:47:20 +0200481 public void setChronometerRunning(boolean running) {
482 mLastChronometerRunning = running;
483 setChronometerRunning(running, mPrivateLayout);
484 setChronometerRunning(running, mPublicLayout);
485 if (mChildrenContainer != null) {
486 List<ExpandableNotificationRow> notificationChildren =
487 mChildrenContainer.getNotificationChildren();
488 for (int i = 0; i < notificationChildren.size(); i++) {
489 ExpandableNotificationRow child = notificationChildren.get(i);
490 child.setChronometerRunning(running);
491 }
492 }
493 }
494
495 private void setChronometerRunning(boolean running, NotificationContentView layout) {
496 if (layout != null) {
497 running = running || isPinned();
498 View contractedChild = layout.getContractedChild();
499 View expandedChild = layout.getExpandedChild();
500 View headsUpChild = layout.getHeadsUpChild();
501 setChronometerRunningForChild(running, contractedChild);
502 setChronometerRunningForChild(running, expandedChild);
503 setChronometerRunningForChild(running, headsUpChild);
504 }
505 }
506
507 private void setChronometerRunningForChild(boolean running, View child) {
508 if (child != null) {
509 View chronometer = child.findViewById(com.android.internal.R.id.chronometer);
510 if (chronometer instanceof Chronometer) {
511 ((Chronometer) chronometer).setStarted(running);
512 }
513 }
514 }
515
Selim Cinekea4bef72015-12-02 15:51:10 -0800516 public NotificationHeaderView getNotificationHeader() {
517 if (mNotificationHeader != null) {
518 return mNotificationHeader;
Selim Cinek8d6440d2015-10-22 13:00:05 -0700519 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800520 return mPrivateLayout.getNotificationHeader();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700521 }
522
Selim Cinek570981d2015-12-01 11:37:01 -0800523 public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) {
524 mOnExpandClickListener = onExpandClickListener;
525 }
526
Selim Cinek31aada42015-12-18 17:51:15 -0800527 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
528 mHeadsUpManager = headsUpManager;
529 }
530
Selim Cinek01af3342016-02-09 19:25:31 -0800531 public void reInflateViews() {
532 initDimens();
533 if (mIsSummaryWithChildren) {
534 removeView(mNotificationHeader);
535 mNotificationHeader = null;
536 recreateNotificationHeader();
537 if (mChildrenContainer != null) {
538 mChildrenContainer.reInflateViews();
539 }
540 }
541 if (mGuts != null) {
542 View oldGuts = mGuts;
543 int index = indexOfChild(oldGuts);
544 removeView(oldGuts);
545 mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate(
546 R.layout.notification_guts, this, false);
547 mGuts.setVisibility(oldGuts.getVisibility());
548 addView(mGuts, index);
549 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800550 if (mSettingsIconRow != null) {
551 View oldSettings = mSettingsIconRow;
552 int settingsIndex = indexOfChild(oldSettings);
553 removeView(oldSettings);
554 mSettingsIconRow = (NotificationSettingsIconRow) LayoutInflater.from(mContext).inflate(
555 R.layout.notification_settings_icon_row, this, false);
556 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
557 mSettingsIconRow.setVisibility(oldSettings.getVisibility());
558 addView(mSettingsIconRow, settingsIndex);
559
560 }
Selim Cinekde33a4a2016-02-11 16:43:41 -0800561 mPrivateLayout.reInflateViews();
562 mPublicLayout.reInflateViews();
Selim Cinek01af3342016-02-09 19:25:31 -0800563 }
564
Chris Wren78403d72014-07-28 10:23:24 +0100565 public interface ExpansionLogger {
566 public void logNotificationExpansion(String key, boolean userAction, boolean expanded);
567 }
Selim Cinek1685e632014-04-08 02:27:49 +0200568
Chris Wren51c75102013-07-16 20:49:17 -0400569 public ExpandableNotificationRow(Context context, AttributeSet attrs) {
570 super(context, attrs);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700571 mFalsingManager = FalsingManager.getInstance(context);
Selim Cinek01af3342016-02-09 19:25:31 -0800572 initDimens();
573 }
574
575 private void initDimens() {
Selim Cinekda42d652015-12-04 15:51:16 -0800576 mNotificationMinHeightLegacy = getResources().getDimensionPixelSize(
577 R.dimen.notification_min_height_legacy);
578 mNotificationMinHeight = getResources().getDimensionPixelSize(
579 R.dimen.notification_min_height);
580 mNotificationMaxHeight = getResources().getDimensionPixelSize(
581 R.dimen.notification_max_height);
Selim Cinek77019c72015-12-09 10:18:02 -0800582 mMaxHeadsUpHeightLegacy = getResources().getDimensionPixelSize(
583 R.dimen.notification_max_heads_up_height_legacy);
584 mMaxHeadsUpHeight = getResources().getDimensionPixelSize(
585 R.dimen.notification_max_heads_up_height);
Chris Wren51c75102013-07-16 20:49:17 -0400586 }
587
Christoph Studera7fe6312014-06-27 19:32:44 +0200588 /**
589 * Resets this view so it can be re-used for an updated notification.
590 */
Christoph Studer22f2ee52014-07-29 22:57:21 +0200591 @Override
Christoph Studera7fe6312014-06-27 19:32:44 +0200592 public void reset() {
Christoph Studer22f2ee52014-07-29 22:57:21 +0200593 super.reset();
Chris Wren78403d72014-07-28 10:23:24 +0100594 final boolean wasExpanded = isExpanded();
Selim Cinek379ff8f2015-02-20 17:03:16 +0100595 mMaxViewHeight = 0;
Christoph Studera7fe6312014-06-27 19:32:44 +0200596 mExpandable = false;
597 mHasUserChangedExpansion = false;
598 mUserLocked = false;
599 mShowingPublic = false;
Jorim Jaggiae441282014-08-01 02:45:18 +0200600 mSensitive = false;
601 mShowingPublicInitialized = false;
Christoph Studera7fe6312014-06-27 19:32:44 +0200602 mIsSystemExpanded = false;
Selim Cinek83bc7832015-10-22 13:26:54 -0700603 mOnKeyguard = false;
Selim Cinek1a521f32014-11-03 17:39:29 +0100604 mPublicLayout.reset(mIsHeadsUp);
605 mPrivateLayout.reset(mIsHeadsUp);
Selim Cinek31094df2014-08-14 19:28:15 +0200606 resetHeight();
Mady Mellor4b80b102016-01-22 08:03:58 -0800607 resetTranslation();
Selim Cinek31094df2014-08-14 19:28:15 +0200608 logExpansionEvent(false, wasExpanded);
609 }
610
611 public void resetHeight() {
Selim Cinek1a521f32014-11-03 17:39:29 +0100612 if (mIsHeadsUp) {
613 resetActualHeight();
614 }
Christoph Studera7fe6312014-06-27 19:32:44 +0200615 mMaxExpandHeight = 0;
Selim Cinek8d490d42015-04-10 00:05:50 -0700616 mHeadsUpHeight = 0;
Selim Cineka5e211b2014-08-11 17:35:48 +0200617 mWasReset = true;
Selim Cinek31094df2014-08-14 19:28:15 +0200618 onHeightReset();
Selim Cinek6e28a672014-09-05 14:43:28 +0200619 requestLayout();
Christoph Studera7fe6312014-06-27 19:32:44 +0200620 }
621
Jorim Jaggi251957d2014-04-09 04:24:09 +0200622 @Override
623 protected void onFinishInflate() {
624 super.onFinishInflate();
Jorim Jaggibe565df2014-04-28 17:51:23 +0200625 mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800626 mPublicLayout.setContainingNotification(this);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200627 mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800628 mPrivateLayout.setExpandClickListener(mExpandClickListener);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800629 mPrivateLayout.setContainingNotification(this);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800630 mPublicLayout.setExpandClickListener(mExpandClickListener);
Mady Mellor4b80b102016-01-22 08:03:58 -0800631 mSettingsIconRowStub = (ViewStub) findViewById(R.id.settings_icon_row_stub);
632 mSettingsIconRowStub.setOnInflateListener(new ViewStub.OnInflateListener() {
633 @Override
634 public void onInflate(ViewStub stub, View inflated) {
635 mSettingsIconRow = (NotificationSettingsIconRow) inflated;
636 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
637 }
638 });
Selim Cinekab29aeb2015-02-20 18:18:32 +0100639 mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub);
640 mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() {
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200641 @Override
642 public void onInflate(ViewStub stub, View inflated) {
643 mGuts = (NotificationGuts) inflated;
644 mGuts.setClipTopAmount(getClipTopAmount());
645 mGuts.setActualHeight(getActualHeight());
Mady Mellor4b80b102016-01-22 08:03:58 -0800646 mTranslateableViews.add(mGuts);
Selim Cinekab29aeb2015-02-20 18:18:32 +0100647 mGutsStub = null;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200648 }
649 });
Selim Cinekb5605e52015-02-20 18:21:41 +0100650 mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub);
651 mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() {
652
653 @Override
654 public void onInflate(ViewStub stub, View inflated) {
655 mChildrenContainer = (NotificationChildrenContainer) inflated;
Selim Cinek388df6d2015-10-22 13:25:11 -0700656 mChildrenContainer.setNotificationParent(ExpandableNotificationRow.this);
Mady Mellor4b80b102016-01-22 08:03:58 -0800657 mTranslateableViews.add(mChildrenContainer);
Selim Cinekb5605e52015-02-20 18:21:41 +0100658 }
659 });
Selim Cinek863834b2014-05-20 04:20:25 +0200660 mVetoButton = findViewById(R.id.veto);
Mady Mellor4b80b102016-01-22 08:03:58 -0800661
662 // Add the views that we translate to reveal the gear
663 mTranslateableViews = new ArrayList<View>();
664 for (int i = 0; i < getChildCount(); i++) {
665 mTranslateableViews.add(getChildAt(i));
666 }
667 // Remove views that don't translate
668 mTranslateableViews.remove(mVetoButton);
669 mTranslateableViews.remove(mSettingsIconRowStub);
670 mTranslateableViews.remove(mChildrenContainerStub);
671 mTranslateableViews.remove(mGutsStub);
672 }
673
674 public void setTranslationForOutline(float translationX) {
675 setOutlineRect(false, translationX, getTop(), getRight() + translationX, getBottom());
676 }
677
678 public void resetTranslation() {
679 if (mTranslateableViews != null) {
680 for (int i = 0; i < mTranslateableViews.size(); i++) {
681 mTranslateableViews.get(i).setTranslationX(0);
682 }
683 setTranslationForOutline(0);
684 }
685 if (mSettingsIconRow != null) {
686 mSettingsIconRow.resetState();
687 }
688 }
689
690 public void animateTranslateNotification(final float leftTarget) {
691 if (mTranslateAnim != null) {
692 mTranslateAnim.cancel();
693 }
694 AnimatorSet set = new AnimatorSet();
695 if (mTranslateableViews != null) {
696 for (int i = 0; i < mTranslateableViews.size(); i++) {
697 final View animView = mTranslateableViews.get(i);
698 final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(
699 animView, "translationX", leftTarget);
700 if (i == 0) {
701 translateAnim.addUpdateListener(new AnimatorUpdateListener() {
702 @Override
703 public void onAnimationUpdate(ValueAnimator animation) {
704 setTranslationForOutline((float) animation.getAnimatedValue());
705 }
706 });
707 }
708 translateAnim.addListener(new AnimatorListenerAdapter() {
709 @Override
710 public void onAnimationEnd(Animator anim) {
711 if (mSettingsIconRow != null && leftTarget == 0) {
712 mSettingsIconRow.resetState();
713 }
714 mTranslateAnim = null;
715 }
716 });
717 set.play(translateAnim);
718 }
719 }
720 mTranslateAnim = set;
721 set.start();
722 }
723
724 public float getSpaceForGear() {
725 if (mSettingsIconRow != null) {
726 return mSettingsIconRow.getSpaceForGear();
727 }
728 return 0;
729 }
730
731 public NotificationSettingsIconRow getSettingsRow() {
732 if (mSettingsIconRow == null) {
733 mSettingsIconRowStub.inflate();
734 }
735 return mSettingsIconRow;
736 }
737
738 public ArrayList<View> getContentViews() {
739 return mTranslateableViews;
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200740 }
741
Selim Cinekab29aeb2015-02-20 18:18:32 +0100742 public void inflateGuts() {
743 if (mGuts == null) {
744 mGutsStub.inflate();
745 }
746 }
747
Selim Cinekda42d652015-12-04 15:51:16 -0800748 private void updateChildrenVisibility() {
Selim Cinekd84a5932015-12-15 11:45:36 -0800749 mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE
750 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -0800751 if (mChildrenContainer != null) {
752 mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
753 : INVISIBLE);
Selim Cinekb5605e52015-02-20 18:21:41 +0100754 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800755 if (mNotificationHeader != null) {
756 mNotificationHeader.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
757 : INVISIBLE);
758 }
Selim Cinekda42d652015-12-04 15:51:16 -0800759 // The limits might have changed if the view suddenly became a group or vice versa
760 updateLimits();
Selim Cinekb5605e52015-02-20 18:21:41 +0100761 }
762
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200763 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -0800764 public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
765 if (super.onRequestSendAccessibilityEventInternal(child, event)) {
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200766 // Add a record for the entire layout since its content is somehow small.
767 // The event comes from a leaf view that is interacted with.
768 AccessibilityEvent record = AccessibilityEvent.obtain();
769 onInitializeAccessibilityEvent(record);
770 dispatchPopulateAccessibilityEvent(record);
771 event.appendRecord(record);
772 return true;
773 }
774 return false;
Jorim Jaggic5dc0d02014-04-15 15:42:55 +0200775 }
Chris Wren51c75102013-07-16 20:49:17 -0400776
John Spurlocke15452b2014-08-21 09:44:39 -0400777 @Override
Jorim Jaggi4e857f42014-11-17 19:14:04 +0100778 public void setDark(boolean dark, boolean fade, long delay) {
779 super.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -0400780 final NotificationContentView showing = getShowingLayout();
781 if (showing != null) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +0100782 showing.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -0400783 }
Selim Cinek9c7712d2015-12-08 19:19:48 -0800784 if (mIsSummaryWithChildren) {
785 mChildrenContainer.setDark(dark, fade, delay);
786 mNotificationHeaderWrapper.setDark(dark, fade, delay);
787 }
John Spurlocke15452b2014-08-21 09:44:39 -0400788 }
789
Chris Wren51c75102013-07-16 20:49:17 -0400790 public boolean isExpandable() {
Selim Cinek388df6d2015-10-22 13:25:11 -0700791 if (mIsSummaryWithChildren && !mShowingPublic) {
792 return !mChildrenExpanded;
793 }
Chris Wren51c75102013-07-16 20:49:17 -0400794 return mExpandable;
795 }
796
797 public void setExpandable(boolean expandable) {
798 mExpandable = expandable;
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800799 mPrivateLayout.updateExpandButtons(isExpandable());
Chris Wren51c75102013-07-16 20:49:17 -0400800 }
801
Selim Cinek4ffd6362015-12-29 15:12:23 +0100802 @Override
803 public void setClipToActualHeight(boolean clipToActualHeight) {
Selim Cinek084c16b2016-01-22 17:48:22 -0800804 super.setClipToActualHeight(clipToActualHeight || isUserLocked());
805 getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked());
Selim Cinek4ffd6362015-12-29 15:12:23 +0100806 }
807
Selim Cinek1685e632014-04-08 02:27:49 +0200808 /**
809 * @return whether the user has changed the expansion state
810 */
811 public boolean hasUserChangedExpansion() {
812 return mHasUserChangedExpansion;
813 }
814
Chris Wren51c75102013-07-16 20:49:17 -0400815 public boolean isUserExpanded() {
816 return mUserExpanded;
817 }
818
Selim Cinek1685e632014-04-08 02:27:49 +0200819 /**
820 * Set this notification to be expanded by the user
821 *
822 * @param userExpanded whether the user wants this notification to be expanded
823 */
Chris Wren51c75102013-07-16 20:49:17 -0400824 public void setUserExpanded(boolean userExpanded) {
Selim Cinek388df6d2015-10-22 13:25:11 -0700825 setUserExpanded(userExpanded, false /* allowChildExpansion */);
826 }
827
828 /**
829 * Set this notification to be expanded by the user
830 *
831 * @param userExpanded whether the user wants this notification to be expanded
832 * @param allowChildExpansion whether a call to this method allows expanding children
833 */
834 public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700835 mFalsingManager.setNotificationExpanded();
Selim Cinek388df6d2015-10-22 13:25:11 -0700836 if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion) {
837 mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded);
838 return;
839 }
Christoph Studera7fe6312014-06-27 19:32:44 +0200840 if (userExpanded && !mExpandable) return;
Chris Wren78403d72014-07-28 10:23:24 +0100841 final boolean wasExpanded = isExpanded();
Selim Cinek1685e632014-04-08 02:27:49 +0200842 mHasUserChangedExpansion = true;
Chris Wren51c75102013-07-16 20:49:17 -0400843 mUserExpanded = userExpanded;
Chris Wren78403d72014-07-28 10:23:24 +0100844 logExpansionEvent(true, wasExpanded);
Chris Wren51c75102013-07-16 20:49:17 -0400845 }
846
Selim Cinekccd14fb2014-08-12 18:53:24 +0200847 public void resetUserExpansion() {
848 mHasUserChangedExpansion = false;
849 mUserExpanded = false;
850 }
851
Chris Wren51c75102013-07-16 20:49:17 -0400852 public boolean isUserLocked() {
853 return mUserLocked;
854 }
855
856 public void setUserLocked(boolean userLocked) {
857 mUserLocked = userLocked;
858 }
859
Selim Cinek1685e632014-04-08 02:27:49 +0200860 /**
861 * @return has the system set this notification to be expanded
862 */
863 public boolean isSystemExpanded() {
864 return mIsSystemExpanded;
865 }
866
867 /**
868 * Set this notification to be expanded by the system.
869 *
870 * @param expand whether the system wants this notification to be expanded.
871 */
872 public void setSystemExpanded(boolean expand) {
Selim Cinek31094df2014-08-14 19:28:15 +0200873 if (expand != mIsSystemExpanded) {
874 final boolean wasExpanded = isExpanded();
875 mIsSystemExpanded = expand;
Selim Cinekb5605e52015-02-20 18:21:41 +0100876 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +0200877 logExpansionEvent(false, wasExpanded);
Selim Cinek83bc7832015-10-22 13:26:54 -0700878 if (mChildrenContainer != null) {
879 mChildrenContainer.updateGroupOverflow();
880 }
Selim Cinek31094df2014-08-14 19:28:15 +0200881 }
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200882 }
883
884 /**
Selim Cinek83bc7832015-10-22 13:26:54 -0700885 * @param onKeyguard whether to prevent notification expansion
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200886 */
Selim Cinek83bc7832015-10-22 13:26:54 -0700887 public void setOnKeyguard(boolean onKeyguard) {
888 if (onKeyguard != mOnKeyguard) {
Selim Cinek31094df2014-08-14 19:28:15 +0200889 final boolean wasExpanded = isExpanded();
Selim Cinek83bc7832015-10-22 13:26:54 -0700890 mOnKeyguard = onKeyguard;
Selim Cinek31094df2014-08-14 19:28:15 +0200891 logExpansionEvent(false, wasExpanded);
892 if (wasExpanded != isExpanded()) {
Selim Cinek2108fe02015-12-10 12:56:13 -0800893 if (mIsSummaryWithChildren) {
894 mChildrenContainer.updateGroupOverflow();
895 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800896 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +0200897 }
898 }
Selim Cinek1685e632014-04-08 02:27:49 +0200899 }
900
901 /**
Dan Sandler0d3e62f2014-07-14 17:13:50 -0400902 * @return Can the underlying notification be cleared?
903 */
904 public boolean isClearable() {
Selim Cineka37774f2014-11-11 19:16:18 +0100905 return mStatusBarNotification != null && mStatusBarNotification.isClearable();
Dan Sandler0d3e62f2014-07-14 17:13:50 -0400906 }
907
908 /**
Selim Cinek1685e632014-04-08 02:27:49 +0200909 * Apply an expansion state to the layout.
Selim Cinek1685e632014-04-08 02:27:49 +0200910 */
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200911 public void applyExpansionToLayout() {
912 boolean expand = isExpanded();
Chris Wren51c75102013-07-16 20:49:17 -0400913 if (expand && mExpandable) {
Selim Cinekeef84282015-10-30 16:28:00 -0700914 setActualHeight(mMaxExpandHeight);
Chris Wren51c75102013-07-16 20:49:17 -0400915 } else {
Selim Cinek860b6da2015-12-16 19:02:19 -0800916 setActualHeight(getMinHeight());
Chris Wren51c75102013-07-16 20:49:17 -0400917 }
Chris Wren51c75102013-07-16 20:49:17 -0400918 }
Dan Sandlera5e0f412014-01-23 15:11:54 -0500919
Jorim Jaggi9cbadd32014-05-01 20:18:31 +0200920 @Override
921 public int getIntrinsicHeight() {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200922 if (isUserLocked()) {
923 return getActualHeight();
924 }
Selim Cinekd84a5932015-12-15 11:45:36 -0800925 if (mGuts != null && mGuts.areGutsExposed()) {
926 return mGuts.getHeight();
927 } else if ((isChildInGroup() && !isGroupExpanded())) {
928 return mPrivateLayout.getMinHeight();
929 } else if (mSensitive && mHideSensitiveForIntrinsicHeight) {
930 return getMinHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -0700931 } else if (mIsSummaryWithChildren && !mOnKeyguard) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800932 return mChildrenContainer.getIntrinsicHeight();
Selim Cinek60122be2015-04-15 18:16:50 -0700933 } else if (mIsHeadsUp) {
Selim Cinek31aada42015-12-18 17:51:15 -0800934 if (isPinned()) {
935 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
936 } else if (isExpanded()) {
Selim Cinekd84a5932015-12-15 11:45:36 -0800937 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -0700938 } else {
Selim Cinekd84a5932015-12-15 11:45:36 -0800939 return Math.max(getMinHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -0700940 }
Selim Cinek31aada42015-12-18 17:51:15 -0800941 } else if (isExpanded()) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700942 return getMaxExpandHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -0800943 } else {
944 return getMinHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200945 }
Selim Cinekb5605e52015-02-20 18:21:41 +0100946 }
Selim Cinek1685e632014-04-08 02:27:49 +0200947
Selim Cinekeef84282015-10-30 16:28:00 -0700948 private boolean isGroupExpanded() {
949 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinekb5605e52015-02-20 18:21:41 +0100950 }
951
Selim Cinekeef84282015-10-30 16:28:00 -0700952 /**
953 * @return whether this view has a header on the top of the content
954 */
955 private boolean hasNotificationHeader() {
956 return mIsSummaryWithChildren;
Selim Cinek1685e632014-04-08 02:27:49 +0200957 }
958
Selim Cinek263398f2015-10-21 17:40:23 -0700959 private void onChildrenCountChanged() {
Selim Cinek8fc93c92015-11-23 17:48:07 -0800960 mIsSummaryWithChildren = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS
Selim Cinek263398f2015-10-21 17:40:23 -0700961 && mGroupManager.hasGroupChildren(mStatusBarNotification);
Selim Cinek8fc93c92015-11-23 17:48:07 -0800962 if (mIsSummaryWithChildren) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800963 if (mChildrenContainer == null) {
964 mChildrenContainerStub.inflate();
965 }
Selim Cinek8fc93c92015-11-23 17:48:07 -0800966 if (mNotificationHeader == null) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800967 recreateNotificationHeader();
968 }
Selim Cinek263398f2015-10-21 17:40:23 -0700969 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800970 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinekea4bef72015-12-02 15:51:10 -0800971 updateChildrenHeaderAppearance();
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800972 updateHeaderChildCount();
Selim Cinekda42d652015-12-04 15:51:16 -0800973 updateChildrenVisibility();
Selim Cinek263398f2015-10-21 17:40:23 -0700974 }
975
Selim Cinek1685e632014-04-08 02:27:49 +0200976 /**
977 * Check whether the view state is currently expanded. This is given by the system in {@link
978 * #setSystemExpanded(boolean)} and can be overridden by user expansion or
979 * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this
980 * view can differ from this state, if layout params are modified from outside.
981 *
982 * @return whether the view state is currently expanded.
983 */
Selim Cinek83bc7832015-10-22 13:26:54 -0700984 public boolean isExpanded() {
985 return !mOnKeyguard
Selim Cinekb5605e52015-02-20 18:21:41 +0100986 && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded())
987 || isUserExpanded());
988 }
989
990 private boolean isSystemChildExpanded() {
991 return mIsSystemChildExpanded;
992 }
993
994 public void setSystemChildExpanded(boolean expanded) {
995 mIsSystemChildExpanded = expanded;
Selim Cinek1685e632014-04-08 02:27:49 +0200996 }
997
998 @Override
999 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
1000 super.onLayout(changed, left, top, right, bottom);
Selim Cineka5e211b2014-08-11 17:35:48 +02001001 boolean updateExpandHeight = mMaxExpandHeight == 0 && !mWasReset;
Selim Cinek8d490d42015-04-10 00:05:50 -07001002 updateMaxHeights();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001003 if (updateExpandHeight) {
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001004 applyExpansionToLayout();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001005 }
Selim Cineka5e211b2014-08-11 17:35:48 +02001006 mWasReset = false;
Selim Cinek1685e632014-04-08 02:27:49 +02001007 }
1008
Selim Cinek8d490d42015-04-10 00:05:50 -07001009 private void updateMaxHeights() {
Selim Cinekd2319fb2014-09-01 19:41:54 +02001010 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek8d490d42015-04-10 00:05:50 -07001011 View expandedChild = mPrivateLayout.getExpandedChild();
1012 if (expandedChild == null) {
1013 expandedChild = mPrivateLayout.getContractedChild();
1014 }
1015 mMaxExpandHeight = expandedChild.getHeight();
1016 View headsUpChild = mPrivateLayout.getHeadsUpChild();
Selim Cinek1f3f5442015-04-10 17:54:46 -07001017 if (headsUpChild == null) {
1018 headsUpChild = mPrivateLayout.getContractedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -07001019 }
Selim Cinek1f3f5442015-04-10 17:54:46 -07001020 mHeadsUpHeight = headsUpChild.getHeight();
Selim Cinekd2319fb2014-09-01 19:41:54 +02001021 if (intrinsicBefore != getIntrinsicHeight()) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001022 notifyHeightChanged(false /* needsAnimation */);
Selim Cinekd2319fb2014-09-01 19:41:54 +02001023 }
1024 }
1025
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001026 @Override
1027 public void notifyHeightChanged(boolean needsAnimation) {
1028 super.notifyHeightChanged(needsAnimation);
1029 getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked());
1030 }
1031
Jorim Jaggiae441282014-08-01 02:45:18 +02001032 public void setSensitive(boolean sensitive) {
1033 mSensitive = sensitive;
1034 }
1035
1036 public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
Selim Cinek60122be2015-04-15 18:16:50 -07001037 mHideSensitiveForIntrinsicHeight = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02001038 }
1039
1040 public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
1041 long duration) {
1042 boolean oldShowingPublic = mShowingPublic;
1043 mShowingPublic = mSensitive && hideSensitive;
1044 if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
1045 return;
1046 }
Dan Sandlera5e0f412014-01-23 15:11:54 -05001047
1048 // bail out if no public version
Selim Cinek1685e632014-04-08 02:27:49 +02001049 if (mPublicLayout.getChildCount() == 0) return;
Dan Sandlera5e0f412014-01-23 15:11:54 -05001050
Jorim Jaggiae441282014-08-01 02:45:18 +02001051 if (!animated) {
1052 mPublicLayout.animate().cancel();
1053 mPrivateLayout.animate().cancel();
1054 mPublicLayout.setAlpha(1f);
1055 mPrivateLayout.setAlpha(1f);
1056 mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
Selim Cinekd84a5932015-12-15 11:45:36 -08001057 updateChildrenVisibility();
Jorim Jaggiae441282014-08-01 02:45:18 +02001058 } else {
1059 animateShowingPublic(delay, duration);
1060 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001061
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001062 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinek757d8792016-01-28 16:21:08 -08001063 updateClearability();
Jorim Jaggiae441282014-08-01 02:45:18 +02001064 mShowingPublicInitialized = true;
1065 }
1066
1067 private void animateShowingPublic(long delay, long duration) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001068 View[] privateViews = mIsSummaryWithChildren ?
1069 new View[] {mChildrenContainer, mNotificationHeader}
1070 : new View[] {mPrivateLayout};
1071 View[] publicViews = new View[] {mPublicLayout};
1072 View[] hiddenChildren = mShowingPublic ? privateViews : publicViews;
1073 View[] shownChildren = mShowingPublic ? publicViews : privateViews;
1074 for (final View hiddenView : hiddenChildren) {
1075 hiddenView.setVisibility(View.VISIBLE);
1076 hiddenView.animate().cancel();
1077 hiddenView.animate()
1078 .alpha(0f)
1079 .setStartDelay(delay)
1080 .setDuration(duration)
1081 .withEndAction(new Runnable() {
1082 @Override
1083 public void run() {
1084 hiddenView.setVisibility(View.INVISIBLE);
1085 }
1086 });
1087 }
1088 for (View showView : shownChildren) {
1089 showView.setVisibility(View.VISIBLE);
1090 showView.setAlpha(0f);
1091 showView.animate().cancel();
1092 showView.animate()
1093 .alpha(1f)
1094 .setStartDelay(delay)
1095 .setDuration(duration);
1096 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001097 }
1098
Selim Cinek3776fe02016-02-04 13:32:43 -08001099 public boolean mustStayOnScreen() {
1100 return mIsHeadsUp;
1101 }
1102
Selim Cinek757d8792016-01-28 16:21:08 -08001103 private void updateClearability() {
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001104 // public versions cannot be dismissed
1105 mVetoButton.setVisibility(isClearable() && !mShowingPublic ? View.VISIBLE : View.GONE);
Dan Sandlera5e0f412014-01-23 15:11:54 -05001106 }
Jorim Jaggi251957d2014-04-09 04:24:09 +02001107
Selim Cinekb5605e52015-02-20 18:21:41 +01001108 public void setChildrenExpanded(boolean expanded, boolean animate) {
1109 mChildrenExpanded = expanded;
Selim Cinek7b836392015-12-04 20:02:59 -08001110 if (mNotificationHeader != null) {
1111 mNotificationHeader.setExpanded(expanded);
1112 }
Selim Cinek83bc7832015-10-22 13:26:54 -07001113 if (mChildrenContainer != null) {
1114 mChildrenContainer.setChildrenExpanded(expanded);
1115 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001116 }
1117
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001118 public void updateHeaderChildCount() {
1119 if (mIsSummaryWithChildren) {
1120 mNotificationHeader.setChildCount(
1121 mChildrenContainer.getNotificationChildren().size());
Selim Cinekb5605e52015-02-20 18:21:41 +01001122 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001123 }
1124
1125 public static void applyTint(View v, int color) {
1126 int alpha;
1127 if (color != 0) {
1128 alpha = COLORED_DIVIDER_ALPHA;
1129 } else {
1130 color = 0xff000000;
1131 alpha = DEFAULT_DIVIDER_ALPHA;
1132 }
1133 if (v.getBackground() instanceof ColorDrawable) {
1134 ColorDrawable background = (ColorDrawable) v.getBackground();
1135 background.mutate();
1136 background.setColor(color);
1137 background.setAlpha(alpha);
1138 }
1139 }
1140
Selim Cinek1685e632014-04-08 02:27:49 +02001141 public int getMaxExpandHeight() {
Selim Cinekb5605e52015-02-20 18:21:41 +01001142 return mMaxExpandHeight;
Chris Wren51c75102013-07-16 20:49:17 -04001143 }
Jorim Jaggi584a7aa2014-04-10 23:26:13 +02001144
Jorim Jaggibe565df2014-04-28 17:51:23 +02001145 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001146 public boolean isContentExpandable() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001147 NotificationContentView showingLayout = getShowingLayout();
1148 return showingLayout.isContentExpandable();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001149 }
1150
1151 @Override
Selim Cinek560e64d2015-06-09 19:58:11 -07001152 protected View getContentView() {
1153 return getShowingLayout();
1154 }
1155
1156 @Override
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001157 public void setActualHeight(int height, boolean notifyListeners) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001158 super.setActualHeight(height, notifyListeners);
Selim Cinekeef84282015-10-30 16:28:00 -07001159 int contentHeight = Math.max(getMinHeight(), height);
Selim Cinekb5605e52015-02-20 18:21:41 +01001160 mPrivateLayout.setContentHeight(contentHeight);
1161 mPublicLayout.setContentHeight(contentHeight);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001162 if (mGuts != null) {
1163 mGuts.setActualHeight(height);
1164 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001165 invalidate();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001166 }
1167
1168 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01001169 public int getMaxContentHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001170 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001171 return mChildrenContainer.getMaxContentHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001172 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001173 NotificationContentView showingLayout = getShowingLayout();
1174 return showingLayout.getMaxHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001175 }
1176
1177 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001178 public int getMinHeight() {
Selim Cinek31aada42015-12-18 17:51:15 -08001179 if (mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) {
1180 return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
1181 } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001182 return mChildrenContainer.getMinHeight();
Selim Cinek31aada42015-12-18 17:51:15 -08001183 } else if (mIsHeadsUp) {
1184 return mHeadsUpHeight;
Selim Cinekb55386d2015-12-16 17:26:49 -08001185 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001186 NotificationContentView showingLayout = getShowingLayout();
1187 return showingLayout.getMinHeight();
1188 }
1189
1190 @Override
1191 public int getMinExpandHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001192 if (mIsSummaryWithChildren && !mOnKeyguard) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001193 return mChildrenContainer.getMinExpandHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001194 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001195 return getMinHeight();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001196 }
1197
1198 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02001199 public void setClipTopAmount(int clipTopAmount) {
1200 super.setClipTopAmount(clipTopAmount);
1201 mPrivateLayout.setClipTopAmount(clipTopAmount);
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001202 mPublicLayout.setClipTopAmount(clipTopAmount);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001203 if (mGuts != null) {
1204 mGuts.setClipTopAmount(clipTopAmount);
1205 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001206 }
1207
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001208 private void recreateNotificationHeader() {
1209 final Notification.Builder builder = Notification.Builder.recoverBuilder(getContext(),
1210 getStatusBarNotification().getNotification());
1211 final RemoteViews header = builder.makeNotificationHeader();
1212 if (mNotificationHeader == null) {
1213 mNotificationHeader = (NotificationHeaderView) header.apply(getContext(), this);
1214 final View expandButton = mNotificationHeader.findViewById(
1215 com.android.internal.R.id.expand_button);
1216 expandButton.setVisibility(VISIBLE);
1217 mNotificationHeader.setOnClickListener(mExpandClickListener);
Selim Cinek9c7712d2015-12-08 19:19:48 -08001218 mNotificationHeaderWrapper = NotificationViewWrapper.wrap(getContext(),
1219 mNotificationHeader);
Selim Cinekb5a83612015-12-11 14:14:39 -08001220 addView(mNotificationHeader, indexOfChild(mChildrenContainer) + 1);
Mady Mellor4b80b102016-01-22 08:03:58 -08001221 mTranslateableViews.add(mNotificationHeader);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001222 } else {
1223 header.reapply(getContext(), mNotificationHeader);
Selim Cinek4ffd6362015-12-29 15:12:23 +01001224 mNotificationHeaderWrapper.notifyContentUpdated(mEntry.notification);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001225 }
Selim Cinek7b836392015-12-04 20:02:59 -08001226 updateHeaderExpandButton();
Selim Cinekea4bef72015-12-02 15:51:10 -08001227 updateChildrenHeaderAppearance();
Selim Cinek8fc93c92015-11-23 17:48:07 -08001228 updateHeaderChildCount();
Selim Cinek343e6e22014-04-11 21:23:30 +02001229 }
Selim Cinek7d447722014-06-10 15:51:59 +02001230
Selim Cinek7b836392015-12-04 20:02:59 -08001231 private void updateHeaderExpandButton() {
1232 if (mIsSummaryWithChildren) {
1233 mNotificationHeader.setIsGroupHeader(true /* isGroupHeader*/);
1234 }
1235 }
1236
Selim Cinekea4bef72015-12-02 15:51:10 -08001237 public void updateChildrenHeaderAppearance() {
1238 if (mIsSummaryWithChildren) {
1239 mHeaderUtil.updateChildrenHeaderAppearance();
1240 }
1241 }
1242
Selim Cinek31094df2014-08-14 19:28:15 +02001243 public boolean isMaxExpandHeightInitialized() {
1244 return mMaxExpandHeight != 0;
Selim Cinek7d447722014-06-10 15:51:59 +02001245 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001246
1247 private NotificationContentView getShowingLayout() {
1248 return mShowingPublic ? mPublicLayout : mPrivateLayout;
1249 }
Chris Wren78403d72014-07-28 10:23:24 +01001250
Jorim Jaggi59ec3042015-06-05 15:18:43 -07001251 @Override
1252 public void setShowingLegacyBackground(boolean showing) {
1253 super.setShowingLegacyBackground(showing);
1254 mPrivateLayout.setShowingLegacyBackground(showing);
1255 mPublicLayout.setShowingLegacyBackground(showing);
1256 }
1257
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001258 @Override
1259 protected void updateBackgroundTint() {
1260 super.updateBackgroundTint();
1261 updateNoBackgroundState();
1262 if (mIsSummaryWithChildren) {
1263 List<ExpandableNotificationRow> notificationChildren =
1264 mChildrenContainer.getNotificationChildren();
1265 for (int i = 0; i < notificationChildren.size(); i++) {
1266 ExpandableNotificationRow child = notificationChildren.get(i);
1267 child.updateNoBackgroundState();
1268 }
1269 }
1270 }
1271
1272 private void updateNoBackgroundState() {
1273 mShowNoBackground = isChildInGroup() && hasSameBgColor(mNotificationParent);
1274 updateBackground();
1275 }
1276
Chris Wren78403d72014-07-28 10:23:24 +01001277 public void setExpansionLogger(ExpansionLogger logger, String key) {
1278 mLogger = logger;
1279 mLoggingKey = key;
1280 }
1281
Selim Cinek6183d122016-01-14 18:48:41 -08001282 @Override
Selim Cinek61633a82016-01-25 15:54:10 -08001283 public boolean needsIncreasedPadding() {
1284 return mIsSummaryWithChildren && isGroupExpanded();
1285 }
1286
1287 @Override
Selim Cinek6183d122016-01-14 18:48:41 -08001288 protected boolean disallowSingleClick(MotionEvent event) {
1289 float x = event.getX();
1290 float y = event.getY();
1291 NotificationHeaderView header = getNotificationHeader();
1292 if (header != null) {
1293 return header.isInTouchRect(x, y);
1294 }
1295 return super.disallowSingleClick(event);
1296 }
1297
Chris Wren78403d72014-07-28 10:23:24 +01001298 private void logExpansionEvent(boolean userAction, boolean wasExpanded) {
1299 final boolean nowExpanded = isExpanded();
1300 if (wasExpanded != nowExpanded && mLogger != null) {
1301 mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ;
1302 }
1303 }
Selim Cinek570981d2015-12-01 11:37:01 -08001304
1305 public interface OnExpandClickListener {
Selim Cinek31aada42015-12-18 17:51:15 -08001306 void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
Selim Cinek570981d2015-12-01 11:37:01 -08001307 }
Chris Wren51c75102013-07-16 20:49:17 -04001308}