blob: e4005062f3dd2291b2a72f1af84c08b01dc95c0d [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;
Mady Mellor4b80b102016-01-22 08:03:58 -080021import android.animation.ObjectAnimator;
Mady Mellor4b80b102016-01-22 08:03:58 -080022import android.animation.ValueAnimator.AnimatorUpdateListener;
Selim Cinekddf1b392016-05-27 16:33:10 -070023import android.annotation.Nullable;
Chris Wren51c75102013-07-16 20:49:17 -040024import android.content.Context;
Selim Cinekcab4a602014-09-03 14:47:57 +020025import android.graphics.drawable.AnimatedVectorDrawable;
26import android.graphics.drawable.AnimationDrawable;
Selim Cinekb5605e52015-02-20 18:21:41 +010027import android.graphics.drawable.ColorDrawable;
Selim Cinekcab4a602014-09-03 14:47:57 +020028import android.graphics.drawable.Drawable;
Selim Cinekda42d652015-12-04 15:51:16 -080029import android.os.Build;
Selim Cineke9bad242016-06-15 11:46:37 -070030import android.os.Bundle;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020031import android.service.notification.StatusBarNotification;
Chris Wren51c75102013-07-16 20:49:17 -040032import android.util.AttributeSet;
Mady Mellorb0a82462016-04-30 17:31:02 -070033import android.util.FloatProperty;
34import android.util.Property;
Selim Cinek01af3342016-02-09 19:25:31 -080035import android.view.LayoutInflater;
Selim Cinek6183d122016-01-14 18:48:41 -080036import android.view.MotionEvent;
Selim Cinekeaa29ca2015-11-23 13:51:13 -080037import android.view.NotificationHeaderView;
Dan Sandlera5e0f412014-01-23 15:11:54 -050038import android.view.View;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +020039import android.view.ViewStub;
Jorim Jaggife40f7d2014-04-28 15:20:04 +020040import android.view.accessibility.AccessibilityEvent;
Selim Cineke9bad242016-06-15 11:46:37 -070041import android.view.accessibility.AccessibilityNodeInfo;
Selim Cinek98713a42015-09-21 15:47:20 +020042import android.widget.Chronometer;
Selim Cinekcab4a602014-09-03 14:47:57 +020043import android.widget.ImageView;
Selim Cinekb5605e52015-02-20 18:21:41 +010044
Chris Wren698b1702016-05-23 11:16:32 -040045import com.android.internal.logging.MetricsLogger;
Chris Wren698b1702016-05-23 11:16:32 -040046import com.android.internal.logging.MetricsProto.MetricsEvent;
Selim Cinek4bb59342016-04-08 19:29:35 -070047import com.android.internal.util.NotificationColorUtil;
Dan Sandlera5e0f412014-01-23 15:11:54 -050048import com.android.systemui.R;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070049import com.android.systemui.classifier.FalsingManager;
Selim Cinekc897bd32016-03-18 17:32:31 -070050import com.android.systemui.statusbar.notification.HybridNotificationView;
Selim Cinekb5605e52015-02-20 18:21:41 +010051import com.android.systemui.statusbar.phone.NotificationGroupManager;
Selim Cinek31aada42015-12-18 17:51:15 -080052import com.android.systemui.statusbar.policy.HeadsUpManager;
Selim Cinekb5605e52015-02-20 18:21:41 +010053import com.android.systemui.statusbar.stack.NotificationChildrenContainer;
Selim Cineke9bad242016-06-15 11:46:37 -070054import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Selim Cinekb5605e52015-02-20 18:21:41 +010055import com.android.systemui.statusbar.stack.StackScrollState;
56import com.android.systemui.statusbar.stack.StackStateAnimator;
57import com.android.systemui.statusbar.stack.StackViewState;
58
Mady Mellor4b80b102016-01-22 08:03:58 -080059import java.util.ArrayList;
Selim Cinekb5605e52015-02-20 18:21:41 +010060import java.util.List;
Dan Sandlera5e0f412014-01-23 15:11:54 -050061
Jorim Jaggi4222d9a2014-04-23 16:13:15 +020062public class ExpandableNotificationRow extends ActivatableNotificationView {
Selim Cinekb5605e52015-02-20 18:21:41 +010063
64 private static final int DEFAULT_DIVIDER_ALPHA = 0x29;
65 private static final int COLORED_DIVIDER_ALPHA = 0x7B;
Selim Cinek01af3342016-02-09 19:25:31 -080066 private int mNotificationMinHeightLegacy;
67 private int mMaxHeadsUpHeightLegacy;
68 private int mMaxHeadsUpHeight;
69 private int mNotificationMinHeight;
70 private int mNotificationMaxHeight;
Mady Mellorb0a82462016-04-30 17:31:02 -070071 private int mIncreasedPaddingBetweenElements;
Chris Wren51c75102013-07-16 20:49:17 -040072
Selim Cinek1685e632014-04-08 02:27:49 +020073 /** Does this row contain layouts that can adapt to row expansion */
Chris Wren51c75102013-07-16 20:49:17 -040074 private boolean mExpandable;
Selim Cinek1685e632014-04-08 02:27:49 +020075 /** Has the user actively changed the expansion state of this row */
76 private boolean mHasUserChangedExpansion;
77 /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */
Chris Wren51c75102013-07-16 20:49:17 -040078 private boolean mUserExpanded;
Selim Cinek31aada42015-12-18 17:51:15 -080079
80 /**
81 * Has this notification been expanded while it was pinned
82 */
83 private boolean mExpandedWhenPinned;
Selim Cinek1685e632014-04-08 02:27:49 +020084 /** Is the user touching this row */
Chris Wren51c75102013-07-16 20:49:17 -040085 private boolean mUserLocked;
Selim Cinek1685e632014-04-08 02:27:49 +020086 /** Are we showing the "public" version */
Dan Sandlera5e0f412014-01-23 15:11:54 -050087 private boolean mShowingPublic;
Jorim Jaggiae441282014-08-01 02:45:18 +020088 private boolean mSensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -080089 private boolean mSensitiveHiddenInGeneral;
Jorim Jaggiae441282014-08-01 02:45:18 +020090 private boolean mShowingPublicInitialized;
Selim Cinek60122be2015-04-15 18:16:50 -070091 private boolean mHideSensitiveForIntrinsicHeight;
Chris Wren51c75102013-07-16 20:49:17 -040092
Selim Cinek1685e632014-04-08 02:27:49 +020093 /**
94 * Is this notification expanded by the system. The expansion state can be overridden by the
95 * user expansion.
96 */
97 private boolean mIsSystemExpanded;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +020098
99 /**
Selim Cinek83bc7832015-10-22 13:26:54 -0700100 * Whether the notification is on the keyguard and the expansion is disabled.
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200101 */
Selim Cinek83bc7832015-10-22 13:26:54 -0700102 private boolean mOnKeyguard;
Jorim Jaggidce3c4c2014-04-29 23:12:24 +0200103
Mady Mellorb0a82462016-04-30 17:31:02 -0700104 private Animator mTranslateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -0800105 private ArrayList<View> mTranslateableViews;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200106 private NotificationContentView mPublicLayout;
107 private NotificationContentView mPrivateLayout;
Selim Cinek1685e632014-04-08 02:27:49 +0200108 private int mMaxExpandHeight;
Selim Cinek8d490d42015-04-10 00:05:50 -0700109 private int mHeadsUpHeight;
Selim Cinek863834b2014-05-20 04:20:25 +0200110 private View mVetoButton;
Selim Cinek4bb59342016-04-08 19:29:35 -0700111 private int mNotificationColor;
Chris Wren78403d72014-07-28 10:23:24 +0100112 private ExpansionLogger mLogger;
113 private String mLoggingKey;
Mady Mellor4b80b102016-01-22 08:03:58 -0800114 private NotificationSettingsIconRow mSettingsIconRow;
Selim Cinek8d490d42015-04-10 00:05:50 -0700115 private NotificationGuts mGuts;
Selim Cinekda42d652015-12-04 15:51:16 -0800116 private NotificationData.Entry mEntry;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200117 private StatusBarNotification mStatusBarNotification;
Mady Mellor3fd273e2016-03-15 21:08:14 -0700118 private String mAppName;
Selim Cinek1a521f32014-11-03 17:39:29 +0100119 private boolean mIsHeadsUp;
Selim Cinek98713a42015-09-21 15:47:20 +0200120 private boolean mLastChronometerRunning = true;
Selim Cinekb5605e52015-02-20 18:21:41 +0100121 private ViewStub mChildrenContainerStub;
122 private NotificationGroupManager mGroupManager;
Selim Cinekb5605e52015-02-20 18:21:41 +0100123 private boolean mChildrenExpanded;
Selim Cinek263398f2015-10-21 17:40:23 -0700124 private boolean mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100125 private NotificationChildrenContainer mChildrenContainer;
Mady Mellor4b80b102016-01-22 08:03:58 -0800126 private ViewStub mSettingsIconRowStub;
Selim Cinekab29aeb2015-02-20 18:18:32 +0100127 private ViewStub mGutsStub;
Selim Cinekb5605e52015-02-20 18:21:41 +0100128 private boolean mIsSystemChildExpanded;
Selim Cinek684a4422015-04-15 16:18:39 -0700129 private boolean mIsPinned;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700130 private FalsingManager mFalsingManager;
Selim Cinek31aada42015-12-18 17:51:15 -0800131 private HeadsUpManager mHeadsUpManager;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200132
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700133 private boolean mJustClicked;
Selim Cinek5a175d92015-11-23 18:01:33 -0800134 private boolean mIconAnimationRunning;
Selim Cinek34d93b02015-10-22 12:30:38 -0700135 private boolean mShowNoBackground;
Selim Cinek388df6d2015-10-22 13:25:11 -0700136 private ExpandableNotificationRow mNotificationParent;
Selim Cinek570981d2015-12-01 11:37:01 -0800137 private OnExpandClickListener mOnExpandClickListener;
Mady Mellorb0a82462016-04-30 17:31:02 -0700138 private boolean mGroupExpansionChanging;
139
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800140 private OnClickListener mExpandClickListener = new OnClickListener() {
141 @Override
142 public void onClick(View v) {
Selim Cinek624c02db2015-12-14 21:00:02 -0800143 if (!mShowingPublic && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) {
Mady Mellor1a5d8ea2016-06-09 10:42:42 -0700144 mGroupExpansionChanging = true;
Chris Wren698b1702016-05-23 11:16:32 -0400145 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
146 boolean nowExpanded = mGroupManager.toggleGroupExpansion(mStatusBarNotification);
147 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400148 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_GROUP_EXPANDER,
149 nowExpanded);
150 logExpansionEvent(true /* userAction */, wasExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800151 } else {
Selim Cineke9bad242016-06-15 11:46:37 -0700152 if (v.isAccessibilityFocused()) {
153 mPrivateLayout.setFocusOnVisibilityChange();
154 }
Selim Cinek31aada42015-12-18 17:51:15 -0800155 boolean nowExpanded;
156 if (isPinned()) {
157 nowExpanded = !mExpandedWhenPinned;
158 mExpandedWhenPinned = nowExpanded;
159 } else {
160 nowExpanded = !isExpanded();
161 setUserExpanded(nowExpanded);
162 }
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800163 notifyHeightChanged(true);
Selim Cinek31aada42015-12-18 17:51:15 -0800164 mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded);
Chris Wren698b1702016-05-23 11:16:32 -0400165 MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_EXPANDER,
166 nowExpanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800167 }
168 }
169 };
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700170 private boolean mForceUnlocked;
Selim Cinek3f19f602016-05-02 18:01:56 -0700171 private boolean mDismissed;
172 private boolean mKeepInParent;
173 private boolean mRemoved;
Mady Mellorb0a82462016-04-30 17:31:02 -0700174 private static final Property<ExpandableNotificationRow, Float> TRANSLATE_CONTENT =
175 new FloatProperty<ExpandableNotificationRow>("translate") {
176 @Override
177 public void setValue(ExpandableNotificationRow object, float value) {
178 object.setTranslation(value);
179 }
180
181 @Override
182 public Float get(ExpandableNotificationRow object) {
183 return object.getTranslation();
184 }
185 };
Selim Cinekddf1b392016-05-27 16:33:10 -0700186 private OnClickListener mOnClickListener;
Selim Cinek73cf02a2016-06-17 13:08:00 -0700187 private boolean mHeadsupDisappearRunning;
Selim Cineke9bad242016-06-15 11:46:37 -0700188 private View mChildAfterViewWhenDismissed;
189 private View mGroupParentWhenDismissed;
190 private boolean mRefocusOnDismiss;
Mady Mellorb0a82462016-04-30 17:31:02 -0700191
192 public boolean isGroupExpansionChanging() {
193 if (isChildInGroup()) {
194 return mNotificationParent.isGroupExpansionChanging();
195 }
196 return mGroupExpansionChanging;
197 }
198
199 public void setGroupExpansionChanging(boolean changing) {
200 mGroupExpansionChanging = changing;
201 }
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700202
Adrian Roos599be342016-06-13 14:54:39 -0700203 @Override
204 public void setActualHeightAnimating(boolean animating) {
205 if (mPrivateLayout != null) {
206 mPrivateLayout.setContentHeightAnimating(animating);
207 }
208 }
209
Selim Cinek8d490d42015-04-10 00:05:50 -0700210 public NotificationContentView getPrivateLayout() {
211 return mPrivateLayout;
212 }
213
214 public NotificationContentView getPublicLayout() {
215 return mPublicLayout;
216 }
217
Selim Cinekcab4a602014-09-03 14:47:57 +0200218 public void setIconAnimationRunning(boolean running) {
219 setIconAnimationRunning(running, mPublicLayout);
220 setIconAnimationRunning(running, mPrivateLayout);
Selim Cinek5a175d92015-11-23 18:01:33 -0800221 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700222 setIconAnimationRunningForChild(running, mChildrenContainer.getHeaderView());
Selim Cinek5a175d92015-11-23 18:01:33 -0800223 List<ExpandableNotificationRow> notificationChildren =
224 mChildrenContainer.getNotificationChildren();
225 for (int i = 0; i < notificationChildren.size(); i++) {
226 ExpandableNotificationRow child = notificationChildren.get(i);
227 child.setIconAnimationRunning(running);
228 }
229 }
230 mIconAnimationRunning = running;
Selim Cinekcab4a602014-09-03 14:47:57 +0200231 }
232
233 private void setIconAnimationRunning(boolean running, NotificationContentView layout) {
234 if (layout != null) {
235 View contractedChild = layout.getContractedChild();
236 View expandedChild = layout.getExpandedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -0700237 View headsUpChild = layout.getHeadsUpChild();
Selim Cinekcab4a602014-09-03 14:47:57 +0200238 setIconAnimationRunningForChild(running, contractedChild);
239 setIconAnimationRunningForChild(running, expandedChild);
Selim Cinek8d490d42015-04-10 00:05:50 -0700240 setIconAnimationRunningForChild(running, headsUpChild);
Selim Cinekcab4a602014-09-03 14:47:57 +0200241 }
242 }
243
244 private void setIconAnimationRunningForChild(boolean running, View child) {
245 if (child != null) {
246 ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon);
247 setIconRunning(icon, running);
248 ImageView rightIcon = (ImageView) child.findViewById(
249 com.android.internal.R.id.right_icon);
250 setIconRunning(rightIcon, running);
251 }
252 }
253
254 private void setIconRunning(ImageView imageView, boolean running) {
255 if (imageView != null) {
256 Drawable drawable = imageView.getDrawable();
257 if (drawable instanceof AnimationDrawable) {
258 AnimationDrawable animationDrawable = (AnimationDrawable) drawable;
259 if (running) {
260 animationDrawable.start();
261 } else {
262 animationDrawable.stop();
263 }
264 } else if (drawable instanceof AnimatedVectorDrawable) {
265 AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable;
266 if (running) {
267 animationDrawable.start();
268 } else {
269 animationDrawable.stop();
270 }
271 }
272 }
273 }
274
Selim Cinekda42d652015-12-04 15:51:16 -0800275 public void onNotificationUpdated(NotificationData.Entry entry) {
276 mEntry = entry;
277 mStatusBarNotification = entry.notification;
Adrian Roosb88b1a12015-12-09 18:51:05 -0800278 mPrivateLayout.onNotificationUpdated(entry);
279 mPublicLayout.onNotificationUpdated(entry);
Selim Cinek757d8792016-01-28 16:21:08 -0800280 mShowingPublicInitialized = false;
Selim Cinek4bb59342016-04-08 19:29:35 -0700281 updateNotificationColor();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800282 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700283 mChildrenContainer.recreateNotificationHeader(mExpandClickListener, mEntry.notification);
Selim Cinekc897bd32016-03-18 17:32:31 -0700284 mChildrenContainer.onNotificationUpdated();
Selim Cinek8fc93c92015-11-23 17:48:07 -0800285 }
Selim Cinek5a175d92015-11-23 18:01:33 -0800286 if (mIconAnimationRunning) {
287 setIconAnimationRunning(true);
288 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800289 if (mNotificationParent != null) {
290 mNotificationParent.updateChildrenHeaderAppearance();
291 }
Selim Cinek263398f2015-10-21 17:40:23 -0700292 onChildrenCountChanged();
Selim Cinek624c02db2015-12-14 21:00:02 -0800293 // The public layouts expand button is always visible
294 mPublicLayout.updateExpandButtons(true);
Selim Cinekda42d652015-12-04 15:51:16 -0800295 updateLimits();
296 }
297
298 private void updateLimits() {
Selim Cineka1744872016-03-11 15:36:06 -0800299 updateLimitsForView(mPrivateLayout);
300 updateLimitsForView(mPublicLayout);
301 }
302
303 private void updateLimitsForView(NotificationContentView layout) {
304 boolean customView = layout.getContractedChild().getId()
Selim Cinekda42d652015-12-04 15:51:16 -0800305 != com.android.internal.R.id.status_bar_latest_event_content;
306 boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N;
307 int minHeight = customView && beforeN && !mIsSummaryWithChildren ?
308 mNotificationMinHeightLegacy : mNotificationMinHeight;
Selim Cineka1744872016-03-11 15:36:06 -0800309 boolean headsUpCustom = layout.getHeadsUpChild() != null &&
310 layout.getHeadsUpChild().getId()
311 != com.android.internal.R.id.status_bar_latest_event_content;
Selim Cinek77019c72015-12-09 10:18:02 -0800312 int headsUpheight = headsUpCustom && beforeN ? mMaxHeadsUpHeightLegacy
313 : mMaxHeadsUpHeight;
Selim Cineka1744872016-03-11 15:36:06 -0800314 layout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200315 }
316
317 public StatusBarNotification getStatusBarNotification() {
318 return mStatusBarNotification;
319 }
320
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700321 public boolean isHeadsUp() {
322 return mIsHeadsUp;
323 }
324
Selim Cinek1a521f32014-11-03 17:39:29 +0100325 public void setHeadsUp(boolean isHeadsUp) {
Selim Cinekc80fdb12015-04-13 15:09:08 -0700326 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek1a521f32014-11-03 17:39:29 +0100327 mIsHeadsUp = isHeadsUp;
Selim Cinek8d490d42015-04-10 00:05:50 -0700328 mPrivateLayout.setHeadsUp(isHeadsUp);
Selim Cinekb41b2f62016-04-26 14:03:29 -0700329 if (mIsSummaryWithChildren) {
330 // The overflow might change since we allow more lines as HUN.
331 mChildrenContainer.updateGroupOverflow();
332 }
Selim Cinekc80fdb12015-04-13 15:09:08 -0700333 if (intrinsicBefore != getIntrinsicHeight()) {
334 notifyHeightChanged(false /* needsAnimation */);
335 }
Selim Cinek1a521f32014-11-03 17:39:29 +0100336 }
337
Selim Cinekb5605e52015-02-20 18:21:41 +0100338 public void setGroupManager(NotificationGroupManager groupManager) {
339 mGroupManager = groupManager;
Selim Cinek83bc7832015-10-22 13:26:54 -0700340 mPrivateLayout.setGroupManager(groupManager);
Selim Cinekb5605e52015-02-20 18:21:41 +0100341 }
342
Adrian Roosb88b1a12015-12-09 18:51:05 -0800343 public void setRemoteInputController(RemoteInputController r) {
344 mPrivateLayout.setRemoteInputController(r);
345 }
346
Mady Mellor3fd273e2016-03-15 21:08:14 -0700347 public void setAppName(String appName) {
348 mAppName = appName;
349 if (mSettingsIconRow != null) {
350 mSettingsIconRow.setAppName(mAppName);
351 }
352 }
353
Selim Cinekb5605e52015-02-20 18:21:41 +0100354 public void addChildNotification(ExpandableNotificationRow row) {
355 addChildNotification(row, -1);
356 }
357
358 /**
359 * Add a child notification to this view.
360 *
361 * @param row the row to add
362 * @param childIndex the index to add it at, if -1 it will be added at the end
363 */
364 public void addChildNotification(ExpandableNotificationRow row, int childIndex) {
365 if (mChildrenContainer == null) {
366 mChildrenContainerStub.inflate();
367 }
368 mChildrenContainer.addNotification(row, childIndex);
Selim Cinek263398f2015-10-21 17:40:23 -0700369 onChildrenCountChanged();
370 row.setIsChildInGroup(true, this);
Selim Cinekb5605e52015-02-20 18:21:41 +0100371 }
372
373 public void removeChildNotification(ExpandableNotificationRow row) {
374 if (mChildrenContainer != null) {
375 mChildrenContainer.removeNotification(row);
376 }
Selim Cinek263398f2015-10-21 17:40:23 -0700377 onChildrenCountChanged();
378 row.setIsChildInGroup(false, null);
379 }
380
381 public boolean isChildInGroup() {
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700382 return mNotificationParent != null;
Selim Cinek263398f2015-10-21 17:40:23 -0700383 }
384
Selim Cinek388df6d2015-10-22 13:25:11 -0700385 public ExpandableNotificationRow getNotificationParent() {
386 return mNotificationParent;
387 }
388
Selim Cinek263398f2015-10-21 17:40:23 -0700389 /**
390 * @param isChildInGroup Is this notification now in a group
391 * @param parent the new parent notification
392 */
Selim Cineka6c6bfb2015-10-29 16:27:08 -0700393 public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {;
394 boolean childInGroup = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup;
395 mNotificationParent = childInGroup ? parent : null;
396 mPrivateLayout.setIsChildInGroup(childInGroup);
Mady Mellorc7d65b42016-05-04 11:44:57 -0400397 resetBackgroundAlpha();
Mady Mellorb0a82462016-04-30 17:31:02 -0700398 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -0700399 updateClickAndFocus();
Mady Mellorb0a82462016-04-30 17:31:02 -0700400 if (mNotificationParent != null) {
401 mNotificationParent.updateBackgroundForGroupState();
402 }
Selim Cinek34d93b02015-10-22 12:30:38 -0700403 }
404
405 @Override
Selim Cinek72109472016-01-15 16:33:22 -0800406 public boolean onTouchEvent(MotionEvent event) {
407 if (event.getActionMasked() != MotionEvent.ACTION_DOWN
408 || !isChildInGroup() || isGroupExpanded()) {
409 return super.onTouchEvent(event);
410 } else {
411 return false;
412 }
413 }
414
415 @Override
Mady Mellorf0625802016-02-11 18:03:48 -0800416 protected boolean handleSlideBack() {
417 if (mSettingsIconRow != null && mSettingsIconRow.isVisible()) {
418 animateTranslateNotification(0 /* targetLeft */);
419 return true;
420 }
421 return false;
422 }
423
424 @Override
Selim Cinek34d93b02015-10-22 12:30:38 -0700425 protected boolean shouldHideBackground() {
426 return super.shouldHideBackground() || mShowNoBackground;
Selim Cinek263398f2015-10-21 17:40:23 -0700427 }
428
429 @Override
430 public boolean isSummaryWithChildren() {
431 return mIsSummaryWithChildren;
Selim Cinekb5605e52015-02-20 18:21:41 +0100432 }
433
434 @Override
435 public boolean areChildrenExpanded() {
436 return mChildrenExpanded;
437 }
438
439 public List<ExpandableNotificationRow> getNotificationChildren() {
440 return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren();
441 }
442
Selim Cinekeef84282015-10-30 16:28:00 -0700443 public int getNumberOfNotificationChildren() {
444 if (mChildrenContainer == null) {
445 return 0;
446 }
447 return mChildrenContainer.getNotificationChildren().size();
448 }
449
Selim Cinekb5605e52015-02-20 18:21:41 +0100450 /**
451 * Apply the order given in the list to the children.
452 *
453 * @param childOrder the new list order
454 * @return whether the list order has changed
455 */
456 public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder) {
457 return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder);
458 }
459
460 public void getChildrenStates(StackScrollState resultState) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700461 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100462 StackViewState parentState = resultState.getViewStateForView(this);
463 mChildrenContainer.getState(resultState, parentState);
464 }
465 }
466
467 public void applyChildrenState(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700468 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100469 mChildrenContainer.applyState(state);
470 }
471 }
472
473 public void prepareExpansionChanged(StackScrollState state) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700474 if (mIsSummaryWithChildren) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100475 mChildrenContainer.prepareExpansionChanged(state);
476 }
477 }
478
479 public void startChildAnimation(StackScrollState finalState,
Selim Cinek99695592016-01-12 17:51:35 -0800480 StackStateAnimator stateAnimator, long delay, long duration) {
Selim Cinek83bc7832015-10-22 13:26:54 -0700481 if (mIsSummaryWithChildren) {
Selim Cinek99695592016-01-12 17:51:35 -0800482 mChildrenContainer.startAnimationToState(finalState, stateAnimator, delay,
Selim Cinekb5605e52015-02-20 18:21:41 +0100483 duration);
484 }
485 }
486
487 public ExpandableNotificationRow getViewAtPosition(float y) {
Selim Cinek43d30f02016-03-04 10:51:32 -0800488 if (!mIsSummaryWithChildren || !mChildrenExpanded) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100489 return this;
490 } else {
491 ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y);
492 return view == null ? this : view;
493 }
494 }
495
Selim Cinekab29aeb2015-02-20 18:18:32 +0100496 public NotificationGuts getGuts() {
497 return mGuts;
498 }
499
Selim Cinek684a4422015-04-15 16:18:39 -0700500 /**
501 * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this
502 * the notification will be rendered on top of the screen.
503 *
504 * @param pinned whether it is pinned
505 */
506 public void setPinned(boolean pinned) {
Selim Cinekdef35a82016-05-03 15:52:51 -0700507 int intrinsicHeight = getIntrinsicHeight();
Selim Cinek684a4422015-04-15 16:18:39 -0700508 mIsPinned = pinned;
Selim Cinekdef35a82016-05-03 15:52:51 -0700509 if (intrinsicHeight != getIntrinsicHeight()) {
510 notifyHeightChanged(false);
511 }
Selim Cinek31aada42015-12-18 17:51:15 -0800512 if (pinned) {
513 setIconAnimationRunning(true);
514 mExpandedWhenPinned = false;
515 } else if (mExpandedWhenPinned) {
516 setUserExpanded(true);
517 }
Selim Cinek98713a42015-09-21 15:47:20 +0200518 setChronometerRunning(mLastChronometerRunning);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700519 }
520
Selim Cinek684a4422015-04-15 16:18:39 -0700521 public boolean isPinned() {
522 return mIsPinned;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700523 }
524
Selim Cinek31aada42015-12-18 17:51:15 -0800525 /**
526 * @param atLeastMinHeight should the value returned be at least the minimum height.
527 * Used to avoid cyclic calls
528 * @return the height of the heads up notification when pinned
529 */
530 public int getPinnedHeadsUpHeight(boolean atLeastMinHeight) {
Selim Cinek77019c72015-12-09 10:18:02 -0800531 if (mIsSummaryWithChildren) {
532 return mChildrenContainer.getIntrinsicHeight();
533 }
Selim Cinek31aada42015-12-18 17:51:15 -0800534 if(mExpandedWhenPinned) {
535 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
536 } else if (atLeastMinHeight) {
Selim Cinek567e8452016-03-24 10:54:56 -0700537 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek31aada42015-12-18 17:51:15 -0800538 } else {
539 return mHeadsUpHeight;
540 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700541 }
542
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700543 /**
544 * Mark whether this notification was just clicked, i.e. the user has just clicked this
545 * notification in this frame.
546 */
547 public void setJustClicked(boolean justClicked) {
548 mJustClicked = justClicked;
549 }
550
551 /**
552 * @return true if this notification has been clicked in this frame, false otherwise
553 */
554 public boolean wasJustClicked() {
555 return mJustClicked;
556 }
557
Selim Cinek98713a42015-09-21 15:47:20 +0200558 public void setChronometerRunning(boolean running) {
559 mLastChronometerRunning = running;
560 setChronometerRunning(running, mPrivateLayout);
561 setChronometerRunning(running, mPublicLayout);
562 if (mChildrenContainer != null) {
563 List<ExpandableNotificationRow> notificationChildren =
564 mChildrenContainer.getNotificationChildren();
565 for (int i = 0; i < notificationChildren.size(); i++) {
566 ExpandableNotificationRow child = notificationChildren.get(i);
567 child.setChronometerRunning(running);
568 }
569 }
570 }
571
572 private void setChronometerRunning(boolean running, NotificationContentView layout) {
573 if (layout != null) {
574 running = running || isPinned();
575 View contractedChild = layout.getContractedChild();
576 View expandedChild = layout.getExpandedChild();
577 View headsUpChild = layout.getHeadsUpChild();
578 setChronometerRunningForChild(running, contractedChild);
579 setChronometerRunningForChild(running, expandedChild);
580 setChronometerRunningForChild(running, headsUpChild);
581 }
582 }
583
584 private void setChronometerRunningForChild(boolean running, View child) {
585 if (child != null) {
586 View chronometer = child.findViewById(com.android.internal.R.id.chronometer);
587 if (chronometer instanceof Chronometer) {
588 ((Chronometer) chronometer).setStarted(running);
589 }
590 }
591 }
592
Selim Cinekea4bef72015-12-02 15:51:10 -0800593 public NotificationHeaderView getNotificationHeader() {
Mady Mellorb0a82462016-04-30 17:31:02 -0700594 if (mIsSummaryWithChildren) {
595 return mChildrenContainer.getHeaderView();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700596 }
Selim Cinekea4bef72015-12-02 15:51:10 -0800597 return mPrivateLayout.getNotificationHeader();
Selim Cinek8d6440d2015-10-22 13:00:05 -0700598 }
599
Selim Cinek34eda5e2016-02-18 17:10:43 -0800600 private NotificationHeaderView getVisibleNotificationHeader() {
Mady Mellorb0a82462016-04-30 17:31:02 -0700601 if (mIsSummaryWithChildren) {
602 return mChildrenContainer.getHeaderView();
Selim Cinek34eda5e2016-02-18 17:10:43 -0800603 }
604 return getShowingLayout().getVisibleNotificationHeader();
605 }
606
Selim Cinek570981d2015-12-01 11:37:01 -0800607 public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) {
608 mOnExpandClickListener = onExpandClickListener;
609 }
610
Selim Cinekddf1b392016-05-27 16:33:10 -0700611 @Override
612 public void setOnClickListener(@Nullable OnClickListener l) {
613 super.setOnClickListener(l);
614 mOnClickListener = l;
615 updateClickAndFocus();
616 }
617
618 private void updateClickAndFocus() {
619 boolean normalChild = !isChildInGroup() || isGroupExpanded();
620 boolean clickable = mOnClickListener != null && normalChild;
621 if (isFocusable() != normalChild) {
622 setFocusable(normalChild);
623 }
624 if (isClickable() != clickable) {
625 setClickable(clickable);
626 }
627 }
628
Selim Cinek31aada42015-12-18 17:51:15 -0800629 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
630 mHeadsUpManager = headsUpManager;
631 }
632
Selim Cinek01af3342016-02-09 19:25:31 -0800633 public void reInflateViews() {
634 initDimens();
635 if (mIsSummaryWithChildren) {
Selim Cinek01af3342016-02-09 19:25:31 -0800636 if (mChildrenContainer != null) {
Mady Mellorb0a82462016-04-30 17:31:02 -0700637 mChildrenContainer.reInflateViews(mExpandClickListener, mEntry.notification);
Selim Cinek01af3342016-02-09 19:25:31 -0800638 }
639 }
640 if (mGuts != null) {
641 View oldGuts = mGuts;
642 int index = indexOfChild(oldGuts);
643 removeView(oldGuts);
644 mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate(
645 R.layout.notification_guts, this, false);
646 mGuts.setVisibility(oldGuts.getVisibility());
647 addView(mGuts, index);
648 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800649 if (mSettingsIconRow != null) {
650 View oldSettings = mSettingsIconRow;
651 int settingsIndex = indexOfChild(oldSettings);
652 removeView(oldSettings);
653 mSettingsIconRow = (NotificationSettingsIconRow) LayoutInflater.from(mContext).inflate(
654 R.layout.notification_settings_icon_row, this, false);
655 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
Mady Mellor3fd273e2016-03-15 21:08:14 -0700656 mSettingsIconRow.setAppName(mAppName);
Mady Mellor4b80b102016-01-22 08:03:58 -0800657 mSettingsIconRow.setVisibility(oldSettings.getVisibility());
658 addView(mSettingsIconRow, settingsIndex);
659
660 }
Selim Cinekde33a4a2016-02-11 16:43:41 -0800661 mPrivateLayout.reInflateViews();
662 mPublicLayout.reInflateViews();
Selim Cinek01af3342016-02-09 19:25:31 -0800663 }
664
Selim Cinekc3179332016-03-04 14:44:56 -0800665 public void setContentBackground(int customBackgroundColor, boolean animate,
666 NotificationContentView notificationContentView) {
667 if (getShowingLayout() == notificationContentView) {
668 setTintColor(customBackgroundColor, animate);
669 }
670 }
671
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700672 public void closeRemoteInput() {
673 mPrivateLayout.closeRemoteInput();
674 mPublicLayout.closeRemoteInput();
675 }
676
Selim Cinekc897bd32016-03-18 17:32:31 -0700677 /**
678 * Set by how much the single line view should be indented.
679 */
680 public void setSingleLineWidthIndention(int indention) {
681 mPrivateLayout.setSingleLineWidthIndention(indention);
682 }
683
684 public int getNotificationColor() {
Selim Cinek4bb59342016-04-08 19:29:35 -0700685 return mNotificationColor;
686 }
687
688 private void updateNotificationColor() {
689 mNotificationColor = NotificationColorUtil.resolveContrastColor(mContext,
690 getStatusBarNotification().getNotification().color);
Selim Cinekc897bd32016-03-18 17:32:31 -0700691 }
692
693 public HybridNotificationView getSingleLineView() {
694 return mPrivateLayout.getSingleLineView();
695 }
696
Selim Cinekf07d0622016-03-21 19:52:52 -0700697 public boolean isOnKeyguard() {
698 return mOnKeyguard;
699 }
700
Selim Cinekc1e389d2016-04-07 11:02:57 -0700701 public void removeAllChildren() {
702 List<ExpandableNotificationRow> notificationChildren
703 = mChildrenContainer.getNotificationChildren();
704 ArrayList<ExpandableNotificationRow> clonedList = new ArrayList<>(notificationChildren);
705 for (int i = 0; i < clonedList.size(); i++) {
706 ExpandableNotificationRow row = clonedList.get(i);
Selim Cinek3f19f602016-05-02 18:01:56 -0700707 if (row.keepInParent()) {
708 continue;
709 }
Selim Cinekc1e389d2016-04-07 11:02:57 -0700710 mChildrenContainer.removeNotification(row);
Selim Cinekc1e389d2016-04-07 11:02:57 -0700711 row.setIsChildInGroup(false, null);
712 }
713 onChildrenCountChanged();
714 }
715
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700716 public void setForceUnlocked(boolean forceUnlocked) {
717 mForceUnlocked = forceUnlocked;
718 if (mIsSummaryWithChildren) {
719 List<ExpandableNotificationRow> notificationChildren = getNotificationChildren();
720 for (ExpandableNotificationRow child : notificationChildren) {
721 child.setForceUnlocked(forceUnlocked);
722 }
723 }
724 }
725
Selim Cineke9bad242016-06-15 11:46:37 -0700726 public void setDismissed(boolean dismissed, boolean fromAccessibility) {
Selim Cinek3f19f602016-05-02 18:01:56 -0700727 mDismissed = dismissed;
Selim Cineke9bad242016-06-15 11:46:37 -0700728 mGroupParentWhenDismissed = mNotificationParent;
729 mRefocusOnDismiss = fromAccessibility;
730 mChildAfterViewWhenDismissed = null;
731 if (isChildInGroup()) {
732 List<ExpandableNotificationRow> notificationChildren =
733 mNotificationParent.getNotificationChildren();
734 int i = notificationChildren.indexOf(this);
735 if (i != -1 && i < notificationChildren.size() - 1) {
736 mChildAfterViewWhenDismissed = notificationChildren.get(i + 1);
737 }
738 }
Selim Cinek3f19f602016-05-02 18:01:56 -0700739 }
740
741 public boolean isDismissed() {
742 return mDismissed;
743 }
744
745 public boolean keepInParent() {
746 return mKeepInParent;
747 }
748
749 public void setKeepInParent(boolean keepInParent) {
750 mKeepInParent = keepInParent;
751 }
752
753 public boolean isRemoved() {
754 return mRemoved;
755 }
756
Adrian Roosd009ab12016-05-20 17:58:53 -0700757 public void setRemoved() {
758 mRemoved = true;
759
760 mPrivateLayout.setRemoved();
Selim Cinek3f19f602016-05-02 18:01:56 -0700761 }
762
Selim Cinekd1395642016-04-28 12:22:42 -0700763 public NotificationChildrenContainer getChildrenContainer() {
764 return mChildrenContainer;
765 }
766
Selim Cinek73cf02a2016-06-17 13:08:00 -0700767 public void setHeadsupDisappearRunning(boolean running) {
768 mHeadsupDisappearRunning = running;
769 mPrivateLayout.setHeadsupDisappearRunning(running);
770 }
771
Selim Cineke9bad242016-06-15 11:46:37 -0700772 public View getChildAfterViewWhenDismissed() {
773 return mChildAfterViewWhenDismissed;
774 }
775
776 public View getGroupParentWhenDismissed() {
777 return mGroupParentWhenDismissed;
778 }
779
Selim Cinek9e624e72016-07-20 13:46:49 -0700780 public void performDismiss() {
781 mVetoButton.performClick();
782 }
783
784 public void setOnDismissListener(OnClickListener listener) {
785 mVetoButton.setOnClickListener(listener);
786 }
787
Chris Wren78403d72014-07-28 10:23:24 +0100788 public interface ExpansionLogger {
789 public void logNotificationExpansion(String key, boolean userAction, boolean expanded);
790 }
Selim Cinek1685e632014-04-08 02:27:49 +0200791
Chris Wren51c75102013-07-16 20:49:17 -0400792 public ExpandableNotificationRow(Context context, AttributeSet attrs) {
793 super(context, attrs);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700794 mFalsingManager = FalsingManager.getInstance(context);
Selim Cinek01af3342016-02-09 19:25:31 -0800795 initDimens();
796 }
797
798 private void initDimens() {
Selim Cinekf619ffc2016-02-17 14:53:05 -0800799 mNotificationMinHeightLegacy = getFontScaledHeight(R.dimen.notification_min_height_legacy);
800 mNotificationMinHeight = getFontScaledHeight(R.dimen.notification_min_height);
801 mNotificationMaxHeight = getFontScaledHeight(R.dimen.notification_max_height);
802 mMaxHeadsUpHeightLegacy = getFontScaledHeight(
Selim Cinek77019c72015-12-09 10:18:02 -0800803 R.dimen.notification_max_heads_up_height_legacy);
Selim Cinekf619ffc2016-02-17 14:53:05 -0800804 mMaxHeadsUpHeight = getFontScaledHeight(R.dimen.notification_max_heads_up_height);
Mady Mellorb0a82462016-04-30 17:31:02 -0700805 mIncreasedPaddingBetweenElements = getResources()
806 .getDimensionPixelSize(R.dimen.notification_divider_height_increased);
Selim Cinekf619ffc2016-02-17 14:53:05 -0800807 }
808
809 /**
810 * @param dimenId the dimen to look up
811 * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp
812 */
813 private int getFontScaledHeight(int dimenId) {
814 int dimensionPixelSize = getResources().getDimensionPixelSize(dimenId);
815 float factor = Math.max(1.0f, getResources().getDisplayMetrics().scaledDensity /
816 getResources().getDisplayMetrics().density);
817 return (int) (dimensionPixelSize * factor);
Chris Wren51c75102013-07-16 20:49:17 -0400818 }
819
Christoph Studera7fe6312014-06-27 19:32:44 +0200820 /**
821 * Resets this view so it can be re-used for an updated notification.
822 */
Christoph Studer22f2ee52014-07-29 22:57:21 +0200823 @Override
Christoph Studera7fe6312014-06-27 19:32:44 +0200824 public void reset() {
Christoph Studer22f2ee52014-07-29 22:57:21 +0200825 super.reset();
Chris Wren78403d72014-07-28 10:23:24 +0100826 final boolean wasExpanded = isExpanded();
Christoph Studera7fe6312014-06-27 19:32:44 +0200827 mExpandable = false;
828 mHasUserChangedExpansion = false;
829 mUserLocked = false;
830 mShowingPublic = false;
Jorim Jaggiae441282014-08-01 02:45:18 +0200831 mSensitive = false;
832 mShowingPublicInitialized = false;
Christoph Studera7fe6312014-06-27 19:32:44 +0200833 mIsSystemExpanded = false;
Selim Cinek83bc7832015-10-22 13:26:54 -0700834 mOnKeyguard = false;
Selim Cinek51d94912016-03-02 15:34:28 -0800835 mPublicLayout.reset();
836 mPrivateLayout.reset();
Selim Cinek31094df2014-08-14 19:28:15 +0200837 resetHeight();
Mady Mellor4b80b102016-01-22 08:03:58 -0800838 resetTranslation();
Selim Cinek31094df2014-08-14 19:28:15 +0200839 logExpansionEvent(false, wasExpanded);
840 }
841
842 public void resetHeight() {
Christoph Studera7fe6312014-06-27 19:32:44 +0200843 mMaxExpandHeight = 0;
Selim Cinek8d490d42015-04-10 00:05:50 -0700844 mHeadsUpHeight = 0;
Selim Cinek31094df2014-08-14 19:28:15 +0200845 onHeightReset();
Selim Cinek6e28a672014-09-05 14:43:28 +0200846 requestLayout();
Christoph Studera7fe6312014-06-27 19:32:44 +0200847 }
848
Jorim Jaggi251957d2014-04-09 04:24:09 +0200849 @Override
850 protected void onFinishInflate() {
851 super.onFinishInflate();
Jorim Jaggibe565df2014-04-28 17:51:23 +0200852 mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800853 mPublicLayout.setContainingNotification(this);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200854 mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800855 mPrivateLayout.setExpandClickListener(mExpandClickListener);
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800856 mPrivateLayout.setContainingNotification(this);
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800857 mPublicLayout.setExpandClickListener(mExpandClickListener);
Mady Mellor4b80b102016-01-22 08:03:58 -0800858 mSettingsIconRowStub = (ViewStub) findViewById(R.id.settings_icon_row_stub);
859 mSettingsIconRowStub.setOnInflateListener(new ViewStub.OnInflateListener() {
860 @Override
861 public void onInflate(ViewStub stub, View inflated) {
862 mSettingsIconRow = (NotificationSettingsIconRow) inflated;
863 mSettingsIconRow.setNotificationRowParent(ExpandableNotificationRow.this);
Mady Mellor3fd273e2016-03-15 21:08:14 -0700864 mSettingsIconRow.setAppName(mAppName);
Mady Mellor4b80b102016-01-22 08:03:58 -0800865 }
866 });
Selim Cinekab29aeb2015-02-20 18:18:32 +0100867 mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub);
868 mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() {
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200869 @Override
870 public void onInflate(ViewStub stub, View inflated) {
871 mGuts = (NotificationGuts) inflated;
872 mGuts.setClipTopAmount(getClipTopAmount());
873 mGuts.setActualHeight(getActualHeight());
Selim Cinekab29aeb2015-02-20 18:18:32 +0100874 mGutsStub = null;
Jorim Jaggib1cd3c12014-09-08 19:55:17 +0200875 }
876 });
Selim Cinekb5605e52015-02-20 18:21:41 +0100877 mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub);
878 mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() {
879
880 @Override
881 public void onInflate(ViewStub stub, View inflated) {
882 mChildrenContainer = (NotificationChildrenContainer) inflated;
Selim Cinek388df6d2015-10-22 13:25:11 -0700883 mChildrenContainer.setNotificationParent(ExpandableNotificationRow.this);
Selim Cinekc897bd32016-03-18 17:32:31 -0700884 mChildrenContainer.onNotificationUpdated();
Mady Mellor4b80b102016-01-22 08:03:58 -0800885 mTranslateableViews.add(mChildrenContainer);
Selim Cinekb5605e52015-02-20 18:21:41 +0100886 }
887 });
Selim Cinek863834b2014-05-20 04:20:25 +0200888 mVetoButton = findViewById(R.id.veto);
Selim Cinek9e624e72016-07-20 13:46:49 -0700889 mVetoButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
890 mVetoButton.setContentDescription(mContext.getString(
891 R.string.accessibility_remove_notification));
Mady Mellor4b80b102016-01-22 08:03:58 -0800892
893 // Add the views that we translate to reveal the gear
894 mTranslateableViews = new ArrayList<View>();
895 for (int i = 0; i < getChildCount(); i++) {
896 mTranslateableViews.add(getChildAt(i));
897 }
898 // Remove views that don't translate
899 mTranslateableViews.remove(mVetoButton);
900 mTranslateableViews.remove(mSettingsIconRowStub);
901 mTranslateableViews.remove(mChildrenContainerStub);
902 mTranslateableViews.remove(mGutsStub);
903 }
904
Selim Cinek9e624e72016-07-20 13:46:49 -0700905 public View getVetoButton() {
906 return mVetoButton;
907 }
908
Mady Mellor4b80b102016-01-22 08:03:58 -0800909 public void resetTranslation() {
910 if (mTranslateableViews != null) {
911 for (int i = 0; i < mTranslateableViews.size(); i++) {
912 mTranslateableViews.get(i).setTranslationX(0);
913 }
Mady Mellor4b80b102016-01-22 08:03:58 -0800914 }
Mady Mellorb0a82462016-04-30 17:31:02 -0700915 invalidateOutline();
Mady Mellor4b80b102016-01-22 08:03:58 -0800916 if (mSettingsIconRow != null) {
917 mSettingsIconRow.resetState();
918 }
919 }
920
921 public void animateTranslateNotification(final float leftTarget) {
922 if (mTranslateAnim != null) {
923 mTranslateAnim.cancel();
924 }
Mady Mellorb0a82462016-04-30 17:31:02 -0700925 mTranslateAnim = getTranslateViewAnimator(leftTarget, null /* updateListener */);
Mady Mellor34958fa2016-02-23 09:52:17 -0800926 if (mTranslateAnim != null) {
927 mTranslateAnim.start();
928 }
929 }
930
931 @Override
932 public void setTranslation(float translationX) {
933 if (areGutsExposed()) {
934 // Don't translate if guts are showing.
935 return;
936 }
937 // Translate the group of views
938 for (int i = 0; i < mTranslateableViews.size(); i++) {
939 if (mTranslateableViews.get(i) != null) {
940 mTranslateableViews.get(i).setTranslationX(translationX);
941 }
942 }
Mady Mellorb0a82462016-04-30 17:31:02 -0700943 invalidateOutline();
Mady Mellor34958fa2016-02-23 09:52:17 -0800944 if (mSettingsIconRow != null) {
945 mSettingsIconRow.updateSettingsIcons(translationX, getMeasuredWidth());
946 }
947 }
948
949 @Override
950 public float getTranslation() {
951 if (mTranslateableViews != null && mTranslateableViews.size() > 0) {
952 // All of the views in the list should have same translation, just use first one.
953 return mTranslateableViews.get(0).getTranslationX();
954 }
955 return 0;
956 }
957
958 public Animator getTranslateViewAnimator(final float leftTarget,
959 AnimatorUpdateListener listener) {
Mady Mellor723f1f92016-03-13 15:54:06 -0700960 if (mTranslateAnim != null) {
961 mTranslateAnim.cancel();
962 }
Mady Mellor34958fa2016-02-23 09:52:17 -0800963 if (areGutsExposed()) {
964 // No translation if guts are exposed.
965 return null;
966 }
Mady Mellorb0a82462016-04-30 17:31:02 -0700967 final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(this, TRANSLATE_CONTENT,
968 leftTarget);
969 if (listener != null) {
970 translateAnim.addUpdateListener(listener);
Mady Mellor4b80b102016-01-22 08:03:58 -0800971 }
Mady Mellorb0a82462016-04-30 17:31:02 -0700972 translateAnim.addListener(new AnimatorListenerAdapter() {
973 boolean cancelled = false;
974
975 @Override
976 public void onAnimationCancel(Animator anim) {
977 cancelled = true;
978 }
979
980 @Override
981 public void onAnimationEnd(Animator anim) {
982 if (!cancelled && mSettingsIconRow != null && leftTarget == 0) {
983 mSettingsIconRow.resetState();
984 mTranslateAnim = null;
985 }
986 }
987 });
988 mTranslateAnim = translateAnim;
989 return translateAnim;
Mady Mellor4b80b102016-01-22 08:03:58 -0800990 }
991
992 public float getSpaceForGear() {
993 if (mSettingsIconRow != null) {
994 return mSettingsIconRow.getSpaceForGear();
995 }
996 return 0;
997 }
998
999 public NotificationSettingsIconRow getSettingsRow() {
1000 if (mSettingsIconRow == null) {
1001 mSettingsIconRowStub.inflate();
1002 }
1003 return mSettingsIconRow;
1004 }
1005
Selim Cinekab29aeb2015-02-20 18:18:32 +01001006 public void inflateGuts() {
1007 if (mGuts == null) {
1008 mGutsStub.inflate();
1009 }
1010 }
1011
Selim Cinekda42d652015-12-04 15:51:16 -08001012 private void updateChildrenVisibility() {
Selim Cinekd84a5932015-12-15 11:45:36 -08001013 mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE
1014 : INVISIBLE);
Selim Cinekef5127e2015-12-21 16:55:58 -08001015 if (mChildrenContainer != null) {
1016 mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE
1017 : INVISIBLE);
Mady Mellorb0a82462016-04-30 17:31:02 -07001018 mChildrenContainer.updateHeaderVisibility(!mShowingPublic && mIsSummaryWithChildren
1019 ? VISIBLE
Selim Cinekef5127e2015-12-21 16:55:58 -08001020 : INVISIBLE);
1021 }
Selim Cinekda42d652015-12-04 15:51:16 -08001022 // The limits might have changed if the view suddenly became a group or vice versa
1023 updateLimits();
Selim Cinekb5605e52015-02-20 18:21:41 +01001024 }
1025
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001026 @Override
Alan Viverettea54956a2015-01-07 16:05:02 -08001027 public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
1028 if (super.onRequestSendAccessibilityEventInternal(child, event)) {
Jorim Jaggife40f7d2014-04-28 15:20:04 +02001029 // Add a record for the entire layout since its content is somehow small.
1030 // The event comes from a leaf view that is interacted with.
1031 AccessibilityEvent record = AccessibilityEvent.obtain();
1032 onInitializeAccessibilityEvent(record);
1033 dispatchPopulateAccessibilityEvent(record);
1034 event.appendRecord(record);
1035 return true;
1036 }
1037 return false;
Jorim Jaggic5dc0d02014-04-15 15:42:55 +02001038 }
Chris Wren51c75102013-07-16 20:49:17 -04001039
John Spurlocke15452b2014-08-21 09:44:39 -04001040 @Override
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001041 public void setDark(boolean dark, boolean fade, long delay) {
1042 super.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -04001043 final NotificationContentView showing = getShowingLayout();
1044 if (showing != null) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001045 showing.setDark(dark, fade, delay);
John Spurlocke15452b2014-08-21 09:44:39 -04001046 }
Selim Cinek9c7712d2015-12-08 19:19:48 -08001047 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001048 mChildrenContainer.setDark(dark, fade, delay);
Selim Cinek9c7712d2015-12-08 19:19:48 -08001049 }
John Spurlocke15452b2014-08-21 09:44:39 -04001050 }
1051
Chris Wren51c75102013-07-16 20:49:17 -04001052 public boolean isExpandable() {
Selim Cinek388df6d2015-10-22 13:25:11 -07001053 if (mIsSummaryWithChildren && !mShowingPublic) {
1054 return !mChildrenExpanded;
1055 }
Chris Wren51c75102013-07-16 20:49:17 -04001056 return mExpandable;
1057 }
1058
1059 public void setExpandable(boolean expandable) {
1060 mExpandable = expandable;
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001061 mPrivateLayout.updateExpandButtons(isExpandable());
Chris Wren51c75102013-07-16 20:49:17 -04001062 }
1063
Selim Cinek4ffd6362015-12-29 15:12:23 +01001064 @Override
1065 public void setClipToActualHeight(boolean clipToActualHeight) {
Selim Cinek084c16b2016-01-22 17:48:22 -08001066 super.setClipToActualHeight(clipToActualHeight || isUserLocked());
1067 getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked());
Selim Cinek4ffd6362015-12-29 15:12:23 +01001068 }
1069
Selim Cinek1685e632014-04-08 02:27:49 +02001070 /**
1071 * @return whether the user has changed the expansion state
1072 */
1073 public boolean hasUserChangedExpansion() {
1074 return mHasUserChangedExpansion;
1075 }
1076
Chris Wren51c75102013-07-16 20:49:17 -04001077 public boolean isUserExpanded() {
1078 return mUserExpanded;
1079 }
1080
Selim Cinek1685e632014-04-08 02:27:49 +02001081 /**
1082 * Set this notification to be expanded by the user
1083 *
1084 * @param userExpanded whether the user wants this notification to be expanded
1085 */
Chris Wren51c75102013-07-16 20:49:17 -04001086 public void setUserExpanded(boolean userExpanded) {
Selim Cinek388df6d2015-10-22 13:25:11 -07001087 setUserExpanded(userExpanded, false /* allowChildExpansion */);
1088 }
1089
1090 /**
1091 * Set this notification to be expanded by the user
1092 *
1093 * @param userExpanded whether the user wants this notification to be expanded
1094 * @param allowChildExpansion whether a call to this method allows expanding children
1095 */
1096 public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001097 mFalsingManager.setNotificationExpanded();
Selim Cinek388df6d2015-10-22 13:25:11 -07001098 if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion) {
Chris Wren698b1702016-05-23 11:16:32 -04001099 final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinek388df6d2015-10-22 13:25:11 -07001100 mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded);
Chris Wren698b1702016-05-23 11:16:32 -04001101 logExpansionEvent(true /* userAction */, wasExpanded);
Selim Cinek388df6d2015-10-22 13:25:11 -07001102 return;
1103 }
Christoph Studera7fe6312014-06-27 19:32:44 +02001104 if (userExpanded && !mExpandable) return;
Chris Wren78403d72014-07-28 10:23:24 +01001105 final boolean wasExpanded = isExpanded();
Selim Cinek1685e632014-04-08 02:27:49 +02001106 mHasUserChangedExpansion = true;
Chris Wren51c75102013-07-16 20:49:17 -04001107 mUserExpanded = userExpanded;
Chris Wren78403d72014-07-28 10:23:24 +01001108 logExpansionEvent(true, wasExpanded);
Chris Wren51c75102013-07-16 20:49:17 -04001109 }
1110
Selim Cinekccd14fb2014-08-12 18:53:24 +02001111 public void resetUserExpansion() {
1112 mHasUserChangedExpansion = false;
1113 mUserExpanded = false;
1114 }
1115
Chris Wren51c75102013-07-16 20:49:17 -04001116 public boolean isUserLocked() {
Selim Cinek1b2a05e2016-04-28 14:20:39 -07001117 return mUserLocked && !mForceUnlocked;
Chris Wren51c75102013-07-16 20:49:17 -04001118 }
1119
1120 public void setUserLocked(boolean userLocked) {
1121 mUserLocked = userLocked;
Selim Cinek8f2f6a62016-02-23 19:56:31 -08001122 mPrivateLayout.setUserExpanding(userLocked);
Selim Cinek42357e02016-02-24 18:48:01 -08001123 if (mIsSummaryWithChildren) {
1124 mChildrenContainer.setUserLocked(userLocked);
Mady Mellorc7d65b42016-05-04 11:44:57 -04001125 if (userLocked || (!userLocked && !isGroupExpanded())) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001126 updateBackgroundForGroupState();
1127 }
Selim Cinek42357e02016-02-24 18:48:01 -08001128 }
Chris Wren51c75102013-07-16 20:49:17 -04001129 }
1130
Selim Cinek1685e632014-04-08 02:27:49 +02001131 /**
1132 * @return has the system set this notification to be expanded
1133 */
1134 public boolean isSystemExpanded() {
1135 return mIsSystemExpanded;
1136 }
1137
1138 /**
1139 * Set this notification to be expanded by the system.
1140 *
1141 * @param expand whether the system wants this notification to be expanded.
1142 */
1143 public void setSystemExpanded(boolean expand) {
Selim Cinek31094df2014-08-14 19:28:15 +02001144 if (expand != mIsSystemExpanded) {
1145 final boolean wasExpanded = isExpanded();
1146 mIsSystemExpanded = expand;
Selim Cinekb5605e52015-02-20 18:21:41 +01001147 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +02001148 logExpansionEvent(false, wasExpanded);
Selim Cineked6913b2016-06-01 12:01:17 -07001149 if (mIsSummaryWithChildren) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001150 mChildrenContainer.updateGroupOverflow();
1151 }
Selim Cinek31094df2014-08-14 19:28:15 +02001152 }
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001153 }
1154
1155 /**
Selim Cinek83bc7832015-10-22 13:26:54 -07001156 * @param onKeyguard whether to prevent notification expansion
Jorim Jaggidce3c4c2014-04-29 23:12:24 +02001157 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001158 public void setOnKeyguard(boolean onKeyguard) {
1159 if (onKeyguard != mOnKeyguard) {
Selim Cinek31094df2014-08-14 19:28:15 +02001160 final boolean wasExpanded = isExpanded();
Selim Cinek83bc7832015-10-22 13:26:54 -07001161 mOnKeyguard = onKeyguard;
Selim Cinek31094df2014-08-14 19:28:15 +02001162 logExpansionEvent(false, wasExpanded);
1163 if (wasExpanded != isExpanded()) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001164 if (mIsSummaryWithChildren) {
1165 mChildrenContainer.updateGroupOverflow();
1166 }
Mady Mellor4b80b102016-01-22 08:03:58 -08001167 notifyHeightChanged(false /* needsAnimation */);
Selim Cinek31094df2014-08-14 19:28:15 +02001168 }
1169 }
Selim Cinek1685e632014-04-08 02:27:49 +02001170 }
1171
1172 /**
Selim Cinek9e624e72016-07-20 13:46:49 -07001173 * @return Can the underlying notification be cleared? This can be different from whether the
1174 * notification can be dismissed in case notifications are sensitive on the lockscreen.
1175 * @see #canViewBeDismissed()
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001176 */
1177 public boolean isClearable() {
Selim Cineka37774f2014-11-11 19:16:18 +01001178 return mStatusBarNotification != null && mStatusBarNotification.isClearable();
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001179 }
1180
Jorim Jaggi9cbadd32014-05-01 20:18:31 +02001181 @Override
1182 public int getIntrinsicHeight() {
Jorim Jaggibe565df2014-04-28 17:51:23 +02001183 if (isUserLocked()) {
1184 return getActualHeight();
1185 }
Selim Cinekd84a5932015-12-15 11:45:36 -08001186 if (mGuts != null && mGuts.areGutsExposed()) {
1187 return mGuts.getHeight();
1188 } else if ((isChildInGroup() && !isGroupExpanded())) {
1189 return mPrivateLayout.getMinHeight();
1190 } else if (mSensitive && mHideSensitiveForIntrinsicHeight) {
1191 return getMinHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001192 } else if (mIsSummaryWithChildren && !mOnKeyguard) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001193 return mChildrenContainer.getIntrinsicHeight();
Selim Cinek73cf02a2016-06-17 13:08:00 -07001194 } else if (mIsHeadsUp || mHeadsupDisappearRunning) {
1195 if (isPinned() || mHeadsupDisappearRunning) {
Selim Cinek31aada42015-12-18 17:51:15 -08001196 return getPinnedHeadsUpHeight(true /* atLeastMinHeight */);
1197 } else if (isExpanded()) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001198 return Math.max(getMaxExpandHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001199 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001200 return Math.max(getCollapsedHeight(), mHeadsUpHeight);
Selim Cinek8d490d42015-04-10 00:05:50 -07001201 }
Selim Cinek31aada42015-12-18 17:51:15 -08001202 } else if (isExpanded()) {
Selim Cinek83bc7832015-10-22 13:26:54 -07001203 return getMaxExpandHeight();
Selim Cinekd84a5932015-12-15 11:45:36 -08001204 } else {
Selim Cinek567e8452016-03-24 10:54:56 -07001205 return getCollapsedHeight();
Selim Cinek1685e632014-04-08 02:27:49 +02001206 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001207 }
Selim Cinek1685e632014-04-08 02:27:49 +02001208
Mady Mellorb0a82462016-04-30 17:31:02 -07001209 public boolean isGroupExpanded() {
Selim Cinekeef84282015-10-30 16:28:00 -07001210 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Selim Cinekb5605e52015-02-20 18:21:41 +01001211 }
1212
Selim Cinek263398f2015-10-21 17:40:23 -07001213 private void onChildrenCountChanged() {
Selim Cinek8fc93c92015-11-23 17:48:07 -08001214 mIsSummaryWithChildren = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS
Mady Mellorb0a82462016-04-30 17:31:02 -07001215 && mChildrenContainer != null && mChildrenContainer.getNotificationChildCount() > 0;
1216 if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() == null) {
1217 mChildrenContainer.recreateNotificationHeader(mExpandClickListener,
1218 mEntry.notification);
Selim Cinek263398f2015-10-21 17:40:23 -07001219 }
Mady Mellor6baed9e2016-05-25 16:05:09 -07001220 getShowingLayout().updateBackgroundColor(false /* animate */);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001221 mPrivateLayout.updateExpandButtons(isExpandable());
Selim Cinekea4bef72015-12-02 15:51:10 -08001222 updateChildrenHeaderAppearance();
Selim Cinekda42d652015-12-04 15:51:16 -08001223 updateChildrenVisibility();
Selim Cinek263398f2015-10-21 17:40:23 -07001224 }
1225
Mady Mellorb0a82462016-04-30 17:31:02 -07001226 public void updateChildrenHeaderAppearance() {
Selim Cineked6913b2016-06-01 12:01:17 -07001227 if (mIsSummaryWithChildren) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001228 mChildrenContainer.updateChildrenHeaderAppearance();
1229 }
1230 }
1231
Selim Cinek1685e632014-04-08 02:27:49 +02001232 /**
1233 * Check whether the view state is currently expanded. This is given by the system in {@link
1234 * #setSystemExpanded(boolean)} and can be overridden by user expansion or
1235 * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this
1236 * view can differ from this state, if layout params are modified from outside.
1237 *
1238 * @return whether the view state is currently expanded.
1239 */
Selim Cinek83bc7832015-10-22 13:26:54 -07001240 public boolean isExpanded() {
Selim Cineke81b82b2016-03-04 11:22:28 -08001241 return isExpanded(false /* allowOnKeyguard */);
1242 }
1243
1244 public boolean isExpanded(boolean allowOnKeyguard) {
1245 return (!mOnKeyguard || allowOnKeyguard)
Selim Cinekb5605e52015-02-20 18:21:41 +01001246 && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded())
1247 || isUserExpanded());
1248 }
1249
1250 private boolean isSystemChildExpanded() {
1251 return mIsSystemChildExpanded;
1252 }
1253
1254 public void setSystemChildExpanded(boolean expanded) {
1255 mIsSystemChildExpanded = expanded;
Selim Cinek1685e632014-04-08 02:27:49 +02001256 }
1257
1258 @Override
1259 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
1260 super.onLayout(changed, left, top, right, bottom);
Selim Cinek8d490d42015-04-10 00:05:50 -07001261 updateMaxHeights();
Mady Mellora6edc872016-04-26 11:01:03 -07001262 if (mSettingsIconRow != null) {
1263 mSettingsIconRow.updateVerticalLocation();
1264 }
Selim Cinek1685e632014-04-08 02:27:49 +02001265 }
1266
Selim Cinek8d490d42015-04-10 00:05:50 -07001267 private void updateMaxHeights() {
Selim Cinekd2319fb2014-09-01 19:41:54 +02001268 int intrinsicBefore = getIntrinsicHeight();
Selim Cinek8d490d42015-04-10 00:05:50 -07001269 View expandedChild = mPrivateLayout.getExpandedChild();
1270 if (expandedChild == null) {
1271 expandedChild = mPrivateLayout.getContractedChild();
1272 }
1273 mMaxExpandHeight = expandedChild.getHeight();
1274 View headsUpChild = mPrivateLayout.getHeadsUpChild();
Selim Cinek1f3f5442015-04-10 17:54:46 -07001275 if (headsUpChild == null) {
1276 headsUpChild = mPrivateLayout.getContractedChild();
Selim Cinek8d490d42015-04-10 00:05:50 -07001277 }
Selim Cinek1f3f5442015-04-10 17:54:46 -07001278 mHeadsUpHeight = headsUpChild.getHeight();
Selim Cinekd2319fb2014-09-01 19:41:54 +02001279 if (intrinsicBefore != getIntrinsicHeight()) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001280 notifyHeightChanged(false /* needsAnimation */);
Selim Cinekd2319fb2014-09-01 19:41:54 +02001281 }
1282 }
1283
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001284 @Override
1285 public void notifyHeightChanged(boolean needsAnimation) {
1286 super.notifyHeightChanged(needsAnimation);
1287 getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked());
1288 }
1289
Selim Cinek3c76d502016-02-19 15:16:33 -08001290 public void setSensitive(boolean sensitive, boolean hideSensitive) {
Jorim Jaggiae441282014-08-01 02:45:18 +02001291 mSensitive = sensitive;
Selim Cinek3c76d502016-02-19 15:16:33 -08001292 mSensitiveHiddenInGeneral = hideSensitive;
Jorim Jaggiae441282014-08-01 02:45:18 +02001293 }
1294
1295 public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) {
Selim Cinek60122be2015-04-15 18:16:50 -07001296 mHideSensitiveForIntrinsicHeight = hideSensitive;
Selim Cineka52f6a12016-02-29 15:35:58 -08001297 if (mIsSummaryWithChildren) {
1298 List<ExpandableNotificationRow> notificationChildren =
1299 mChildrenContainer.getNotificationChildren();
1300 for (int i = 0; i < notificationChildren.size(); i++) {
1301 ExpandableNotificationRow child = notificationChildren.get(i);
1302 child.setHideSensitiveForIntrinsicHeight(hideSensitive);
1303 }
1304 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001305 }
1306
1307 public void setHideSensitive(boolean hideSensitive, boolean animated, long delay,
1308 long duration) {
1309 boolean oldShowingPublic = mShowingPublic;
1310 mShowingPublic = mSensitive && hideSensitive;
1311 if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) {
1312 return;
1313 }
Dan Sandlera5e0f412014-01-23 15:11:54 -05001314
1315 // bail out if no public version
Selim Cinek1685e632014-04-08 02:27:49 +02001316 if (mPublicLayout.getChildCount() == 0) return;
Dan Sandlera5e0f412014-01-23 15:11:54 -05001317
Jorim Jaggiae441282014-08-01 02:45:18 +02001318 if (!animated) {
1319 mPublicLayout.animate().cancel();
1320 mPrivateLayout.animate().cancel();
Selim Cineka554c702016-06-17 18:02:12 -07001321 if (mChildrenContainer != null) {
1322 mChildrenContainer.animate().cancel();
1323 mChildrenContainer.setAlpha(1f);
1324 }
Jorim Jaggiae441282014-08-01 02:45:18 +02001325 mPublicLayout.setAlpha(1f);
1326 mPrivateLayout.setAlpha(1f);
1327 mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE);
Selim Cinekd84a5932015-12-15 11:45:36 -08001328 updateChildrenVisibility();
Jorim Jaggiae441282014-08-01 02:45:18 +02001329 } else {
1330 animateShowingPublic(delay, duration);
1331 }
Selim Cinekc3179332016-03-04 14:44:56 -08001332 NotificationContentView showingLayout = getShowingLayout();
1333 showingLayout.updateBackgroundColor(animated);
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001334 mPrivateLayout.updateExpandButtons(isExpandable());
Jorim Jaggiae441282014-08-01 02:45:18 +02001335 mShowingPublicInitialized = true;
1336 }
1337
1338 private void animateShowingPublic(long delay, long duration) {
Mady Mellorb0a82462016-04-30 17:31:02 -07001339 View[] privateViews = mIsSummaryWithChildren
1340 ? new View[] {mChildrenContainer}
Selim Cinekd84a5932015-12-15 11:45:36 -08001341 : new View[] {mPrivateLayout};
1342 View[] publicViews = new View[] {mPublicLayout};
1343 View[] hiddenChildren = mShowingPublic ? privateViews : publicViews;
1344 View[] shownChildren = mShowingPublic ? publicViews : privateViews;
1345 for (final View hiddenView : hiddenChildren) {
1346 hiddenView.setVisibility(View.VISIBLE);
1347 hiddenView.animate().cancel();
1348 hiddenView.animate()
1349 .alpha(0f)
1350 .setStartDelay(delay)
1351 .setDuration(duration)
1352 .withEndAction(new Runnable() {
1353 @Override
1354 public void run() {
1355 hiddenView.setVisibility(View.INVISIBLE);
1356 }
1357 });
1358 }
1359 for (View showView : shownChildren) {
1360 showView.setVisibility(View.VISIBLE);
1361 showView.setAlpha(0f);
1362 showView.animate().cancel();
1363 showView.animate()
1364 .alpha(1f)
1365 .setStartDelay(delay)
1366 .setDuration(duration);
1367 }
Dan Sandler0d3e62f2014-07-14 17:13:50 -04001368 }
1369
Selim Cinek3776fe02016-02-04 13:32:43 -08001370 public boolean mustStayOnScreen() {
1371 return mIsHeadsUp;
1372 }
1373
Selim Cinek9e624e72016-07-20 13:46:49 -07001374 /**
1375 * @return Whether this view is allowed to be dismissed. Only valid for visible notifications as
1376 * otherwise some state might not be updated. To request about the general clearability
1377 * see {@link #isClearable()}.
1378 */
1379 public boolean canViewBeDismissed() {
Selim Cineke9bad242016-06-15 11:46:37 -07001380 return isClearable() && (!mShowingPublic || !mSensitiveHiddenInGeneral);
Dan Sandlera5e0f412014-01-23 15:11:54 -05001381 }
Jorim Jaggi251957d2014-04-09 04:24:09 +02001382
Ricky Waicd35def2016-05-03 11:07:07 +01001383 public void makeActionsVisibile() {
1384 setUserExpanded(true, true);
1385 if (isChildInGroup()) {
1386 mGroupManager.setGroupExpanded(mStatusBarNotification, true);
1387 }
1388 notifyHeightChanged(false);
1389 }
1390
Selim Cinekb5605e52015-02-20 18:21:41 +01001391 public void setChildrenExpanded(boolean expanded, boolean animate) {
1392 mChildrenExpanded = expanded;
Selim Cinek83bc7832015-10-22 13:26:54 -07001393 if (mChildrenContainer != null) {
1394 mChildrenContainer.setChildrenExpanded(expanded);
1395 }
Mady Mellor1a5d8ea2016-06-09 10:42:42 -07001396 updateBackgroundForGroupState();
Selim Cinekddf1b392016-05-27 16:33:10 -07001397 updateClickAndFocus();
Selim Cinekb5605e52015-02-20 18:21:41 +01001398 }
1399
Selim Cinekb5605e52015-02-20 18:21:41 +01001400 public static void applyTint(View v, int color) {
1401 int alpha;
1402 if (color != 0) {
1403 alpha = COLORED_DIVIDER_ALPHA;
1404 } else {
1405 color = 0xff000000;
1406 alpha = DEFAULT_DIVIDER_ALPHA;
1407 }
1408 if (v.getBackground() instanceof ColorDrawable) {
1409 ColorDrawable background = (ColorDrawable) v.getBackground();
1410 background.mutate();
1411 background.setColor(color);
1412 background.setAlpha(alpha);
1413 }
1414 }
1415
Selim Cinek1685e632014-04-08 02:27:49 +02001416 public int getMaxExpandHeight() {
Selim Cinekb5605e52015-02-20 18:21:41 +01001417 return mMaxExpandHeight;
Chris Wren51c75102013-07-16 20:49:17 -04001418 }
Jorim Jaggi584a7aa2014-04-10 23:26:13 +02001419
Mady Mellor34958fa2016-02-23 09:52:17 -08001420 public boolean areGutsExposed() {
1421 return (mGuts != null && mGuts.areGutsExposed());
1422 }
1423
Jorim Jaggibe565df2014-04-28 17:51:23 +02001424 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001425 public boolean isContentExpandable() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001426 NotificationContentView showingLayout = getShowingLayout();
1427 return showingLayout.isContentExpandable();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001428 }
1429
1430 @Override
Selim Cinek560e64d2015-06-09 19:58:11 -07001431 protected View getContentView() {
Selim Cineka5703182016-05-11 21:23:16 -04001432 if (mIsSummaryWithChildren) {
1433 return mChildrenContainer;
1434 }
Selim Cinek560e64d2015-06-09 19:58:11 -07001435 return getShowingLayout();
1436 }
1437
1438 @Override
Mady Mellorb0a82462016-04-30 17:31:02 -07001439 public int getExtraBottomPadding() {
1440 if (mIsSummaryWithChildren && isGroupExpanded()) {
1441 return mIncreasedPaddingBetweenElements;
1442 }
1443 return 0;
1444 }
1445
1446 @Override
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001447 public void setActualHeight(int height, boolean notifyListeners) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001448 super.setActualHeight(height, notifyListeners);
Mady Mellorb53bc272016-02-11 18:28:23 -08001449 if (mGuts != null && mGuts.areGutsExposed()) {
1450 mGuts.setActualHeight(height);
1451 return;
1452 }
Selim Cinekeef84282015-10-30 16:28:00 -07001453 int contentHeight = Math.max(getMinHeight(), height);
Selim Cinekb5605e52015-02-20 18:21:41 +01001454 mPrivateLayout.setContentHeight(contentHeight);
1455 mPublicLayout.setContentHeight(contentHeight);
Selim Cinek42357e02016-02-24 18:48:01 -08001456 if (mIsSummaryWithChildren) {
1457 mChildrenContainer.setActualHeight(height);
1458 }
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001459 if (mGuts != null) {
1460 mGuts.setActualHeight(height);
1461 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001462 }
1463
1464 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01001465 public int getMaxContentHeight() {
Selim Cinek83bc7832015-10-22 13:26:54 -07001466 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001467 return mChildrenContainer.getMaxContentHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001468 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001469 NotificationContentView showingLayout = getShowingLayout();
1470 return showingLayout.getMaxHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +02001471 }
1472
1473 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001474 public int getMinHeight() {
Selim Cinek31aada42015-12-18 17:51:15 -08001475 if (mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) {
1476 return getPinnedHeadsUpHeight(false /* atLeastMinHeight */);
1477 } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) {
Selim Cinekb55386d2015-12-16 17:26:49 -08001478 return mChildrenContainer.getMinHeight();
Selim Cinek31aada42015-12-18 17:51:15 -08001479 } else if (mIsHeadsUp) {
1480 return mHeadsUpHeight;
Selim Cinekb55386d2015-12-16 17:26:49 -08001481 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001482 NotificationContentView showingLayout = getShowingLayout();
1483 return showingLayout.getMinHeight();
1484 }
1485
1486 @Override
Selim Cinek567e8452016-03-24 10:54:56 -07001487 public int getCollapsedHeight() {
Selim Cinek2c584612016-02-29 16:14:25 -08001488 if (mIsSummaryWithChildren && !mShowingPublic) {
Selim Cinek567e8452016-03-24 10:54:56 -07001489 return mChildrenContainer.getCollapsedHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -07001490 }
Selim Cinek816c8e42015-11-19 12:00:45 -08001491 return getMinHeight();
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001492 }
1493
1494 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +02001495 public void setClipTopAmount(int clipTopAmount) {
1496 super.setClipTopAmount(clipTopAmount);
1497 mPrivateLayout.setClipTopAmount(clipTopAmount);
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001498 mPublicLayout.setClipTopAmount(clipTopAmount);
Jorim Jaggib1cd3c12014-09-08 19:55:17 +02001499 if (mGuts != null) {
1500 mGuts.setClipTopAmount(clipTopAmount);
1501 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001502 }
1503
Selim Cinek31094df2014-08-14 19:28:15 +02001504 public boolean isMaxExpandHeightInitialized() {
1505 return mMaxExpandHeight != 0;
Selim Cinek7d447722014-06-10 15:51:59 +02001506 }
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001507
Selim Cinek42357e02016-02-24 18:48:01 -08001508 public NotificationContentView getShowingLayout() {
Selim Cinek2f0df8a2014-06-10 17:40:42 +02001509 return mShowingPublic ? mPublicLayout : mPrivateLayout;
1510 }
Chris Wren78403d72014-07-28 10:23:24 +01001511
Jorim Jaggi59ec3042015-06-05 15:18:43 -07001512 @Override
1513 public void setShowingLegacyBackground(boolean showing) {
1514 super.setShowingLegacyBackground(showing);
1515 mPrivateLayout.setShowingLegacyBackground(showing);
1516 mPublicLayout.setShowingLegacyBackground(showing);
1517 }
1518
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001519 @Override
1520 protected void updateBackgroundTint() {
1521 super.updateBackgroundTint();
Mady Mellorb0a82462016-04-30 17:31:02 -07001522 updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001523 if (mIsSummaryWithChildren) {
1524 List<ExpandableNotificationRow> notificationChildren =
1525 mChildrenContainer.getNotificationChildren();
1526 for (int i = 0; i < notificationChildren.size(); i++) {
1527 ExpandableNotificationRow child = notificationChildren.get(i);
Mady Mellorb0a82462016-04-30 17:31:02 -07001528 child.updateBackgroundForGroupState();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001529 }
1530 }
1531 }
1532
Mady Mellorb0a82462016-04-30 17:31:02 -07001533 /**
1534 * Called when a group has finished animating from collapsed or expanded state.
1535 */
1536 public void onFinishedExpansionChange() {
1537 mGroupExpansionChanging = false;
1538 updateBackgroundForGroupState();
1539 }
1540
1541 /**
1542 * Updates the parent and children backgrounds in a group based on the expansion state.
1543 */
1544 public void updateBackgroundForGroupState() {
1545 if (mIsSummaryWithChildren) {
1546 // Only when the group has finished expanding do we hide its background.
1547 mShowNoBackground = isGroupExpanded() && !isGroupExpansionChanging() && !isUserLocked();
1548 mChildrenContainer.updateHeaderForExpansion(mShowNoBackground);
1549 List<ExpandableNotificationRow> children = mChildrenContainer.getNotificationChildren();
1550 for (int i = 0; i < children.size(); i++) {
1551 children.get(i).updateBackgroundForGroupState();
1552 }
1553 } else if (isChildInGroup()) {
1554 final int childColor = getShowingLayout().getBackgroundColorForExpansionState();
1555 // Only show a background if the group is expanded OR if it is expanding / collapsing
1556 // and has a custom background color
1557 final boolean showBackground = isGroupExpanded()
1558 || ((mNotificationParent.isGroupExpansionChanging()
1559 || mNotificationParent.isUserLocked()) && childColor != 0);
1560 mShowNoBackground = !showBackground;
1561 } else {
1562 // Only children or parents ever need no background.
1563 mShowNoBackground = false;
1564 }
1565 updateOutline();
Selim Cineka6c6bfb2015-10-29 16:27:08 -07001566 updateBackground();
1567 }
1568
Adrian Roos4a579672016-05-24 16:54:37 -07001569 public int getPositionOfChild(ExpandableNotificationRow childRow) {
1570 if (mIsSummaryWithChildren) {
1571 return mChildrenContainer.getPositionInLinearLayout(childRow);
1572 }
1573 return 0;
1574 }
1575
Chris Wren78403d72014-07-28 10:23:24 +01001576 public void setExpansionLogger(ExpansionLogger logger, String key) {
1577 mLogger = logger;
1578 mLoggingKey = key;
1579 }
1580
Chris Wren6abeeb92016-05-26 14:44:38 -04001581 public void onExpandedByGesture(boolean userExpanded) {
1582 int event = MetricsEvent.ACTION_NOTIFICATION_GESTURE_EXPANDER;
1583 if (mGroupManager.isSummaryOfGroup(getStatusBarNotification())) {
1584 event = MetricsEvent.ACTION_NOTIFICATION_GROUP_GESTURE_EXPANDER;
1585 }
1586 MetricsLogger.action(mContext, event, userExpanded);
1587 }
1588
Selim Cinek6183d122016-01-14 18:48:41 -08001589 @Override
Selim Cinek42357e02016-02-24 18:48:01 -08001590 public float getIncreasedPaddingAmount() {
1591 if (mIsSummaryWithChildren) {
1592 if (isGroupExpanded()) {
1593 return 1.0f;
1594 } else if (isUserLocked()) {
Selim Cinekf07d0622016-03-21 19:52:52 -07001595 return mChildrenContainer.getGroupExpandFraction();
Selim Cinek42357e02016-02-24 18:48:01 -08001596 }
1597 }
1598 return 0.0f;
Selim Cinek61633a82016-01-25 15:54:10 -08001599 }
1600
1601 @Override
Selim Cinek6183d122016-01-14 18:48:41 -08001602 protected boolean disallowSingleClick(MotionEvent event) {
1603 float x = event.getX();
1604 float y = event.getY();
Selim Cinek34eda5e2016-02-18 17:10:43 -08001605 NotificationHeaderView header = getVisibleNotificationHeader();
Selim Cinek6183d122016-01-14 18:48:41 -08001606 if (header != null) {
Mady Mellora8833512016-03-09 09:50:18 -08001607 return header.isInTouchRect(x - getTranslation(), y);
Selim Cinek6183d122016-01-14 18:48:41 -08001608 }
1609 return super.disallowSingleClick(event);
1610 }
1611
Chris Wren78403d72014-07-28 10:23:24 +01001612 private void logExpansionEvent(boolean userAction, boolean wasExpanded) {
Chris Wren698b1702016-05-23 11:16:32 -04001613 boolean nowExpanded = isExpanded();
1614 if (mIsSummaryWithChildren) {
1615 nowExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification);
1616 }
Chris Wren78403d72014-07-28 10:23:24 +01001617 if (wasExpanded != nowExpanded && mLogger != null) {
1618 mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ;
1619 }
1620 }
Selim Cinek570981d2015-12-01 11:37:01 -08001621
Selim Cineke9bad242016-06-15 11:46:37 -07001622 @Override
1623 public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
1624 super.onInitializeAccessibilityNodeInfoInternal(info);
1625 if (canViewBeDismissed()) {
1626 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS);
1627 }
1628 }
1629
1630 @Override
1631 public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
1632 if (super.performAccessibilityActionInternal(action, arguments)) {
1633 return true;
1634 }
1635 switch (action) {
1636 case AccessibilityNodeInfo.ACTION_DISMISS:
1637 NotificationStackScrollLayout.performDismiss(this, mGroupManager,
1638 true /* fromAccessibility */);
1639 return true;
1640 }
1641 return false;
1642 }
1643
1644 public boolean shouldRefocusOnDismiss() {
1645 return mRefocusOnDismiss || isAccessibilityFocused();
1646 }
1647
Selim Cinek570981d2015-12-01 11:37:01 -08001648 public interface OnExpandClickListener {
Selim Cinek31aada42015-12-18 17:51:15 -08001649 void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded);
Selim Cinek570981d2015-12-01 11:37:01 -08001650 }
Chris Wren51c75102013-07-16 20:49:17 -04001651}