blob: da125d8f77a632ea3142d28591525cc1388f6f7a [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;
Selim Cineka5e211b2014-08-11 17:35:48 +0200108 private boolean mWasReset;
Mady Mellor4b80b102016-01-22 08:03:58 -0800109 private NotificationSettingsIconRow mSettingsIconRow;
Selim Cinek8d490d42015-04-10 00:05:50 -0700110 private NotificationGuts mGuts;
Selim Cinekda42d652015-12-04 15:51:16 -0800111 private NotificationData.Entry mEntry;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200112 private StatusBarNotification mStatusBarNotification;
Selim Cinek1a521f32014-11-03 17:39:29 +0100113 private boolean mIsHeadsUp;
Selim Cinek98713a42015-09-21 15:47:20 +0200114 private boolean mLastChronometerRunning = true;
Selim Cinekeef84282015-10-30 16:28:00 -0700115 private NotificationHeaderView mNotificationHeader;
Selim Cinek9c7712d2015-12-08 19:19:48 -0800116 private NotificationViewWrapper mNotificationHeaderWrapper;
Selim Cinekb5605e52015-02-20 18:21:41 +0100117 private ViewStub mChildrenContainerStub;
118 private NotificationGroupManager mGroupManager;
Selim Cinekb5605e52015-02-20 18:21:41 +0100119 private boolean mChildrenExpanded;
Selim Cinek263398f2015-10-21 17:40:23 -0700120 private boolean mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100121 private NotificationChildrenContainer mChildrenContainer;
Mady Mellor4b80b102016-01-22 08:03:58 -0800122 private ViewStub mSettingsIconRowStub;
Selim Cinekab29aeb2015-02-20 18:18:32 +0100123 private ViewStub mGutsStub;
Selim Cinekb5605e52015-02-20 18:21:41 +0100124 private boolean mIsSystemChildExpanded;
Selim Cinek684a4422015-04-15 16:18:39 -0700125 private boolean mIsPinned;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700126 private FalsingManager mFalsingManager;
Selim Cinek31aada42015-12-18 17:51:15 -0800127 private HeadsUpManager mHeadsUpManager;
Selim Cinekea4bef72015-12-02 15:51:10 -0800128 private NotificationHeaderUtil mHeaderUtil = new NotificationHeaderUtil(this);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200129
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700130 private boolean mJustClicked;
Selim Cinek5a175d92015-11-23 18:01:33 -0800131 private boolean mIconAnimationRunning;
Selim Cinek34d93b02015-10-22 12:30:38 -0700132 private boolean mShowNoBackground;
Selim Cinek388df6d2015-10-22 13:25:11 -0700133 private ExpandableNotificationRow mNotificationParent;
Selim Cinek570981d2015-12-01 11:37:01 -0800134 private OnExpandClickListener mOnExpandClickListener;
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800135 private OnClickListener mExpandClickListener = new OnClickListener() {
136 @Override
137 public void onClick(View v) {
Selim Cinek624c02db2015-12-14 21:00:02 -0800138 if (!mShowingPublic && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800139 mGroupManager.toggleGroupExpansion(mStatusBarNotification);
Selim Cinek31aada42015-12-18 17:51:15 -0800140 mOnExpandClickListener.onExpandClicked(mEntry,
Selim Cinek570981d2015-12-01 11:37:01 -0800141 mGroupManager.isGroupExpanded(mStatusBarNotification));
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800142 } else {
Selim Cinek31aada42015-12-18 17:51:15 -0800143 boolean nowExpanded;
144 if (isPinned()) {
145 nowExpanded = !mExpandedWhenPinned;
146 mExpandedWhenPinned = nowExpanded;
147 } else {
148 nowExpanded = !isExpanded();
149 setUserExpanded(nowExpanded);
150 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800151 notifyHeightChanged(true);
Selim Cinek31aada42015-12-18 17:51:15 -0800152 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800153 }
154 }
155 };
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700156
Selim Cinek8d490d42015-04-10 00:05:50 -0700157 public NotificationContentView getPrivateLayout() {
158 return mPrivateLayout;
159 }
160
161 public NotificationContentView getPublicLayout() {
162 return mPublicLayout;
163 }
164
Selim Cinekcab4a602014-09-03 14:47:57 +0200165 public void setIconAnimationRunning(boolean running) {
166 setIconAnimationRunning(running, mPublicLayout);
167 setIconAnimationRunning(running, mPrivateLayout);
Selim Cinek5a175d92015-11-23 18:01:33 -0800168 setIconAnimationRunningForChild(running, mNotificationHeader);
169 if (mIsSummaryWithChildren) {
170 List<ExpandableNotificationRow> notificationChildren =
171 mChildrenContainer.getNotificationChildren();
172 for (int i = 0; i < notificationChildren.size(); i++) {
173 ExpandableNotificationRow child = notificationChildren.get(i);
174 child.setIconAnimationRunning(running);
175 }
176 }
177 mIconAnimationRunning = running;
Selim Cinekcab4a602014-09-03 14:47:57 +0200178 }
179
180 private void setIconAnimationRunning(boolean running, NotificationContentView layout) {
181 if (layout != null) {
182 View contractedChild = layout.getContractedChild();
183 View expandedChild = layout.getExpandedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -0700184 View headsUpChild = layout.getHeadsUpChild();
Selim Cinekcab4a602014-09-03 14:47:57 +0200185 setIconAnimationRunningForChild(running, contractedChild);
186 setIconAnimationRunningForChild(running, expandedChild);
Selim Cinek8d490d42015-04-10 00:05:50 -0700187 setIconAnimationRunningForChild(running, headsUpChild);
Selim Cinekcab4a602014-09-03 14:47:57 +0200188 }
189 }
190
191 private void setIconAnimationRunningForChild(boolean running, View child) {
192 if (child != null) {
193 ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon);
194 setIconRunning(icon, running);
195 ImageView rightIcon = (ImageView) child.findViewById(
196 com.android.internal.R.id.right_icon);
197 setIconRunning(rightIcon, running);
198 }
199 }
200
201 private void setIconRunning(ImageView imageView, boolean running) {
202 if (imageView != null) {
203 Drawable drawable = imageView.getDrawable();
204 if (drawable instanceof AnimationDrawable) {
205 AnimationDrawable animationDrawable = (AnimationDrawable) drawable;
206 if (running) {
207 animationDrawable.start();
208 } else {
209 animationDrawable.stop();
210 }
211 } else if (drawable instanceof AnimatedVectorDrawable) {
212 AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable;
213 if (running) {
214 animationDrawable.start();
215 } else {
216 animationDrawable.stop();
217 }
218 }
219 }
220 }
221
Selim Cinekda42d652015-12-04 15:51:16 -0800222 public void onNotificationUpdated(NotificationData.Entry entry) {
223 mEntry = entry;
224 mStatusBarNotification = entry.notification;
Adrian Roosb88b1a12015-12-09 18:51:05 -0800225 mPrivateLayout.onNotificationUpdated(entry);
226 mPublicLayout.onNotificationUpdated(entry);
Selim Cinek757d8792016-01-28 16:21:08 -0800227 mShowingPublicInitialized = false;
228 updateClearability();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800229 if (mIsSummaryWithChildren) {
230 recreateNotificationHeader();
231 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800232 if (mIconAnimationRunning) {
233 setIconAnimationRunning(true);
234 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800235 if (mNotificationParent != null) {
236 mNotificationParent.updateChildrenHeaderAppearance();
237 }
Selim Cinek263398f2015-10-21 17:40:23 -0700238 onChildrenCountChanged();
Selim Cinek624c02db2015-12-14 21:00:02 -0800239 // The public layouts expand button is always visible
240 mPublicLayout.updateExpandButtons(true);
Selim Cinekda42d652015-12-04 15:51:16 -0800241 updateLimits();
242 }
243
244 private void updateLimits() {
245 boolean customView = getPrivateLayout().getContractedChild().getId()
246 != com.android.internal.R.id.status_bar_latest_event_content;
247 boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N;
248 int minHeight = customView && beforeN && !mIsSummaryWithChildren ?
249 mNotificationMinHeightLegacy : mNotificationMinHeight;
Selim Cinek77019c72015-12-09 10:18:02 -0800250 boolean headsUpCustom = getPrivateLayout().getHeadsUpChild() != null &&
251 getPrivateLayout().getHeadsUpChild().getId()
252 != com.android.internal.R.id.status_bar_latest_event_content;
253 int headsUpheight = headsUpCustom && beforeN ? mMaxHeadsUpHeightLegacy
254 : mMaxHeadsUpHeight;
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 Cinek34eda5e2016-02-18 17:10:43 -0800523 private NotificationHeaderView getVisibleNotificationHeader() {
524 if (mNotificationHeader != null) {
525 return mNotificationHeader;
526 }
527 return getShowingLayout().getVisibleNotificationHeader();
528 }
529
Selim Cinek570981d2015-12-01 11:37:01 -0800530 public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) {
531 mOnExpandClickListener = onExpandClickListener;
532 }
533
Selim Cinek31aada42015-12-18 17:51:15 -0800534 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
535 mHeadsUpManager = headsUpManager;
536 }
537
Selim Cinek01af3342016-02-09 19:25:31 -0800538 public void reInflateViews() {
539 initDimens();
540 if (mIsSummaryWithChildren) {
541 removeView(mNotificationHeader);
542 mNotificationHeader = null;
543 recreateNotificationHeader();
544 if (mChildrenContainer != null) {
545 mChildrenContainer.reInflateViews();
546 }
547 }
548 if (mGuts != null) {
549 View oldGuts = mGuts;
550 int index = indexOfChild(oldGuts);
551 removeView(oldGuts);
552 mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate(
553 R.layout.notification_guts, this, false);
554 mGuts.setVisibility(oldGuts.getVisibility());
555 addView(mGuts, index);
556 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800557 if (mSettingsIconRow != null) {
558 View oldSettings = mSettingsIconRow;
559 int settingsIndex = indexOfChild(oldSettings);
560 removeView(oldSettings);
561 mSettingsIconRow = (NotificationSettingsIconRow) LayoutInflater.from(mContext).inflate(
562 R.layout.notification_settings_icon_row, this, false);
563 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
564 mSettingsIconRow.setVisibility(oldSettings.getVisibility());
565 addView(mSettingsIconRow, settingsIndex);
566
567 }
Selim Cinekde33a4a2016-02-11 16:43:41 -0800568 mPrivateLayout.reInflateViews();
569 mPublicLayout.reInflateViews();
Selim Cinek01af3342016-02-09 19:25:31 -0800570 }
571
Chris Wren78403d72014-07-28 10:23:24 +0100572 public interface ExpansionLogger {
573 public void logNotificationExpansion(String key, boolean userAction, boolean expanded);
574 }
Selim Cinek1685e632014-04-08 02:27:49 +0200575
Chris Wren51c75102013-07-16 20:49:17 -0400576 public ExpandableNotificationRow(Context context, AttributeSet attrs) {
577 super(context, attrs);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700578 mFalsingManager = FalsingManager.getInstance(context);
Selim Cinek01af3342016-02-09 19:25:31 -0800579 initDimens();
580 }
581
582 private void initDimens() {
Selim Cinekf619ffc2016-02-17 14:53:05 -0800583 mNotificationMinHeightLegacy = getFontScaledHeight(R.dimen.notification_min_height_legacy);
584 mNotificationMinHeight = getFontScaledHeight(R.dimen.notification_min_height);
585 mNotificationMaxHeight = getFontScaledHeight(R.dimen.notification_max_height);
586 mMaxHeadsUpHeightLegacy = getFontScaledHeight(
Selim Cinek77019c72015-12-09 10:18:02 -0800587 R.dimen.notification_max_heads_up_height_legacy);
Selim Cinekf619ffc2016-02-17 14:53:05 -0800588 mMaxHeadsUpHeight = getFontScaledHeight(R.dimen.notification_max_heads_up_height);
589 }
590
591 /**
592 * @param dimenId the dimen to look up
593 * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
594 */
595 private int getFontScaledHeight(int dimenId) {
596 int dimensionPixelSize = getResources().getDimensionPixelSize(dimenId);
597 float factor = Math.max(1.0f, getResources().getDisplayMetrics().scaledDensity /
598 getResources().getDisplayMetrics().density);
599 return (int) (dimensionPixelSize * factor);
Chris Wren51c75102013-07-16 20:49:17 -0400600 }
601
Christoph Studera7fe6312014-06-27 19:32:44 +0200602 /**
603 * Resets this view so it can be re-used for an updated notification.
604 */
Christoph Studer22f2ee52014-07-29 22:57:21 +0200605 @Override
Christoph Studera7fe6312014-06-27 19:32:44 +0200606 public void reset() {
Christoph Studer22f2ee52014-07-29 22:57:21 +0200607 super.reset();
Chris Wren78403d72014-07-28 10:23:24 +0100608 final boolean wasExpanded = isExpanded();
Christoph Studera7fe6312014-06-27 19:32:44 +0200609 mExpandable = false;
610 mHasUserChangedExpansion = false;
611 mUserLocked = false;
612 mShowingPublic = false;
Jorim Jaggiae441282014-08-01 02:45:18 +0200613 mSensitive = false;
614 mShowingPublicInitialized = false;
Christoph Studera7fe6312014-06-27 19:32:44 +0200615 mIsSystemExpanded = false;
Selim Cinek83bc7832015-10-22 13:26:54 -0700616 mOnKeyguard = false;
Selim Cinek1a521f32014-11-03 17:39:29 +0100617 mPublicLayout.reset(mIsHeadsUp);
618 mPrivateLayout.reset(mIsHeadsUp);
Selim Cinek31094df2014-08-14 19:28:15 +0200619 resetHeight();
Mady Mellor4b80b102016-01-22 08:03:58 -0800620 resetTranslation();
Selim Cinek31094df2014-08-14 19:28:15 +0200621 logExpansionEvent(false, wasExpanded);
622 }
623
624 public void resetHeight() {
Selim Cinek1a521f32014-11-03 17:39:29 +0100625 if (mIsHeadsUp) {
626 resetActualHeight();
627 }
Christoph Studera7fe6312014-06-27 19:32:44 +0200628 mMaxExpandHeight = 0;
Selim Cinek8d490d42015-04-10 00:05:50 -0700629 mHeadsUpHeight = 0;
Selim Cineka5e211b2014-08-11 17:35:48 +0200630 mWasReset = true;
Selim Cinek31094df2014-08-14 19:28:15 +0200631 onHeightReset();
Selim Cinek6e28a672014-09-05 14:43:28 +0200632 requestLayout();
Christoph Studera7fe6312014-06-27 19:32:44 +0200633 }
634
Jorim Jaggi251957d2014-04-09 04:24:09 +0200635 @Override
636 protected void onFinishInflate() {
637 super.onFinishInflate();
Jorim Jaggibe565df2014-04-28 17:51:23 +0200638 mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800639 mPublicLayout.setContainingNotification(this);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200640 mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800641 mPrivateLayout.setExpandClickListener(mExpandClickListener);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800642 mPrivateLayout.setContainingNotification(this);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800643 mPublicLayout.setExpandClickListener(mExpandClickListener);
Mady Mellor4b80b102016-01-22 08:03:58 -0800644 mSettingsIconRowStub = (ViewStub) findViewById(R.id.settings_icon_row_stub);
645 mSettingsIconRowStub.setOnInflateListener(new ViewStub.OnInflateListener() {
646 @Override
647 public void onInflate(ViewStub stub, View inflated) {
648 mSettingsIconRow = (NotificationSettingsIconRow) inflated;
649 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
650 }
651 });
Selim Cinekab29aeb2015-02-20 18:18:32 +0100652 mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub);
653 mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() {
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200654 @Override
655 public void onInflate(ViewStub stub, View inflated) {
656 mGuts = (NotificationGuts) inflated;
657 mGuts.setClipTopAmount(getClipTopAmount());
658 mGuts.setActualHeight(getActualHeight());
Mady Mellor4b80b102016-01-22 08:03:58 -0800659 mTranslateableViews.add(mGuts);
Selim Cinekab29aeb2015-02-20 18:18:32 +0100660 mGutsStub = null;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200661 }
662 });
Selim Cinekb5605e52015-02-20 18:21:41 +0100663 mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub);
664 mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() {
665
666 @Override
667 public void onInflate(ViewStub stub, View inflated) {
668 mChildrenContainer = (NotificationChildrenContainer) inflated;
Selim Cinek388df6d2015-10-22 13:25:11 -0700669 mChildrenContainer.setNotificationParent(ExpandableNotificationRow.this);
Mady Mellor4b80b102016-01-22 08:03:58 -0800670 mTranslateableViews.add(mChildrenContainer);
Selim Cinekb5605e52015-02-20 18:21:41 +0100671 }
672 });
Selim Cinek863834b2014-05-20 04:20:25 +0200673 mVetoButton = findViewById(R.id.veto);
Mady Mellor4b80b102016-01-22 08:03:58 -0800674
675 // Add the views that we translate to reveal the gear
676 mTranslateableViews = new ArrayList<View>();
677 for (int i = 0; i < getChildCount(); i++) {
678 mTranslateableViews.add(getChildAt(i));
679 }
680 // Remove views that don't translate
681 mTranslateableViews.remove(mVetoButton);
682 mTranslateableViews.remove(mSettingsIconRowStub);
683 mTranslateableViews.remove(mChildrenContainerStub);
684 mTranslateableViews.remove(mGutsStub);
685 }
686
687 public void setTranslationForOutline(float translationX) {
688 setOutlineRect(false, translationX, getTop(), getRight() + translationX, getBottom());
689 }
690
691 public void resetTranslation() {
692 if (mTranslateableViews != null) {
693 for (int i = 0; i < mTranslateableViews.size(); i++) {
694 mTranslateableViews.get(i).setTranslationX(0);
695 }
696 setTranslationForOutline(0);
697 }
698 if (mSettingsIconRow != null) {
699 mSettingsIconRow.resetState();
700 }
701 }
702
703 public void animateTranslateNotification(final float leftTarget) {
704 if (mTranslateAnim != null) {
705 mTranslateAnim.cancel();
706 }
707 AnimatorSet set = new AnimatorSet();
708 if (mTranslateableViews != null) {
709 for (int i = 0; i < mTranslateableViews.size(); i++) {
710 final View animView = mTranslateableViews.get(i);
711 final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(
712 animView, "translationX", leftTarget);
713 if (i == 0) {
714 translateAnim.addUpdateListener(new AnimatorUpdateListener() {
715 @Override
716 public void onAnimationUpdate(ValueAnimator animation) {
717 setTranslationForOutline((float) animation.getAnimatedValue());
718 }
719 });
720 }
721 translateAnim.addListener(new AnimatorListenerAdapter() {
722 @Override
723 public void onAnimationEnd(Animator anim) {
724 if (mSettingsIconRow != null && leftTarget == 0) {
725 mSettingsIconRow.resetState();
726 }
727 mTranslateAnim = null;
728 }
729 });
730 set.play(translateAnim);
731 }
732 }
733 mTranslateAnim = set;
734 set.start();
735 }
736
737 public float getSpaceForGear() {
738 if (mSettingsIconRow != null) {
739 return mSettingsIconRow.getSpaceForGear();
740 }
741 return 0;
742 }
743
744 public NotificationSettingsIconRow getSettingsRow() {
745 if (mSettingsIconRow == null) {
746 mSettingsIconRowStub.inflate();
747 }
748 return mSettingsIconRow;
749 }
750
751 public ArrayList<View> getContentViews() {
752 return mTranslateableViews;
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200753 }
754
Selim Cinekab29aeb2015-02-20 18:18:32 +0100755 public void inflateGuts() {
756 if (mGuts == null) {
757 mGutsStub.inflate();
758 }
759 }
760
Selim Cinekda42d652015-12-04 15:51:16 -0800761 private void updateChildrenVisibility() {
Selim Cinekd84a5932015-12-15 11:45:36 -0800762 mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE
763 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -0800764 if (mChildrenContainer != null) {
765 mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
766 : INVISIBLE);
Selim Cinekb5605e52015-02-20 18:21:41 +0100767 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800768 if (mNotificationHeader != null) {
769 mNotificationHeader.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
770 : INVISIBLE);
771 }
Selim Cinekda42d652015-12-04 15:51:16 -0800772 // The limits might have changed if the view suddenly became a group or vice versa
773 updateLimits();
Selim Cinekb5605e52015-02-20 18:21:41 +0100774 }
775
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200776 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -0800777 public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
778 if (super.onRequestSendAccessibilityEventInternal(child, event)) {
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200779 // Add a record for the entire layout since its content is somehow small.
780 // The event comes from a leaf view that is interacted with.
781 AccessibilityEvent record = AccessibilityEvent.obtain();
782 onInitializeAccessibilityEvent(record);
783 dispatchPopulateAccessibilityEvent(record);
784 event.appendRecord(record);
785 return true;
786 }
787 return false;
Jorim Jaggic5dc0d02014-04-15 15:42:55 +0200788 }
Chris Wren51c75102013-07-16 20:49:17 -0400789
John Spurlocke15452b2014-08-21 09:44:39 -0400790 @Override
Jorim Jaggi4e857f42014-11-17 19:14:04 +0100791 public void setDark(boolean dark, boolean fade, long delay) {
792 super.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -0400793 final NotificationContentView showing = getShowingLayout();
794 if (showing != null) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +0100795 showing.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -0400796 }
Selim Cinek9c7712d2015-12-08 19:19:48 -0800797 if (mIsSummaryWithChildren) {
798 mChildrenContainer.setDark(dark, fade, delay);
799 mNotificationHeaderWrapper.setDark(dark, fade, delay);
800 }
John Spurlocke15452b2014-08-21 09:44:39 -0400801 }
802
Chris Wren51c75102013-07-16 20:49:17 -0400803 public boolean isExpandable() {
Selim Cinek388df6d2015-10-22 13:25:11 -0700804 if (mIsSummaryWithChildren && !mShowingPublic) {
805 return !mChildrenExpanded;
806 }
Chris Wren51c75102013-07-16 20:49:17 -0400807 return mExpandable;
808 }
809
810 public void setExpandable(boolean expandable) {
811 mExpandable = expandable;
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800812 mPrivateLayout.updateExpandButtons(isExpandable());
Chris Wren51c75102013-07-16 20:49:17 -0400813 }
814
Selim Cinek4ffd6362015-12-29 15:12:23 +0100815 @Override
816 public void setClipToActualHeight(boolean clipToActualHeight) {
Selim Cinek084c16b2016-01-22 17:48:22 -0800817 super.setClipToActualHeight(clipToActualHeight || isUserLocked());
818 getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked());
Selim Cinek4ffd6362015-12-29 15:12:23 +0100819 }
820
Selim Cinek1685e632014-04-08 02:27:49 +0200821 /**
822 * @return whether the user has changed the expansion state
823 */
824 public boolean hasUserChangedExpansion() {
825 return mHasUserChangedExpansion;
826 }
827
Chris Wren51c75102013-07-16 20:49:17 -0400828 public boolean isUserExpanded() {
829 return mUserExpanded;
830 }
831
Selim Cinek1685e632014-04-08 02:27:49 +0200832 /**
833 * Set this notification to be expanded by the user
834 *
835 * @param userExpanded whether the user wants this notification to be expanded
836 */
Chris Wren51c75102013-07-16 20:49:17 -0400837 public void setUserExpanded(boolean userExpanded) {
Selim Cinek388df6d2015-10-22 13:25:11 -0700838 setUserExpanded(userExpanded, false /* allowChildExpansion */);
839 }
840
841 /**
842 * Set this notification to be expanded by the user
843 *
844 * @param userExpanded whether the user wants this notification to be expanded
845 * @param allowChildExpansion whether a call to this method allows expanding children
846 */
847 public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700848 mFalsingManager.setNotificationExpanded();
Selim Cinek388df6d2015-10-22 13:25:11 -0700849 if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion) {
850 mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded);
851 return;
852 }
Christoph Studera7fe6312014-06-27 19:32:44 +0200853 if (userExpanded && !mExpandable) return;
Chris Wren78403d72014-07-28 10:23:24 +0100854 final boolean wasExpanded = isExpanded();
Selim Cinek1685e632014-04-08 02:27:49 +0200855 mHasUserChangedExpansion = true;
Chris Wren51c75102013-07-16 20:49:17 -0400856 mUserExpanded = userExpanded;
Chris Wren78403d72014-07-28 10:23:24 +0100857 logExpansionEvent(true, wasExpanded);
Chris Wren51c75102013-07-16 20:49:17 -0400858 }
859
Selim Cinekccd14fb2014-08-12 18:53:24 +0200860 public void resetUserExpansion() {
861 mHasUserChangedExpansion = false;
862 mUserExpanded = false;
863 }
864
Chris Wren51c75102013-07-16 20:49:17 -0400865 public boolean isUserLocked() {
866 return mUserLocked;
867 }
868
869 public void setUserLocked(boolean userLocked) {
870 mUserLocked = userLocked;
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800871 mPrivateLayout.setUserExpanding(userLocked);
Selim Cinek42357e02016-02-24 18:48:01 -0800872 if (mIsSummaryWithChildren) {
873 mChildrenContainer.setUserLocked(userLocked);
874 }
Chris Wren51c75102013-07-16 20:49:17 -0400875 }
876
Selim Cinek1685e632014-04-08 02:27:49 +0200877 /**
878 * @return has the system set this notification to be expanded
879 */
880 public boolean isSystemExpanded() {
881 return mIsSystemExpanded;
882 }
883
884 /**
885 * Set this notification to be expanded by the system.
886 *
887 * @param expand whether the system wants this notification to be expanded.
888 */
889 public void setSystemExpanded(boolean expand) {
Selim Cinek31094df2014-08-14 19:28:15 +0200890 if (expand != mIsSystemExpanded) {
891 final boolean wasExpanded = isExpanded();
892 mIsSystemExpanded = expand;
Selim Cinekb5605e52015-02-20 18:21:41 +0100893 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +0200894 logExpansionEvent(false, wasExpanded);
Selim Cinek83bc7832015-10-22 13:26:54 -0700895 if (mChildrenContainer != null) {
896 mChildrenContainer.updateGroupOverflow();
897 }
Selim Cinek31094df2014-08-14 19:28:15 +0200898 }
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200899 }
900
901 /**
Selim Cinek83bc7832015-10-22 13:26:54 -0700902 * @param onKeyguard whether to prevent notification expansion
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200903 */
Selim Cinek83bc7832015-10-22 13:26:54 -0700904 public void setOnKeyguard(boolean onKeyguard) {
905 if (onKeyguard != mOnKeyguard) {
Selim Cinek31094df2014-08-14 19:28:15 +0200906 final boolean wasExpanded = isExpanded();
Selim Cinek83bc7832015-10-22 13:26:54 -0700907 mOnKeyguard = onKeyguard;
Selim Cinek31094df2014-08-14 19:28:15 +0200908 logExpansionEvent(false, wasExpanded);
909 if (wasExpanded != isExpanded()) {
Selim Cinek2108fe02015-12-10 12:56:13 -0800910 if (mIsSummaryWithChildren) {
911 mChildrenContainer.updateGroupOverflow();
912 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800913 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +0200914 }
915 }
Selim Cinek1685e632014-04-08 02:27:49 +0200916 }
917
918 /**
Dan Sandler0d3e62f2014-07-14 17:13:50 -0400919 * @return Can the underlying notification be cleared?
920 */
921 public boolean isClearable() {
Selim Cineka37774f2014-11-11 19:16:18 +0100922 return mStatusBarNotification != null && mStatusBarNotification.isClearable();
Dan Sandler0d3e62f2014-07-14 17:13:50 -0400923 }
924
925 /**
Selim Cinek1685e632014-04-08 02:27:49 +0200926 * Apply an expansion state to the layout.
Selim Cinek1685e632014-04-08 02:27:49 +0200927 */
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200928 public void applyExpansionToLayout() {
929 boolean expand = isExpanded();
Chris Wren51c75102013-07-16 20:49:17 -0400930 if (expand && mExpandable) {
Selim Cinekeef84282015-10-30 16:28:00 -0700931 setActualHeight(mMaxExpandHeight);
Chris Wren51c75102013-07-16 20:49:17 -0400932 } else {
Selim Cinek860b6da2015-12-16 19:02:19 -0800933 setActualHeight(getMinHeight());
Chris Wren51c75102013-07-16 20:49:17 -0400934 }
Chris Wren51c75102013-07-16 20:49:17 -0400935 }
Dan Sandlera5e0f412014-01-23 15:11:54 -0500936
Jorim Jaggi9cbadd32014-05-01 20:18:31 +0200937 @Override
938 public int getIntrinsicHeight() {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200939 if (isUserLocked()) {
940 return getActualHeight();
941 }
Selim Cinekd84a5932015-12-15 11:45:36 -0800942 if (mGuts != null && mGuts.areGutsExposed()) {
943 return mGuts.getHeight();
944 } else if ((isChildInGroup() && !isGroupExpanded())) {
945 return mPrivateLayout.getMinHeight();
946 } else if (mSensitive && mHideSensitiveForIntrinsicHeight) {
947 return getMinHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -0700948 } else if (mIsSummaryWithChildren && !mOnKeyguard) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800949 return mChildrenContainer.getIntrinsicHeight();
Selim Cinek60122be2015-04-15 18:16:50 -0700950 } else if (mIsHeadsUp) {
Selim Cinek31aada42015-12-18 17:51:15 -0800951 if (isPinned()) {
952 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
953 } else if (isExpanded()) {
Selim Cinekd84a5932015-12-15 11:45:36 -0800954 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -0700955 } else {
Selim Cinekd84a5932015-12-15 11:45:36 -0800956 return Math.max(getMinHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -0700957 }
Selim Cinek31aada42015-12-18 17:51:15 -0800958 } else if (isExpanded()) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700959 return getMaxExpandHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -0800960 } else {
961 return getMinHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200962 }
Selim Cinekb5605e52015-02-20 18:21:41 +0100963 }
Selim Cinek1685e632014-04-08 02:27:49 +0200964
Selim Cinekeef84282015-10-30 16:28:00 -0700965 private boolean isGroupExpanded() {
966 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinekb5605e52015-02-20 18:21:41 +0100967 }
968
Selim Cinekeef84282015-10-30 16:28:00 -0700969 /**
970 * @return whether this view has a header on the top of the content
971 */
972 private boolean hasNotificationHeader() {
973 return mIsSummaryWithChildren;
Selim Cinek1685e632014-04-08 02:27:49 +0200974 }
975
Selim Cinek263398f2015-10-21 17:40:23 -0700976 private void onChildrenCountChanged() {
Selim Cinek8fc93c92015-11-23 17:48:07 -0800977 mIsSummaryWithChildren = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS
Selim Cinek263398f2015-10-21 17:40:23 -0700978 && mGroupManager.hasGroupChildren(mStatusBarNotification);
Selim Cinek8fc93c92015-11-23 17:48:07 -0800979 if (mIsSummaryWithChildren) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800980 if (mChildrenContainer == null) {
981 mChildrenContainerStub.inflate();
982 }
Selim Cinek8fc93c92015-11-23 17:48:07 -0800983 if (mNotificationHeader == null) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800984 recreateNotificationHeader();
985 }
Selim Cinek263398f2015-10-21 17:40:23 -0700986 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800987 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinekea4bef72015-12-02 15:51:10 -0800988 updateChildrenHeaderAppearance();
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800989 updateHeaderChildCount();
Selim Cinekda42d652015-12-04 15:51:16 -0800990 updateChildrenVisibility();
Selim Cinek263398f2015-10-21 17:40:23 -0700991 }
992
Selim Cinek1685e632014-04-08 02:27:49 +0200993 /**
994 * Check whether the view state is currently expanded. This is given by the system in {@link
995 * #setSystemExpanded(boolean)} and can be overridden by user expansion or
996 * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this
997 * view can differ from this state, if layout params are modified from outside.
998 *
999 * @return whether the view state is currently expanded.
1000 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001001 public boolean isExpanded() {
1002 return !mOnKeyguard
Selim Cinekb5605e52015-02-20 18:21:41 +01001003 && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded())
1004 || isUserExpanded());
1005 }
1006
1007 private boolean isSystemChildExpanded() {
1008 return mIsSystemChildExpanded;
1009 }
1010
1011 public void setSystemChildExpanded(boolean expanded) {
1012 mIsSystemChildExpanded = expanded;
Selim Cinek1685e632014-04-08 02:27:49 +02001013 }
1014
1015 @Override
1016 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
1017 super.onLayout(changed, left, top, right, bottom);
Selim Cineka5e211b2014-08-11 17:35:48 +02001018 boolean updateExpandHeight = mMaxExpandHeight == 0 && !mWasReset;
Selim Cinek8d490d42015-04-10 00:05:50 -07001019 updateMaxHeights();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001020 if (updateExpandHeight) {
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001021 applyExpansionToLayout();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001022 }
Selim Cineka5e211b2014-08-11 17:35:48 +02001023 mWasReset = false;
Selim Cinek1685e632014-04-08 02:27:49 +02001024 }
1025
Selim Cinek8d490d42015-04-10 00:05:50 -07001026 private void updateMaxHeights() {
Selim Cinekd2319fb2014-09-01 19:41:54 +02001027 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek8d490d42015-04-10 00:05:50 -07001028 View expandedChild = mPrivateLayout.getExpandedChild();
1029 if (expandedChild == null) {
1030 expandedChild = mPrivateLayout.getContractedChild();
1031 }
1032 mMaxExpandHeight = expandedChild.getHeight();
1033 View headsUpChild = mPrivateLayout.getHeadsUpChild();
Selim Cinek1f3f5442015-04-10 17:54:46 -07001034 if (headsUpChild == null) {
1035 headsUpChild = mPrivateLayout.getContractedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -07001036 }
Selim Cinek1f3f5442015-04-10 17:54:46 -07001037 mHeadsUpHeight = headsUpChild.getHeight();
Selim Cinekd2319fb2014-09-01 19:41:54 +02001038 if (intrinsicBefore != getIntrinsicHeight()) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001039 notifyHeightChanged(false /* needsAnimation */);
Selim Cinekd2319fb2014-09-01 19:41:54 +02001040 }
1041 }
1042
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001043 @Override
1044 public void notifyHeightChanged(boolean needsAnimation) {
1045 super.notifyHeightChanged(needsAnimation);
1046 getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked());
1047 }
1048
Selim Cinek3c76d502016-02-19 15:16:33 -08001049 public void setSensitive(boolean sensitive, boolean hideSensitive) {
Jorim Jaggiae441282014-08-01 02:45:18 +02001050 mSensitive = sensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -08001051 mSensitiveHiddenInGeneral = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02001052 }
1053
1054 public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
Selim Cinek60122be2015-04-15 18:16:50 -07001055 mHideSensitiveForIntrinsicHeight = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02001056 }
1057
1058 public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
1059 long duration) {
1060 boolean oldShowingPublic = mShowingPublic;
1061 mShowingPublic = mSensitive && hideSensitive;
1062 if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
1063 return;
1064 }
Dan Sandlera5e0f412014-01-23 15:11:54 -05001065
1066 // bail out if no public version
Selim Cinek1685e632014-04-08 02:27:49 +02001067 if (mPublicLayout.getChildCount() == 0) return;
Dan Sandlera5e0f412014-01-23 15:11:54 -05001068
Jorim Jaggiae441282014-08-01 02:45:18 +02001069 if (!animated) {
1070 mPublicLayout.animate().cancel();
1071 mPrivateLayout.animate().cancel();
1072 mPublicLayout.setAlpha(1f);
1073 mPrivateLayout.setAlpha(1f);
1074 mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
Selim Cinekd84a5932015-12-15 11:45:36 -08001075 updateChildrenVisibility();
Jorim Jaggiae441282014-08-01 02:45:18 +02001076 } else {
1077 animateShowingPublic(delay, duration);
1078 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001079
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001080 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinek757d8792016-01-28 16:21:08 -08001081 updateClearability();
Jorim Jaggiae441282014-08-01 02:45:18 +02001082 mShowingPublicInitialized = true;
1083 }
1084
1085 private void animateShowingPublic(long delay, long duration) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001086 View[] privateViews = mIsSummaryWithChildren ?
1087 new View[] {mChildrenContainer, mNotificationHeader}
1088 : new View[] {mPrivateLayout};
1089 View[] publicViews = new View[] {mPublicLayout};
1090 View[] hiddenChildren = mShowingPublic ? privateViews : publicViews;
1091 View[] shownChildren = mShowingPublic ? publicViews : privateViews;
1092 for (final View hiddenView : hiddenChildren) {
1093 hiddenView.setVisibility(View.VISIBLE);
1094 hiddenView.animate().cancel();
1095 hiddenView.animate()
1096 .alpha(0f)
1097 .setStartDelay(delay)
1098 .setDuration(duration)
1099 .withEndAction(new Runnable() {
1100 @Override
1101 public void run() {
1102 hiddenView.setVisibility(View.INVISIBLE);
1103 }
1104 });
1105 }
1106 for (View showView : shownChildren) {
1107 showView.setVisibility(View.VISIBLE);
1108 showView.setAlpha(0f);
1109 showView.animate().cancel();
1110 showView.animate()
1111 .alpha(1f)
1112 .setStartDelay(delay)
1113 .setDuration(duration);
1114 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001115 }
1116
Selim Cinek3776fe02016-02-04 13:32:43 -08001117 public boolean mustStayOnScreen() {
1118 return mIsHeadsUp;
1119 }
1120
Selim Cinek757d8792016-01-28 16:21:08 -08001121 private void updateClearability() {
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001122 // public versions cannot be dismissed
Selim Cinek3c76d502016-02-19 15:16:33 -08001123 mVetoButton.setVisibility(isClearable() && (!mShowingPublic
1124 || !mSensitiveHiddenInGeneral) ? View.VISIBLE : View.GONE);
Dan Sandlera5e0f412014-01-23 15:11:54 -05001125 }
Jorim Jaggi251957d2014-04-09 04:24:09 +02001126
Selim Cinekb5605e52015-02-20 18:21:41 +01001127 public void setChildrenExpanded(boolean expanded, boolean animate) {
1128 mChildrenExpanded = expanded;
Selim Cinek7b836392015-12-04 20:02:59 -08001129 if (mNotificationHeader != null) {
1130 mNotificationHeader.setExpanded(expanded);
1131 }
Selim Cinek83bc7832015-10-22 13:26:54 -07001132 if (mChildrenContainer != null) {
1133 mChildrenContainer.setChildrenExpanded(expanded);
1134 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001135 }
1136
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001137 public void updateHeaderChildCount() {
1138 if (mIsSummaryWithChildren) {
1139 mNotificationHeader.setChildCount(
1140 mChildrenContainer.getNotificationChildren().size());
Selim Cinekb5605e52015-02-20 18:21:41 +01001141 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001142 }
1143
1144 public static void applyTint(View v, int color) {
1145 int alpha;
1146 if (color != 0) {
1147 alpha = COLORED_DIVIDER_ALPHA;
1148 } else {
1149 color = 0xff000000;
1150 alpha = DEFAULT_DIVIDER_ALPHA;
1151 }
1152 if (v.getBackground() instanceof ColorDrawable) {
1153 ColorDrawable background = (ColorDrawable) v.getBackground();
1154 background.mutate();
1155 background.setColor(color);
1156 background.setAlpha(alpha);
1157 }
1158 }
1159
Selim Cinek1685e632014-04-08 02:27:49 +02001160 public int getMaxExpandHeight() {
Selim Cinekb5605e52015-02-20 18:21:41 +01001161 return mMaxExpandHeight;
Chris Wren51c75102013-07-16 20:49:17 -04001162 }
Jorim Jaggi584a7aa2014-04-10 23:26:13 +02001163
Jorim Jaggibe565df2014-04-28 17:51:23 +02001164 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001165 public boolean isContentExpandable() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001166 NotificationContentView showingLayout = getShowingLayout();
1167 return showingLayout.isContentExpandable();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001168 }
1169
1170 @Override
Selim Cinek560e64d2015-06-09 19:58:11 -07001171 protected View getContentView() {
1172 return getShowingLayout();
1173 }
1174
1175 @Override
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001176 public void setActualHeight(int height, boolean notifyListeners) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001177 super.setActualHeight(height, notifyListeners);
Selim Cinekeef84282015-10-30 16:28:00 -07001178 int contentHeight = Math.max(getMinHeight(), height);
Selim Cinekb5605e52015-02-20 18:21:41 +01001179 mPrivateLayout.setContentHeight(contentHeight);
1180 mPublicLayout.setContentHeight(contentHeight);
Selim Cinek42357e02016-02-24 18:48:01 -08001181 if (mIsSummaryWithChildren) {
1182 mChildrenContainer.setActualHeight(height);
1183 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001184 if (mGuts != null) {
1185 mGuts.setActualHeight(height);
1186 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001187 invalidate();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001188 }
1189
1190 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01001191 public int getMaxContentHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001192 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001193 return mChildrenContainer.getMaxContentHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001194 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001195 NotificationContentView showingLayout = getShowingLayout();
1196 return showingLayout.getMaxHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001197 }
1198
1199 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001200 public int getMinHeight() {
Selim Cinek31aada42015-12-18 17:51:15 -08001201 if (mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) {
1202 return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
1203 } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001204 return mChildrenContainer.getMinHeight();
Selim Cinek31aada42015-12-18 17:51:15 -08001205 } else if (mIsHeadsUp) {
1206 return mHeadsUpHeight;
Selim Cinekb55386d2015-12-16 17:26:49 -08001207 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001208 NotificationContentView showingLayout = getShowingLayout();
1209 return showingLayout.getMinHeight();
1210 }
1211
1212 @Override
1213 public int getMinExpandHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001214 if (mIsSummaryWithChildren && !mOnKeyguard) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001215 return mChildrenContainer.getMinExpandHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001216 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001217 return getMinHeight();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001218 }
1219
1220 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02001221 public void setClipTopAmount(int clipTopAmount) {
1222 super.setClipTopAmount(clipTopAmount);
1223 mPrivateLayout.setClipTopAmount(clipTopAmount);
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001224 mPublicLayout.setClipTopAmount(clipTopAmount);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001225 if (mGuts != null) {
1226 mGuts.setClipTopAmount(clipTopAmount);
1227 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001228 }
1229
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001230 private void recreateNotificationHeader() {
1231 final Notification.Builder builder = Notification.Builder.recoverBuilder(getContext(),
1232 getStatusBarNotification().getNotification());
1233 final RemoteViews header = builder.makeNotificationHeader();
1234 if (mNotificationHeader == null) {
1235 mNotificationHeader = (NotificationHeaderView) header.apply(getContext(), this);
1236 final View expandButton = mNotificationHeader.findViewById(
1237 com.android.internal.R.id.expand_button);
1238 expandButton.setVisibility(VISIBLE);
1239 mNotificationHeader.setOnClickListener(mExpandClickListener);
Selim Cinek9c7712d2015-12-08 19:19:48 -08001240 mNotificationHeaderWrapper = NotificationViewWrapper.wrap(getContext(),
1241 mNotificationHeader);
Selim Cinekb5a83612015-12-11 14:14:39 -08001242 addView(mNotificationHeader, indexOfChild(mChildrenContainer) + 1);
Mady Mellor4b80b102016-01-22 08:03:58 -08001243 mTranslateableViews.add(mNotificationHeader);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001244 } else {
1245 header.reapply(getContext(), mNotificationHeader);
Selim Cinek4ffd6362015-12-29 15:12:23 +01001246 mNotificationHeaderWrapper.notifyContentUpdated(mEntry.notification);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001247 }
Selim Cinek7b836392015-12-04 20:02:59 -08001248 updateHeaderExpandButton();
Selim Cinekea4bef72015-12-02 15:51:10 -08001249 updateChildrenHeaderAppearance();
Selim Cinek8fc93c92015-11-23 17:48:07 -08001250 updateHeaderChildCount();
Selim Cinek343e6e22014-04-11 21:23:30 +02001251 }
Selim Cinek7d447722014-06-10 15:51:59 +02001252
Selim Cinek7b836392015-12-04 20:02:59 -08001253 private void updateHeaderExpandButton() {
1254 if (mIsSummaryWithChildren) {
1255 mNotificationHeader.setIsGroupHeader(true /* isGroupHeader*/);
1256 }
1257 }
1258
Selim Cinekea4bef72015-12-02 15:51:10 -08001259 public void updateChildrenHeaderAppearance() {
1260 if (mIsSummaryWithChildren) {
1261 mHeaderUtil.updateChildrenHeaderAppearance();
1262 }
1263 }
1264
Selim Cinek31094df2014-08-14 19:28:15 +02001265 public boolean isMaxExpandHeightInitialized() {
1266 return mMaxExpandHeight != 0;
Selim Cinek7d447722014-06-10 15:51:59 +02001267 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001268
Selim Cinek42357e02016-02-24 18:48:01 -08001269 public NotificationContentView getShowingLayout() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001270 return mShowingPublic ? mPublicLayout : mPrivateLayout;
1271 }
Chris Wren78403d72014-07-28 10:23:24 +01001272
Jorim Jaggi59ec3042015-06-05 15:18:43 -07001273 @Override
1274 public void setShowingLegacyBackground(boolean showing) {
1275 super.setShowingLegacyBackground(showing);
1276 mPrivateLayout.setShowingLegacyBackground(showing);
1277 mPublicLayout.setShowingLegacyBackground(showing);
1278 }
1279
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001280 @Override
1281 protected void updateBackgroundTint() {
1282 super.updateBackgroundTint();
1283 updateNoBackgroundState();
1284 if (mIsSummaryWithChildren) {
1285 List<ExpandableNotificationRow> notificationChildren =
1286 mChildrenContainer.getNotificationChildren();
1287 for (int i = 0; i < notificationChildren.size(); i++) {
1288 ExpandableNotificationRow child = notificationChildren.get(i);
1289 child.updateNoBackgroundState();
1290 }
1291 }
1292 }
1293
1294 private void updateNoBackgroundState() {
1295 mShowNoBackground = isChildInGroup() && hasSameBgColor(mNotificationParent);
1296 updateBackground();
1297 }
1298
Chris Wren78403d72014-07-28 10:23:24 +01001299 public void setExpansionLogger(ExpansionLogger logger, String key) {
1300 mLogger = logger;
1301 mLoggingKey = key;
1302 }
1303
Selim Cinek6183d122016-01-14 18:48:41 -08001304 @Override
Selim Cinek42357e02016-02-24 18:48:01 -08001305 public float getIncreasedPaddingAmount() {
1306 if (mIsSummaryWithChildren) {
1307 if (isGroupExpanded()) {
1308 return 1.0f;
1309 } else if (isUserLocked()) {
1310 return mChildrenContainer.getChildExpandFraction();
1311 }
1312 }
1313 return 0.0f;
Selim Cinek61633a82016-01-25 15:54:10 -08001314 }
1315
1316 @Override
Selim Cinek6183d122016-01-14 18:48:41 -08001317 protected boolean disallowSingleClick(MotionEvent event) {
1318 float x = event.getX();
1319 float y = event.getY();
Selim Cinek34eda5e2016-02-18 17:10:43 -08001320 NotificationHeaderView header = getVisibleNotificationHeader();
Selim Cinek6183d122016-01-14 18:48:41 -08001321 if (header != null) {
1322 return header.isInTouchRect(x, y);
1323 }
1324 return super.disallowSingleClick(event);
1325 }
1326
Chris Wren78403d72014-07-28 10:23:24 +01001327 private void logExpansionEvent(boolean userAction, boolean wasExpanded) {
1328 final boolean nowExpanded = isExpanded();
1329 if (wasExpanded != nowExpanded && mLogger != null) {
1330 mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ;
1331 }
1332 }
Selim Cinek570981d2015-12-01 11:37:01 -08001333
1334 public interface OnExpandClickListener {
Selim Cinek31aada42015-12-18 17:51:15 -08001335 void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
Selim Cinek570981d2015-12-01 11:37:01 -08001336 }
Chris Wren51c75102013-07-16 20:49:17 -04001337}