blob: 9799d75a890f1b1d506aeabdb411f4d0f4c042b2 [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());
Selim Cinekab29aeb2015-02-20 18:18:32 +0100659 mGutsStub = null;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200660 }
661 });
Selim Cinekb5605e52015-02-20 18:21:41 +0100662 mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub);
663 mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() {
664
665 @Override
666 public void onInflate(ViewStub stub, View inflated) {
667 mChildrenContainer = (NotificationChildrenContainer) inflated;
Selim Cinek388df6d2015-10-22 13:25:11 -0700668 mChildrenContainer.setNotificationParent(ExpandableNotificationRow.this);
Mady Mellor4b80b102016-01-22 08:03:58 -0800669 mTranslateableViews.add(mChildrenContainer);
Selim Cinekb5605e52015-02-20 18:21:41 +0100670 }
671 });
Selim Cinek863834b2014-05-20 04:20:25 +0200672 mVetoButton = findViewById(R.id.veto);
Mady Mellor4b80b102016-01-22 08:03:58 -0800673
674 // Add the views that we translate to reveal the gear
675 mTranslateableViews = new ArrayList<View>();
676 for (int i = 0; i < getChildCount(); i++) {
677 mTranslateableViews.add(getChildAt(i));
678 }
679 // Remove views that don't translate
680 mTranslateableViews.remove(mVetoButton);
681 mTranslateableViews.remove(mSettingsIconRowStub);
682 mTranslateableViews.remove(mChildrenContainerStub);
683 mTranslateableViews.remove(mGutsStub);
684 }
685
686 public void setTranslationForOutline(float translationX) {
687 setOutlineRect(false, translationX, getTop(), getRight() + translationX, getBottom());
688 }
689
690 public void resetTranslation() {
691 if (mTranslateableViews != null) {
692 for (int i = 0; i < mTranslateableViews.size(); i++) {
693 mTranslateableViews.get(i).setTranslationX(0);
694 }
695 setTranslationForOutline(0);
696 }
697 if (mSettingsIconRow != null) {
698 mSettingsIconRow.resetState();
699 }
700 }
701
702 public void animateTranslateNotification(final float leftTarget) {
703 if (mTranslateAnim != null) {
704 mTranslateAnim.cancel();
705 }
706 AnimatorSet set = new AnimatorSet();
707 if (mTranslateableViews != null) {
708 for (int i = 0; i < mTranslateableViews.size(); i++) {
709 final View animView = mTranslateableViews.get(i);
710 final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(
711 animView, "translationX", leftTarget);
712 if (i == 0) {
713 translateAnim.addUpdateListener(new AnimatorUpdateListener() {
714 @Override
715 public void onAnimationUpdate(ValueAnimator animation) {
716 setTranslationForOutline((float) animation.getAnimatedValue());
717 }
718 });
719 }
720 translateAnim.addListener(new AnimatorListenerAdapter() {
721 @Override
722 public void onAnimationEnd(Animator anim) {
723 if (mSettingsIconRow != null && leftTarget == 0) {
724 mSettingsIconRow.resetState();
725 }
726 mTranslateAnim = null;
727 }
728 });
729 set.play(translateAnim);
730 }
731 }
732 mTranslateAnim = set;
733 set.start();
734 }
735
736 public float getSpaceForGear() {
737 if (mSettingsIconRow != null) {
738 return mSettingsIconRow.getSpaceForGear();
739 }
740 return 0;
741 }
742
743 public NotificationSettingsIconRow getSettingsRow() {
744 if (mSettingsIconRow == null) {
745 mSettingsIconRowStub.inflate();
746 }
747 return mSettingsIconRow;
748 }
749
750 public ArrayList<View> getContentViews() {
751 return mTranslateableViews;
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200752 }
753
Selim Cinekab29aeb2015-02-20 18:18:32 +0100754 public void inflateGuts() {
755 if (mGuts == null) {
756 mGutsStub.inflate();
757 }
758 }
759
Selim Cinekda42d652015-12-04 15:51:16 -0800760 private void updateChildrenVisibility() {
Selim Cinekd84a5932015-12-15 11:45:36 -0800761 mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE
762 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -0800763 if (mChildrenContainer != null) {
764 mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
765 : INVISIBLE);
Selim Cinekb5605e52015-02-20 18:21:41 +0100766 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800767 if (mNotificationHeader != null) {
768 mNotificationHeader.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
769 : INVISIBLE);
770 }
Selim Cinekda42d652015-12-04 15:51:16 -0800771 // The limits might have changed if the view suddenly became a group or vice versa
772 updateLimits();
Selim Cinekb5605e52015-02-20 18:21:41 +0100773 }
774
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200775 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -0800776 public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
777 if (super.onRequestSendAccessibilityEventInternal(child, event)) {
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200778 // Add a record for the entire layout since its content is somehow small.
779 // The event comes from a leaf view that is interacted with.
780 AccessibilityEvent record = AccessibilityEvent.obtain();
781 onInitializeAccessibilityEvent(record);
782 dispatchPopulateAccessibilityEvent(record);
783 event.appendRecord(record);
784 return true;
785 }
786 return false;
Jorim Jaggic5dc0d02014-04-15 15:42:55 +0200787 }
Chris Wren51c75102013-07-16 20:49:17 -0400788
John Spurlocke15452b2014-08-21 09:44:39 -0400789 @Override
Jorim Jaggi4e857f42014-11-17 19:14:04 +0100790 public void setDark(boolean dark, boolean fade, long delay) {
791 super.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -0400792 final NotificationContentView showing = getShowingLayout();
793 if (showing != null) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +0100794 showing.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -0400795 }
Selim Cinek9c7712d2015-12-08 19:19:48 -0800796 if (mIsSummaryWithChildren) {
797 mChildrenContainer.setDark(dark, fade, delay);
798 mNotificationHeaderWrapper.setDark(dark, fade, delay);
799 }
John Spurlocke15452b2014-08-21 09:44:39 -0400800 }
801
Chris Wren51c75102013-07-16 20:49:17 -0400802 public boolean isExpandable() {
Selim Cinek388df6d2015-10-22 13:25:11 -0700803 if (mIsSummaryWithChildren && !mShowingPublic) {
804 return !mChildrenExpanded;
805 }
Chris Wren51c75102013-07-16 20:49:17 -0400806 return mExpandable;
807 }
808
809 public void setExpandable(boolean expandable) {
810 mExpandable = expandable;
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800811 mPrivateLayout.updateExpandButtons(isExpandable());
Chris Wren51c75102013-07-16 20:49:17 -0400812 }
813
Selim Cinek4ffd6362015-12-29 15:12:23 +0100814 @Override
815 public void setClipToActualHeight(boolean clipToActualHeight) {
Selim Cinek084c16b2016-01-22 17:48:22 -0800816 super.setClipToActualHeight(clipToActualHeight || isUserLocked());
817 getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked());
Selim Cinek4ffd6362015-12-29 15:12:23 +0100818 }
819
Selim Cinek1685e632014-04-08 02:27:49 +0200820 /**
821 * @return whether the user has changed the expansion state
822 */
823 public boolean hasUserChangedExpansion() {
824 return mHasUserChangedExpansion;
825 }
826
Chris Wren51c75102013-07-16 20:49:17 -0400827 public boolean isUserExpanded() {
828 return mUserExpanded;
829 }
830
Selim Cinek1685e632014-04-08 02:27:49 +0200831 /**
832 * Set this notification to be expanded by the user
833 *
834 * @param userExpanded whether the user wants this notification to be expanded
835 */
Chris Wren51c75102013-07-16 20:49:17 -0400836 public void setUserExpanded(boolean userExpanded) {
Selim Cinek388df6d2015-10-22 13:25:11 -0700837 setUserExpanded(userExpanded, false /* allowChildExpansion */);
838 }
839
840 /**
841 * Set this notification to be expanded by the user
842 *
843 * @param userExpanded whether the user wants this notification to be expanded
844 * @param allowChildExpansion whether a call to this method allows expanding children
845 */
846 public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700847 mFalsingManager.setNotificationExpanded();
Selim Cinek388df6d2015-10-22 13:25:11 -0700848 if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion) {
849 mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded);
850 return;
851 }
Christoph Studera7fe6312014-06-27 19:32:44 +0200852 if (userExpanded && !mExpandable) return;
Chris Wren78403d72014-07-28 10:23:24 +0100853 final boolean wasExpanded = isExpanded();
Selim Cinek1685e632014-04-08 02:27:49 +0200854 mHasUserChangedExpansion = true;
Chris Wren51c75102013-07-16 20:49:17 -0400855 mUserExpanded = userExpanded;
Chris Wren78403d72014-07-28 10:23:24 +0100856 logExpansionEvent(true, wasExpanded);
Chris Wren51c75102013-07-16 20:49:17 -0400857 }
858
Selim Cinekccd14fb2014-08-12 18:53:24 +0200859 public void resetUserExpansion() {
860 mHasUserChangedExpansion = false;
861 mUserExpanded = false;
862 }
863
Chris Wren51c75102013-07-16 20:49:17 -0400864 public boolean isUserLocked() {
865 return mUserLocked;
866 }
867
868 public void setUserLocked(boolean userLocked) {
869 mUserLocked = userLocked;
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800870 mPrivateLayout.setUserExpanding(userLocked);
Selim Cinek42357e02016-02-24 18:48:01 -0800871 if (mIsSummaryWithChildren) {
872 mChildrenContainer.setUserLocked(userLocked);
873 }
Chris Wren51c75102013-07-16 20:49:17 -0400874 }
875
Selim Cinek1685e632014-04-08 02:27:49 +0200876 /**
877 * @return has the system set this notification to be expanded
878 */
879 public boolean isSystemExpanded() {
880 return mIsSystemExpanded;
881 }
882
883 /**
884 * Set this notification to be expanded by the system.
885 *
886 * @param expand whether the system wants this notification to be expanded.
887 */
888 public void setSystemExpanded(boolean expand) {
Selim Cinek31094df2014-08-14 19:28:15 +0200889 if (expand != mIsSystemExpanded) {
890 final boolean wasExpanded = isExpanded();
891 mIsSystemExpanded = expand;
Selim Cinekb5605e52015-02-20 18:21:41 +0100892 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +0200893 logExpansionEvent(false, wasExpanded);
Selim Cinek83bc7832015-10-22 13:26:54 -0700894 if (mChildrenContainer != null) {
895 mChildrenContainer.updateGroupOverflow();
896 }
Selim Cinek31094df2014-08-14 19:28:15 +0200897 }
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200898 }
899
900 /**
Selim Cinek83bc7832015-10-22 13:26:54 -0700901 * @param onKeyguard whether to prevent notification expansion
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200902 */
Selim Cinek83bc7832015-10-22 13:26:54 -0700903 public void setOnKeyguard(boolean onKeyguard) {
904 if (onKeyguard != mOnKeyguard) {
Selim Cinek31094df2014-08-14 19:28:15 +0200905 final boolean wasExpanded = isExpanded();
Selim Cinek83bc7832015-10-22 13:26:54 -0700906 mOnKeyguard = onKeyguard;
Selim Cinek31094df2014-08-14 19:28:15 +0200907 logExpansionEvent(false, wasExpanded);
908 if (wasExpanded != isExpanded()) {
Selim Cinek2108fe02015-12-10 12:56:13 -0800909 if (mIsSummaryWithChildren) {
910 mChildrenContainer.updateGroupOverflow();
911 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800912 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +0200913 }
914 }
Selim Cinek1685e632014-04-08 02:27:49 +0200915 }
916
917 /**
Dan Sandler0d3e62f2014-07-14 17:13:50 -0400918 * @return Can the underlying notification be cleared?
919 */
920 public boolean isClearable() {
Selim Cineka37774f2014-11-11 19:16:18 +0100921 return mStatusBarNotification != null && mStatusBarNotification.isClearable();
Dan Sandler0d3e62f2014-07-14 17:13:50 -0400922 }
923
924 /**
Selim Cinek1685e632014-04-08 02:27:49 +0200925 * Apply an expansion state to the layout.
Selim Cinek1685e632014-04-08 02:27:49 +0200926 */
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200927 public void applyExpansionToLayout() {
928 boolean expand = isExpanded();
Chris Wren51c75102013-07-16 20:49:17 -0400929 if (expand && mExpandable) {
Selim Cinekeef84282015-10-30 16:28:00 -0700930 setActualHeight(mMaxExpandHeight);
Chris Wren51c75102013-07-16 20:49:17 -0400931 } else {
Selim Cinek860b6da2015-12-16 19:02:19 -0800932 setActualHeight(getMinHeight());
Chris Wren51c75102013-07-16 20:49:17 -0400933 }
Chris Wren51c75102013-07-16 20:49:17 -0400934 }
Dan Sandlera5e0f412014-01-23 15:11:54 -0500935
Jorim Jaggi9cbadd32014-05-01 20:18:31 +0200936 @Override
937 public int getIntrinsicHeight() {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200938 if (isUserLocked()) {
939 return getActualHeight();
940 }
Selim Cinekd84a5932015-12-15 11:45:36 -0800941 if (mGuts != null && mGuts.areGutsExposed()) {
942 return mGuts.getHeight();
943 } else if ((isChildInGroup() && !isGroupExpanded())) {
944 return mPrivateLayout.getMinHeight();
945 } else if (mSensitive && mHideSensitiveForIntrinsicHeight) {
946 return getMinHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -0700947 } else if (mIsSummaryWithChildren && !mOnKeyguard) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800948 return mChildrenContainer.getIntrinsicHeight();
Selim Cinek60122be2015-04-15 18:16:50 -0700949 } else if (mIsHeadsUp) {
Selim Cinek31aada42015-12-18 17:51:15 -0800950 if (isPinned()) {
951 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
952 } else if (isExpanded()) {
Selim Cinekd84a5932015-12-15 11:45:36 -0800953 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -0700954 } else {
Selim Cinekd84a5932015-12-15 11:45:36 -0800955 return Math.max(getMinHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -0700956 }
Selim Cinek31aada42015-12-18 17:51:15 -0800957 } else if (isExpanded()) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700958 return getMaxExpandHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -0800959 } else {
960 return getMinHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200961 }
Selim Cinekb5605e52015-02-20 18:21:41 +0100962 }
Selim Cinek1685e632014-04-08 02:27:49 +0200963
Selim Cinekeef84282015-10-30 16:28:00 -0700964 private boolean isGroupExpanded() {
965 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinekb5605e52015-02-20 18:21:41 +0100966 }
967
Selim Cinekeef84282015-10-30 16:28:00 -0700968 /**
969 * @return whether this view has a header on the top of the content
970 */
971 private boolean hasNotificationHeader() {
972 return mIsSummaryWithChildren;
Selim Cinek1685e632014-04-08 02:27:49 +0200973 }
974
Selim Cinek263398f2015-10-21 17:40:23 -0700975 private void onChildrenCountChanged() {
Selim Cinek8fc93c92015-11-23 17:48:07 -0800976 mIsSummaryWithChildren = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS
Selim Cinek263398f2015-10-21 17:40:23 -0700977 && mGroupManager.hasGroupChildren(mStatusBarNotification);
Selim Cinek8fc93c92015-11-23 17:48:07 -0800978 if (mIsSummaryWithChildren) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800979 if (mChildrenContainer == null) {
980 mChildrenContainerStub.inflate();
981 }
Selim Cinek8fc93c92015-11-23 17:48:07 -0800982 if (mNotificationHeader == null) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800983 recreateNotificationHeader();
984 }
Selim Cinek263398f2015-10-21 17:40:23 -0700985 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800986 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinekea4bef72015-12-02 15:51:10 -0800987 updateChildrenHeaderAppearance();
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800988 updateHeaderChildCount();
Selim Cinekda42d652015-12-04 15:51:16 -0800989 updateChildrenVisibility();
Selim Cinek263398f2015-10-21 17:40:23 -0700990 }
991
Selim Cinek1685e632014-04-08 02:27:49 +0200992 /**
993 * Check whether the view state is currently expanded. This is given by the system in {@link
994 * #setSystemExpanded(boolean)} and can be overridden by user expansion or
995 * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this
996 * view can differ from this state, if layout params are modified from outside.
997 *
998 * @return whether the view state is currently expanded.
999 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001000 public boolean isExpanded() {
1001 return !mOnKeyguard
Selim Cinekb5605e52015-02-20 18:21:41 +01001002 && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded())
1003 || isUserExpanded());
1004 }
1005
1006 private boolean isSystemChildExpanded() {
1007 return mIsSystemChildExpanded;
1008 }
1009
1010 public void setSystemChildExpanded(boolean expanded) {
1011 mIsSystemChildExpanded = expanded;
Selim Cinek1685e632014-04-08 02:27:49 +02001012 }
1013
1014 @Override
1015 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
1016 super.onLayout(changed, left, top, right, bottom);
Selim Cineka5e211b2014-08-11 17:35:48 +02001017 boolean updateExpandHeight = mMaxExpandHeight == 0 && !mWasReset;
Selim Cinek8d490d42015-04-10 00:05:50 -07001018 updateMaxHeights();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001019 if (updateExpandHeight) {
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001020 applyExpansionToLayout();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001021 }
Selim Cineka5e211b2014-08-11 17:35:48 +02001022 mWasReset = false;
Selim Cinek1685e632014-04-08 02:27:49 +02001023 }
1024
Selim Cinek8d490d42015-04-10 00:05:50 -07001025 private void updateMaxHeights() {
Selim Cinekd2319fb2014-09-01 19:41:54 +02001026 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek8d490d42015-04-10 00:05:50 -07001027 View expandedChild = mPrivateLayout.getExpandedChild();
1028 if (expandedChild == null) {
1029 expandedChild = mPrivateLayout.getContractedChild();
1030 }
1031 mMaxExpandHeight = expandedChild.getHeight();
1032 View headsUpChild = mPrivateLayout.getHeadsUpChild();
Selim Cinek1f3f5442015-04-10 17:54:46 -07001033 if (headsUpChild == null) {
1034 headsUpChild = mPrivateLayout.getContractedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -07001035 }
Selim Cinek1f3f5442015-04-10 17:54:46 -07001036 mHeadsUpHeight = headsUpChild.getHeight();
Selim Cinekd2319fb2014-09-01 19:41:54 +02001037 if (intrinsicBefore != getIntrinsicHeight()) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001038 notifyHeightChanged(false /* needsAnimation */);
Selim Cinekd2319fb2014-09-01 19:41:54 +02001039 }
1040 }
1041
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001042 @Override
1043 public void notifyHeightChanged(boolean needsAnimation) {
1044 super.notifyHeightChanged(needsAnimation);
1045 getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked());
1046 }
1047
Selim Cinek3c76d502016-02-19 15:16:33 -08001048 public void setSensitive(boolean sensitive, boolean hideSensitive) {
Jorim Jaggiae441282014-08-01 02:45:18 +02001049 mSensitive = sensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -08001050 mSensitiveHiddenInGeneral = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02001051 }
1052
1053 public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
Selim Cinek60122be2015-04-15 18:16:50 -07001054 mHideSensitiveForIntrinsicHeight = hideSensitive;
Selim Cineka52f6a12016-02-29 15:35:58 -08001055 if (mIsSummaryWithChildren) {
1056 List<ExpandableNotificationRow> notificationChildren =
1057 mChildrenContainer.getNotificationChildren();
1058 for (int i = 0; i < notificationChildren.size(); i++) {
1059 ExpandableNotificationRow child = notificationChildren.get(i);
1060 child.setHideSensitiveForIntrinsicHeight(hideSensitive);
1061 }
1062 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001063 }
1064
1065 public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
1066 long duration) {
1067 boolean oldShowingPublic = mShowingPublic;
1068 mShowingPublic = mSensitive && hideSensitive;
1069 if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
1070 return;
1071 }
Dan Sandlera5e0f412014-01-23 15:11:54 -05001072
1073 // bail out if no public version
Selim Cinek1685e632014-04-08 02:27:49 +02001074 if (mPublicLayout.getChildCount() == 0) return;
Dan Sandlera5e0f412014-01-23 15:11:54 -05001075
Jorim Jaggiae441282014-08-01 02:45:18 +02001076 if (!animated) {
1077 mPublicLayout.animate().cancel();
1078 mPrivateLayout.animate().cancel();
1079 mPublicLayout.setAlpha(1f);
1080 mPrivateLayout.setAlpha(1f);
1081 mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
Selim Cinekd84a5932015-12-15 11:45:36 -08001082 updateChildrenVisibility();
Jorim Jaggiae441282014-08-01 02:45:18 +02001083 } else {
1084 animateShowingPublic(delay, duration);
1085 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001086
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001087 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinek757d8792016-01-28 16:21:08 -08001088 updateClearability();
Jorim Jaggiae441282014-08-01 02:45:18 +02001089 mShowingPublicInitialized = true;
1090 }
1091
1092 private void animateShowingPublic(long delay, long duration) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001093 View[] privateViews = mIsSummaryWithChildren ?
1094 new View[] {mChildrenContainer, mNotificationHeader}
1095 : new View[] {mPrivateLayout};
1096 View[] publicViews = new View[] {mPublicLayout};
1097 View[] hiddenChildren = mShowingPublic ? privateViews : publicViews;
1098 View[] shownChildren = mShowingPublic ? publicViews : privateViews;
1099 for (final View hiddenView : hiddenChildren) {
1100 hiddenView.setVisibility(View.VISIBLE);
1101 hiddenView.animate().cancel();
1102 hiddenView.animate()
1103 .alpha(0f)
1104 .setStartDelay(delay)
1105 .setDuration(duration)
1106 .withEndAction(new Runnable() {
1107 @Override
1108 public void run() {
1109 hiddenView.setVisibility(View.INVISIBLE);
1110 }
1111 });
1112 }
1113 for (View showView : shownChildren) {
1114 showView.setVisibility(View.VISIBLE);
1115 showView.setAlpha(0f);
1116 showView.animate().cancel();
1117 showView.animate()
1118 .alpha(1f)
1119 .setStartDelay(delay)
1120 .setDuration(duration);
1121 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001122 }
1123
Selim Cinek3776fe02016-02-04 13:32:43 -08001124 public boolean mustStayOnScreen() {
1125 return mIsHeadsUp;
1126 }
1127
Selim Cinek757d8792016-01-28 16:21:08 -08001128 private void updateClearability() {
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001129 // public versions cannot be dismissed
Selim Cinek3c76d502016-02-19 15:16:33 -08001130 mVetoButton.setVisibility(isClearable() && (!mShowingPublic
1131 || !mSensitiveHiddenInGeneral) ? View.VISIBLE : View.GONE);
Dan Sandlera5e0f412014-01-23 15:11:54 -05001132 }
Jorim Jaggi251957d2014-04-09 04:24:09 +02001133
Selim Cinekb5605e52015-02-20 18:21:41 +01001134 public void setChildrenExpanded(boolean expanded, boolean animate) {
1135 mChildrenExpanded = expanded;
Selim Cinek7b836392015-12-04 20:02:59 -08001136 if (mNotificationHeader != null) {
1137 mNotificationHeader.setExpanded(expanded);
1138 }
Selim Cinek83bc7832015-10-22 13:26:54 -07001139 if (mChildrenContainer != null) {
1140 mChildrenContainer.setChildrenExpanded(expanded);
1141 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001142 }
1143
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001144 public void updateHeaderChildCount() {
1145 if (mIsSummaryWithChildren) {
1146 mNotificationHeader.setChildCount(
1147 mChildrenContainer.getNotificationChildren().size());
Selim Cinekb5605e52015-02-20 18:21:41 +01001148 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001149 }
1150
1151 public static void applyTint(View v, int color) {
1152 int alpha;
1153 if (color != 0) {
1154 alpha = COLORED_DIVIDER_ALPHA;
1155 } else {
1156 color = 0xff000000;
1157 alpha = DEFAULT_DIVIDER_ALPHA;
1158 }
1159 if (v.getBackground() instanceof ColorDrawable) {
1160 ColorDrawable background = (ColorDrawable) v.getBackground();
1161 background.mutate();
1162 background.setColor(color);
1163 background.setAlpha(alpha);
1164 }
1165 }
1166
Selim Cinek1685e632014-04-08 02:27:49 +02001167 public int getMaxExpandHeight() {
Selim Cinekb5605e52015-02-20 18:21:41 +01001168 return mMaxExpandHeight;
Chris Wren51c75102013-07-16 20:49:17 -04001169 }
Jorim Jaggi584a7aa2014-04-10 23:26:13 +02001170
Jorim Jaggibe565df2014-04-28 17:51:23 +02001171 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001172 public boolean isContentExpandable() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001173 NotificationContentView showingLayout = getShowingLayout();
1174 return showingLayout.isContentExpandable();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001175 }
1176
1177 @Override
Selim Cinek560e64d2015-06-09 19:58:11 -07001178 protected View getContentView() {
1179 return getShowingLayout();
1180 }
1181
1182 @Override
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001183 public void setActualHeight(int height, boolean notifyListeners) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001184 super.setActualHeight(height, notifyListeners);
Mady Mellorb53bc272016-02-11 18:28:23 -08001185 if (mGuts != null && mGuts.areGutsExposed()) {
1186 mGuts.setActualHeight(height);
1187 return;
1188 }
Selim Cinekeef84282015-10-30 16:28:00 -07001189 int contentHeight = Math.max(getMinHeight(), height);
Selim Cinekb5605e52015-02-20 18:21:41 +01001190 mPrivateLayout.setContentHeight(contentHeight);
1191 mPublicLayout.setContentHeight(contentHeight);
Selim Cinek42357e02016-02-24 18:48:01 -08001192 if (mIsSummaryWithChildren) {
1193 mChildrenContainer.setActualHeight(height);
1194 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001195 if (mGuts != null) {
1196 mGuts.setActualHeight(height);
1197 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001198 }
1199
1200 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01001201 public int getMaxContentHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001202 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001203 return mChildrenContainer.getMaxContentHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001204 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001205 NotificationContentView showingLayout = getShowingLayout();
1206 return showingLayout.getMaxHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001207 }
1208
1209 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001210 public int getMinHeight() {
Selim Cinek31aada42015-12-18 17:51:15 -08001211 if (mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) {
1212 return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
1213 } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001214 return mChildrenContainer.getMinHeight();
Selim Cinek31aada42015-12-18 17:51:15 -08001215 } else if (mIsHeadsUp) {
1216 return mHeadsUpHeight;
Selim Cinekb55386d2015-12-16 17:26:49 -08001217 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001218 NotificationContentView showingLayout = getShowingLayout();
1219 return showingLayout.getMinHeight();
1220 }
1221
1222 @Override
1223 public int getMinExpandHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001224 if (mIsSummaryWithChildren && !mOnKeyguard) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001225 return mChildrenContainer.getMinExpandHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001226 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001227 return getMinHeight();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001228 }
1229
1230 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02001231 public void setClipTopAmount(int clipTopAmount) {
1232 super.setClipTopAmount(clipTopAmount);
1233 mPrivateLayout.setClipTopAmount(clipTopAmount);
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001234 mPublicLayout.setClipTopAmount(clipTopAmount);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001235 if (mGuts != null) {
1236 mGuts.setClipTopAmount(clipTopAmount);
1237 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001238 }
1239
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001240 private void recreateNotificationHeader() {
1241 final Notification.Builder builder = Notification.Builder.recoverBuilder(getContext(),
1242 getStatusBarNotification().getNotification());
1243 final RemoteViews header = builder.makeNotificationHeader();
1244 if (mNotificationHeader == null) {
1245 mNotificationHeader = (NotificationHeaderView) header.apply(getContext(), this);
1246 final View expandButton = mNotificationHeader.findViewById(
1247 com.android.internal.R.id.expand_button);
1248 expandButton.setVisibility(VISIBLE);
1249 mNotificationHeader.setOnClickListener(mExpandClickListener);
Selim Cinek9c7712d2015-12-08 19:19:48 -08001250 mNotificationHeaderWrapper = NotificationViewWrapper.wrap(getContext(),
1251 mNotificationHeader);
Selim Cinekb5a83612015-12-11 14:14:39 -08001252 addView(mNotificationHeader, indexOfChild(mChildrenContainer) + 1);
Mady Mellor4b80b102016-01-22 08:03:58 -08001253 mTranslateableViews.add(mNotificationHeader);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001254 } else {
1255 header.reapply(getContext(), mNotificationHeader);
Selim Cinek4ffd6362015-12-29 15:12:23 +01001256 mNotificationHeaderWrapper.notifyContentUpdated(mEntry.notification);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001257 }
Selim Cinek7b836392015-12-04 20:02:59 -08001258 updateHeaderExpandButton();
Selim Cinekea4bef72015-12-02 15:51:10 -08001259 updateChildrenHeaderAppearance();
Selim Cinek8fc93c92015-11-23 17:48:07 -08001260 updateHeaderChildCount();
Selim Cinek343e6e22014-04-11 21:23:30 +02001261 }
Selim Cinek7d447722014-06-10 15:51:59 +02001262
Selim Cinek7b836392015-12-04 20:02:59 -08001263 private void updateHeaderExpandButton() {
1264 if (mIsSummaryWithChildren) {
1265 mNotificationHeader.setIsGroupHeader(true /* isGroupHeader*/);
1266 }
1267 }
1268
Selim Cinekea4bef72015-12-02 15:51:10 -08001269 public void updateChildrenHeaderAppearance() {
1270 if (mIsSummaryWithChildren) {
1271 mHeaderUtil.updateChildrenHeaderAppearance();
1272 }
1273 }
1274
Selim Cinek31094df2014-08-14 19:28:15 +02001275 public boolean isMaxExpandHeightInitialized() {
1276 return mMaxExpandHeight != 0;
Selim Cinek7d447722014-06-10 15:51:59 +02001277 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001278
Selim Cinek42357e02016-02-24 18:48:01 -08001279 public NotificationContentView getShowingLayout() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001280 return mShowingPublic ? mPublicLayout : mPrivateLayout;
1281 }
Chris Wren78403d72014-07-28 10:23:24 +01001282
Jorim Jaggi59ec3042015-06-05 15:18:43 -07001283 @Override
1284 public void setShowingLegacyBackground(boolean showing) {
1285 super.setShowingLegacyBackground(showing);
1286 mPrivateLayout.setShowingLegacyBackground(showing);
1287 mPublicLayout.setShowingLegacyBackground(showing);
1288 }
1289
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001290 @Override
1291 protected void updateBackgroundTint() {
1292 super.updateBackgroundTint();
1293 updateNoBackgroundState();
1294 if (mIsSummaryWithChildren) {
1295 List<ExpandableNotificationRow> notificationChildren =
1296 mChildrenContainer.getNotificationChildren();
1297 for (int i = 0; i < notificationChildren.size(); i++) {
1298 ExpandableNotificationRow child = notificationChildren.get(i);
1299 child.updateNoBackgroundState();
1300 }
1301 }
1302 }
1303
1304 private void updateNoBackgroundState() {
1305 mShowNoBackground = isChildInGroup() && hasSameBgColor(mNotificationParent);
1306 updateBackground();
1307 }
1308
Chris Wren78403d72014-07-28 10:23:24 +01001309 public void setExpansionLogger(ExpansionLogger logger, String key) {
1310 mLogger = logger;
1311 mLoggingKey = key;
1312 }
1313
Selim Cinek6183d122016-01-14 18:48:41 -08001314 @Override
Selim Cinek42357e02016-02-24 18:48:01 -08001315 public float getIncreasedPaddingAmount() {
1316 if (mIsSummaryWithChildren) {
1317 if (isGroupExpanded()) {
1318 return 1.0f;
1319 } else if (isUserLocked()) {
1320 return mChildrenContainer.getChildExpandFraction();
1321 }
1322 }
1323 return 0.0f;
Selim Cinek61633a82016-01-25 15:54:10 -08001324 }
1325
1326 @Override
Selim Cinek6183d122016-01-14 18:48:41 -08001327 protected boolean disallowSingleClick(MotionEvent event) {
1328 float x = event.getX();
1329 float y = event.getY();
Selim Cinek34eda5e2016-02-18 17:10:43 -08001330 NotificationHeaderView header = getVisibleNotificationHeader();
Selim Cinek6183d122016-01-14 18:48:41 -08001331 if (header != null) {
1332 return header.isInTouchRect(x, y);
1333 }
1334 return super.disallowSingleClick(event);
1335 }
1336
Chris Wren78403d72014-07-28 10:23:24 +01001337 private void logExpansionEvent(boolean userAction, boolean wasExpanded) {
1338 final boolean nowExpanded = isExpanded();
1339 if (wasExpanded != nowExpanded && mLogger != null) {
1340 mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ;
1341 }
1342 }
Selim Cinek570981d2015-12-01 11:37:01 -08001343
1344 public interface OnExpandClickListener {
Selim Cinek31aada42015-12-18 17:51:15 -08001345 void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
Selim Cinek570981d2015-12-01 11:37:01 -08001346 }
Chris Wren51c75102013-07-16 20:49:17 -04001347}