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