Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 19 | import android.app.Notification; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 20 | import android.content.Context; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 21 | import android.graphics.drawable.AnimatedVectorDrawable; |
| 22 | import android.graphics.drawable.AnimationDrawable; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 23 | import android.graphics.drawable.ColorDrawable; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 24 | import android.graphics.drawable.Drawable; |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 25 | import android.os.Build; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 26 | import android.service.notification.StatusBarNotification; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 27 | import android.util.AttributeSet; |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 28 | import android.view.NotificationHeaderView; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 29 | import android.view.View; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 30 | import android.view.ViewStub; |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 31 | import android.view.accessibility.AccessibilityEvent; |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 32 | import android.widget.Chronometer; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 33 | import android.widget.ImageView; |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 34 | import android.widget.RemoteViews; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 35 | |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 36 | import com.android.systemui.R; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 37 | import com.android.systemui.classifier.FalsingManager; |
Selim Cinek | 0ffbda6 | 2016-01-01 20:29:12 +0100 | [diff] [blame] | 38 | import com.android.systemui.statusbar.notification.NotificationViewWrapper; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 39 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 40 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 41 | import com.android.systemui.statusbar.stack.NotificationChildrenContainer; |
| 42 | import com.android.systemui.statusbar.stack.StackScrollState; |
| 43 | import com.android.systemui.statusbar.stack.StackStateAnimator; |
| 44 | import com.android.systemui.statusbar.stack.StackViewState; |
| 45 | |
| 46 | import java.util.List; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 47 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 48 | public class ExpandableNotificationRow extends ActivatableNotificationView { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 49 | |
| 50 | private static final int DEFAULT_DIVIDER_ALPHA = 0x29; |
| 51 | private static final int COLORED_DIVIDER_ALPHA = 0x7B; |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 52 | private final int mNotificationMinHeightLegacy; |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 53 | private final int mMaxHeadsUpHeightLegacy; |
| 54 | private final int mMaxHeadsUpHeight; |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 55 | private final int mNotificationMinHeight; |
| 56 | private final int mNotificationMaxHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 57 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 58 | /** Does this row contain layouts that can adapt to row expansion */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 59 | private boolean mExpandable; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 60 | /** Has the user actively changed the expansion state of this row */ |
| 61 | private boolean mHasUserChangedExpansion; |
| 62 | /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 63 | private boolean mUserExpanded; |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Has this notification been expanded while it was pinned |
| 67 | */ |
| 68 | private boolean mExpandedWhenPinned; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 69 | /** Is the user touching this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 70 | private boolean mUserLocked; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 71 | /** Are we showing the "public" version */ |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 72 | private boolean mShowingPublic; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 73 | private boolean mSensitive; |
| 74 | private boolean mShowingPublicInitialized; |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame] | 75 | private boolean mHideSensitiveForIntrinsicHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 76 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 77 | /** |
| 78 | * Is this notification expanded by the system. The expansion state can be overridden by the |
| 79 | * user expansion. |
| 80 | */ |
| 81 | private boolean mIsSystemExpanded; |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 82 | |
| 83 | /** |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 84 | * Whether the notification is on the keyguard and the expansion is disabled. |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 85 | */ |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 86 | private boolean mOnKeyguard; |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 87 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 88 | private NotificationContentView mPublicLayout; |
| 89 | private NotificationContentView mPrivateLayout; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 90 | private int mMaxExpandHeight; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 91 | private int mHeadsUpHeight; |
Selim Cinek | 863834b | 2014-05-20 04:20:25 +0200 | [diff] [blame] | 92 | private View mVetoButton; |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 93 | private boolean mClearable; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 94 | private ExpansionLogger mLogger; |
| 95 | private String mLoggingKey; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 96 | private boolean mWasReset; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 97 | private NotificationGuts mGuts; |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 98 | private NotificationData.Entry mEntry; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 99 | private StatusBarNotification mStatusBarNotification; |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 100 | private boolean mIsHeadsUp; |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 101 | private boolean mLastChronometerRunning = true; |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 102 | private NotificationHeaderView mNotificationHeader; |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 103 | private NotificationViewWrapper mNotificationHeaderWrapper; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 104 | private ViewStub mChildrenContainerStub; |
| 105 | private NotificationGroupManager mGroupManager; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 106 | private boolean mChildrenExpanded; |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 107 | private boolean mIsSummaryWithChildren; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 108 | private NotificationChildrenContainer mChildrenContainer; |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 109 | private ViewStub mGutsStub; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 110 | private boolean mIsSystemChildExpanded; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 111 | private boolean mIsPinned; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 112 | private FalsingManager mFalsingManager; |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 113 | private HeadsUpManager mHeadsUpManager; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 114 | private NotificationHeaderUtil mHeaderUtil = new NotificationHeaderUtil(this); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 115 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 116 | private boolean mJustClicked; |
Selim Cinek | 5a175d9 | 2015-11-23 18:01:33 -0800 | [diff] [blame] | 117 | private boolean mIconAnimationRunning; |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 118 | private boolean mShowNoBackground; |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 119 | private ExpandableNotificationRow mNotificationParent; |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 120 | private OnExpandClickListener mOnExpandClickListener; |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 121 | private OnClickListener mExpandClickListener = new OnClickListener() { |
| 122 | @Override |
| 123 | public void onClick(View v) { |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 124 | if (!mShowingPublic && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 125 | mGroupManager.toggleGroupExpansion(mStatusBarNotification); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 126 | mOnExpandClickListener.onExpandClicked(mEntry, |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 127 | mGroupManager.isGroupExpanded(mStatusBarNotification)); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 128 | } else { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 129 | boolean nowExpanded; |
| 130 | if (isPinned()) { |
| 131 | nowExpanded = !mExpandedWhenPinned; |
| 132 | mExpandedWhenPinned = nowExpanded; |
| 133 | } else { |
| 134 | nowExpanded = !isExpanded(); |
| 135 | setUserExpanded(nowExpanded); |
| 136 | } |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 137 | notifyHeightChanged(true); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 138 | mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | }; |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 142 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 143 | public NotificationContentView getPrivateLayout() { |
| 144 | return mPrivateLayout; |
| 145 | } |
| 146 | |
| 147 | public NotificationContentView getPublicLayout() { |
| 148 | return mPublicLayout; |
| 149 | } |
| 150 | |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 151 | public void setIconAnimationRunning(boolean running) { |
| 152 | setIconAnimationRunning(running, mPublicLayout); |
| 153 | setIconAnimationRunning(running, mPrivateLayout); |
Selim Cinek | 5a175d9 | 2015-11-23 18:01:33 -0800 | [diff] [blame] | 154 | setIconAnimationRunningForChild(running, mNotificationHeader); |
| 155 | if (mIsSummaryWithChildren) { |
| 156 | List<ExpandableNotificationRow> notificationChildren = |
| 157 | mChildrenContainer.getNotificationChildren(); |
| 158 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 159 | ExpandableNotificationRow child = notificationChildren.get(i); |
| 160 | child.setIconAnimationRunning(running); |
| 161 | } |
| 162 | } |
| 163 | mIconAnimationRunning = running; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | private void setIconAnimationRunning(boolean running, NotificationContentView layout) { |
| 167 | if (layout != null) { |
| 168 | View contractedChild = layout.getContractedChild(); |
| 169 | View expandedChild = layout.getExpandedChild(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 170 | View headsUpChild = layout.getHeadsUpChild(); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 171 | setIconAnimationRunningForChild(running, contractedChild); |
| 172 | setIconAnimationRunningForChild(running, expandedChild); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 173 | setIconAnimationRunningForChild(running, headsUpChild); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
| 177 | private void setIconAnimationRunningForChild(boolean running, View child) { |
| 178 | if (child != null) { |
| 179 | ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon); |
| 180 | setIconRunning(icon, running); |
| 181 | ImageView rightIcon = (ImageView) child.findViewById( |
| 182 | com.android.internal.R.id.right_icon); |
| 183 | setIconRunning(rightIcon, running); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | private void setIconRunning(ImageView imageView, boolean running) { |
| 188 | if (imageView != null) { |
| 189 | Drawable drawable = imageView.getDrawable(); |
| 190 | if (drawable instanceof AnimationDrawable) { |
| 191 | AnimationDrawable animationDrawable = (AnimationDrawable) drawable; |
| 192 | if (running) { |
| 193 | animationDrawable.start(); |
| 194 | } else { |
| 195 | animationDrawable.stop(); |
| 196 | } |
| 197 | } else if (drawable instanceof AnimatedVectorDrawable) { |
| 198 | AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable; |
| 199 | if (running) { |
| 200 | animationDrawable.start(); |
| 201 | } else { |
| 202 | animationDrawable.stop(); |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 208 | public void onNotificationUpdated(NotificationData.Entry entry) { |
| 209 | mEntry = entry; |
| 210 | mStatusBarNotification = entry.notification; |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 211 | mPrivateLayout.onNotificationUpdated(entry); |
| 212 | mPublicLayout.onNotificationUpdated(entry); |
Selim Cinek | a37774f | 2014-11-11 19:16:18 +0100 | [diff] [blame] | 213 | updateVetoButton(); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 214 | if (mIsSummaryWithChildren) { |
| 215 | recreateNotificationHeader(); |
| 216 | } |
Selim Cinek | 5a175d9 | 2015-11-23 18:01:33 -0800 | [diff] [blame] | 217 | if (mIconAnimationRunning) { |
| 218 | setIconAnimationRunning(true); |
| 219 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 220 | if (mNotificationParent != null) { |
| 221 | mNotificationParent.updateChildrenHeaderAppearance(); |
| 222 | } |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 223 | onChildrenCountChanged(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 224 | // The public layouts expand button is always visible |
| 225 | mPublicLayout.updateExpandButtons(true); |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 226 | updateLimits(); |
| 227 | } |
| 228 | |
| 229 | private void updateLimits() { |
| 230 | boolean customView = getPrivateLayout().getContractedChild().getId() |
| 231 | != com.android.internal.R.id.status_bar_latest_event_content; |
| 232 | boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N; |
| 233 | int minHeight = customView && beforeN && !mIsSummaryWithChildren ? |
| 234 | mNotificationMinHeightLegacy : mNotificationMinHeight; |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 235 | boolean headsUpCustom = getPrivateLayout().getHeadsUpChild() != null && |
| 236 | getPrivateLayout().getHeadsUpChild().getId() |
| 237 | != com.android.internal.R.id.status_bar_latest_event_content; |
| 238 | int headsUpheight = headsUpCustom && beforeN ? mMaxHeadsUpHeightLegacy |
| 239 | : mMaxHeadsUpHeight; |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 240 | mMaxViewHeight = mNotificationMaxHeight; |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 241 | mPrivateLayout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight); |
| 242 | mPublicLayout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | public StatusBarNotification getStatusBarNotification() { |
| 246 | return mStatusBarNotification; |
| 247 | } |
| 248 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 249 | public boolean isHeadsUp() { |
| 250 | return mIsHeadsUp; |
| 251 | } |
| 252 | |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 253 | public void setHeadsUp(boolean isHeadsUp) { |
Selim Cinek | c80fdb1 | 2015-04-13 15:09:08 -0700 | [diff] [blame] | 254 | int intrinsicBefore = getIntrinsicHeight(); |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 255 | mIsHeadsUp = isHeadsUp; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 256 | mPrivateLayout.setHeadsUp(isHeadsUp); |
Selim Cinek | c80fdb1 | 2015-04-13 15:09:08 -0700 | [diff] [blame] | 257 | if (intrinsicBefore != getIntrinsicHeight()) { |
| 258 | notifyHeightChanged(false /* needsAnimation */); |
| 259 | } |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 260 | } |
| 261 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 262 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 263 | mGroupManager = groupManager; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 264 | mPrivateLayout.setGroupManager(groupManager); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 265 | } |
| 266 | |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 267 | public void setRemoteInputController(RemoteInputController r) { |
| 268 | mPrivateLayout.setRemoteInputController(r); |
| 269 | } |
| 270 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 271 | public void addChildNotification(ExpandableNotificationRow row) { |
| 272 | addChildNotification(row, -1); |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Add a child notification to this view. |
| 277 | * |
| 278 | * @param row the row to add |
| 279 | * @param childIndex the index to add it at, if -1 it will be added at the end |
| 280 | */ |
| 281 | public void addChildNotification(ExpandableNotificationRow row, int childIndex) { |
| 282 | if (mChildrenContainer == null) { |
| 283 | mChildrenContainerStub.inflate(); |
| 284 | } |
| 285 | mChildrenContainer.addNotification(row, childIndex); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 286 | onChildrenCountChanged(); |
| 287 | row.setIsChildInGroup(true, this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | public void removeChildNotification(ExpandableNotificationRow row) { |
| 291 | if (mChildrenContainer != null) { |
| 292 | mChildrenContainer.removeNotification(row); |
| 293 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 294 | mHeaderUtil.restoreNotificationHeader(row); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 295 | onChildrenCountChanged(); |
| 296 | row.setIsChildInGroup(false, null); |
| 297 | } |
| 298 | |
| 299 | public boolean isChildInGroup() { |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 300 | return mNotificationParent != null; |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 303 | public ExpandableNotificationRow getNotificationParent() { |
| 304 | return mNotificationParent; |
| 305 | } |
| 306 | |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 307 | /** |
| 308 | * @param isChildInGroup Is this notification now in a group |
| 309 | * @param parent the new parent notification |
| 310 | */ |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 311 | public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {; |
| 312 | boolean childInGroup = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup; |
| 313 | mNotificationParent = childInGroup ? parent : null; |
| 314 | mPrivateLayout.setIsChildInGroup(childInGroup); |
| 315 | updateNoBackgroundState(); |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | @Override |
| 319 | protected boolean shouldHideBackground() { |
| 320 | return super.shouldHideBackground() || mShowNoBackground; |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | @Override |
| 324 | public boolean isSummaryWithChildren() { |
| 325 | return mIsSummaryWithChildren; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | @Override |
| 329 | public boolean areChildrenExpanded() { |
| 330 | return mChildrenExpanded; |
| 331 | } |
| 332 | |
| 333 | public List<ExpandableNotificationRow> getNotificationChildren() { |
| 334 | return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren(); |
| 335 | } |
| 336 | |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 337 | public int getNumberOfNotificationChildren() { |
| 338 | if (mChildrenContainer == null) { |
| 339 | return 0; |
| 340 | } |
| 341 | return mChildrenContainer.getNotificationChildren().size(); |
| 342 | } |
| 343 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 344 | /** |
| 345 | * Apply the order given in the list to the children. |
| 346 | * |
| 347 | * @param childOrder the new list order |
| 348 | * @return whether the list order has changed |
| 349 | */ |
| 350 | public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder) { |
| 351 | return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder); |
| 352 | } |
| 353 | |
| 354 | public void getChildrenStates(StackScrollState resultState) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 355 | if (mIsSummaryWithChildren) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 356 | StackViewState parentState = resultState.getViewStateForView(this); |
| 357 | mChildrenContainer.getState(resultState, parentState); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | public void applyChildrenState(StackScrollState state) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 362 | if (mIsSummaryWithChildren) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 363 | mChildrenContainer.applyState(state); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | public void prepareExpansionChanged(StackScrollState state) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 368 | if (mIsSummaryWithChildren) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 369 | mChildrenContainer.prepareExpansionChanged(state); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | public void startChildAnimation(StackScrollState finalState, |
Selim Cinek | 9969559 | 2016-01-12 17:51:35 -0800 | [diff] [blame] | 374 | StackStateAnimator stateAnimator, long delay, long duration) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 375 | if (mIsSummaryWithChildren) { |
Selim Cinek | 9969559 | 2016-01-12 17:51:35 -0800 | [diff] [blame] | 376 | mChildrenContainer.startAnimationToState(finalState, stateAnimator, delay, |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 377 | duration); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | public ExpandableNotificationRow getViewAtPosition(float y) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 382 | if (!mIsSummaryWithChildren || !mChildrenExpanded) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 383 | return this; |
| 384 | } else { |
| 385 | ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y); |
| 386 | return view == null ? this : view; |
| 387 | } |
| 388 | } |
| 389 | |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 390 | public NotificationGuts getGuts() { |
| 391 | return mGuts; |
| 392 | } |
| 393 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 394 | /** |
| 395 | * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this |
| 396 | * the notification will be rendered on top of the screen. |
| 397 | * |
| 398 | * @param pinned whether it is pinned |
| 399 | */ |
| 400 | public void setPinned(boolean pinned) { |
| 401 | mIsPinned = pinned; |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 402 | if (pinned) { |
| 403 | setIconAnimationRunning(true); |
| 404 | mExpandedWhenPinned = false; |
| 405 | } else if (mExpandedWhenPinned) { |
| 406 | setUserExpanded(true); |
| 407 | } |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 408 | setChronometerRunning(mLastChronometerRunning); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 411 | public boolean isPinned() { |
| 412 | return mIsPinned; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 415 | /** |
| 416 | * @param atLeastMinHeight should the value returned be at least the minimum height. |
| 417 | * Used to avoid cyclic calls |
| 418 | * @return the height of the heads up notification when pinned |
| 419 | */ |
| 420 | public int getPinnedHeadsUpHeight(boolean atLeastMinHeight) { |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 421 | if (mIsSummaryWithChildren) { |
| 422 | return mChildrenContainer.getIntrinsicHeight(); |
| 423 | } |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 424 | if(mExpandedWhenPinned) { |
| 425 | return Math.max(getMaxExpandHeight(), mHeadsUpHeight); |
| 426 | } else if (atLeastMinHeight) { |
| 427 | return Math.max(getMinHeight(), mHeadsUpHeight); |
| 428 | } else { |
| 429 | return mHeadsUpHeight; |
| 430 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 433 | /** |
| 434 | * Mark whether this notification was just clicked, i.e. the user has just clicked this |
| 435 | * notification in this frame. |
| 436 | */ |
| 437 | public void setJustClicked(boolean justClicked) { |
| 438 | mJustClicked = justClicked; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * @return true if this notification has been clicked in this frame, false otherwise |
| 443 | */ |
| 444 | public boolean wasJustClicked() { |
| 445 | return mJustClicked; |
| 446 | } |
| 447 | |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 448 | public void setChronometerRunning(boolean running) { |
| 449 | mLastChronometerRunning = running; |
| 450 | setChronometerRunning(running, mPrivateLayout); |
| 451 | setChronometerRunning(running, mPublicLayout); |
| 452 | if (mChildrenContainer != null) { |
| 453 | List<ExpandableNotificationRow> notificationChildren = |
| 454 | mChildrenContainer.getNotificationChildren(); |
| 455 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 456 | ExpandableNotificationRow child = notificationChildren.get(i); |
| 457 | child.setChronometerRunning(running); |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | private void setChronometerRunning(boolean running, NotificationContentView layout) { |
| 463 | if (layout != null) { |
| 464 | running = running || isPinned(); |
| 465 | View contractedChild = layout.getContractedChild(); |
| 466 | View expandedChild = layout.getExpandedChild(); |
| 467 | View headsUpChild = layout.getHeadsUpChild(); |
| 468 | setChronometerRunningForChild(running, contractedChild); |
| 469 | setChronometerRunningForChild(running, expandedChild); |
| 470 | setChronometerRunningForChild(running, headsUpChild); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | private void setChronometerRunningForChild(boolean running, View child) { |
| 475 | if (child != null) { |
| 476 | View chronometer = child.findViewById(com.android.internal.R.id.chronometer); |
| 477 | if (chronometer instanceof Chronometer) { |
| 478 | ((Chronometer) chronometer).setStarted(running); |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 483 | public NotificationHeaderView getNotificationHeader() { |
| 484 | if (mNotificationHeader != null) { |
| 485 | return mNotificationHeader; |
Selim Cinek | 8d6440d | 2015-10-22 13:00:05 -0700 | [diff] [blame] | 486 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 487 | return mPrivateLayout.getNotificationHeader(); |
Selim Cinek | 8d6440d | 2015-10-22 13:00:05 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 490 | public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) { |
| 491 | mOnExpandClickListener = onExpandClickListener; |
| 492 | } |
| 493 | |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 494 | public void setHeadsUpManager(HeadsUpManager headsUpManager) { |
| 495 | mHeadsUpManager = headsUpManager; |
| 496 | } |
| 497 | |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 498 | public interface ExpansionLogger { |
| 499 | public void logNotificationExpansion(String key, boolean userAction, boolean expanded); |
| 500 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 501 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 502 | public ExpandableNotificationRow(Context context, AttributeSet attrs) { |
| 503 | super(context, attrs); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 504 | mFalsingManager = FalsingManager.getInstance(context); |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 505 | mNotificationMinHeightLegacy = getResources().getDimensionPixelSize( |
| 506 | R.dimen.notification_min_height_legacy); |
| 507 | mNotificationMinHeight = getResources().getDimensionPixelSize( |
| 508 | R.dimen.notification_min_height); |
| 509 | mNotificationMaxHeight = getResources().getDimensionPixelSize( |
| 510 | R.dimen.notification_max_height); |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 511 | mMaxHeadsUpHeightLegacy = getResources().getDimensionPixelSize( |
| 512 | R.dimen.notification_max_heads_up_height_legacy); |
| 513 | mMaxHeadsUpHeight = getResources().getDimensionPixelSize( |
| 514 | R.dimen.notification_max_heads_up_height); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 515 | } |
| 516 | |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 517 | /** |
| 518 | * Resets this view so it can be re-used for an updated notification. |
| 519 | */ |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 520 | @Override |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 521 | public void reset() { |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 522 | super.reset(); |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 523 | final boolean wasExpanded = isExpanded(); |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 524 | mMaxViewHeight = 0; |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 525 | mExpandable = false; |
| 526 | mHasUserChangedExpansion = false; |
| 527 | mUserLocked = false; |
| 528 | mShowingPublic = false; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 529 | mSensitive = false; |
| 530 | mShowingPublicInitialized = false; |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 531 | mIsSystemExpanded = false; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 532 | mOnKeyguard = false; |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 533 | mPublicLayout.reset(mIsHeadsUp); |
| 534 | mPrivateLayout.reset(mIsHeadsUp); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 535 | resetHeight(); |
| 536 | logExpansionEvent(false, wasExpanded); |
| 537 | } |
| 538 | |
| 539 | public void resetHeight() { |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 540 | if (mIsHeadsUp) { |
| 541 | resetActualHeight(); |
| 542 | } |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 543 | mMaxExpandHeight = 0; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 544 | mHeadsUpHeight = 0; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 545 | mWasReset = true; |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 546 | onHeightReset(); |
Selim Cinek | 6e28a67 | 2014-09-05 14:43:28 +0200 | [diff] [blame] | 547 | requestLayout(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 548 | } |
| 549 | |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 550 | @Override |
| 551 | protected void onFinishInflate() { |
| 552 | super.onFinishInflate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 553 | mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic); |
Selim Cinek | fa0a2d3 | 2016-01-14 13:02:21 -0800 | [diff] [blame^] | 554 | mPublicLayout.setContainingNotification(this); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 555 | mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 556 | mPrivateLayout.setExpandClickListener(mExpandClickListener); |
Selim Cinek | fa0a2d3 | 2016-01-14 13:02:21 -0800 | [diff] [blame^] | 557 | mPrivateLayout.setContainingNotification(this); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 558 | mPublicLayout.setExpandClickListener(mExpandClickListener); |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 559 | mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub); |
| 560 | mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() { |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 561 | @Override |
| 562 | public void onInflate(ViewStub stub, View inflated) { |
| 563 | mGuts = (NotificationGuts) inflated; |
| 564 | mGuts.setClipTopAmount(getClipTopAmount()); |
| 565 | mGuts.setActualHeight(getActualHeight()); |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 566 | mGutsStub = null; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 567 | } |
| 568 | }); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 569 | mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub); |
| 570 | mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() { |
| 571 | |
| 572 | @Override |
| 573 | public void onInflate(ViewStub stub, View inflated) { |
| 574 | mChildrenContainer = (NotificationChildrenContainer) inflated; |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 575 | mChildrenContainer.setNotificationParent(ExpandableNotificationRow.this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 576 | } |
| 577 | }); |
Selim Cinek | 863834b | 2014-05-20 04:20:25 +0200 | [diff] [blame] | 578 | mVetoButton = findViewById(R.id.veto); |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 579 | } |
| 580 | |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 581 | public void inflateGuts() { |
| 582 | if (mGuts == null) { |
| 583 | mGutsStub.inflate(); |
| 584 | } |
| 585 | } |
| 586 | |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 587 | private void updateChildrenVisibility() { |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 588 | mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE |
| 589 | : INVISIBLE); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 590 | if (mChildrenContainer != null) { |
| 591 | mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE |
| 592 | : INVISIBLE); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 593 | } |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 594 | if (mNotificationHeader != null) { |
| 595 | mNotificationHeader.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE |
| 596 | : INVISIBLE); |
| 597 | } |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 598 | // The limits might have changed if the view suddenly became a group or vice versa |
| 599 | updateLimits(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 600 | } |
| 601 | |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 602 | @Override |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 603 | public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) { |
| 604 | if (super.onRequestSendAccessibilityEventInternal(child, event)) { |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 605 | // Add a record for the entire layout since its content is somehow small. |
| 606 | // The event comes from a leaf view that is interacted with. |
| 607 | AccessibilityEvent record = AccessibilityEvent.obtain(); |
| 608 | onInitializeAccessibilityEvent(record); |
| 609 | dispatchPopulateAccessibilityEvent(record); |
| 610 | event.appendRecord(record); |
| 611 | return true; |
| 612 | } |
| 613 | return false; |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 614 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 615 | |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 616 | @Override |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 617 | public void setDark(boolean dark, boolean fade, long delay) { |
| 618 | super.setDark(dark, fade, delay); |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 619 | final NotificationContentView showing = getShowingLayout(); |
| 620 | if (showing != null) { |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 621 | showing.setDark(dark, fade, delay); |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 622 | } |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 623 | if (mIsSummaryWithChildren) { |
| 624 | mChildrenContainer.setDark(dark, fade, delay); |
| 625 | mNotificationHeaderWrapper.setDark(dark, fade, delay); |
| 626 | } |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 627 | } |
| 628 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 629 | public boolean isExpandable() { |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 630 | if (mIsSummaryWithChildren && !mShowingPublic) { |
| 631 | return !mChildrenExpanded; |
| 632 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 633 | return mExpandable; |
| 634 | } |
| 635 | |
| 636 | public void setExpandable(boolean expandable) { |
| 637 | mExpandable = expandable; |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 638 | mPrivateLayout.updateExpandButtons(isExpandable()); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 639 | } |
| 640 | |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 641 | @Override |
| 642 | public void setClipToActualHeight(boolean clipToActualHeight) { |
| 643 | super.setClipToActualHeight(clipToActualHeight); |
| 644 | getShowingLayout().setClipToActualHeight(clipToActualHeight); |
| 645 | } |
| 646 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 647 | /** |
| 648 | * @return whether the user has changed the expansion state |
| 649 | */ |
| 650 | public boolean hasUserChangedExpansion() { |
| 651 | return mHasUserChangedExpansion; |
| 652 | } |
| 653 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 654 | public boolean isUserExpanded() { |
| 655 | return mUserExpanded; |
| 656 | } |
| 657 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 658 | /** |
| 659 | * Set this notification to be expanded by the user |
| 660 | * |
| 661 | * @param userExpanded whether the user wants this notification to be expanded |
| 662 | */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 663 | public void setUserExpanded(boolean userExpanded) { |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 664 | setUserExpanded(userExpanded, false /* allowChildExpansion */); |
| 665 | } |
| 666 | |
| 667 | /** |
| 668 | * Set this notification to be expanded by the user |
| 669 | * |
| 670 | * @param userExpanded whether the user wants this notification to be expanded |
| 671 | * @param allowChildExpansion whether a call to this method allows expanding children |
| 672 | */ |
| 673 | public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 674 | mFalsingManager.setNotificationExpanded(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 675 | if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion) { |
| 676 | mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded); |
| 677 | return; |
| 678 | } |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 679 | if (userExpanded && !mExpandable) return; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 680 | final boolean wasExpanded = isExpanded(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 681 | mHasUserChangedExpansion = true; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 682 | mUserExpanded = userExpanded; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 683 | logExpansionEvent(true, wasExpanded); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 684 | } |
| 685 | |
Selim Cinek | ccd14fb | 2014-08-12 18:53:24 +0200 | [diff] [blame] | 686 | public void resetUserExpansion() { |
| 687 | mHasUserChangedExpansion = false; |
| 688 | mUserExpanded = false; |
| 689 | } |
| 690 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 691 | public boolean isUserLocked() { |
| 692 | return mUserLocked; |
| 693 | } |
| 694 | |
| 695 | public void setUserLocked(boolean userLocked) { |
| 696 | mUserLocked = userLocked; |
| 697 | } |
| 698 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 699 | /** |
| 700 | * @return has the system set this notification to be expanded |
| 701 | */ |
| 702 | public boolean isSystemExpanded() { |
| 703 | return mIsSystemExpanded; |
| 704 | } |
| 705 | |
| 706 | /** |
| 707 | * Set this notification to be expanded by the system. |
| 708 | * |
| 709 | * @param expand whether the system wants this notification to be expanded. |
| 710 | */ |
| 711 | public void setSystemExpanded(boolean expand) { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 712 | if (expand != mIsSystemExpanded) { |
| 713 | final boolean wasExpanded = isExpanded(); |
| 714 | mIsSystemExpanded = expand; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 715 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 716 | logExpansionEvent(false, wasExpanded); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 717 | if (mChildrenContainer != null) { |
| 718 | mChildrenContainer.updateGroupOverflow(); |
| 719 | } |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 720 | } |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | /** |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 724 | * @param onKeyguard whether to prevent notification expansion |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 725 | */ |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 726 | public void setOnKeyguard(boolean onKeyguard) { |
| 727 | if (onKeyguard != mOnKeyguard) { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 728 | final boolean wasExpanded = isExpanded(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 729 | mOnKeyguard = onKeyguard; |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 730 | logExpansionEvent(false, wasExpanded); |
| 731 | if (wasExpanded != isExpanded()) { |
Selim Cinek | 2108fe0 | 2015-12-10 12:56:13 -0800 | [diff] [blame] | 732 | if (mIsSummaryWithChildren) { |
| 733 | mChildrenContainer.updateGroupOverflow(); |
| 734 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 735 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 736 | } |
| 737 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | /** |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 741 | * @return Can the underlying notification be cleared? |
| 742 | */ |
| 743 | public boolean isClearable() { |
Selim Cinek | a37774f | 2014-11-11 19:16:18 +0100 | [diff] [blame] | 744 | return mStatusBarNotification != null && mStatusBarNotification.isClearable(); |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | /** |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 748 | * Apply an expansion state to the layout. |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 749 | */ |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 750 | public void applyExpansionToLayout() { |
| 751 | boolean expand = isExpanded(); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 752 | if (expand && mExpandable) { |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 753 | setActualHeight(mMaxExpandHeight); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 754 | } else { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 755 | setActualHeight(getMinHeight()); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 756 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 757 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 758 | |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 759 | @Override |
| 760 | public int getIntrinsicHeight() { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 761 | if (isUserLocked()) { |
| 762 | return getActualHeight(); |
| 763 | } |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 764 | if (mGuts != null && mGuts.areGutsExposed()) { |
| 765 | return mGuts.getHeight(); |
| 766 | } else if ((isChildInGroup() && !isGroupExpanded())) { |
| 767 | return mPrivateLayout.getMinHeight(); |
| 768 | } else if (mSensitive && mHideSensitiveForIntrinsicHeight) { |
| 769 | return getMinHeight(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 770 | } else if (mIsSummaryWithChildren && !mOnKeyguard) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 771 | return mChildrenContainer.getIntrinsicHeight(); |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame] | 772 | } else if (mIsHeadsUp) { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 773 | if (isPinned()) { |
| 774 | return getPinnedHeadsUpHeight(true /* atLeastMinHeight */); |
| 775 | } else if (isExpanded()) { |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 776 | return Math.max(getMaxExpandHeight(), mHeadsUpHeight); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 777 | } else { |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 778 | return Math.max(getMinHeight(), mHeadsUpHeight); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 779 | } |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 780 | } else if (isExpanded()) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 781 | return getMaxExpandHeight(); |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 782 | } else { |
| 783 | return getMinHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 784 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 785 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 786 | |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 787 | private boolean isGroupExpanded() { |
| 788 | return mGroupManager.isGroupExpanded(mStatusBarNotification); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 789 | } |
| 790 | |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 791 | /** |
| 792 | * @return whether this view has a header on the top of the content |
| 793 | */ |
| 794 | private boolean hasNotificationHeader() { |
| 795 | return mIsSummaryWithChildren; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 796 | } |
| 797 | |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 798 | private void onChildrenCountChanged() { |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 799 | mIsSummaryWithChildren = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 800 | && mGroupManager.hasGroupChildren(mStatusBarNotification); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 801 | if (mIsSummaryWithChildren) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 802 | if (mChildrenContainer == null) { |
| 803 | mChildrenContainerStub.inflate(); |
| 804 | } |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 805 | if (mNotificationHeader == null) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 806 | recreateNotificationHeader(); |
| 807 | } |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 808 | } |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 809 | mPrivateLayout.updateExpandButtons(isExpandable()); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 810 | updateChildrenHeaderAppearance(); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 811 | updateHeaderChildCount(); |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 812 | updateChildrenVisibility(); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 815 | /** |
| 816 | * Check whether the view state is currently expanded. This is given by the system in {@link |
| 817 | * #setSystemExpanded(boolean)} and can be overridden by user expansion or |
| 818 | * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this |
| 819 | * view can differ from this state, if layout params are modified from outside. |
| 820 | * |
| 821 | * @return whether the view state is currently expanded. |
| 822 | */ |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 823 | public boolean isExpanded() { |
| 824 | return !mOnKeyguard |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 825 | && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded()) |
| 826 | || isUserExpanded()); |
| 827 | } |
| 828 | |
| 829 | private boolean isSystemChildExpanded() { |
| 830 | return mIsSystemChildExpanded; |
| 831 | } |
| 832 | |
| 833 | public void setSystemChildExpanded(boolean expanded) { |
| 834 | mIsSystemChildExpanded = expanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | @Override |
| 838 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 839 | super.onLayout(changed, left, top, right, bottom); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 840 | boolean updateExpandHeight = mMaxExpandHeight == 0 && !mWasReset; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 841 | updateMaxHeights(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 842 | if (updateExpandHeight) { |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 843 | applyExpansionToLayout(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 844 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 845 | mWasReset = false; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 846 | } |
| 847 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 848 | private void updateMaxHeights() { |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 849 | int intrinsicBefore = getIntrinsicHeight(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 850 | View expandedChild = mPrivateLayout.getExpandedChild(); |
| 851 | if (expandedChild == null) { |
| 852 | expandedChild = mPrivateLayout.getContractedChild(); |
| 853 | } |
| 854 | mMaxExpandHeight = expandedChild.getHeight(); |
| 855 | View headsUpChild = mPrivateLayout.getHeadsUpChild(); |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 856 | if (headsUpChild == null) { |
| 857 | headsUpChild = mPrivateLayout.getContractedChild(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 858 | } |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 859 | mHeadsUpHeight = headsUpChild.getHeight(); |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 860 | if (intrinsicBefore != getIntrinsicHeight()) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 861 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | |
Selim Cinek | fa0a2d3 | 2016-01-14 13:02:21 -0800 | [diff] [blame^] | 865 | @Override |
| 866 | public void notifyHeightChanged(boolean needsAnimation) { |
| 867 | super.notifyHeightChanged(needsAnimation); |
| 868 | getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked()); |
| 869 | } |
| 870 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 871 | public void setSensitive(boolean sensitive) { |
| 872 | mSensitive = sensitive; |
| 873 | } |
| 874 | |
| 875 | public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) { |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame] | 876 | mHideSensitiveForIntrinsicHeight = hideSensitive; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | public void setHideSensitive(boolean hideSensitive, boolean animated, long delay, |
| 880 | long duration) { |
| 881 | boolean oldShowingPublic = mShowingPublic; |
| 882 | mShowingPublic = mSensitive && hideSensitive; |
| 883 | if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) { |
| 884 | return; |
| 885 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 886 | |
| 887 | // bail out if no public version |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 888 | if (mPublicLayout.getChildCount() == 0) return; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 889 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 890 | if (!animated) { |
| 891 | mPublicLayout.animate().cancel(); |
| 892 | mPrivateLayout.animate().cancel(); |
| 893 | mPublicLayout.setAlpha(1f); |
| 894 | mPrivateLayout.setAlpha(1f); |
| 895 | mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE); |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 896 | updateChildrenVisibility(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 897 | } else { |
| 898 | animateShowingPublic(delay, duration); |
| 899 | } |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 900 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 901 | mPrivateLayout.updateExpandButtons(isExpandable()); |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 902 | updateVetoButton(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 903 | mShowingPublicInitialized = true; |
| 904 | } |
| 905 | |
| 906 | private void animateShowingPublic(long delay, long duration) { |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 907 | View[] privateViews = mIsSummaryWithChildren ? |
| 908 | new View[] {mChildrenContainer, mNotificationHeader} |
| 909 | : new View[] {mPrivateLayout}; |
| 910 | View[] publicViews = new View[] {mPublicLayout}; |
| 911 | View[] hiddenChildren = mShowingPublic ? privateViews : publicViews; |
| 912 | View[] shownChildren = mShowingPublic ? publicViews : privateViews; |
| 913 | for (final View hiddenView : hiddenChildren) { |
| 914 | hiddenView.setVisibility(View.VISIBLE); |
| 915 | hiddenView.animate().cancel(); |
| 916 | hiddenView.animate() |
| 917 | .alpha(0f) |
| 918 | .setStartDelay(delay) |
| 919 | .setDuration(duration) |
| 920 | .withEndAction(new Runnable() { |
| 921 | @Override |
| 922 | public void run() { |
| 923 | hiddenView.setVisibility(View.INVISIBLE); |
| 924 | } |
| 925 | }); |
| 926 | } |
| 927 | for (View showView : shownChildren) { |
| 928 | showView.setVisibility(View.VISIBLE); |
| 929 | showView.setAlpha(0f); |
| 930 | showView.animate().cancel(); |
| 931 | showView.animate() |
| 932 | .alpha(1f) |
| 933 | .setStartDelay(delay) |
| 934 | .setDuration(duration); |
| 935 | } |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | private void updateVetoButton() { |
| 939 | // public versions cannot be dismissed |
| 940 | mVetoButton.setVisibility(isClearable() && !mShowingPublic ? View.VISIBLE : View.GONE); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 941 | } |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 942 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 943 | public void setChildrenExpanded(boolean expanded, boolean animate) { |
| 944 | mChildrenExpanded = expanded; |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 945 | if (mNotificationHeader != null) { |
| 946 | mNotificationHeader.setExpanded(expanded); |
| 947 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 948 | if (mChildrenContainer != null) { |
| 949 | mChildrenContainer.setChildrenExpanded(expanded); |
| 950 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 951 | } |
| 952 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 953 | public void updateHeaderChildCount() { |
| 954 | if (mIsSummaryWithChildren) { |
| 955 | mNotificationHeader.setChildCount( |
| 956 | mChildrenContainer.getNotificationChildren().size()); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 957 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | public static void applyTint(View v, int color) { |
| 961 | int alpha; |
| 962 | if (color != 0) { |
| 963 | alpha = COLORED_DIVIDER_ALPHA; |
| 964 | } else { |
| 965 | color = 0xff000000; |
| 966 | alpha = DEFAULT_DIVIDER_ALPHA; |
| 967 | } |
| 968 | if (v.getBackground() instanceof ColorDrawable) { |
| 969 | ColorDrawable background = (ColorDrawable) v.getBackground(); |
| 970 | background.mutate(); |
| 971 | background.setColor(color); |
| 972 | background.setAlpha(alpha); |
| 973 | } |
| 974 | } |
| 975 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 976 | public int getMaxExpandHeight() { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 977 | return mMaxExpandHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 978 | } |
Jorim Jaggi | 584a7aa | 2014-04-10 23:26:13 +0200 | [diff] [blame] | 979 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 980 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 981 | public boolean isContentExpandable() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 982 | NotificationContentView showingLayout = getShowingLayout(); |
| 983 | return showingLayout.isContentExpandable(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | @Override |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 987 | protected View getContentView() { |
| 988 | return getShowingLayout(); |
| 989 | } |
| 990 | |
| 991 | @Override |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 992 | public void setActualHeight(int height, boolean notifyListeners) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 993 | super.setActualHeight(height, notifyListeners); |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 994 | int contentHeight = Math.max(getMinHeight(), height); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 995 | mPrivateLayout.setContentHeight(contentHeight); |
| 996 | mPublicLayout.setContentHeight(contentHeight); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 997 | if (mGuts != null) { |
| 998 | mGuts.setActualHeight(height); |
| 999 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1000 | invalidate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1004 | public int getMaxContentHeight() { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1005 | if (mIsSummaryWithChildren && !mShowingPublic) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1006 | return mChildrenContainer.getMaxContentHeight(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1007 | } |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 1008 | NotificationContentView showingLayout = getShowingLayout(); |
| 1009 | return showingLayout.getMaxHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 1013 | public int getMinHeight() { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 1014 | if (mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) { |
| 1015 | return getPinnedHeadsUpHeight(false /* atLeastMinHeight */); |
| 1016 | } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) { |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 1017 | return mChildrenContainer.getMinHeight(); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 1018 | } else if (mIsHeadsUp) { |
| 1019 | return mHeadsUpHeight; |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 1020 | } |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1021 | NotificationContentView showingLayout = getShowingLayout(); |
| 1022 | return showingLayout.getMinHeight(); |
| 1023 | } |
| 1024 | |
| 1025 | @Override |
| 1026 | public int getMinExpandHeight() { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1027 | if (mIsSummaryWithChildren && !mOnKeyguard) { |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 1028 | return mChildrenContainer.getMinExpandHeight(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1029 | } |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1030 | return getMinHeight(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | @Override |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1034 | public void setClipTopAmount(int clipTopAmount) { |
| 1035 | super.setClipTopAmount(clipTopAmount); |
| 1036 | mPrivateLayout.setClipTopAmount(clipTopAmount); |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 1037 | mPublicLayout.setClipTopAmount(clipTopAmount); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 1038 | if (mGuts != null) { |
| 1039 | mGuts.setClipTopAmount(clipTopAmount); |
| 1040 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1041 | } |
| 1042 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1043 | private void recreateNotificationHeader() { |
| 1044 | final Notification.Builder builder = Notification.Builder.recoverBuilder(getContext(), |
| 1045 | getStatusBarNotification().getNotification()); |
| 1046 | final RemoteViews header = builder.makeNotificationHeader(); |
| 1047 | if (mNotificationHeader == null) { |
| 1048 | mNotificationHeader = (NotificationHeaderView) header.apply(getContext(), this); |
| 1049 | final View expandButton = mNotificationHeader.findViewById( |
| 1050 | com.android.internal.R.id.expand_button); |
| 1051 | expandButton.setVisibility(VISIBLE); |
| 1052 | mNotificationHeader.setOnClickListener(mExpandClickListener); |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 1053 | mNotificationHeaderWrapper = NotificationViewWrapper.wrap(getContext(), |
| 1054 | mNotificationHeader); |
Selim Cinek | b5a8361 | 2015-12-11 14:14:39 -0800 | [diff] [blame] | 1055 | addView(mNotificationHeader, indexOfChild(mChildrenContainer) + 1); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1056 | } else { |
| 1057 | header.reapply(getContext(), mNotificationHeader); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 1058 | mNotificationHeaderWrapper.notifyContentUpdated(mEntry.notification); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1059 | } |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 1060 | updateHeaderExpandButton(); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 1061 | updateChildrenHeaderAppearance(); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 1062 | updateHeaderChildCount(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1063 | } |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 1064 | |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 1065 | private void updateHeaderExpandButton() { |
| 1066 | if (mIsSummaryWithChildren) { |
| 1067 | mNotificationHeader.setIsGroupHeader(true /* isGroupHeader*/); |
| 1068 | } |
| 1069 | } |
| 1070 | |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 1071 | public void updateChildrenHeaderAppearance() { |
| 1072 | if (mIsSummaryWithChildren) { |
| 1073 | mHeaderUtil.updateChildrenHeaderAppearance(); |
| 1074 | } |
| 1075 | } |
| 1076 | |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 1077 | public boolean isMaxExpandHeightInitialized() { |
| 1078 | return mMaxExpandHeight != 0; |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 1079 | } |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 1080 | |
| 1081 | private NotificationContentView getShowingLayout() { |
| 1082 | return mShowingPublic ? mPublicLayout : mPrivateLayout; |
| 1083 | } |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1084 | |
Jorim Jaggi | 59ec304 | 2015-06-05 15:18:43 -0700 | [diff] [blame] | 1085 | @Override |
| 1086 | public void setShowingLegacyBackground(boolean showing) { |
| 1087 | super.setShowingLegacyBackground(showing); |
| 1088 | mPrivateLayout.setShowingLegacyBackground(showing); |
| 1089 | mPublicLayout.setShowingLegacyBackground(showing); |
| 1090 | } |
| 1091 | |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 1092 | @Override |
| 1093 | protected void updateBackgroundTint() { |
| 1094 | super.updateBackgroundTint(); |
| 1095 | updateNoBackgroundState(); |
| 1096 | if (mIsSummaryWithChildren) { |
| 1097 | List<ExpandableNotificationRow> notificationChildren = |
| 1098 | mChildrenContainer.getNotificationChildren(); |
| 1099 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 1100 | ExpandableNotificationRow child = notificationChildren.get(i); |
| 1101 | child.updateNoBackgroundState(); |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | private void updateNoBackgroundState() { |
| 1107 | mShowNoBackground = isChildInGroup() && hasSameBgColor(mNotificationParent); |
| 1108 | updateBackground(); |
| 1109 | } |
| 1110 | |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1111 | public void setExpansionLogger(ExpansionLogger logger, String key) { |
| 1112 | mLogger = logger; |
| 1113 | mLoggingKey = key; |
| 1114 | } |
| 1115 | |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1116 | private void logExpansionEvent(boolean userAction, boolean wasExpanded) { |
| 1117 | final boolean nowExpanded = isExpanded(); |
| 1118 | if (wasExpanded != nowExpanded && mLogger != null) { |
| 1119 | mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ; |
| 1120 | } |
| 1121 | } |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 1122 | |
| 1123 | public interface OnExpandClickListener { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 1124 | void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded); |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 1125 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1126 | } |