blob: 27b94d10f91c08cb9014bb54bdccbee76fc722f8 [file] [log] [blame]
Chris Wren51c75102013-07-16 20:49:17 -04001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.systemui.statusbar;
18
Mady Mellor4b80b102016-01-22 08:03:58 -080019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
21import android.animation.AnimatorSet;
22import android.animation.ObjectAnimator;
23import android.animation.ValueAnimator;
24import android.animation.ValueAnimator.AnimatorUpdateListener;
Selim Cineka6c6bfb2015-10-29 16:27:08 -070025import android.app.Notification;
Chris Wren51c75102013-07-16 20:49:17 -040026import android.content.Context;
Selim Cinekcab4a602014-09-03 14:47:57 +020027import android.graphics.drawable.AnimatedVectorDrawable;
28import android.graphics.drawable.AnimationDrawable;
Selim Cinekb5605e52015-02-20 18:21:41 +010029import android.graphics.drawable.ColorDrawable;
Selim Cinekcab4a602014-09-03 14:47:57 +020030import android.graphics.drawable.Drawable;
Selim Cinekda42d652015-12-04 15:51:16 -080031import android.os.Build;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020032import android.service.notification.StatusBarNotification;
Chris Wren51c75102013-07-16 20:49:17 -040033import android.util.AttributeSet;
Selim Cinek01af3342016-02-09 19:25:31 -080034import android.view.LayoutInflater;
Selim Cinek6183d122016-01-14 18:48:41 -080035import android.view.MotionEvent;
Selim Cinekeaa29ca2015-11-23 13:51:13 -080036import android.view.NotificationHeaderView;
Dan Sandlera5e0f412014-01-23 15:11:54 -050037import android.view.View;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020038import android.view.ViewStub;
Jorim Jaggife40f7d2014-04-28 15:20:04 +020039import android.view.accessibility.AccessibilityEvent;
Selim Cinek98713a42015-09-21 15:47:20 +020040import android.widget.Chronometer;
Selim Cinekcab4a602014-09-03 14:47:57 +020041import android.widget.ImageView;
Selim Cinekeaa29ca2015-11-23 13:51:13 -080042import android.widget.RemoteViews;
Selim Cinekb5605e52015-02-20 18:21:41 +010043
Dan Sandlera5e0f412014-01-23 15:11:54 -050044import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070045import com.android.systemui.classifier.FalsingManager;
Selim Cinek0ffbda62016-01-01 20:29:12 +010046import com.android.systemui.statusbar.notification.NotificationViewWrapper;
Selim Cinekb5605e52015-02-20 18:21:41 +010047import com.android.systemui.statusbar.phone.NotificationGroupManager;
Selim Cinek31aada42015-12-18 17:51:15 -080048import com.android.systemui.statusbar.policy.HeadsUpManager;
Selim Cinekb5605e52015-02-20 18:21:41 +010049import com.android.systemui.statusbar.stack.NotificationChildrenContainer;
50import com.android.systemui.statusbar.stack.StackScrollState;
51import com.android.systemui.statusbar.stack.StackStateAnimator;
52import com.android.systemui.statusbar.stack.StackViewState;
53
Mady Mellor4b80b102016-01-22 08:03:58 -080054import java.util.ArrayList;
Selim Cinekb5605e52015-02-20 18:21:41 +010055import java.util.List;
Dan Sandlera5e0f412014-01-23 15:11:54 -050056
Jorim Jaggi4222d9a2014-04-23 16:13:15 +020057public class ExpandableNotificationRow extends ActivatableNotificationView {
Selim Cinekb5605e52015-02-20 18:21:41 +010058
59 private static final int DEFAULT_DIVIDER_ALPHA = 0x29;
60 private static final int COLORED_DIVIDER_ALPHA = 0x7B;
Selim Cinek01af3342016-02-09 19:25:31 -080061 private int mNotificationMinHeightLegacy;
62 private int mMaxHeadsUpHeightLegacy;
63 private int mMaxHeadsUpHeight;
64 private int mNotificationMinHeight;
65 private int mNotificationMaxHeight;
Chris Wren51c75102013-07-16 20:49:17 -040066
Selim Cinek1685e632014-04-08 02:27:49 +020067 /** Does this row contain layouts that can adapt to row expansion */
Chris Wren51c75102013-07-16 20:49:17 -040068 private boolean mExpandable;
Selim Cinek1685e632014-04-08 02:27:49 +020069 /** Has the user actively changed the expansion state of this row */
70 private boolean mHasUserChangedExpansion;
71 /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */
Chris Wren51c75102013-07-16 20:49:17 -040072 private boolean mUserExpanded;
Selim Cinek31aada42015-12-18 17:51:15 -080073
74 /**
75 * Has this notification been expanded while it was pinned
76 */
77 private boolean mExpandedWhenPinned;
Selim Cinek1685e632014-04-08 02:27:49 +020078 /** Is the user touching this row */
Chris Wren51c75102013-07-16 20:49:17 -040079 private boolean mUserLocked;
Selim Cinek1685e632014-04-08 02:27:49 +020080 /** Are we showing the "public" version */
Dan Sandlera5e0f412014-01-23 15:11:54 -050081 private boolean mShowingPublic;
Jorim Jaggiae441282014-08-01 02:45:18 +020082 private boolean mSensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -080083 private boolean mSensitiveHiddenInGeneral;
Jorim Jaggiae441282014-08-01 02:45:18 +020084 private boolean mShowingPublicInitialized;
Selim Cinek60122be2015-04-15 18:16:50 -070085 private boolean mHideSensitiveForIntrinsicHeight;
Chris Wren51c75102013-07-16 20:49:17 -040086
Selim Cinek1685e632014-04-08 02:27:49 +020087 /**
88 * Is this notification expanded by the system. The expansion state can be overridden by the
89 * user expansion.
90 */
91 private boolean mIsSystemExpanded;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +020092
93 /**
Selim Cinek83bc7832015-10-22 13:26:54 -070094 * Whether the notification is on the keyguard and the expansion is disabled.
Jorim Jaggidce3c4c2014-04-29 23:12:24 +020095 */
Selim Cinek83bc7832015-10-22 13:26:54 -070096 private boolean mOnKeyguard;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +020097
Mady Mellor4b80b102016-01-22 08:03:58 -080098 private AnimatorSet mTranslateAnim;
99 private ArrayList<View> mTranslateableViews;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200100 private NotificationContentView mPublicLayout;
101 private NotificationContentView mPrivateLayout;
Selim Cinek1685e632014-04-08 02:27:49 +0200102 private int mMaxExpandHeight;
Selim Cinek8d490d42015-04-10 00:05:50 -0700103 private int mHeadsUpHeight;
Selim Cinek863834b2014-05-20 04:20:25 +0200104 private View mVetoButton;
Dan Sandler0d3e62f2014-07-14 17:13:50 -0400105 private boolean mClearable;
Chris Wren78403d72014-07-28 10:23:24 +0100106 private ExpansionLogger mLogger;
107 private String mLoggingKey;
Mady Mellor4b80b102016-01-22 08:03:58 -0800108 private NotificationSettingsIconRow mSettingsIconRow;
Selim Cinek8d490d42015-04-10 00:05:50 -0700109 private NotificationGuts mGuts;
Selim Cinekda42d652015-12-04 15:51:16 -0800110 private NotificationData.Entry mEntry;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200111 private StatusBarNotification mStatusBarNotification;
Selim Cinek1a521f32014-11-03 17:39:29 +0100112 private boolean mIsHeadsUp;
Selim Cinek98713a42015-09-21 15:47:20 +0200113 private boolean mLastChronometerRunning = true;
Selim Cinekeef84282015-10-30 16:28:00 -0700114 private NotificationHeaderView mNotificationHeader;
Selim Cinek9c7712d2015-12-08 19:19:48 -0800115 private NotificationViewWrapper mNotificationHeaderWrapper;
Selim Cinekb5605e52015-02-20 18:21:41 +0100116 private ViewStub mChildrenContainerStub;
117 private NotificationGroupManager mGroupManager;
Selim Cinekb5605e52015-02-20 18:21:41 +0100118 private boolean mChildrenExpanded;
Selim Cinek263398f2015-10-21 17:40:23 -0700119 private boolean mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100120 private NotificationChildrenContainer mChildrenContainer;
Mady Mellor4b80b102016-01-22 08:03:58 -0800121 private ViewStub mSettingsIconRowStub;
Selim Cinekab29aeb2015-02-20 18:18:32 +0100122 private ViewStub mGutsStub;
Selim Cinekb5605e52015-02-20 18:21:41 +0100123 private boolean mIsSystemChildExpanded;
Selim Cinek684a4422015-04-15 16:18:39 -0700124 private boolean mIsPinned;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700125 private FalsingManager mFalsingManager;
Selim Cinek31aada42015-12-18 17:51:15 -0800126 private HeadsUpManager mHeadsUpManager;
Selim Cinekea4bef72015-12-02 15:51:10 -0800127 private NotificationHeaderUtil mHeaderUtil = new NotificationHeaderUtil(this);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200128
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700129 private boolean mJustClicked;
Selim Cinek5a175d92015-11-23 18:01:33 -0800130 private boolean mIconAnimationRunning;
Selim Cinek34d93b02015-10-22 12:30:38 -0700131 private boolean mShowNoBackground;
Selim Cinek388df6d2015-10-22 13:25:11 -0700132 private ExpandableNotificationRow mNotificationParent;
Selim Cinek570981d2015-12-01 11:37:01 -0800133 private OnExpandClickListener mOnExpandClickListener;
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800134 private OnClickListener mExpandClickListener = new OnClickListener() {
135 @Override
136 public void onClick(View v) {
Selim Cinek624c02db2015-12-14 21:00:02 -0800137 if (!mShowingPublic && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800138 mGroupManager.toggleGroupExpansion(mStatusBarNotification);
Selim Cinek31aada42015-12-18 17:51:15 -0800139 mOnExpandClickListener.onExpandClicked(mEntry,
Selim Cinek570981d2015-12-01 11:37:01 -0800140 mGroupManager.isGroupExpanded(mStatusBarNotification));
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800141 } else {
Selim Cinek31aada42015-12-18 17:51:15 -0800142 boolean nowExpanded;
143 if (isPinned()) {
144 nowExpanded = !mExpandedWhenPinned;
145 mExpandedWhenPinned = nowExpanded;
146 } else {
147 nowExpanded = !isExpanded();
148 setUserExpanded(nowExpanded);
149 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800150 notifyHeightChanged(true);
Selim Cinek31aada42015-12-18 17:51:15 -0800151 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800152 }
153 }
154 };
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700155
Selim Cinek8d490d42015-04-10 00:05:50 -0700156 public NotificationContentView getPrivateLayout() {
157 return mPrivateLayout;
158 }
159
160 public NotificationContentView getPublicLayout() {
161 return mPublicLayout;
162 }
163
Selim Cinekcab4a602014-09-03 14:47:57 +0200164 public void setIconAnimationRunning(boolean running) {
165 setIconAnimationRunning(running, mPublicLayout);
166 setIconAnimationRunning(running, mPrivateLayout);
Selim Cinek5a175d92015-11-23 18:01:33 -0800167 setIconAnimationRunningForChild(running, mNotificationHeader);
168 if (mIsSummaryWithChildren) {
169 List<ExpandableNotificationRow> notificationChildren =
170 mChildrenContainer.getNotificationChildren();
171 for (int i = 0; i < notificationChildren.size(); i++) {
172 ExpandableNotificationRow child = notificationChildren.get(i);
173 child.setIconAnimationRunning(running);
174 }
175 }
176 mIconAnimationRunning = running;
Selim Cinekcab4a602014-09-03 14:47:57 +0200177 }
178
179 private void setIconAnimationRunning(boolean running, NotificationContentView layout) {
180 if (layout != null) {
181 View contractedChild = layout.getContractedChild();
182 View expandedChild = layout.getExpandedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -0700183 View headsUpChild = layout.getHeadsUpChild();
Selim Cinekcab4a602014-09-03 14:47:57 +0200184 setIconAnimationRunningForChild(running, contractedChild);
185 setIconAnimationRunningForChild(running, expandedChild);
Selim Cinek8d490d42015-04-10 00:05:50 -0700186 setIconAnimationRunningForChild(running, headsUpChild);
Selim Cinekcab4a602014-09-03 14:47:57 +0200187 }
188 }
189
190 private void setIconAnimationRunningForChild(boolean running, View child) {
191 if (child != null) {
192 ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon);
193 setIconRunning(icon, running);
194 ImageView rightIcon = (ImageView) child.findViewById(
195 com.android.internal.R.id.right_icon);
196 setIconRunning(rightIcon, running);
197 }
198 }
199
200 private void setIconRunning(ImageView imageView, boolean running) {
201 if (imageView != null) {
202 Drawable drawable = imageView.getDrawable();
203 if (drawable instanceof AnimationDrawable) {
204 AnimationDrawable animationDrawable = (AnimationDrawable) drawable;
205 if (running) {
206 animationDrawable.start();
207 } else {
208 animationDrawable.stop();
209 }
210 } else if (drawable instanceof AnimatedVectorDrawable) {
211 AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable;
212 if (running) {
213 animationDrawable.start();
214 } else {
215 animationDrawable.stop();
216 }
217 }
218 }
219 }
220
Selim Cinekda42d652015-12-04 15:51:16 -0800221 public void onNotificationUpdated(NotificationData.Entry entry) {
222 mEntry = entry;
223 mStatusBarNotification = entry.notification;
Adrian Roosb88b1a12015-12-09 18:51:05 -0800224 mPrivateLayout.onNotificationUpdated(entry);
225 mPublicLayout.onNotificationUpdated(entry);
Selim Cinek757d8792016-01-28 16:21:08 -0800226 mShowingPublicInitialized = false;
227 updateClearability();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800228 if (mIsSummaryWithChildren) {
229 recreateNotificationHeader();
230 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800231 if (mIconAnimationRunning) {
232 setIconAnimationRunning(true);
233 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800234 if (mNotificationParent != null) {
235 mNotificationParent.updateChildrenHeaderAppearance();
236 }
Selim Cinek263398f2015-10-21 17:40:23 -0700237 onChildrenCountChanged();
Selim Cinek624c02db2015-12-14 21:00:02 -0800238 // The public layouts expand button is always visible
239 mPublicLayout.updateExpandButtons(true);
Selim Cinekda42d652015-12-04 15:51:16 -0800240 updateLimits();
241 }
242
243 private void updateLimits() {
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 Cinek860b6da2015-12-16 19:02:19 -0800254 mPrivateLayout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight);
255 mPublicLayout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200256 }
257
258 public StatusBarNotification getStatusBarNotification() {
259 return mStatusBarNotification;
260 }
261
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700262 public boolean isHeadsUp() {
263 return mIsHeadsUp;
264 }
265
Selim Cinek1a521f32014-11-03 17:39:29 +0100266 public void setHeadsUp(boolean isHeadsUp) {
Selim Cinekc80fdb12015-04-13 15:09:08 -0700267 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek1a521f32014-11-03 17:39:29 +0100268 mIsHeadsUp = isHeadsUp;
Selim Cinek8d490d42015-04-10 00:05:50 -0700269 mPrivateLayout.setHeadsUp(isHeadsUp);
Selim Cinekc80fdb12015-04-13 15:09:08 -0700270 if (intrinsicBefore != getIntrinsicHeight()) {
271 notifyHeightChanged(false /* needsAnimation */);
272 }
Selim Cinek1a521f32014-11-03 17:39:29 +0100273 }
274
Selim Cinekb5605e52015-02-20 18:21:41 +0100275 public void setGroupManager(NotificationGroupManager groupManager) {
276 mGroupManager = groupManager;
Selim Cinek83bc7832015-10-22 13:26:54 -0700277 mPrivateLayout.setGroupManager(groupManager);
Selim Cinekb5605e52015-02-20 18:21:41 +0100278 }
279
Adrian Roosb88b1a12015-12-09 18:51:05 -0800280 public void setRemoteInputController(RemoteInputController r) {
281 mPrivateLayout.setRemoteInputController(r);
282 }
283
Selim Cinekb5605e52015-02-20 18:21:41 +0100284 public void addChildNotification(ExpandableNotificationRow row) {
285 addChildNotification(row, -1);
286 }
287
288 /**
289 * Add a child notification to this view.
290 *
291 * @param row the row to add
292 * @param childIndex the index to add it at, if -1 it will be added at the end
293 */
294 public void addChildNotification(ExpandableNotificationRow row, int childIndex) {
295 if (mChildrenContainer == null) {
296 mChildrenContainerStub.inflate();
297 }
298 mChildrenContainer.addNotification(row, childIndex);
Selim Cinek263398f2015-10-21 17:40:23 -0700299 onChildrenCountChanged();
300 row.setIsChildInGroup(true, this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100301 }
302
303 public void removeChildNotification(ExpandableNotificationRow row) {
304 if (mChildrenContainer != null) {
305 mChildrenContainer.removeNotification(row);
306 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800307 mHeaderUtil.restoreNotificationHeader(row);
Selim Cinek263398f2015-10-21 17:40:23 -0700308 onChildrenCountChanged();
309 row.setIsChildInGroup(false, null);
310 }
311
312 public boolean isChildInGroup() {
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700313 return mNotificationParent != null;
Selim Cinek263398f2015-10-21 17:40:23 -0700314 }
315
Selim Cinek388df6d2015-10-22 13:25:11 -0700316 public ExpandableNotificationRow getNotificationParent() {
317 return mNotificationParent;
318 }
319
Selim Cinek263398f2015-10-21 17:40:23 -0700320 /**
321 * @param isChildInGroup Is this notification now in a group
322 * @param parent the new parent notification
323 */
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700324 public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {;
325 boolean childInGroup = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup;
326 mNotificationParent = childInGroup ? parent : null;
327 mPrivateLayout.setIsChildInGroup(childInGroup);
328 updateNoBackgroundState();
Selim Cinek34d93b02015-10-22 12:30:38 -0700329 }
330
331 @Override
Selim Cinek72109472016-01-15 16:33:22 -0800332 public boolean onTouchEvent(MotionEvent event) {
333 if (event.getActionMasked() != MotionEvent.ACTION_DOWN
334 || !isChildInGroup() || isGroupExpanded()) {
335 return super.onTouchEvent(event);
336 } else {
337 return false;
338 }
339 }
340
341 @Override
Mady Mellorf0625802016-02-11 18:03:48 -0800342 protected boolean handleSlideBack() {
343 if (mSettingsIconRow != null && mSettingsIconRow.isVisible()) {
344 animateTranslateNotification(0 /* targetLeft */);
345 return true;
346 }
347 return false;
348 }
349
350 @Override
Selim Cinek34d93b02015-10-22 12:30:38 -0700351 protected boolean shouldHideBackground() {
352 return super.shouldHideBackground() || mShowNoBackground;
Selim Cinek263398f2015-10-21 17:40:23 -0700353 }
354
355 @Override
356 public boolean isSummaryWithChildren() {
357 return mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100358 }
359
360 @Override
361 public boolean areChildrenExpanded() {
362 return mChildrenExpanded;
363 }
364
365 public List<ExpandableNotificationRow> getNotificationChildren() {
366 return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren();
367 }
368
Selim Cinekeef84282015-10-30 16:28:00 -0700369 public int getNumberOfNotificationChildren() {
370 if (mChildrenContainer == null) {
371 return 0;
372 }
373 return mChildrenContainer.getNotificationChildren().size();
374 }
375
Selim Cinekb5605e52015-02-20 18:21:41 +0100376 /**
377 * Apply the order given in the list to the children.
378 *
379 * @param childOrder the new list order
380 * @return whether the list order has changed
381 */
382 public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder) {
383 return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder);
384 }
385
386 public void getChildrenStates(StackScrollState resultState) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700387 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100388 StackViewState parentState = resultState.getViewStateForView(this);
389 mChildrenContainer.getState(resultState, parentState);
390 }
391 }
392
393 public void applyChildrenState(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700394 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100395 mChildrenContainer.applyState(state);
396 }
397 }
398
399 public void prepareExpansionChanged(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700400 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100401 mChildrenContainer.prepareExpansionChanged(state);
402 }
403 }
404
405 public void startChildAnimation(StackScrollState finalState,
Selim Cinek99695592016-01-12 17:51:35 -0800406 StackStateAnimator stateAnimator, long delay, long duration) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700407 if (mIsSummaryWithChildren) {
Selim Cinek99695592016-01-12 17:51:35 -0800408 mChildrenContainer.startAnimationToState(finalState, stateAnimator, delay,
Selim Cinekb5605e52015-02-20 18:21:41 +0100409 duration);
410 }
411 }
412
413 public ExpandableNotificationRow getViewAtPosition(float y) {
Selim Cinek43d30f02016-03-04 10:51:32 -0800414 if (!mIsSummaryWithChildren || !mChildrenExpanded) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100415 return this;
416 } else {
417 ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y);
418 return view == null ? this : view;
419 }
420 }
421
Selim Cinekab29aeb2015-02-20 18:18:32 +0100422 public NotificationGuts getGuts() {
423 return mGuts;
424 }
425
Selim Cinek684a4422015-04-15 16:18:39 -0700426 /**
427 * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this
428 * the notification will be rendered on top of the screen.
429 *
430 * @param pinned whether it is pinned
431 */
432 public void setPinned(boolean pinned) {
433 mIsPinned = pinned;
Selim Cinek31aada42015-12-18 17:51:15 -0800434 if (pinned) {
435 setIconAnimationRunning(true);
436 mExpandedWhenPinned = false;
437 } else if (mExpandedWhenPinned) {
438 setUserExpanded(true);
439 }
Selim Cinek98713a42015-09-21 15:47:20 +0200440 setChronometerRunning(mLastChronometerRunning);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700441 }
442
Selim Cinek684a4422015-04-15 16:18:39 -0700443 public boolean isPinned() {
444 return mIsPinned;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700445 }
446
Selim Cinek31aada42015-12-18 17:51:15 -0800447 /**
448 * @param atLeastMinHeight should the value returned be at least the minimum height.
449 * Used to avoid cyclic calls
450 * @return the height of the heads up notification when pinned
451 */
452 public int getPinnedHeadsUpHeight(boolean atLeastMinHeight) {
Selim Cinek77019c72015-12-09 10:18:02 -0800453 if (mIsSummaryWithChildren) {
454 return mChildrenContainer.getIntrinsicHeight();
455 }
Selim Cinek31aada42015-12-18 17:51:15 -0800456 if(mExpandedWhenPinned) {
457 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
458 } else if (atLeastMinHeight) {
459 return Math.max(getMinHeight(), mHeadsUpHeight);
460 } else {
461 return mHeadsUpHeight;
462 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700463 }
464
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700465 /**
466 * Mark whether this notification was just clicked, i.e. the user has just clicked this
467 * notification in this frame.
468 */
469 public void setJustClicked(boolean justClicked) {
470 mJustClicked = justClicked;
471 }
472
473 /**
474 * @return true if this notification has been clicked in this frame, false otherwise
475 */
476 public boolean wasJustClicked() {
477 return mJustClicked;
478 }
479
Selim Cinek98713a42015-09-21 15:47:20 +0200480 public void setChronometerRunning(boolean running) {
481 mLastChronometerRunning = running;
482 setChronometerRunning(running, mPrivateLayout);
483 setChronometerRunning(running, mPublicLayout);
484 if (mChildrenContainer != null) {
485 List<ExpandableNotificationRow> notificationChildren =
486 mChildrenContainer.getNotificationChildren();
487 for (int i = 0; i < notificationChildren.size(); i++) {
488 ExpandableNotificationRow child = notificationChildren.get(i);
489 child.setChronometerRunning(running);
490 }
491 }
492 }
493
494 private void setChronometerRunning(boolean running, NotificationContentView layout) {
495 if (layout != null) {
496 running = running || isPinned();
497 View contractedChild = layout.getContractedChild();
498 View expandedChild = layout.getExpandedChild();
499 View headsUpChild = layout.getHeadsUpChild();
500 setChronometerRunningForChild(running, contractedChild);
501 setChronometerRunningForChild(running, expandedChild);
502 setChronometerRunningForChild(running, headsUpChild);
503 }
504 }
505
506 private void setChronometerRunningForChild(boolean running, View child) {
507 if (child != null) {
508 View chronometer = child.findViewById(com.android.internal.R.id.chronometer);
509 if (chronometer instanceof Chronometer) {
510 ((Chronometer) chronometer).setStarted(running);
511 }
512 }
513 }
514
Selim Cinekea4bef72015-12-02 15:51:10 -0800515 public NotificationHeaderView getNotificationHeader() {
516 if (mNotificationHeader != null) {
517 return mNotificationHeader;
Selim Cinek8d6440d2015-10-22 13:00:05 -0700518 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800519 return mPrivateLayout.getNotificationHeader();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700520 }
521
Selim Cinek34eda5e2016-02-18 17:10:43 -0800522 private NotificationHeaderView getVisibleNotificationHeader() {
523 if (mNotificationHeader != null) {
524 return mNotificationHeader;
525 }
526 return getShowingLayout().getVisibleNotificationHeader();
527 }
528
Selim Cinek570981d2015-12-01 11:37:01 -0800529 public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) {
530 mOnExpandClickListener = onExpandClickListener;
531 }
532
Selim Cinek31aada42015-12-18 17:51:15 -0800533 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
534 mHeadsUpManager = headsUpManager;
535 }
536
Selim Cinek01af3342016-02-09 19:25:31 -0800537 public void reInflateViews() {
538 initDimens();
539 if (mIsSummaryWithChildren) {
540 removeView(mNotificationHeader);
541 mNotificationHeader = null;
542 recreateNotificationHeader();
543 if (mChildrenContainer != null) {
544 mChildrenContainer.reInflateViews();
545 }
546 }
547 if (mGuts != null) {
548 View oldGuts = mGuts;
549 int index = indexOfChild(oldGuts);
550 removeView(oldGuts);
551 mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate(
552 R.layout.notification_guts, this, false);
553 mGuts.setVisibility(oldGuts.getVisibility());
554 addView(mGuts, index);
555 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800556 if (mSettingsIconRow != null) {
557 View oldSettings = mSettingsIconRow;
558 int settingsIndex = indexOfChild(oldSettings);
559 removeView(oldSettings);
560 mSettingsIconRow = (NotificationSettingsIconRow) LayoutInflater.from(mContext).inflate(
561 R.layout.notification_settings_icon_row, this, false);
562 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
563 mSettingsIconRow.setVisibility(oldSettings.getVisibility());
564 addView(mSettingsIconRow, settingsIndex);
565
566 }
Selim Cinekde33a4a2016-02-11 16:43:41 -0800567 mPrivateLayout.reInflateViews();
568 mPublicLayout.reInflateViews();
Selim Cinek01af3342016-02-09 19:25:31 -0800569 }
570
Chris Wren78403d72014-07-28 10:23:24 +0100571 public interface ExpansionLogger {
572 public void logNotificationExpansion(String key, boolean userAction, boolean expanded);
573 }
Selim Cinek1685e632014-04-08 02:27:49 +0200574
Chris Wren51c75102013-07-16 20:49:17 -0400575 public ExpandableNotificationRow(Context context, AttributeSet attrs) {
576 super(context, attrs);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700577 mFalsingManager = FalsingManager.getInstance(context);
Selim Cinek01af3342016-02-09 19:25:31 -0800578 initDimens();
579 }
580
581 private void initDimens() {
Selim Cinekf619ffc2016-02-17 14:53:05 -0800582 mNotificationMinHeightLegacy = getFontScaledHeight(R.dimen.notification_min_height_legacy);
583 mNotificationMinHeight = getFontScaledHeight(R.dimen.notification_min_height);
584 mNotificationMaxHeight = getFontScaledHeight(R.dimen.notification_max_height);
585 mMaxHeadsUpHeightLegacy = getFontScaledHeight(
Selim Cinek77019c72015-12-09 10:18:02 -0800586 R.dimen.notification_max_heads_up_height_legacy);
Selim Cinekf619ffc2016-02-17 14:53:05 -0800587 mMaxHeadsUpHeight = getFontScaledHeight(R.dimen.notification_max_heads_up_height);
588 }
589
590 /**
591 * @param dimenId the dimen to look up
592 * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
593 */
594 private int getFontScaledHeight(int dimenId) {
595 int dimensionPixelSize = getResources().getDimensionPixelSize(dimenId);
596 float factor = Math.max(1.0f, getResources().getDisplayMetrics().scaledDensity /
597 getResources().getDisplayMetrics().density);
598 return (int) (dimensionPixelSize * factor);
Chris Wren51c75102013-07-16 20:49:17 -0400599 }
600
Christoph Studera7fe6312014-06-27 19:32:44 +0200601 /**
602 * Resets this view so it can be re-used for an updated notification.
603 */
Christoph Studer22f2ee52014-07-29 22:57:21 +0200604 @Override
Christoph Studera7fe6312014-06-27 19:32:44 +0200605 public void reset() {
Christoph Studer22f2ee52014-07-29 22:57:21 +0200606 super.reset();
Chris Wren78403d72014-07-28 10:23:24 +0100607 final boolean wasExpanded = isExpanded();
Christoph Studera7fe6312014-06-27 19:32:44 +0200608 mExpandable = false;
609 mHasUserChangedExpansion = false;
610 mUserLocked = false;
611 mShowingPublic = false;
Jorim Jaggiae441282014-08-01 02:45:18 +0200612 mSensitive = false;
613 mShowingPublicInitialized = false;
Christoph Studera7fe6312014-06-27 19:32:44 +0200614 mIsSystemExpanded = false;
Selim Cinek83bc7832015-10-22 13:26:54 -0700615 mOnKeyguard = false;
Selim Cinek51d94912016-03-02 15:34:28 -0800616 mPublicLayout.reset();
617 mPrivateLayout.reset();
Selim Cinek31094df2014-08-14 19:28:15 +0200618 resetHeight();
Mady Mellor4b80b102016-01-22 08:03:58 -0800619 resetTranslation();
Selim Cinek31094df2014-08-14 19:28:15 +0200620 logExpansionEvent(false, wasExpanded);
621 }
622
623 public void resetHeight() {
Christoph Studera7fe6312014-06-27 19:32:44 +0200624 mMaxExpandHeight = 0;
Selim Cinek8d490d42015-04-10 00:05:50 -0700625 mHeadsUpHeight = 0;
Selim Cinek31094df2014-08-14 19:28:15 +0200626 onHeightReset();
Selim Cinek6e28a672014-09-05 14:43:28 +0200627 requestLayout();
Christoph Studera7fe6312014-06-27 19:32:44 +0200628 }
629
Jorim Jaggi251957d2014-04-09 04:24:09 +0200630 @Override
631 protected void onFinishInflate() {
632 super.onFinishInflate();
Jorim Jaggibe565df2014-04-28 17:51:23 +0200633 mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800634 mPublicLayout.setContainingNotification(this);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200635 mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800636 mPrivateLayout.setExpandClickListener(mExpandClickListener);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800637 mPrivateLayout.setContainingNotification(this);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800638 mPublicLayout.setExpandClickListener(mExpandClickListener);
Mady Mellor4b80b102016-01-22 08:03:58 -0800639 mSettingsIconRowStub = (ViewStub) findViewById(R.id.settings_icon_row_stub);
640 mSettingsIconRowStub.setOnInflateListener(new ViewStub.OnInflateListener() {
641 @Override
642 public void onInflate(ViewStub stub, View inflated) {
643 mSettingsIconRow = (NotificationSettingsIconRow) inflated;
644 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
645 }
646 });
Selim Cinekab29aeb2015-02-20 18:18:32 +0100647 mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub);
648 mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() {
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200649 @Override
650 public void onInflate(ViewStub stub, View inflated) {
651 mGuts = (NotificationGuts) inflated;
652 mGuts.setClipTopAmount(getClipTopAmount());
653 mGuts.setActualHeight(getActualHeight());
Selim Cinekab29aeb2015-02-20 18:18:32 +0100654 mGutsStub = null;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200655 }
656 });
Selim Cinekb5605e52015-02-20 18:21:41 +0100657 mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub);
658 mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() {
659
660 @Override
661 public void onInflate(ViewStub stub, View inflated) {
662 mChildrenContainer = (NotificationChildrenContainer) inflated;
Selim Cinek388df6d2015-10-22 13:25:11 -0700663 mChildrenContainer.setNotificationParent(ExpandableNotificationRow.this);
Mady Mellor4b80b102016-01-22 08:03:58 -0800664 mTranslateableViews.add(mChildrenContainer);
Selim Cinekb5605e52015-02-20 18:21:41 +0100665 }
666 });
Selim Cinek863834b2014-05-20 04:20:25 +0200667 mVetoButton = findViewById(R.id.veto);
Mady Mellor4b80b102016-01-22 08:03:58 -0800668
669 // Add the views that we translate to reveal the gear
670 mTranslateableViews = new ArrayList<View>();
671 for (int i = 0; i < getChildCount(); i++) {
672 mTranslateableViews.add(getChildAt(i));
673 }
674 // Remove views that don't translate
675 mTranslateableViews.remove(mVetoButton);
676 mTranslateableViews.remove(mSettingsIconRowStub);
677 mTranslateableViews.remove(mChildrenContainerStub);
678 mTranslateableViews.remove(mGutsStub);
679 }
680
Mady Mellor34958fa2016-02-23 09:52:17 -0800681 private void setTranslationForOutline(float translationX) {
Mady Mellor4b80b102016-01-22 08:03:58 -0800682 setOutlineRect(false, translationX, getTop(), getRight() + translationX, getBottom());
683 }
684
685 public void resetTranslation() {
686 if (mTranslateableViews != null) {
687 for (int i = 0; i < mTranslateableViews.size(); i++) {
688 mTranslateableViews.get(i).setTranslationX(0);
689 }
690 setTranslationForOutline(0);
691 }
692 if (mSettingsIconRow != null) {
693 mSettingsIconRow.resetState();
694 }
695 }
696
697 public void animateTranslateNotification(final float leftTarget) {
698 if (mTranslateAnim != null) {
699 mTranslateAnim.cancel();
700 }
Mady Mellor34958fa2016-02-23 09:52:17 -0800701 mTranslateAnim = (AnimatorSet) getTranslateViewAnimator(leftTarget,
702 null /* updateListener */);
703 if (mTranslateAnim != null) {
704 mTranslateAnim.start();
705 }
706 }
707
708 @Override
709 public void setTranslation(float translationX) {
710 if (areGutsExposed()) {
711 // Don't translate if guts are showing.
712 return;
713 }
714 // Translate the group of views
715 for (int i = 0; i < mTranslateableViews.size(); i++) {
716 if (mTranslateableViews.get(i) != null) {
717 mTranslateableViews.get(i).setTranslationX(translationX);
718 }
719 }
720 setTranslationForOutline(translationX);
721 if (mSettingsIconRow != null) {
722 mSettingsIconRow.updateSettingsIcons(translationX, getMeasuredWidth());
723 }
724 }
725
726 @Override
727 public float getTranslation() {
728 if (mTranslateableViews != null && mTranslateableViews.size() > 0) {
729 // All of the views in the list should have same translation, just use first one.
730 return mTranslateableViews.get(0).getTranslationX();
731 }
732 return 0;
733 }
734
735 public Animator getTranslateViewAnimator(final float leftTarget,
736 AnimatorUpdateListener listener) {
737 if (areGutsExposed()) {
738 // No translation if guts are exposed.
739 return null;
740 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800741 AnimatorSet set = new AnimatorSet();
742 if (mTranslateableViews != null) {
743 for (int i = 0; i < mTranslateableViews.size(); i++) {
744 final View animView = mTranslateableViews.get(i);
745 final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(
746 animView, "translationX", leftTarget);
747 if (i == 0) {
748 translateAnim.addUpdateListener(new AnimatorUpdateListener() {
749 @Override
750 public void onAnimationUpdate(ValueAnimator animation) {
751 setTranslationForOutline((float) animation.getAnimatedValue());
Mady Mellor34958fa2016-02-23 09:52:17 -0800752 if (mSettingsIconRow != null) {
753 mSettingsIconRow.updateSettingsIcons(
754 (float) animation.getAnimatedValue(), getMeasuredWidth());
755 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800756 }
757 });
Mady Mellor34958fa2016-02-23 09:52:17 -0800758 if (listener != null) {
759 translateAnim.addUpdateListener(listener);
760 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800761 }
762 translateAnim.addListener(new AnimatorListenerAdapter() {
763 @Override
764 public void onAnimationEnd(Animator anim) {
765 if (mSettingsIconRow != null && leftTarget == 0) {
766 mSettingsIconRow.resetState();
767 }
768 mTranslateAnim = null;
769 }
770 });
771 set.play(translateAnim);
772 }
773 }
Mady Mellor34958fa2016-02-23 09:52:17 -0800774 return set;
Mady Mellor4b80b102016-01-22 08:03:58 -0800775 }
776
777 public float getSpaceForGear() {
778 if (mSettingsIconRow != null) {
779 return mSettingsIconRow.getSpaceForGear();
780 }
781 return 0;
782 }
783
784 public NotificationSettingsIconRow getSettingsRow() {
785 if (mSettingsIconRow == null) {
786 mSettingsIconRowStub.inflate();
787 }
788 return mSettingsIconRow;
789 }
790
Selim Cinekab29aeb2015-02-20 18:18:32 +0100791 public void inflateGuts() {
792 if (mGuts == null) {
793 mGutsStub.inflate();
794 }
795 }
796
Selim Cinekda42d652015-12-04 15:51:16 -0800797 private void updateChildrenVisibility() {
Selim Cinekd84a5932015-12-15 11:45:36 -0800798 mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE
799 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -0800800 if (mChildrenContainer != null) {
801 mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
802 : INVISIBLE);
Selim Cinekb5605e52015-02-20 18:21:41 +0100803 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800804 if (mNotificationHeader != null) {
805 mNotificationHeader.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
806 : INVISIBLE);
807 }
Selim Cinekda42d652015-12-04 15:51:16 -0800808 // The limits might have changed if the view suddenly became a group or vice versa
809 updateLimits();
Selim Cinekb5605e52015-02-20 18:21:41 +0100810 }
811
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200812 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -0800813 public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
814 if (super.onRequestSendAccessibilityEventInternal(child, event)) {
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200815 // Add a record for the entire layout since its content is somehow small.
816 // The event comes from a leaf view that is interacted with.
817 AccessibilityEvent record = AccessibilityEvent.obtain();
818 onInitializeAccessibilityEvent(record);
819 dispatchPopulateAccessibilityEvent(record);
820 event.appendRecord(record);
821 return true;
822 }
823 return false;
Jorim Jaggic5dc0d02014-04-15 15:42:55 +0200824 }
Chris Wren51c75102013-07-16 20:49:17 -0400825
John Spurlocke15452b2014-08-21 09:44:39 -0400826 @Override
Jorim Jaggi4e857f42014-11-17 19:14:04 +0100827 public void setDark(boolean dark, boolean fade, long delay) {
828 super.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -0400829 final NotificationContentView showing = getShowingLayout();
830 if (showing != null) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +0100831 showing.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -0400832 }
Selim Cinek9c7712d2015-12-08 19:19:48 -0800833 if (mIsSummaryWithChildren) {
834 mChildrenContainer.setDark(dark, fade, delay);
835 mNotificationHeaderWrapper.setDark(dark, fade, delay);
836 }
John Spurlocke15452b2014-08-21 09:44:39 -0400837 }
838
Chris Wren51c75102013-07-16 20:49:17 -0400839 public boolean isExpandable() {
Selim Cinek388df6d2015-10-22 13:25:11 -0700840 if (mIsSummaryWithChildren && !mShowingPublic) {
841 return !mChildrenExpanded;
842 }
Chris Wren51c75102013-07-16 20:49:17 -0400843 return mExpandable;
844 }
845
846 public void setExpandable(boolean expandable) {
847 mExpandable = expandable;
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800848 mPrivateLayout.updateExpandButtons(isExpandable());
Chris Wren51c75102013-07-16 20:49:17 -0400849 }
850
Selim Cinek4ffd6362015-12-29 15:12:23 +0100851 @Override
852 public void setClipToActualHeight(boolean clipToActualHeight) {
Selim Cinek084c16b2016-01-22 17:48:22 -0800853 super.setClipToActualHeight(clipToActualHeight || isUserLocked());
854 getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked());
Selim Cinek4ffd6362015-12-29 15:12:23 +0100855 }
856
Selim Cinek1685e632014-04-08 02:27:49 +0200857 /**
858 * @return whether the user has changed the expansion state
859 */
860 public boolean hasUserChangedExpansion() {
861 return mHasUserChangedExpansion;
862 }
863
Chris Wren51c75102013-07-16 20:49:17 -0400864 public boolean isUserExpanded() {
865 return mUserExpanded;
866 }
867
Selim Cinek1685e632014-04-08 02:27:49 +0200868 /**
869 * Set this notification to be expanded by the user
870 *
871 * @param userExpanded whether the user wants this notification to be expanded
872 */
Chris Wren51c75102013-07-16 20:49:17 -0400873 public void setUserExpanded(boolean userExpanded) {
Selim Cinek388df6d2015-10-22 13:25:11 -0700874 setUserExpanded(userExpanded, false /* allowChildExpansion */);
875 }
876
877 /**
878 * Set this notification to be expanded by the user
879 *
880 * @param userExpanded whether the user wants this notification to be expanded
881 * @param allowChildExpansion whether a call to this method allows expanding children
882 */
883 public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700884 mFalsingManager.setNotificationExpanded();
Selim Cinek388df6d2015-10-22 13:25:11 -0700885 if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion) {
886 mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded);
887 return;
888 }
Christoph Studera7fe6312014-06-27 19:32:44 +0200889 if (userExpanded && !mExpandable) return;
Chris Wren78403d72014-07-28 10:23:24 +0100890 final boolean wasExpanded = isExpanded();
Selim Cinek1685e632014-04-08 02:27:49 +0200891 mHasUserChangedExpansion = true;
Chris Wren51c75102013-07-16 20:49:17 -0400892 mUserExpanded = userExpanded;
Chris Wren78403d72014-07-28 10:23:24 +0100893 logExpansionEvent(true, wasExpanded);
Chris Wren51c75102013-07-16 20:49:17 -0400894 }
895
Selim Cinekccd14fb2014-08-12 18:53:24 +0200896 public void resetUserExpansion() {
897 mHasUserChangedExpansion = false;
898 mUserExpanded = false;
899 }
900
Chris Wren51c75102013-07-16 20:49:17 -0400901 public boolean isUserLocked() {
902 return mUserLocked;
903 }
904
905 public void setUserLocked(boolean userLocked) {
906 mUserLocked = userLocked;
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800907 mPrivateLayout.setUserExpanding(userLocked);
Selim Cinek42357e02016-02-24 18:48:01 -0800908 if (mIsSummaryWithChildren) {
909 mChildrenContainer.setUserLocked(userLocked);
910 }
Chris Wren51c75102013-07-16 20:49:17 -0400911 }
912
Selim Cinek1685e632014-04-08 02:27:49 +0200913 /**
914 * @return has the system set this notification to be expanded
915 */
916 public boolean isSystemExpanded() {
917 return mIsSystemExpanded;
918 }
919
920 /**
921 * Set this notification to be expanded by the system.
922 *
923 * @param expand whether the system wants this notification to be expanded.
924 */
925 public void setSystemExpanded(boolean expand) {
Selim Cinek31094df2014-08-14 19:28:15 +0200926 if (expand != mIsSystemExpanded) {
927 final boolean wasExpanded = isExpanded();
928 mIsSystemExpanded = expand;
Selim Cinekb5605e52015-02-20 18:21:41 +0100929 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +0200930 logExpansionEvent(false, wasExpanded);
Selim Cinek83bc7832015-10-22 13:26:54 -0700931 if (mChildrenContainer != null) {
932 mChildrenContainer.updateGroupOverflow();
933 }
Selim Cinek31094df2014-08-14 19:28:15 +0200934 }
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200935 }
936
937 /**
Selim Cinek83bc7832015-10-22 13:26:54 -0700938 * @param onKeyguard whether to prevent notification expansion
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200939 */
Selim Cinek83bc7832015-10-22 13:26:54 -0700940 public void setOnKeyguard(boolean onKeyguard) {
941 if (onKeyguard != mOnKeyguard) {
Selim Cinek31094df2014-08-14 19:28:15 +0200942 final boolean wasExpanded = isExpanded();
Selim Cinek83bc7832015-10-22 13:26:54 -0700943 mOnKeyguard = onKeyguard;
Selim Cinek31094df2014-08-14 19:28:15 +0200944 logExpansionEvent(false, wasExpanded);
945 if (wasExpanded != isExpanded()) {
Selim Cinek2108fe02015-12-10 12:56:13 -0800946 if (mIsSummaryWithChildren) {
947 mChildrenContainer.updateGroupOverflow();
948 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800949 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +0200950 }
951 }
Selim Cinek1685e632014-04-08 02:27:49 +0200952 }
953
954 /**
Dan Sandler0d3e62f2014-07-14 17:13:50 -0400955 * @return Can the underlying notification be cleared?
956 */
957 public boolean isClearable() {
Selim Cineka37774f2014-11-11 19:16:18 +0100958 return mStatusBarNotification != null && mStatusBarNotification.isClearable();
Dan Sandler0d3e62f2014-07-14 17:13:50 -0400959 }
960
Jorim Jaggi9cbadd32014-05-01 20:18:31 +0200961 @Override
962 public int getIntrinsicHeight() {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200963 if (isUserLocked()) {
964 return getActualHeight();
965 }
Selim Cinekd84a5932015-12-15 11:45:36 -0800966 if (mGuts != null && mGuts.areGutsExposed()) {
967 return mGuts.getHeight();
968 } else if ((isChildInGroup() && !isGroupExpanded())) {
969 return mPrivateLayout.getMinHeight();
970 } else if (mSensitive && mHideSensitiveForIntrinsicHeight) {
971 return getMinHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -0700972 } else if (mIsSummaryWithChildren && !mOnKeyguard) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800973 return mChildrenContainer.getIntrinsicHeight();
Selim Cinek60122be2015-04-15 18:16:50 -0700974 } else if (mIsHeadsUp) {
Selim Cinek31aada42015-12-18 17:51:15 -0800975 if (isPinned()) {
976 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
977 } else if (isExpanded()) {
Selim Cinekd84a5932015-12-15 11:45:36 -0800978 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -0700979 } else {
Selim Cinekd84a5932015-12-15 11:45:36 -0800980 return Math.max(getMinHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -0700981 }
Selim Cinek31aada42015-12-18 17:51:15 -0800982 } else if (isExpanded()) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700983 return getMaxExpandHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -0800984 } else {
985 return getMinHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200986 }
Selim Cinekb5605e52015-02-20 18:21:41 +0100987 }
Selim Cinek1685e632014-04-08 02:27:49 +0200988
Selim Cinekeef84282015-10-30 16:28:00 -0700989 private boolean isGroupExpanded() {
990 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinekb5605e52015-02-20 18:21:41 +0100991 }
992
Selim Cinekeef84282015-10-30 16:28:00 -0700993 /**
994 * @return whether this view has a header on the top of the content
995 */
996 private boolean hasNotificationHeader() {
997 return mIsSummaryWithChildren;
Selim Cinek1685e632014-04-08 02:27:49 +0200998 }
999
Selim Cinek263398f2015-10-21 17:40:23 -07001000 private void onChildrenCountChanged() {
Selim Cinek8fc93c92015-11-23 17:48:07 -08001001 mIsSummaryWithChildren = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS
Selim Cinek263398f2015-10-21 17:40:23 -07001002 && mGroupManager.hasGroupChildren(mStatusBarNotification);
Selim Cinek8fc93c92015-11-23 17:48:07 -08001003 if (mIsSummaryWithChildren) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001004 if (mChildrenContainer == null) {
1005 mChildrenContainerStub.inflate();
1006 }
Selim Cinek8fc93c92015-11-23 17:48:07 -08001007 if (mNotificationHeader == null) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001008 recreateNotificationHeader();
1009 }
Selim Cinek263398f2015-10-21 17:40:23 -07001010 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001011 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinekea4bef72015-12-02 15:51:10 -08001012 updateChildrenHeaderAppearance();
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001013 updateHeaderChildCount();
Selim Cinekda42d652015-12-04 15:51:16 -08001014 updateChildrenVisibility();
Selim Cinek263398f2015-10-21 17:40:23 -07001015 }
1016
Selim Cinek1685e632014-04-08 02:27:49 +02001017 /**
1018 * Check whether the view state is currently expanded. This is given by the system in {@link
1019 * #setSystemExpanded(boolean)} and can be overridden by user expansion or
1020 * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this
1021 * view can differ from this state, if layout params are modified from outside.
1022 *
1023 * @return whether the view state is currently expanded.
1024 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001025 public boolean isExpanded() {
1026 return !mOnKeyguard
Selim Cinekb5605e52015-02-20 18:21:41 +01001027 && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded())
1028 || isUserExpanded());
1029 }
1030
1031 private boolean isSystemChildExpanded() {
1032 return mIsSystemChildExpanded;
1033 }
1034
1035 public void setSystemChildExpanded(boolean expanded) {
1036 mIsSystemChildExpanded = expanded;
Selim Cinek1685e632014-04-08 02:27:49 +02001037 }
1038
1039 @Override
1040 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
1041 super.onLayout(changed, left, top, right, bottom);
Selim Cinek8d490d42015-04-10 00:05:50 -07001042 updateMaxHeights();
Selim Cinek1685e632014-04-08 02:27:49 +02001043 }
1044
Selim Cinek8d490d42015-04-10 00:05:50 -07001045 private void updateMaxHeights() {
Selim Cinekd2319fb2014-09-01 19:41:54 +02001046 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek8d490d42015-04-10 00:05:50 -07001047 View expandedChild = mPrivateLayout.getExpandedChild();
1048 if (expandedChild == null) {
1049 expandedChild = mPrivateLayout.getContractedChild();
1050 }
1051 mMaxExpandHeight = expandedChild.getHeight();
1052 View headsUpChild = mPrivateLayout.getHeadsUpChild();
Selim Cinek1f3f5442015-04-10 17:54:46 -07001053 if (headsUpChild == null) {
1054 headsUpChild = mPrivateLayout.getContractedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -07001055 }
Selim Cinek1f3f5442015-04-10 17:54:46 -07001056 mHeadsUpHeight = headsUpChild.getHeight();
Selim Cinekd2319fb2014-09-01 19:41:54 +02001057 if (intrinsicBefore != getIntrinsicHeight()) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001058 notifyHeightChanged(false /* needsAnimation */);
Selim Cinekd2319fb2014-09-01 19:41:54 +02001059 }
1060 }
1061
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001062 @Override
1063 public void notifyHeightChanged(boolean needsAnimation) {
1064 super.notifyHeightChanged(needsAnimation);
1065 getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked());
1066 }
1067
Selim Cinek3c76d502016-02-19 15:16:33 -08001068 public void setSensitive(boolean sensitive, boolean hideSensitive) {
Jorim Jaggiae441282014-08-01 02:45:18 +02001069 mSensitive = sensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -08001070 mSensitiveHiddenInGeneral = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02001071 }
1072
1073 public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
Selim Cinek60122be2015-04-15 18:16:50 -07001074 mHideSensitiveForIntrinsicHeight = hideSensitive;
Selim Cineka52f6a12016-02-29 15:35:58 -08001075 if (mIsSummaryWithChildren) {
1076 List<ExpandableNotificationRow> notificationChildren =
1077 mChildrenContainer.getNotificationChildren();
1078 for (int i = 0; i < notificationChildren.size(); i++) {
1079 ExpandableNotificationRow child = notificationChildren.get(i);
1080 child.setHideSensitiveForIntrinsicHeight(hideSensitive);
1081 }
1082 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001083 }
1084
1085 public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
1086 long duration) {
1087 boolean oldShowingPublic = mShowingPublic;
1088 mShowingPublic = mSensitive && hideSensitive;
1089 if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
1090 return;
1091 }
Dan Sandlera5e0f412014-01-23 15:11:54 -05001092
1093 // bail out if no public version
Selim Cinek1685e632014-04-08 02:27:49 +02001094 if (mPublicLayout.getChildCount() == 0) return;
Dan Sandlera5e0f412014-01-23 15:11:54 -05001095
Jorim Jaggiae441282014-08-01 02:45:18 +02001096 if (!animated) {
1097 mPublicLayout.animate().cancel();
1098 mPrivateLayout.animate().cancel();
1099 mPublicLayout.setAlpha(1f);
1100 mPrivateLayout.setAlpha(1f);
1101 mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
Selim Cinekd84a5932015-12-15 11:45:36 -08001102 updateChildrenVisibility();
Jorim Jaggiae441282014-08-01 02:45:18 +02001103 } else {
1104 animateShowingPublic(delay, duration);
1105 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001106
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001107 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinek757d8792016-01-28 16:21:08 -08001108 updateClearability();
Jorim Jaggiae441282014-08-01 02:45:18 +02001109 mShowingPublicInitialized = true;
1110 }
1111
1112 private void animateShowingPublic(long delay, long duration) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001113 View[] privateViews = mIsSummaryWithChildren ?
1114 new View[] {mChildrenContainer, mNotificationHeader}
1115 : new View[] {mPrivateLayout};
1116 View[] publicViews = new View[] {mPublicLayout};
1117 View[] hiddenChildren = mShowingPublic ? privateViews : publicViews;
1118 View[] shownChildren = mShowingPublic ? publicViews : privateViews;
1119 for (final View hiddenView : hiddenChildren) {
1120 hiddenView.setVisibility(View.VISIBLE);
1121 hiddenView.animate().cancel();
1122 hiddenView.animate()
1123 .alpha(0f)
1124 .setStartDelay(delay)
1125 .setDuration(duration)
1126 .withEndAction(new Runnable() {
1127 @Override
1128 public void run() {
1129 hiddenView.setVisibility(View.INVISIBLE);
1130 }
1131 });
1132 }
1133 for (View showView : shownChildren) {
1134 showView.setVisibility(View.VISIBLE);
1135 showView.setAlpha(0f);
1136 showView.animate().cancel();
1137 showView.animate()
1138 .alpha(1f)
1139 .setStartDelay(delay)
1140 .setDuration(duration);
1141 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001142 }
1143
Selim Cinek3776fe02016-02-04 13:32:43 -08001144 public boolean mustStayOnScreen() {
1145 return mIsHeadsUp;
1146 }
1147
Selim Cinek757d8792016-01-28 16:21:08 -08001148 private void updateClearability() {
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001149 // public versions cannot be dismissed
Selim Cinek3c76d502016-02-19 15:16:33 -08001150 mVetoButton.setVisibility(isClearable() && (!mShowingPublic
1151 || !mSensitiveHiddenInGeneral) ? View.VISIBLE : View.GONE);
Dan Sandlera5e0f412014-01-23 15:11:54 -05001152 }
Jorim Jaggi251957d2014-04-09 04:24:09 +02001153
Selim Cinekb5605e52015-02-20 18:21:41 +01001154 public void setChildrenExpanded(boolean expanded, boolean animate) {
1155 mChildrenExpanded = expanded;
Selim Cinek7b836392015-12-04 20:02:59 -08001156 if (mNotificationHeader != null) {
1157 mNotificationHeader.setExpanded(expanded);
1158 }
Selim Cinek83bc7832015-10-22 13:26:54 -07001159 if (mChildrenContainer != null) {
1160 mChildrenContainer.setChildrenExpanded(expanded);
1161 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001162 }
1163
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001164 public void updateHeaderChildCount() {
1165 if (mIsSummaryWithChildren) {
1166 mNotificationHeader.setChildCount(
1167 mChildrenContainer.getNotificationChildren().size());
Selim Cinekb5605e52015-02-20 18:21:41 +01001168 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001169 }
1170
1171 public static void applyTint(View v, int color) {
1172 int alpha;
1173 if (color != 0) {
1174 alpha = COLORED_DIVIDER_ALPHA;
1175 } else {
1176 color = 0xff000000;
1177 alpha = DEFAULT_DIVIDER_ALPHA;
1178 }
1179 if (v.getBackground() instanceof ColorDrawable) {
1180 ColorDrawable background = (ColorDrawable) v.getBackground();
1181 background.mutate();
1182 background.setColor(color);
1183 background.setAlpha(alpha);
1184 }
1185 }
1186
Selim Cinek1685e632014-04-08 02:27:49 +02001187 public int getMaxExpandHeight() {
Selim Cinekb5605e52015-02-20 18:21:41 +01001188 return mMaxExpandHeight;
Chris Wren51c75102013-07-16 20:49:17 -04001189 }
Jorim Jaggi584a7aa2014-04-10 23:26:13 +02001190
Mady Mellor34958fa2016-02-23 09:52:17 -08001191 public boolean areGutsExposed() {
1192 return (mGuts != null && mGuts.areGutsExposed());
1193 }
1194
Jorim Jaggibe565df2014-04-28 17:51:23 +02001195 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001196 public boolean isContentExpandable() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001197 NotificationContentView showingLayout = getShowingLayout();
1198 return showingLayout.isContentExpandable();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001199 }
1200
1201 @Override
Selim Cinek560e64d2015-06-09 19:58:11 -07001202 protected View getContentView() {
1203 return getShowingLayout();
1204 }
1205
1206 @Override
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001207 public void setActualHeight(int height, boolean notifyListeners) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001208 super.setActualHeight(height, notifyListeners);
Mady Mellorb53bc272016-02-11 18:28:23 -08001209 if (mGuts != null && mGuts.areGutsExposed()) {
1210 mGuts.setActualHeight(height);
1211 return;
1212 }
Selim Cinekeef84282015-10-30 16:28:00 -07001213 int contentHeight = Math.max(getMinHeight(), height);
Selim Cinekb5605e52015-02-20 18:21:41 +01001214 mPrivateLayout.setContentHeight(contentHeight);
1215 mPublicLayout.setContentHeight(contentHeight);
Selim Cinek42357e02016-02-24 18:48:01 -08001216 if (mIsSummaryWithChildren) {
1217 mChildrenContainer.setActualHeight(height);
1218 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001219 if (mGuts != null) {
1220 mGuts.setActualHeight(height);
1221 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001222 }
1223
1224 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01001225 public int getMaxContentHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001226 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001227 return mChildrenContainer.getMaxContentHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001228 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001229 NotificationContentView showingLayout = getShowingLayout();
1230 return showingLayout.getMaxHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001231 }
1232
1233 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001234 public int getMinHeight() {
Selim Cinek31aada42015-12-18 17:51:15 -08001235 if (mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) {
1236 return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
1237 } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001238 return mChildrenContainer.getMinHeight();
Selim Cinek31aada42015-12-18 17:51:15 -08001239 } else if (mIsHeadsUp) {
1240 return mHeadsUpHeight;
Selim Cinekb55386d2015-12-16 17:26:49 -08001241 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001242 NotificationContentView showingLayout = getShowingLayout();
1243 return showingLayout.getMinHeight();
1244 }
1245
1246 @Override
1247 public int getMinExpandHeight() {
Selim Cinek2c584612016-02-29 16:14:25 -08001248 if (mIsSummaryWithChildren && !mShowingPublic) {
1249 return mChildrenContainer.getMinExpandHeight(mOnKeyguard);
Selim Cinek83bc7832015-10-22 13:26:54 -07001250 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001251 return getMinHeight();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001252 }
1253
1254 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02001255 public void setClipTopAmount(int clipTopAmount) {
1256 super.setClipTopAmount(clipTopAmount);
1257 mPrivateLayout.setClipTopAmount(clipTopAmount);
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001258 mPublicLayout.setClipTopAmount(clipTopAmount);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001259 if (mGuts != null) {
1260 mGuts.setClipTopAmount(clipTopAmount);
1261 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001262 }
1263
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001264 private void recreateNotificationHeader() {
1265 final Notification.Builder builder = Notification.Builder.recoverBuilder(getContext(),
1266 getStatusBarNotification().getNotification());
1267 final RemoteViews header = builder.makeNotificationHeader();
1268 if (mNotificationHeader == null) {
1269 mNotificationHeader = (NotificationHeaderView) header.apply(getContext(), this);
1270 final View expandButton = mNotificationHeader.findViewById(
1271 com.android.internal.R.id.expand_button);
1272 expandButton.setVisibility(VISIBLE);
1273 mNotificationHeader.setOnClickListener(mExpandClickListener);
Selim Cinek9c7712d2015-12-08 19:19:48 -08001274 mNotificationHeaderWrapper = NotificationViewWrapper.wrap(getContext(),
1275 mNotificationHeader);
Selim Cinekb5a83612015-12-11 14:14:39 -08001276 addView(mNotificationHeader, indexOfChild(mChildrenContainer) + 1);
Mady Mellor4b80b102016-01-22 08:03:58 -08001277 mTranslateableViews.add(mNotificationHeader);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001278 } else {
1279 header.reapply(getContext(), mNotificationHeader);
Selim Cinek4ffd6362015-12-29 15:12:23 +01001280 mNotificationHeaderWrapper.notifyContentUpdated(mEntry.notification);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001281 }
Selim Cinek7b836392015-12-04 20:02:59 -08001282 updateHeaderExpandButton();
Selim Cinekea4bef72015-12-02 15:51:10 -08001283 updateChildrenHeaderAppearance();
Selim Cinek8fc93c92015-11-23 17:48:07 -08001284 updateHeaderChildCount();
Selim Cinek343e6e22014-04-11 21:23:30 +02001285 }
Selim Cinek7d447722014-06-10 15:51:59 +02001286
Selim Cinek7b836392015-12-04 20:02:59 -08001287 private void updateHeaderExpandButton() {
1288 if (mIsSummaryWithChildren) {
1289 mNotificationHeader.setIsGroupHeader(true /* isGroupHeader*/);
1290 }
1291 }
1292
Selim Cinekea4bef72015-12-02 15:51:10 -08001293 public void updateChildrenHeaderAppearance() {
1294 if (mIsSummaryWithChildren) {
1295 mHeaderUtil.updateChildrenHeaderAppearance();
1296 }
1297 }
1298
Selim Cinek31094df2014-08-14 19:28:15 +02001299 public boolean isMaxExpandHeightInitialized() {
1300 return mMaxExpandHeight != 0;
Selim Cinek7d447722014-06-10 15:51:59 +02001301 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001302
Selim Cinek42357e02016-02-24 18:48:01 -08001303 public NotificationContentView getShowingLayout() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001304 return mShowingPublic ? mPublicLayout : mPrivateLayout;
1305 }
Chris Wren78403d72014-07-28 10:23:24 +01001306
Jorim Jaggi59ec3042015-06-05 15:18:43 -07001307 @Override
1308 public void setShowingLegacyBackground(boolean showing) {
1309 super.setShowingLegacyBackground(showing);
1310 mPrivateLayout.setShowingLegacyBackground(showing);
1311 mPublicLayout.setShowingLegacyBackground(showing);
1312 }
1313
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001314 @Override
1315 protected void updateBackgroundTint() {
1316 super.updateBackgroundTint();
1317 updateNoBackgroundState();
1318 if (mIsSummaryWithChildren) {
1319 List<ExpandableNotificationRow> notificationChildren =
1320 mChildrenContainer.getNotificationChildren();
1321 for (int i = 0; i < notificationChildren.size(); i++) {
1322 ExpandableNotificationRow child = notificationChildren.get(i);
1323 child.updateNoBackgroundState();
1324 }
1325 }
1326 }
1327
1328 private void updateNoBackgroundState() {
1329 mShowNoBackground = isChildInGroup() && hasSameBgColor(mNotificationParent);
1330 updateBackground();
1331 }
1332
Chris Wren78403d72014-07-28 10:23:24 +01001333 public void setExpansionLogger(ExpansionLogger logger, String key) {
1334 mLogger = logger;
1335 mLoggingKey = key;
1336 }
1337
Selim Cinek6183d122016-01-14 18:48:41 -08001338 @Override
Selim Cinek42357e02016-02-24 18:48:01 -08001339 public float getIncreasedPaddingAmount() {
1340 if (mIsSummaryWithChildren) {
1341 if (isGroupExpanded()) {
1342 return 1.0f;
1343 } else if (isUserLocked()) {
1344 return mChildrenContainer.getChildExpandFraction();
1345 }
1346 }
1347 return 0.0f;
Selim Cinek61633a82016-01-25 15:54:10 -08001348 }
1349
1350 @Override
Selim Cinek6183d122016-01-14 18:48:41 -08001351 protected boolean disallowSingleClick(MotionEvent event) {
1352 float x = event.getX();
1353 float y = event.getY();
Selim Cinek34eda5e2016-02-18 17:10:43 -08001354 NotificationHeaderView header = getVisibleNotificationHeader();
Selim Cinek6183d122016-01-14 18:48:41 -08001355 if (header != null) {
1356 return header.isInTouchRect(x, y);
1357 }
1358 return super.disallowSingleClick(event);
1359 }
1360
Chris Wren78403d72014-07-28 10:23:24 +01001361 private void logExpansionEvent(boolean userAction, boolean wasExpanded) {
1362 final boolean nowExpanded = isExpanded();
1363 if (wasExpanded != nowExpanded && mLogger != null) {
1364 mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ;
1365 }
1366 }
Selim Cinek570981d2015-12-01 11:37:01 -08001367
1368 public interface OnExpandClickListener {
Selim Cinek31aada42015-12-18 17:51:15 -08001369 void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
Selim Cinek570981d2015-12-01 11:37:01 -08001370 }
Chris Wren51c75102013-07-16 20:49:17 -04001371}